FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
stat_segment.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <vppinfra/mem.h>
17 #include <vlib/vlib.h>
18 #include <vlib/unix/unix.h>
19 #include "stat_segment.h"
20 #include <vnet/vnet.h>
21 #include <vnet/devices/devices.h> /* vnet_get_aggregate_rx_packets */
22 #undef HAVE_MEMFD_CREATE
23 #include <vppinfra/linux/syscall.h>
25 #include <vppinfra/mheap.h>
26 
28 
29 /*
30  * Used only by VPP writers
31  */
32 void
34 {
37  sm->shared_header->in_progress = 1;
38 }
39 
40 void
42 {
44  sm->shared_header->epoch++;
45  sm->shared_header->in_progress = 0;
47 }
48 
49 /*
50  * Change heap to the stats shared memory segment
51  */
52 void *
54 {
56 
57  sm->last = old;
58  ASSERT (sm && sm->shared_header);
59  return clib_mem_set_heap (sm->heap);
60 }
61 
62 static u32
64 {
67  hash_pair_t *hp;
68 
69  /* Must be called in the context of the main heap */
70  ASSERT (clib_mem_get_heap () != sm->heap);
71 
72  hp = hash_get_pair (sm->directory_vector_by_name, name);
73  if (hp)
74  {
75  index = hp->value[0];
76  }
77 
78  return index;
79 }
80 
81 static void
83 {
85 
86  /* Must be called in the context of the main heap */
87  ASSERT (clib_mem_get_heap () != sm->heap);
88 
89  hash_set (sm->directory_vector_by_name, format (0, "%s%c", name, 0), index);
90 }
91 
92 static u32
94 {
96  u32 next_vector_index = vec_len (sm->directory_vector);
97 
98  ssize_t i;
100  {
102  {
103  next_vector_index = i;
104  break;
105  }
106  }
107 
108  return next_vector_index;
109 }
110 
111 static u32
113 {
115 
116  ASSERT (clib_mem_get_heap () == sm->heap);
117 
119 
120  clib_mem_set_heap (oldheap);
121  create_hash_index ((u8 *) e->name, index);
122  clib_mem_set_heap (sm->heap);
123 
124  vec_validate (sm->directory_vector, index);
125  sm->directory_vector[index] = *e;
126 
127  return index;
128 }
129 
130 static void
132 {
135 
136  ASSERT (clib_mem_get_heap () == sm->heap);
137 
138  if (index > vec_len (sm->directory_vector))
139  return;
140 
141  e = &sm->directory_vector[index];
142 
143  clib_mem_set_heap (oldheap);
145  clib_mem_set_heap (sm->heap);
146 
147  memset (e, 0, sizeof (*e));
149 }
150 
151 /*
152  * Called from main heap
153  */
154 void
155 vlib_stats_delete_cm (void *cm_arg)
156 {
160 
161  /* Not all counters have names / hash-table entries */
162  if (!cm->name && !cm->stat_segment_name)
163  {
164  return;
165  }
167 
168  /* Lookup hash-table is on the main heap */
169  char *stat_segment_name =
170  cm->stat_segment_name ? cm->stat_segment_name : cm->name;
171  u32 index = lookup_hash_index ((u8 *) stat_segment_name);
172 
173  e = &sm->directory_vector[index];
175 
176  void *oldheap = clib_mem_set_heap (sm->heap); /* Enter stats segment */
177  clib_mem_set_heap (oldheap); /* Exit stats segment */
178 
179  memset (e, 0, sizeof (*e));
181 
183 }
184 
185 void
186 vlib_stats_pop_heap (void *cm_arg, void *oldheap, u32 cindex,
188 {
191  stat_segment_shared_header_t *shared_header = sm->shared_header;
192  char *stat_segment_name;
194 
195  /* Not all counters have names / hash-table entries */
196  if (!cm->name && !cm->stat_segment_name)
197  {
198  clib_mem_set_heap (oldheap);
199  return;
200  }
201 
202  ASSERT (shared_header);
203 
205 
206  /* Lookup hash-table is on the main heap */
207  stat_segment_name =
208  cm->stat_segment_name ? cm->stat_segment_name : cm->name;
209 
210  clib_mem_set_heap (oldheap); /* Exit stats segment */
211  u32 vector_index = lookup_hash_index ((u8 *) stat_segment_name);
212  /* Back to stats segment */
213  clib_mem_set_heap (sm->heap); /* Re-enter stat segment */
214 
215 
216  /* Update the vector */
217  if (vector_index == STAT_SEGMENT_INDEX_INVALID)
218  { /* New */
219  strncpy (e.name, stat_segment_name, 128 - 1);
220  e.type = type;
221  vector_index = vlib_stats_create_counter (&e, oldheap);
222  }
223 
224  stat_segment_directory_entry_t *ep = &sm->directory_vector[vector_index];
225  ep->data = cm->counters;
226 
227  /* Reset the client hash table pointer, since it WILL change! */
228  shared_header->directory_vector = sm->directory_vector;
229 
231  clib_mem_set_heap (oldheap);
232 }
233 
234 void
235 vlib_stats_register_error_index (void *oldheap, u8 * name, u64 * em_vec,
236  u64 index)
237 {
239  stat_segment_shared_header_t *shared_header = sm->shared_header;
241 
242  ASSERT (shared_header);
243 
245  clib_mem_set_heap (oldheap); /* Exit stats segment */
246  u32 vector_index = lookup_hash_index (name);
247  /* Back to stats segment */
248  clib_mem_set_heap (sm->heap); /* Re-enter stat segment */
249 
250  if (vector_index == STAT_SEGMENT_INDEX_INVALID)
251  {
252  memcpy (e.name, name, vec_len (name));
253  e.name[vec_len (name)] = '\0';
255  e.index = index;
256  vector_index = vlib_stats_create_counter (&e, oldheap);
257 
258  /* Warn clients to refresh any pointers they might be holding */
259  shared_header->directory_vector = sm->directory_vector;
260  }
261 
263 }
264 
265 static void
267 {
268  counter_t **counters = ep->data;
270  int i;
271 
272  vec_validate_aligned (counters, tm->n_vlib_mains - 1,
274  for (i = 0; i < tm->n_vlib_mains; i++)
275  vec_validate_aligned (counters[i], max, CLIB_CACHE_LINE_BYTES);
276 
277  ep->data = counters;
278 }
279 
280 always_inline void
282  u32 thread_index, u32 index, u64 value)
283 {
284  ASSERT (ep->data);
285  counter_t **counters = ep->data;
286  counter_t *cb = counters[thread_index];
287  cb[index] = value;
288 }
289 
290 void
291 vlib_stats_pop_heap2 (u64 * error_vector, u32 thread_index, void *oldheap,
292  int lock)
293 {
295  stat_segment_shared_header_t *shared_header = sm->shared_header;
296 
297  ASSERT (shared_header);
298 
299  if (lock)
301 
302  /* Reset the client hash table pointer, since it WILL change! */
303  vec_validate (sm->error_vector, thread_index);
304  sm->error_vector[thread_index] = error_vector;
305 
306  shared_header->error_vector = sm->error_vector;
307  shared_header->directory_vector = sm->directory_vector;
308 
309  if (lock)
311  clib_mem_set_heap (oldheap);
312 }
313 
314 clib_error_t *
316 {
318  stat_segment_shared_header_t *shared_header;
319  void *oldheap;
320  ssize_t memory_size;
321  int mfd;
322  char *mem_name = "stat_segment_test";
323  void *memaddr;
324 
325  memory_size = sm->memory_size;
326  if (memory_size == 0)
327  memory_size = STAT_SEGMENT_DEFAULT_SIZE;
328 
329  /* Create shared memory segment */
330  if ((mfd = memfd_create (mem_name, 0)) < 0)
331  return clib_error_return (0, "stat segment memfd_create failure");
332 
333  /* Set size */
334  if ((ftruncate (mfd, memory_size)) == -1)
335  return clib_error_return (0, "stat segment ftruncate failure");
336 
337  if ((memaddr =
338  mmap (NULL, memory_size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd,
339  0)) == MAP_FAILED)
340  return clib_error_return (0, "stat segment mmap failure");
341 
342  void *heap;
343  heap =
344  create_mspace_with_base (((u8 *) memaddr) + getpagesize (),
345  memory_size - getpagesize (), 1 /* locked */ );
346  mspace_disable_expand (heap);
347  sm->heap = heap;
348  sm->memfd = mfd;
349 
351  sm->shared_header = shared_header = memaddr;
352 
353  shared_header->version = STAT_SEGMENT_VERSION;
354  shared_header->base = memaddr;
355 
358 
359  oldheap = clib_mem_set_heap (sm->heap);
360 
361  /* Set up the name to counter-vector hash table */
362  sm->directory_vector = 0;
363 
364  shared_header->epoch = 1;
365 
366  /* Scalar stats and node counters */
368 #define _(E,t,n,p) \
369  strcpy(sm->directory_vector[STAT_COUNTER_##E].name, #p "/" #n); \
370  sm->directory_vector[STAT_COUNTER_##E].type = STAT_DIR_TYPE_##t;
372 #undef _
373  /* Save the vector in the shared segment, for clients */
374  shared_header->directory_vector = sm->directory_vector;
375 
376  clib_mem_set_heap (oldheap);
377 
378  /* Total shared memory size */
380  mheap_usage (sm->heap, &usage);
382  usage.bytes_total;
383 
384  return 0;
385 }
386 
387 static int
388 name_sort_cmp (void *a1, void *a2)
389 {
392 
393  return strcmp ((char *) n1->name, (char *) n2->name);
394 }
395 
396 static u8 *
397 format_stat_dir_entry (u8 * s, va_list * args)
398 {
400  va_arg (*args, stat_segment_directory_entry_t *);
401  char *type_name;
402  char *format_string;
403 
404  format_string = "%-74s %-10s %10lld";
405 
406  switch (ep->type)
407  {
409  type_name = "ScalarPtr";
410  break;
411 
414  type_name = "CMainPtr";
415  break;
416 
418  type_name = "ErrIndex";
419  break;
420 
422  type_name = "NameVector";
423  break;
424 
425  case STAT_DIR_TYPE_EMPTY:
426  type_name = "empty";
427  break;
428 
429  default:
430  type_name = "illegal!";
431  break;
432  }
433 
434  return format (s, format_string, ep->name, type_name, 0);
435 }
436 
437 static clib_error_t *
439  unformat_input_t * input,
440  vlib_cli_command_t * cmd)
441 {
444  int i;
445 
446  int verbose = 0;
447 
448  if (unformat (input, "verbose"))
449  verbose = 1;
450 
451  /* Lock even as reader, as this command doesn't handle epoch changes */
453  show_data = vec_dup (sm->directory_vector);
455 
457 
458  vlib_cli_output (vm, "%-74s %10s %10s", "Name", "Type", "Value");
459 
460  for (i = 0; i < vec_len (show_data); i++)
461  {
463 
464  if (ep->type == STAT_DIR_TYPE_EMPTY)
465  continue;
466 
467  vlib_cli_output (vm, "%-100U", format_stat_dir_entry,
468  vec_elt_at_index (show_data, i));
469  }
470 
471  if (verbose)
472  {
473  ASSERT (sm->heap);
474  vlib_cli_output (vm, "%U", format_mheap, sm->heap, 0 /* verbose */ );
475  }
476 
477  return 0;
478 }
479 
480 /* *INDENT-OFF* */
481 VLIB_CLI_COMMAND (show_stat_segment_command, static) =
482 {
483  .path = "show statistics segment",
484  .short_help = "show statistics segment [verbose]",
485  .function = show_stat_segment_command_fn,
486 };
487 /* *INDENT-ON* */
488 
489 /*
490  * Node performance counters:
491  * total_calls [threads][node-index]
492  * total_vectors
493  * total_calls
494  * total suspends
495  */
496 
497 static inline void
499 {
500  vlib_main_t **stat_vms = 0;
501  vlib_node_t ***node_dups = 0;
502  int i, j;
503  static u32 no_max_nodes = 0;
504 
505  vlib_node_get_nodes (0 /* vm, for barrier sync */ ,
506  (u32) ~ 0 /* all threads */ ,
507  1 /* include stats */ ,
508  0 /* barrier sync */ ,
509  &node_dups, &stat_vms);
510 
511  u32 l = vec_len (node_dups[0]);
512 
513  /*
514  * Extend performance nodes if necessary
515  */
516  if (l > no_max_nodes)
517  {
518  void *oldheap = clib_mem_set_heap (sm->heap);
520 
522  [STAT_COUNTER_NODE_CLOCKS], l - 1);
524  [STAT_COUNTER_NODE_VECTORS], l - 1);
526  [STAT_COUNTER_NODE_CALLS], l - 1);
528  [STAT_COUNTER_NODE_SUSPENDS], l - 1);
529 
530  vec_validate (sm->nodes, l - 1);
533  ep->data = sm->nodes;
534 
535  /* Update names dictionary */
536  vlib_node_t **nodes = node_dups[0];
537  int i;
538  for (i = 0; i < vec_len (nodes); i++)
539  {
540  vlib_node_t *n = nodes[i];
541  u8 *s = 0;
542  s = format (s, "%v%c", n->name, 0);
543  if (sm->nodes[n->index])
544  vec_free (sm->nodes[n->index]);
545  sm->nodes[n->index] = s;
546  }
548  clib_mem_set_heap (oldheap);
549  no_max_nodes = l;
550  }
551 
552  for (j = 0; j < vec_len (node_dups); j++)
553  {
554  vlib_node_t **nodes = node_dups[j];
555 
556  for (i = 0; i < vec_len (nodes); i++)
557  {
558  counter_t **counters;
559  counter_t *c;
560  vlib_node_t *n = nodes[i];
561 
563  c = counters[j];
565 
567  c = counters[j];
569 
571  c = counters[j];
572  c[n->index] = n->stats_total.calls - n->stats_last_clear.calls;
573 
575  c = counters[j];
576  c[n->index] =
578  }
579  vec_free (node_dups[j]);
580  }
581  vec_free (node_dups);
582  vec_free (stat_vms);
583 }
584 
585 static void
587 {
588  vlib_main_t *vm = vlib_mains[0];
589  f64 vector_rate;
590  u64 input_packets;
591  f64 dt, now;
592  vlib_main_t *this_vlib_main;
593  int i;
594  static int num_worker_threads_set;
595 
596  /*
597  * Set once at the beginning of time.
598  * Can't do this from the init routine, which happens before
599  * start_workers sets up vlib_mains...
600  */
601  if (PREDICT_FALSE (num_worker_threads_set == 0))
602  {
603  void *oldheap = clib_mem_set_heap (sm->heap);
605 
608  num_worker_threads_set = 1;
610  clib_mem_set_heap (oldheap);
611  }
612 
613  /*
614  * Compute per-worker vector rates, and the average vector rate
615  * across all workers
616  */
617  vector_rate = 0.0;
618 
619  for (i = 0; i < vec_len (vlib_mains); i++)
620  {
621 
622  f64 this_vector_rate;
623 
624  this_vlib_main = vlib_mains[i];
625 
626  this_vector_rate = vlib_internal_node_vector_rate (this_vlib_main);
627  vlib_clear_internal_node_vector_rate (this_vlib_main);
628 
629  vector_rate += this_vector_rate;
630 
631  /* Set the per-worker rate */
634  this_vector_rate);
635  }
636 
637  /* And set the system average rate */
638  vector_rate /= (f64) (i > 1 ? i - 1 : 1);
639 
641 
642  /*
643  * Compute the aggregate input rate
644  */
645  now = vlib_time_now (vm);
647  input_packets = vnet_get_aggregate_rx_packets ();
649  (f64) (input_packets - sm->last_input_packets) / dt;
651  sm->last_input_packets = input_packets;
654 
655  /* Stats segment memory heap counter */
657  mheap_usage (sm->heap, &usage);
659  usage.bytes_used;
660 
661  if (sm->node_counters_enabled)
663 
664  /* *INDENT-OFF* */
666  pool_foreach(g, sm->gauges,
667  ({
668  g->fn(&sm->directory_vector[g->directory_index], g->caller_index);
669  }));
670  /* *INDENT-ON* */
671 
672  /* Heartbeat, so clients detect we're still here */
674 }
675 
676 /*
677  * Accept connection on the socket and exchange the fd for the shared
678  * memory segment.
679  */
680 static clib_error_t *
682 {
684  clib_error_t *err;
685  clib_socket_t client = { 0 };
686 
687  err = clib_socket_accept (sm->socket, &client);
688  if (err)
689  {
690  clib_error_report (err);
691  return err;
692  }
693 
694  /* Send the fd across and close */
695  err = clib_socket_sendmsg (&client, 0, 0, &sm->memfd, 1);
696  if (err)
697  clib_error_report (err);
698  clib_socket_close (&client);
699 
700  return 0;
701 }
702 
703 static clib_error_t *
705 {
707  clib_error_t *error;
709 
710  memset (s, 0, sizeof (clib_socket_t));
711  s->config = (char *) sm->socket_name;
714 
715  if ((error = clib_socket_init (s)))
716  return error;
717 
718  clib_file_t template = { 0 };
720  template.file_descriptor = s->fd;
721  template.description = format (0, "stats segment listener %s", s->config);
722  clib_file_add (&file_main, &template);
723 
724  sm->socket = s;
725 
726  return 0;
727 }
728 
729 static clib_error_t *
731 {
732  /*
733  * cleanup the listener socket on exit.
734  */
736  unlink ((char *) sm->socket_name);
737  return 0;
738 }
739 
741 
742 /* Overrides weak reference in vlib:node_cli.c */
743 f64
745 {
746  return stat_segment_main.update_interval;
747 }
748 
749 static uword
751  vlib_frame_t * f)
752 {
754 
755  while (1)
756  {
759  }
760  return 0; /* or not */
761 }
762 
763 static clib_error_t *
765 {
767 
768  /* set default socket file name when statseg config stanza is empty. */
769  if (!vec_len (sm->socket_name))
770  sm->socket_name = format (0, "%s/%s%c", vlib_unix_get_runtime_dir (),
772  return stats_segment_socket_init ();
773 }
774 
775 /* *INDENT-OFF* */
777 {
778  .runs_after = VLIB_INITS("unix_input_init"),
779 };
780 /* *INDENT-ON* */
781 
782 clib_error_t *
784  u32 caller_index)
785 {
787  stat_segment_shared_header_t *shared_header = sm->shared_header;
788  void *oldheap;
791 
792  ASSERT (shared_header);
793 
794  u32 vector_index = lookup_hash_index (name);
795 
796  if (vector_index != STAT_SEGMENT_INDEX_INVALID) /* Already registered */
797  return clib_error_return (0, "%v is already registered", name);
798 
799  memset (&e, 0, sizeof (e));
801  memcpy (e.name, name, vec_len (name));
802 
803  oldheap = vlib_stats_push_heap (NULL);
805  vector_index = vlib_stats_create_counter (&e, oldheap);
806 
807  shared_header->directory_vector = sm->directory_vector;
808 
810  clib_mem_set_heap (oldheap);
811 
812  /* Back on our own heap */
813  pool_get (sm->gauges, gauge);
814  gauge->fn = update_fn;
815  gauge->caller_index = caller_index;
816  gauge->directory_index = vector_index;
817 
818  return NULL;
819 }
820 
821 clib_error_t *
823 {
825  stat_segment_shared_header_t *shared_header = sm->shared_header;
826  void *oldheap;
828 
829  ASSERT (shared_header);
830  ASSERT (vlib_get_thread_index () == 0);
831 
832  u32 vector_index = lookup_hash_index (name);
833 
834  if (vector_index != STAT_SEGMENT_INDEX_INVALID) /* Already registered */
835  return clib_error_return (0, "%v is already registered", name);
836 
837  memset (&e, 0, sizeof (e));
839  memcpy (e.name, name, vec_len (name));
840 
841  oldheap = vlib_stats_push_heap (NULL);
843 
844  vector_index = vlib_stats_create_counter (&e, oldheap);
845 
846  shared_header->directory_vector = sm->directory_vector;
847 
849  clib_mem_set_heap (oldheap);
850 
851  *index = vector_index;
852  return 0;
853 }
854 
855 clib_error_t *
857 {
859  stat_segment_shared_header_t *shared_header = sm->shared_header;
861  void *oldheap;
862 
863  ASSERT (shared_header);
864 
865  if (index > vec_len (sm->directory_vector))
866  return clib_error_return (0, "%u index does not exist", index);
867 
868  e = &sm->directory_vector[index];
870  return clib_error_return (0, "%u index cannot be deleted", index);
871 
872  oldheap = vlib_stats_push_heap (NULL);
874 
875  vlib_stats_delete_counter (index, oldheap);
876 
878  clib_mem_set_heap (oldheap);
879 
880  return 0;
881 }
882 
883 void
885 {
887 
888  ASSERT (index < vec_len (sm->directory_vector));
890 }
891 
892 static clib_error_t *
894 {
896  sm->update_interval = 10.0;
897 
899  {
900  if (unformat (input, "socket-name %s", &sm->socket_name))
901  ;
902  /* DEPRECATE: default (does nothing) */
903  else if (unformat (input, "default"))
904  ;
905  else if (unformat (input, "size %U",
907  ;
908  else if (unformat (input, "per-node-counters on"))
909  sm->node_counters_enabled = 1;
910  else if (unformat (input, "per-node-counters off"))
911  sm->node_counters_enabled = 0;
912  else if (unformat (input, "update-interval %f", &sm->update_interval))
913  ;
914  else
915  return clib_error_return (0, "unknown input `%U'",
916  format_unformat_error, input);
917  }
918 
919  /*
920  * NULL-terminate socket name string
921  * clib_socket_init()->socket_config() use C str*
922  */
923  if (vec_len (sm->socket_name))
925 
926  return 0;
927 }
928 
930 
931 static clib_error_t *
933 {
935 
936  void *oldheap = vlib_stats_push_heap (sm->interfaces);
938 
939  vec_validate (sm->interfaces, sw_if_index);
940  if (is_add)
941  {
942  vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
943  vnet_sw_interface_t *si_sup =
945  vnet_hw_interface_t *hi_sup;
946 
948  hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index);
949 
950  u8 *s = 0;
951  s = format (s, "%v", hi_sup->name);
953  s = format (s, ".%d", si->sub.id);
954  s = format (s, "%c", 0);
955  sm->interfaces[sw_if_index] = s;
956  }
957  else
958  {
959  vec_free (sm->interfaces[sw_if_index]);
960  sm->interfaces[sw_if_index] = 0;
961  }
962 
965  ep->data = sm->interfaces;
966 
968  clib_mem_set_heap (oldheap);
969 
970  return 0;
971 }
972 
974 
975 /* *INDENT-OFF* */
977 {
979 .name = "statseg-collector-process",
980 .type = VLIB_NODE_TYPE_PROCESS,
981 };
982 
983 /* *INDENT-ON* */
984 
985 /*
986  * fd.io coding-style-patch-verification: ON
987  *
988  * Local Variables:
989  * eval: (c-set-style "gnu")
990  * End:
991  */
static clib_error_t * statseg_config(vlib_main_t *vm, unformat_input_t *input)
Definition: stat_segment.c:893
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:509
static void stat_set_simple_counter(stat_segment_directory_entry_t *ep, u32 thread_index, u32 index, u64 value)
Definition: stat_segment.c:281
void vlib_node_get_nodes(vlib_main_t *vm, u32 max_threads, int include_stats, int barrier_sync, vlib_node_t ****node_dupsp, vlib_main_t ***stat_vmsp)
Get list of nodes.
Definition: node.c:544
uword bytes_total
Definition: mem.h:295
#define hash_set(h, key, value)
Definition: hash.h:255
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
Definition: lock.h:119
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Definition: lock.h:80
void vlib_stats_pop_heap2(u64 *error_vector, u32 thread_index, void *oldheap, int lock)
Definition: stat_segment.c:291
stat_segment_gauges_pool_t * gauges
Definition: stat_segment.h:80
#define hash_unset(h, key)
Definition: hash.h:261
static u64 vnet_get_aggregate_rx_packets(void)
Definition: devices.h:98
stat_segment_shared_header_t * shared_header
Definition: stat_segment.h:99
uint64_t index
static clib_error_t * stats_socket_accept_ready(clib_file_t *uf)
Definition: stat_segment.c:681
stat_segment_main_t stat_segment_main
Definition: stat_segment.c:27
stat_segment_directory_entry_t * directory_vector
Definition: stat_segment.h:84
unsigned long u64
Definition: types.h:89
u32 index
Definition: node.h:279
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:333
static void stat_validate_counter_vector(stat_segment_directory_entry_t *ep, u32 max)
Definition: stat_segment.c:266
static int memfd_create(const char *name, unsigned int flags)
Definition: syscall.h:52
#define STAT_SEGMENT_DEFAULT_SIZE
Definition: stat_segment.h:62
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define vec_terminate_c_string(V)
(If necessary) NULL terminate a vector containing a c-string.
Definition: vec.h:1090
void * vlib_stats_push_heap(void *old)
Definition: stat_segment.c:53
clib_error_t * clib_socket_init(clib_socket_t *s)
Definition: socket.c:384
static void usage(void)
Definition: health_check.c:14
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
vlib_main_t * vm
Definition: in2out_ed.c:1582
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
#define foreach_stat_segment_counter_name
Definition: stat_segment.h:43
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:520
#define vec_foreach_index_backwards(var, v)
Iterate over vector indices (reverse).
void * data
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:252
vlib_main_t ** vlib_mains
Definition: buffer.c:332
uword bytes_used
Definition: mem.h:295
unsigned char u8
Definition: types.h:56
void(* stat_segment_update_fn)(stat_segment_directory_entry_t *e, u32 i)
Definition: stat_segment.h:69
clib_file_function_t * read_function
Definition: file.h:67
double f64
Definition: types.h:142
uword value[0]
Definition: hash.h:165
static void create_hash_index(u8 *name, u32 index)
Definition: stat_segment.c:82
#define CLIB_SOCKET_F_IS_SERVER
Definition: socket.h:58
static u32 vlib_stats_get_next_vector_index()
Definition: stat_segment.c:93
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
Definition: node_funcs.h:482
DLMALLOC_EXPORT mspace create_mspace_with_base(void *base, size_t capacity, int locked)
vlib_node_stats_t stats_last_clear
Definition: node.h:273
uint64_t value
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:513
static void do_stat_segment_updates(stat_segment_main_t *sm)
Definition: stat_segment.c:586
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
static u32 vlib_stats_create_counter(stat_segment_directory_entry_t *e, void *oldheap)
Definition: stat_segment.c:112
void vlib_stats_pop_heap(void *cm_arg, void *oldheap, u32 cindex, stat_directory_type_t type)
Definition: stat_segment.c:186
static char * vlib_unix_get_runtime_dir(void)
Definition: unix.h:141
static clib_error_t * clib_socket_sendmsg(clib_socket_t *s, void *msg, int msglen, int fds[], int num_fds)
Definition: socket.h:151
uint64_t counter_t
64bit counters
Definition: counter_types.h:22
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static vnet_sw_interface_t * vnet_get_sup_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
#define clib_error_return(e, args...)
Definition: error.h:99
clib_file_main_t file_main
Definition: main.c:63
#define hash_get_pair(h, key)
Definition: hash.h:252
stat_segment_update_fn fn
Definition: stat_segment.h:73
unsigned int u32
Definition: types.h:88
static clib_error_t * statseg_init(vlib_main_t *vm)
Definition: stat_segment.c:764
A collection of simple counters.
Definition: counter.h:57
static u32 lookup_hash_index(u8 *name)
Definition: stat_segment.c:63
static clib_error_t * stats_segment_socket_init(void)
Definition: stat_segment.c:704
#define hash_create_string(elts, value_bytes)
Definition: hash.h:690
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:63
char * name
The counter collection&#39;s name.
Definition: counter.h:64
vl_api_fib_path_type_t type
Definition: fib_types.api:123
u8 * format_mheap(u8 *s, va_list *va)
Definition: mem_dlmalloc.c:404
static void vlib_stats_delete_counter(u32 index, void *oldheap)
Definition: stat_segment.c:131
vnet_crypto_main_t * cm
Definition: quic_crypto.c:53
vlib_node_stats_t stats_total
Definition: node.h:269
vnet_sub_interface_t sub
Definition: interface.h:758
clib_error_t * clib_socket_accept(clib_socket_t *server, clib_socket_t *client)
Definition: socket.c:526
stat_directory_type_t
f64 time_last_runtime_stats_clear
Definition: node.h:743
static clib_error_t * clib_socket_close(clib_socket_t *sock)
Definition: socket.h:175
static u8 * format_stat_dir_entry(u8 *s, va_list *args)
Definition: stat_segment.c:397
void vlib_stat_segment_unlock(void)
Definition: stat_segment.c:41
DLMALLOC_EXPORT void mspace_disable_expand(mspace msp)
struct _unformat_input_t unformat_input_t
u64 memory_size
Definition: vhost_user.h:105
static clib_error_t * stats_segment_socket_exit(vlib_main_t *vm)
Definition: stat_segment.c:730
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:429
#define PREDICT_FALSE(x)
Definition: clib.h:120
#define always_inline
Definition: ipsec.h:28
u8 * name
Definition: node.h:263
volatile uint64_t ** error_vector
#define VLIB_EARLY_CONFIG_FUNCTION(x, n,...)
Definition: init.h:226
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
svmdb_client_t * c
clib_error_t * stat_segment_register_gauge(u8 *name, stat_segment_update_fn update_fn, u32 caller_index)
Definition: stat_segment.c:783
static_always_inline uword vlib_get_thread_index(void)
Definition: threads.h:219
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
static void vlib_clear_internal_node_vector_rate(vlib_main_t *vm)
Definition: main.h:418
#define VLIB_MAIN_LOOP_EXIT_FUNCTION(x)
Definition: init.h:178
static void * clib_mem_set_heap(void *heap)
Definition: mem.h:268
static vlib_node_registration_t stat_segment_collector
(constructor) VLIB_REGISTER_NODE (stat_segment_collector)
Definition: stat_segment.c:976
void vlib_stat_segment_lock(void)
Definition: stat_segment.c:33
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(statseg_sw_interface_add_del)
#define STAT_SEGMENT_SOCKET_FILENAME
Definition: stat_client.h:33
string name[64]
Definition: ip.api:44
static void * clib_mem_get_heap(void)
Definition: mem.h:262
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:158
char name[128]
clib_error_t * stat_segment_deregister_state_counter(u32 index)
Definition: stat_segment.c:856
u8 value
Definition: qos.api:54
#define ASSERT(truth)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:696
static uword clib_file_add(clib_file_main_t *um, clib_file_t *template)
Definition: file.h:96
f64 vlib_get_stat_segment_update_rate(void)
Definition: stat_segment.c:744
volatile stat_segment_directory_entry_t * directory_vector
#define clib_error_report(e)
Definition: error.h:113
struct _socket_t clib_socket_t
static void * clib_mem_alloc(uword size)
Definition: mem.h:157
#define CLIB_SOCKET_F_SEQPACKET
Definition: socket.h:63
#define STAT_SEGMENT_VERSION
Definition: stat_segment.h:65
volatile u64 ** error_vector
Definition: stat_segment.h:85
static uword stat_segment_collector_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: stat_segment.c:750
void mheap_usage(void *heap, clib_mem_usage_t *usage)
Definition: mem_dlmalloc.c:437
uword * directory_vector_by_name
Definition: stat_segment.h:83
char * stat_segment_name
Name in stat segment directory.
Definition: counter.h:65
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vlib_node_main_t node_main
Definition: main.h:189
#define CLIB_SOCKET_F_PASSCRED
Definition: socket.h:64
u64 uword
Definition: types.h:112
static void update_node_counters(stat_segment_main_t *sm)
Definition: stat_segment.c:498
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:1055
u32 index
Definition: flow_types.api:221
static int name_sort_cmp(void *a1, void *a2)
Definition: stat_segment.c:388
static clib_error_t * statseg_sw_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
Definition: stat_segment.c:932
static clib_error_t * show_stat_segment_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: stat_segment.c:438
unformat_function_t unformat_memory_size
Definition: format.h:296
clib_socket_t * socket
Definition: stat_segment.h:93
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
counter_t ** counters
Per-thread u64 non-atomic counters.
Definition: counter.h:59
vnet_sw_interface_type_t type
Definition: interface.h:736
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
Definition: file.h:51
u8 si
Definition: lisp_types.api:47
void vlib_stats_delete_cm(void *cm_arg)
Definition: stat_segment.c:155
void vlib_stats_register_error_index(void *oldheap, u8 *name, u64 *em_vec, u64 index)
Definition: stat_segment.c:235
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
#define CLIB_SOCKET_F_ALLOW_GROUP_WRITE
Definition: socket.h:62
clib_error_t * vlib_map_stat_segment_init(void)
Definition: stat_segment.c:315
static f64 vlib_internal_node_vector_rate(vlib_main_t *vm)
Definition: main.h:402
#define VLIB_INITS(...)
Definition: init.h:357
#define STAT_SEGMENT_INDEX_INVALID
Definition: stat_segment.h:67
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:33
clib_error_t * stat_segment_register_state_counter(u8 *name, u32 *index)
Definition: stat_segment.c:822
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
void stat_segment_set_state_counter(u32 index, u64 value)
Definition: stat_segment.c:884
clib_spinlock_t * stat_segment_lockp
Definition: stat_segment.h:92
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
stat_directory_type_t type