| 1 |
/* |
| 2 |
* collectd - src/utils_dpdk.h |
| 3 |
* MIT License |
| 4 |
* |
| 5 |
* Copyright(c) 2016 Intel Corporation. All rights reserved. |
| 6 |
* |
| 7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 |
* of this software and associated documentation files (the "Software"), to deal |
| 9 |
* in the Software without restriction, including without limitation the rights |
| 10 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 |
* copies of the Software, and to permit persons to whom the Software is |
| 12 |
* furnished to do so, subject to the following conditions: |
| 13 |
* |
| 14 |
* The above copyright notice and this permission notice shall be included in |
| 15 |
* all copies or substantial portions of the Software. |
| 16 |
* |
| 17 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 |
* SOFTWARE. |
| 24 |
* |
| 25 |
* Authors: |
| 26 |
* Maryam Tahhan <[email protected]> |
| 27 |
* Harry van Haaren <[email protected]> |
| 28 |
* Taras Chornyi <[email protected]> |
| 29 |
* Serhiy Pshyk <[email protected]> |
| 30 |
* Krzysztof Matczak <[email protected]> |
| 31 |
*/ |
| 32 |
|
| 33 |
#ifndef UTILS_DPDK_H |
| 34 |
#define UTILS_DPDK_H |
| 35 |
|
| 36 |
#include <rte_version.h> |
| 37 |
|
| 38 |
#define ERR_BUF_SIZE 1024 |
| 39 |
|
| 40 |
enum DPDK_CMD { |
| 41 |
DPDK_CMD_NONE = 0, |
| 42 |
DPDK_CMD_QUIT, |
| 43 |
DPDK_CMD_INIT, |
| 44 |
DPDK_CMD_GET_STATS, |
| 45 |
DPDK_CMD_GET_EVENTS, |
| 46 |
__DPDK_CMD_LAST, |
| 47 |
}; |
| 48 |
|
| 49 |
struct dpdk_eal_config_s { |
| 50 |
char coremask[DATA_MAX_NAME_LEN]; |
| 51 |
char memory_channels[DATA_MAX_NAME_LEN]; |
| 52 |
char socket_memory[DATA_MAX_NAME_LEN]; |
| 53 |
char file_prefix[DATA_MAX_NAME_LEN]; |
| 54 |
char log_level[DATA_MAX_NAME_LEN]; |
| 55 |
char rte_driver_lib_path[PATH_MAX]; |
| 56 |
}; |
| 57 |
typedef struct dpdk_eal_config_s dpdk_eal_config_t; |
| 58 |
|
| 59 |
struct uint128_s { |
| 60 |
u_int64_t high; |
| 61 |
u_int64_t low; |
| 62 |
}; |
| 63 |
typedef struct uint128_s uint128_t; |
| 64 |
|
| 65 |
typedef struct dpdk_helper_ctx_s dpdk_helper_ctx_t; |
| 66 |
|
| 67 |
int dpdk_helper_init(const char *name, size_t data_size, |
| 68 |
dpdk_helper_ctx_t **pphc); |
| 69 |
void dpdk_helper_shutdown(dpdk_helper_ctx_t *phc); |
| 70 |
int dpdk_helper_eal_config_parse(dpdk_helper_ctx_t *phc, oconfig_item_t *ci); |
| 71 |
int dpdk_helper_eal_config_set(dpdk_helper_ctx_t *phc, dpdk_eal_config_t *ec); |
| 72 |
int dpdk_helper_eal_config_get(dpdk_helper_ctx_t *phc, dpdk_eal_config_t *ec); |
| 73 |
int dpdk_helper_command(dpdk_helper_ctx_t *phc, enum DPDK_CMD cmd, int *result, |
| 74 |
cdtime_t cmd_wait_time); |
| 75 |
void *dpdk_helper_priv_get(dpdk_helper_ctx_t *phc); |
| 76 |
int dpdk_helper_data_size_get(dpdk_helper_ctx_t *phc); |
| 77 |
uint8_t dpdk_helper_eth_dev_count(void); |
| 78 |
|
| 79 |
/* forward declaration of handler function that is called by helper from |
| 80 |
* child process. not implemented in helper. must be provided by client. */ |
| 81 |
int dpdk_helper_command_handler(dpdk_helper_ctx_t *phc, enum DPDK_CMD cmd); |
| 82 |
|
| 83 |
uint128_t str_to_uint128(const char *str, int len); |
| 84 |
|
| 85 |
/* logging functions that should be used in child process */ |
| 86 |
#define DPDK_CHILD_LOG(...) fprintf(stdout, __VA_ARGS__) |
| 87 |
#define DPDK_CHILD_TRACE(_name) \ |
| 88 |
fprintf(stdout, "%s:%s:%d pid=%u\n", _name, __FUNCTION__, __LINE__, getpid()) |
| 89 |
|
| 90 |
#endif /* UTILS_DPDK_H */ |