FD.io VPP  v19.08-27-gf4dcae4
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
63 lookup_or_create_hash_index (u8 * name, u32 next_vector_index)
64 {
66  u32 index;
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  /* we allocate our private copy of 'name' */
76  hash_set (sm->directory_vector_by_name, format (0, "%s%c", name, 0),
77  next_vector_index);
78  index = next_vector_index;
79  }
80  else
81  {
82  index = hp->value[0];
83  }
84 
85  return index;
86 }
87 
88 void
89 vlib_stats_pop_heap (void *cm_arg, void *oldheap, u32 cindex,
91 {
94  stat_segment_shared_header_t *shared_header = sm->shared_header;
95  char *stat_segment_name;
97 
98  /* Not all counters have names / hash-table entries */
99  if (!cm->name && !cm->stat_segment_name)
100  {
101  clib_mem_set_heap (oldheap);
102  return;
103  }
104 
105  ASSERT (shared_header);
106 
108 
109  /* Lookup hash-table is on the main heap */
110  stat_segment_name =
111  cm->stat_segment_name ? cm->stat_segment_name : cm->name;
112  u32 next_vector_index = vec_len (sm->directory_vector);
113  clib_mem_set_heap (oldheap); /* Exit stats segment */
114  u32 vector_index = lookup_or_create_hash_index ((u8 *) stat_segment_name,
115  next_vector_index);
116  /* Back to stats segment */
117  clib_mem_set_heap (sm->heap); /* Re-enter stat segment */
118 
119 
120  /* Update the vector */
121  if (vector_index == next_vector_index)
122  { /* New */
123  strncpy (e.name, stat_segment_name, 128 - 1);
124  e.type = type;
125  vec_add1 (sm->directory_vector, e);
126  }
127 
128  stat_segment_directory_entry_t *ep = &sm->directory_vector[vector_index];
129  ep->offset = stat_segment_offset (shared_header, cm->counters); /* Vector of threads of vectors of counters */
130  u64 *offset_vector =
131  ep->offset_vector ? stat_segment_pointer (shared_header,
132  ep->offset_vector) : 0;
133 
134  /* Update the 2nd dimension offset vector */
135  int i;
136  vec_validate (offset_vector, vec_len (cm->counters) - 1);
137 
138  if (sm->last != offset_vector)
139  {
140  for (i = 0; i < vec_len (cm->counters); i++)
141  offset_vector[i] =
142  stat_segment_offset (shared_header, cm->counters[i]);
143  }
144  else
145  offset_vector[cindex] =
146  stat_segment_offset (shared_header, cm->counters[cindex]);
147 
148  ep->offset_vector = stat_segment_offset (shared_header, offset_vector);
149  sm->directory_vector[vector_index].offset =
150  stat_segment_offset (shared_header, cm->counters);
151 
152  /* Reset the client hash table pointer, since it WILL change! */
153  shared_header->directory_offset =
154  stat_segment_offset (shared_header, sm->directory_vector);
155 
157  clib_mem_set_heap (oldheap);
158 }
159 
160 void
161 vlib_stats_register_error_index (void *oldheap, u8 * name, u64 * em_vec,
162  u64 index)
163 {
165  stat_segment_shared_header_t *shared_header = sm->shared_header;
167 
168  ASSERT (shared_header);
169 
171  u32 next_vector_index = vec_len (sm->directory_vector);
172  clib_mem_set_heap (oldheap); /* Exit stats segment */
173 
174  u32 vector_index = lookup_or_create_hash_index (name,
175  next_vector_index);
176 
177  /* Back to stats segment */
178  clib_mem_set_heap (sm->heap); /* Re-enter stat segment */
179 
180  if (next_vector_index == vector_index)
181  {
182  memcpy (e.name, name, vec_len (name));
183  e.name[vec_len (name)] = '\0';
185  e.offset = index;
186  e.offset_vector = 0;
187  vec_add1 (sm->directory_vector, e);
188 
189  /* Warn clients to refresh any pointers they might be holding */
190  shared_header->directory_offset =
191  stat_segment_offset (shared_header, sm->directory_vector);
192  }
193 
195 }
196 
197 static void
199 {
201  stat_segment_shared_header_t *shared_header = sm->shared_header;
202  counter_t **counters = 0;
204  int i;
205  u64 *offset_vector = 0;
206 
207  vec_validate_aligned (counters, tm->n_vlib_mains - 1,
209  for (i = 0; i < tm->n_vlib_mains; i++)
210  {
211  vec_validate_aligned (counters[i], max, CLIB_CACHE_LINE_BYTES);
212  vec_add1 (offset_vector,
213  stat_segment_offset (shared_header, counters[i]));
214  }
215  ep->offset = stat_segment_offset (shared_header, counters);
216  ep->offset_vector = stat_segment_offset (shared_header, offset_vector);
217 }
218 
219 void
220 vlib_stats_pop_heap2 (u64 * error_vector, u32 thread_index, void *oldheap,
221  int lock)
222 {
224  stat_segment_shared_header_t *shared_header = sm->shared_header;
225 
226  ASSERT (shared_header);
227 
228  if (lock)
230 
231  /* Reset the client hash table pointer, since it WILL change! */
232  vec_validate (sm->error_vector, thread_index);
233  sm->error_vector[thread_index] =
234  stat_segment_offset (shared_header, error_vector);
235 
236  shared_header->error_offset =
237  stat_segment_offset (shared_header, sm->error_vector);
238  shared_header->directory_offset =
239  stat_segment_offset (shared_header, sm->directory_vector);
240 
241  if (lock)
243  clib_mem_set_heap (oldheap);
244 }
245 
246 clib_error_t *
248 {
250  stat_segment_shared_header_t *shared_header;
251  void *oldheap;
252  ssize_t memory_size;
253  int mfd;
254  char *mem_name = "stat_segment_test";
255  void *memaddr;
256 
257  memory_size = sm->memory_size;
258  if (memory_size == 0)
259  memory_size = STAT_SEGMENT_DEFAULT_SIZE;
260 
261  /* Create shared memory segment */
262  if ((mfd = memfd_create (mem_name, 0)) < 0)
263  return clib_error_return (0, "stat segment memfd_create failure");
264 
265  /* Set size */
266  if ((ftruncate (mfd, memory_size)) == -1)
267  return clib_error_return (0, "stat segment ftruncate failure");
268 
269  if ((memaddr =
270  mmap (NULL, memory_size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd,
271  0)) == MAP_FAILED)
272  return clib_error_return (0, "stat segment mmap failure");
273 
274  void *heap;
275 #if USE_DLMALLOC == 0
276  heap = mheap_alloc_with_flags (((u8 *) memaddr) + getpagesize (),
277  memory_size - getpagesize (),
280 #else
281  heap =
282  create_mspace_with_base (((u8 *) memaddr) + getpagesize (),
283  memory_size - getpagesize (), 1 /* locked */ );
284  mspace_disable_expand (heap);
285 #endif
286 
287  sm->heap = heap;
288  sm->memfd = mfd;
289 
291  sm->shared_header = shared_header = memaddr;
292 
293  shared_header->version = STAT_SEGMENT_VERSION;
294 
297 
298  oldheap = clib_mem_set_heap (sm->heap);
299 
300  /* Set up the name to counter-vector hash table */
301  sm->directory_vector = 0;
302 
303  shared_header->epoch = 1;
304 
305  /* Scalar stats and node counters */
307 #define _(E,t,n,p) \
308  strcpy(sm->directory_vector[STAT_COUNTER_##E].name, #p "/" #n); \
309  sm->directory_vector[STAT_COUNTER_##E].type = STAT_DIR_TYPE_##t;
311 #undef _
312  /* Save the vector offset in the shared segment, for clients */
313  shared_header->directory_offset =
314  stat_segment_offset (shared_header, sm->directory_vector);
315 
316  clib_mem_set_heap (oldheap);
317 
318  /* Total shared memory size */
320  mheap_usage (sm->heap, &usage);
322  usage.bytes_total;
323 
324  return 0;
325 }
326 
327 static int
328 name_sort_cmp (void *a1, void *a2)
329 {
332 
333  return strcmp ((char *) n1->name, (char *) n2->name);
334 }
335 
336 static u8 *
337 format_stat_dir_entry (u8 * s, va_list * args)
338 {
340  va_arg (*args, stat_segment_directory_entry_t *);
341  char *type_name;
342  char *format_string;
343 
344  format_string = "%-74s %-10s %10lld";
345 
346  switch (ep->type)
347  {
349  type_name = "ScalarPtr";
350  break;
351 
354  type_name = "CMainPtr";
355  break;
356 
358  type_name = "ErrIndex";
359  break;
360 
361  default:
362  type_name = "illegal!";
363  break;
364  }
365 
366  return format (s, format_string, ep->name, type_name, ep->offset);
367 }
368 
369 static clib_error_t *
371  unformat_input_t * input,
372  vlib_cli_command_t * cmd)
373 {
376  int i;
377 
378  int verbose = 0;
379 
380  if (unformat (input, "verbose"))
381  verbose = 1;
382 
383  /* Lock even as reader, as this command doesn't handle epoch changes */
385  show_data = vec_dup (sm->directory_vector);
387 
389 
390  vlib_cli_output (vm, "%-74s %10s %10s", "Name", "Type", "Value");
391 
392  for (i = 0; i < vec_len (show_data); i++)
393  {
394  vlib_cli_output (vm, "%-100U", format_stat_dir_entry,
395  vec_elt_at_index (show_data, i));
396  }
397 
398  if (verbose)
399  {
400  ASSERT (sm->heap);
401  vlib_cli_output (vm, "%U", format_mheap, sm->heap, 0 /* verbose */ );
402  }
403 
404  return 0;
405 }
406 
407 /* *INDENT-OFF* */
408 VLIB_CLI_COMMAND (show_stat_segment_command, static) =
409 {
410  .path = "show statistics segment",
411  .short_help = "show statistics segment [verbose]",
412  .function = show_stat_segment_command_fn,
413 };
414 /* *INDENT-ON* */
415 
416 /*
417  * Node performance counters:
418  * total_calls [threads][node-index]
419  * total_vectors
420  * total_calls
421  * total suspends
422  */
423 
424 static inline void
426 {
427  vlib_main_t **stat_vms = 0;
428  vlib_node_t ***node_dups = 0;
429  int i, j;
430  stat_segment_shared_header_t *shared_header = sm->shared_header;
431  static u32 no_max_nodes = 0;
432 
433  vlib_node_get_nodes (0 /* vm, for barrier sync */ ,
434  (u32) ~ 0 /* all threads */ ,
435  1 /* include stats */ ,
436  0 /* barrier sync */ ,
437  &node_dups, &stat_vms);
438 
439  u32 l = vec_len (node_dups[0]);
440 
441  /*
442  * Extend performance nodes if necessary
443  */
444  if (l > no_max_nodes)
445  {
446  void *oldheap = clib_mem_set_heap (sm->heap);
448 
450  [STAT_COUNTER_NODE_CLOCKS], l - 1);
452  [STAT_COUNTER_NODE_VECTORS], l - 1);
454  [STAT_COUNTER_NODE_CALLS], l - 1);
456  [STAT_COUNTER_NODE_SUSPENDS], l - 1);
457 
458  vec_validate (sm->nodes, l - 1);
461  ep->offset = stat_segment_offset (shared_header, sm->nodes);
462 
463  int i;
464  u64 *offset_vector =
465  ep->offset_vector ? stat_segment_pointer (shared_header,
466  ep->offset_vector) : 0;
467  /* Update names dictionary */
468  vec_validate (offset_vector, l - 1);
469  vlib_node_t **nodes = node_dups[0];
470 
471  for (i = 0; i < vec_len (nodes); i++)
472  {
473  vlib_node_t *n = nodes[i];
474  u8 *s = 0;
475  s = format (s, "%v%c", n->name, 0);
476  if (sm->nodes[n->index])
477  vec_free (sm->nodes[n->index]);
478  sm->nodes[n->index] = s;
479  offset_vector[i] =
480  sm->nodes[i] ? stat_segment_offset (shared_header,
481  sm->nodes[i]) : 0;
482 
483  }
484  ep->offset_vector = stat_segment_offset (shared_header, offset_vector);
485 
487  clib_mem_set_heap (oldheap);
488  no_max_nodes = l;
489  }
490 
491  for (j = 0; j < vec_len (node_dups); j++)
492  {
493  vlib_node_t **nodes = node_dups[j];
494 
495  for (i = 0; i < vec_len (nodes); i++)
496  {
497  counter_t **counters;
498  counter_t *c;
499  vlib_node_t *n = nodes[i];
500 
501  counters =
502  stat_segment_pointer (shared_header,
503  sm->directory_vector
505  c = counters[j];
507 
508  counters =
509  stat_segment_pointer (shared_header,
510  sm->directory_vector
512  c = counters[j];
514 
515  counters =
516  stat_segment_pointer (shared_header,
517  sm->directory_vector
519  c = counters[j];
520  c[n->index] = n->stats_total.calls - n->stats_last_clear.calls;
521 
522  counters =
523  stat_segment_pointer (shared_header,
524  sm->directory_vector
526  c = counters[j];
527  c[n->index] =
529  }
530  }
531 }
532 
533 static void
535 {
536  stat_segment_shared_header_t *shared_header = sm->shared_header;
537  vlib_main_t *vm = vlib_mains[0];
538  f64 vector_rate;
539  u64 input_packets;
540  f64 dt, now;
541  vlib_main_t *this_vlib_main;
542  int i, start;
543  counter_t **counters;
544  static int num_worker_threads_set;
545 
546  /*
547  * Set once at the beginning of time.
548  * Can't do this from the init routine, which happens before
549  * start_workers sets up vlib_mains...
550  */
551  if (PREDICT_FALSE (num_worker_threads_set == 0))
552  {
554  vec_len (vlib_mains) > 1 ? vec_len (vlib_mains) - 1 : 1;
555 
558  vec_len (vlib_mains));
559  num_worker_threads_set = 1;
560  }
561 
562  /*
563  * Compute per-worker vector rates, and the average vector rate
564  * across all workers
565  */
566  vector_rate = 0.0;
567 
568  counters =
569  stat_segment_pointer (shared_header,
570  sm->directory_vector
572 
573  start = vec_len (vlib_mains) > 1 ? 1 : 0;
574 
575  for (i = start; i < vec_len (vlib_mains); i++)
576  {
577 
578  f64 this_vector_rate;
579 
580  this_vlib_main = vlib_mains[i];
581 
582  this_vector_rate = vlib_last_vector_length_per_node (this_vlib_main);
583  vector_rate += this_vector_rate;
584 
585  /* Set the per-worker rate */
586  counters[i - start][0] = this_vector_rate;
587  }
588 
589  /* And set the system average rate */
590  vector_rate /= (f64) (i - start);
591 
593 
594  /*
595  * Compute the aggregate input rate
596  */
597  now = vlib_time_now (vm);
599  input_packets = vnet_get_aggregate_rx_packets ();
601  (f64) (input_packets - sm->last_input_packets) / dt;
603  sm->last_input_packets = input_packets;
606 
607  /* Stats segment memory heap counter */
609  mheap_usage (sm->heap, &usage);
611  usage.bytes_used;
612 
613  if (sm->node_counters_enabled)
615 
616  /* *INDENT-OFF* */
618  pool_foreach(g, sm->gauges,
619  ({
620  g->fn(&sm->directory_vector[g->directory_index], g->caller_index);
621  }));
622  /* *INDENT-ON* */
623 
624  /* Heartbeat, so clients detect we're still here */
626 }
627 
628 /*
629  * Accept connection on the socket and exchange the fd for the shared
630  * memory segment.
631  */
632 static clib_error_t *
634 {
636  clib_error_t *err;
637  clib_socket_t client = { 0 };
638 
639  err = clib_socket_accept (sm->socket, &client);
640  if (err)
641  {
642  clib_error_report (err);
643  return err;
644  }
645 
646  /* Send the fd across and close */
647  err = clib_socket_sendmsg (&client, 0, 0, &sm->memfd, 1);
648  if (err)
649  clib_error_report (err);
650  clib_socket_close (&client);
651 
652  return 0;
653 }
654 
655 static void
657 {
659  clib_error_t *error;
661 
662  memset (s, 0, sizeof (clib_socket_t));
663  s->config = (char *) sm->socket_name;
666 
667  if ((error = clib_socket_init (s)))
668  {
669  clib_error_report (error);
670  return;
671  }
672 
673  clib_file_t template = { 0 };
675  template.file_descriptor = s->fd;
676  template.description = format (0, "stats segment listener %s", s->config);
677  clib_file_add (&file_main, &template);
678 
679  sm->socket = s;
680 }
681 
682 static clib_error_t *
684 {
685  /*
686  * cleanup the listener socket on exit.
687  */
689  unlink ((char *) sm->socket_name);
690  return 0;
691 }
692 
694 
695 static uword
697  vlib_frame_t * f)
698 {
700 
701  /* Wait for Godot... */
702  f64 sleep_duration = 10;
703 
704  while (1)
705  {
707  vlib_process_suspend (vm, sleep_duration);
708  }
709  return 0; /* or not */
710 }
711 
712 static clib_error_t *
714 {
716 
717  if (sm->socket_name)
719 
720  return 0;
721 }
722 
723 /* *INDENT-OFF* */
725 {
726  .runs_after = VLIB_INITS("unix_input_init"),
727 };
728 /* *INDENT-ON* */
729 
730 
731 clib_error_t *
733  u32 caller_index)
734 {
736  stat_segment_shared_header_t *shared_header = sm->shared_header;
737  void *oldheap;
740 
741  ASSERT (shared_header);
742 
743  u32 next_vector_index = vec_len (sm->directory_vector);
744  u32 vector_index = lookup_or_create_hash_index (name,
745  next_vector_index);
746 
747  if (vector_index < next_vector_index) /* Already registered */
748  return clib_error_return (0, "%v is alreadty registered", name);
749 
750  oldheap = vlib_stats_push_heap (NULL);
752 
753  memset (&e, 0, sizeof (e));
755 
756  memcpy (e.name, name, vec_len (name));
757  vec_add1 (sm->directory_vector, e);
758 
759  shared_header->directory_offset =
760  stat_segment_offset (shared_header, sm->directory_vector);
761 
763  clib_mem_set_heap (oldheap);
764 
765  /* Back on our own heap */
766  pool_get (sm->gauges, gauge);
767  gauge->fn = update_fn;
768  gauge->caller_index = caller_index;
769  gauge->directory_index = next_vector_index;
770 
771  return NULL;
772 }
773 
774 static clib_error_t *
776 {
778 
780  {
781  if (unformat (input, "socket-name %s", &sm->socket_name))
782  ;
783  else if (unformat (input, "default"))
784  {
786  sm->socket_name = format (sm->socket_name, "%s",
788  }
789  else if (unformat (input, "size %U",
791  ;
792  else if (unformat (input, "per-node-counters on"))
793  sm->node_counters_enabled = 1;
794  else if (unformat (input, "per-node-counters off"))
795  sm->node_counters_enabled = 0;
796  else
797  return clib_error_return (0, "unknown input `%U'",
798  format_unformat_error, input);
799  }
800 
801  /* set default socket file name when statseg config stanza is empty. */
802  if (!vec_len (sm->socket_name))
803  sm->socket_name = format (sm->socket_name, "%s",
805  /*
806  * NULL-terminate socket name string
807  * clib_socket_init()->socket_config() use C str*
808  */
810 
811  return 0;
812 }
813 
814 static clib_error_t *
816 {
818  stat_segment_shared_header_t *shared_header = sm->shared_header;
819 
820  void *oldheap = vlib_stats_push_heap (sm->interfaces);
822 
823  vec_validate (sm->interfaces, sw_if_index);
824  if (is_add)
825  {
826  vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
827  vnet_sw_interface_t *si_sup =
829  vnet_hw_interface_t *hi_sup;
830 
832  hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index);
833 
834  u8 *s = 0;
835  s = format (s, "%v", hi_sup->name);
837  s = format (s, ".%d", si->sub.id);
838  s = format (s, "%c", 0);
839  sm->interfaces[sw_if_index] = s;
840  }
841  else
842  {
843  vec_free (sm->interfaces[sw_if_index]);
844  sm->interfaces[sw_if_index] = 0;
845  }
846 
849  ep->offset = stat_segment_offset (shared_header, sm->interfaces);
850 
851  int i;
852  u64 *offset_vector =
853  ep->offset_vector ? stat_segment_pointer (shared_header,
854  ep->offset_vector) : 0;
855 
856  vec_validate (offset_vector, vec_len (sm->interfaces) - 1);
857 
858  if (sm->last != sm->interfaces)
859  {
860  /* the interface vector moved, so need to recalulate the offset array */
861  for (i = 0; i < vec_len (sm->interfaces); i++)
862  {
863  offset_vector[i] =
864  sm->interfaces[i] ? stat_segment_offset (shared_header,
865  sm->interfaces[i]) : 0;
866  }
867  }
868  else
869  {
870  offset_vector[sw_if_index] =
871  sm->interfaces[sw_if_index] ?
872  stat_segment_offset (shared_header, sm->interfaces[sw_if_index]) : 0;
873  }
874  ep->offset_vector = stat_segment_offset (shared_header, offset_vector);
875 
877  clib_mem_set_heap (oldheap);
878 
879  return 0;
880 }
881 
884 
885 /* *INDENT-OFF* */
887 {
889 .name = "statseg-collector-process",
890 .type = VLIB_NODE_TYPE_PROCESS,
891 };
892 
893 /* *INDENT-ON* */
894 
895 /*
896  * fd.io coding-style-patch-verification: ON
897  *
898  * Local Variables:
899  * eval: (c-set-style "gnu")
900  * End:
901  */
static clib_error_t * statseg_config(vlib_main_t *vm, unformat_input_t *input)
Definition: stat_segment.c:775
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
uword bytes_total
Definition: mem.h:307
Definition: stat_segment.h:62
#define hash_set(h, key, value)
Definition: hash.h:255
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
Definition: lock.h:100
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Definition: lock.h:78
void vlib_stats_pop_heap2(u64 *error_vector, u32 thread_index, void *oldheap, int lock)
Definition: stat_segment.c:220
stat_segment_gauges_pool_t * gauges
Definition: stat_segment.h:116
static u64 vnet_get_aggregate_rx_packets(void)
Definition: devices.h:98
stat_segment_shared_header_t * shared_header
Definition: stat_segment.h:132
static clib_error_t * stats_socket_accept_ready(clib_file_t *uf)
Definition: stat_segment.c:633
stat_segment_main_t stat_segment_main
Definition: stat_segment.c:27
void * vlib_stats_push_heap(void *old)
Definition: stat_segment.c:53
stat_segment_directory_entry_t * directory_vector
Definition: stat_segment.h:120
unsigned long u64
Definition: types.h:89
#define NULL
Definition: clib.h:58
u32 index
Definition: node.h:279
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:258
static uint64_t stat_segment_offset(void *start, void *data)
Definition: stat_segment.h:94
static void stat_validate_counter_vector(stat_segment_directory_entry_t *ep, u32 max)
Definition: stat_segment.c:198
static int memfd_create(const char *name, unsigned int flags)
Definition: syscall.h:52
#define STAT_SEGMENT_DEFAULT_SIZE
Definition: stat_segment.h:75
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:1014
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
int i
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)
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
#define foreach_stat_segment_counter_name
Definition: stat_segment.h:44
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:450
#define MHEAP_FLAG_THREAD_SAFE
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
vlib_main_t ** vlib_mains
Definition: buffer.c:321
uword bytes_used
Definition: mem.h:307
unsigned char u8
Definition: types.h:56
void(* stat_segment_update_fn)(stat_segment_directory_entry_t *e, u32 i)
Definition: stat_segment.h:105
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
atomic_int_fast64_t in_progress
Definition: stat_segment.h:87
clib_file_function_t * read_function
Definition: file.h:67
double f64
Definition: types.h:142
uword value[0]
Definition: hash.h:165
static f64 vlib_last_vector_length_per_node(vlib_main_t *vm)
Definition: main.h:349
#define CLIB_SOCKET_F_IS_SERVER
Definition: socket.h:58
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:422
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
Definition: stat_segment.h:68
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:493
static void do_stat_segment_updates(stat_segment_main_t *sm)
Definition: stat_segment.c:534
vl_api_interface_index_t sw_if_index
Definition: gre.api:50
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
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:569
#define MHEAP_FLAG_DISABLE_VM
void vlib_stats_pop_heap(void *cm_arg, void *oldheap, u32 cindex, stat_directory_type_t type)
Definition: stat_segment.c:89
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:109
unsigned int u32
Definition: types.h:88
static clib_error_t * statseg_init(vlib_main_t *vm)
Definition: stat_segment.c:713
A collection of simple counters.
Definition: counter.h:57
#define hash_create_string(elts, value_bytes)
Definition: hash.h:690
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:61
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:354
vnet_crypto_main_t * cm
Definition: quic_crypto.c:41
vlib_node_stats_t stats_total
Definition: node.h:269
vnet_sub_interface_t sub
Definition: interface.h:719
static void * stat_segment_pointer(void *start, uint64_t offset)
Definition: stat_segment.h:100
static void stats_segment_socket_init(void)
Definition: stat_segment.c:656
clib_error_t * clib_socket_accept(clib_socket_t *server, clib_socket_t *client)
Definition: socket.c:524
f64 time_last_runtime_stats_clear
Definition: node.h:759
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:337
void vlib_stat_segment_unlock(void)
Definition: stat_segment.c:41
uint64_t offset
Definition: stat_segment.h:66
DLMALLOC_EXPORT void mspace_disable_expand(mspace msp)
struct _unformat_input_t unformat_input_t
u64 memory_size
Definition: vhost_user.h:141
static clib_error_t * stats_segment_socket_exit(vlib_main_t *vm)
Definition: stat_segment.c:683
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:375
#define PREDICT_FALSE(x)
Definition: clib.h:111
u8 name[64]
Definition: memclnt.api:152
u8 * name
Definition: node.h:263
#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:732
vlib_main_t * vm
Definition: buffer.c:312
#define STAT_SEGMENT_SOCKET_FILE
Definition: stat_client.h:38
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
#define VLIB_MAIN_LOOP_EXIT_FUNCTION(x)
Definition: init.h:178
stat_directory_type_t
Definition: stat_client.h:27
static void * clib_mem_set_heap(void *heap)
Definition: mem.h:282
static vlib_node_registration_t stat_segment_collector
(constructor) VLIB_REGISTER_NODE (stat_segment_collector)
Definition: stat_segment.c:886
void vlib_stat_segment_lock(void)
Definition: stat_segment.c:33
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(statseg_sw_interface_add_del)
uint64_t offset_vector
Definition: stat_segment.h:70
static void * clib_mem_get_heap(void)
Definition: mem.h:276
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
void * mheap_alloc_with_flags(void *memory, uword memory_size, uword flags)
Definition: mheap.c:885
char name[128]
Definition: stat_segment.h:71
#define ASSERT(truth)
static uword clib_file_add(clib_file_main_t *um, clib_file_t *template)
Definition: file.h:96
#define clib_error_report(e)
Definition: error.h:113
struct _socket_t clib_socket_t
atomic_int_fast64_t epoch
Definition: stat_segment.h:86
static void * clib_mem_alloc(uword size)
Definition: mem.h:153
#define CLIB_SOCKET_F_SEQPACKET
Definition: socket.h:63
#define STAT_SEGMENT_VERSION
Definition: stat_segment.h:78
static uword stat_segment_collector_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: stat_segment.c:696
static u32 lookup_or_create_hash_index(u8 *name, u32 next_vector_index)
Definition: stat_segment.c:63
void mheap_usage(void *heap, clib_mem_usage_t *usage)
Definition: mem_dlmalloc.c:387
uword * directory_vector_by_name
Definition: stat_segment.h:119
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:140
#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:425
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:980
static int name_sort_cmp(void *a1, void *a2)
Definition: stat_segment.c:328
static clib_error_t * statseg_sw_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
Definition: stat_segment.c:815
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:370
unformat_function_t unformat_memory_size
Definition: format.h:296
clib_socket_t * socket
Definition: stat_segment.h:126
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:697
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
Definition: file.h:51
void vlib_stats_register_error_index(void *oldheap, u8 *name, u64 *em_vec, u64 index)
Definition: stat_segment.c:161
#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:247
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:768
#define VLIB_INITS(...)
Definition: init.h:344
atomic_int_fast64_t error_offset
Definition: stat_segment.h:89
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
clib_spinlock_t * stat_segment_lockp
Definition: stat_segment.h:125
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
atomic_int_fast64_t directory_offset
Definition: stat_segment.h:88
stat_directory_type_t type
Definition: stat_segment.h:64