X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdpdkevents.c;h=4c8196aed48e7a4df708a1dbb2a719eb19260cb4;hp=32d3d6af4e9d65a396f45362d4db0305c8bfe514;hb=48efd3deb4c9139fd060ff3d289896e9031bcc7c;hpb=7c2336dde35a7b42853b6ca167d4164619e52333 diff --git a/src/dpdkevents.c b/src/dpdkevents.c index 32d3d6af..4c8196ae 100644 --- a/src/dpdkevents.c +++ b/src/dpdkevents.c @@ -32,12 +32,12 @@ #include "collectd.h" -#include "common.h" #include "plugin.h" +#include "utils/common/common.h" #include "semaphore.h" #include "sys/mman.h" -#include "utils_dpdk.h" +#include "utils/dpdk/dpdk.h" #include "utils_time.h" #include @@ -66,19 +66,19 @@ typedef struct dpdk_ka_monitor_s { typedef struct dpdk_link_status_config_s { int enabled; - _Bool send_updated; + bool send_updated; uint32_t enabled_port_mask; char port_name[RTE_MAX_ETHPORTS][DATA_MAX_NAME_LEN]; - _Bool notify; + bool notify; } dpdk_link_status_config_t; typedef struct dpdk_keep_alive_config_s { int enabled; - _Bool send_updated; + bool send_updated; uint128_t lcore_mask; dpdk_keepalive_shm_t *shm; char shm_name[DATA_MAX_NAME_LEN]; - _Bool notify; + bool notify; int fd; } dpdk_keep_alive_config_t; @@ -129,12 +129,11 @@ static int dpdk_event_keep_alive_shm_open(void) { shm_name); } - char errbuf[ERR_BUF_SIZE]; int fd = shm_open(shm_name, O_RDONLY, 0); if (fd < 0) { ERROR(DPDK_EVENTS_PLUGIN ": Failed to open %s as SHM:%s. Is DPDK KA " "primary application running?", - shm_name, sstrerror(errno, errbuf, sizeof(errbuf))); + shm_name, STRERRNO); return errno; } @@ -166,8 +165,7 @@ static int dpdk_event_keep_alive_shm_open(void) { ec->config.keep_alive.shm = (dpdk_keepalive_shm_t *)mmap( 0, sizeof(*(ec->config.keep_alive.shm)), PROT_READ, MAP_SHARED, fd, 0); if (ec->config.keep_alive.shm == MAP_FAILED) { - ERROR(DPDK_EVENTS_PLUGIN ": Failed to mmap KA SHM:%s", - sstrerror(errno, errbuf, sizeof(errbuf))); + ERROR(DPDK_EVENTS_PLUGIN ": Failed to mmap KA SHM:%s", STRERRNO); close(fd); return errno; } @@ -187,8 +185,8 @@ static void dpdk_events_default_config(void) { /* Link Status */ ec->config.link_status.enabled = 1; ec->config.link_status.enabled_port_mask = ~0; - ec->config.link_status.send_updated = 1; - ec->config.link_status.notify = 0; + ec->config.link_status.send_updated = true; + ec->config.link_status.notify = false; for (int i = 0; i < RTE_MAX_ETHPORTS; i++) { ec->config.link_status.port_name[i][0] = 0; @@ -196,8 +194,8 @@ static void dpdk_events_default_config(void) { /* Keep Alive */ ec->config.keep_alive.enabled = 1; - ec->config.keep_alive.send_updated = 1; - ec->config.keep_alive.notify = 0; + ec->config.keep_alive.send_updated = true; + ec->config.keep_alive.notify = false; /* by default enable 128 cores */ memset(&ec->config.keep_alive.lcore_mask, 1, sizeof(ec->config.keep_alive.lcore_mask)); @@ -421,8 +419,12 @@ static int dpdk_events_config(oconfig_item_t *ci) { static int dpdk_helper_link_status_get(dpdk_helper_ctx_t *phc) { dpdk_events_ctx_t *ec = DPDK_EVENTS_CTX_GET(phc); - /* get Link Status values from DPDK */ +/* get Link Status values from DPDK */ +#if RTE_VERSION < RTE_VERSION_NUM(18, 05, 0, 0) uint8_t nb_ports = rte_eth_dev_count(); +#else + uint8_t nb_ports = rte_eth_dev_count_avail(); +#endif if (nb_ports == 0) { DPDK_CHILD_LOG("dpdkevent-helper: No DPDK ports available. " "Check bound devices to DPDK driver.\n"); @@ -430,7 +432,7 @@ static int dpdk_helper_link_status_get(dpdk_helper_ctx_t *phc) { } ec->nb_ports = nb_ports > RTE_MAX_ETHPORTS ? RTE_MAX_ETHPORTS : nb_ports; - for (int i = 0; i < ec->nb_ports; i++) { + for (unsigned int i = 0; i < ec->nb_ports; i++) { if (ec->config.link_status.enabled_port_mask & (1 << i)) { struct rte_eth_link link; ec->link_info[i].read_time = cdtime(); @@ -499,7 +501,7 @@ static int dpdk_events_link_status_dispatch(dpdk_helper_ctx_t *phc) { ec->nb_ports); /* dispatch Link Status values to collectd */ - for (int i = 0; i < ec->nb_ports; i++) { + for (unsigned int i = 0; i < ec->nb_ports; i++) { if (ec->config.link_status.enabled_port_mask & (1 << i)) { if (!ec->config.link_status.send_updated || ec->link_info[i].status_updated) { @@ -509,17 +511,17 @@ static int dpdk_events_link_status_dispatch(dpdk_helper_ctx_t *phc) { char dev_name[DATA_MAX_NAME_LEN]; if (ec->config.link_status.port_name[i][0] != 0) { - snprintf(dev_name, sizeof(dev_name), "%s", - ec->config.link_status.port_name[i]); + ssnprintf(dev_name, sizeof(dev_name), "%s", + ec->config.link_status.port_name[i]); } else { - snprintf(dev_name, sizeof(dev_name), "port.%d", i); + ssnprintf(dev_name, sizeof(dev_name), "port.%d", i); } if (ec->config.link_status.notify) { int sev = ec->link_info[i].link_status ? NOTIF_OKAY : NOTIF_WARNING; char msg[DATA_MAX_NAME_LEN]; - snprintf(msg, sizeof(msg), "Link Status: %s", - ec->link_info[i].link_status ? "UP" : "DOWN"); + ssnprintf(msg, sizeof(msg), "Link Status: %s", + ec->link_info[i].link_status ? "UP" : "DOWN"); dpdk_events_notification_dispatch(sev, dev_name, ec->link_info[i].read_time, msg); } else { @@ -555,7 +557,7 @@ static void dpdk_events_keep_alive_dispatch(dpdk_helper_ctx_t *phc) { } char core_name[DATA_MAX_NAME_LEN]; - snprintf(core_name, sizeof(core_name), "lcore%u", i); + ssnprintf(core_name, sizeof(core_name), "lcore%u", i); if (!ec->config.keep_alive.send_updated || (ec->core_info[i].lcore_state != @@ -570,34 +572,34 @@ static void dpdk_events_keep_alive_dispatch(dpdk_helper_ctx_t *phc) { switch (ec->config.keep_alive.shm->core_state[i]) { case RTE_KA_STATE_ALIVE: sev = NOTIF_OKAY; - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: ALIVE", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: ALIVE", i); break; case RTE_KA_STATE_MISSING: - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: MISSING", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: MISSING", i); sev = NOTIF_WARNING; break; case RTE_KA_STATE_DEAD: - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: DEAD", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: DEAD", i); sev = NOTIF_FAILURE; break; case RTE_KA_STATE_UNUSED: - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: UNUSED", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: UNUSED", i); sev = NOTIF_OKAY; break; case RTE_KA_STATE_GONE: - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: GONE", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: GONE", i); sev = NOTIF_FAILURE; break; case RTE_KA_STATE_DOZING: - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: DOZING", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: DOZING", i); sev = NOTIF_OKAY; break; case RTE_KA_STATE_SLEEP: - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: SLEEP", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: SLEEP", i); sev = NOTIF_OKAY; break; default: - snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: UNKNOWN", i); + ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: UNKNOWN", i); sev = NOTIF_FAILURE; }