FD.io VPP  v21.01.1
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 
27 
28 /*
29  * Used only by VPP writers
30  */
31 void
33 {
36  sm->shared_header->in_progress = 1;
37 }
38 
39 void
41 {
43  sm->shared_header->epoch++;
44  sm->shared_header->in_progress = 0;
46 }
47 
48 /*
49  * Change heap to the stats shared memory segment
50  */
51 void *
53 {
55 
56  sm->last = old;
57  ASSERT (sm && sm->shared_header);
58  return clib_mem_set_heap (sm->heap);
59 }
60 
61 static u32
63 {
66  hash_pair_t *hp;
67 
68  /* Must be called in the context of the main heap */
69  ASSERT (clib_mem_get_heap () != sm->heap);
70 
71  hp = hash_get_pair (sm->directory_vector_by_name, name);
72  if (hp)
73  {
74  index = hp->value[0];
75  }
76 
77  return index;
78 }
79 
80 static void
82 {
84 
85  /* Must be called in the context of the main heap */
86  ASSERT (clib_mem_get_heap () != sm->heap);
87 
88  hash_set (sm->directory_vector_by_name, format (0, "%s%c", name, 0), index);
89 }
90 
91 static u32
93 {
95  u32 next_vector_index = vec_len (sm->directory_vector);
96 
97  ssize_t i;
99  {
101  {
102  next_vector_index = i;
103  break;
104  }
105  }
106 
107  return next_vector_index;
108 }
109 
110 static u32
112 {
114 
115  ASSERT (clib_mem_get_heap () == sm->heap);
116 
118 
119  clib_mem_set_heap (oldheap);
120  create_hash_index ((u8 *) e->name, index);
121  clib_mem_set_heap (sm->heap);
122 
123  vec_validate (sm->directory_vector, index);
124  sm->directory_vector[index] = *e;
125 
126  return index;
127 }
128 
129 static void
131 {
134 
135  ASSERT (clib_mem_get_heap () == sm->heap);
136 
137  if (index > vec_len (sm->directory_vector))
138  return;
139 
140  e = &sm->directory_vector[index];
141 
142  clib_mem_set_heap (oldheap);
144  clib_mem_set_heap (sm->heap);
145 
146  memset (e, 0, sizeof (*e));
148 }
149 
150 /*
151  * Called from main heap
152  */
153 void
154 vlib_stats_delete_cm (void *cm_arg)
155 {
159 
160  /* Not all counters have names / hash-table entries */
161  if (!cm->name && !cm->stat_segment_name)
162  {
163  return;
164  }
166 
167  /* Lookup hash-table is on the main heap */
168  char *stat_segment_name =
169  cm->stat_segment_name ? cm->stat_segment_name : cm->name;
170  u32 index = lookup_hash_index ((u8 *) stat_segment_name);
171 
172  e = &sm->directory_vector[index];
174 
175  void *oldheap = clib_mem_set_heap (sm->heap); /* Enter stats segment */
176  clib_mem_set_heap (oldheap); /* Exit stats segment */
177 
178  memset (e, 0, sizeof (*e));
180 
182 }
183 
184 void
185 vlib_stats_pop_heap (void *cm_arg, void *oldheap, u32 cindex,
187 {
190  stat_segment_shared_header_t *shared_header = sm->shared_header;
191  char *stat_segment_name;
193 
194  /* Not all counters have names / hash-table entries */
195  if (!cm->name && !cm->stat_segment_name)
196  {
197  clib_mem_set_heap (oldheap);
198  return;
199  }
200 
201  ASSERT (shared_header);
202 
204 
205  /* Lookup hash-table is on the main heap */
206  stat_segment_name =
207  cm->stat_segment_name ? cm->stat_segment_name : cm->name;
208 
209  clib_mem_set_heap (oldheap); /* Exit stats segment */
210  u32 vector_index = lookup_hash_index ((u8 *) stat_segment_name);
211  /* Back to stats segment */
212  clib_mem_set_heap (sm->heap); /* Re-enter stat segment */
213 
214 
215  /* Update the vector */
216  if (vector_index == STAT_SEGMENT_INDEX_INVALID)
217  { /* New */
218  strncpy (e.name, stat_segment_name, 128 - 1);
219  e.type = type;
220  vector_index = vlib_stats_create_counter (&e, oldheap);
221  }
222 
223  stat_segment_directory_entry_t *ep = &sm->directory_vector[vector_index];
224  ep->data = cm->counters;
225 
226  /* Reset the client hash table pointer, since it WILL change! */
227  shared_header->directory_vector = sm->directory_vector;
228 
230  clib_mem_set_heap (oldheap);
231 }
232 
233 void
234 vlib_stats_register_error_index (void *oldheap, u8 * name, u64 * em_vec,
235  u64 index)
236 {
238  stat_segment_shared_header_t *shared_header = sm->shared_header;
240 
241  ASSERT (shared_header);
242 
244  clib_mem_set_heap (oldheap); /* Exit stats segment */
245  u32 vector_index = lookup_hash_index (name);
246  /* Back to stats segment */
247  clib_mem_set_heap (sm->heap); /* Re-enter stat segment */
248 
249  if (vector_index == STAT_SEGMENT_INDEX_INVALID)
250  {
251  memcpy (e.name, name, vec_len (name));
252  e.name[vec_len (name)] = '\0';
254  e.index = index;
255  vector_index = vlib_stats_create_counter (&e, oldheap);
256 
257  /* Warn clients to refresh any pointers they might be holding */
258  shared_header->directory_vector = sm->directory_vector;
259  }
260 
262 }
263 
264 static void
266 {
267  counter_t **counters = ep->data;
269  int i;
270 
271  vec_validate_aligned (counters, tm->n_vlib_mains - 1,
273  for (i = 0; i < tm->n_vlib_mains; i++)
274  vec_validate_aligned (counters[i], max, CLIB_CACHE_LINE_BYTES);
275 
276  ep->data = counters;
277 }
278 
279 always_inline void
281  u32 thread_index, u32 index, u64 value)
282 {
283  ASSERT (ep->data);
284  counter_t **counters = ep->data;
285  counter_t *cb = counters[thread_index];
286  cb[index] = value;
287 }
288 
289 void
290 vlib_stats_pop_heap2 (u64 * error_vector, u32 thread_index, void *oldheap,
291  int lock)
292 {
294  stat_segment_shared_header_t *shared_header = sm->shared_header;
295 
296  ASSERT (shared_header);
297 
298  if (lock)
300 
301  /* Reset the client hash table pointer, since it WILL change! */
302  vec_validate (sm->error_vector, thread_index);
303  sm->error_vector[thread_index] = error_vector;
304 
305  shared_header->error_vector = sm->error_vector;
306  shared_header->directory_vector = sm->directory_vector;
307 
308  if (lock)
310  clib_mem_set_heap (oldheap);
311 }
312 
313 clib_error_t *
315 {
317  stat_segment_shared_header_t *shared_header;
318  void *oldheap;
319  uword memory_size, sys_page_sz;
320  int mfd;
321  char *mem_name = "stat segment";
322  void *heap, *memaddr;
323 
324  memory_size = sm->memory_size;
325  if (memory_size == 0)
326  memory_size = STAT_SEGMENT_DEFAULT_SIZE;
327 
330 
331  mfd = clib_mem_vm_create_fd (sm->log2_page_sz, mem_name);
332 
333  if (mfd == -1)
334  return clib_error_return (0, "stat segment memory fd failure: %U",
336  /* Set size */
337  if ((ftruncate (mfd, memory_size)) == -1)
338  return clib_error_return (0, "stat segment ftruncate failure");
339 
340  memaddr = clib_mem_vm_map_shared (0, memory_size, mfd, 0, mem_name);
341 
342  if (memaddr == CLIB_MEM_VM_MAP_FAILED)
343  return clib_error_return (0, "stat segment mmap failure");
344 
345  sys_page_sz = clib_mem_get_page_size ();
346 
347  heap = clib_mem_create_heap (((u8 *) memaddr) + sys_page_sz, memory_size
348  - sys_page_sz, 1 /* locked */ ,
349  "stat segment");
350  sm->heap = heap;
351  sm->memfd = mfd;
352 
354  sm->shared_header = shared_header = memaddr;
355 
356  shared_header->version = STAT_SEGMENT_VERSION;
357  shared_header->base = memaddr;
358 
361 
362  oldheap = clib_mem_set_heap (sm->heap);
363 
364  /* Set up the name to counter-vector hash table */
365  sm->directory_vector = 0;
366 
367  shared_header->epoch = 1;
368 
369  /* Scalar stats and node counters */
371 #define _(E,t,n,p) \
372  strcpy(sm->directory_vector[STAT_COUNTER_##E].name, #p "/" #n); \
373  sm->directory_vector[STAT_COUNTER_##E].type = STAT_DIR_TYPE_##t;
375 #undef _
376  /* Save the vector in the shared segment, for clients */
377  shared_header->directory_vector = sm->directory_vector;
378 
379  clib_mem_set_heap (oldheap);
380 
381  /* Total shared memory size */
383  clib_mem_get_heap_usage (sm->heap, &usage);
385  usage.bytes_total;
386 
387  return 0;
388 }
389 
390 static int
391 name_sort_cmp (void *a1, void *a2)
392 {
395 
396  return strcmp ((char *) n1->name, (char *) n2->name);
397 }
398 
399 static u8 *
400 format_stat_dir_entry (u8 * s, va_list * args)
401 {
403  va_arg (*args, stat_segment_directory_entry_t *);
404  char *type_name;
405  char *format_string;
406 
407  format_string = "%-74s %-10s %10lld";
408 
409  switch (ep->type)
410  {
412  type_name = "ScalarPtr";
413  break;
414 
417  type_name = "CMainPtr";
418  break;
419 
421  type_name = "ErrIndex";
422  break;
423 
425  type_name = "NameVector";
426  break;
427 
428  case STAT_DIR_TYPE_EMPTY:
429  type_name = "empty";
430  break;
431 
432  default:
433  type_name = "illegal!";
434  break;
435  }
436 
437  return format (s, format_string, ep->name, type_name, 0);
438 }
439 
440 static clib_error_t *
442  unformat_input_t * input,
443  vlib_cli_command_t * cmd)
444 {
447  int i;
448 
449  int verbose = 0;
450 
451  if (unformat (input, "verbose"))
452  verbose = 1;
453 
454  /* Lock even as reader, as this command doesn't handle epoch changes */
456  show_data = vec_dup (sm->directory_vector);
458 
460 
461  vlib_cli_output (vm, "%-74s %10s %10s", "Name", "Type", "Value");
462 
463  for (i = 0; i < vec_len (show_data); i++)
464  {
466 
467  if (ep->type == STAT_DIR_TYPE_EMPTY)
468  continue;
469 
470  vlib_cli_output (vm, "%-100U", format_stat_dir_entry,
471  vec_elt_at_index (show_data, i));
472  }
473 
474  if (verbose)
475  {
476  ASSERT (sm->heap);
477  vlib_cli_output (vm, "%U", format_clib_mem_heap, sm->heap,
478  0 /* verbose */ );
479  }
480 
481  return 0;
482 }
483 
484 /* *INDENT-OFF* */
485 VLIB_CLI_COMMAND (show_stat_segment_command, static) =
486 {
487  .path = "show statistics segment",
488  .short_help = "show statistics segment [verbose]",
489  .function = show_stat_segment_command_fn,
490 };
491 /* *INDENT-ON* */
492 
493 /*
494  * Node performance counters:
495  * total_calls [threads][node-index]
496  * total_vectors
497  * total_calls
498  * total suspends
499  */
500 
501 static inline void
503 {
504  vlib_main_t **stat_vms = 0;
505  vlib_node_t ***node_dups = 0;
506  int i, j;
507  static u32 no_max_nodes = 0;
508 
509  vlib_node_get_nodes (0 /* vm, for barrier sync */ ,
510  (u32) ~ 0 /* all threads */ ,
511  1 /* include stats */ ,
512  0 /* barrier sync */ ,
513  &node_dups, &stat_vms);
514 
515  u32 l = vec_len (node_dups[0]);
516 
517  /*
518  * Extend performance nodes if necessary
519  */
520  if (l > no_max_nodes)
521  {
522  void *oldheap = clib_mem_set_heap (sm->heap);
524 
526  [STAT_COUNTER_NODE_CLOCKS], l - 1);
528  [STAT_COUNTER_NODE_VECTORS], l - 1);
530  [STAT_COUNTER_NODE_CALLS], l - 1);
532  [STAT_COUNTER_NODE_SUSPENDS], l - 1);
533 
534  vec_validate (sm->nodes, l - 1);
537  ep->data = sm->nodes;
538 
539  /* Update names dictionary */
540  vlib_node_t **nodes = node_dups[0];
541  int i;
542  for (i = 0; i < vec_len (nodes); i++)
543  {
544  vlib_node_t *n = nodes[i];
545  u8 *s = 0;
546  s = format (s, "%v%c", n->name, 0);
547  if (sm->nodes[n->index])
548  vec_free (sm->nodes[n->index]);
549  sm->nodes[n->index] = s;
550  }
552  clib_mem_set_heap (oldheap);
553  no_max_nodes = l;
554  }
555 
556  for (j = 0; j < vec_len (node_dups); j++)
557  {
558  vlib_node_t **nodes = node_dups[j];
559 
560  for (i = 0; i < vec_len (nodes); i++)
561  {
562  counter_t **counters;
563  counter_t *c;
564  vlib_node_t *n = nodes[i];
565 
567  c = counters[j];
569 
571  c = counters[j];
573 
575  c = counters[j];
576  c[n->index] = n->stats_total.calls - n->stats_last_clear.calls;
577 
579  c = counters[j];
580  c[n->index] =
582  }
583  vec_free (node_dups[j]);
584  }
585  vec_free (node_dups);
586  vec_free (stat_vms);
587 }
588 
589 static void
591 {
592  vlib_main_t *vm = vlib_mains[0];
593  f64 vector_rate;
594  u64 input_packets;
595  f64 dt, now;
596  vlib_main_t *this_vlib_main;
597  int i;
598  static int num_worker_threads_set;
599 
600  /*
601  * Set once at the beginning of time.
602  * Can't do this from the init routine, which happens before
603  * start_workers sets up vlib_mains...
604  */
605  if (PREDICT_FALSE (num_worker_threads_set == 0))
606  {
607  void *oldheap = clib_mem_set_heap (sm->heap);
609 
612  num_worker_threads_set = 1;
614  clib_mem_set_heap (oldheap);
615  }
616 
617  /*
618  * Compute per-worker vector rates, and the average vector rate
619  * across all workers
620  */
621  vector_rate = 0.0;
622 
623  for (i = 0; i < vec_len (vlib_mains); i++)
624  {
625 
626  f64 this_vector_rate;
627 
628  this_vlib_main = vlib_mains[i];
629 
630  this_vector_rate = vlib_internal_node_vector_rate (this_vlib_main);
631  vlib_clear_internal_node_vector_rate (this_vlib_main);
632 
633  vector_rate += this_vector_rate;
634 
635  /* Set the per-worker rate */
638  this_vector_rate);
639  }
640 
641  /* And set the system average rate */
642  vector_rate /= (f64) (i > 1 ? i - 1 : 1);
643 
645 
646  /*
647  * Compute the aggregate input rate
648  */
649  now = vlib_time_now (vm);
651  input_packets = vnet_get_aggregate_rx_packets ();
653  (f64) (input_packets - sm->last_input_packets) / dt;
655  sm->last_input_packets = input_packets;
658 
659  /* Stats segment memory heap counter */
661  clib_mem_get_heap_usage (sm->heap, &usage);
663  usage.bytes_used;
664 
665  if (sm->node_counters_enabled)
667 
668  /* *INDENT-OFF* */
670  pool_foreach (g, sm->gauges)
671  {
673  }
674  /* *INDENT-ON* */
675 
676  /* Heartbeat, so clients detect we're still here */
678 }
679 
680 /*
681  * Accept connection on the socket and exchange the fd for the shared
682  * memory segment.
683  */
684 static clib_error_t *
686 {
688  clib_error_t *err;
689  clib_socket_t client = { 0 };
690 
691  err = clib_socket_accept (sm->socket, &client);
692  if (err)
693  {
694  clib_error_report (err);
695  return err;
696  }
697 
698  /* Send the fd across and close */
699  err = clib_socket_sendmsg (&client, 0, 0, &sm->memfd, 1);
700  if (err)
701  clib_error_report (err);
702  clib_socket_close (&client);
703 
704  return 0;
705 }
706 
707 static clib_error_t *
709 {
713 
714  memset (s, 0, sizeof (clib_socket_t));
715  s->config = (char *) sm->socket_name;
718 
719  if ((error = clib_socket_init (s)))
720  return error;
721 
722  clib_file_t template = { 0 };
724  template.file_descriptor = s->fd;
725  template.description = format (0, "stats segment listener %s", s->config);
726  clib_file_add (&file_main, &template);
727 
728  sm->socket = s;
729 
730  return 0;
731 }
732 
733 static clib_error_t *
735 {
736  /*
737  * cleanup the listener socket on exit.
738  */
740  unlink ((char *) sm->socket_name);
741  return 0;
742 }
743 
745 
746 /* Overrides weak reference in vlib:node_cli.c */
747 f64
749 {
750  return stat_segment_main.update_interval;
751 }
752 
753 static uword
755  vlib_frame_t * f)
756 {
758 
759  while (1)
760  {
763  }
764  return 0; /* or not */
765 }
766 
767 static clib_error_t *
769 {
771 
772  /* set default socket file name when statseg config stanza is empty. */
773  if (!vec_len (sm->socket_name))
774  sm->socket_name = format (0, "%s/%s%c", vlib_unix_get_runtime_dir (),
776  return stats_segment_socket_init ();
777 }
778 
779 /* *INDENT-OFF* */
781 {
782  .runs_after = VLIB_INITS("unix_input_init"),
783 };
784 /* *INDENT-ON* */
785 
786 clib_error_t *
788  u32 caller_index)
789 {
791  stat_segment_shared_header_t *shared_header = sm->shared_header;
792  void *oldheap;
795 
796  ASSERT (shared_header);
797 
798  u32 vector_index = lookup_hash_index (name);
799 
800  if (vector_index != STAT_SEGMENT_INDEX_INVALID) /* Already registered */
801  return clib_error_return (0, "%v is already registered", name);
802 
803  memset (&e, 0, sizeof (e));
805  memcpy (e.name, name, vec_len (name));
806 
807  oldheap = vlib_stats_push_heap (NULL);
809  vector_index = vlib_stats_create_counter (&e, oldheap);
810 
811  shared_header->directory_vector = sm->directory_vector;
812 
814  clib_mem_set_heap (oldheap);
815 
816  /* Back on our own heap */
817  pool_get (sm->gauges, gauge);
818  gauge->fn = update_fn;
819  gauge->caller_index = caller_index;
820  gauge->directory_index = vector_index;
821 
822  return NULL;
823 }
824 
825 clib_error_t *
827 {
829  stat_segment_shared_header_t *shared_header = sm->shared_header;
830  void *oldheap;
832 
833  ASSERT (shared_header);
834  ASSERT (vlib_get_thread_index () == 0);
835 
836  u32 vector_index = lookup_hash_index (name);
837 
838  if (vector_index != STAT_SEGMENT_INDEX_INVALID) /* Already registered */
839  return clib_error_return (0, "%v is already registered", name);
840 
841  memset (&e, 0, sizeof (e));
843  memcpy (e.name, name, vec_len (name));
844 
845  oldheap = vlib_stats_push_heap (NULL);
847 
848  vector_index = vlib_stats_create_counter (&e, oldheap);
849 
850  shared_header->directory_vector = sm->directory_vector;
851 
853  clib_mem_set_heap (oldheap);
854 
855  *index = vector_index;
856  return 0;
857 }
858 
859 clib_error_t *
861 {
863  stat_segment_shared_header_t *shared_header = sm->shared_header;
865  void *oldheap;
866 
867  ASSERT (shared_header);
868 
869  if (index > vec_len (sm->directory_vector))
870  return clib_error_return (0, "%u index does not exist", index);
871 
872  e = &sm->directory_vector[index];
874  return clib_error_return (0, "%u index cannot be deleted", index);
875 
876  oldheap = vlib_stats_push_heap (NULL);
878 
879  vlib_stats_delete_counter (index, oldheap);
880 
882  clib_mem_set_heap (oldheap);
883 
884  return 0;
885 }
886 
887 void
889 {
891 
892  ASSERT (index < vec_len (sm->directory_vector));
894 }
895 
896 static clib_error_t *
898 {
900  sm->update_interval = 10.0;
901 
903  {
904  if (unformat (input, "socket-name %s", &sm->socket_name))
905  ;
906  /* DEPRECATE: default (does nothing) */
907  else if (unformat (input, "default"))
908  ;
909  else if (unformat (input, "size %U",
911  ;
912  else if (unformat (input, "page-size %U",
914  ;
915  else if (unformat (input, "per-node-counters on"))
916  sm->node_counters_enabled = 1;
917  else if (unformat (input, "per-node-counters off"))
918  sm->node_counters_enabled = 0;
919  else if (unformat (input, "update-interval %f", &sm->update_interval))
920  ;
921  else
922  return clib_error_return (0, "unknown input `%U'",
923  format_unformat_error, input);
924  }
925 
926  /*
927  * NULL-terminate socket name string
928  * clib_socket_init()->socket_config() use C str*
929  */
930  if (vec_len (sm->socket_name))
932 
933  return 0;
934 }
935 
937 
938 static clib_error_t *
940 {
942 
943  void *oldheap = vlib_stats_push_heap (sm->interfaces);
945 
946  vec_validate (sm->interfaces, sw_if_index);
947  if (is_add)
948  {
949  vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
950  vnet_sw_interface_t *si_sup =
952  vnet_hw_interface_t *hi_sup;
953 
955  hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index);
956 
957  u8 *s = 0;
958  s = format (s, "%v", hi_sup->name);
960  s = format (s, ".%d", si->sub.id);
961  s = format (s, "%c", 0);
962  sm->interfaces[sw_if_index] = s;
963  }
964  else
965  {
966  vec_free (sm->interfaces[sw_if_index]);
967  sm->interfaces[sw_if_index] = 0;
968  }
969 
972  ep->data = sm->interfaces;
973 
975  clib_mem_set_heap (oldheap);
976 
977  return 0;
978 }
979 
981 
982 /* *INDENT-OFF* */
984 {
986 .name = "statseg-collector-process",
987 .type = VLIB_NODE_TYPE_PROCESS,
988 };
989 
990 /* *INDENT-ON* */
991 
992 /*
993  * fd.io coding-style-patch-verification: ON
994  *
995  * Local Variables:
996  * eval: (c-set-style "gnu")
997  * End:
998  */
static clib_error_t * statseg_config(vlib_main_t *vm, unformat_input_t *input)
Definition: stat_segment.c:897
#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:280
__clib_export int clib_mem_vm_create_fd(clib_mem_page_sz_t log2_page_size, char *fmt,...)
Definition: mem.c:264
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:534
uword bytes_total
Definition: mem.h:393
#define CLIB_MEM_VM_MAP_FAILED
Definition: mem.h:54
#define hash_set(h, key, value)
Definition: hash.h:255
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
Definition: lock.h:121
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Definition: lock.h:82
void vlib_stats_pop_heap2(u64 *error_vector, u32 thread_index, void *oldheap, int lock)
Definition: stat_segment.c:290
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:96
stat_segment_shared_header_t * shared_header
Definition: stat_segment.h:100
uint64_t index
static clib_error_t * stats_socket_accept_ready(clib_file_t *uf)
Definition: stat_segment.c:685
stat_segment_main_t stat_segment_main
Definition: stat_segment.c:26
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:527
void clib_mem_get_heap_usage(clib_mem_heap_t *heap, clib_mem_usage_t *usage)
Definition: mem_dlmalloc.c:473
clib_mem_heap_t * clib_mem_create_heap(void *base, uword size, int is_locked, char *fmt,...)
Definition: mem_dlmalloc.c:533
stat_segment_directory_entry_t * directory_vector
Definition: stat_segment.h:84
unsigned long u64
Definition: types.h:89
__clib_export void * clib_mem_vm_map_shared(void *base, uword size, int fd, uword offset, char *fmt,...)
Definition: mem.c:59
u32 index
Definition: node.h:280
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:334
static clib_mem_heap_t * clib_mem_set_heap(clib_mem_heap_t *heap)
Definition: mem.h:365
static void stat_validate_counter_vector(stat_segment_directory_entry_t *ep, u32 max)
Definition: stat_segment.c:265
#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:52
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:1580
#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:251
static_always_inline uword clib_mem_get_page_size(void)
Definition: mem.h:468
vlib_main_t ** vlib_mains
Definition: buffer.c:332
uword bytes_used
Definition: mem.h:393
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_export clib_error_t * clib_socket_init(clib_socket_t *s)
Definition: socket.c:384
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:81
#define CLIB_SOCKET_F_IS_SERVER
Definition: socket.h:58
static u32 vlib_stats_get_next_vector_index()
Definition: stat_segment.c:92
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
vlib_node_stats_t stats_last_clear
Definition: node.h:274
uint64_t value
static void do_stat_segment_updates(stat_segment_main_t *sm)
Definition: stat_segment.c:590
#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:111
void vlib_stats_pop_heap(void *cm_arg, void *oldheap, u32 cindex, stat_directory_type_t type)
Definition: stat_segment.c:185
static char * vlib_unix_get_runtime_dir(void)
Definition: unix.h:143
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
description fragment has unexpected format
Definition: map.api:433
#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:768
A collection of simple counters.
Definition: counter.h:57
static u32 lookup_hash_index(u8 *name)
Definition: stat_segment.c:62
static clib_error_t * stats_segment_socket_init(void)
Definition: stat_segment.c:708
#define hash_create_string(elts, value_bytes)
Definition: hash.h:690
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:65
char * name
The counter collection&#39;s name.
Definition: counter.h:64
vl_api_fib_path_type_t type
Definition: fib_types.api:123
static void vlib_stats_delete_counter(u32 index, void *oldheap)
Definition: stat_segment.c:130
vnet_crypto_main_t * cm
Definition: quic_crypto.c:53
Definition: cJSON.c:84
vlib_node_stats_t stats_total
Definition: node.h:270
vnet_sub_interface_t sub
Definition: interface.h:759
stat_directory_type_t
f64 time_last_runtime_stats_clear
Definition: node.h:744
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:400
void vlib_stat_segment_unlock(void)
Definition: stat_segment.c:40
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:734
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:429
#define PREDICT_FALSE(x)
Definition: clib.h:121
#define always_inline
Definition: ipsec.h:28
u8 * name
Definition: node.h:264
volatile uint64_t ** error_vector
#define VLIB_EARLY_CONFIG_FUNCTION(x, n,...)
Definition: init.h:226
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:170
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
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:787
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:419
__clib_export clib_error_t * clib_socket_accept(clib_socket_t *server, clib_socket_t *client)
Definition: socket.c:526
#define VLIB_MAIN_LOOP_EXIT_FUNCTION(x)
Definition: init.h:178
unformat_function_t unformat_log2_page_size
Definition: format.h:301
static vlib_node_registration_t stat_segment_collector
(constructor) VLIB_REGISTER_NODE (stat_segment_collector)
Definition: stat_segment.c:983
void vlib_stat_segment_lock(void)
Definition: stat_segment.c:32
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
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:158
static clib_mem_heap_t * clib_mem_get_heap(void)
Definition: mem.h:359
char name[128]
clib_error_t * stat_segment_deregister_state_counter(u32 index)
Definition: stat_segment.c:860
u8 value
Definition: qos.api:54
#define ASSERT(truth)
u8 * format_clib_mem_heap(u8 *s, va_list *va)
Definition: mem_dlmalloc.c:422
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:748
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:253
#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_always_inline clib_error_t * clib_mem_get_last_error(void)
Definition: mem.h:553
static uword stat_segment_collector_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: stat_segment.c:754
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:188
#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:502
#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:391
static clib_error_t * statseg_sw_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
Definition: stat_segment.c:939
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:441
unformat_function_t unformat_memory_size
Definition: format.h:295
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:737
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:154
void vlib_stats_register_error_index(void *oldheap, u8 *name, u64 *em_vec, u64 index)
Definition: stat_segment.c:234
#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:314
static f64 vlib_internal_node_vector_rate(vlib_main_t *vm)
Definition: main.h:403
__clib_export u8 * format_clib_error(u8 *s, va_list *va)
Definition: error.c:191
#define VLIB_INITS(...)
Definition: init.h:357
#define STAT_SEGMENT_INDEX_INVALID
Definition: stat_segment.h:67
clib_mem_page_sz_t log2_page_sz
Definition: stat_segment.h:96
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
clib_error_t * stat_segment_register_state_counter(u8 *name, u32 *index)
Definition: stat_segment.c:826
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:888
clib_spinlock_t * stat_segment_lockp
Definition: stat_segment.h:92
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170
stat_directory_type_t type