Skip to content

Commit

Permalink
Update DC (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoftsm committed Oct 2, 2023
1 parent 4597a65 commit 1245d0c
Show file tree
Hide file tree
Showing 10 changed files with 5 additions and 117 deletions.
2 changes: 1 addition & 1 deletion kernel-collector
16 changes: 0 additions & 16 deletions src/cachestat.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ static __always_inline int netdata_common_page_cache_lru()
libnetdata_update_u64(&fill->add_to_page_cache_lru, 1);
} else {
data.ct = bpf_ktime_get_ns();
#if (LINUX_VERSION_CODE > KERNEL_VERSION(4,11,0))
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
#else
data.name[0] = '\0';
#endif

data.add_to_page_cache_lru = 1;
bpf_map_update_elem(&cstat_pid, &key, &data, BPF_ANY);
Expand All @@ -91,11 +87,7 @@ static __always_inline int netdata_common_page_accessed()
libnetdata_update_u64(&fill->mark_page_accessed, 1);
} else {
data.ct = bpf_ktime_get_ns();
#if (LINUX_VERSION_CODE > KERNEL_VERSION(4,11,0))
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
#else
data.name[0] = '\0';
#endif

data.mark_page_accessed = 1;
bpf_map_update_elem(&cstat_pid, &key, &data, BPF_ANY);
Expand All @@ -119,11 +111,7 @@ static __always_inline int netdata_common_page_dirtied()
libnetdata_update_u64(&fill->account_page_dirtied, 1);
} else {
data.ct = bpf_ktime_get_ns();
#if (LINUX_VERSION_CODE > KERNEL_VERSION(4,11,0))
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
#else
data.name[0] = '\0';
#endif

data.account_page_dirtied = 1;
bpf_map_update_elem(&cstat_pid, &key, &data, BPF_ANY);
Expand All @@ -147,11 +135,7 @@ static __always_inline int netdata_common_buffer_dirty()
libnetdata_update_u64(&fill->mark_buffer_dirty, 1);
} else {
data.ct = bpf_ktime_get_ns();
#if (LINUX_VERSION_CODE > KERNEL_VERSION(4,11,0))
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
#else
data.name[0] = '\0';
#endif

data.mark_buffer_dirty = 1;
bpf_map_update_elem(&cstat_pid, &key, &data, BPF_ANY);
Expand Down
32 changes: 3 additions & 29 deletions src/dc.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ static __always_inline int netdata_common_lookup_fast()
libnetdata_update_u64(&fill->references, 1);
} else {
data.references = 1;
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
bpf_map_update_elem(&dcstat_pid, &key, &data, BPF_ANY);

libnetdata_update_global(&dcstat_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1);
Expand All @@ -86,6 +87,7 @@ static __always_inline int netdata_common_d_lookup(long ret)
libnetdata_update_u64(&fill->slow, 1);
} else {
data.slow = 1;
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
bpf_map_update_elem(&dcstat_pid, &key, &data, BPF_ANY);

libnetdata_update_global(&dcstat_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1);
Expand All @@ -99,6 +101,7 @@ static __always_inline int netdata_common_d_lookup(long ret)
libnetdata_update_u64(&fill->missed, 1);
} else {
data.missed = 1;
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
bpf_map_update_elem(&dcstat_pid, &key, &data, BPF_ANY);

libnetdata_update_global(&dcstat_ctrl, NETDATA_CONTROLLER_PID_TABLE_ADD, 1);
Expand All @@ -108,23 +111,6 @@ static __always_inline int netdata_common_d_lookup(long ret)
return 0;
}

static inline int netdata_release_task_dcstat()
{
netdata_dc_stat_t *removeme;
__u32 key = 0;
if (netdata_dc_not_update_apps())
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;
}

/***********************************************************************************
*
* DC SECTION(kprobe)
Expand All @@ -145,12 +131,6 @@ int BPF_KRETPROBE(netdata_d_lookup_kretprobe)
return netdata_common_d_lookup(ret);
}

SEC("kprobe/release_task")
int BPF_KPROBE(netdata_dcstat_release_task_kprobe)
{
return netdata_release_task_dcstat();
}

/***********************************************************************************
*
* DC SECTION(trampoline)
Expand All @@ -170,11 +150,5 @@ int BPF_PROG(netdata_d_lookup_fexit, const struct dentry *parent, const struct q
return netdata_common_d_lookup((long)ret);
}

SEC("fentry/release_task")
int BPF_PROG(netdata_dcstat_release_task_fentry)
{
return netdata_release_task_dcstat();
}

char _license[] SEC("license") = "GPL";

15 changes: 1 addition & 14 deletions src/dc.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
#include "dc.skel.h"

char *function_list[] = { "lookup_fast",
"d_lookup",
"release_task"
"d_lookup"
};
// This preprocessor is defined here, because it is not useful in kernel-colector
#define NETDATA_DCSTAT_RELEASE_TASK 2
Expand All @@ -26,14 +25,12 @@ static inline void ebpf_disable_probes(struct dc_bpf *obj)
{
bpf_program__set_autoload(obj->progs.netdata_lookup_fast_kprobe, false);
bpf_program__set_autoload(obj->progs.netdata_d_lookup_kretprobe, false);
bpf_program__set_autoload(obj->progs.netdata_dcstat_release_task_kprobe, false);
}

static inline void ebpf_disable_trampoline(struct dc_bpf *obj)
{
bpf_program__set_autoload(obj->progs.netdata_lookup_fast_fentry, false);
bpf_program__set_autoload(obj->progs.netdata_d_lookup_fexit, false);
bpf_program__set_autoload(obj->progs.netdata_dcstat_release_task_fentry, false);
}

static void ebpf_set_trampoline_target(struct dc_bpf *obj)
Expand All @@ -43,9 +40,6 @@ static void ebpf_set_trampoline_target(struct dc_bpf *obj)

bpf_program__set_attach_target(obj->progs.netdata_d_lookup_fexit, 0,
function_list[NETDATA_D_LOOKUP]);

bpf_program__set_attach_target(obj->progs.netdata_dcstat_release_task_fentry, 0,
function_list[NETDATA_DCSTAT_RELEASE_TASK]);
}

static int ebpf_attach_probes(struct dc_bpf *obj)
Expand All @@ -62,13 +56,6 @@ static int ebpf_attach_probes(struct dc_bpf *obj)
if (ret)
return -1;

obj->links.netdata_dcstat_release_task_kprobe = bpf_program__attach_kprobe(obj->progs.netdata_dcstat_release_task_kprobe,
false,
function_list[NETDATA_DCSTAT_RELEASE_TASK]);
ret = libbpf_get_error(obj->links.netdata_lookup_fast_kprobe);
if (ret)
return -1;

return 0;
}

Expand Down
8 changes: 0 additions & 8 deletions src/fd.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ static __always_inline int netdata_apps_do_sys_openat2(long ret)
libnetdata_update_u32(&fill->open_err, 1) ;
} else {
data.ct = bpf_ktime_get_ns();
#if (LINUX_VERSION_CODE > KERNEL_VERSION(4,11,0))
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
#else
data.name[0] = '\0';
#endif
data.open_call = 1;
if (ret < 0)
data.open_err = 1;
Expand Down Expand Up @@ -112,11 +108,7 @@ static __always_inline int netdata_apps_close_fd(int ret)
libnetdata_update_u32(&fill->close_err, 1) ;
} else {
data.ct = bpf_ktime_get_ns();
#if (LINUX_VERSION_CODE > KERNEL_VERSION(4,11,0))
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
#else
data.name[0] = '\0';
#endif
data.close_call = 1;
if (ret < 0)
data.close_err = 1;
Expand Down
29 changes: 0 additions & 29 deletions src/netdata_dc.h

This file was deleted.

4 changes: 0 additions & 4 deletions src/process.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ struct {
static __always_inline void netdata_fill_common_process_data(struct netdata_pid_stat_t *data)
{
data->ct = bpf_ktime_get_ns();
#if (LINUX_VERSION_CODE > KERNEL_VERSION(4,11,0))
bpf_get_current_comm(&data->name, TASK_COMM_LEN);
#else
data->name[0] = '\0';
#endif

__u64 pid_tgid = bpf_get_current_pid_tgid();
__u32 tgid = (__u32)( 0x00000000FFFFFFFF & pid_tgid);
Expand Down
4 changes: 0 additions & 4 deletions src/shm.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ static __always_inline int netdata_update_apps(__u32 idx)
netdata_update_stored_data(fill, idx);
} else {
data.ct = bpf_ktime_get_ns();
#if (LINUX_VERSION_CODE > KERNEL_VERSION(4,11,0))
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
#else
data.name[0] = '\0';
#endif

netdata_set_structure_value(&data, idx);
bpf_map_update_elem(&tbl_pid_shm, &key, &data, BPF_ANY);
Expand Down
4 changes: 0 additions & 4 deletions src/socket.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ static __always_inline short unsigned int set_idx_value(netdata_socket_idx_t *ns
static __always_inline void update_socket_common(netdata_socket_t *data, __u16 protocol, __u16 family)
{
data->ct = bpf_ktime_get_ns();
#if (LINUX_VERSION_CODE > KERNEL_VERSION(4,11,0))
bpf_get_current_comm(&data->name, TASK_COMM_LEN);
#else
data->name[0] = '\0';
#endif

data->first = bpf_ktime_get_ns();
data->ct = data->first;
Expand Down
8 changes: 0 additions & 8 deletions src/swap.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ static __always_inline int common_readpage()
libnetdata_update_u64(&fill->read, 1);
} else {
data.ct = bpf_ktime_get_ns();
#if (LINUX_VERSION_CODE > KERNEL_VERSION(4,11,0))
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
#else
data.name[0] = '\0';
#endif
data.read = 1;

bpf_map_update_elem(&tbl_pid_swap, &key, &data, BPF_ANY);
Expand All @@ -93,11 +89,7 @@ static __always_inline int common_writepage()
libnetdata_update_u64(&fill->write, 1);
} else {
data.ct = bpf_ktime_get_ns();
#if (LINUX_VERSION_CODE > KERNEL_VERSION(4,11,0))
bpf_get_current_comm(&data.name, TASK_COMM_LEN);
#else
data.name[0] = '\0';
#endif
data.write = 1;

bpf_map_update_elem(&tbl_pid_swap, &key, &data, BPF_ANY);
Expand Down

0 comments on commit 1245d0c

Please sign in to comment.