diff --git a/includes/netdata_common.h b/includes/netdata_common.h index 05a53a94..07d6c050 100644 --- a/includes/netdata_common.h +++ b/includes/netdata_common.h @@ -163,7 +163,7 @@ static __always_inline void *netdata_get_pid_structure(__u32 *store_pid, void *c { __u32 pid, key = NETDATA_CONTROLLER_APPS_LEVEL; - __u32 *level = bpf_map_lookup_elem(ctrl_tbl ,&key); + __u64 *level = bpf_map_lookup_elem(ctrl_tbl ,&key); if (level) { if (*level == NETDATA_APPS_LEVEL_REAL_PARENT) pid = netdata_get_real_parent_pid(); @@ -179,6 +179,15 @@ static __always_inline void *netdata_get_pid_structure(__u32 *store_pid, void *c return bpf_map_lookup_elem(pid_tbl, store_pid); } +static __always_inline __u32 monitor_apps(void *ctrl_tbl) +{ + __u32 apps_key = NETDATA_CONTROLLER_APPS_ENABLED; + __u64 *apps = bpf_map_lookup_elem(ctrl_tbl ,&apps_key); + if (!apps || (apps && *apps == 0)) + return 0; + + return 1; +} #endif /* _NETDATA_COMMON_ */ diff --git a/kernel/btrfs_kern.c b/kernel/btrfs_kern.c index 121f6721..3334f124 100644 --- a/kernel/btrfs_kern.c +++ b/kernel/btrfs_kern.c @@ -51,6 +51,12 @@ struct { __uint(max_entries, 4192); } tmp_btrfs SEC(".maps"); +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __type(key, __u32); + __type(value, __u64); + __uint(max_entries, NETDATA_CONTROLLER_END); +} btrfs_ctrl SEC(".maps"); #else struct bpf_map_def SEC("maps") tbl_btrfs = { @@ -73,6 +79,13 @@ struct bpf_map_def SEC("maps") tmp_btrfs = { .value_size = sizeof(__u64), .max_entries = 4192 }; + +struct bpf_map_def SEC("maps") btrfs_ctrl = { + .type = BPF_MAP_TYPE_ARRAY, + .key_size = sizeof(__u32), + .value_size = sizeof(__u64), + .max_entries = NETDATA_CONTROLLER_END +}; #endif /************************************************************************************ @@ -89,6 +102,8 @@ static __always_inline int netdata_btrfs_entry() bpf_map_update_elem(&tmp_btrfs, &pid, &ts, BPF_ANY); + libnetdata_update_global(&btrfs_ctrl, NETDATA_CONTROLLER_TEMP_TABLE_ADD, 1); + return 0; } @@ -182,6 +197,8 @@ int netdata_ret_generic_file_read_iter(struct pt_regs *ctx) data = bpf_ktime_get_ns() - *fill; bpf_map_delete_elem(&tmp_btrfs, &pid); + libnetdata_update_global(&btrfs_ctrl, NETDATA_CONTROLLER_TEMP_TABLE_DEL, 1); + // Skip entries with backward time if ( (s64)data < 0) return 0; @@ -208,6 +225,8 @@ int netdata_ret_btrfs_file_write_iter(struct pt_regs *ctx) data = bpf_ktime_get_ns() - *fill; bpf_map_delete_elem(&tmp_btrfs, &pid); + libnetdata_update_global(&btrfs_ctrl, NETDATA_CONTROLLER_TEMP_TABLE_DEL, 1); + // Skip entries with backward time if ( (s64)data < 0) return 0; @@ -234,6 +253,8 @@ int netdata_ret_btrfs_file_open(struct pt_regs *ctx) data = bpf_ktime_get_ns() - *fill; bpf_map_delete_elem(&tmp_btrfs, &pid); + libnetdata_update_global(&btrfs_ctrl, NETDATA_CONTROLLER_TEMP_TABLE_DEL, 1); + // Skip entries with backward time if ( (s64)data < 0) return 0; @@ -260,6 +281,8 @@ int netdata_ret_btrfs_sync_file(struct pt_regs *ctx) data = bpf_ktime_get_ns() - *fill; bpf_map_delete_elem(&tmp_btrfs, &pid); + libnetdata_update_global(&btrfs_ctrl, NETDATA_CONTROLLER_TEMP_TABLE_DEL, 1); + // Skip entries with backward time if ( (s64)data < 0) return 0; diff --git a/kernel/cachestat_kern.c b/kernel/cachestat_kern.c index 2b596b82..ef61a5fb 100644 --- a/kernel/cachestat_kern.c +++ b/kernel/cachestat_kern.c @@ -34,7 +34,7 @@ struct { struct { __uint(type, BPF_MAP_TYPE_ARRAY); __type(key, __u32); - __type(value, __u32); + __type(value, __u64); __uint(max_entries, NETDATA_CONTROLLER_END); } cstat_ctrl SEC(".maps"); @@ -57,7 +57,7 @@ struct bpf_map_def SEC("maps") cstat_pid = { struct bpf_map_def SEC("maps") cstat_ctrl = { .type = BPF_MAP_TYPE_ARRAY, .key_size = sizeof(__u32), - .value_size = sizeof(__u32), + .value_size = sizeof(__u64), .max_entries = NETDATA_CONTROLLER_END }; @@ -75,11 +75,9 @@ int netdata_add_to_page_cache_lru(struct pt_regs* ctx) netdata_cachestat_t *fill, data = {}; libnetdata_update_global(&cstat_global, NETDATA_KEY_CALLS_ADD_TO_PAGE_CACHE_LRU, 1); - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&cstat_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&cstat_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &cstat_ctrl, &cstat_pid); if (fill) { @@ -87,6 +85,8 @@ int netdata_add_to_page_cache_lru(struct pt_regs* ctx) } else { data.add_to_page_cache_lru = 1; bpf_map_update_elem(&cstat_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&cstat_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -98,11 +98,9 @@ int netdata_mark_page_accessed(struct pt_regs* ctx) netdata_cachestat_t *fill, data = {}; libnetdata_update_global(&cstat_global, NETDATA_KEY_CALLS_MARK_PAGE_ACCESSED, 1); - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&cstat_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&cstat_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &cstat_ctrl, &cstat_pid); if (fill) { @@ -110,6 +108,8 @@ int netdata_mark_page_accessed(struct pt_regs* ctx) } else { data.mark_page_accessed = 1; bpf_map_update_elem(&cstat_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&cstat_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -140,11 +140,9 @@ int netdata_set_page_dirty(struct pt_regs* ctx) netdata_cachestat_t *fill, data = {}; libnetdata_update_global(&cstat_global, NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED, 1); - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&cstat_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&cstat_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &cstat_ctrl, &cstat_pid); if (fill) { @@ -152,6 +150,8 @@ int netdata_set_page_dirty(struct pt_regs* ctx) } else { data.account_page_dirtied = 1; bpf_map_update_elem(&cstat_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&cstat_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -167,11 +167,9 @@ int netdata_account_page_dirtied(struct pt_regs* ctx) netdata_cachestat_t *fill, data = {}; libnetdata_update_global(&cstat_global, NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED, 1); - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&cstat_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&cstat_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &cstat_ctrl, &cstat_pid); if (fill) { @@ -179,6 +177,8 @@ int netdata_account_page_dirtied(struct pt_regs* ctx) } else { data.account_page_dirtied = 1; bpf_map_update_elem(&cstat_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&cstat_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -191,11 +191,9 @@ int netdata_mark_buffer_dirty(struct pt_regs* ctx) netdata_cachestat_t *fill, data = {}; libnetdata_update_global(&cstat_global, NETDATA_KEY_CALLS_MARK_BUFFER_DIRTY, 1); - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&cstat_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&cstat_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &cstat_ctrl, &cstat_pid); if (fill) { @@ -203,6 +201,8 @@ int netdata_mark_buffer_dirty(struct pt_regs* ctx) } else { data.mark_buffer_dirty = 1; bpf_map_update_elem(&cstat_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&cstat_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -221,17 +221,15 @@ SEC("kprobe/release_task") int netdata_release_task_dc(struct pt_regs* ctx) { netdata_cachestat_t *removeme; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&cstat_ctrl ,&key); - if (apps) { - if (*apps == 0) - return 0; - } else + __u32 key = 0; + if (!monitor_apps(&cstat_ctrl)) return 0; removeme = netdata_get_pid_structure(&key, &cstat_ctrl, &cstat_pid); if (removeme) { bpf_map_delete_elem(&cstat_pid, &key); + + libnetdata_update_global(&cstat_ctrl, NETDATA_CONTROLLER_PID_TABLE_DEL, 1); } return 0; diff --git a/kernel/dc_kern.c b/kernel/dc_kern.c index 7dbe9baa..eec4d389 100644 --- a/kernel/dc_kern.c +++ b/kernel/dc_kern.c @@ -37,7 +37,7 @@ struct { struct { __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); __type(key, __u32); - __type(value, __u32); + __type(value, __u64); __uint(max_entries, NETDATA_CONTROLLER_END); } dcstat_ctrl SEC(".maps"); @@ -60,7 +60,7 @@ struct bpf_map_def SEC("maps") dcstat_pid = { struct bpf_map_def SEC("maps") dcstat_ctrl = { .type = BPF_MAP_TYPE_ARRAY, .key_size = sizeof(__u32), - .value_size = sizeof(__u32), + .value_size = sizeof(__u64), .max_entries = NETDATA_CONTROLLER_END }; @@ -78,11 +78,9 @@ int netdata_lookup_fast(struct pt_regs* ctx) netdata_dc_stat_t *fill, data = {}; libnetdata_update_global(&dcstat_global, NETDATA_KEY_DC_REFERENCE, 1); - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&dcstat_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&dcstat_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &dcstat_ctrl, &dcstat_pid); if (fill) { @@ -90,6 +88,8 @@ int netdata_lookup_fast(struct pt_regs* ctx) } else { data.references = 1; bpf_map_update_elem(&dcstat_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&dcstat_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -103,32 +103,31 @@ int netdata_d_lookup(struct pt_regs* ctx) int ret = PT_REGS_RC(ctx); - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&dcstat_ctrl ,&key); - if (!apps) + __u32 key = 0; + if (!monitor_apps(&dcstat_ctrl)) return 0; - if (*apps == 1) { - fill = netdata_get_pid_structure(&key, &dcstat_ctrl, &dcstat_pid); - if (fill) { - libnetdata_update_u64(&fill->slow, 1); - } else { - data.slow = 1; - bpf_map_update_elem(&dcstat_pid, &key, &data, BPF_ANY); - } + fill = netdata_get_pid_structure(&key, &dcstat_ctrl, &dcstat_pid); + if (fill) { + libnetdata_update_u64(&fill->slow, 1); + } else { + data.slow = 1; + bpf_map_update_elem(&dcstat_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&dcstat_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } // file not found if (ret == 0) { libnetdata_update_global(&dcstat_global, NETDATA_KEY_DC_MISS, 1); - if (*apps == 1) { - fill = netdata_get_pid_structure(&key, &dcstat_ctrl, &dcstat_pid); - if (fill) { - libnetdata_update_u64(&fill->missed, 1); - } else { - data.missed = 1; - bpf_map_update_elem(&dcstat_pid, &key, &data, BPF_ANY); - } + fill = netdata_get_pid_structure(&key, &dcstat_ctrl, &dcstat_pid); + if (fill) { + libnetdata_update_u64(&fill->missed, 1); + } else { + data.missed = 1; + bpf_map_update_elem(&dcstat_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&dcstat_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } } @@ -148,17 +147,15 @@ SEC("kprobe/release_task") int netdata_release_task_dc(struct pt_regs* ctx) { netdata_dc_stat_t *removeme; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&dcstat_ctrl ,&key); - if (apps) { - if (*apps == 0) - return 0; - } else + __u32 key = 0; + if (!monitor_apps(&dcstat_ctrl)) return 0; removeme = netdata_get_pid_structure(&key, &dcstat_ctrl, &dcstat_pid); if (removeme) { bpf_map_delete_elem(&dcstat_pid, &key); + + libnetdata_update_global(&dcstat_ctrl, NETDATA_CONTROLLER_PID_TABLE_DEL, 1); } return 0; diff --git a/kernel/disk_kern.c b/kernel/disk_kern.c index 2e222be7..39b75bd4 100644 --- a/kernel/disk_kern.c +++ b/kernel/disk_kern.c @@ -40,6 +40,13 @@ struct { __uint(max_entries, 8192); } tmp_disk_tp_stat SEC(".maps"); +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __type(key, __u32); + __type(value, __u64); + __uint(max_entries, NETDATA_CONTROLLER_END); +} disk_ctrl SEC(".maps"); + #else //Hardware @@ -62,6 +69,13 @@ struct bpf_map_def SEC("maps") tmp_disk_tp_stat = { .max_entries = 8192 }; +struct bpf_map_def SEC("maps") disk_ctrl = { + .type = BPF_MAP_TYPE_ARRAY, + .key_size = sizeof(__u32), + .value_size = sizeof(__u64), + .max_entries = NETDATA_CONTROLLER_END +}; + #endif /************************************************************************************ @@ -90,6 +104,8 @@ int netdata_block_rq_issue(struct netdata_block_rq_issue *ptr) bpf_map_update_elem(&tmp_disk_tp_stat, &key, &value, BPF_ANY); + libnetdata_update_global(&disk_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); + return 0; } @@ -129,6 +145,8 @@ int netdata_block_rq_complete(struct netdata_block_rq_complete *ptr) bpf_map_delete_elem(&tmp_disk_tp_stat, &key); + libnetdata_update_global(&disk_ctrl, NETDATA_CONTROLLER_PID_TABLE_DEL, 1); + return 0; } diff --git a/kernel/ext4_kern.c b/kernel/ext4_kern.c index d058b83e..5dd0758a 100644 --- a/kernel/ext4_kern.c +++ b/kernel/ext4_kern.c @@ -38,6 +38,13 @@ struct { __uint(max_entries, 4192); } tmp_ext4 SEC(".maps"); +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __type(key, __u32); + __type(value, __u64); + __uint(max_entries, NETDATA_CONTROLLER_END); +} ext4_ctrl SEC(".maps"); + #else struct bpf_map_def SEC("maps") tbl_ext4 = { @@ -54,6 +61,13 @@ struct bpf_map_def SEC("maps") tmp_ext4 = { .max_entries = 4192 }; +struct bpf_map_def SEC("maps") ext4_ctrl = { + .type = BPF_MAP_TYPE_ARRAY, + .key_size = sizeof(__u32), + .value_size = sizeof(__u64), + .max_entries = NETDATA_CONTROLLER_END +}; + #endif /************************************************************************************ @@ -70,6 +84,8 @@ static __always_inline int netdata_ext4_entry() bpf_map_update_elem(&tmp_ext4, &pid, &ts, BPF_ANY); + libnetdata_update_global(&ext4_ctrl, NETDATA_CONTROLLER_TEMP_TABLE_ADD, 1); + return 0; } @@ -118,6 +134,8 @@ static void netdata_ext4_store_bin(__u32 bin, __u32 selection) data = 1; bpf_map_update_elem(&tbl_ext4, &idx, &data, BPF_ANY); + + libnetdata_update_global(&ext4_ctrl, NETDATA_CONTROLLER_TEMP_TABLE_DEL, 1); } SEC("kretprobe/ext4_file_read_iter") diff --git a/kernel/fd_kern.c b/kernel/fd_kern.c index b289496c..a79d4cf6 100644 --- a/kernel/fd_kern.c +++ b/kernel/fd_kern.c @@ -41,7 +41,7 @@ struct { struct { __uint(type, BPF_MAP_TYPE_ARRAY); __type(key, __u32); - __type(value, __u32); + __type(value, __u64); __uint(max_entries, NETDATA_CONTROLLER_END); } fd_ctrl SEC(".maps"); @@ -64,7 +64,7 @@ struct bpf_map_def SEC("maps") tbl_fd_global = { struct bpf_map_def SEC("maps") fd_ctrl = { .type = BPF_MAP_TYPE_ARRAY, .key_size = sizeof(__u32), - .value_size = sizeof(__u32), + .value_size = sizeof(__u64), .max_entries = NETDATA_CONTROLLER_END }; @@ -96,7 +96,6 @@ int netdata_sys_open(struct pt_regs* ctx) #endif struct netdata_fd_stat_t *fill; struct netdata_fd_stat_t data = { }; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; libnetdata_update_global(&tbl_fd_global, NETDATA_KEY_CALLS_DO_SYS_OPEN, 1); #if NETDATASEL < 2 @@ -105,10 +104,9 @@ int netdata_sys_open(struct pt_regs* ctx) } #endif - __u32 *apps = bpf_map_lookup_elem(&fd_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&fd_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &fd_ctrl, &tbl_fd_pid); if (fill) { @@ -132,6 +130,8 @@ int netdata_sys_open(struct pt_regs* ctx) data.open_call = 1; bpf_map_update_elem(&tbl_fd_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&fd_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -156,14 +156,13 @@ SEC("kprobe/close_fd") # else /* RHEL_MAJOR */ SEC("kprobe/__close_fd") # endif /* RHEL_MAJOR */ -# endif/* NETDATASEL < 2 */ +# endif /* NETDATASEL < 2 */ #endif /* KERNEL > 5.11 */ int netdata_close(struct pt_regs* ctx) { #if NETDATASEL < 2 int ret = (int)PT_REGS_RC(ctx); #endif - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; struct netdata_fd_stat_t data = { }; struct netdata_fd_stat_t *fill; @@ -174,10 +173,9 @@ int netdata_close(struct pt_regs* ctx) } #endif - __u32 *apps = bpf_map_lookup_elem(&fd_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&fd_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &fd_ctrl, &tbl_fd_pid); if (fill) { @@ -197,6 +195,8 @@ int netdata_close(struct pt_regs* ctx) #endif bpf_map_update_elem(&tbl_fd_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&fd_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -215,17 +215,15 @@ SEC("kprobe/release_task") int netdata_release_task_fd(struct pt_regs* ctx) { struct netdata_fd_stat_t *removeme; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&fd_ctrl ,&key); - if (apps) { - if (*apps == 0) - return 0; - } else + __u32 key = 0; + if (!monitor_apps(&fd_ctrl)) return 0; removeme = netdata_get_pid_structure(&key, &fd_ctrl, &tbl_fd_pid); if (removeme) { bpf_map_delete_elem(&tbl_fd_pid, &key); + + libnetdata_update_global(&fd_ctrl, NETDATA_CONTROLLER_PID_TABLE_DEL, 1); } return 0; diff --git a/kernel/nfs_kern.c b/kernel/nfs_kern.c index 2d2ab218..1f9e2d21 100644 --- a/kernel/nfs_kern.c +++ b/kernel/nfs_kern.c @@ -38,6 +38,13 @@ struct { __uint(max_entries, 4192); } tmp_nfs SEC(".maps"); +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __type(key, __u32); + __type(value, __u64); + __uint(max_entries, NETDATA_CONTROLLER_END); +} nfs_ctrl SEC(".maps"); + #else struct bpf_map_def SEC("maps") tbl_nfs = { @@ -54,6 +61,13 @@ struct bpf_map_def SEC("maps") tmp_nfs = { .max_entries = 4192 }; +struct bpf_map_def SEC("maps") nfs_ctrl = { + .type = BPF_MAP_TYPE_ARRAY, + .key_size = sizeof(__u32), + .value_size = sizeof(__u64), + .max_entries = NETDATA_CONTROLLER_END +}; + #endif /************************************************************************************ @@ -70,6 +84,8 @@ static __always_inline int netdata_nfs_entry() bpf_map_update_elem(&tmp_nfs, &pid, &ts, BPF_ANY); + libnetdata_update_global(&nfs_ctrl, NETDATA_CONTROLLER_TEMP_TABLE_ADD, 1); + return 0; } @@ -124,6 +140,8 @@ static void netdata_nfs_store_bin(__u32 bin, __u32 selection) data = 1; bpf_map_update_elem(&tbl_nfs, &idx, &data, BPF_ANY); + + libnetdata_update_global(&nfs_ctrl, NETDATA_CONTROLLER_TEMP_TABLE_DEL, 1); } SEC("kretprobe/nfs_file_read") diff --git a/kernel/process_kern.c b/kernel/process_kern.c index 0c7447f4..ce85816c 100644 --- a/kernel/process_kern.c +++ b/kernel/process_kern.c @@ -40,7 +40,7 @@ struct { struct { __uint(type, BPF_MAP_TYPE_ARRAY); __type(key, __u32); - __type(value, __u32); + __type(value, __u64); __uint(max_entries, NETDATA_CONTROLLER_END); } process_ctrl SEC(".maps"); @@ -63,7 +63,7 @@ struct bpf_map_def SEC("maps") tbl_total_stats = { struct bpf_map_def SEC("maps") process_ctrl = { .type = BPF_MAP_TYPE_ARRAY, .key_size = sizeof(__u32), - .value_size = sizeof(__u32), + .value_size = sizeof(__u64), .max_entries = NETDATA_CONTROLLER_END }; @@ -94,13 +94,11 @@ SEC("tracepoint/sched/sched_process_exit") int netdata_tracepoint_sched_process_exit(struct netdata_sched_process_exit *ptr) { struct netdata_pid_stat_t *fill; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; libnetdata_update_global(&tbl_total_stats, NETDATA_KEY_CALLS_DO_EXIT, 1); - __u32 *apps = bpf_map_lookup_elem(&process_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&process_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &process_ctrl, &tbl_pid_stats); if (fill) { @@ -114,17 +112,17 @@ SEC("kprobe/release_task") int netdata_release_task(struct pt_regs* ctx) { struct netdata_pid_stat_t *fill; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; libnetdata_update_global(&tbl_total_stats, NETDATA_KEY_CALLS_RELEASE_TASK, 1); - __u32 *apps = bpf_map_lookup_elem(&process_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&process_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &process_ctrl, &tbl_pid_stats); if (fill) { libnetdata_update_u32(&fill->release_call, 1) ; + + libnetdata_update_global(&process_ctrl, NETDATA_CONTROLLER_PID_TABLE_DEL, 1); } return 0; @@ -135,14 +133,12 @@ int netdata_tracepoint_sched_process_exec(struct netdata_sched_process_exec *ptr { struct netdata_pid_stat_t data = { }; struct netdata_pid_stat_t *fill; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; // This is necessary, because it represents the main function to start a thread libnetdata_update_global(&tbl_total_stats, NETDATA_KEY_CALLS_PROCESS, 1); - __u32 *apps = bpf_map_lookup_elem(&process_ctrl, &key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&process_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &process_ctrl, &tbl_pid_stats); if (fill) { @@ -153,6 +149,8 @@ int netdata_tracepoint_sched_process_exec(struct netdata_sched_process_exec *ptr data.create_process = 1; bpf_map_update_elem(&tbl_pid_stats, &key, &data, BPF_ANY); + + libnetdata_update_global(&process_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -163,7 +161,6 @@ int netdata_tracepoint_sched_process_fork(struct netdata_sched_process_fork *ptr { struct netdata_pid_stat_t data = { }; struct netdata_pid_stat_t *fill; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; libnetdata_update_global(&tbl_total_stats, NETDATA_KEY_CALLS_PROCESS, 1); @@ -174,10 +171,9 @@ int netdata_tracepoint_sched_process_fork(struct netdata_sched_process_fork *ptr libnetdata_update_global(&tbl_total_stats, NETDATA_KEY_CALLS_THREAD, 1); } - __u32 *apps = bpf_map_lookup_elem(&process_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&process_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &process_ctrl, &tbl_pid_stats); if (fill) { @@ -192,6 +188,8 @@ int netdata_tracepoint_sched_process_fork(struct netdata_sched_process_fork *ptr data.create_thread = 1; bpf_map_update_elem(&tbl_pid_stats, &key, &data, BPF_ANY); + + libnetdata_update_global(&process_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } @@ -218,7 +216,6 @@ int netdata_fork(struct pt_regs* ctx) #if NETDATASEL < 2 int ret = (int)PT_REGS_RC(ctx); #endif - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; struct netdata_pid_stat_t data = { }; struct netdata_pid_stat_t *fill; @@ -228,10 +225,9 @@ int netdata_fork(struct pt_regs* ctx) } #endif - __u32 *apps = bpf_map_lookup_elem(&process_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&process_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &process_ctrl, &tbl_pid_stats); if (fill) { @@ -250,6 +246,8 @@ int netdata_fork(struct pt_regs* ctx) } #endif bpf_map_update_elem(&tbl_pid_stats, &key, &data, BPF_ANY); + + libnetdata_update_global(&process_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -270,7 +268,6 @@ int netdata_sys_clone(struct pt_regs *ctx) #endif struct netdata_pid_stat_t data = { }; struct netdata_pid_stat_t *fill; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; #if NETDATASEL < 2 if (ret < 0) { @@ -278,10 +275,9 @@ int netdata_sys_clone(struct pt_regs *ctx) } #endif - __u32 *apps = bpf_map_lookup_elem(&process_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&process_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &process_ctrl, &tbl_pid_stats); if (fill) { @@ -302,6 +298,8 @@ int netdata_sys_clone(struct pt_regs *ctx) #endif bpf_map_update_elem(&tbl_pid_stats, &key, &data, BPF_ANY); + + libnetdata_update_global(&process_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; } diff --git a/kernel/shm_kern.c b/kernel/shm_kern.c index 6542d0aa..eec31943 100644 --- a/kernel/shm_kern.c +++ b/kernel/shm_kern.c @@ -33,7 +33,7 @@ struct { struct { __uint(type, BPF_MAP_TYPE_ARRAY); __type(key, __u32); - __type(value, __u32); + __type(value, __u64); __uint(max_entries, NETDATA_CONTROLLER_END); } shm_ctrl SEC(".maps"); #else @@ -54,7 +54,7 @@ struct bpf_map_def SEC("maps") tbl_pid_shm = { struct bpf_map_def SEC("maps") shm_ctrl = { .type = BPF_MAP_TYPE_ARRAY, .key_size = sizeof(__u32), - .value_size = sizeof(__u32), + .value_size = sizeof(__u64), .max_entries = NETDATA_CONTROLLER_END }; #endif @@ -71,13 +71,9 @@ int netdata_syscall_shmget(struct pt_regs *ctx) libnetdata_update_global(&tbl_shm, NETDATA_KEY_SHMGET_CALL, 1); // check if apps is enabled; if not, don't record apps data. - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&shm_ctrl, &key); - if (apps) { - if (*apps == 0) { - return 0; - } - } + __u32 key = 0; + if (!monitor_apps(&shm_ctrl)) + return 0; netdata_shm_t *fill = netdata_get_pid_structure(&key, &shm_ctrl, &tbl_pid_shm); if (fill) { @@ -85,6 +81,8 @@ int netdata_syscall_shmget(struct pt_regs *ctx) } else { data.get = 1; bpf_map_update_elem(&tbl_pid_shm, &key, &data, BPF_ANY); + + libnetdata_update_global(&shm_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -102,13 +100,9 @@ int netdata_syscall_shmat(struct pt_regs *ctx) libnetdata_update_global(&tbl_shm, NETDATA_KEY_SHMAT_CALL, 1); // check if apps is enabled; if not, don't record apps data. - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&shm_ctrl, &key); - if (apps) { - if (*apps == 0) { - return 0; - } - } + __u32 key = 0; + if (!monitor_apps(&shm_ctrl)) + return 0; netdata_shm_t *fill = netdata_get_pid_structure(&key, &shm_ctrl, &tbl_pid_shm); if (fill) { @@ -116,6 +110,8 @@ int netdata_syscall_shmat(struct pt_regs *ctx) } else { data.at = 1; bpf_map_update_elem(&tbl_pid_shm, &key, &data, BPF_ANY); + + libnetdata_update_global(&shm_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -133,13 +129,9 @@ int netdata_syscall_shmdt(struct pt_regs *ctx) libnetdata_update_global(&tbl_shm, NETDATA_KEY_SHMDT_CALL, 1); // check if apps is enabled; if not, don't record apps data. - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&shm_ctrl, &key); - if (apps) { - if (*apps == 0) { - return 0; - } - } + __u32 key = 0; + if (!monitor_apps(&shm_ctrl)) + return 0; netdata_shm_t *fill = netdata_get_pid_structure(&key, &shm_ctrl, &tbl_pid_shm); if (fill) { @@ -147,6 +139,8 @@ int netdata_syscall_shmdt(struct pt_regs *ctx) } else { data.dt = 1; bpf_map_update_elem(&tbl_pid_shm, &key, &data, BPF_ANY); + + libnetdata_update_global(&shm_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -164,13 +158,9 @@ int netdata_syscall_shmctl(struct pt_regs *ctx) libnetdata_update_global(&tbl_shm, NETDATA_KEY_SHMCTL_CALL, 1); // check if apps is enabled; if not, don't record apps data. - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&shm_ctrl, &key); - if (apps) { - if (*apps == 0) { - return 0; - } - } + __u32 key = 0; + if (!monitor_apps(&shm_ctrl)) + return 0; netdata_shm_t *fill = netdata_get_pid_structure(&key, &shm_ctrl, &tbl_pid_shm); if (fill) { @@ -178,6 +168,8 @@ int netdata_syscall_shmctl(struct pt_regs *ctx) } else { data.ctl = 1; bpf_map_update_elem(&tbl_pid_shm, &key, &data, BPF_ANY); + + libnetdata_update_global(&shm_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -196,17 +188,15 @@ SEC("kprobe/release_task") int netdata_release_task_shm(struct pt_regs* ctx) { netdata_shm_t *removeme; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&shm_ctrl ,&key); - if (apps) { - if (*apps == 0) - return 0; - } else + __u32 key = 0; + if (!monitor_apps(&shm_ctrl)) return 0; removeme = netdata_get_pid_structure(&key, &shm_ctrl, &tbl_pid_shm); if (removeme) { bpf_map_delete_elem(&tbl_pid_shm, &key); + + libnetdata_update_global(&shm_ctrl, NETDATA_CONTROLLER_PID_TABLE_DEL, 1); } return 0; diff --git a/kernel/socket_kern.c b/kernel/socket_kern.c index 8fc09df7..908a421b 100644 --- a/kernel/socket_kern.c +++ b/kernel/socket_kern.c @@ -87,7 +87,7 @@ struct { struct { __uint(type, BPF_MAP_TYPE_ARRAY); __type(key, __u32); - __type(value, __u32); + __type(value, __u64); __uint(max_entries, NETDATA_CONTROLLER_END); } socket_ctrl SEC(".maps"); @@ -138,7 +138,7 @@ struct bpf_map_def SEC("maps") tbl_lports = { struct bpf_map_def SEC("maps") socket_ctrl = { .type = BPF_MAP_TYPE_ARRAY, .key_size = sizeof(__u32), - .value_size = sizeof(__u32), + .value_size = sizeof(__u64), .max_entries = NETDATA_CONTROLLER_END }; @@ -258,13 +258,9 @@ static __always_inline void update_pid_bandwidth(__u64 sent, __u64 received, __u { netdata_bandwidth_t *b; netdata_bandwidth_t data = { }; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&socket_ctrl ,&key); - if (apps) { - if (*apps == 0) - return; - } else + __u32 key = 0; + if (!monitor_apps(&socket_ctrl)) return; __u64 pid_tgid = bpf_get_current_pid_tgid(); @@ -340,12 +336,8 @@ static __always_inline void update_pid_connection(__u8 version) netdata_bandwidth_t *stored; netdata_bandwidth_t data = { }; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&socket_ctrl ,&key); - if (apps) { - if (*apps == 0) - return; - } else + __u32 key = 0; + if (!monitor_apps(&socket_ctrl)) return; __u64 pid_tgid = bpf_get_current_pid_tgid(); @@ -381,12 +373,8 @@ static __always_inline void update_pid_cleanup(__u64 drop, __u64 close) netdata_bandwidth_t *b; netdata_bandwidth_t data = { }; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&socket_ctrl ,&key); - if (apps) { - if (*apps == 0) - return; - } else + __u32 key = 0; + if (!monitor_apps(&socket_ctrl)) return; __u64 pid_tgid = bpf_get_current_pid_tgid(); @@ -691,11 +679,9 @@ SEC("kprobe/release_task") int netdata_release_task_socket(struct pt_regs* ctx) { netdata_bandwidth_t *removeme; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&socket_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&socket_ctrl)) + return 0; removeme = (netdata_bandwidth_t *) netdata_get_pid_structure(&key, &socket_ctrl, &tbl_bandwidth); if (removeme) diff --git a/kernel/swap_kern.c b/kernel/swap_kern.c index 34cbbf62..b8fef085 100644 --- a/kernel/swap_kern.c +++ b/kernel/swap_kern.c @@ -39,7 +39,7 @@ struct { struct { __uint(type, BPF_MAP_TYPE_ARRAY); __type(key, __u32); - __type(value, __u32); + __type(value, __u64); __uint(max_entries, NETDATA_CONTROLLER_END); } swap_ctrl SEC(".maps"); #else @@ -60,7 +60,7 @@ struct bpf_map_def SEC("maps") tbl_pid_swap = { struct bpf_map_def SEC("maps") swap_ctrl = { .type = BPF_MAP_TYPE_ARRAY, .key_size = sizeof(__u32), - .value_size = sizeof(__u32), + .value_size = sizeof(__u64), .max_entries = NETDATA_CONTROLLER_END }; #endif @@ -78,11 +78,9 @@ int netdata_swap_readpage(struct pt_regs* ctx) libnetdata_update_global(&tbl_swap, NETDATA_KEY_SWAP_READPAGE_CALL, 1); - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&swap_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&swap_ctrl)) + return 0; netdata_swap_access_t *fill = netdata_get_pid_structure(&key, &swap_ctrl, &tbl_pid_swap); if (fill) { @@ -90,6 +88,8 @@ int netdata_swap_readpage(struct pt_regs* ctx) } else { data.read = 1; bpf_map_update_elem(&tbl_pid_swap, &key, &data, BPF_ANY); + + libnetdata_update_global(&swap_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -102,11 +102,9 @@ int netdata_swap_writepage(struct pt_regs* ctx) libnetdata_update_global(&tbl_swap, NETDATA_KEY_SWAP_WRITEPAGE_CALL, 1); - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&swap_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&swap_ctrl)) + return 0; netdata_swap_access_t *fill = netdata_get_pid_structure(&key, &swap_ctrl, &tbl_pid_swap); if (fill) { @@ -114,6 +112,8 @@ int netdata_swap_writepage(struct pt_regs* ctx) } else { data.write = 1; bpf_map_update_elem(&tbl_pid_swap, &key, &data, BPF_ANY); + + libnetdata_update_global(&swap_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -138,17 +138,15 @@ SEC("kprobe/release_task") int netdata_release_task_swap(struct pt_regs* ctx) { netdata_cachestat_t *removeme; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&swap_ctrl ,&key); - if (apps) { - if (*apps == 0) - return 0; - } else + __u32 key = 0; + if (!monitor_apps(&swap_ctrl)) return 0; removeme = netdata_get_pid_structure(&key, &swap_ctrl, &tbl_pid_swap); if (removeme) { bpf_map_delete_elem(&tbl_pid_swap, &key); + + libnetdata_update_global(&swap_ctrl, NETDATA_CONTROLLER_PID_TABLE_DEL, 1); } return 0; diff --git a/kernel/tester_user.c b/kernel/tester_user.c index 5d24931d..cf47c2a0 100644 --- a/kernel/tester_user.c +++ b/kernel/tester_user.c @@ -28,15 +28,15 @@ static ebpf_specify_name_t dc_optional_name[] = { {.program_name = "netdata_look // Version 5_4 must be present for kernels newer than 4.17.0 ebpf_module_t ebpf_modules[] = { { .kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4 | NETDATA_V5_10 | NETDATA_V5_14, - .flags = NETDATA_FLAG_BTRFS, .name = "btrfs", .update_names = NULL, .ctrl_table = NULL }, + .flags = NETDATA_FLAG_BTRFS, .name = "btrfs", .update_names = NULL, .ctrl_table = "btrfs_ctrl" }, { .kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4 | NETDATA_V5_15 | NETDATA_V5_14 | NETDATA_V5_16, .flags = NETDATA_FLAG_CACHESTAT, .name = "cachestat", .update_names = NULL, .ctrl_table = "cstat_ctrl" }, { .kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4 | NETDATA_V5_14, .flags = NETDATA_FLAG_DC, .name = "dc", .update_names = dc_optional_name, .ctrl_table = "dcstat_ctrl" }, { .kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4 | NETDATA_V5_14, - .flags = NETDATA_FLAG_DISK, .name = "disk", .update_names = NULL, .ctrl_table = NULL }, + .flags = NETDATA_FLAG_DISK, .name = "disk", .update_names = NULL, .ctrl_table = "disk_ctrl" }, { .kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4 | NETDATA_V5_14, - .flags = NETDATA_FLAG_EXT4, .name = "ext4", .update_names = NULL, .ctrl_table = NULL }, + .flags = NETDATA_FLAG_EXT4, .name = "ext4", .update_names = NULL, .ctrl_table = "ext4_ctrl" }, { .kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4 | NETDATA_V5_11 | NETDATA_V5_14, .flags = NETDATA_FLAG_FD, .name = "fd", .update_names = NULL, .ctrl_table = "fd_ctrl" }, { .kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4 | NETDATA_V5_14, @@ -52,7 +52,7 @@ ebpf_module_t ebpf_modules[] = { { .kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4 | NETDATA_V5_14, .flags = NETDATA_FLAG_SYNC, .name = "msync", .update_names = NULL, .ctrl_table = NULL }, { .kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4 | NETDATA_V5_14, - .flags = NETDATA_FLAG_NFS, .name = "nfs", .update_names = NULL, .ctrl_table = NULL }, + .flags = NETDATA_FLAG_NFS, .name = "nfs", .update_names = NULL, .ctrl_table = "nfs_ctrl" }, { .kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4 | NETDATA_V5_14, .flags = NETDATA_FLAG_OOMKILL, .name = "oomkill", .update_names = NULL, .ctrl_table = NULL }, { .kernels = NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4 | NETDATA_V5_14 | NETDATA_V5_10, @@ -74,9 +74,9 @@ ebpf_module_t ebpf_modules[] = { { .kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4 | NETDATA_V5_14, .flags = NETDATA_FLAG_VFS, .name = "vfs", .update_names = NULL, .ctrl_table = "vfs_ctrl" }, { .kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4 | NETDATA_V5_14, - .flags = NETDATA_FLAG_XFS, .name = "xfs", .update_names = NULL, .ctrl_table = NULL }, + .flags = NETDATA_FLAG_XFS, .name = "xfs", .update_names = NULL, .ctrl_table = "xfs_ctrl" }, { .kernels = NETDATA_V3_10 | NETDATA_V4_14 | NETDATA_V4_16 | NETDATA_V4_18 | NETDATA_V5_4 | NETDATA_V5_14, - .flags = NETDATA_FLAG_ZFS, .name = "zfs", .update_names = NULL, .ctrl_table = NULL }, + .flags = NETDATA_FLAG_ZFS, .name = "zfs", .update_names = NULL, .ctrl_table = "zfs_ctrl" }, { .kernels = 0, .name = NULL, .update_names = NULL } }; diff --git a/kernel/vfs_kern.c b/kernel/vfs_kern.c index 58f05e3b..614362d2 100644 --- a/kernel/vfs_kern.c +++ b/kernel/vfs_kern.c @@ -41,7 +41,7 @@ struct { struct { __uint(type, BPF_MAP_TYPE_ARRAY); __type(key, __u32); - __type(value, __u32); + __type(value, __u64); __uint(max_entries, NETDATA_CONTROLLER_END); } vfs_ctrl SEC(".maps"); #else @@ -62,7 +62,7 @@ struct bpf_map_def SEC("maps") tbl_vfs_stats = { struct bpf_map_def SEC("maps") vfs_ctrl = { .type = BPF_MAP_TYPE_ARRAY, .key_size = sizeof(__u32), - .value_size = sizeof(__u32), + .value_size = sizeof(__u64), .max_entries = NETDATA_CONTROLLER_END }; #endif @@ -103,11 +103,9 @@ int netdata_sys_write(struct pt_regs* ctx) struct netdata_vfs_stat_t data = { }; __u64 tot; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&vfs_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&vfs_ctrl)) + return 0; libnetdata_update_global(&tbl_vfs_stats, NETDATA_KEY_CALLS_VFS_WRITE, 1); #if NETDATASEL < 2 @@ -148,6 +146,8 @@ int netdata_sys_write(struct pt_regs* ctx) data.write_call = 1; bpf_map_update_elem(&tbl_vfs_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&vfs_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -180,11 +180,9 @@ int netdata_sys_writev(struct pt_regs* ctx) tot = libnetdata_log2l(ret); libnetdata_update_global(&tbl_vfs_stats, NETDATA_KEY_BYTES_VFS_WRITEV, tot); - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&vfs_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&vfs_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &vfs_ctrl, &tbl_vfs_pid); if (fill) { @@ -214,6 +212,8 @@ int netdata_sys_writev(struct pt_regs* ctx) data.writev_call = 1; bpf_map_update_elem(&tbl_vfs_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&vfs_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -246,11 +246,9 @@ int netdata_sys_read(struct pt_regs* ctx) tot = libnetdata_log2l(ret); libnetdata_update_global(&tbl_vfs_stats, NETDATA_KEY_BYTES_VFS_READ, tot); - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&vfs_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&vfs_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &vfs_ctrl, &tbl_vfs_pid); if (fill) { @@ -280,6 +278,8 @@ int netdata_sys_read(struct pt_regs* ctx) data.read_call = 1; bpf_map_update_elem(&tbl_vfs_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&vfs_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -312,11 +312,9 @@ int netdata_sys_readv(struct pt_regs* ctx) tot = libnetdata_log2l(ret); libnetdata_update_global(&tbl_vfs_stats, NETDATA_KEY_BYTES_VFS_READV, tot); - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&vfs_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&vfs_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &vfs_ctrl, &tbl_vfs_pid); if (fill) { @@ -347,6 +345,8 @@ int netdata_sys_readv(struct pt_regs* ctx) data.readv_call = 1; bpf_map_update_elem(&tbl_vfs_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&vfs_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -373,11 +373,9 @@ int netdata_sys_unlink(struct pt_regs* ctx) } #endif - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&vfs_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&vfs_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &vfs_ctrl, &tbl_vfs_pid); if (fill) { @@ -403,6 +401,8 @@ int netdata_sys_unlink(struct pt_regs* ctx) data.unlink_call = 1; bpf_map_update_elem(&tbl_vfs_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&vfs_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -429,11 +429,9 @@ int netdata_vfs_fsync(struct pt_regs* ctx) } #endif - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&vfs_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&vfs_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &vfs_ctrl, &tbl_vfs_pid); if (fill) { @@ -459,6 +457,8 @@ int netdata_vfs_fsync(struct pt_regs* ctx) data.fsync_call = 1; bpf_map_update_elem(&tbl_vfs_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&vfs_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -485,11 +485,9 @@ int netdata_vfs_open(struct pt_regs* ctx) } #endif - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&vfs_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&vfs_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &vfs_ctrl, &tbl_vfs_pid); if (fill) { @@ -515,6 +513,8 @@ int netdata_vfs_open(struct pt_regs* ctx) data.open_call = 1; bpf_map_update_elem(&tbl_vfs_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&vfs_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -541,11 +541,9 @@ int netdata_vfs_create(struct pt_regs* ctx) } #endif - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&vfs_ctrl ,&key); - if (apps) - if (*apps == 0) - return 0; + __u32 key = 0; + if (!monitor_apps(&vfs_ctrl)) + return 0; fill = netdata_get_pid_structure(&key, &vfs_ctrl, &tbl_vfs_pid); if (fill) { @@ -571,6 +569,8 @@ int netdata_vfs_create(struct pt_regs* ctx) data.create_call = 1; bpf_map_update_elem(&tbl_vfs_pid, &key, &data, BPF_ANY); + + libnetdata_update_global(&vfs_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1); } return 0; @@ -589,17 +589,15 @@ SEC("kprobe/release_task") int netdata_release_task_vfs(struct pt_regs* ctx) { struct netdata_vfs_stat_t *removeme; - __u32 key = NETDATA_CONTROLLER_APPS_ENABLED; - __u32 *apps = bpf_map_lookup_elem(&vfs_ctrl ,&key); - if (apps) { - if (*apps == 0) - return 0; - } else + __u32 key = 0; + if (!monitor_apps(&vfs_ctrl)) return 0; removeme = netdata_get_pid_structure(&key, &vfs_ctrl, &tbl_vfs_pid); if (removeme) { bpf_map_delete_elem(&tbl_vfs_pid, &key); + + libnetdata_update_global(&vfs_ctrl, NETDATA_CONTROLLER_PID_TABLE_DEL, 1); } return 0; diff --git a/kernel/xfs_kern.c b/kernel/xfs_kern.c index 248bf78a..e227f342 100644 --- a/kernel/xfs_kern.c +++ b/kernel/xfs_kern.c @@ -38,6 +38,14 @@ struct { __type(value, __u64); __uint(max_entries, 4192); } tmp_xfs SEC(".maps"); + +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __type(key, __u32); + __type(value, __u64); + __uint(max_entries, NETDATA_CONTROLLER_END); +} xfs_ctrl SEC(".maps"); + #else struct bpf_map_def SEC("maps") tbl_xfs = { .type = BPF_MAP_TYPE_PERCPU_ARRAY, @@ -52,6 +60,13 @@ struct bpf_map_def SEC("maps") tmp_xfs = { .value_size = sizeof(__u64), .max_entries = 4192 }; + +struct bpf_map_def SEC("maps") xfs_ctrl = { + .type = BPF_MAP_TYPE_ARRAY, + .key_size = sizeof(__u32), + .value_size = sizeof(__u64), + .max_entries = NETDATA_CONTROLLER_END +}; #endif /************************************************************************************ @@ -68,6 +83,8 @@ static __always_inline int netdata_xfs_entry() bpf_map_update_elem(&tmp_xfs, &pid, &ts, BPF_ANY); + libnetdata_update_global(&xfs_ctrl, NETDATA_CONTROLLER_TEMP_TABLE_ADD, 1); + return 0; } @@ -116,6 +133,8 @@ static void netdata_xfs_store_bin(__u32 bin, __u32 selection) data = 1; bpf_map_update_elem(&tbl_xfs, &idx, &data, BPF_ANY); + + libnetdata_update_global(&xfs_ctrl, NETDATA_CONTROLLER_TEMP_TABLE_DEL, 1); } SEC("kretprobe/xfs_file_read_iter") diff --git a/kernel/zfs_kern.c b/kernel/zfs_kern.c index 4ae6cee3..efefb782 100644 --- a/kernel/zfs_kern.c +++ b/kernel/zfs_kern.c @@ -37,6 +37,14 @@ struct { __type(value, __u64); __uint(max_entries, 4192); } tmp_zfs SEC(".maps"); + +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __type(key, __u32); + __type(value, __u64); + __uint(max_entries, NETDATA_CONTROLLER_END); +} zfs_ctrl SEC(".maps"); + #else struct bpf_map_def SEC("maps") tbl_zfs = { .type = BPF_MAP_TYPE_PERCPU_ARRAY, @@ -51,6 +59,13 @@ struct bpf_map_def SEC("maps") tmp_zfs = { .value_size = sizeof(__u64), .max_entries = 4192 }; + +struct bpf_map_def SEC("maps") zfs_ctrl = { + .type = BPF_MAP_TYPE_ARRAY, + .key_size = sizeof(__u32), + .value_size = sizeof(__u64), + .max_entries = NETDATA_CONTROLLER_END +}; #endif /************************************************************************************ @@ -67,6 +82,8 @@ static __always_inline int netdata_zfs_entry() bpf_map_update_elem(&tmp_zfs, &pid, &ts, BPF_ANY); + libnetdata_update_global(&zfs_ctrl, NETDATA_CONTROLLER_TEMP_TABLE_ADD, 1); + return 0; } @@ -115,6 +132,8 @@ static void netdata_zfs_store_bin(__u32 bin, __u32 selection) data = 1; bpf_map_update_elem(&tbl_zfs, &idx, &data, BPF_ANY); + + libnetdata_update_global(&zfs_ctrl, NETDATA_CONTROLLER_TEMP_TABLE_DEL, 1); } SEC("kretprobe/zpl_iter_read")