Skip to content

Commit

Permalink
Organize Headers (#198)
Browse files Browse the repository at this point in the history
Reorganize headers and add macro that defines architecture.
  • Loading branch information
thiagoftsm authored Feb 24, 2021
1 parent 423fde7 commit 6d51a2a
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 67 deletions.
24 changes: 24 additions & 0 deletions includes/netdata_cache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef _NETDATA_CACHE_H_
#define _NETDATA_CACHE_H_ 1

#include <linux/sched.h>

typedef struct netdata_cachestat {
__u64 add_to_page_cache_lru;
__u64 mark_page_accessed;
__u64 account_page_dirtied;
__u64 mark_buffer_dirty;
} netdata_cachestat_t;

enum cachestat_counters {
NETDATA_KEY_CALLS_ADD_TO_PAGE_CACHE_LRU,
NETDATA_KEY_CALLS_MARK_PAGE_ACCESSED,
NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED,
NETDATA_KEY_CALLS_MARK_BUFFER_DIRTY,

NETDATA_CACHESTAT_END
};

#endif /* _NETDATA_CACHE_H_ */
37 changes: 37 additions & 0 deletions includes/netdata_ebpf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef _NETDATA_EBPF_
#define _NETDATA_EBPF_ 1

#include <linux/sched.h>

#include "netdata_cache.h"
#include "netdata_network.h"
#include "netdata_process.h"

struct netdata_error_report_t {
char comm[TASK_COMM_LEN];
__u32 pid;

int type;
int err;
};

// Copied from linux/samples/bpf/tracex1_kern.c
#define _(P) \
({ \
typeof(P) val = 0; \
bpf_probe_read(&val, sizeof(val), &(P)); \
val; \
})

// Copied from linux/samples/bpf/trace_common.h
#ifdef __x86_64__
#define NETDATA_SYSCALL(SYS) "__x64_sys_" __stringify(SYS)
#elif defined(__s390x__)
#define NETDATA_SYSCALL(SYS) "__s390x_" __stringify(SYS)
#else
#define NETDATA_SYSCALL(SYS) "sys_" __stringify(SYS)
#endif

#endif /* _NETDATA_EBPF_ */
32 changes: 32 additions & 0 deletions includes/netdata_network.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef _NETDATA_NETWORK_H_
#define _NETDATA_NETWORK_H_ 1

#include <linux/sched.h>

enum socket_counters {
NETDATA_KEY_CALLS_TCP_SENDMSG,
NETDATA_KEY_ERROR_TCP_SENDMSG,
NETDATA_KEY_BYTES_TCP_SENDMSG,

NETDATA_KEY_CALLS_TCP_CLEANUP_RBUF,
NETDATA_KEY_ERROR_TCP_CLEANUP_RBUF,
NETDATA_KEY_BYTES_TCP_CLEANUP_RBUF,

NETDATA_KEY_CALLS_TCP_CLOSE,

NETDATA_KEY_CALLS_UDP_RECVMSG,
NETDATA_KEY_ERROR_UDP_RECVMSG,
NETDATA_KEY_BYTES_UDP_RECVMSG,

NETDATA_KEY_CALLS_UDP_SENDMSG,
NETDATA_KEY_ERROR_UDP_SENDMSG,
NETDATA_KEY_BYTES_UDP_SENDMSG,

NETDATA_KEY_TCP_RETRANSMIT,

NETDATA_SOCKET_COUNTER
};

#endif /* _NETDATA_NETWORK_H_ */
57 changes: 3 additions & 54 deletions kernel/netdata_ebpf.h → includes/netdata_process.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef _NETDATA_EBPF_PROCESS_
#define _NETDATA_EBPF_PROCESS_ 1
#ifndef _NETDATA_EBPF_PROCESS_H_
#define _NETDATA_EBPF_PROCESS_H_ 1

#include <linux/sched.h>

struct netdata_error_report_t {
char comm[TASK_COMM_LEN];
__u32 pid;

int type;
int err;
};

struct netdata_pid_stat_t {
__u64 pid_tgid; //Unique identifier
__u32 pid; //process id
Expand Down Expand Up @@ -50,7 +42,6 @@ struct netdata_pid_stat_t {
__u8 removeme;
};

// ebpf_process.c
enum process_counters {
NETDATA_KEY_CALLS_DO_SYS_OPEN,
NETDATA_KEY_ERROR_DO_SYS_OPEN,
Expand Down Expand Up @@ -90,46 +81,4 @@ enum process_counters {
NETDATA_GLOBAL_COUNTER
};

// network_viewer.c
enum socket_counters {
NETDATA_KEY_CALLS_TCP_SENDMSG,
NETDATA_KEY_ERROR_TCP_SENDMSG,
NETDATA_KEY_BYTES_TCP_SENDMSG,

NETDATA_KEY_CALLS_TCP_CLEANUP_RBUF,
NETDATA_KEY_ERROR_TCP_CLEANUP_RBUF,
NETDATA_KEY_BYTES_TCP_CLEANUP_RBUF,

NETDATA_KEY_CALLS_TCP_CLOSE,

NETDATA_KEY_CALLS_UDP_RECVMSG,
NETDATA_KEY_ERROR_UDP_RECVMSG,
NETDATA_KEY_BYTES_UDP_RECVMSG,

NETDATA_KEY_CALLS_UDP_SENDMSG,
NETDATA_KEY_ERROR_UDP_SENDMSG,
NETDATA_KEY_BYTES_UDP_SENDMSG,

NETDATA_KEY_TCP_RETRANSMIT,

NETDATA_SOCKET_COUNTER
};

// cachestat.c
typedef struct netdata_cachestat {
__u64 add_to_page_cache_lru;
__u64 mark_page_accessed;
__u64 account_page_dirtied;
__u64 mark_buffer_dirty;
} netdata_cachestat_t;

enum cachestat_counters {
NETDATA_KEY_CALLS_ADD_TO_PAGE_CACHE_LRU,
NETDATA_KEY_CALLS_MARK_PAGE_ACCESSED,
NETDATA_KEY_CALLS_ACCOUNT_PAGE_DIRTIED,
NETDATA_KEY_CALLS_MARK_BUFFER_DIRTY,

NETDATA_CACHESTAT_END
};

#endif /* _NETDATA_EBPF_PROCESS_ */
#endif /* _NETDATA_EBPF_PROCESS_H_ */
18 changes: 5 additions & 13 deletions kernel/process_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,19 +685,11 @@ int netdata_fork(struct pt_regs* ctx)
}

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,3,0))
# if defined(CONFIG_X86_64)
# if NETDATASEL < 2
SEC("kretprobe/__x64_sys_clone")
# else
SEC("kprobe/__x64_sys_clone")
# endif
# else
# if NETDATASEL < 2
SEC("kretprobe/sys_clone")
# else
SEC("kprobe/sys_clone")
# endif
# endif
#if NETDATASEL < 2
SEC("kretprobe/" NETDATA_SYSCALL(clone))
#else
SEC("kprobe/" NETDATA_SYSCALL(clone))
#endif
int netdata_clone(struct pt_regs* ctx)
{
#if NETDATASEL < 2
Expand Down

0 comments on commit 6d51a2a

Please sign in to comment.