diff options
author | vkalintiris <vasilis@netdata.cloud> | 2022-01-19 08:54:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-19 08:54:37 +0200 |
commit | 37082fcbc150619b54b2a64c3621afc617607adc (patch) | |
tree | c0a5559cd3c5f1abcda0c099de993273bcebaff5 /daemon | |
parent | cc119e9e878959f155d38630c6d8e504d213383e (diff) |
Compute platform-specific list of static_threads at runtime. (#11955)
Compute array of static threads at runtime.
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/analytics.h | 12 | ||||
-rw-r--r-- | daemon/common.h | 2 | ||||
-rw-r--r-- | daemon/global_statistics.c | 2 | ||||
-rw-r--r-- | daemon/global_statistics.h | 12 | ||||
-rw-r--r-- | daemon/main.c | 41 | ||||
-rw-r--r-- | daemon/main.h | 18 | ||||
-rw-r--r-- | daemon/service.c | 2 | ||||
-rw-r--r-- | daemon/service.h | 19 | ||||
-rw-r--r-- | daemon/static_threads.c | 161 | ||||
-rw-r--r-- | daemon/static_threads.h | 46 | ||||
-rw-r--r-- | daemon/static_threads_freebsd.c | 31 | ||||
-rw-r--r-- | daemon/static_threads_linux.c | 71 | ||||
-rw-r--r-- | daemon/static_threads_macos.c | 31 |
13 files changed, 349 insertions, 99 deletions
diff --git a/daemon/analytics.h b/daemon/analytics.h index 343448cd71..76c1cbb7e0 100644 --- a/daemon/analytics.h +++ b/daemon/analytics.h @@ -17,17 +17,6 @@ #define ANALYTICS_MAX_JSON_HITS 255 #define ANALYTICS_MAX_DASHBOARD_HITS 255 -#define NETDATA_PLUGIN_HOOK_ANALYTICS \ - { \ - .name = "ANALYTICS", \ - .config_section = NULL, \ - .config_name = NULL, \ - .enabled = 0, \ - .thread = NULL, \ - .init_routine = NULL, \ - .start_routine = analytics_main \ - }, - /* Needed to calculate the space needed for parameters */ #define ANALYTICS_NO_OF_ITEMS 39 @@ -80,7 +69,6 @@ struct analytics_data { uint8_t dashboard_hits; }; -extern void *analytics_main(void *ptr); extern void analytics_get_data(char *name, BUFFER *wb); extern void set_late_global_environment(void); extern void analytics_free_data(void); diff --git a/daemon/common.h b/daemon/common.h index c892dbdb16..5354e2ae00 100644 --- a/daemon/common.h +++ b/daemon/common.h @@ -79,8 +79,8 @@ // the netdata daemon #include "daemon.h" #include "main.h" +#include "static_threads.h" #include "signals.h" -#include "service.h" #include "commands.h" #include "analytics.h" diff --git a/daemon/global_statistics.c b/daemon/global_statistics.c index a152a00ae2..f4f3e5762b 100644 --- a/daemon/global_statistics.c +++ b/daemon/global_statistics.c @@ -172,7 +172,7 @@ static inline void global_statistics_copy(struct global_statistics *gs, uint8_t #endif } -void global_statistics_charts(void) { +static void global_statistics_charts(void) { static unsigned long long old_web_requests = 0, old_web_usec = 0, old_content_size = 0, diff --git a/daemon/global_statistics.h b/daemon/global_statistics.h index c200a693bf..268b5319e7 100644 --- a/daemon/global_statistics.h +++ b/daemon/global_statistics.h @@ -8,17 +8,6 @@ // ---------------------------------------------------------------------------- // global statistics -#define NETDATA_PLUGIN_HOOK_GLOBAL_STATISTICS \ - {.name = "GLOBAL_STATS", \ - .config_section = NULL, \ - .config_name = NULL, \ - .enabled = 1, \ - .thread = NULL, \ - .init_routine = NULL, \ - .start_routine = global_statistics_main}, - -extern void *global_statistics_main(void *ptr); - extern void rrdr_query_completed(uint64_t db_points_read, uint64_t result_points_generated); extern void finished_web_request_statistics(uint64_t dt, @@ -29,6 +18,5 @@ extern void finished_web_request_statistics(uint64_t dt, extern uint64_t web_client_connected(void); extern void web_client_disconnected(void); -extern void global_statistics_charts(void); #endif /* NETDATA_GLOBAL_STATISTICS_H */ diff --git a/daemon/main.c b/daemon/main.c index 2ec5c33f9e..7c8e09a5fe 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -2,10 +2,13 @@ #include "common.h" #include "buildinfo.h" +#include "static_threads.h" int netdata_zero_metrics_enabled; int netdata_anonymous_statistics_enabled; +struct netdata_static_thread *static_threads; + struct config netdata_config = { .first_section = NULL, .last_section = NULL, @@ -76,41 +79,6 @@ void netdata_cleanup_and_exit(int ret) { exit(ret); } -struct netdata_static_thread static_threads[] = { - NETDATA_PLUGIN_HOOK_GLOBAL_STATISTICS - - NETDATA_PLUGIN_HOOK_CHECKS - NETDATA_PLUGIN_HOOK_FREEBSD - NETDATA_PLUGIN_HOOK_MACOS - - // linux internal plugins - NETDATA_PLUGIN_HOOK_LINUX_PROC - NETDATA_PLUGIN_HOOK_LINUX_DISKSPACE - NETDATA_PLUGIN_HOOK_LINUX_TIMEX - NETDATA_PLUGIN_HOOK_LINUX_CGROUPS - NETDATA_PLUGIN_HOOK_LINUX_TC - - NETDATA_PLUGIN_HOOK_IDLEJITTER - NETDATA_PLUGIN_HOOK_STATSD - -#if defined(ENABLE_ACLK) || defined(ACLK_NG) - NETDATA_ACLK_HOOK -#endif - - // common plugins for all systems - {"BACKENDS", NULL, NULL, 1, NULL, NULL, backends_main}, - {"EXPORTING", NULL, NULL, 1, NULL, NULL, exporting_main}, - {"WEB_SERVER[static1]", NULL, NULL, 0, NULL, NULL, socket_listen_main_static_threaded}, - {"STREAM", NULL, NULL, 0, NULL, NULL, rrdpush_sender_thread}, - - NETDATA_PLUGIN_HOOK_PLUGINSD - NETDATA_PLUGIN_HOOK_HEALTH - NETDATA_PLUGIN_HOOK_ANALYTICS - NETDATA_PLUGIN_HOOK_SERVICE - - {NULL, NULL, NULL, 0, NULL, NULL, NULL} -}; - void web_server_threading_selection(void) { web_server_mode = web_server_mode_id(config_get(CONFIG_SECTION_WEB, "mode", web_server_mode_name(web_server_mode))); @@ -281,6 +249,8 @@ void cancel_main_threads() { } else info("All threads finished."); + + free(static_threads); } struct option_def option_definitions[] = { @@ -723,6 +693,7 @@ int main(int argc, char **argv) { size_t default_stacksize; char *user = NULL; + static_threads = static_threads_get(); netdata_ready=0; // set the name for logging diff --git a/daemon/main.h b/daemon/main.h index 4000ab70b8..63d6c5a095 100644 --- a/daemon/main.h +++ b/daemon/main.h @@ -7,10 +7,6 @@ extern struct config netdata_config; -#define NETDATA_MAIN_THREAD_RUNNING CONFIG_BOOLEAN_YES -#define NETDATA_MAIN_THREAD_EXITING (CONFIG_BOOLEAN_YES + 1) -#define NETDATA_MAIN_THREAD_EXITED CONFIG_BOOLEAN_NO - /** * This struct contains information about command line options. */ @@ -26,20 +22,6 @@ struct option_def { const char *default_value; }; -struct netdata_static_thread { - char *name; // the name of the thread as it should appear in the logs - - char *config_section; // the section of netdata.conf to check if this is enabled or not - char *config_name; // the name of the config option to check if it is true or false - - volatile sig_atomic_t enabled; // the current status of the thread - - netdata_thread_t *thread; // internal use, to maintain a pointer to the created thread - - void (*init_routine) (void); // an initialization function to run before spawning the thread - void *(*start_routine) (void *); // the threaded worker -}; - extern void cancel_main_threads(void); extern int killpid(pid_t pid); extern void netdata_cleanup_and_exit(int ret) NORETURN; diff --git a/daemon/service.c b/daemon/service.c index 9cba0694fa..d3a4e5500b 100644 --- a/daemon/service.c +++ b/daemon/service.c @@ -5,7 +5,7 @@ /* Run service jobs every X seconds */ #define SERVICE_HEARTBEAT 10 -void service_main_cleanup(void *ptr) +static void service_main_cleanup(void *ptr) { struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr; static_thread->enabled = NETDATA_MAIN_THREAD_EXITING; diff --git a/daemon/service.h b/daemon/service.h deleted file mode 100644 index cb03bec2cd..0000000000 --- a/daemon/service.h +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later - -#ifndef NETDATA_SERVICE_H -#define NETDATA_SERVICE_H 1 - -#define NETDATA_PLUGIN_HOOK_SERVICE \ - { \ - .name = "SERVICE", \ - .config_section = NULL, \ - .config_name = NULL, \ - .enabled = 1, \ - .thread = NULL, \ - .init_routine = NULL, \ - .start_routine = service_main \ - }, - -extern void *service_main(void *ptr); - -#endif //NETDATA_SERVICE_H diff --git a/daemon/static_threads.c b/daemon/static_threads.c new file mode 100644 index 0000000000..534b3c3d8c --- /dev/null +++ b/daemon/static_threads.c @@ -0,0 +1,161 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "common.h" + +extern void *aclk_starter(void *ptr); +extern void *analytics_main(void *ptr); +extern void *checks_main(void *ptr); +extern void *cpuidlejitter_main(void *ptr); +extern void *global_statistics_main(void *ptr); +extern void *health_main(void *ptr); +extern void *pluginsd_main(void *ptr); +extern void *service_main(void *ptr); +extern void *statsd_main(void *ptr); + +const struct netdata_static_thread static_threads_common[] = { + { + .name = "PLUGIN[check]", + .config_section = CONFIG_SECTION_PLUGINS, + .config_name = "checks", + .enabled = 0, + .thread = NULL, + .init_routine = NULL, + .start_routine = checks_main + }, + { + .name = "PLUGIN[idlejitter]", + .config_section = CONFIG_SECTION_PLUGINS, + .config_name = "idlejitter", + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = cpuidlejitter_main + }, + { + .name = "ANALYTICS", + .config_section = NULL, + .config_name = NULL, + .enabled = 0, + .thread = NULL, + .init_routine = NULL, + .start_routine = analytics_main + }, + { + .name = "GLOBAL_STATS", + .config_section = NULL, + .config_name = NULL, + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = global_statistics_main + }, + { + .name = "HEALTH", + .config_section = NULL, + .config_name = NULL, + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = health_main + }, + { + .name = "PLUGINSD", + .config_section = NULL, + .config_name = NULL, + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = pluginsd_main + }, + { + .name = "SERVICE", + .config_section = NULL, + .config_name = NULL, + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = service_main + }, + { + .name = "STATSD", + .config_section = NULL, + .config_name = NULL, + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = statsd_main + }, + { + .name = "BACKENDS", + .config_section = NULL, + .config_name = NULL, + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = backends_main + }, + { + .name = "EXPORTING", + .config_section = NULL, + .config_name = NULL, + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = exporting_main + }, + { + .name = "STREAM", + .config_section = NULL, + .config_name = NULL, + .enabled = 0, + .thread = NULL, + .init_routine = NULL, + .start_routine = rrdpush_sender_thread + }, + { + .name = "WEB_SERVER[static1]", + .config_section = NULL, + .config_name = NULL, + .enabled = 0, + .thread = NULL, + .init_routine = NULL, + .start_routine = socket_listen_main_static_threaded + }, + +#if defined(ENABLE_ACLK) || defined(ACLK_NG) + { + .name = "ACLK_Main", + .config_section = NULL, + .config_name = NULL, + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = aclk_starter + }, +#endif + + {NULL, NULL, NULL, 0, NULL, NULL, NULL} +}; + +struct netdata_static_thread * +static_threads_concat(const struct netdata_static_thread *lhs, + const struct netdata_static_thread *rhs) +{ + struct netdata_static_thread *res; + + int lhs_size = 0; + for (; lhs[lhs_size].name; lhs_size++) {} + + int rhs_size = 0; + for (; rhs[rhs_size].name; rhs_size++) {} + + res = callocz(lhs_size + rhs_size + 1, sizeof(struct netdata_static_thread)); + + for (int i = 0; i != lhs_size; i++) + memcpy(&res[i], &lhs[i], sizeof(struct netdata_static_thread)); + + for (int i = 0; i != rhs_size; i++) + memcpy(&res[lhs_size + i], &rhs[i], sizeof(struct netdata_static_thread)); + + return res; +} diff --git a/daemon/static_threads.h b/daemon/static_threads.h new file mode 100644 index 0000000000..dac615e76d --- /dev/null +++ b/daemon/static_threads.h @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef NETDATA_STATIC_THREADS_H +#define NETDATA_STATIC_THREADS_H + +#include "common.h" + +struct netdata_static_thread { + // the name of the thread as it should appear in the logs + char *name; + + // the section of netdata.conf to check if this is enabled or not + char *config_section; + + // the name of the config option to check if it is true or false + char *config_name; + + // the current status of the thread + volatile sig_atomic_t enabled; + + // internal use, to maintain a pointer to the created thread + netdata_thread_t *thread; + + // an initialization function to run before spawning the thread + void (*init_routine) (void); + + // the threaded worker + void *(*start_routine) (void *); +}; + +#define NETDATA_MAIN_THREAD_RUNNING CONFIG_BOOLEAN_YES +#define NETDATA_MAIN_THREAD_EXITING (CONFIG_BOOLEAN_YES + 1) +#define NETDATA_MAIN_THREAD_EXITED CONFIG_BOOLEAN_NO + +extern const struct netdata_static_thread static_threads_common[]; +extern const struct netdata_static_thread static_threads_linux[]; +extern const struct netdata_static_thread static_threads_freebsd[]; +extern const struct netdata_static_thread static_threads_macos[]; + +struct netdata_static_thread * +static_threads_concat(const struct netdata_static_thread *lhs, + const struct netdata_static_thread *rhs); + +struct netdata_static_thread *static_threads_get(); + +#endif /* NETDATA_STATIC_THREADS_H */ diff --git a/daemon/static_threads_freebsd.c b/daemon/static_threads_freebsd.c new file mode 100644 index 0000000000..48066bff52 --- /dev/null +++ b/daemon/static_threads_freebsd.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "common.h" + +extern void *freebsd_main(void *ptr); + +const struct netdata_static_thread static_threads_freebsd[] = { + { + .name = "PLUGIN[freebsd]", + .config_section = CONFIG_SECTION_PLUGINS, + .config_name = "freebsd", + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = freebsd_main + }, + + {NULL, NULL, NULL, 0, NULL, NULL, NULL} +}; + +const struct netdata_static_thread static_threads_linux[] = { + {NULL, NULL, NULL, 0, NULL, NULL, NULL} +}; + +const struct netdata_static_thread static_threads_macos[] = { + {NULL, NULL, NULL, 0, NULL, NULL, NULL} +}; + +struct netdata_static_thread *static_threads_get() { + return static_threads_concat(static_threads_common, static_threads_freebsd); +} diff --git a/daemon/static_threads_linux.c b/daemon/static_threads_linux.c new file mode 100644 index 0000000000..e55c0fec7c --- /dev/null +++ b/daemon/static_threads_linux.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "common.h" + +extern void *cgroups_main(void *ptr); +extern void *proc_main(void *ptr); +extern void *diskspace_main(void *ptr); +extern void *tc_main(void *ptr); +extern void *timex_main(void *ptr); + +const struct netdata_static_thread static_threads_linux[] = { + { + .name = "PLUGIN[timex]", + .config_section = CONFIG_SECTION_PLUGINS, + .config_name = "timex", + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = timex_main + }, + { + .name = "PLUGIN[tc]", + .config_section = CONFIG_SECTION_PLUGINS, + .config_name = "tc", + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = tc_main + }, + { + .name = "PLUGIN[diskspace]", + .config_section = CONFIG_SECTION_PLUGINS, + .config_name = "diskspace", + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = diskspace_main + }, + { + .name = "PLUGIN[proc]", + .config_section = CONFIG_SECTION_PLUGINS, + .config_name = "proc", + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = proc_main + }, + { + .name = "PLUGIN[cgroups]", + .config_section = CONFIG_SECTION_PLUGINS, + .config_name = "cgroups", + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = cgroups_main + }, + + {NULL, NULL, NULL, 0, NULL, NULL, NULL} +}; + +const struct netdata_static_thread static_threads_freebsd[] = { + {NULL, NULL, NULL, 0, NULL, NULL, NULL} +}; + +const struct netdata_static_thread static_threads_macos[] = { + {NULL, NULL, NULL, 0, NULL, NULL, NULL} +}; + +struct netdata_static_thread *static_threads_get() { + return static_threads_concat(static_threads_common, static_threads_linux); +} diff --git a/daemon/static_threads_macos.c b/daemon/static_threads_macos.c new file mode 100644 index 0000000000..ae34a1363d --- /dev/null +++ b/daemon/static_threads_macos.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "common.h" + +extern void *macos_main(void *ptr); + +const struct netdata_static_thread static_threads_macos[] = { + { + .name = "PLUGIN[macos]", + .config_section = CONFIG_SECTION_PLUGINS, + .config_name = "macos", + .enabled = 1, + .thread = NULL, + .init_routine = NULL, + .start_routine = macos_main + }, + + {NULL, NULL, NULL, 0, NULL, NULL, NULL} +}; + +const struct netdata_static_thread static_threads_freebsd[] = { + {NULL, NULL, NULL, 0, NULL, NULL, NULL} +}; + +const struct netdata_static_thread static_threads_linux[] = { + {NULL, NULL, NULL, 0, NULL, NULL, NULL} +}; + +struct netdata_static_thread *static_threads_get() { + return static_threads_concat(static_threads_common, static_threads_macos); +} |