FD.io VPP  v19.04.2-12-g66b1689
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>
26 
27 /*
28  * Used only by VPP writers
29  */
30 void
32 {
35  sm->shared_header->in_progress = 1;
36 }
37 
38 void
40 {
42  sm->shared_header->epoch++;
43  sm->shared_header->in_progress = 0;
45 }
46 
47 /*
48  * Change heap to the stats shared memory segment
49  */
50 void *
52 {
54 
55  sm->last = old;
56  ASSERT (sm && sm->shared_header);
57  return clib_mem_set_heap (sm->heap);
58 }
59 
60 /* Name to vector index hash */
61 static u32
62 lookup_or_create_hash_index (void *oldheap, char *name, u32 next_vector_index)
63 {
65  u32 index;
66  hash_pair_t *hp;
67 
68  hp = hash_get_pair (sm->directory_vector_by_name, name);
69  if (!hp)
70  {
71  hash_set (sm->directory_vector_by_name, name, next_vector_index);
72  index = next_vector_index;
73  }
74  else
75  {
76  index = hp->value[0];
77  }
78 
79  return index;
80 }
81 
82 void
83 vlib_stats_pop_heap (void *cm_arg, void *oldheap, u32 cindex,
85 {
88  stat_segment_shared_header_t *shared_header = sm->shared_header;
89  char *stat_segment_name;
91 
92  /* Not all counters have names / hash-table entries */
93  if (!cm->name && !cm->stat_segment_name)
94  {
95  clib_mem_set_heap (oldheap);
96  return;
97  }
98 
99  ASSERT (shared_header);
100 
102 
103  /* Lookup hash-table is on the main heap */
104  stat_segment_name =
105  cm->stat_segment_name ? cm->stat_segment_name : cm->name;
106  u32 next_vector_index = vec_len (sm->directory_vector);
107  clib_mem_set_heap (oldheap); /* Exit stats segment */
108  u32 vector_index = lookup_or_create_hash_index (oldheap, stat_segment_name,
109  next_vector_index);
110  /* Back to stats segment */
111  clib_mem_set_heap (sm->heap); /* Re-enter stat segment */
112 
113 
114  /* Update the vector */
115  if (vector_index == next_vector_index)
116  { /* New */
117  strncpy (e.name, stat_segment_name, 128 - 1);
118  e.type = type;
119  vec_add1 (sm->directory_vector, e);
120  }
121 
122  stat_segment_directory_entry_t *ep = &sm->directory_vector[vector_index];
123  ep->offset = stat_segment_offset (shared_header, cm->counters); /* Vector of threads of vectors of counters */
124  u64 *offset_vector =
125  ep->offset_vector ? stat_segment_pointer (shared_header,
126  ep->offset_vector) : 0;
127 
128  /* Update the 2nd dimension offset vector */
129  int i;
130  vec_validate (offset_vector, vec_len (cm->counters) - 1);
131 
132  if (sm->last != offset_vector)
133  {
134  for (i = 0; i < vec_len (cm->counters); i++)
135  offset_vector[i] =
136  stat_segment_offset (shared_header, cm->counters[i]);
137  }
138  else
139  offset_vector[cindex] =
140  stat_segment_offset (shared_header, cm->counters[cindex]);
141 
142  ep->offset_vector = stat_segment_offset (shared_header, offset_vector);
143  sm->directory_vector[vector_index].offset =
144  stat_segment_offset (shared_header, cm->counters);
145 
146  /* Reset the client hash table pointer, since it WILL change! */
147  shared_header->directory_offset =
148  stat_segment_offset (shared_header, sm->directory_vector);
149 
151  clib_mem_set_heap (oldheap);
152 }
153 
154 void
155 vlib_stats_register_error_index (void *oldheap, u8 * name, u64 * em_vec,
156  u64 index)
157 {
159  stat_segment_shared_header_t *shared_header = sm->shared_header;
161  hash_pair_t *hp;
162 
163  ASSERT (shared_header);
164 
166  u32 next_vector_index = vec_len (sm->directory_vector);
167  clib_mem_set_heap (oldheap); /* Exit stats segment */
168 
169  u32 vector_index = lookup_or_create_hash_index (oldheap, (char *) name,
170  next_vector_index);
171 
172  /* Back to stats segment */
173  clib_mem_set_heap (sm->heap); /* Re-enter stat segment */
174 
175  if (next_vector_index == vector_index)
176  {
177  memcpy (e.name, name, vec_len (name));
178  e.name[vec_len (name)] = '\0';
180  e.offset = index;
181  e.offset_vector = 0;
182  vec_add1 (sm->directory_vector, e);
183 
184  /* Warn clients to refresh any pointers they might be holding */
185  shared_header->directory_offset =
186  stat_segment_offset (shared_header, sm->directory_vector);
187  }
188  else
189  {
190  vec_free (name);
191  }
192 
194 }
195 
196 static void
198 {
200  stat_segment_shared_header_t *shared_header = sm->shared_header;
201  counter_t **counters = 0;
203  int i;
204  u64 *offset_vector = 0;
205 
206  vec_validate_aligned (counters, tm->n_vlib_mains - 1,
208  for (i = 0; i < tm->n_vlib_mains; i++)
209  {
210  vec_validate_aligned (counters[i], max, CLIB_CACHE_LINE_BYTES);
211  vec_add1 (offset_vector,
212  stat_segment_offset (shared_header, counters[i]));
213  }
214  ep->offset = stat_segment_offset (shared_header, counters);
215  ep->offset_vector = stat_segment_offset (shared_header, offset_vector);
216 }
217 
218 void
219 vlib_stats_pop_heap2 (u64 * error_vector, u32 thread_index, void *oldheap)
220 {
222  stat_segment_shared_header_t *shared_header = sm->shared_header;
223 
224  ASSERT (shared_header);
225 
227 
228  /* Reset the client hash table pointer, since it WILL change! */
229  shared_header->error_offset =
230  stat_segment_offset (shared_header, error_vector);
231  shared_header->directory_offset =
232  stat_segment_offset (shared_header, sm->directory_vector);
233 
235  clib_mem_set_heap (oldheap);
236 }
237 
238 clib_error_t *
240 {
242  stat_segment_shared_header_t *shared_header;
244  void *oldheap;
245  ssize_t memory_size;
246  int mfd;
247  char *mem_name = "stat_segment_test";
248  void *memaddr;
249 
250  memory_size = sm->memory_size;
251  if (memory_size == 0)
252  memory_size = STAT_SEGMENT_DEFAULT_SIZE;
253 
254  /* Create shared memory segment */
255  if ((mfd = memfd_create (mem_name, 0)) < 0)
256  return clib_error_return (0, "stat segment memfd_create failure");
257 
258  /* Set size */
259  if ((ftruncate (mfd, memory_size)) == -1)
260  return clib_error_return (0, "stat segment ftruncate failure");
261 
262  if ((memaddr =
263  mmap (NULL, memory_size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd,
264  0)) == MAP_FAILED)
265  return clib_error_return (0, "stat segment mmap failure");
266 
267  void *heap;
268 #if USE_DLMALLOC == 0
269  heap = mheap_alloc_with_flags (((u8 *) memaddr) + getpagesize (),
270  memory_size - getpagesize (),
273 #else
274  heap =
275  create_mspace_with_base (((u8 *) memaddr) + getpagesize (),
276  memory_size - getpagesize (), 1 /* locked */ );
277  mspace_disable_expand (heap);
278 #endif
279 
280  sm->heap = heap;
281  sm->memfd = mfd;
282 
284  sm->shared_header = shared_header = memaddr;
287 
288  oldheap = clib_mem_set_heap (sm->heap);
289 
290  /* Set up the name to counter-vector hash table */
291  sm->directory_vector = 0;
292 
293  shared_header->epoch = 1;
294 
295  /* Scalar stats and node counters */
297 #define _(E,t,n,p) \
298  strcpy(sm->directory_vector[STAT_COUNTER_##E].name, #p "/" #n); \
299  sm->directory_vector[STAT_COUNTER_##E].type = STAT_DIR_TYPE_##t;
301 #undef _
302  /* Save the vector offset in the shared segment, for clients */
303  shared_header->directory_offset =
304  stat_segment_offset (shared_header, sm->directory_vector);
305 
306  clib_mem_set_heap (oldheap);
307 
308  return 0;
309 }
310 
311 static int
312 name_sort_cmp (void *a1, void *a2)
313 {
316 
317  return strcmp ((char *) n1->name, (char *) n2->name);
318 }
319 
320 static u8 *
321 format_stat_dir_entry (u8 * s, va_list * args)
322 {
324  va_arg (*args, stat_segment_directory_entry_t *);
325  char *type_name;
326  char *format_string;
327 
328  format_string = "%-74s %-10s %10lld";
329 
330  switch (ep->type)
331  {
333  type_name = "ScalarPtr";
334  break;
335 
338  type_name = "CMainPtr";
339  break;
340 
342  type_name = "ErrIndex";
343  break;
344 
345  default:
346  type_name = "illegal!";
347  break;
348  }
349 
350  return format (s, format_string, ep->name, type_name, ep->offset);
351 }
352 
353 static clib_error_t *
355  unformat_input_t * input,
356  vlib_cli_command_t * cmd)
357 {
359  counter_t *counter;
360  hash_pair_t *p;
361  stat_segment_directory_entry_t *show_data, *this;
362  int i, j;
363 
364  int verbose = 0;
365  u8 *s;
366 
367  if (unformat (input, "verbose"))
368  verbose = 1;
369 
370  /* Lock even as reader, as this command doesn't handle epoch changes */
372  show_data = vec_dup (sm->directory_vector);
374 
376 
377  vlib_cli_output (vm, "%-74s %10s %10s", "Name", "Type", "Value");
378 
379  for (i = 0; i < vec_len (show_data); i++)
380  {
381  vlib_cli_output (vm, "%-100U", format_stat_dir_entry,
382  vec_elt_at_index (show_data, i));
383  }
384 
385  if (verbose)
386  {
387  ASSERT (sm->heap);
388  vlib_cli_output (vm, "%U", format_mheap, sm->heap, 0 /* verbose */ );
389  }
390 
391  return 0;
392 }
393 
394 /* *INDENT-OFF* */
395 VLIB_CLI_COMMAND (show_stat_segment_command, static) =
396 {
397  .path = "show statistics segment",
398  .short_help = "show statistics segment [verbose]",
399  .function = show_stat_segment_command_fn,
400 };
401 /* *INDENT-ON* */
402 
403 /*
404  * Node performance counters:
405  * total_calls [threads][node-index]
406  * total_vectors
407  * total_calls
408  * total suspends
409  */
410 
411 static inline void
413 {
414  vlib_main_t *vm = vlib_mains[0];
415  vlib_main_t **stat_vms = 0;
416  vlib_node_t ***node_dups = 0;
417  int i, j;
418  stat_segment_shared_header_t *shared_header = sm->shared_header;
419  static u32 no_max_nodes = 0;
420 
421  vlib_node_get_nodes (0 /* vm, for barrier sync */ ,
422  (u32) ~ 0 /* all threads */ ,
423  1 /* include stats */ ,
424  0 /* barrier sync */ ,
425  &node_dups, &stat_vms);
426 
427  u32 l = vec_len (node_dups[0]);
428 
429  /*
430  * Extend performance nodes if necessary
431  */
432  if (l > no_max_nodes)
433  {
434  void *oldheap = clib_mem_set_heap (sm->heap);
436 
445 
446  vec_validate (sm->nodes, l);
449  ep->offset = stat_segment_offset (shared_header, sm->nodes);
450 
451  int i;
452  u64 *offset_vector =
453  ep->offset_vector ? stat_segment_pointer (shared_header,
454  ep->offset_vector) : 0;
455  /* Update names dictionary */
456  vec_validate (offset_vector, l);
457  vlib_node_t **nodes = node_dups[0];
458  for (i = 0; i < vec_len (nodes); i++)
459  {
460  vlib_node_t *n = nodes[i];
461  u8 *s = 0;
462  s = format (s, "%v%c", n->name, 0);
463  if (sm->nodes[n->index])
464  vec_free (sm->nodes[n->index]);
465  sm->nodes[n->index] = s;
466  offset_vector[i] =
467  sm->nodes[i] ? stat_segment_offset (shared_header,
468  sm->nodes[i]) : 0;
469 
470  }
471  ep->offset_vector = stat_segment_offset (shared_header, offset_vector);
472 
474  clib_mem_set_heap (oldheap);
475  no_max_nodes = l;
476  }
477 
478  for (j = 0; j < vec_len (node_dups); j++)
479  {
480  vlib_node_t **nodes = node_dups[j];
481  u32 l = vec_len (nodes);
482 
483  for (i = 0; i < vec_len (nodes); i++)
484  {
485  counter_t **counters;
486  counter_t *c;
487  vlib_node_t *n = nodes[i];
488 
489  counters =
490  stat_segment_pointer (shared_header,
491  sm->directory_vector
493  c = counters[j];
495 
496  counters =
497  stat_segment_pointer (shared_header,
498  sm->directory_vector
500  c = counters[j];
502 
503  counters =
504  stat_segment_pointer (shared_header,
505  sm->directory_vector
507  c = counters[j];
508  c[n->index] = n->stats_total.calls - n->stats_last_clear.calls;
509 
510  counters =
511  stat_segment_pointer (shared_header,
512  sm->directory_vector
514  c = counters[j];
515  c[n->index] =
517  }
518  }
519 }
520 
521 static void
523 {
524  stat_segment_shared_header_t *shared_header = sm->shared_header;
525  vlib_main_t *vm = vlib_mains[0];
526  f64 vector_rate;
527  u64 input_packets, last_input_packets;
528  f64 dt, now;
529  vlib_main_t *this_vlib_main;
530  int i, start;
531  counter_t **counters;
532  static int num_worker_threads_set;
533 
534  /*
535  * Set once at the beginning of time.
536  * Can't do this from the init routine, which happens before
537  * start_workers sets up vlib_mains...
538  */
539  if (PREDICT_FALSE (num_worker_threads_set == 0))
540  {
542  vec_len (vlib_mains) > 1 ? vec_len (vlib_mains) - 1 : 1;
543 
546  vec_len (vlib_mains));
547  num_worker_threads_set = 1;
548  }
549 
550  /*
551  * Compute per-worker vector rates, and the average vector rate
552  * across all workers
553  */
554  vector_rate = 0.0;
555 
556  counters =
557  stat_segment_pointer (shared_header,
558  sm->directory_vector
560 
561  start = vec_len (vlib_mains) > 1 ? 1 : 0;
562 
563  for (i = start; i < vec_len (vlib_mains); i++)
564  {
565 
566  f64 this_vector_rate;
567 
568  this_vlib_main = vlib_mains[i];
569 
570  this_vector_rate = vlib_last_vector_length_per_node (this_vlib_main);
571  vector_rate += this_vector_rate;
572 
573  /* Set the per-worker rate */
574  counters[i - start][0] = this_vector_rate;
575  }
576 
577  /* And set the system average rate */
578  vector_rate /= (f64) (i - start);
579 
581 
582  /*
583  * Compute the aggregate input rate
584  */
585  now = vlib_time_now (vm);
587  input_packets = vnet_get_aggregate_rx_packets ();
589  (f64) (input_packets - sm->last_input_packets) / dt;
591  sm->last_input_packets = input_packets;
594 
595  if (sm->node_counters_enabled)
597 
598  /* *INDENT-OFF* */
600  pool_foreach(g, sm->gauges,
601  ({
602  g->fn(&sm->directory_vector[g->directory_index], g->caller_index);
603  }));
604  /* *INDENT-ON* */
605 
606  /* Heartbeat, so clients detect we're still here */
608 }
609 
610 /*
611  * Accept connection on the socket and exchange the fd for the shared
612  * memory segment.
613  */
614 static clib_error_t *
616 {
618  clib_error_t *err;
619  clib_socket_t client = { 0 };
620 
621  err = clib_socket_accept (sm->socket, &client);
622  if (err)
623  {
624  clib_error_report (err);
625  return err;
626  }
627 
628  /* Send the fd across and close */
629  err = clib_socket_sendmsg (&client, 0, 0, &sm->memfd, 1);
630  if (err)
631  clib_error_report (err);
632  clib_socket_close (&client);
633 
634  return 0;
635 }
636 
637 static void
639 {
641  clib_error_t *error;
643 
644  memset (s, 0, sizeof (clib_socket_t));
645  s->config = (char *) sm->socket_name;
648 
649  if ((error = clib_socket_init (s)))
650  {
651  clib_error_report (error);
652  return;
653  }
654 
655  clib_file_t template = { 0 };
657  template.file_descriptor = s->fd;
658  template.description = format (0, "stats segment listener %s", s->config);
659  clib_file_add (&file_main, &template);
660 
661  sm->socket = s;
662 }
663 
664 static clib_error_t *
666 {
667  /*
668  * cleanup the listener socket on exit.
669  */
671  unlink ((char *) sm->socket_name);
672  return 0;
673 }
674 
676 
677 static uword
679  vlib_frame_t * f)
680 {
682 
683  /* Wait for Godot... */
684  f64 sleep_duration = 10;
685 
686  while (1)
687  {
689  vlib_process_suspend (vm, sleep_duration);
690  }
691  return 0; /* or not */
692 }
693 
694 static clib_error_t *
696 {
698  clib_error_t *error;
699 
700  /* dependent on unix_input_init */
701  if ((error = vlib_call_init_function (vm, unix_input_init)))
702  return error;
703 
704  if (sm->socket_name)
706 
707  return 0;
708 }
709 
710 clib_error_t *
712  u32 caller_index)
713 {
715  stat_segment_shared_header_t *shared_header = sm->shared_header;
716  void *oldheap;
718  u32 index;
720 
721  ASSERT (shared_header);
722 
723  oldheap = vlib_stats_push_heap (NULL);
725 
726  memset (&e, 0, sizeof (e));
728 
729  memcpy (e.name, name, vec_len (name));
730  index = vec_len (sm->directory_vector);
731  vec_add1 (sm->directory_vector, e);
732 
733  shared_header->directory_offset =
734  stat_segment_offset (shared_header, sm->directory_vector);
735 
737  clib_mem_set_heap (oldheap);
738 
739  /* Back on our own heap */
740  pool_get (sm->gauges, gauge);
741  gauge->fn = update_fn;
742  gauge->caller_index = caller_index;
743  gauge->directory_index = index;
744 
745  return NULL;
746 }
747 
748 static clib_error_t *
750 {
752 
753  /* set default socket file name when statseg config stanza is empty. */
755 
757  {
758  if (unformat (input, "socket-name %s", &sm->socket_name))
759  ;
760  else if (unformat (input, "default"))
762  else
763  if (unformat
764  (input, "size %U", unformat_memory_size, &sm->memory_size))
765  ;
766  else if (unformat (input, "per-node-counters on"))
767  sm->node_counters_enabled = 1;
768  else if (unformat (input, "per-node-counters off"))
769  sm->node_counters_enabled = 0;
770  else
771  return clib_error_return (0, "unknown input `%U'",
772  format_unformat_error, input);
773  }
774  return 0;
775 }
776 
777 static clib_error_t *
779 {
781  stat_segment_shared_header_t *shared_header = sm->shared_header;
782 
783  void *oldheap = vlib_stats_push_heap (sm->interfaces);
785 
786  vec_validate (sm->interfaces, sw_if_index);
787  if (is_add)
788  {
789  vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
790  vnet_sw_interface_t *si_sup =
792  vnet_hw_interface_t *hi_sup;
793 
795  hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index);
796 
797  u8 *s = 0;
798  s = format (s, "%v", hi_sup->name);
800  s = format (s, ".%d", si->sub.id);
801  s = format (s, "%c", 0);
802  sm->interfaces[sw_if_index] = s;
803  }
804  else
805  {
806  vec_free (sm->interfaces[sw_if_index]);
807  sm->interfaces[sw_if_index] = 0;
808  }
809 
812  ep->offset = stat_segment_offset (shared_header, sm->interfaces);
813 
814  int i;
815  u64 *offset_vector =
816  ep->offset_vector ? stat_segment_pointer (shared_header,
817  ep->offset_vector) : 0;
818 
819  vec_validate (offset_vector, vec_len (sm->interfaces) - 1);
820 
821  if (sm->last != sm->interfaces)
822  {
823  /* the interface vector moved, so need to recalulate the offset array */
824  for (i = 0; i < vec_len (sm->interfaces); i++)
825  {
826  offset_vector[i] =
827  sm->interfaces[i] ? stat_segment_offset (shared_header,
828  sm->interfaces[i]) : 0;
829  }
830  }
831  else
832  {
833  offset_vector[sw_if_index] =
834  sm->interfaces[sw_if_index] ?
835  stat_segment_offset (shared_header, sm->interfaces[sw_if_index]) : 0;
836  }
837  ep->offset_vector = stat_segment_offset (shared_header, offset_vector);
838 
840  clib_mem_set_heap (oldheap);
841 
842  return 0;
843 }
844 
848 
849 /* *INDENT-OFF* */
851 {
853 .name = "statseg-collector-process",
854 .type = VLIB_NODE_TYPE_PROCESS,
855 };
856 
857 /* *INDENT-ON* */
858 
859 /*
860  * fd.io coding-style-patch-verification: ON
861  *
862  * Local Variables:
863  * eval: (c-set-style "gnu")
864  * End:
865  */
static clib_error_t * statseg_config(vlib_main_t *vm, unformat_input_t *input)
Definition: stat_segment.c:749
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
u32 sw_if_index
Definition: ipsec_gre.api:37
Definition: stat_segment.h:58
#define hash_set(h, key, value)
Definition: hash.h:255
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
Definition: lock.h:89
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Definition: lock.h:74
stat_segment_gauges_pool_t * gauges
Definition: stat_segment.h:108
static clib_error_t * unix_input_init(vlib_main_t *vm)
Definition: input.c:412
static u64 vnet_get_aggregate_rx_packets(void)
Definition: devices.h:98
stat_segment_shared_header_t * shared_header
Definition: stat_segment.h:123
static clib_error_t * stats_socket_accept_ready(clib_file_t *uf)
Definition: stat_segment.c:615
stat_segment_main_t stat_segment_main
Definition: stat_segment.c:25
void * vlib_stats_push_heap(void *old)
Definition: stat_segment.c:51
stat_segment_directory_entry_t * directory_vector
Definition: stat_segment.h:112
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:255
static uint64_t stat_segment_offset(void *start, void *data)
Definition: stat_segment.h:86
static void stat_validate_counter_vector(stat_segment_directory_entry_t *ep, u32 max)
Definition: stat_segment.c:197
static int memfd_create(const char *name, unsigned int flags)
Definition: syscall.h:52
#define STAT_SEGMENT_DEFAULT_SIZE
Definition: stat_segment.h:71
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#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 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:42
#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
unsigned char u8
Definition: types.h:56
void(* stat_segment_update_fn)(stat_segment_directory_entry_t *e, u32 i)
Definition: stat_segment.h:97
atomic_int_fast64_t in_progress
Definition: stat_segment.h:79
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:346
#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:452
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:64
#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:522
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
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:83
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:101
unsigned int u32
Definition: types.h:88
static clib_error_t * statseg_init(vlib_main_t *vm)
Definition: stat_segment.c:695
A collection of simple counters.
Definition: counter.h:57
#define vlib_call_init_function(vm, x)
Definition: init.h:260
#define hash_create_string(elts, value_bytes)
Definition: hash.h:690
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:57
char * name
The counter collection&#39;s name.
Definition: counter.h:64
u8 * format_mheap(u8 *s, va_list *va)
Definition: mem_dlmalloc.c:354
vlib_node_stats_t stats_total
Definition: node.h:269
vnet_sub_interface_t sub
Definition: interface.h:704
static void * stat_segment_pointer(void *start, uint64_t offset)
Definition: stat_segment.h:92
static void stats_segment_socket_init(void)
Definition: stat_segment.c:638
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:760
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:321
void vlib_stat_segment_unlock(void)
Definition: stat_segment.c:39
uint64_t offset
Definition: stat_segment.h:62
DLMALLOC_EXPORT void mspace_disable_expand(mspace msp)
struct _unformat_input_t unformat_input_t
u64 memory_size
Definition: vhost_user.h:115
static clib_error_t * stats_segment_socket_exit(vlib_main_t *vm)
Definition: stat_segment.c:665
#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:216
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
#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:711
static u32 lookup_or_create_hash_index(void *oldheap, char *name, u32 next_vector_index)
Definition: stat_segment.c:62
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:168
stat_directory_type_t
Definition: stat_client.h:27
static void * clib_mem_set_heap(void *heap)
Definition: mem.h:261
static vlib_node_registration_t stat_segment_collector
(constructor) VLIB_REGISTER_NODE (stat_segment_collector)
Definition: stat_segment.c:850
void vlib_stat_segment_lock(void)
Definition: stat_segment.c:31
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(statseg_sw_interface_add_del)
uint64_t offset_vector
Definition: stat_segment.h:66
#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:67
#define ASSERT(truth)
u8 is_add
Definition: ipsec_gre.api:36
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:78
static void * clib_mem_alloc(uword size)
Definition: mem.h:132
#define CLIB_SOCKET_F_SEQPACKET
Definition: socket.h:63
static uword stat_segment_collector_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: stat_segment.c:678
uword * directory_vector_by_name
Definition: stat_segment.h:111
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:135
#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:412
#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:312
static clib_error_t * statseg_sw_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
Definition: stat_segment.c:778
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:354
unformat_function_t unformat_memory_size
Definition: format.h:295
clib_socket_t * socket
Definition: stat_segment.h:117
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:682
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:155
#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:239
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
atomic_int_fast64_t error_offset
Definition: stat_segment.h:81
void vlib_stats_pop_heap2(u64 *error_vector, u32 thread_index, void *oldheap)
Definition: stat_segment.c:219
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
clib_spinlock_t * stat_segment_lockp
Definition: stat_segment.h:116
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170
atomic_int_fast64_t directory_offset
Definition: stat_segment.h:80
stat_directory_type_t type
Definition: stat_segment.h:60