summaryrefslogtreecommitdiffstats
path: root/libnetdata
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-04-14 18:12:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-04-14 18:12:14 +0000
commitbb50acdcb8073654ea667b8c0272e335bd43f844 (patch)
tree1e00c8a29871426f8182658928dcb62e42d57ce8 /libnetdata
parentReleasing debian version 1.33.1-1. (diff)
downloadnetdata-bb50acdcb8073654ea667b8c0272e335bd43f844.tar.xz
netdata-bb50acdcb8073654ea667b8c0272e335bd43f844.zip
Merging upstream version 1.34.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libnetdata')
-rw-r--r--libnetdata/README.md2
-rw-r--r--libnetdata/adaptive_resortable_list/README.md2
-rw-r--r--libnetdata/avl/README.md2
-rw-r--r--libnetdata/buffer/README.md3
-rw-r--r--libnetdata/buffer/buffer.c42
-rw-r--r--libnetdata/circular_buffer/README.md2
-rw-r--r--libnetdata/clocks/README.md2
-rw-r--r--libnetdata/config/README.md2
-rw-r--r--libnetdata/config/appconfig.c7
-rw-r--r--libnetdata/config/appconfig.h1
-rw-r--r--libnetdata/dictionary/README.md2
-rw-r--r--libnetdata/ebpf/README.md2
-rw-r--r--libnetdata/ebpf/ebpf.c268
-rw-r--r--libnetdata/ebpf/ebpf.h45
-rw-r--r--libnetdata/eval/README.md2
-rw-r--r--libnetdata/json/README.md2
-rw-r--r--libnetdata/libnetdata.h15
-rw-r--r--libnetdata/locks/README.md2
-rw-r--r--libnetdata/log/README.md2
-rw-r--r--libnetdata/log/log.h2
-rw-r--r--libnetdata/os.h7
-rw-r--r--libnetdata/popen/README.md2
-rw-r--r--libnetdata/procfile/README.md2
-rw-r--r--libnetdata/procfile/procfile.h3
-rw-r--r--libnetdata/simple_pattern/README.md2
-rw-r--r--libnetdata/socket/README.md2
-rw-r--r--libnetdata/statistical/README.md2
-rw-r--r--libnetdata/storage_number/README.md2
-rw-r--r--libnetdata/threads/README.md2
-rw-r--r--libnetdata/threads/threads.c1
-rw-r--r--libnetdata/url/README.md2
31 files changed, 354 insertions, 80 deletions
diff --git a/libnetdata/README.md b/libnetdata/README.md
index cdb199f5..fe0690d6 100644
--- a/libnetdata/README.md
+++ b/libnetdata/README.md
@@ -7,4 +7,4 @@ custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/READM
`libnetdata` is a collection of library code that is used by all Netdata `C` programs.
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/adaptive_resortable_list/README.md b/libnetdata/adaptive_resortable_list/README.md
index 74e379a9..9eb942bc 100644
--- a/libnetdata/adaptive_resortable_list/README.md
+++ b/libnetdata/adaptive_resortable_list/README.md
@@ -96,4 +96,4 @@ Compared to unoptimized code (test No 1: 4.6sec):
Do not use ARL if the a name/keyword may appear more than once in the
source data.
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Fadaptive_resortable_list%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/avl/README.md b/libnetdata/avl/README.md
index 2097be57..36392bd7 100644
--- a/libnetdata/avl/README.md
+++ b/libnetdata/avl/README.md
@@ -14,4 +14,4 @@ use any memory allocations and their memory footprint is optimized
In addition to the above, this version of AVL, provides versions using locks
and traversal functions.
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Favl%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/buffer/README.md b/libnetdata/buffer/README.md
index 5a9d7b02..c5f66e6e 100644
--- a/libnetdata/buffer/README.md
+++ b/libnetdata/buffer/README.md
@@ -13,5 +13,4 @@ Also, they are super fast in printing and appending data to the string and its `
is just a lookup (it does not traverse the string).
Netdata uses `BUFFER`s for preparing web responses and buffering data to be sent upstream or
-to backend databases.
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Fbuffer%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+to external databases.
diff --git a/libnetdata/buffer/buffer.c b/libnetdata/buffer/buffer.c
index c37da21e..8ea90985 100644
--- a/libnetdata/buffer/buffer.c
+++ b/libnetdata/buffer/buffer.c
@@ -87,14 +87,19 @@ inline char *print_number_llu_r(char *str, unsigned long long uvalue) {
}
inline char *print_number_llu_r_smart(char *str, unsigned long long uvalue) {
-#ifdef ENVIRONMENT32
- if(uvalue > (unsigned long long)0xffffffff)
- str = print_number_llu_r(str, uvalue);
- else
- str = print_number_lu_r(str, uvalue);
-#else
- do *str++ = (char)('0' + (uvalue % 10)); while(uvalue /= 10);
-#endif
+ switch (sizeof(void *)) {
+ case 4:
+ str = (uvalue > (unsigned long long) 0xffffffff) ? print_number_llu_r(str, uvalue) :
+ print_number_lu_r(str, uvalue);
+ break;
+ case 8:
+ do {
+ *str++ = (char) ('0' + (uvalue % 10));
+ } while (uvalue /= 10);
+ break;
+ default:
+ fatal("Netdata supports only 32-bit & 64-bit systems.");
+ }
return str;
}
@@ -106,14 +111,19 @@ void buffer_print_llu(BUFFER *wb, unsigned long long uvalue)
char *str = &wb->buffer[wb->len];
char *wstr = str;
-#ifdef ENVIRONMENT32
- if(uvalue > (unsigned long long)0xffffffff)
- wstr = print_number_llu_r(wstr, uvalue);
- else
- wstr = print_number_lu_r(wstr, uvalue);
-#else
- do *wstr++ = (char)('0' + (uvalue % 10)); while(uvalue /= 10);
-#endif
+ switch (sizeof(void *)) {
+ case 4:
+ wstr = (uvalue > (unsigned long long) 0xffffffff) ? print_number_llu_r(wstr, uvalue) :
+ print_number_lu_r(wstr, uvalue);
+ break;
+ case 8:
+ do {
+ *wstr++ = (char) ('0' + (uvalue % 10));
+ } while (uvalue /= 10);
+ break;
+ default:
+ fatal("Netdata supports only 32-bit & 64-bit systems.");
+ }
// terminate it
*wstr = '\0';
diff --git a/libnetdata/circular_buffer/README.md b/libnetdata/circular_buffer/README.md
index d36c05f5..4482173d 100644
--- a/libnetdata/circular_buffer/README.md
+++ b/libnetdata/circular_buffer/README.md
@@ -8,5 +8,3 @@ custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/circu
`struct circular_buffer` is an adaptive circular buffer. It will start at an initial size
and grow up to a maximum size as it fills. Two indices within the structure track the current
`read` and `write` position for data.
-
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Fcircular_buffer%2README&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)]()
diff --git a/libnetdata/clocks/README.md b/libnetdata/clocks/README.md
index e53b86a6..3a7ce55f 100644
--- a/libnetdata/clocks/README.md
+++ b/libnetdata/clocks/README.md
@@ -2,4 +2,4 @@
custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/clocks/README.md
-->
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Fclocks%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/config/README.md b/libnetdata/config/README.md
index a71f1ee1..2eccf7a2 100644
--- a/libnetdata/config/README.md
+++ b/libnetdata/config/README.md
@@ -51,4 +51,4 @@ When you get the configuration file from the server, there will be a
comment above all `name = value` pairs the server does not use.
So you know that whatever you wrote there, is not used.
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Fconfig%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/config/appconfig.c b/libnetdata/config/appconfig.c
index 37e9e768..0daa6e5e 100644
--- a/libnetdata/config/appconfig.c
+++ b/libnetdata/config/appconfig.c
@@ -591,7 +591,7 @@ int appconfig_load(struct config *root, char *filename, int overwrite_used, cons
int line = 0;
struct section *co = NULL;
int is_exporter_config = 0;
- int _backends = 0; // number of backend sections we have
+ int _connectors = 0; // number of exporting connector sections we have
char working_instance[CONFIG_MAX_NAME + 1];
char working_connector[CONFIG_MAX_NAME + 1];
struct section *working_connector_section = NULL;
@@ -641,8 +641,8 @@ int appconfig_load(struct config *root, char *filename, int overwrite_used, cons
strncpy(working_connector, s, CONFIG_MAX_NAME);
s = s + rc + 1;
if (unlikely(!(*s))) {
- _backends++;
- sprintf(buffer, "instance_%d", _backends);
+ _connectors++;
+ sprintf(buffer, "instance_%d", _connectors);
s = buffer;
}
strncpy(working_instance, s, CONFIG_MAX_NAME);
@@ -793,7 +793,6 @@ void appconfig_generate(struct config *root, BUFFER *wb, int only_changed)
|| !strcmp(co->name, CONFIG_SECTION_CLOUD)
|| !strcmp(co->name, CONFIG_SECTION_REGISTRY)
|| !strcmp(co->name, CONFIG_SECTION_HEALTH)
- || !strcmp(co->name, CONFIG_SECTION_BACKEND)
|| !strcmp(co->name, CONFIG_SECTION_STREAM)
|| !strcmp(co->name, CONFIG_SECTION_HOST_LABEL)
|| !strcmp(co->name, CONFIG_SECTION_ML)
diff --git a/libnetdata/config/appconfig.h b/libnetdata/config/appconfig.h
index bfc92735..b5cf7741 100644
--- a/libnetdata/config/appconfig.h
+++ b/libnetdata/config/appconfig.h
@@ -89,7 +89,6 @@
#define CONFIG_SECTION_CLOUD "cloud"
#define CONFIG_SECTION_REGISTRY "registry"
#define CONFIG_SECTION_HEALTH "health"
-#define CONFIG_SECTION_BACKEND "backend"
#define CONFIG_SECTION_STREAM "stream"
#define CONFIG_SECTION_ML "ml"
#define CONFIG_SECTION_EXPORTING "exporting:global"
diff --git a/libnetdata/dictionary/README.md b/libnetdata/dictionary/README.md
index 234ff184..6049c7f6 100644
--- a/libnetdata/dictionary/README.md
+++ b/libnetdata/dictionary/README.md
@@ -2,4 +2,4 @@
custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/dictionary/README.md
-->
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Fdictionary%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/ebpf/README.md b/libnetdata/ebpf/README.md
index 09c6607d..534867f3 100644
--- a/libnetdata/ebpf/README.md
+++ b/libnetdata/ebpf/README.md
@@ -2,4 +2,4 @@
custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/ebpf/README.md
-->
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Febpf%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/ebpf/ebpf.c b/libnetdata/ebpf/ebpf.c
index ca40492f..dde6d57f 100644
--- a/libnetdata/ebpf/ebpf.c
+++ b/libnetdata/ebpf/ebpf.c
@@ -279,7 +279,7 @@ static char *ebpf_select_kernel_name(uint32_t selector)
{
static char *kernel_names[] = { NETDATA_IDX_STR_V3_10, NETDATA_IDX_STR_V4_14, NETDATA_IDX_STR_V4_16,
NETDATA_IDX_STR_V4_18, NETDATA_IDX_STR_V5_4, NETDATA_IDX_STR_V5_10,
- NETDATA_IDX_STR_V5_11, NETDATA_IDX_STR_V5_15
+ NETDATA_IDX_STR_V5_11, NETDATA_IDX_STR_V5_15, NETDATA_IDX_STR_V5_16
};
return kernel_names[selector];
@@ -301,7 +301,9 @@ static int ebpf_select_max_index(int is_rhf, uint32_t kver)
if (kver >= NETDATA_EBPF_KERNEL_4_11)
return NETDATA_IDX_V4_18;
} else { // Kernels from kernel.org
- if (kver >= NETDATA_EBPF_KERNEL_5_15)
+ if (kver >= NETDATA_EBPF_KERNEL_5_16)
+ return NETDATA_IDX_V5_16;
+ else if (kver >= NETDATA_EBPF_KERNEL_5_15)
return NETDATA_IDX_V5_15;
else if (kver >= NETDATA_EBPF_KERNEL_5_11)
return NETDATA_IDX_V5_11;
@@ -451,14 +453,53 @@ void ebpf_update_pid_table(ebpf_local_maps_t *pid, ebpf_module_t *em)
pid->user_input = em->pid_map_size;
}
-void ebpf_update_map_sizes(struct bpf_object *program, ebpf_module_t *em)
+/**
+ * Update map size
+ *
+ * Update map size with information read from configuration files.
+ *
+ * @param map the structure with file descriptor to update.
+ * @param lmap the structure with information from configuration files.
+ * @param em the structure with information about how the module/thread is working.
+ * @param map_name the name of the file used to log.
+ */
+void ebpf_update_map_size(struct bpf_map *map, ebpf_local_maps_t *lmap, ebpf_module_t *em, const char *map_name)
+{
+ uint32_t apps_type = NETDATA_EBPF_MAP_PID | NETDATA_EBPF_MAP_RESIZABLE;
+ if (lmap->user_input && lmap->user_input != lmap->internal_input) {
+#ifdef NETDATA_INTERNAL_CHECKS
+ info("Changing map %s from size %u to %u ", map_name, lmap->internal_input, lmap->user_input);
+#endif
+#ifdef LIBBPF_MAJOR_VERSION
+ bpf_map__set_max_entries(map, lmap->user_input);
+#else
+ bpf_map__resize(map, lmap->user_input);
+#endif
+ } else if (((lmap->type & apps_type) == apps_type) && (!em->apps_charts) && (!em->cgroup_charts)) {
+ lmap->user_input = ND_EBPF_DEFAULT_MIN_PID;
+#ifdef LIBBPF_MAJOR_VERSION
+ bpf_map__set_max_entries(map, lmap->user_input);
+#else
+ bpf_map__resize(map, lmap->user_input);
+#endif
+ }
+}
+
+/**
+ * Update Legacy map sizes
+ *
+ * Update map size for eBPF legacy code.
+ *
+ * @param program the structure with values read from binary.
+ * @param em the structure with information about how the module/thread is working.
+ */
+static void ebpf_update_legacy_map_sizes(struct bpf_object *program, ebpf_module_t *em)
{
struct bpf_map *map;
ebpf_local_maps_t *maps = em->maps;
if (!maps)
return;
- uint32_t apps_type = NETDATA_EBPF_MAP_PID | NETDATA_EBPF_MAP_RESIZABLE;
bpf_map__for_each(map, program)
{
const char *map_name = bpf_map__name(map);
@@ -467,15 +508,7 @@ void ebpf_update_map_sizes(struct bpf_object *program, ebpf_module_t *em)
ebpf_local_maps_t *w = &maps[i];
if (w->type & NETDATA_EBPF_MAP_RESIZABLE) {
if (!strcmp(w->name, map_name)) {
- if (w->user_input && w->user_input != w->internal_input) {
-#ifdef NETDATA_INTERNAL_CHECKS
- info("Changing map %s from size %u to %u ", map_name, w->internal_input, w->user_input);
-#endif
- bpf_map__resize(map, w->user_input);
- } else if (((w->type & apps_type) == apps_type) && (!em->apps_charts) && (!em->cgroup_charts)) {
- w->user_input = ND_EBPF_DEFAULT_MIN_PID;
- bpf_map__resize(map, w->user_input);
- }
+ ebpf_update_map_size(map, w, em, map_name);
}
}
@@ -564,7 +597,32 @@ static void ebpf_update_maps(ebpf_module_t *em, struct bpf_object *obj)
}
}
-static void ebpf_update_controller(ebpf_module_t *em, struct bpf_object *obj)
+/**
+ * Update Controller
+ *
+ * Update controller value with user input.
+ *
+ * @param fd the table file descriptor
+ * @param em structure with information about eBPF program we will load.
+ */
+void ebpf_update_controller(int fd, ebpf_module_t *em)
+{
+ uint32_t key = NETDATA_CONTROLLER_APPS_ENABLED;
+ uint32_t value = em->apps_charts | em->cgroup_charts;
+ int ret = bpf_map_update_elem(fd, &key, &value, 0);
+ if (ret)
+ error("Add key(%u) for controller table failed.", key);
+}
+
+/**
+ * Update Legacy controller
+ *
+ * Update legacy controller table when eBPF program has it.
+ *
+ * @param em structure with information about eBPF program we will load.
+ * @param obj bpf object with tables.
+ */
+static void ebpf_update_legacy_controller(ebpf_module_t *em, struct bpf_object *obj)
{
ebpf_local_maps_t *maps = em->maps;
if (!maps)
@@ -580,11 +638,7 @@ static void ebpf_update_controller(ebpf_module_t *em, struct bpf_object *obj)
w->type &= ~NETDATA_EBPF_MAP_CONTROLLER;
w->type |= NETDATA_EBPF_MAP_CONTROLLER_UPDATED;
- uint32_t key = NETDATA_CONTROLLER_APPS_ENABLED;
- int value = em->apps_charts | em->cgroup_charts;
- int ret = bpf_map_update_elem(w->map_fd, &key, &value, 0);
- if (ret)
- error("Add key(%u) for controller table failed.", key);
+ ebpf_update_controller(w->map_fd, em);
}
i++;
}
@@ -620,7 +674,7 @@ struct bpf_link **ebpf_load_program(char *plugins_dir, ebpf_module_t *em, int kv
return NULL;
}
- ebpf_update_map_sizes(*obj, em);
+ ebpf_update_legacy_map_sizes(*obj, em);
if (bpf_object__load(*obj)) {
error("ERROR: loading BPF object file failed %s\n", lpath);
@@ -629,7 +683,7 @@ struct bpf_link **ebpf_load_program(char *plugins_dir, ebpf_module_t *em, int kv
}
ebpf_update_maps(em, *obj);
- ebpf_update_controller(em, *obj);
+ ebpf_update_legacy_controller(em, *obj);
size_t count_programs = ebpf_count_programs(*obj);
@@ -716,14 +770,131 @@ static void ebpf_select_mode_string(char *output, size_t len, netdata_run_mode_t
}
/**
+ * Convert string to load mode
+ *
+ * Convert the string given as argument to value present in enum.
+ *
+ * @param str value read from configuraion file.
+ *
+ * @return It returns the value to be used.
+ */
+netdata_ebpf_load_mode_t epbf_convert_string_to_load_mode(char *str)
+{
+ if (!strcasecmp(str, EBPF_CFG_CORE_PROGRAM))
+ return EBPF_LOAD_CORE;
+ else if (!strcasecmp(str, EBPF_CFG_LEGACY_PROGRAM))
+ return EBPF_LOAD_LEGACY;
+
+ return EBPF_LOAD_PLAY_DICE;
+}
+
+/**
+ * Convert load mode to string
+ *
+ * @param mode value that will select the string
+ *
+ * @return It returns the string associated to mode.
+ */
+static char *ebpf_convert_load_mode_to_string(netdata_ebpf_load_mode_t mode)
+{
+ if (mode == EBPF_LOAD_CORE)
+ return EBPF_CFG_CORE_PROGRAM;
+ else if (mode == EBPF_LOAD_LEGACY)
+ return EBPF_CFG_LEGACY_PROGRAM;
+
+ return EBPF_CFG_DEFAULT_PROGRAM;
+}
+
+/**
+ * CO-RE type
+ *
+ * Select the preferential type of CO-RE
+ *
+ * @param str value read from configuration file.
+ * @param lmode load mode used by collector.
+ */
+netdata_ebpf_program_loaded_t ebpf_convert_core_type(char *str, netdata_run_mode_t lmode)
+{
+ if (!strcasecmp(str, EBPF_CFG_ATTACH_TRACEPOINT))
+ return EBPF_LOAD_TRACEPOINT;
+ else if (!strcasecmp(str, EBPF_CFG_ATTACH_PROBE)) {
+ return (lmode == MODE_ENTRY) ? EBPF_LOAD_PROBE : EBPF_LOAD_RETPROBE;
+ }
+
+ return EBPF_LOAD_TRAMPOLINE;
+}
+
+#ifdef LIBBPF_MAJOR_VERSION
+/**
+ * Adjust Thread Load
+ *
+ * Adjust thread configuraton according specified load.
+ *
+ * @param mod the main structure that will be adjusted.
+ * @param file the btf file used with thread.
+ */
+void ebpf_adjust_thread_load(ebpf_module_t *mod, struct btf *file)
+{
+ if (!file) {
+ mod->load = EBPF_LOAD_LEGACY;
+ } else if (mod->load == EBPF_LOAD_PLAY_DICE && file) {
+ mod->load = EBPF_LOAD_CORE;
+ }
+}
+
+/**
+ *
+ * @param filename
+ * @return
+ */
+struct btf *ebpf_parse_btf_file(const char *filename)
+{
+ struct btf *bf = btf__parse(filename, NULL);
+ if (libbpf_get_error(bf)) {
+ fprintf(stderr, "Cannot parse btf file");
+ btf__free(bf);
+ return NULL;
+ }
+
+ return bf;
+}
+#endif
+
+/**
+ * Update target with configuration
+ *
+ * Update target load mode with value.
+ *
+ * @param em the module structure
+ * @param value value used to update.
+ */
+static void ebpf_update_target_with_conf(ebpf_module_t *em, netdata_ebpf_program_loaded_t value)
+{
+ netdata_ebpf_targets_t *targets = em->targets;
+ if (!targets) {
+ return;
+ }
+
+ int i = 0;
+ while (targets[i].name) {
+ targets[i].mode = value;
+ i++;
+ }
+}
+
+/**
+ * Update Module using config
+ *
+ * Update configuration for a specific thread.
+ *
* @param modules structure that will be updated
*/
void ebpf_update_module_using_config(ebpf_module_t *modules)
{
char default_value[EBPF_MAX_MODE_LENGTH + 1];
ebpf_select_mode_string(default_value, EBPF_MAX_MODE_LENGTH, modules->mode);
- char *mode = appconfig_get(modules->cfg, EBPF_GLOBAL_SECTION, EBPF_CFG_LOAD_MODE, default_value);
- modules->mode = ebpf_select_mode(mode);
+ char *value = appconfig_get(modules->cfg, EBPF_GLOBAL_SECTION, EBPF_CFG_LOAD_MODE, default_value);
+ modules->mode = ebpf_select_mode(value);
modules->update_every = (int)appconfig_get_number(modules->cfg, EBPF_GLOBAL_SECTION,
EBPF_CFG_UPDATE_EVERY, modules->update_every);
@@ -733,8 +904,15 @@ void ebpf_update_module_using_config(ebpf_module_t *modules)
modules->pid_map_size = (uint32_t)appconfig_get_number(modules->cfg, EBPF_GLOBAL_SECTION, EBPF_CFG_PID_SIZE,
modules->pid_map_size);
-}
+ value = ebpf_convert_load_mode_to_string(modules->load);
+ value = appconfig_get(modules->cfg, EBPF_GLOBAL_SECTION, EBPF_CFG_TYPE_FORMAT, value);
+ modules->load = epbf_convert_string_to_load_mode(value);
+
+ value = appconfig_get(modules->cfg, EBPF_GLOBAL_SECTION, EBPF_CFG_CORE_ATTACH, EBPF_CFG_ATTACH_TRAMPOLINE);
+ netdata_ebpf_program_loaded_t fill_lm = ebpf_convert_core_type(value, modules->mode);
+ ebpf_update_target_with_conf(modules, fill_lm);
+}
/**
* Update module
@@ -991,3 +1169,45 @@ int ebpf_disable_tracing_values(char *subsys, char *eventname)
{
return ebpf_change_tracing_values(subsys, eventname, "0");
}
+
+/**
+ * Select PC prefix
+ *
+ * Identify the prefix to run on PC architecture.
+ *
+ * @return It returns 32 or 64 according to host arch.
+ */
+static uint32_t ebpf_select_pc_prefix()
+{
+ long counter = 1;
+ uint32_t i;
+ for (i = 0; i < 128; i++) {
+ counter <<= 1;
+ if (counter < 0)
+ break;
+ }
+
+ return counter;
+}
+
+/**
+ * Select Host Prefix
+ *
+ * Select prefix to syscall when host is running a kernel newer than 4.17.0
+ *
+ * @param output the vector to store data.
+ * @param length length of output vector.
+ * @param syscall the syscall that prefix will be attached;
+ * @param kver the current kernel version in format MAJOR*65536 + MINOR*256 + PATCH
+ */
+void ebpf_select_host_prefix(char *output, size_t length, char *syscall, int kver)
+{
+ if (kver < NETDATA_EBPF_KERNEL_4_17)
+ snprintfz(output, length, "sys_%s", syscall);
+ else {
+ uint32_t arch = ebpf_select_pc_prefix();
+ // Prefix selected according https://www.kernel.org/doc/html/latest/process/adding-syscalls.html
+ char *prefix = (arch == 32) ? "__ia32" : "__x64";
+ snprintfz(output, length, "%s_sys_%s", prefix, syscall);
+ }
+} \ No newline at end of file
diff --git a/libnetdata/ebpf/ebpf.h b/libnetdata/ebpf/ebpf.h
index 12529967..f701e1d4 100644
--- a/libnetdata/ebpf/ebpf.h
+++ b/libnetdata/ebpf/ebpf.h
@@ -5,6 +5,10 @@
#include <bpf/bpf.h>
#include <bpf/libbpf.h>
+#ifdef LIBBPF_DEPRECATED
+#include <bpf/btf.h>
+#include <linux/btf.h>
+#endif
#include <stdlib.h> // Necessary for stdtoul
#define NETDATA_DEBUGFS "/sys/kernel/debug/tracing/"
@@ -17,11 +21,25 @@
#define EBPF_CFG_LOAD_MODE_RETURN "return"
#define EBPF_MAX_MODE_LENGTH 6
+#define EBPF_CFG_TYPE_FORMAT "ebpf type format"
+#define EBPF_CFG_DEFAULT_PROGRAM "auto"
+#define EBPF_CFG_CORE_PROGRAM "CO-RE"
+#define EBPF_CFG_LEGACY_PROGRAM "legacy"
+
+#define EBPF_CFG_CORE_ATTACH "ebpf co-re tracing"
+#define EBPF_CFG_ATTACH_TRAMPOLINE "trampoline"
+#define EBPF_CFG_ATTACH_TRACEPOINT "tracepoint"
+#define EBPF_CFG_ATTACH_PROBE "probe"
+
+#define EBPF_CFG_PROGRAM_PATH "btf path"
+
#define EBPF_CFG_UPDATE_EVERY "update every"
#define EBPF_CFG_PID_SIZE "pid table size"
#define EBPF_CFG_APPLICATION "apps"
#define EBPF_CFG_CGROUP "cgroups"
+#define EBPF_COMMON_FNCT_CLEAN_UP "release_task"
+
/**
* The RedHat magic number was got doing:
*
@@ -57,7 +75,8 @@ enum netdata_ebpf_kernel_versions {
NETDATA_EBPF_KERNEL_5_0 = 327680, // 327680 = 5 * 65536 + 0 * 256
NETDATA_EBPF_KERNEL_5_10 = 330240, // 330240 = 5 * 65536 + 10 * 256
NETDATA_EBPF_KERNEL_5_11 = 330496, // 330240 = 5 * 65536 + 11 * 256
- NETDATA_EBPF_KERNEL_5_15 = 331520 // 331520 = 5 * 65536 + 15 * 256
+ NETDATA_EBPF_KERNEL_5_15 = 331520, // 331520 = 5 * 65536 + 15 * 256
+ NETDATA_EBPF_KERNEL_5_16 = 331776 // 331776 = 5 * 65536 + 16 * 256
};
enum netdata_kernel_flag {
@@ -68,7 +87,8 @@ enum netdata_kernel_flag {
NETDATA_V5_4 = 1 << 4,
NETDATA_V5_10 = 1 << 5,
NETDATA_V5_11 = 1 << 6,
- NETDATA_V5_15 = 1 << 7
+ NETDATA_V5_15 = 1 << 7,
+ NETDATA_V5_16 = 1 << 8
};
enum netdata_kernel_idx {
@@ -79,7 +99,8 @@ enum netdata_kernel_idx {
NETDATA_IDX_V5_4 ,
NETDATA_IDX_V5_10,
NETDATA_IDX_V5_11,
- NETDATA_IDX_V5_15
+ NETDATA_IDX_V5_15,
+ NETDATA_IDX_V5_16
};
#define NETDATA_IDX_STR_V3_10 "3.10"
@@ -90,6 +111,7 @@ enum netdata_kernel_idx {
#define NETDATA_IDX_STR_V5_10 "5.10"
#define NETDATA_IDX_STR_V5_11 "5.11"
#define NETDATA_IDX_STR_V5_15 "5.15"
+#define NETDATA_IDX_STR_V5_16 "5.16"
/**
* Minimum value has relationship with libbpf support.
@@ -229,6 +251,8 @@ extern void ebpf_load_addresses(ebpf_addresses_t *fa, int fd);
extern void ebpf_fill_algorithms(int *algorithms, size_t length, int algorithm);
extern char **ebpf_fill_histogram_dimension(size_t maximum);
extern void ebpf_update_stats(ebpf_plugin_stats_t *report, ebpf_module_t *em);
+extern void ebpf_update_controller(int fd, ebpf_module_t *em);
+extern void ebpf_update_map_size(struct bpf_map *map, ebpf_local_maps_t *lmap, ebpf_module_t *em, const char *map_name);
// Histogram
#define NETDATA_EBPF_HIST_MAX_BINS 24UL
@@ -250,4 +274,19 @@ extern int ebpf_is_tracepoint_enabled(char *subsys, char *eventname);
extern int ebpf_enable_tracing_values(char *subsys, char *eventname);
extern int ebpf_disable_tracing_values(char *subsys, char *eventname);
+// BTF Section
+#define EBPF_DEFAULT_BTF_FILE "/sys/kernel/btf"
+#define EBPF_DEFAULT_ERROR_MSG "Cannot open or load BPF file for thread"
+
+// BTF helpers
+#define NETDATA_EBPF_MAX_SYSCALL_LENGTH 255
+
+extern netdata_ebpf_load_mode_t epbf_convert_string_to_load_mode(char *str);
+extern netdata_ebpf_program_loaded_t ebpf_convert_core_type(char *str, netdata_run_mode_t lmode);
+extern void ebpf_select_host_prefix(char *output, size_t length, char *syscall, int kver);
+#ifdef LIBBPF_MAJOR_VERSION
+extern void ebpf_adjust_thread_load(ebpf_module_t *mod, struct btf *file);
+extern struct btf *ebpf_parse_btf_file(const char *filename);
+#endif
+
#endif /* NETDATA_EBPF_H */
diff --git a/libnetdata/eval/README.md b/libnetdata/eval/README.md
index 72b4089a..8b137891 100644
--- a/libnetdata/eval/README.md
+++ b/libnetdata/eval/README.md
@@ -1 +1 @@
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Feval%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/json/README.md b/libnetdata/json/README.md
index 79a48e24..2e04b8b6 100644
--- a/libnetdata/json/README.md
+++ b/libnetdata/json/README.md
@@ -7,4 +7,4 @@ custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/json/
`json` contains a parser for json strings, based on `jsmn` (<https://github.com/zserge/jsmn>), but case you have installed the JSON-C library, the installation script will prefer it, you can also force its use with `--enable-jsonc` in the compilation time.
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Fjson%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/libnetdata.h b/libnetdata/libnetdata.h
index 809cefa0..7f62c882 100644
--- a/libnetdata/libnetdata.h
+++ b/libnetdata/libnetdata.h
@@ -168,14 +168,6 @@ extern "C" {
// ----------------------------------------------------------------------------
// netdata common definitions
-#if (SIZEOF_VOID_P == 8)
-#define ENVIRONMENT64
-#elif (SIZEOF_VOID_P == 4)
-#define ENVIRONMENT32
-#else
-#error "Cannot detect if this is a 32 or 64 bit CPU"
-#endif
-
#ifdef __GNUC__
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif // __GNUC__
@@ -304,6 +296,13 @@ extern char *find_and_replace(const char *src, const char *find, const char *rep
/* misc. */
#define UNUSED(x) (void)(x)
+
+#ifdef __GNUC__
+#define UNUSED_FUNCTION(x) __attribute__((unused)) UNUSED_##x
+#else
+#define UNUSED_FUNCTION(x) UNUSED_##x
+#endif
+
#define error_report(x, args...) do { errno = 0; error(x, ##args); } while(0)
// Taken from linux kernel
diff --git a/libnetdata/locks/README.md b/libnetdata/locks/README.md
index b525c97f..a83f1b64 100644
--- a/libnetdata/locks/README.md
+++ b/libnetdata/locks/README.md
@@ -2,4 +2,4 @@
custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/locks/README.md
-->
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Flocks%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/log/README.md b/libnetdata/log/README.md
index c0d7a340..a767dd44 100644
--- a/libnetdata/log/README.md
+++ b/libnetdata/log/README.md
@@ -2,4 +2,4 @@
custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/log/README.md
-->
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Flog%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/log/log.h b/libnetdata/log/log.h
index c8380d0c..4cb62e95 100644
--- a/libnetdata/log/log.h
+++ b/libnetdata/log/log.h
@@ -36,7 +36,7 @@ extern "C" {
#define D_CONNECT_TO 0x0000000001000000
#define D_RRDHOST 0x0000000002000000
#define D_LOCKS 0x0000000004000000
-#define D_BACKEND 0x0000000008000000
+#define D_EXPORTING 0x0000000008000000
#define D_STATSD 0x0000000010000000
#define D_POLLFD 0x0000000020000000
#define D_STREAM 0x0000000040000000
diff --git a/libnetdata/os.h b/libnetdata/os.h
index 7872f82b..5e7746df 100644
--- a/libnetdata/os.h
+++ b/libnetdata/os.h
@@ -57,4 +57,11 @@ extern pid_t get_system_pid_max(void);
extern unsigned int system_hz;
extern void get_system_HZ(void);
+#include <sys/timex.h>
+#if defined(__FreeBSD__) || defined(__APPLE__)
+#define ADJUST_TIMEX(x) ntp_adjtime(x)
+#else
+#define ADJUST_TIMEX(x) adjtimex(x)
+#endif
+
#endif //NETDATA_OS_H
diff --git a/libnetdata/popen/README.md b/libnetdata/popen/README.md
index e51e2059..db4aefae 100644
--- a/libnetdata/popen/README.md
+++ b/libnetdata/popen/README.md
@@ -2,4 +2,4 @@
custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/popen/README.md
-->
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Fpopen%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/procfile/README.md b/libnetdata/procfile/README.md
index 3eeb1e20..65638030 100644
--- a/libnetdata/procfile/README.md
+++ b/libnetdata/procfile/README.md
@@ -64,4 +64,4 @@ and the data are inside the processor's caches.
This library is extensively used in Netdata and its plugins.
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Fprocfile%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/procfile/procfile.h b/libnetdata/procfile/procfile.h
index d29adf8e..5263ad77 100644
--- a/libnetdata/procfile/procfile.h
+++ b/libnetdata/procfile/procfile.h
@@ -103,4 +103,7 @@ extern int procfile_adaptive_initial_allocation;
// return the Nth word of the current line
#define procfile_lineword(ff, line, word) (((line) < procfile_lines(ff) && (word) < procfile_linewords((ff), (line))) ? procfile_word((ff), (ff)->lines->lines[(line)].first + (word)) : "")
+// Open file without logging file IO error if any
+#define procfile_open_no_log(filename, separators, flags) procfile_open(filename, separators, flags | PROCFILE_FLAG_NO_ERROR_ON_FILE_IO)
+
#endif /* NETDATA_PROCFILE_H */
diff --git a/libnetdata/simple_pattern/README.md b/libnetdata/simple_pattern/README.md
index a90759c3..cb377f84 100644
--- a/libnetdata/simple_pattern/README.md
+++ b/libnetdata/simple_pattern/README.md
@@ -40,4 +40,4 @@ Netdata stops processing to the first positive or negative match
(left to right). If it is not matched by either positive or negative
patterns, it is denied at the end.
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Fsimple_pattern%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/socket/README.md b/libnetdata/socket/README.md
index 6736f13b..70bfd344 100644
--- a/libnetdata/socket/README.md
+++ b/libnetdata/socket/README.md
@@ -2,4 +2,4 @@
custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/socket/README.md
-->
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Fsocket%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/statistical/README.md b/libnetdata/statistical/README.md
index ee1faba2..f254081d 100644
--- a/libnetdata/statistical/README.md
+++ b/libnetdata/statistical/README.md
@@ -2,4 +2,4 @@
custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/statistical/README.md
-->
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Fstatistical%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/storage_number/README.md b/libnetdata/storage_number/README.md
index 295b3d6e..4cd19a98 100644
--- a/libnetdata/storage_number/README.md
+++ b/libnetdata/storage_number/README.md
@@ -14,4 +14,4 @@ have less decimal precision) and 3 bits for flags.
This provides an extremely optimized memory footprint with just 0.0001% max accuracy loss.
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Fstorage_number%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/threads/README.md b/libnetdata/threads/README.md
index 377da5ea..75ab11b1 100644
--- a/libnetdata/threads/README.md
+++ b/libnetdata/threads/README.md
@@ -2,4 +2,4 @@
custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/threads/README.md
-->
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Fthreads%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+
diff --git a/libnetdata/threads/threads.c b/libnetdata/threads/threads.c
index d7636940..12007aff 100644
--- a/libnetdata/threads/threads.c
+++ b/libnetdata/threads/threads.c
@@ -147,6 +147,7 @@ void uv_thread_set_name_np(uv_thread_t ut, const char* name) {
pthread_set_name_np(ut, threadname);
#elif defined(__APPLE__)
// Apple can only set its own name
+ UNUSED(ut);
#else
ret = pthread_setname_np(ut, threadname);
#endif
diff --git a/libnetdata/url/README.md b/libnetdata/url/README.md
index 4a95547a..bd289d95 100644
--- a/libnetdata/url/README.md
+++ b/libnetdata/url/README.md
@@ -2,4 +2,4 @@
custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/url/README.md
-->
-[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Flibnetdata%2Furl%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>)
+