FD.io VPP  v19.04.1-1-ge4a0f9f
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
156 {
158  stat_segment_shared_header_t *shared_header = sm->shared_header;
160  hash_pair_t *hp;
161 
162  ASSERT (shared_header);
163 
165 
166  memcpy (e.name, name, vec_len (name));
167  e.name[vec_len (name)] = '\0';
169  e.offset = index;
170  e.offset_vector = 0;
171  vec_add1 (sm->directory_vector, e);
172 
173  /* Warn clients to refresh any pointers they might be holding */
174  shared_header->directory_offset =
175  stat_segment_offset (shared_header, sm->directory_vector);
176 
178 }
179 
180 static void
182 {
184  stat_segment_shared_header_t *shared_header = sm->shared_header;
185  counter_t **counters = 0;
187  int i;
188  u64 *offset_vector = 0;
189 
190  vec_validate_aligned (counters, tm->n_vlib_mains - 1,
192  for (i = 0; i < tm->n_vlib_mains; i++)
193  {
194  vec_validate_aligned (counters[i], max, CLIB_CACHE_LINE_BYTES);
195  vec_add1 (offset_vector,
196  stat_segment_offset (shared_header, counters[i]));
197  }
198  ep->offset = stat_segment_offset (shared_header, counters);
199  ep->offset_vector = stat_segment_offset (shared_header, offset_vector);
200 }
201 
202 void
203 vlib_stats_pop_heap2 (u64 * error_vector, u32 thread_index, void *oldheap)
204 {
206  stat_segment_shared_header_t *shared_header = sm->shared_header;
207 
208  ASSERT (shared_header);
209 
211 
212  /* Reset the client hash table pointer, since it WILL change! */
213  shared_header->error_offset =
214  stat_segment_offset (shared_header, error_vector);
215  shared_header->directory_offset =
216  stat_segment_offset (shared_header, sm->directory_vector);
217 
219  clib_mem_set_heap (oldheap);
220 }
221 
222 clib_error_t *
224 {
226  stat_segment_shared_header_t *shared_header;
228  void *oldheap;
229  ssize_t memory_size;
230  int mfd;
231  char *mem_name = "stat_segment_test";
232  void *memaddr;
233 
234  memory_size = sm->memory_size;
235  if (memory_size == 0)
236  memory_size = STAT_SEGMENT_DEFAULT_SIZE;
237 
238  /* Create shared memory segment */
239  if ((mfd = memfd_create (mem_name, 0)) < 0)
240  return clib_error_return (0, "stat segment memfd_create failure");
241 
242  /* Set size */
243  if ((ftruncate (mfd, memory_size)) == -1)
244  return clib_error_return (0, "stat segment ftruncate failure");
245 
246  if ((memaddr =
247  mmap (NULL, memory_size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd,
248  0)) == MAP_FAILED)
249  return clib_error_return (0, "stat segment mmap failure");
250 
251  void *heap;
252 #if USE_DLMALLOC == 0
253  heap = mheap_alloc_with_flags (((u8 *) memaddr) + getpagesize (),
254  memory_size - getpagesize (),
257 #else
258  heap =
259  create_mspace_with_base (((u8 *) memaddr) + getpagesize (),
260  memory_size - getpagesize (), 1 /* locked */ );
261  mspace_disable_expand (heap);
262 #endif
263 
264  sm->heap = heap;
265  sm->memfd = mfd;
266 
268  sm->shared_header = shared_header = memaddr;
271 
272  oldheap = clib_mem_set_heap (sm->heap);
273 
274  /* Set up the name to counter-vector hash table */
275  sm->directory_vector = 0;
276 
277  shared_header->epoch = 1;
278 
279  /* Scalar stats and node counters */
281 #define _(E,t,n,p) \
282  strcpy(sm->directory_vector[STAT_COUNTER_##E].name, #p "/" #n); \
283  sm->directory_vector[STAT_COUNTER_##E].type = STAT_DIR_TYPE_##t;
285 #undef _
286  /* Save the vector offset in the shared segment, for clients */
287  shared_header->directory_offset =
288  stat_segment_offset (shared_header, sm->directory_vector);
289 
290  clib_mem_set_heap (oldheap);
291 
292  return 0;
293 }
294 
295 static int
296 name_sort_cmp (void *a1, void *a2)
297 {
300 
301  return strcmp ((char *) n1->name, (char *) n2->name);
302 }
303 
304 static u8 *
305 format_stat_dir_entry (u8 * s, va_list * args)
306 {
308  va_arg (*args, stat_segment_directory_entry_t *);
309  char *type_name;
310  char *format_string;
311 
312  format_string = "%-74s %-10s %10lld";
313 
314  switch (ep->type)
315  {
317  type_name = "ScalarPtr";
318  break;
319 
322  type_name = "CMainPtr";
323  break;
324 
326  type_name = "ErrIndex";
327  break;
328 
329  default:
330  type_name = "illegal!";
331  break;
332  }
333 
334  return format (s, format_string, ep->name, type_name, ep->offset);
335 }
336 
337 static clib_error_t *
339  unformat_input_t * input,
340  vlib_cli_command_t * cmd)
341 {
343  counter_t *counter;
344  hash_pair_t *p;
345  stat_segment_directory_entry_t *show_data, *this;
346  int i, j;
347 
348  int verbose = 0;
349  u8 *s;
350 
351  if (unformat (input, "verbose"))
352  verbose = 1;
353 
354  /* Lock even as reader, as this command doesn't handle epoch changes */
356  show_data = vec_dup (sm->directory_vector);
358 
360 
361  vlib_cli_output (vm, "%-74s %10s %10s", "Name", "Type", "Value");
362 
363  for (i = 0; i < vec_len (show_data); i++)
364  {
365  vlib_cli_output (vm, "%-100U", format_stat_dir_entry,
366  vec_elt_at_index (show_data, i));
367  }
368 
369  if (verbose)
370  {
371  ASSERT (sm->heap);
372  vlib_cli_output (vm, "%U", format_mheap, sm->heap, 0 /* verbose */ );
373  }
374 
375  return 0;
376 }
377 
378 /* *INDENT-OFF* */
379 VLIB_CLI_COMMAND (show_stat_segment_command, static) =
380 {
381  .path = "show statistics segment",
382  .short_help = "show statistics segment [verbose]",
383  .function = show_stat_segment_command_fn,
384 };
385 /* *INDENT-ON* */
386 
387 /*
388  * Node performance counters:
389  * total_calls [threads][node-index]
390  * total_vectors
391  * total_calls
392  * total suspends
393  */
394 
395 static inline void
397 {
398  vlib_main_t *vm = vlib_mains[0];
399  vlib_main_t **stat_vms = 0;
400  vlib_node_t ***node_dups = 0;
401  int i, j;
402  stat_segment_shared_header_t *shared_header = sm->shared_header;
403  static u32 no_max_nodes = 0;
404 
405  vlib_node_get_nodes (0 /* vm, for barrier sync */ ,
406  (u32) ~ 0 /* all threads */ ,
407  1 /* include stats */ ,
408  0 /* barrier sync */ ,
409  &node_dups, &stat_vms);
410 
411  u32 l = vec_len (node_dups[0]);
412 
413  /*
414  * Extend performance nodes if necessary
415  */
416  if (l > no_max_nodes)
417  {
418  void *oldheap = clib_mem_set_heap (sm->heap);
420 
429 
430  vec_validate (sm->nodes, l);
433  ep->offset = stat_segment_offset (shared_header, sm->nodes);
434 
435  int i;
436  u64 *offset_vector =
437  ep->offset_vector ? stat_segment_pointer (shared_header,
438  ep->offset_vector) : 0;
439  /* Update names dictionary */
440  vec_validate (offset_vector, l);
441  vlib_node_t **nodes = node_dups[0];
442  for (i = 0; i < vec_len (nodes); i++)
443  {
444  vlib_node_t *n = nodes[i];
445  u8 *s = 0;
446  s = format (s, "%v%c", n->name, 0);
447  if (sm->nodes[n->index])
448  vec_free (sm->nodes[n->index]);
449  sm->nodes[n->index] = s;
450  offset_vector[i] =
451  sm->nodes[i] ? stat_segment_offset (shared_header,
452  sm->nodes[i]) : 0;
453 
454  }
455  ep->offset_vector = stat_segment_offset (shared_header, offset_vector);
456 
458  clib_mem_set_heap (oldheap);
459  no_max_nodes = l;
460  }
461 
462  for (j = 0; j < vec_len (node_dups); j++)
463  {
464  vlib_node_t **nodes = node_dups[j];
465  u32 l = vec_len (nodes);
466 
467  for (i = 0; i < vec_len (nodes); i++)
468  {
469  counter_t **counters;
470  counter_t *c;
471  vlib_node_t *n = nodes[i];
472 
473  counters =
474  stat_segment_pointer (shared_header,
475  sm->directory_vector
477  c = counters[j];
479 
480  counters =
481  stat_segment_pointer (shared_header,
482  sm->directory_vector
484  c = counters[j];
486 
487  counters =
488  stat_segment_pointer (shared_header,
489  sm->directory_vector
491  c = counters[j];
492  c[n->index] = n->stats_total.calls - n->stats_last_clear.calls;
493 
494  counters =
495  stat_segment_pointer (shared_header,
496  sm->directory_vector
498  c = counters[j];
499  c[n->index] =
501  }
502  }
503 }
504 
505 static void
507 {
508  vlib_main_t *vm = vlib_mains[0];
509  f64 vector_rate;
510  u64 input_packets, last_input_packets;
511  f64 dt, now;
512  vlib_main_t *this_vlib_main;
513  int i, start;
514 
515  /*
516  * Compute the average vector rate across all workers
517  */
518  vector_rate = 0.0;
519 
520  start = vec_len (vlib_mains) > 1 ? 1 : 0;
521 
522  for (i = start; i < vec_len (vlib_mains); i++)
523  {
524  this_vlib_main = vlib_mains[i];
525  vector_rate += vlib_last_vector_length_per_node (this_vlib_main);
526  }
527  vector_rate /= (f64) (i - start);
528 
530  vector_rate / ((f64) (vec_len (vlib_mains) - start));
531 
532  /*
533  * Compute the aggregate input rate
534  */
535  now = vlib_time_now (vm);
537  input_packets = vnet_get_aggregate_rx_packets ();
539  (f64) (input_packets - sm->last_input_packets) / dt;
541  sm->last_input_packets = input_packets;
544 
545  if (sm->node_counters_enabled)
547 
548  /* *INDENT-OFF* */
550  pool_foreach(g, sm->gauges,
551  ({
552  g->fn(&sm->directory_vector[g->directory_index], g->caller_index);
553  }));
554  /* *INDENT-ON* */
555 
556  /* Heartbeat, so clients detect we're still here */
558 }
559 
560 /*
561  * Accept connection on the socket and exchange the fd for the shared
562  * memory segment.
563  */
564 static clib_error_t *
566 {
568  clib_error_t *err;
569  clib_socket_t client = { 0 };
570 
571  err = clib_socket_accept (sm->socket, &client);
572  if (err)
573  {
574  clib_error_report (err);
575  return err;
576  }
577 
578  /* Send the fd across and close */
579  err = clib_socket_sendmsg (&client, 0, 0, &sm->memfd, 1);
580  if (err)
581  clib_error_report (err);
582  clib_socket_close (&client);
583 
584  return 0;
585 }
586 
587 static void
589 {
591  clib_error_t *error;
593 
594  memset (s, 0, sizeof (clib_socket_t));
595  s->config = (char *) sm->socket_name;
598 
599  if ((error = clib_socket_init (s)))
600  {
601  clib_error_report (error);
602  return;
603  }
604 
605  clib_file_t template = { 0 };
607  template.file_descriptor = s->fd;
608  template.description = format (0, "stats segment listener %s", s->config);
609  clib_file_add (&file_main, &template);
610 
611  sm->socket = s;
612 }
613 
614 static clib_error_t *
616 {
617  /*
618  * cleanup the listener socket on exit.
619  */
621  unlink ((char *) sm->socket_name);
622  return 0;
623 }
624 
626 
627 static uword
629  vlib_frame_t * f)
630 {
632 
633  /* Wait for Godot... */
634  f64 sleep_duration = 10;
635 
636  while (1)
637  {
639  vlib_process_suspend (vm, sleep_duration);
640  }
641  return 0; /* or not */
642 }
643 
644 static clib_error_t *
646 {
648  clib_error_t *error;
649 
650  /* dependent on unix_input_init */
651  if ((error = vlib_call_init_function (vm, unix_input_init)))
652  return error;
653 
654  if (sm->socket_name)
656 
657  return 0;
658 }
659 
660 clib_error_t *
662  u32 caller_index)
663 {
665  stat_segment_shared_header_t *shared_header = sm->shared_header;
666  void *oldheap;
668  u32 index;
670 
671  ASSERT (shared_header);
672 
673  oldheap = vlib_stats_push_heap (NULL);
675 
676  memset (&e, 0, sizeof (e));
678 
679  memcpy (e.name, name, vec_len (name));
680  index = vec_len (sm->directory_vector);
681  vec_add1 (sm->directory_vector, e);
682 
683  shared_header->directory_offset =
684  stat_segment_offset (shared_header, sm->directory_vector);
685 
687  clib_mem_set_heap (oldheap);
688 
689  /* Back on our own heap */
690  pool_get (sm->gauges, gauge);
691  gauge->fn = update_fn;
692  gauge->caller_index = caller_index;
693  gauge->directory_index = index;
694 
695  return NULL;
696 }
697 
698 static clib_error_t *
700 {
702 
703  /* set default socket file name when statseg config stanza is empty. */
705 
707  {
708  if (unformat (input, "socket-name %s", &sm->socket_name))
709  ;
710  else if (unformat (input, "default"))
712  else
713  if (unformat
714  (input, "size %U", unformat_memory_size, &sm->memory_size))
715  ;
716  else if (unformat (input, "per-node-counters on"))
717  sm->node_counters_enabled = 1;
718  else if (unformat (input, "per-node-counters off"))
719  sm->node_counters_enabled = 0;
720  else
721  return clib_error_return (0, "unknown input `%U'",
722  format_unformat_error, input);
723  }
724  return 0;
725 }
726 
727 static clib_error_t *
729 {
731  stat_segment_shared_header_t *shared_header = sm->shared_header;
732 
733  void *oldheap = vlib_stats_push_heap (sm->interfaces);
735 
736  vec_validate (sm->interfaces, sw_if_index);
737  if (is_add)
738  {
739  vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
740  vnet_sw_interface_t *si_sup =
742  vnet_hw_interface_t *hi_sup;
743 
745  hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index);
746 
747  u8 *s = 0;
748  s = format (s, "%v", hi_sup->name);
750  s = format (s, ".%d", si->sub.id);
751  s = format (s, "%c", 0);
752  sm->interfaces[sw_if_index] = s;
753  }
754  else
755  {
756  vec_free (sm->interfaces[sw_if_index]);
757  sm->interfaces[sw_if_index] = 0;
758  }
759 
762  ep->offset = stat_segment_offset (shared_header, sm->interfaces);
763 
764  int i;
765  u64 *offset_vector =
766  ep->offset_vector ? stat_segment_pointer (shared_header,
767  ep->offset_vector) : 0;
768 
769  vec_validate (offset_vector, vec_len (sm->interfaces) - 1);
770 
771  if (sm->last != sm->interfaces)
772  {
773  /* the interface vector moved, so need to recalulate the offset array */
774  for (i = 0; i < vec_len (sm->interfaces); i++)
775  {
776  offset_vector[i] =
777  sm->interfaces[i] ? stat_segment_offset (shared_header,
778  sm->interfaces[i]) : 0;
779  }
780  }
781  else
782  {
783  offset_vector[sw_if_index] =
784  sm->interfaces[sw_if_index] ?
785  stat_segment_offset (shared_header, sm->interfaces[sw_if_index]) : 0;
786  }
787  ep->offset_vector = stat_segment_offset (shared_header, offset_vector);
788 
790  clib_mem_set_heap (oldheap);
791 
792  return 0;
793 }
794 
798 
799 /* *INDENT-OFF* */
801 {
803 .name = "statseg-collector-process",
804 .type = VLIB_NODE_TYPE_PROCESS,
805 };
806 
807 /* *INDENT-ON* */
808 
809 /*
810  * fd.io coding-style-patch-verification: ON
811  *
812  * Local Variables:
813  * eval: (c-set-style "gnu")
814  * End:
815  */
static clib_error_t * statseg_config(vlib_main_t *vm, unformat_input_t *input)
Definition: stat_segment.c:699
#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:53
#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:103
static clib_error_t * unix_input_init(vlib_main_t *vm)
Definition: input.c:412
void vlib_stats_register_error_index(u8 *name, u64 *em_vec, u64 index)
Definition: stat_segment.c:155
static u64 vnet_get_aggregate_rx_packets(void)
Definition: devices.h:98
stat_segment_shared_header_t * shared_header
Definition: stat_segment.h:118
static clib_error_t * stats_socket_accept_ready(clib_file_t *uf)
Definition: stat_segment.c:565
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:107
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:81
static void stat_validate_counter_vector(stat_segment_directory_entry_t *ep, u32 max)
Definition: stat_segment.c:181
static int memfd_create(const char *name, unsigned int flags)
Definition: syscall.h:52
#define STAT_SEGMENT_DEFAULT_SIZE
Definition: stat_segment.h:66
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:40
#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:92
atomic_int_fast64_t in_progress
Definition: stat_segment.h:74
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:59
#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:506
#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:96
unsigned int u32
Definition: types.h:88
static clib_error_t * statseg_init(vlib_main_t *vm)
Definition: stat_segment.c:645
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:87
static void stats_segment_socket_init(void)
Definition: stat_segment.c:588
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:305
void vlib_stat_segment_unlock(void)
Definition: stat_segment.c:39
uint64_t offset
Definition: stat_segment.h:57
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:615
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:375
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:661
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:800
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:61
#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:62
#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:73
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:628
uword * directory_vector_by_name
Definition: stat_segment.h:106
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:396
#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:296
static clib_error_t * statseg_sw_interface_add_del(vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
Definition: stat_segment.c:728
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:338
unformat_function_t unformat_memory_size
Definition: format.h:295
clib_socket_t * socket
Definition: stat_segment.h:112
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
#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:223
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:725
atomic_int_fast64_t error_offset
Definition: stat_segment.h:76
void vlib_stats_pop_heap2(u64 *error_vector, u32 thread_index, void *oldheap)
Definition: stat_segment.c:203
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
clib_spinlock_t * stat_segment_lockp
Definition: stat_segment.h:111
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170
atomic_int_fast64_t directory_offset
Definition: stat_segment.h:75
stat_directory_type_t type
Definition: stat_segment.h:55