summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/vnet/ip/ip_api.c1
-rw-r--r--src/vpp/CMakeLists.txt2
-rw-r--r--src/vpp/api/api.c2
-rw-r--r--src/vpp/api/custom_dump.c1
-rw-r--r--src/vpp/app/vpp_get_stats.c1
-rw-r--r--src/vpp/stats/stat_segment.c145
-rw-r--r--src/vpp/stats/stat_segment.h21
-rw-r--r--src/vpp/stats/stats_to_be_deprecated.c (renamed from src/vpp/stats/stats.c)68
-rw-r--r--src/vpp/stats/stats_to_be_deprecated.h (renamed from src/vpp/stats/stats.h)17
9 files changed, 147 insertions, 111 deletions
diff --git a/src/vnet/ip/ip_api.c b/src/vnet/ip/ip_api.c
index bed5889b24a..477090d07f1 100644
--- a/src/vnet/ip/ip_api.c
+++ b/src/vnet/ip/ip_api.c
@@ -20,7 +20,6 @@
#include <vnet/vnet.h>
#include <vlibmemory/api.h>
-#include <vpp/stats/stats.h>
#include <vnet/interface.h>
#include <vnet/api_errno.h>
#include <vnet/ethernet/ethernet.h>
diff --git a/src/vpp/CMakeLists.txt b/src/vpp/CMakeLists.txt
index 999b2808e87..601bc0397d6 100644
--- a/src/vpp/CMakeLists.txt
+++ b/src/vpp/CMakeLists.txt
@@ -56,7 +56,7 @@ set(VPP_SOURCES
app/version.c
oam/oam.c
oam/oam_api.c
- stats/stats.c
+ stats/stats_to_be_deprecated.c
stats/stat_segment.c
api/api.c
api/json_format.c
diff --git a/src/vpp/api/api.c b/src/vpp/api/api.c
index f7643f423f3..d69b84fd0b9 100644
--- a/src/vpp/api/api.c
+++ b/src/vpp/api/api.c
@@ -56,7 +56,7 @@
#undef BIHASH_TYPE
#undef __included_bihash_template_h__
-#include <vpp/stats/stats.h>
+#include <vnet/ip/format.h>
#include <vpp/api/vpe_msg_enum.h>
diff --git a/src/vpp/api/custom_dump.c b/src/vpp/api/custom_dump.c
index f8a8b738b9a..baa675c908d 100644
--- a/src/vpp/api/custom_dump.c
+++ b/src/vpp/api/custom_dump.c
@@ -40,7 +40,6 @@
#include <vlibmemory/api.h>
#include <vnet/lisp-cp/lisp_types.h>
#include <vnet/qos/qos_types.h>
-#include <vpp/stats/stats.h>
#include <vpp/oam/oam.h>
#include <vnet/ethernet/ethernet.h>
diff --git a/src/vpp/app/vpp_get_stats.c b/src/vpp/app/vpp_get_stats.c
index c1a5acb797c..1852b772b5e 100644
--- a/src/vpp/app/vpp_get_stats.c
+++ b/src/vpp/app/vpp_get_stats.c
@@ -19,7 +19,6 @@
#include <vpp-api/client/stat_client.h>
#include <vlib/vlib.h>
-#include <vpp/stats/stats.h>
static int
stat_poll_loop (u8 ** patterns)
diff --git a/src/vpp/stats/stat_segment.c b/src/vpp/stats/stat_segment.c
index 7bf6624e075..37beb94cb41 100644
--- a/src/vpp/stats/stat_segment.c
+++ b/src/vpp/stats/stat_segment.c
@@ -14,17 +14,23 @@
*/
#include <vppinfra/mem.h>
-#include <vpp/stats/stats.h>
+#include <vlib/vlib.h>
+#include <vlib/unix/unix.h>
+#include "stat_segment.h"
+#include <vnet/vnet.h>
+#include <vnet/devices/devices.h> /* vnet_get_aggregate_rx_packets */
#undef HAVE_MEMFD_CREATE
#include <vppinfra/linux/syscall.h>
+stat_segment_main_t stat_segment_main;
+
/*
* Used only by VPP writers
*/
void
vlib_stat_segment_lock (void)
{
- stats_main_t *sm = &stats_main;
+ stat_segment_main_t *sm = &stat_segment_main;
clib_spinlock_lock (sm->stat_segment_lockp);
sm->shared_header->in_progress = 1;
}
@@ -32,7 +38,7 @@ vlib_stat_segment_lock (void)
void
vlib_stat_segment_unlock (void)
{
- stats_main_t *sm = &stats_main;
+ stat_segment_main_t *sm = &stat_segment_main;
sm->shared_header->epoch++;
sm->shared_header->in_progress = 0;
clib_spinlock_unlock (sm->stat_segment_lockp);
@@ -44,7 +50,7 @@ vlib_stat_segment_unlock (void)
void *
vlib_stats_push_heap (void)
{
- stats_main_t *sm = &stats_main;
+ stat_segment_main_t *sm = &stat_segment_main;
ASSERT (sm && sm->shared_header);
return clib_mem_set_heap (sm->heap);
@@ -54,7 +60,7 @@ vlib_stats_push_heap (void)
static u32
lookup_or_create_hash_index (void *oldheap, char *name, u32 next_vector_index)
{
- stats_main_t *sm = &stats_main;
+ stat_segment_main_t *sm = &stat_segment_main;
u32 index;
hash_pair_t *hp;
@@ -76,7 +82,7 @@ void
vlib_stats_pop_heap (void *cm_arg, void *oldheap, stat_directory_type_t type)
{
vlib_simple_counter_main_t *cm = (vlib_simple_counter_main_t *) cm_arg;
- stats_main_t *sm = &stats_main;
+ stat_segment_main_t *sm = &stat_segment_main;
stat_segment_shared_header_t *shared_header = sm->shared_header;
char *stat_segment_name;
stat_segment_directory_entry_t e = { 0 };
@@ -138,7 +144,7 @@ vlib_stats_pop_heap (void *cm_arg, void *oldheap, stat_directory_type_t type)
void
vlib_stats_register_error_index (u8 * name, u64 * em_vec, u64 index)
{
- stats_main_t *sm = &stats_main;
+ stat_segment_main_t *sm = &stat_segment_main;
stat_segment_shared_header_t *shared_header = sm->shared_header;
stat_segment_directory_entry_t e;
hash_pair_t *hp;
@@ -163,7 +169,7 @@ vlib_stats_register_error_index (u8 * name, u64 * em_vec, u64 index)
static void
stat_validate_counter_vector (stat_segment_directory_entry_t * ep, u32 max)
{
- stats_main_t *sm = &stats_main;
+ stat_segment_main_t *sm = &stat_segment_main;
stat_segment_shared_header_t *shared_header = sm->shared_header;
counter_t **counters = 0;
vlib_thread_main_t *tm = vlib_get_thread_main ();
@@ -185,7 +191,7 @@ stat_validate_counter_vector (stat_segment_directory_entry_t * ep, u32 max)
void
vlib_stats_pop_heap2 (u64 * error_vector, u32 thread_index, void *oldheap)
{
- stats_main_t *sm = &stats_main;
+ stat_segment_main_t *sm = &stat_segment_main;
stat_segment_shared_header_t *shared_header = sm->shared_header;
ASSERT (shared_header);
@@ -205,7 +211,7 @@ vlib_stats_pop_heap2 (u64 * error_vector, u32 thread_index, void *oldheap)
clib_error_t *
vlib_map_stat_segment_init (void)
{
- stats_main_t *sm = &stats_main;
+ stat_segment_main_t *sm = &stat_segment_main;
stat_segment_shared_header_t *shared_header;
stat_segment_directory_entry_t *ep;
@@ -329,7 +335,7 @@ show_stat_segment_command_fn (vlib_main_t * vm,
unformat_input_t * input,
vlib_cli_command_t * cmd)
{
- stats_main_t *sm = &stats_main;
+ stat_segment_main_t *sm = &stat_segment_main;
counter_t *counter;
hash_pair_t *p;
stat_segment_directory_entry_t *show_data, *this;
@@ -383,7 +389,7 @@ VLIB_CLI_COMMAND (show_stat_segment_command, static) =
*/
static inline void
-update_node_counters (stats_main_t * sm)
+update_node_counters (stat_segment_main_t * sm)
{
vlib_main_t *vm = vlib_mains[0];
vlib_main_t **stat_vms = 0;
@@ -465,14 +471,8 @@ update_node_counters (stats_main_t * sm)
}
}
-/*
- * Called by stats_thread_fn, in stats.c, which runs in a
- * separate pthread, which won't halt the parade
- * in single-forwarding-core cases.
- */
-
-void
-do_stat_segment_updates (stats_main_t * sm)
+static void
+do_stat_segment_updates (stat_segment_main_t * sm)
{
vlib_main_t *vm = vlib_mains[0];
f64 vector_rate;
@@ -518,15 +518,105 @@ do_stat_segment_updates (stats_main_t * sm)
sm->directory_vector[STAT_COUNTER_HEARTBEAT].value++;
}
+/*
+ * Accept connection on the socket and exchange the fd for the shared
+ * memory segment.
+ */
+static clib_error_t *
+stats_socket_accept_ready (clib_file_t * uf)
+{
+ stat_segment_main_t *sm = &stat_segment_main;
+ clib_error_t *err;
+ clib_socket_t client = { 0 };
+
+ err = clib_socket_accept (sm->socket, &client);
+ if (err)
+ {
+ clib_error_report (err);
+ return err;
+ }
+
+ /* Send the fd across and close */
+ err = clib_socket_sendmsg (&client, 0, 0, &sm->memfd, 1);
+ if (err)
+ clib_error_report (err);
+ clib_socket_close (&client);
+
+ return 0;
+}
+
+static void
+stats_segment_socket_init (void)
+{
+ stat_segment_main_t *sm = &stat_segment_main;
+ clib_error_t *error;
+ clib_socket_t *s = clib_mem_alloc (sizeof (clib_socket_t));
+
+ s->config = (char *) sm->socket_name;
+ s->flags = CLIB_SOCKET_F_IS_SERVER | CLIB_SOCKET_F_SEQPACKET |
+ CLIB_SOCKET_F_ALLOW_GROUP_WRITE | CLIB_SOCKET_F_PASSCRED;
+ if ((error = clib_socket_init (s)))
+ {
+ clib_error_report (error);
+ return;
+ }
+
+ clib_file_t template = { 0 };
+ template.read_function = stats_socket_accept_ready;
+ template.file_descriptor = s->fd;
+ template.description =
+ format (0, "stats segment listener %s", STAT_SEGMENT_SOCKET_FILE);
+ clib_file_add (&file_main, &template);
+
+ sm->socket = s;
+}
+
+static uword
+stat_segment_collector_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
+ vlib_frame_t * f)
+{
+ stat_segment_main_t *sm = &stat_segment_main;
+
+ /* Wait for Godot... */
+ f64 sleep_duration = 10;
+
+ while (1)
+ {
+ do_stat_segment_updates (sm);
+ vlib_process_suspend (vm, sleep_duration);
+ }
+ return 0; /* or not */
+}
+
+static clib_error_t *
+statseg_init (vlib_main_t * vm)
+{
+ stat_segment_main_t *sm = &stat_segment_main;
+ clib_error_t *error;
+
+ if ((error = vlib_call_init_function (vm, unix_input_init)))
+ return error;
+
+ if (sm->socket_name)
+ stats_segment_socket_init ();
+
+ return 0;
+}
+
static clib_error_t *
statseg_config (vlib_main_t * vm, unformat_input_t * input)
{
- stats_main_t *sm = &stats_main;
- uword ms;
+ stat_segment_main_t *sm = &stat_segment_main;
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
- if (unformat (input, "size %U", unformat_memory_size, &sm->memory_size))
+ if (unformat (input, "socket-name %s", &sm->socket_name))
+ ;
+ else if (unformat (input, "default"))
+ sm->socket_name = format (0, "%s", STAT_SEGMENT_SOCKET_FILE);
+ else
+ if (unformat
+ (input, "size %U", unformat_memory_size, &sm->memory_size))
;
else if (unformat (input, "per-node-counters on"))
sm->node_counters_enabled = 1;
@@ -540,8 +630,17 @@ statseg_config (vlib_main_t * vm, unformat_input_t * input)
return 0;
}
+VLIB_INIT_FUNCTION (statseg_init);
VLIB_EARLY_CONFIG_FUNCTION (statseg_config, "statseg");
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (stat_segment_collector, static) =
+{
+.function = stat_segment_collector_process,.name =
+ "statseg-collector-process",.type = VLIB_NODE_TYPE_PROCESS,};
+
+/* *INDENT-ON* */
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vpp/stats/stat_segment.h b/src/vpp/stats/stat_segment.h
index 0efd45ac5f0..21c7c3b0d48 100644
--- a/src/vpp/stats/stat_segment.h
+++ b/src/vpp/stats/stat_segment.h
@@ -17,6 +17,8 @@
#define included_stat_segment_h
#include <stdatomic.h>
+#include <vlib/vlib.h>
+#include <vppinfra/socket.h>
/* Default socket to exchange segment fd */
#define STAT_SEGMENT_SOCKET_FILE "/run/vpp/stats.sock"
@@ -94,4 +96,23 @@ stat_segment_pointer (void *start, uint64_t offset)
return ((char *) start + offset);
}
+typedef struct
+{
+ /* statistics segment */
+ uword *directory_vector_by_name;
+ stat_segment_directory_entry_t *directory_vector;
+ clib_spinlock_t *stat_segment_lockp;
+ clib_socket_t *socket;
+ u8 *socket_name;
+ ssize_t memory_size;
+ u8 node_counters_enabled;
+ void *heap;
+ stat_segment_shared_header_t *shared_header; /* pointer to shared memory segment */
+ int memfd;
+
+ u64 last_input_packets;
+} stat_segment_main_t;
+
+extern stat_segment_main_t stat_segment_main;
+
#endif
diff --git a/src/vpp/stats/stats.c b/src/vpp/stats/stats_to_be_deprecated.c
index 25b8c184546..94d68c839d5 100644
--- a/src/vpp/stats/stats.c
+++ b/src/vpp/stats/stats_to_be_deprecated.c
@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <vpp/stats/stats.h>
+#include "stats_to_be_deprecated.h"
#include <signal.h>
#include <vnet/fib/ip4_fib.h>
#include <vnet/fib/fib_entry.h>
@@ -2338,60 +2338,6 @@ stats_set_poller_delay (u32 poller_delay_sec)
}
}
-/*
- * Accept connection on the socket and exchange the fd for the shared
- * memory segment.
- */
-static clib_error_t *
-stats_socket_accept_ready (clib_file_t * uf)
-{
- stats_main_t *sm = &stats_main;
- clib_error_t *err;
- clib_socket_t client = { 0 };
-
- err = clib_socket_accept (sm->socket, &client);
- if (err)
- {
- clib_error_report (err);
- return err;
- }
-
- /* Send the fd across and close */
- err = clib_socket_sendmsg (&client, 0, 0, &sm->memfd, 1);
- if (err)
- clib_error_report (err);
- clib_socket_close (&client);
-
- return 0;
-}
-
-static void
-stats_segment_socket_init (void)
-{
- stats_main_t *sm = &stats_main;
- clib_error_t *error;
- clib_socket_t *s = clib_mem_alloc (sizeof (clib_socket_t));
-
- s->config = (char *) sm->socket_name;
- s->flags = CLIB_SOCKET_F_IS_SERVER | CLIB_SOCKET_F_SEQPACKET |
- CLIB_SOCKET_F_ALLOW_GROUP_WRITE | CLIB_SOCKET_F_PASSCRED;
- if ((error = clib_socket_init (s)))
- {
- clib_error_report (error);
- return;
- }
-
- clib_file_t template = { 0 };
- clib_file_main_t *fm = &file_main;
- template.read_function = stats_socket_accept_ready;
- template.file_descriptor = s->fd;
- template.description =
- format (0, "stats segment listener %s", STAT_SEGMENT_SOCKET_FILE);
- clib_file_add (fm, &template);
-
- sm->socket = s;
-}
-
static clib_error_t *
stats_config (vlib_main_t * vm, unformat_input_t * input)
{
@@ -2400,11 +2346,7 @@ stats_config (vlib_main_t * vm, unformat_input_t * input)
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
- if (unformat (input, "socket-name %s", &sm->socket_name))
- ;
- else if (unformat (input, "default"))
- sm->socket_name = format (0, "%s", STAT_SEGMENT_SOCKET_FILE);
- else if (unformat (input, "interval %u", &sec))
+ if (unformat (input, "interval %u", &sec))
{
int rv = stats_set_poller_delay (sec);
if (rv)
@@ -2421,9 +2363,6 @@ stats_config (vlib_main_t * vm, unformat_input_t * input)
}
}
- if (sm->socket_name)
- stats_segment_socket_init ();
-
return 0;
}
@@ -2482,9 +2421,6 @@ stats_thread_fn (void *arg)
ip46_fib_stats_delay (sm, sm->stats_poll_interval_in_seconds,
0 /* nsec */ );
- /* Always update stats segment data */
- do_stat_segment_updates (sm);
-
if (!(sm->enable_poller))
continue;
diff --git a/src/vpp/stats/stats.h b/src/vpp/stats/stats_to_be_deprecated.h
index f21451d352b..9259527661b 100644
--- a/src/vpp/stats/stats.h
+++ b/src/vpp/stats/stats_to_be_deprecated.h
@@ -26,7 +26,6 @@
#include <vlib/unix/unix.h>
#include <vlibmemory/api.h>
#include <vlibapi/api_helper_macros.h>
-#include <vpp/stats/stat_segment.h>
typedef struct
{
@@ -156,20 +155,6 @@ typedef struct
vpe_client_stats_registration_t **regs_tmp;
vpe_client_registration_t **clients_tmp;
- /* statistics segment */
- uword *directory_vector_by_name;
- stat_segment_directory_entry_t *directory_vector;
- clib_spinlock_t *stat_segment_lockp;
- clib_socket_t *socket;
- u8 *socket_name;
- ssize_t memory_size;
- u8 node_counters_enabled;
- void *heap;
- stat_segment_shared_header_t *shared_header; /* pointer to shared memory segment */
- int memfd;
-
- u64 last_input_packets;
-
/* convenience */
vlib_main_t *vlib_main;
vnet_main_t *vnet_main;
@@ -179,8 +164,6 @@ typedef struct
extern stats_main_t stats_main;
-void do_stat_segment_updates (stats_main_t * sm);
-
#endif /* __included_stats_h__ */
/*