X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_dpdk.c;h=4911c80920d461931f5a937387afe961cace0d4d;hb=be126043c2be20399d7670fe194645292018bde0;hp=640f08bc0f49dd1159e7d2ec7f649474e2f4411a;hpb=2412d3ca76f7ac24e67543720c1d385188da0ce3;p=collectd.git diff --git a/src/utils_dpdk.c b/src/utils_dpdk.c index 640f08bc..4911c809 100644 --- a/src/utils_dpdk.c +++ b/src/utils_dpdk.c @@ -38,6 +38,7 @@ #include #include +#include #include "common.h" #include "utils_dpdk.h" @@ -102,10 +103,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", + 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.process_type, DATA_MAX_NAME_LEN, "%s", "secondary"); + snprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN, "%s", DPDK_DEFAULT_RTE_CONFIG); } @@ -181,7 +182,7 @@ int dpdk_helper_eal_config_parse(dpdk_helper_ctx_t *phc, oconfig_item_t *ci) { 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, + snprintf(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 { @@ -263,7 +264,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, @@ -850,3 +851,22 @@ uint128_t str_to_uint128(const char *str, int len) { } return lcore_mask; } + +uint8_t dpdk_helper_eth_dev_count() { + uint8_t ports = rte_eth_dev_count(); + if (ports == 0) { + ERROR( + "%s:%d: No DPDK ports available. Check bound devices to DPDK driver.\n", + __FUNCTION__, __LINE__); + return ports; + } + + if (ports > RTE_MAX_ETHPORTS) { + ERROR("%s:%d: Number of DPDK ports (%u) is greater than " + "RTE_MAX_ETHPORTS=%d. Ignoring extra ports\n", + __FUNCTION__, __LINE__, ports, RTE_MAX_ETHPORTS); + ports = RTE_MAX_ETHPORTS; + } + + return ports; +}