X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_dpdk.c;h=2f37818bfcc73044f2f4641eb6a88dcd5b4004ea;hb=23fadd68220155b7a2c124f68c54357450d76581;hp=e3c737931a01f2f3c2a3084efb5eb8c222cc9d11;hpb=98df65fb8d8f5dd67f596f7f3a411c56fab80458;p=collectd.git diff --git a/src/utils_dpdk.c b/src/utils_dpdk.c index e3c73793..2f37818b 100644 --- a/src/utils_dpdk.c +++ b/src/utils_dpdk.c @@ -44,8 +44,9 @@ #include "utils_dpdk.h" #define DPDK_DEFAULT_RTE_CONFIG "/var/run/.rte_config" -#define DPDK_EAL_ARGC 5 -#define DPDK_MAX_BUFFER_SIZE (4096 * 4) +#define DPDK_EAL_ARGC 10 +// Complete trace should fit into 1024 chars +#define DPDK_MAX_BUFFER_SIZE 896 #define DPDK_CDM_DEFAULT_TIMEOUT 10000 enum DPDK_HELPER_STATUS { @@ -66,7 +67,7 @@ struct dpdk_helper_ctx_s { int eal_initialized; size_t shm_size; - const char *shm_name; + char shm_name[DATA_MAX_NAME_LEN]; sem_t sema_cmd_start; sem_t sema_cmd_complete; @@ -103,11 +104,10 @@ static void dpdk_helper_config_default(dpdk_helper_ctx_t *phc) { DPDK_HELPER_TRACE(phc->shm_name); - ssnprintf(phc->eal_config.coremask, DATA_MAX_NAME_LEN, "%s", "0xf"); - ssnprintf(phc->eal_config.memory_channels, DATA_MAX_NAME_LEN, "%s", "1"); - ssnprintf(phc->eal_config.process_type, DATA_MAX_NAME_LEN, "%s", "secondary"); - ssnprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN, "%s", - DPDK_DEFAULT_RTE_CONFIG); + snprintf(phc->eal_config.coremask, DATA_MAX_NAME_LEN, "%s", "0xf"); + snprintf(phc->eal_config.memory_channels, DATA_MAX_NAME_LEN, "%s", "1"); + snprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN, "%s", + DPDK_DEFAULT_RTE_CONFIG); } int dpdk_helper_eal_config_set(dpdk_helper_ctx_t *phc, dpdk_eal_config_t *ec) { @@ -162,6 +162,7 @@ int dpdk_helper_eal_config_parse(dpdk_helper_ctx_t *phc, oconfig_item_t *ci) { int status = 0; for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; + if (strcasecmp("Coremask", child->key) == 0) { status = cf_util_get_string_buffer(child, phc->eal_config.coremask, sizeof(phc->eal_config.coremask)); @@ -176,15 +177,25 @@ int dpdk_helper_eal_config_parse(dpdk_helper_ctx_t *phc, oconfig_item_t *ci) { status = cf_util_get_string_buffer(child, phc->eal_config.socket_memory, sizeof(phc->eal_config.socket_memory)); DEBUG("dpdk_common: EAL:Socket memory %s", phc->eal_config.socket_memory); - } else if (strcasecmp("ProcessType", child->key) == 0) { - status = cf_util_get_string_buffer(child, phc->eal_config.process_type, - sizeof(phc->eal_config.process_type)); - DEBUG("dpdk_common: EAL:Process type %s", phc->eal_config.process_type); - } else if ((strcasecmp("FilePrefix", child->key) == 0) && - (child->values[0].type == OCONFIG_TYPE_STRING)) { - ssnprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN, - "/var/run/.%s_config", child->values[0].value.string); - DEBUG("dpdk_common: EAL:File prefix %s", phc->eal_config.file_prefix); + } else if (strcasecmp("FilePrefix", child->key) == 0) { + char prefix[DATA_MAX_NAME_LEN]; + + status = cf_util_get_string_buffer(child, prefix, sizeof(prefix)); + if (status == 0) { + snprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN, + "/var/run/.%s_config", prefix); + DEBUG("dpdk_common: EAL:File prefix %s", phc->eal_config.file_prefix); + } + } else if (strcasecmp("LogLevel", child->key) == 0) { + status = cf_util_get_string_buffer(child, phc->eal_config.log_level, + sizeof(phc->eal_config.log_level)); + DEBUG("dpdk_common: EAL:LogLevel %s", phc->eal_config.log_level); + } else if (strcasecmp("RteDriverLibPath", child->key) == 0) { + status = cf_util_get_string_buffer( + child, phc->eal_config.rte_driver_lib_path, + sizeof(phc->eal_config.rte_driver_lib_path)); + DEBUG("dpdk_common: EAL:RteDriverLibPath %s", + phc->eal_config.rte_driver_lib_path); } else { ERROR("dpdk_common: Invalid '%s' configuration option", child->key); status = -EINVAL; @@ -242,13 +253,16 @@ static void dpdk_shm_cleanup(const char *name, size_t size, void *map) { DPDK_HELPER_TRACE(name); char errbuf[ERR_BUF_SIZE]; + /* + * Call shm_unlink first, as 'name' might be no longer accessible after munmap + */ + if (shm_unlink(name)) + ERROR("shm_unlink failure %s", sstrerror(errno, errbuf, sizeof(errbuf))); + if (map != NULL) { if (munmap(map, size)) ERROR("munmap failure %s", sstrerror(errno, errbuf, sizeof(errbuf))); } - - if (shm_unlink(name)) - ERROR("shm_unlink failure %s", sstrerror(errno, errbuf, sizeof(errbuf))); } void *dpdk_helper_priv_get(dpdk_helper_ctx_t *phc) { @@ -264,7 +278,7 @@ int dpdk_helper_data_size_get(dpdk_helper_ctx_t *phc) { return -EINVAL; } - return (phc->shm_size - sizeof(dpdk_helper_ctx_t)); + return phc->shm_size - sizeof(dpdk_helper_ctx_t); } int dpdk_helper_init(const char *name, size_t data_size, @@ -313,7 +327,7 @@ int dpdk_helper_init(const char *name, size_t data_size, } phc->shm_size = shm_size; - phc->shm_name = name; + sstrncpy(phc->shm_name, name, sizeof(phc->shm_name)); dpdk_helper_config_default(phc); @@ -322,11 +336,9 @@ int dpdk_helper_init(const char *name, size_t data_size, return 0; } -int dpdk_helper_shutdown(dpdk_helper_ctx_t *phc) { - if (phc == NULL) { - ERROR("%s:Invalid argument(phc)", __FUNCTION__); - return -EINVAL; - } +void dpdk_helper_shutdown(dpdk_helper_ctx_t *phc) { + if (phc == NULL) + return; DPDK_HELPER_TRACE(phc->shm_name); @@ -339,8 +351,6 @@ int dpdk_helper_shutdown(dpdk_helper_ctx_t *phc) { sem_destroy(&phc->sema_cmd_start); sem_destroy(&phc->sema_cmd_complete); dpdk_shm_cleanup(phc->shm_name, phc->shm_size, (void *)phc); - - return 0; } static int dpdk_helper_spawn(dpdk_helper_ctx_t *phc) { @@ -471,7 +481,6 @@ static int dpdk_helper_eal_init(dpdk_helper_ctx_t *phc) { /* EAL config must be initialized */ assert(phc->eal_config.coremask[0] != 0); assert(phc->eal_config.memory_channels[0] != 0); - assert(phc->eal_config.process_type[0] != 0); assert(phc->eal_config.file_prefix[0] != 0); argp[argc++] = "collectd-dpdk"; @@ -493,7 +502,16 @@ static int dpdk_helper_eal_init(dpdk_helper_ctx_t *phc) { } argp[argc++] = "--proc-type"; - argp[argc++] = phc->eal_config.process_type; + argp[argc++] = "secondary"; + + if (strcasecmp(phc->eal_config.log_level, "") != 0) { + argp[argc++] = "--log-level"; + argp[argc++] = phc->eal_config.log_level; + } + if (strcasecmp(phc->eal_config.rte_driver_lib_path, "") != 0) { + argp[argc++] = "-d"; + argp[argc++] = phc->eal_config.rte_driver_lib_path; + } assert(argc <= (DPDK_EAL_ARGC * 2 + 1)); @@ -699,6 +717,8 @@ static void dpdk_helper_check_pipe(dpdk_helper_ctx_t *phc) { .fd = phc->pipes[0], .events = POLLIN, }; int data_avail = poll(&fds, 1, 0); + DEBUG("%s:dpdk_helper_check_pipe: poll data_avail=%d", phc->shm_name, + data_avail); if (data_avail < 0) { if (errno != EINTR || errno != EAGAIN) { char errbuf[ERR_BUF_SIZE]; @@ -707,10 +727,12 @@ static void dpdk_helper_check_pipe(dpdk_helper_ctx_t *phc) { } } while (data_avail) { - int nbytes = read(phc->pipes[0], buf, sizeof(buf)); + int nbytes = read(phc->pipes[0], buf, (sizeof(buf) - 1)); + DEBUG("%s:dpdk_helper_check_pipe: read nbytes=%d", phc->shm_name, nbytes); if (nbytes <= 0) break; - sstrncpy(out, buf, nbytes); + buf[nbytes] = '\n'; + sstrncpy(out, buf, (nbytes + 1)); DEBUG("%s: helper process:\n%s", phc->shm_name, out); } }