dpdkstat plugin rework
[collectd.git] / src / utils_dpdk.h
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
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is 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
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  * DEALINGS IN THE SOFTWARE.
24  *
25  * Authors:
26  *   Maryam Tahhan <maryam.tahhan@intel.com>
27  *   Harry van Haaren <harry.van.haaren@intel.com>
28  *   Serhiy Pshyk <serhiyx.pshyk@intel.com>
29  **/
30
31 #ifndef UTILS_DPDK_H
32 #define UTILS_DPDK_H
33
34 #include <rte_version.h>
35
36 #define ERR_BUF_SIZE 1024
37
38 #if RTE_VER_RELEASE == 16 && RTE_VER_MINOR == 0
39 #if RTE_VER_MONTH == 4
40 #define DPDK_VER_16_04 RTE_VERSION_NUM(16, 4, 0, 16)
41 #endif
42 #if RTE_VER_MONTH == 7
43 #define DPDK_VER_16_07 RTE_VERSION_NUM(16, 7, 0, 16)
44 #endif
45 #endif
46
47 enum DPDK_CMD {
48   DPDK_CMD_NONE = 0,
49   DPDK_CMD_QUIT,
50   DPDK_CMD_INIT,
51   DPDK_CMD_GET_STATS,
52   DPDK_CMD_GET_EVENTS,
53   __DPDK_CMD_LAST,
54 };
55
56 struct dpdk_eal_config_s {
57   char coremask[DATA_MAX_NAME_LEN];
58   char memory_channels[DATA_MAX_NAME_LEN];
59   char socket_memory[DATA_MAX_NAME_LEN];
60   char process_type[DATA_MAX_NAME_LEN];
61   char file_prefix[DATA_MAX_NAME_LEN];
62 };
63 typedef struct dpdk_eal_config_s dpdk_eal_config_t;
64
65 struct uint128_s {
66   u_int64_t high;
67   u_int64_t low;
68 };
69 typedef struct uint128_s uint128_t;
70
71 typedef struct dpdk_helper_ctx_s dpdk_helper_ctx_t;
72
73 int dpdk_helper_init(const char *name, size_t data_size,
74                      dpdk_helper_ctx_t **pphc);
75 int dpdk_helper_shutdown(dpdk_helper_ctx_t *phc);
76 int dpdk_helper_eal_config_parse(dpdk_helper_ctx_t *phc, oconfig_item_t *ci);
77 int dpdk_helper_eal_config_set(dpdk_helper_ctx_t *phc, dpdk_eal_config_t *ec);
78 int dpdk_helper_eal_config_get(dpdk_helper_ctx_t *phc, dpdk_eal_config_t *ec);
79 int dpdk_helper_command(dpdk_helper_ctx_t *phc, enum DPDK_CMD cmd, int *result,
80                         cdtime_t cmd_wait_time);
81 void *dpdk_helper_priv_get(dpdk_helper_ctx_t *phc);
82 int dpdk_helper_data_size_get(dpdk_helper_ctx_t *phc);
83
84 /* forward declaration of handler function that is called by helper from
85  * child process. not implemented in helper. must be provided by client. */
86 int dpdk_helper_command_handler(dpdk_helper_ctx_t *phc, enum DPDK_CMD cmd);
87
88 uint128_t str_to_uint128(const char *str, int len);
89
90 /* logging functions that should be used in child process */
91 #define DPDK_CHILD_LOG(...) fprintf(stdout, __VA_ARGS__)
92 #define DPDK_CHILD_TRACE(_name)                                                \
93   fprintf(stdout, "%s:%s:%d pid=%u\n", _name, __FUNCTION__, __LINE__, getpid())
94
95 #endif /* UTILS_DPDK_H */