Skip to content

Commit

Permalink
Remove Warnings (ebpf) (netdata#18484)
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoftsm authored Sep 5, 2024
1 parent 0426b7f commit 6611f94
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 36 deletions.
19 changes: 10 additions & 9 deletions src/collectors/ebpf.plugin/ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ static void get_ipv6_last_addr(union netdata_ip_t *out, union netdata_ip_t *in,
*
* @return it returns 0 on success and -1 otherwise.
*/
static inline int ebpf_ip2nl(uint8_t *dst, char *ip, int domain, char *source)
static inline int ebpf_ip2nl(uint8_t *dst, const char *ip, int domain, char *source)
{
if (inet_pton(domain, ip, dst) <= 0) {
netdata_log_error("The address specified (%s) is invalid ", source);
Expand Down Expand Up @@ -1662,14 +1662,14 @@ void ebpf_clean_ip_structure(ebpf_network_viewer_ip_list_t **clean)
* @param out a pointer to store the link list
* @param ip the value given as parameter
*/
static void ebpf_parse_ip_list_unsafe(void **out, char *ip)
static void ebpf_parse_ip_list_unsafe(void **out, const char *ip)
{
ebpf_network_viewer_ip_list_t **list = (ebpf_network_viewer_ip_list_t **)out;

char *ipdup = strdupz(ip);
union netdata_ip_t first = { };
union netdata_ip_t last = { };
char *is_ipv6;
const char *is_ipv6;
if (*ip == '*' && *(ip+1) == '\0') {
memset(first.addr8, 0, sizeof(first.addr8));
memset(last.addr8, 0xFF, sizeof(last.addr8));
Expand All @@ -1680,7 +1680,8 @@ static void ebpf_parse_ip_list_unsafe(void **out, char *ip)
goto storethisip;
}

char *end = ip;
char *enddup = strdupz(ip);
char *end = enddup;
// Move while I cannot find a separator
while (*end && *end != '/' && *end != '-') end++;

Expand Down Expand Up @@ -1810,7 +1811,7 @@ static void ebpf_parse_ip_list_unsafe(void **out, char *ip)

ebpf_network_viewer_ip_list_t *store;

storethisip:
storethisip:
store = callocz(1, sizeof(ebpf_network_viewer_ip_list_t));
store->value = ipdup;
store->hash = simple_hash(ipdup);
Expand All @@ -1821,8 +1822,9 @@ static void ebpf_parse_ip_list_unsafe(void **out, char *ip)
ebpf_fill_ip_list_unsafe(list, store, "socket");
return;

cleanipdup:
cleanipdup:
freez(ipdup);
freez(enddup);
}

/**
Expand Down Expand Up @@ -2773,7 +2775,7 @@ static inline void ebpf_set_load_mode(netdata_ebpf_load_mode_t load, netdata_ebp
* @param str value read from configuration file.
* @param origin specify the configuration file loaded
*/
static inline void epbf_update_load_mode(char *str, netdata_ebpf_load_mode_t origin)
static inline void epbf_update_load_mode(const char *str, netdata_ebpf_load_mode_t origin)
{
netdata_ebpf_load_mode_t load = epbf_convert_string_to_load_mode(str);

Expand Down Expand Up @@ -4074,7 +4076,6 @@ int main(int argc, char **argv)
heartbeat_t hb;
heartbeat_init(&hb);
int update_apps_every = (int) EBPF_CFG_UPDATE_APPS_EVERY_DEFAULT;
uint32_t max_period = EBPF_CLEANUP_FACTOR;
int update_apps_list = update_apps_every - 1;
int process_maps_per_core = ebpf_modules[EBPF_MODULE_PROCESS_IDX].maps_per_core;
//Plugin will be killed when it receives a signal
Expand All @@ -4097,7 +4098,7 @@ int main(int argc, char **argv)
pthread_mutex_lock(&collect_data_mutex);
ebpf_parse_proc_files();
if (collect_pids & (1<<EBPF_MODULE_PROCESS_IDX)) {
collect_data_for_all_processes(process_pid_fd, process_maps_per_core, max_period);
collect_data_for_all_processes(process_pid_fd, process_maps_per_core);
}

ebpf_create_apps_charts(apps_groups_root_target);
Expand Down
11 changes: 5 additions & 6 deletions src/collectors/ebpf.plugin/ebpf_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ int pids_fd[EBPF_PIDS_END_IDX];

static size_t
// global_iterations_counter = 1,
calls_counter = 0,
//calls_counter = 0,
// file_counter = 0,
// filenames_allocated_counter = 0,
// inodes_changed_counter = 0,
Expand Down Expand Up @@ -426,7 +426,7 @@ static inline void assign_target_to_pid(ebpf_pid_data_t *p)
static inline int read_proc_pid_cmdline(ebpf_pid_data_t *p, char *cmdline)
{
char filename[FILENAME_MAX + 1];
snprintfz(filename, FILENAME_MAX, "%s/proc/%d/cmdline", netdata_configured_host_prefix, p->pid);
snprintfz(filename, FILENAME_MAX, "%s/proc/%u/cmdline", netdata_configured_host_prefix, p->pid);

int ret = 0;

Expand Down Expand Up @@ -490,7 +490,7 @@ static inline int read_proc_pid_stat(ebpf_pid_data_t *p)
char *comm = procfile_lineword(ff, 0, 1);
int32_t ppid = (int32_t)str2pid_t(procfile_lineword(ff, 0, 3));

if (p->ppid == ppid && p->target)
if (p->ppid == (uint32_t)ppid && p->target)
goto without_cmdline_target;

p->ppid = ppid;
Expand Down Expand Up @@ -546,7 +546,7 @@ static inline int ebpf_collect_data_for_pid(pid_t pid)
read_proc_pid_stat(p);

// check its parent pid
if (unlikely( p->ppid > pid_max)) {
if (unlikely( p->ppid > (uint32_t)pid_max)) {
netdata_log_error("Pid %d (command '%s') states invalid parent pid %u. Using 0.", pid, p->comm, p->ppid);
p->ppid = 0;
}
Expand Down Expand Up @@ -906,9 +906,8 @@ void ebpf_process_sum_values_for_pids(ebpf_process_stat_t *process, struct ebpf_
*
* @param tbl_pid_stats_fd The mapped file descriptor for the hash table.
* @param maps_per_core do I have hash maps per core?
* @param max_period max period to wait before remove from hash table.
*/
void collect_data_for_all_processes(int tbl_pid_stats_fd, int maps_per_core, uint32_t max_period)
void collect_data_for_all_processes(int tbl_pid_stats_fd, int maps_per_core)
{
if (tbl_pid_stats_fd == -1)
return;
Expand Down
2 changes: 1 addition & 1 deletion src/collectors/ebpf.plugin/ebpf_apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ int ebpf_read_hash_table(void *ep, int fd, uint32_t pid);

int get_pid_comm(pid_t pid, size_t n, char *dest);

void collect_data_for_all_processes(int tbl_pid_stats_fd, int maps_per_core, uint32_t max_period);
void collect_data_for_all_processes(int tbl_pid_stats_fd, int maps_per_core);
void ebpf_process_apps_accumulator(ebpf_process_stat_t *out, int maps_per_core);

// The default value is at least 32 times smaller than maximum number of PIDs allowed on system,
Expand Down
6 changes: 2 additions & 4 deletions src/collectors/ebpf.plugin/ebpf_cachestat.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,8 @@ static inline void cachestat_save_pid_values(netdata_publish_cachestat_t *out, n
* Read the apps table and store data inside the structure.
*
* @param maps_per_core do I need to read all cores?
* @param max_period limit of iterations without updates before remove data from hash table
*/
static void ebpf_read_cachestat_apps_table(int maps_per_core, uint32_t max_period)
static void ebpf_read_cachestat_apps_table(int maps_per_core)
{
netdata_cachestat_pid_t *cv = cachestat_vector;
int fd = cachestat_maps[NETDATA_CACHESTAT_PID_STATS].map_fd;
Expand Down Expand Up @@ -845,7 +844,6 @@ void *ebpf_read_cachestat_thread(void *ptr)

int maps_per_core = em->maps_per_core;
int update_every = em->update_every;
uint32_t max_period = EBPF_CLEANUP_FACTOR;

int counter = update_every - 1;

Expand All @@ -859,7 +857,7 @@ void *ebpf_read_cachestat_thread(void *ptr)
continue;

pthread_mutex_lock(&collect_data_mutex);
ebpf_read_cachestat_apps_table(maps_per_core, max_period);
ebpf_read_cachestat_apps_table(maps_per_core);
ebpf_resume_apps_data();
pthread_mutex_unlock(&collect_data_mutex);

Expand Down
6 changes: 2 additions & 4 deletions src/collectors/ebpf.plugin/ebpf_dcstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,8 @@ static void ebpf_dcstat_apps_accumulator(netdata_dcstat_pid_t *out, int maps_per
* Read the apps table and store data inside the structure.
*
* @param maps_per_core do I need to read all cores?
* @param max_period limit of iterations without updates before remove data from hash table
*/
static void ebpf_read_dc_apps_table(int maps_per_core, uint32_t max_period)
static void ebpf_read_dc_apps_table(int maps_per_core)
{
netdata_dcstat_pid_t *cv = dcstat_vector;
int fd = dcstat_maps[NETDATA_DCSTAT_PID_STATS].map_fd;
Expand Down Expand Up @@ -656,15 +655,14 @@ void *ebpf_read_dcstat_thread(void *ptr)
uint32_t lifetime = em->lifetime;
uint32_t running_time = 0;
usec_t period = update_every * USEC_PER_SEC;
uint32_t max_period = EBPF_CLEANUP_FACTOR;
pids_fd[EBPF_PIDS_DCSTAT_IDX] = dcstat_maps[NETDATA_DCSTAT_PID_STATS].map_fd;
while (!ebpf_plugin_stop() && running_time < lifetime) {
(void)heartbeat_next(&hb, period);
if (ebpf_plugin_stop() || ++counter != update_every)
continue;

pthread_mutex_lock(&collect_data_mutex);
ebpf_read_dc_apps_table(maps_per_core, max_period);
ebpf_read_dc_apps_table(maps_per_core);
ebpf_dc_resume_apps_data();
pthread_mutex_unlock(&collect_data_mutex);

Expand Down
6 changes: 2 additions & 4 deletions src/collectors/ebpf.plugin/ebpf_fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,8 @@ static void fd_apps_accumulator(netdata_fd_stat_t *out, int maps_per_core)
* Read the apps table and store data inside the structure.
*
* @param maps_per_core do I need to read all cores?
* @param max_period limit of iterations without updates before remove data from hash table
*/
static void ebpf_read_fd_apps_table(int maps_per_core, uint32_t max_period)
static void ebpf_read_fd_apps_table(int maps_per_core)
{
netdata_fd_stat_t *fv = fd_vector;
int fd = fd_maps[NETDATA_FD_PID_STATS].map_fd;
Expand Down Expand Up @@ -797,15 +796,14 @@ void *ebpf_read_fd_thread(void *ptr)
uint32_t lifetime = em->lifetime;
uint32_t running_time = 0;
int period = USEC_PER_SEC;
uint32_t max_period = EBPF_CLEANUP_FACTOR;
pids_fd[EBPF_PIDS_FD_IDX] = fd_maps[NETDATA_FD_PID_STATS].map_fd;
while (!ebpf_plugin_stop() && running_time < lifetime) {
(void)heartbeat_next(&hb, period);
if (ebpf_plugin_stop() || ++counter != update_every)
continue;

pthread_mutex_lock(&collect_data_mutex);
ebpf_read_fd_apps_table(maps_per_core, max_period);
ebpf_read_fd_apps_table(maps_per_core);
ebpf_fd_resume_apps_data();
pthread_mutex_unlock(&collect_data_mutex);

Expand Down
6 changes: 2 additions & 4 deletions src/collectors/ebpf.plugin/ebpf_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,8 @@ static void ebpf_update_shm_cgroup()
* Read the apps table and store data inside the structure.
*
* @param maps_per_core do I need to read all cores?
* @param max_period limit of iterations without updates before remove data from hash table
*/
static void ebpf_read_shm_apps_table(int maps_per_core, uint32_t max_period)
static void ebpf_read_shm_apps_table(int maps_per_core)
{
netdata_ebpf_shm_t *cv = shm_vector;
int fd = shm_maps[NETDATA_PID_SHM_TABLE].map_fd;
Expand Down Expand Up @@ -1075,15 +1074,14 @@ void *ebpf_read_shm_thread(void *ptr)
uint32_t lifetime = em->lifetime;
uint32_t running_time = 0;
usec_t period = update_every * USEC_PER_SEC;
uint32_t max_period = EBPF_CLEANUP_FACTOR;
pids_fd[EBPF_PIDS_SHM_IDX] = shm_maps[NETDATA_PID_SHM_TABLE].map_fd;
while (!ebpf_plugin_stop() && running_time < lifetime) {
(void)heartbeat_next(&hb, period);
if (ebpf_plugin_stop() || ++counter != update_every)
continue;

pthread_mutex_lock(&collect_data_mutex);
ebpf_read_shm_apps_table(maps_per_core, max_period);
ebpf_read_shm_apps_table(maps_per_core);
ebpf_shm_resume_apps_data();
pthread_mutex_unlock(&collect_data_mutex);

Expand Down
6 changes: 2 additions & 4 deletions src/collectors/ebpf.plugin/ebpf_swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,8 @@ void ebpf_swap_resume_apps_data() {
* Read the apps table and store data inside the structure.
*
* @param maps_per_core do I need to read all cores?
* @param max_period limit of iterations without updates before remove data from hash table
*/
static void ebpf_read_swap_apps_table(int maps_per_core, uint32_t max_period)
static void ebpf_read_swap_apps_table(int maps_per_core)
{
netdata_ebpf_swap_t *cv = swap_vector;
int fd = swap_maps[NETDATA_PID_SWAP_TABLE].map_fd;
Expand Down Expand Up @@ -609,7 +608,6 @@ void *ebpf_read_swap_thread(void *ptr)
uint32_t lifetime = em->lifetime;
uint32_t running_time = 0;
usec_t period = update_every * USEC_PER_SEC;
uint32_t max_period = EBPF_CLEANUP_FACTOR;
pids_fd[EBPF_PIDS_SWAP_IDX] = swap_maps[NETDATA_PID_SWAP_TABLE].map_fd;

while (!ebpf_plugin_stop() && running_time < lifetime) {
Expand All @@ -618,7 +616,7 @@ void *ebpf_read_swap_thread(void *ptr)
continue;

pthread_mutex_lock(&collect_data_mutex);
ebpf_read_swap_apps_table(maps_per_core, max_period);
ebpf_read_swap_apps_table(maps_per_core);
ebpf_swap_resume_apps_data();
pthread_mutex_unlock(&collect_data_mutex);

Expand Down

0 comments on commit 6611f94

Please sign in to comment.