Update libbpf (#11480)

This commit is contained in:
thiagoftsm 2021-09-20 16:51:58 +00:00 committed by GitHub
parent cb405deec8
commit 4e828eb9b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 263 additions and 202 deletions

View File

@ -67,7 +67,7 @@ struct config collector_config = { .first_section = NULL,
int running_on_kernel = 0;
char kernel_string[64];
int ebpf_nprocs;
static int isrh;
int isrh = 0;
uint32_t finalized_threads = 1;
pthread_mutex_t lock;
@ -970,20 +970,6 @@ static void ebpf_allocate_common_vectors()
global_process_stat = callocz((size_t)ebpf_nprocs, sizeof(ebpf_process_stat_t));
}
/**
* Fill the ebpf_data structure with default values
*
* @param ef the pointer to set default values
*/
void fill_ebpf_data(ebpf_data_t *ef)
{
memset(ef, 0, sizeof(ebpf_data_t));
ef->kernel_string = kernel_string;
ef->running_on_kernel = running_on_kernel;
ef->map_fd = callocz(EBPF_MAX_MAPS, sizeof(int));
ef->isrh = isrh;
}
/**
* Define how to load the ebpf programs
*
@ -1245,6 +1231,8 @@ void set_global_variables()
isrh = get_redhat_release();
pid_max = get_system_pid_max();
running_on_kernel = ebpf_get_kernel_version();
ebpf_update_kernel(kernel_string, 63, isrh, running_on_kernel);
}
/**
@ -1654,7 +1642,6 @@ int main(int argc, char **argv)
ebpf_load_thread_config();
ebpf_manage_pid(getpid());
running_on_kernel = get_kernel_version(kernel_string, 63);
if (!has_condition_to_run(running_on_kernel)) {
error("The current collector cannot run on this kernel.");
return 2;

View File

@ -144,6 +144,7 @@ extern pthread_mutex_t lock;
extern int close_ebpf_plugin;
extern int ebpf_nprocs;
extern int running_on_kernel;
extern int isrh;
extern char *ebpf_plugin_dir;
extern char kernel_string[64];
@ -196,8 +197,6 @@ extern void write_err_chart(char *name, char *family, netdata_publish_syscall_t
extern void write_io_chart(char *chart, char *family, char *dwrite, long long vwrite,
char *dread, long long vread);
extern void fill_ebpf_data(ebpf_data_t *ef);
extern void ebpf_create_charts_on_apps(char *name,
char *title,
char *units,

View File

@ -3,7 +3,6 @@
#include "ebpf.h"
#include "ebpf_cachestat.h"
static ebpf_data_t cachestat_data;
netdata_publish_cachestat_t **cachestat_pid;
static struct bpf_link **probe_links = NULL;
@ -633,7 +632,6 @@ void *ebpf_cachestat_thread(void *ptr)
ebpf_module_t *em = (ebpf_module_t *)ptr;
em->maps = cachestat_maps;
fill_ebpf_data(&cachestat_data);
ebpf_update_pid_table(&cachestat_maps[NETDATA_CACHESTAT_PID_STATS], em);
@ -642,12 +640,8 @@ void *ebpf_cachestat_thread(void *ptr)
pthread_mutex_lock(&lock);
ebpf_cachestat_allocate_global_vectors(NETDATA_CACHESTAT_END);
if (ebpf_update_kernel(&cachestat_data)) {
pthread_mutex_unlock(&lock);
goto endcachestat;
}
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects, cachestat_data.map_fd);
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects);
if (!probe_links) {
pthread_mutex_unlock(&lock);
goto endcachestat;

View File

@ -7,8 +7,6 @@ static char *dcstat_counter_dimension_name[NETDATA_DCSTAT_IDX_END] = { "ratio",
static netdata_syscall_stat_t dcstat_counter_aggregated_data[NETDATA_DCSTAT_IDX_END];
static netdata_publish_syscall_t dcstat_counter_publish_aggregated[NETDATA_DCSTAT_IDX_END];
static ebpf_data_t dcstat_data;
netdata_dcstat_pid_t *dcstat_vector = NULL;
netdata_publish_dcstat_t **dcstat_pid = NULL;
@ -583,7 +581,6 @@ void *ebpf_dcstat_thread(void *ptr)
ebpf_module_t *em = (ebpf_module_t *)ptr;
em->maps = dcstat_maps;
fill_ebpf_data(&dcstat_data);
ebpf_update_pid_table(&dcstat_maps[NETDATA_DCSTAT_PID_STATS], em);
@ -596,7 +593,7 @@ void *ebpf_dcstat_thread(void *ptr)
pthread_mutex_lock(&lock);
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects, dcstat_data.map_fd);
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects);
if (!probe_links) {
pthread_mutex_unlock(&lock);
goto enddcstat;

View File

@ -18,8 +18,6 @@ static ebpf_local_maps_t disk_maps[] = {{.name = "tbl_disk_iocall", .internal_in
{.name = NULL, .internal_input = 0, .user_input = 0,
.type = NETDATA_EBPF_MAP_CONTROLLER,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED}};
static ebpf_data_t disk_data;
static avl_tree_lock disk_tree;
netdata_ebpf_disks_t *disk_list = NULL;
@ -792,15 +790,9 @@ void *ebpf_disk_thread(void *ptr)
ebpf_module_t *em = (ebpf_module_t *)ptr;
em->maps = disk_maps;
fill_ebpf_data(&disk_data);
if (!em->enabled)
goto enddisk;
if (ebpf_update_kernel(&disk_data)) {
goto enddisk;
}
if (ebpf_disk_enable_tracepoints()) {
em->enabled = CONFIG_BOOLEAN_NO;
goto enddisk;
@ -817,7 +809,7 @@ void *ebpf_disk_thread(void *ptr)
goto enddisk;
}
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects, disk_data.map_fd);
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects);
if (!probe_links) {
goto enddisk;
}

View File

@ -29,7 +29,6 @@ struct config fd_config = { .first_section = NULL, .last_section = NULL, .mutex
.index = {.avl_tree = { .root = NULL, .compar = appconfig_section_compare },
.rwlock = AVL_LOCK_INITIALIZER } };
static ebpf_data_t fd_data;
static struct bpf_link **probe_links = NULL;
static struct bpf_object *objects = NULL;
@ -82,7 +81,6 @@ static void ebpf_fd_cleanup(void *ptr)
}
ebpf_cleanup_publish_syscall(fd_publish_aggregated);
freez(fd_data.map_fd);
freez(fd_thread.thread);
freez(fd_values);
freez(fd_vector);
@ -499,17 +497,13 @@ void *ebpf_fd_thread(void *ptr)
ebpf_module_t *em = (ebpf_module_t *)ptr;
em->maps = fd_maps;
fill_ebpf_data(&fd_data);
if (!em->enabled)
goto endfd;
if (ebpf_update_kernel(&fd_data))
goto endfd;
ebpf_fd_allocate_global_vectors();
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects, fd_data.map_fd);
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects);
if (!probe_links) {
goto endfd;
}

View File

@ -8,6 +8,28 @@ struct config fs_config = { .first_section = NULL,
.index = { .avl_tree = { .root = NULL, .compar = appconfig_section_compare },
.rwlock = AVL_LOCK_INITIALIZER } };
static ebpf_local_maps_t fs_maps[] = {{.name = "tbl_ext4", .internal_input = NETDATA_KEY_CALLS_SYNC,
.user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
{.name = "tbl_xfs", .internal_input = NETDATA_KEY_CALLS_SYNC,
.user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
{.name = "tbl_nfs", .internal_input = NETDATA_KEY_CALLS_SYNC,
.user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
{.name = "tbl_zfs", .internal_input = NETDATA_KEY_CALLS_SYNC,
.user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
{.name = "tbl_btrfs", .internal_input = NETDATA_KEY_CALLS_SYNC,
.user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
{.name = "tbl_ext_addr", .internal_input = 1,
.user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
{.name = NULL, .internal_input = 0, .user_input = 0,
.type = NETDATA_EBPF_MAP_CONTROLLER,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED}};
ebpf_filesystem_partitions_t localfs[] =
{{.filesystem = "ext4",
.optional_filesystem = NULL,
@ -200,17 +222,8 @@ int ebpf_filesystem_initialize_ebpf_data(ebpf_module_t *em)
for (i = 0; localfs[i].filesystem; i++) {
ebpf_filesystem_partitions_t *efp = &localfs[i];
if (!efp->probe_links && efp->flags & NETDATA_FILESYSTEM_LOAD_EBPF_PROGRAM) {
ebpf_data_t *ed = &efp->kernel_info;
fill_ebpf_data(ed);
if (ebpf_update_kernel(ed)) {
em->thread_name = saved_name;
return -1;
}
em->thread_name = efp->filesystem;
efp->probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string,
&efp->objects, ed->map_fd);
efp->probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &efp->objects);
if (!efp->probe_links) {
em->thread_name = saved_name;
return -1;
@ -218,8 +231,9 @@ int ebpf_filesystem_initialize_ebpf_data(ebpf_module_t *em)
efp->flags |= NETDATA_FILESYSTEM_FLAG_HAS_PARTITION;
// Nedeed for filesystems like btrfs
if ((efp->flags & NETDATA_FILESYSTEM_FILL_ADDRESS_TABLE) && (efp->addresses.function))
ebpf_load_addresses(&efp->addresses, efp->kernel_info.map_fd[NETDATA_ADDR_FS_TABLE]);
if ((efp->flags & NETDATA_FILESYSTEM_FILL_ADDRESS_TABLE) && (efp->addresses.function)) {
ebpf_load_addresses(&efp->addresses, fs_maps[i + 1].map_fd);
}
}
efp->flags &= ~NETDATA_FILESYSTEM_LOAD_EBPF_PROGRAM;
}
@ -331,7 +345,6 @@ void ebpf_filesystem_cleanup_ebpf_data()
for (i = 0; localfs[i].filesystem; i++) {
ebpf_filesystem_partitions_t *efp = &localfs[i];
if (efp->probe_links) {
freez(efp->kernel_info.map_fd);
freez(efp->family_name);
freez(efp->hread.name);
@ -428,12 +441,11 @@ static inline netdata_ebpf_histogram_t *select_hist(ebpf_filesystem_partitions_t
*
* Read the table with number of calls for all functions
*/
static void read_filesystem_table(ebpf_filesystem_partitions_t *efp)
static void read_filesystem_table(ebpf_filesystem_partitions_t *efp, int fd)
{
netdata_idx_t *values = filesystem_hash_values;
uint32_t key;
uint32_t idx;
int fd = efp->kernel_info.map_fd[NETDATA_MAIN_FS_TABLE];
for (key = 0; key < NETDATA_KEY_CALLS_SYNC; key++) {
netdata_ebpf_histogram_t *w = select_hist(efp, &idx, key);
if (!w) {
@ -471,7 +483,7 @@ static void read_filesystem_tables()
for (i = 0; localfs[i].filesystem; i++) {
ebpf_filesystem_partitions_t *efp = &localfs[i];
if (efp->flags & NETDATA_FILESYSTEM_FLAG_HAS_PARTITION) {
read_filesystem_table(efp);
read_filesystem_table(efp, fs_maps[i].map_fd);
}
}
}
@ -603,6 +615,7 @@ void *ebpf_filesystem_thread(void *ptr)
netdata_thread_cleanup_push(ebpf_filesystem_cleanup, ptr);
ebpf_module_t *em = (ebpf_module_t *)ptr;
em->maps = fs_maps;
ebpf_update_filesystem();
if (!em->enabled)

View File

@ -59,7 +59,6 @@ typedef struct ebpf_filesystem_partitions {
uint32_t flags;
uint32_t enabled;
ebpf_data_t kernel_info;
ebpf_addresses_t addresses;
} ebpf_filesystem_partitions_t;

View File

@ -36,8 +36,6 @@ static ebpf_local_maps_t hardirq_maps[] = {
}
};
static ebpf_data_t hardirq_data;
#define HARDIRQ_TP_CLASS_IRQ "irq"
#define HARDIRQ_TP_CLASS_IRQ_VECTORS "irq_vectors"
static ebpf_tracepoint_t hardirq_tracepoints[] = {
@ -466,22 +464,16 @@ void *ebpf_hardirq_thread(void *ptr)
ebpf_module_t *em = (ebpf_module_t *)ptr;
em->maps = hardirq_maps;
fill_ebpf_data(&hardirq_data);
if (!em->enabled) {
goto endhardirq;
}
if (ebpf_update_kernel(&hardirq_data)) {
goto endhardirq;
}
if (ebpf_enable_tracepoints(hardirq_tracepoints) == 0) {
em->enabled = CONFIG_BOOLEAN_NO;
goto endhardirq;
}
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects, hardirq_data.map_fd);
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects);
if (!probe_links) {
goto endhardirq;
}

View File

@ -10,7 +10,6 @@ static ebpf_local_maps_t mount_maps[] = {{.name = "tbl_mount", .internal_input =
.type = NETDATA_EBPF_MAP_CONTROLLER,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED}};
static ebpf_data_t mount_data;
static char *mount_dimension_name[NETDATA_EBPF_MOUNT_SYSCALL] = { "mount", "umount" };
static netdata_syscall_stat_t mount_aggregated_data[NETDATA_EBPF_MOUNT_SYSCALL];
static netdata_publish_syscall_t mount_publish_aggregated[NETDATA_EBPF_MOUNT_SYSCALL];
@ -227,15 +226,11 @@ void *ebpf_mount_thread(void *ptr)
ebpf_module_t *em = (ebpf_module_t *)ptr;
em->maps = mount_maps;
fill_ebpf_data(&mount_data);
if (!em->enabled)
goto endmount;
if (ebpf_update_kernel(&mount_data))
goto endmount;
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects, mount_data.map_fd);
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects);
if (!probe_links) {
goto endmount;
}

View File

@ -28,8 +28,6 @@ static ebpf_local_maps_t oomkill_maps[] = {
}
};
static ebpf_data_t oomkill_data;
static ebpf_tracepoint_t oomkill_tracepoints[] = {
{.enabled = false, .class = "oom", .event = "mark_victim"},
/* end */
@ -188,22 +186,16 @@ void *ebpf_oomkill_thread(void *ptr)
ebpf_module_t *em = (ebpf_module_t *)ptr;
em->maps = oomkill_maps;
fill_ebpf_data(&oomkill_data);
if (!em->enabled) {
goto endoomkill;
}
if (ebpf_update_kernel(&oomkill_data)) {
goto endoomkill;
}
if (ebpf_enable_tracepoints(oomkill_tracepoints) == 0) {
em->enabled = CONFIG_BOOLEAN_NO;
goto endoomkill;
}
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects, oomkill_data.map_fd);
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects);
if (!probe_links) {
goto endoomkill;
}

View File

@ -34,8 +34,6 @@ static netdata_idx_t *process_hash_values = NULL;
static netdata_syscall_stat_t process_aggregated_data[NETDATA_KEY_PUBLISH_PROCESS_END];
static netdata_publish_syscall_t process_publish_aggregated[NETDATA_KEY_PUBLISH_PROCESS_END];
static ebpf_data_t process_data;
ebpf_process_stat_t **global_process_stats = NULL;
ebpf_process_publish_apps_t **current_apps_data = NULL;
@ -561,8 +559,6 @@ static void ebpf_process_cleanup(void *ptr)
freez(global_process_stats);
freez(current_apps_data);
freez(process_data.map_fd);
if (probe_links) {
struct bpf_program *prog;
size_t i = 0 ;
@ -609,7 +605,7 @@ static void change_syscalls()
*/
static void set_local_pointers()
{
if (process_data.isrh >= NETDATA_MINIMUM_RH_VERSION && process_data.isrh < NETDATA_RH_8)
if (isrh >= NETDATA_MINIMUM_RH_VERSION && isrh < NETDATA_RH_8)
change_syscalls();
}
@ -663,20 +659,14 @@ void *ebpf_process_thread(void *ptr)
ebpf_module_t *em = (ebpf_module_t *)ptr;
em->maps = process_maps;
process_enabled = em->enabled;
fill_ebpf_data(&process_data);
pthread_mutex_lock(&lock);
ebpf_process_allocate_global_vectors(NETDATA_KEY_PUBLISH_PROCESS_END);
if (ebpf_update_kernel(&process_data)) {
pthread_mutex_unlock(&lock);
goto endprocess;
}
ebpf_update_pid_table(&process_maps[0], em);
set_local_pointers();
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects, process_data.map_fd);
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects);
if (!probe_links) {
pthread_mutex_unlock(&lock);
goto endprocess;

View File

@ -54,8 +54,6 @@ static netdata_idx_t *socket_hash_values = NULL;
static netdata_syscall_stat_t socket_aggregated_data[NETDATA_MAX_SOCKET_VECTOR];
static netdata_publish_syscall_t socket_publish_aggregated[NETDATA_MAX_SOCKET_VECTOR];
static ebpf_data_t socket_data;
ebpf_socket_publish_apps_t **socket_bandwidth_curr = NULL;
static ebpf_bandwidth_t *bandwidth_vector = NULL;
@ -1900,7 +1898,6 @@ static void ebpf_socket_cleanup(void *ptr)
clean_hostnames(network_viewer_opt.excluded_hostnames);
pthread_mutex_destroy(&nv_mutex);
freez(socket_data.map_fd);
freez(socket_threads.thread);
@ -2869,7 +2866,6 @@ void *ebpf_socket_thread(void *ptr)
ebpf_module_t *em = (ebpf_module_t *)ptr;
em->maps = socket_maps;
fill_ebpf_data(&socket_data);
parse_network_viewer_section(&socket_config);
parse_service_name_section(&socket_config);
@ -2887,15 +2883,10 @@ void *ebpf_socket_thread(void *ptr)
ebpf_socket_allocate_global_vectors(NETDATA_MAX_SOCKET_VECTOR);
initialize_inbound_outbound();
if (ebpf_update_kernel(&socket_data)) {
pthread_mutex_unlock(&lock);
goto endsocket;
}
if (running_on_kernel < NETDATA_EBPF_KERNEL_5_0)
em->mode = MODE_ENTRY;
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects, socket_data.map_fd);
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects);
if (!probe_links) {
pthread_mutex_unlock(&lock);
goto endsocket;

View File

@ -28,8 +28,6 @@ static ebpf_local_maps_t softirq_maps[] = {
}
};
static ebpf_data_t softirq_data;
#define SOFTIRQ_TP_CLASS_IRQ "irq"
static ebpf_tracepoint_t softirq_tracepoints[] = {
{.enabled = false, .class = SOFTIRQ_TP_CLASS_IRQ, .event = "softirq_entry"},
@ -246,22 +244,16 @@ void *ebpf_softirq_thread(void *ptr)
ebpf_module_t *em = (ebpf_module_t *)ptr;
em->maps = softirq_maps;
fill_ebpf_data(&softirq_data);
if (!em->enabled) {
goto endsoftirq;
}
if (ebpf_update_kernel(&softirq_data)) {
goto endsoftirq;
}
if (ebpf_enable_tracepoints(softirq_tracepoints) == 0) {
em->enabled = CONFIG_BOOLEAN_NO;
goto endsoftirq;
}
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects, softirq_data.map_fd);
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects);
if (!probe_links) {
goto endsoftirq;
}

View File

@ -15,7 +15,6 @@ static netdata_idx_t *swap_values = NULL;
netdata_publish_swap_t **swap_pid = NULL;
static ebpf_data_t swap_data;
struct config swap_config = { .first_section = NULL,
.last_section = NULL,
.mutex = NETDATA_MUTEX_INITIALIZER,
@ -421,18 +420,13 @@ void *ebpf_swap_thread(void *ptr)
ebpf_module_t *em = (ebpf_module_t *)ptr;
em->maps = swap_maps;
fill_ebpf_data(&swap_data);
ebpf_update_pid_table(&swap_maps[NETDATA_PID_SWAP_TABLE], em);
if (!em->enabled)
goto endswap;
if (ebpf_update_kernel(&swap_data)) {
goto endswap;
}
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects, swap_data.map_fd);
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects);
if (!probe_links) {
goto endswap;
}

View File

@ -3,8 +3,6 @@
#include "ebpf.h"
#include "ebpf_sync.h"
static ebpf_data_t sync_data;
static char *sync_counter_dimension_name[NETDATA_SYNC_IDX_END] = { "sync", "syncfs", "msync", "fsync", "fdatasync",
"sync_file_range" };
static netdata_syscall_stat_t sync_counter_aggregated_data[NETDATA_SYNC_IDX_END];
@ -17,6 +15,28 @@ static netdata_idx_t sync_hash_values[NETDATA_SYNC_IDX_END];
struct netdata_static_thread sync_threads = {"SYNC KERNEL", NULL, NULL, 1,
NULL, NULL, NULL};
static ebpf_local_maps_t sync_maps[] = {{.name = "tbl_sync", .internal_input = NETDATA_SYNC_END,
.user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
{.name = "tbl_syncfs", .internal_input = NETDATA_SYNC_END,
.user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
{.name = "tbl_msync", .internal_input = NETDATA_SYNC_END,
.user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
{.name = "tbl_fsync", .internal_input = NETDATA_SYNC_END,
.user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
{.name = "tbl_fdatasync", .internal_input = NETDATA_SYNC_END,
.user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
{.name = "tbl_syncfr", .internal_input = NETDATA_SYNC_END,
.user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
{.name = NULL, .internal_input = 0, .user_input = 0,
.type = NETDATA_EBPF_MAP_CONTROLLER,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED}};
struct config sync_config = { .first_section = NULL,
.last_section = NULL,
.mutex = NETDATA_MUTEX_INITIALIZER,
@ -53,15 +73,8 @@ static int ebpf_sync_initialize_syscall(ebpf_module_t *em)
for (i = 0; local_syscalls[i].syscall; i++) {
ebpf_sync_syscalls_t *w = &local_syscalls[i];
if (!w->probe_links && w->enabled) {
fill_ebpf_data(&w->kernel_info);
if (ebpf_update_kernel(&w->kernel_info)) {
em->thread_name = saved_name;
error("Cannot update the kernel for eBPF module %s", w->syscall);
return -1;
}
em->thread_name = w->syscall;
w->probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &w->objects, w->kernel_info.map_fd);
w->probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &w->objects);
if (!w->probe_links) {
em->thread_name = saved_name;
return -1;
@ -95,7 +108,7 @@ static void read_global_table()
int i;
for (i = 0; local_syscalls[i].syscall; i++) {
if (local_syscalls[i].enabled) {
int fd = local_syscalls[i].kernel_info.map_fd[NETDATA_SYNC_GLOBLAL_TABLE];
int fd = sync_maps[i].map_fd;
if (!bpf_map_lookup_elem(fd, &idx, &stored)) {
sync_hash_values[i] = stored;
}
@ -228,8 +241,6 @@ void ebpf_sync_cleanup_objects()
for (i = 0; local_syscalls[i].syscall; i++) {
ebpf_sync_syscalls_t *w = &local_syscalls[i];
if (w->probe_links) {
freez(w->kernel_info.map_fd);
struct bpf_program *prog;
size_t j = 0 ;
bpf_object__for_each_program(prog, w->objects) {
@ -358,7 +369,7 @@ void *ebpf_sync_thread(void *ptr)
netdata_thread_cleanup_push(ebpf_sync_cleanup, ptr);
ebpf_module_t *em = (ebpf_module_t *)ptr;
fill_ebpf_data(&sync_data);
em->maps = sync_maps;
ebpf_sync_parse_syscalls();

View File

@ -37,8 +37,6 @@ typedef struct ebpf_sync_syscalls {
struct bpf_object *objects;
struct bpf_link **probe_links;
ebpf_data_t kernel_info;
} ebpf_sync_syscalls_t;
enum netdata_sync_charts {

View File

@ -16,8 +16,6 @@ static netdata_publish_syscall_t vfs_publish_aggregated[NETDATA_KEY_PUBLISH_VFS_
netdata_publish_vfs_t **vfs_pid = NULL;
netdata_publish_vfs_t *vfs_vector = NULL;
static ebpf_data_t vfs_data;
static ebpf_local_maps_t vfs_maps[] = {{.name = "tbl_vfs_pid", .internal_input = ND_EBPF_DEFAULT_PID_SIZE,
.user_input = 0, .type = NETDATA_EBPF_MAP_RESIZABLE | NETDATA_EBPF_MAP_PID,
.map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
@ -84,7 +82,6 @@ static void ebpf_vfs_cleanup(void *ptr)
UNUSED(dt);
}
freez(vfs_data.map_fd);
freez(vfs_hash_values);
freez(vfs_vector);
@ -896,7 +893,6 @@ void *ebpf_vfs_thread(void *ptr)
ebpf_module_t *em = (ebpf_module_t *)ptr;
em->maps = vfs_maps;
fill_ebpf_data(&vfs_data);
ebpf_update_pid_table(&vfs_maps[NETDATA_VFS_PID], em);
@ -905,11 +901,7 @@ void *ebpf_vfs_thread(void *ptr)
if (!em->enabled)
goto endvfs;
if (ebpf_update_kernel(&vfs_data)) {
goto endvfs;
}
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects, vfs_data.map_fd);
probe_links = ebpf_load_program(ebpf_plugin_dir, em, kernel_string, &objects);
if (!probe_links) {
goto endvfs;
}

View File

@ -64,13 +64,19 @@ int clean_kprobe_events(FILE *out, int pid, netdata_ebpf_events_t *ptr)
//----------------------------------------------------------------------------------------------------------------------
int get_kernel_version(char *out, int size)
/**
* Get Kernel version
*
* Get the current kernel from /proc and returns an integer value representing it
*
* @return it returns a value representing the kernel version.
*/
int ebpf_get_kernel_version()
{
char major[16], minor[16], patch[16];
char ver[VERSION_STRING_LEN];
char *version = ver;
out[0] = '\0';
int fd = open("/proc/sys/kernel/osrelease", O_RDONLY);
if (fd < 0)
return -1;
@ -104,10 +110,6 @@ int get_kernel_version(char *out, int size)
*move++ = *version++;
*move = '\0';
fd = snprintf(out, (size_t)size, "%s.%s.%s", major, minor, patch);
if (fd > size)
error("The buffer to store kernel version is not smaller than necessary.");
return ((int)(str2l(major) * 65536) + (int)(str2l(minor) * 256) + (int)str2l(patch));
}
@ -272,14 +274,24 @@ char *ebpf_kernel_suffix(int version, int isrh)
//----------------------------------------------------------------------------------------------------------------------
int ebpf_update_kernel(ebpf_data_t *ed)
/**
* Update Kernel
*
* Update string used to load eBPF programs
*
* @param ks vector to store the value
* @param length available length to store kernel
* @param isrh Is a Red Hat distribution?
* @param version the kernel version
*/
void ebpf_update_kernel(char *ks, size_t length, int isrh, int version)
{
char *kernel = ebpf_kernel_suffix(ed->running_on_kernel, (ed->isrh < 0) ? 0 : 1);
size_t length = strlen(kernel);
strncpyz(ed->kernel_string, kernel, length);
ed->kernel_string[length] = '\0';
return 0;
char *kernel = ebpf_kernel_suffix(version, (isrh < 0) ? 0 : 1);
size_t len = strlen(kernel);
if (len > length)
len = length - 1;
strncpyz(ks, kernel, len);
ks[len] = '\0';
}
static int select_file(char *name, const char *program, size_t length, int mode, char *kernel_string)
@ -386,15 +398,14 @@ static struct bpf_link **ebpf_attach_programs(struct bpf_object *obj, size_t len
return links;
}
static void ebpf_update_maps(ebpf_module_t *em, int *map_fd, struct bpf_object *obj)
static void ebpf_update_maps(ebpf_module_t *em, struct bpf_object *obj)
{
if (!map_fd)
if (!em->maps)
return;
ebpf_local_maps_t *maps = em->maps;
struct bpf_map *map;
size_t i = 0;
bpf_map__for_each(map, obj)
bpf_map__for_each(map, obj)
{
int fd = bpf_map__fd(map);
if (maps) {
@ -408,8 +419,6 @@ static void ebpf_update_maps(ebpf_module_t *em, int *map_fd, struct bpf_object *
j++;
}
}
map_fd[i] = fd;
i++;
}
}
@ -420,7 +429,7 @@ static void ebpf_update_controller(ebpf_module_t *em, struct bpf_object *obj)
return;
struct bpf_map *map;
bpf_map__for_each(map, obj)
bpf_map__for_each(map, obj)
{
size_t i = 0;
while (maps[i].name) {
@ -441,7 +450,7 @@ static void ebpf_update_controller(ebpf_module_t *em, struct bpf_object *obj)
}
struct bpf_link **ebpf_load_program(char *plugins_dir, ebpf_module_t *em, char *kernel_string,
struct bpf_object **obj, int *map_fd)
struct bpf_object **obj)
{
char lpath[4096];
char lname[128];
@ -466,7 +475,7 @@ struct bpf_link **ebpf_load_program(char *plugins_dir, ebpf_module_t *em, char *
return NULL;
}
ebpf_update_maps(em, map_fd, *obj);
ebpf_update_maps(em, *obj);
ebpf_update_controller(em, *obj);
size_t count_programs = ebpf_count_programs(*obj);

View File

@ -166,16 +166,15 @@ typedef struct ebpf_module {
const char *config_file;
} ebpf_module_t;
extern int get_kernel_version(char *out, int size);
extern int ebpf_get_kernel_version();
extern int get_redhat_release();
extern int has_condition_to_run(int version);
extern char *ebpf_kernel_suffix(int version, int isrh);
extern int ebpf_update_kernel(ebpf_data_t *ef);
extern void ebpf_update_kernel(char *ks, size_t length, int isrh, int version);
extern struct bpf_link **ebpf_load_program(char *plugins_dir,
ebpf_module_t *em,
char *kernel_string,
struct bpf_object **obj,
int *map_fd);
struct bpf_object **obj);
extern void ebpf_mount_config_name(char *filename, size_t length, char *path, const char *config);
extern int ebpf_load_config(struct config *config, char *filename);

View File

@ -944,8 +944,28 @@ bundle_jsonc
# -----------------------------------------------------------------------------
get_kernel_version() {
r="$(uname -r | cut -f 1 -d '-')"
read -r -a p <<< "$(echo "${r}" | tr '.' ' ')"
printf "%03d%03d%03d" "${p[0]}" "${p[1]}" "${p[2]}"
}
rename_libbpf_packaging() {
if [ "$(get_kernel_version)" -ge "005004014" ]; then
cp packaging/current_libbpf.checksums packaging/libbpf.checksums
cp packaging/current_libbpf.version packaging/libbpf.version
else
cp packaging/libbpf_0_0_9.checksums packaging/libbpf.checksums
cp packaging/libbpf_0_0_9.version packaging/libbpf.version
fi
}
build_libbpf() {
pushd "${1}/src" > /dev/null || exit 1
mkdir root build
run env CFLAGS=-fPIC CXXFLAGS= LDFLAGS= BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=.. ${make} ${MAKEOPTS} install
popd > /dev/null || exit 1
}
@ -970,6 +990,8 @@ bundle_libbpf() {
return 0
fi
rename_libbpf_packaging
progress "Prepare libbpf"
LIBBPF_PACKAGE_VERSION="$(cat packaging/libbpf.version)"
@ -1569,27 +1591,6 @@ install_go() {
install_go
function get_kernel_version() {
r="$(uname -r | cut -f 1 -d '-')"
read -r -a p <<< "$(echo "${r}" | tr '.' ' ')"
printf "%03d%03d%03d" "${p[0]}" "${p[1]}" "${p[2]}"
}
function get_rh_version() {
if [ ! -f /etc/redhat-release ]; then
printf "000000000"
return
fi
r="$(cut -f 4 -d ' ' < /etc/redhat-release)"
read -r -a p <<< "$(echo "${r}" | tr '.' ' ')"
printf "%03d%03d%03d" "${p[0]}" "${p[1]}" "${p[2]}"
}
detect_libc() {
libc=
if ldd --version 2>&1 | grep -q -i glibc; then

View File

@ -0,0 +1,3 @@
826c2b1e17df316d5667ae78cab0fbc7aacbb65479afe601175a29fdb6499853 netdata-kernel-collector-glibc-v0.7.10.tar.xz
e7d74be56d80c8a999bf0428c059e8dbfbcaed62eeb247f99970c4b01808ab6d netdata-kernel-collector-musl-v0.7.10.tar.xz
f2dbf0402fcaf172b09bacf1e60dbb2ccd69cea5bc4af2a8f66be2e0e37d7025 netdata-kernel-collector-static-v0.7.10.tar.xz

View File

@ -0,0 +1 @@
v0.7.10

View File

@ -0,0 +1 @@
1e4c81c2695cad65fd6a585fb6d8195c933f81d4bc2352964d73d17ad0b08b40 v0.4.0_netdata.tar.gz

View File

@ -0,0 +1 @@
0.4.0_netdata

View File

@ -1,3 +1,3 @@
826c2b1e17df316d5667ae78cab0fbc7aacbb65479afe601175a29fdb6499853 netdata-kernel-collector-glibc-v0.7.10.tar.xz
e7d74be56d80c8a999bf0428c059e8dbfbcaed62eeb247f99970c4b01808ab6d netdata-kernel-collector-musl-v0.7.10.tar.xz
f2dbf0402fcaf172b09bacf1e60dbb2ccd69cea5bc4af2a8f66be2e0e37d7025 netdata-kernel-collector-static-v0.7.10.tar.xz
7db767f09bd422c2e15c7bd8af47eea9c32f3c435a1166e02ac65abad36fd6e4 netdata-kernel-collector-glibc-v0.8.0.tar.xz
705da99b6f7d782f1eca1924b12629826ae15844ab781555d7849a9baa682e50 netdata-kernel-collector-musl-v0.8.0.tar.xz
13d48b50786d007cf10e35ce7b9641935b5df684d2637f122a7a51651dd5c8a6 netdata-kernel-collector-static-v0.8.0.tar.xz

View File

@ -1 +1,2 @@
v0.7.10
v0.8.0

View File

@ -1 +1 @@
fc33402ba33c8f8c5aa18afbb86a9932965886f2906c50e8f2110a1a2126e3ee v0.0.9_netdata-1.tar.gz
1e4c81c2695cad65fd6a585fb6d8195c933f81d4bc2352964d73d17ad0b08b40 v0.4.0_netdata.tar.gz

View File

@ -1 +1 @@
0.0.9_netdata-1
0.4.0_netdata

View File

@ -0,0 +1 @@
fc33402ba33c8f8c5aa18afbb86a9932965886f2906c50e8f2110a1a2126e3ee v0.0.9_netdata-1.tar.gz

View File

@ -0,0 +1 @@
0.0.9_netdata-1

1
tests/ebpf/README.md Normal file
View File

@ -0,0 +1 @@
The file `sync_tester.c` can be used to fill all dimensions present in synchronization submenu.

120
tests/ebpf/sync_tester.c Normal file
View File

@ -0,0 +1,120 @@
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/types.h>
#define _GNU_SOURCE /* See feature_test_macros(7) */
#define __USE_GNU
#include <fcntl.h>
#include <unistd.h>
void test_sync_file_range(char *output, char *text, size_t length)
{
int fd = open (output, O_WRONLY | O_CREAT | O_APPEND, 0660);
if (fd < 0 ) {
perror("Cannot get page size");
return;
}
int i;
size_t offset = 0;
for ( i = 0 ; i < 10000; i++ ) {
write(fd, text, length);
sync_file_range(fd, offset, length, SYNC_FILE_RANGE_WRITE);
offset += length;
}
close(fd);
sleep(5);
}
// test based on IBM example https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_71/apis/msync.htm
void test_msync(char *output, char *text, size_t length)
{
int pagesize = sysconf(_SC_PAGE_SIZE);
if (pagesize < 0) {
perror("Cannot get page size");
return;
}
int fd = open(output, (O_CREAT | O_TRUNC | O_RDWR), (S_IRWXU | S_IRWXG | S_IRWXO));
if (fd < 0 ) {
perror("Cannot open file");
return;
}
off_t lastoffset = lseek( fd, pagesize, SEEK_SET);
ssize_t written = write(fd, " ", 1);
if ( written != 1 ) {
perror("Write error. ");
close(fd);
return;
}
off_t my_offset = 0;
void *address = mmap(NULL, pagesize, PROT_WRITE, MAP_SHARED, fd, my_offset);
if ( address == MAP_FAILED ) {
perror("Map error. ");
close(fd);
return;
}
(void) strcpy( (char*) address, text);
if ( msync( address, pagesize, MS_SYNC) < 0 ) {
perror("msync failed with error:");
}
close(fd);
sleep(5);
}
void test_synchronization(char *output, char *text, size_t length, int (*fcnt)(int))
{
int fd = open (output, O_WRONLY | O_CREAT | O_APPEND, 0660);
if (fd < 0 ) {
perror("Cannot get page size");
return;
}
int i;
for ( i = 0 ; i < 10000; i++ )
write(fd, text, length);
fcnt(fd);
close(fd);
sleep(5);
}
void remove_files(char **files) {
size_t i = 0;
while (files[i]) {
unlink(files[i]);
i++;
}
}
int main()
{
char *default_text = { "This is a simple example to test a PR. The sleep is used to create different peaks on charts.\n" };
char *files[] = { "fsync.txt", "fdatasync.txt", "syncfs.txt", "msync.txt", "sync_file_range.txt", NULL };
size_t length = strlen(default_text);
test_synchronization(files[0], default_text, length, fsync);
test_synchronization(files[1], default_text, length, fdatasync);
test_synchronization(files[2], default_text, length, syncfs);
test_msync(files[3], default_text, length);
test_sync_file_range(files[4], default_text, length);
sync();
remove_files(files);
return 0;
}