* Copyright(c) 2020 Intel Corporation
*/
+#ifndef RTE_EXEC_ENV_WINDOWS
#include <unistd.h>
#include <pthread.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <dlfcn.h>
+#endif /* !RTE_EXEC_ENV_WINDOWS */
/* we won't link against libbsd, so just always use DPDKs-specific strlcpy */
#undef RTE_USE_LIBBSD
#include <rte_common.h>
#include <rte_spinlock.h>
#include <rte_version.h>
-#include <rte_option.h>
#include "rte_telemetry.h"
#include "telemetry_json.h"
#define MAX_CMD_LEN 56
#define MAX_HELP_LEN 64
#define MAX_OUTPUT_LEN (1024 * 16)
+#define MAX_CONNECTIONS 10
+#ifndef RTE_EXEC_ENV_WINDOWS
static void *
client_handler(void *socket);
+#endif /* !RTE_EXEC_ENV_WINDOWS */
struct cmd_callback {
char cmd[MAX_CMD_LEN];
char help[MAX_HELP_LEN];
};
+#ifndef RTE_EXEC_ENV_WINDOWS
struct socket {
int sock;
char path[sizeof(((struct sockaddr_un *)0)->sun_path)];
handler fn;
+ uint16_t *num_clients;
};
static struct socket v2_socket; /* socket for v2 telemetry */
static struct socket v1_socket; /* socket for v1 telemetry */
+#endif /* !RTE_EXEC_ENV_WINDOWS */
static char telemetry_log_error[1024]; /* Will contain error on init failure */
/* list of command callbacks, with one command registered by default */
static struct cmd_callback callbacks[TELEMETRY_MAX_CALLBACKS];
static int num_callbacks; /* How many commands are registered */
/* Used when accessing or modifying list of command callbacks */
static rte_spinlock_t callback_sl = RTE_SPINLOCK_INITIALIZER;
+#ifndef RTE_EXEC_ENV_WINDOWS
+static uint16_t v2_clients;
+#endif /* !RTE_EXEC_ENV_WINDOWS */
int
rte_telemetry_register_cmd(const char *cmd, telemetry_cb fn, const char *help)
return 0;
}
+#ifndef RTE_EXEC_ENV_WINDOWS
+
static int
list_commands(const char *cmd __rte_unused, const char *params __rte_unused,
struct rte_tel_data *d)
bytes = read(s, buffer, sizeof(buffer) - 1);
}
close(s);
+ __atomic_sub_fetch(&v2_clients, 1, __ATOMIC_RELAXED);
return NULL;
}
int s_accepted = accept(s->sock, NULL, NULL);
if (s_accepted < 0) {
snprintf(telemetry_log_error,
- sizeof(telemetry_log_error),
- "Error with accept, telemetry thread quitting\n");
+ sizeof(telemetry_log_error),
+ "Error with accept, telemetry thread quitting");
return NULL;
}
+ if (s->num_clients != NULL) {
+ uint16_t conns = __atomic_load_n(s->num_clients,
+ __ATOMIC_RELAXED);
+ if (conns >= MAX_CONNECTIONS) {
+ close(s_accepted);
+ continue;
+ }
+ __atomic_add_fetch(s->num_clients, 1,
+ __ATOMIC_RELAXED);
+ }
pthread_create(&th, NULL, s->fn, (void *)(uintptr_t)s_accepted);
pthread_detach(th);
}
}
static int
-telemetry_legacy_init(const char *runtime_dir)
+telemetry_legacy_init(const char *runtime_dir, rte_cpuset_t *cpuset)
{
pthread_t t_old;
if (v1_socket.sock < 0)
return -1;
pthread_create(&t_old, NULL, socket_listener, &v1_socket);
+ pthread_setaffinity_np(t_old, sizeof(*cpuset), cpuset);
return 0;
}
static int
-telemetry_v2_init(const char *runtime_dir)
+telemetry_v2_init(const char *runtime_dir, rte_cpuset_t *cpuset)
{
pthread_t t_new;
+ v2_socket.num_clients = &v2_clients;
rte_telemetry_register_cmd("/", list_commands,
"Returns list of available commands, Takes no parameters");
rte_telemetry_register_cmd("/info", json_info,
if (v2_socket.sock < 0)
return -1;
pthread_create(&t_new, NULL, socket_listener, &v2_socket);
+ pthread_setaffinity_np(t_new, sizeof(*cpuset), cpuset);
atexit(unlink_sockets);
return 0;
}
+#endif /* !RTE_EXEC_ENV_WINDOWS */
+
int32_t
-rte_telemetry_init(void)
+rte_telemetry_init(const char *runtime_dir, rte_cpuset_t *cpuset,
+ const char **err_str)
{
- const char *error_str;
- if (telemetry_v2_init(rte_eal_get_runtime_dir()) != 0) {
- error_str = telemetry_log_error;
- printf("Error initialising telemetry - %s", error_str);
+#ifndef RTE_EXEC_ENV_WINDOWS
+ if (telemetry_v2_init(runtime_dir, cpuset) != 0) {
+ *err_str = telemetry_log_error;
return -1;
}
- if (telemetry_legacy_init(rte_eal_get_runtime_dir()) != 0) {
- error_str = telemetry_log_error;
- printf("No telemetry legacy support- %s", error_str);
+ if (telemetry_legacy_init(runtime_dir, cpuset) != 0) {
+ *err_str = telemetry_log_error;
}
- return 0;
-}
+#else /* RTE_EXEC_ENV_WINDOWS */
+ RTE_SET_USED(runtime_dir);
+ RTE_SET_USED(cpuset);
+ RTE_SET_USED(err_str);
-static struct rte_option option = {
- .name = "telemetry",
- .usage = "Enable telemetry backend",
- .cb = &rte_telemetry_init,
- .enabled = 0
-};
+ snprintf(telemetry_log_error, sizeof(telemetry_log_error),
+ "DPDK Telemetry is not supported on Windows.");
+#endif /* RTE_EXEC_ENV_WINDOWS */
-RTE_INIT(telemetry_register_op) {
- rte_option_register(&option);
+ return 0;
}