FD.io VPP  v19.04.4-rc0-5-ge88582fac
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  vec_free (node_dups[j]);
519  }
520  vec_free (node_dups);
521  vec_free (stat_vms);
522 }
523 
524 static void
526 {
527  stat_segment_shared_header_t *shared_header = sm->shared_header;
528  vlib_main_t *vm = vlib_mains[0];
529  f64 vector_rate;
530  u64 input_packets, last_input_packets;
531  f64 dt, now;
532  vlib_main_t *this_vlib_main;
533  int i, start;
534  counter_t **counters;
535  static int num_worker_threads_set;
536 
537  /*
538  * Set once at the beginning of time.
539  * Can't do this from the init routine, which happens before
540  * start_workers sets up vlib_mains...
541  */
542  if (PREDICT_FALSE (num_worker_threads_set == 0))
543  {
545  vec_len (vlib_mains) > 1 ? vec_len (vlib_mains) - 1 : 1;
546 
549  vec_len (vlib_mains));
550  num_worker_threads_set = 1;
551  }
552 
553  /*
554  * Compute per-worker vector rates, and the average vector rate
555  * across all workers
556  */
557  vector_rate = 0.0;
558 
559  counters =
560  stat_segment_pointer (shared_header,
561  sm->directory_vector
563 
564  start = vec_len (vlib_mains) > 1 ? 1 : 0;
565 
566  for (i = start; i < vec_len (vlib_mains); i++)
567  {
568 
569  f64 this_vector_rate;
570 
571  this_vlib_main = vlib_mains[i];
572 
573  this_vector_rate = vlib_last_vector_length_per_node (this_vlib_main);
574  vector_rate += this_vector_rate;
575 
576  /* Set the per-worker rate */
577  counters[i - start][0] = this_vector_rate;
578  }
579 
580  /* And set the system average rate */
581  vector_rate /= (f64) (i - start);
582 
584 
585  /*
586  * Compute the aggregate input rate
587  */
588  now = vlib_time_now (vm);
590  input_packets = vnet_get_aggregate_rx_packets ();
592  (f64) (input_packets - sm->last_input_packets) / dt;
594  sm->last_input_packets = input_packets;
597 
598  if (sm->node_counters_enabled)
600 
601  /* *INDENT-OFF* */
603  pool_foreach(g, sm->gauges,
604  ({
605  g->fn(&sm->directory_vector[g->directory_index], g->caller_index);
606  }));
607  /* *INDENT-ON* */
608 
609  /* Heartbeat, so clients detect we're still here */
611 }
612 
613 /*
614  * Accept connection on the socket and exchange the fd for the shared
615  * memory segment.
616  */
617 static clib_error_t *
619 {
621  clib_error_t *err;
622  clib_socket_t client = { 0 };
623 
624  err = clib_socket_accept (sm->socket, &client);
625  if (err)
626  {
627  clib_error_report (err);
628  return err;
629  }
630 
631  /* Send the fd across and close */
632  err = clib_socket_sendmsg (&client, 0, 0, &sm->memfd, 1);
633  if (err)
634  clib_error_report (err);
635  clib_socket_close (&client);
636 
637  return 0;
638 }
639 
640 static void
642 {
644  clib_error_t *error;
646 
647  memset (s, 0, sizeof (clib_socket_t));
648  s->config = (char *) sm->socket_name;
651 
652  if ((error = clib_socket_init (s)))
653  {
654  clib_error_report (error);
655  return;
656  }
657 
658  clib_file_t template = { 0 };
660  template.file_descriptor = s->fd;
661  template.description = format (0, "stats segment listener %s", s->config);
662  clib_file_add (&file_main, &template);
663 
664  sm->socket = s;
665 }
666 
667 static clib_error_t *
669 {
670  /*
671  * cleanup the listener socket on exit.
672  */
674  unlink ((char *) sm->socket_name);
675  return 0;
676 }
677 
679 
680 static uword
682  vlib_frame_t * f)
683 {
685 
686  /* Wait for Godot... */
687  f64 sleep_duration = 10;
688 
689  while (1)
690  {
692  vlib_process_suspend (vm, sleep_duration);
693  }
694  return 0; /* or not */
695 }
696 
697 static clib_error_t *
699 {
701  clib_error_t *error;
702 
703  /* dependent on unix_input_init */
704  if ((error = vlib_call_init_function (vm, unix_input_init)))
705  return error;
706 
707  if (sm->socket_name)
709 
710  return 0;
711 }
712 
713 clib_error_t *
715  u32 caller_index)
716 {
718  stat_segment_shared_header_t *shared_header = sm->shared_header;
719  void *oldheap;
721  u32 index;
723 
724  ASSERT (shared_header);
725 
726  oldheap = vlib_stats_push_heap (NULL);
728 
729  memset (&e, 0, sizeof (e));
731 
732  memcpy (e.name, name, vec_len (name));
733  index = vec_len (sm->directory_vector);
734  vec_add1 (sm->directory_vector, e);
735 
736  shared_header->directory_offset =
737  stat_segment_offset (shared_header, sm->directory_vector);
738 
740  clib_mem_set_heap (oldheap);
741 
742  /* Back on our own heap */
743  pool_get (sm->gauges, gauge);
744  gauge->fn = update_fn;
745  gauge->caller_index = caller_index;
746  gauge->directory_index = index;
747 
748  return NULL;
749 }
750 
751 static clib_error_t *
753 {
755 
756  /* set default socket file name when statseg config stanza is empty. */
758 
760  {
761  if (unformat (input, "socket-name %s", &sm->socket_name))
762  ;
763  else if (unformat (input, "default"))
765  else
766  if (unformat
767  (input, "size %U", unformat_memory_size, &sm->memory_size))
768  ;
769  else if (unformat (input, "per-node-counters on"))
770  sm->node_counters_enabled = 1;
771  else if (unformat (input, "per-node-counters off"))
772  sm->node_counters_enabled = 0;
773  else
774  return clib_error_return (0, "unknown input `%U'",
775  format_unformat_error, input);
776  }
777  return 0;
778 }
779 
780 static clib_error_t *
782 {
784  stat_segment_shared_header_t *shared_header = sm->shared_header;
785 
786  void *oldheap = vlib_stats_push_heap (sm->interfaces);
788 
789  vec_validate (sm->interfaces, sw_if_index);
790  if (is_add)
791  {
792  vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
793  vnet_sw_interface_t *si_sup =
795  vnet_hw_interface_t *hi_sup;
796 
798  hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index);
799 
800  u8 *s = 0;
801  s = format (s, "%v", hi_sup->name);
803  s = format (s, ".%d", si->sub.id);
804  s = format (s, "%c", 0);
805  sm->interfaces[sw_if_index] = s;
806  }
807  else
808  {
809  vec_free (sm->interfaces[sw_if_index]);
810  sm->interfaces[sw_if_index] = 0;
811  }
812 
815  ep->offset = stat_segment_offset (shared_header, sm->interfaces);
816 
817  int i;
818  u64 *offset_vector =
819  ep->offset_vector ? stat_segment_pointer (shared_header,
820  ep->offset_vector) : 0;
821 
822  vec_validate (offset_vector, vec_len (sm->interfaces) - 1);
823 
824  if (sm->last != sm->interfaces)
825  {
826  /* the interface vector moved, so need to recalulate the offset array */
827  for (i = 0; i < vec_len (sm->interfaces); i++)
828  {
829  offset_vector[i] =
830  sm->interfaces[i] ? stat_segment_offset (shared_header,
831  sm->interfaces[i]) : 0;
832  }
833  }
834  else
835  {
836  offset_vector[sw_if_index] =
837  sm->interfaces[sw_if_index] ?
838  stat_segment_offset (shared_header, sm->interfaces[sw_if_index]) : 0;
839  }
840  ep->offset_vector = stat_segment_offset (shared_header, offset_vector);
841 
843  clib_mem_set_heap (oldheap);
844 
845  return 0;
846 }
847 
851 
852 /* *INDENT-OFF* */
854 {
856 .name = "statseg-collector-process",
857 .type = VLIB_NODE_TYPE_PROCESS,
858 };
859 
860 /* *INDENT-ON* */
861 
862 /*
863  * fd.io coding-style-patch-verification: ON
864  *
865  * Local Variables:
866  * eval: (c-set-style "gnu")
867  * End:
868  */
static clib_error_t * statseg_config(vlib_main_t *vm, unformat_input_t *input)
Definition: stat_segment.c:752
#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:618
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: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: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:525
#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:698
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:641
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: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:668
#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:714
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:853
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:681
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:781
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