ebpf_sync.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "ebpf.h"
  3. #include "ebpf_sync.h"
  4. static char *sync_counter_dimension_name[NETDATA_SYNC_IDX_END] = { "sync", "syncfs", "msync", "fsync", "fdatasync",
  5. "sync_file_range" };
  6. static netdata_syscall_stat_t sync_counter_aggregated_data[NETDATA_SYNC_IDX_END];
  7. static netdata_publish_syscall_t sync_counter_publish_aggregated[NETDATA_SYNC_IDX_END];
  8. static netdata_idx_t sync_hash_values[NETDATA_SYNC_IDX_END];
  9. struct netdata_static_thread sync_threads = {"SYNC KERNEL", NULL, NULL, 1,
  10. NULL, NULL, NULL};
  11. static ebpf_local_maps_t sync_maps[] = {{.name = "tbl_sync", .internal_input = NETDATA_SYNC_END,
  12. .user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
  13. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
  14. {.name = "tbl_syncfs", .internal_input = NETDATA_SYNC_END,
  15. .user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
  16. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
  17. {.name = "tbl_msync", .internal_input = NETDATA_SYNC_END,
  18. .user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
  19. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
  20. {.name = "tbl_fsync", .internal_input = NETDATA_SYNC_END,
  21. .user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
  22. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
  23. {.name = "tbl_fdatasync", .internal_input = NETDATA_SYNC_END,
  24. .user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
  25. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
  26. {.name = "tbl_syncfr", .internal_input = NETDATA_SYNC_END,
  27. .user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
  28. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
  29. {.name = NULL, .internal_input = 0, .user_input = 0,
  30. .type = NETDATA_EBPF_MAP_CONTROLLER,
  31. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED}};
  32. struct config sync_config = { .first_section = NULL,
  33. .last_section = NULL,
  34. .mutex = NETDATA_MUTEX_INITIALIZER,
  35. .index = { .avl_tree = { .root = NULL, .compar = appconfig_section_compare },
  36. .rwlock = AVL_LOCK_INITIALIZER } };
  37. netdata_ebpf_targets_t sync_targets[] = { {.name = NETDATA_SYSCALLS_SYNC, .mode = EBPF_LOAD_TRAMPOLINE},
  38. {.name = NETDATA_SYSCALLS_SYNCFS, .mode = EBPF_LOAD_TRAMPOLINE},
  39. {.name = NETDATA_SYSCALLS_MSYNC, .mode = EBPF_LOAD_TRAMPOLINE},
  40. {.name = NETDATA_SYSCALLS_FSYNC, .mode = EBPF_LOAD_TRAMPOLINE},
  41. {.name = NETDATA_SYSCALLS_FDATASYNC, .mode = EBPF_LOAD_TRAMPOLINE},
  42. {.name = NETDATA_SYSCALLS_SYNC_FILE_RANGE, .mode = EBPF_LOAD_TRAMPOLINE},
  43. {.name = NULL, .mode = EBPF_LOAD_TRAMPOLINE}};
  44. static enum ebpf_threads_status ebpf_sync_exited = NETDATA_THREAD_EBPF_RUNNING;
  45. #ifdef LIBBPF_MAJOR_VERSION
  46. /*****************************************************************
  47. *
  48. * BTF FUNCTIONS
  49. *
  50. *****************************************************************/
  51. /**
  52. * Disable probe
  53. *
  54. * Disable kprobe to use another method.
  55. *
  56. * @param obj is the main structure for bpf objects.
  57. */
  58. static inline void ebpf_sync_disable_probe(struct sync_bpf *obj)
  59. {
  60. bpf_program__set_autoload(obj->progs.netdata_sync_kprobe, false);
  61. }
  62. /**
  63. * Disable tramppoline
  64. *
  65. * Disable trampoline to use another method.
  66. *
  67. * @param obj is the main structure for bpf objects.
  68. */
  69. static inline void ebpf_sync_disable_trampoline(struct sync_bpf *obj)
  70. {
  71. bpf_program__set_autoload(obj->progs.netdata_sync_fentry, false);
  72. }
  73. /**
  74. * Disable tracepoint
  75. *
  76. * Disable tracepoints according information given.
  77. *
  78. * @param obj object loaded
  79. * @param idx Which syscall will not be disabled
  80. */
  81. void ebpf_sync_disable_tracepoints(struct sync_bpf *obj, sync_syscalls_index_t idx)
  82. {
  83. if (idx != NETDATA_SYNC_SYNC_IDX)
  84. bpf_program__set_autoload(obj->progs.netdata_sync_entry, false);
  85. if (idx != NETDATA_SYNC_SYNCFS_IDX)
  86. bpf_program__set_autoload(obj->progs.netdata_syncfs_entry, false);
  87. if (idx != NETDATA_SYNC_MSYNC_IDX)
  88. bpf_program__set_autoload(obj->progs.netdata_msync_entry, false);
  89. if (idx != NETDATA_SYNC_FSYNC_IDX)
  90. bpf_program__set_autoload(obj->progs.netdata_fsync_entry, false);
  91. if (idx != NETDATA_SYNC_FDATASYNC_IDX)
  92. bpf_program__set_autoload(obj->progs.netdata_fdatasync_entry, false);
  93. if (idx != NETDATA_SYNC_SYNC_FILE_RANGE_IDX)
  94. bpf_program__set_autoload(obj->progs.netdata_sync_file_range_entry, false);
  95. }
  96. /**
  97. * Set hash tables
  98. *
  99. * Set the values for maps according the value given by kernel.
  100. *
  101. * @param obj is the main structure for bpf objects.
  102. * @param idx the index for the main structure
  103. */
  104. static void ebpf_sync_set_hash_tables(struct sync_bpf *obj, sync_syscalls_index_t idx)
  105. {
  106. sync_maps[idx].map_fd = bpf_map__fd(obj->maps.tbl_sync);
  107. }
  108. /**
  109. * Load and attach
  110. *
  111. * Load and attach the eBPF code in kernel.
  112. *
  113. * @param obj is the main structure for bpf objects.
  114. * @param em the structure with configuration
  115. * @param target the syscall that we are attaching a tracer.
  116. * @param idx the index for the main structure
  117. *
  118. * @return it returns 0 on succes and -1 otherwise
  119. */
  120. static inline int ebpf_sync_load_and_attach(struct sync_bpf *obj, ebpf_module_t *em, char *target,
  121. sync_syscalls_index_t idx)
  122. {
  123. netdata_ebpf_targets_t *synct = em->targets;
  124. netdata_ebpf_program_loaded_t test = synct[NETDATA_SYNC_SYNC_IDX].mode;
  125. if (test == EBPF_LOAD_TRAMPOLINE) {
  126. ebpf_sync_disable_probe(obj);
  127. ebpf_sync_disable_tracepoints(obj, NETDATA_SYNC_IDX_END);
  128. bpf_program__set_attach_target(obj->progs.netdata_sync_fentry, 0,
  129. target);
  130. } else if (test == EBPF_LOAD_PROBE ||
  131. test == EBPF_LOAD_RETPROBE) {
  132. ebpf_sync_disable_tracepoints(obj, NETDATA_SYNC_IDX_END);
  133. ebpf_sync_disable_trampoline(obj);
  134. } else {
  135. ebpf_sync_disable_probe(obj);
  136. ebpf_sync_disable_trampoline(obj);
  137. ebpf_sync_disable_tracepoints(obj, idx);
  138. }
  139. int ret = sync_bpf__load(obj);
  140. if (!ret) {
  141. if (test != EBPF_LOAD_PROBE && test != EBPF_LOAD_RETPROBE) {
  142. ret = sync_bpf__attach(obj);
  143. } else {
  144. obj->links.netdata_sync_kprobe = bpf_program__attach_kprobe(obj->progs.netdata_sync_kprobe,
  145. false, target);
  146. ret = (int)libbpf_get_error(obj->links.netdata_sync_kprobe);
  147. }
  148. if (!ret)
  149. ebpf_sync_set_hash_tables(obj, idx);
  150. }
  151. return ret;
  152. }
  153. #endif
  154. /*****************************************************************
  155. *
  156. * CLEANUP THREAD
  157. *
  158. *****************************************************************/
  159. /**
  160. * Cleanup Objects
  161. *
  162. * Cleanup loaded objects when thread was initialized.
  163. */
  164. void ebpf_sync_cleanup_objects()
  165. {
  166. int i;
  167. for (i = 0; local_syscalls[i].syscall; i++) {
  168. ebpf_sync_syscalls_t *w = &local_syscalls[i];
  169. if (w->probe_links) {
  170. struct bpf_program *prog;
  171. size_t j = 0 ;
  172. bpf_object__for_each_program(prog, w->objects) {
  173. bpf_link__destroy(w->probe_links[j]);
  174. j++;
  175. }
  176. freez(w->probe_links);
  177. if (w->objects)
  178. bpf_object__close(w->objects);
  179. }
  180. #ifdef LIBBPF_MAJOR_VERSION
  181. else if (w->sync_obj)
  182. sync_bpf__destroy(w->sync_obj);
  183. #endif
  184. }
  185. }
  186. /**
  187. * Exit
  188. *
  189. * Clean up the main thread.
  190. *
  191. * @param ptr thread data.
  192. */
  193. static void ebpf_sync_exit(void *ptr)
  194. {
  195. ebpf_module_t *em = (ebpf_module_t *)ptr;
  196. if (!em->enabled) {
  197. em->enabled = NETDATA_MAIN_THREAD_EXITED;
  198. return;
  199. }
  200. ebpf_sync_exited = NETDATA_THREAD_EBPF_STOPPING;
  201. }
  202. /**
  203. * Clean up the main thread.
  204. *
  205. * @param ptr thread data.
  206. */
  207. static void ebpf_sync_cleanup(void *ptr)
  208. {
  209. ebpf_module_t *em = (ebpf_module_t *)ptr;
  210. if (ebpf_sync_exited != NETDATA_THREAD_EBPF_STOPPED)
  211. return;
  212. ebpf_sync_cleanup_objects();
  213. freez(sync_threads.thread);
  214. sync_threads.enabled = NETDATA_MAIN_THREAD_EXITED;
  215. em->enabled = NETDATA_MAIN_THREAD_EXITED;
  216. }
  217. /*****************************************************************
  218. *
  219. * INITIALIZE THREAD
  220. *
  221. *****************************************************************/
  222. /**
  223. * Load Legacy
  224. *
  225. * Load legacy code.
  226. *
  227. * @param w is the sync output structure with pointers to objects loaded.
  228. * @param em is structure with configuration
  229. *
  230. * @return 0 on success and -1 otherwise.
  231. */
  232. static int ebpf_sync_load_legacy(ebpf_sync_syscalls_t *w, ebpf_module_t *em)
  233. {
  234. em->thread_name = w->syscall;
  235. if (!w->probe_links) {
  236. w->probe_links = ebpf_load_program(ebpf_plugin_dir, em, running_on_kernel, isrh, &w->objects);
  237. if (!w->probe_links) {
  238. return -1;
  239. }
  240. }
  241. return 0;
  242. }
  243. /*
  244. * Initialize Syscalls
  245. *
  246. * Load the eBPF programs to monitor syscalls
  247. *
  248. * @return 0 on success and -1 otherwise.
  249. */
  250. static int ebpf_sync_initialize_syscall(ebpf_module_t *em)
  251. {
  252. int i;
  253. const char *saved_name = em->thread_name;
  254. int errors = 0;
  255. for (i = 0; local_syscalls[i].syscall; i++) {
  256. ebpf_sync_syscalls_t *w = &local_syscalls[i];
  257. if (w->enabled) {
  258. if (em->load == EBPF_LOAD_LEGACY) {
  259. if (ebpf_sync_load_legacy(w, em))
  260. errors++;
  261. em->thread_name = saved_name;
  262. }
  263. #ifdef LIBBPF_MAJOR_VERSION
  264. else {
  265. char syscall[NETDATA_EBPF_MAX_SYSCALL_LENGTH];
  266. ebpf_select_host_prefix(syscall, NETDATA_EBPF_MAX_SYSCALL_LENGTH, w->syscall, running_on_kernel);
  267. w->sync_obj = sync_bpf__open();
  268. if (!w->sync_obj) {
  269. errors++;
  270. } else {
  271. if (ebpf_is_function_inside_btf(default_btf, syscall)) {
  272. if (ebpf_sync_load_and_attach(w->sync_obj, em, syscall, i)) {
  273. errors++;
  274. }
  275. } else {
  276. if (ebpf_sync_load_legacy(w, em))
  277. errors++;
  278. }
  279. em->thread_name = saved_name;
  280. }
  281. }
  282. #endif
  283. }
  284. }
  285. em->thread_name = saved_name;
  286. memset(sync_counter_aggregated_data, 0 , NETDATA_SYNC_IDX_END * sizeof(netdata_syscall_stat_t));
  287. memset(sync_counter_publish_aggregated, 0 , NETDATA_SYNC_IDX_END * sizeof(netdata_publish_syscall_t));
  288. memset(sync_hash_values, 0 , NETDATA_SYNC_IDX_END * sizeof(netdata_idx_t));
  289. return (errors) ? -1 : 0;
  290. }
  291. /*****************************************************************
  292. *
  293. * DATA THREAD
  294. *
  295. *****************************************************************/
  296. /**
  297. * Read global table
  298. *
  299. * Read the table with number of calls for all functions
  300. */
  301. static void read_global_table()
  302. {
  303. netdata_idx_t stored;
  304. uint32_t idx = NETDATA_SYNC_CALL;
  305. int i;
  306. for (i = 0; local_syscalls[i].syscall; i++) {
  307. if (local_syscalls[i].enabled) {
  308. int fd = sync_maps[i].map_fd;
  309. if (!bpf_map_lookup_elem(fd, &idx, &stored)) {
  310. sync_hash_values[i] = stored;
  311. }
  312. }
  313. }
  314. }
  315. /**
  316. * Sync read hash
  317. *
  318. * This is the thread callback.
  319. *
  320. * @param ptr It is a NULL value for this thread.
  321. *
  322. * @return It always returns NULL.
  323. */
  324. void *ebpf_sync_read_hash(void *ptr)
  325. {
  326. netdata_thread_cleanup_push(ebpf_sync_cleanup, ptr);
  327. ebpf_module_t *em = (ebpf_module_t *)ptr;
  328. heartbeat_t hb;
  329. heartbeat_init(&hb);
  330. usec_t step = NETDATA_EBPF_SYNC_SLEEP_MS * em->update_every;
  331. while (ebpf_sync_exited == NETDATA_THREAD_EBPF_RUNNING) {
  332. usec_t dt = heartbeat_next(&hb, step);
  333. (void)dt;
  334. if (ebpf_sync_exited == NETDATA_THREAD_EBPF_STOPPING)
  335. break;
  336. read_global_table();
  337. }
  338. ebpf_sync_exited = NETDATA_THREAD_EBPF_STOPPED;
  339. netdata_thread_cleanup_pop(1);
  340. return NULL;
  341. }
  342. /**
  343. * Create Sync charts
  344. *
  345. * Create charts and dimensions according user input.
  346. *
  347. * @param id chart id
  348. * @param idx the first index with data.
  349. * @param end the last index with data.
  350. */
  351. static void ebpf_send_sync_chart(char *id,
  352. int idx,
  353. int end)
  354. {
  355. write_begin_chart(NETDATA_EBPF_MEMORY_GROUP, id);
  356. netdata_publish_syscall_t *move = &sync_counter_publish_aggregated[idx];
  357. while (move && idx <= end) {
  358. if (local_syscalls[idx].enabled)
  359. write_chart_dimension(move->name, sync_hash_values[idx]);
  360. move = move->next;
  361. idx++;
  362. }
  363. write_end_chart();
  364. }
  365. /**
  366. * Send data
  367. *
  368. * Send global charts to Netdata
  369. */
  370. static void sync_send_data()
  371. {
  372. if (local_syscalls[NETDATA_SYNC_FSYNC_IDX].enabled || local_syscalls[NETDATA_SYNC_FDATASYNC_IDX].enabled) {
  373. ebpf_send_sync_chart(NETDATA_EBPF_FILE_SYNC_CHART, NETDATA_SYNC_FSYNC_IDX, NETDATA_SYNC_FDATASYNC_IDX);
  374. }
  375. if (local_syscalls[NETDATA_SYNC_MSYNC_IDX].enabled)
  376. ebpf_one_dimension_write_charts(NETDATA_EBPF_MEMORY_GROUP, NETDATA_EBPF_MSYNC_CHART,
  377. sync_counter_publish_aggregated[NETDATA_SYNC_MSYNC_IDX].dimension,
  378. sync_hash_values[NETDATA_SYNC_MSYNC_IDX]);
  379. if (local_syscalls[NETDATA_SYNC_SYNC_IDX].enabled || local_syscalls[NETDATA_SYNC_SYNCFS_IDX].enabled) {
  380. ebpf_send_sync_chart(NETDATA_EBPF_SYNC_CHART, NETDATA_SYNC_SYNC_IDX, NETDATA_SYNC_SYNCFS_IDX);
  381. }
  382. if (local_syscalls[NETDATA_SYNC_SYNC_FILE_RANGE_IDX].enabled)
  383. ebpf_one_dimension_write_charts(NETDATA_EBPF_MEMORY_GROUP, NETDATA_EBPF_FILE_SEGMENT_CHART,
  384. sync_counter_publish_aggregated[NETDATA_SYNC_SYNC_FILE_RANGE_IDX].dimension,
  385. sync_hash_values[NETDATA_SYNC_SYNC_FILE_RANGE_IDX]);
  386. }
  387. /**
  388. * Main loop for this collector.
  389. */
  390. static void sync_collector(ebpf_module_t *em)
  391. {
  392. sync_threads.thread = mallocz(sizeof(netdata_thread_t));
  393. sync_threads.start_routine = ebpf_sync_read_hash;
  394. netdata_thread_create(sync_threads.thread, sync_threads.name, NETDATA_THREAD_OPTION_DEFAULT,
  395. ebpf_sync_read_hash, em);
  396. heartbeat_t hb;
  397. heartbeat_init(&hb);
  398. usec_t step = em->update_every * USEC_PER_SEC;
  399. while (!ebpf_exit_plugin) {
  400. (void)heartbeat_next(&hb, step);
  401. if (ebpf_exit_plugin)
  402. break;
  403. pthread_mutex_lock(&lock);
  404. sync_send_data();
  405. pthread_mutex_unlock(&lock);
  406. }
  407. }
  408. /*****************************************************************
  409. *
  410. * MAIN THREAD
  411. *
  412. *****************************************************************/
  413. /**
  414. * Create Sync charts
  415. *
  416. * Create charts and dimensions according user input.
  417. *
  418. * @param id chart id
  419. * @param title chart title
  420. * @param order order number of the specified chart
  421. * @param idx the first index with data.
  422. * @param end the last index with data.
  423. * @param update_every value to overwrite the update frequency set by the server.
  424. */
  425. static void ebpf_create_sync_chart(char *id,
  426. char *title,
  427. int order,
  428. int idx,
  429. int end,
  430. int update_every)
  431. {
  432. ebpf_write_chart_cmd(NETDATA_EBPF_MEMORY_GROUP, id, title, EBPF_COMMON_DIMENSION_CALL,
  433. NETDATA_EBPF_SYNC_SUBMENU, NETDATA_EBPF_CHART_TYPE_LINE, NULL, order,
  434. update_every,
  435. NETDATA_EBPF_MODULE_NAME_SYNC);
  436. netdata_publish_syscall_t *move = &sync_counter_publish_aggregated[idx];
  437. while (move && idx <= end) {
  438. if (local_syscalls[idx].enabled)
  439. ebpf_write_global_dimension(move->name, move->dimension, move->algorithm);
  440. move = move->next;
  441. idx++;
  442. }
  443. }
  444. /**
  445. * Create global charts
  446. *
  447. * Call ebpf_create_chart to create the charts for the collector.
  448. *
  449. * @param update_every value to overwrite the update frequency set by the server.
  450. */
  451. static void ebpf_create_sync_charts(int update_every)
  452. {
  453. if (local_syscalls[NETDATA_SYNC_FSYNC_IDX].enabled || local_syscalls[NETDATA_SYNC_FDATASYNC_IDX].enabled)
  454. ebpf_create_sync_chart(NETDATA_EBPF_FILE_SYNC_CHART,
  455. "Monitor calls for <code>fsync(2)</code> and <code>fdatasync(2)</code>.", 21300,
  456. NETDATA_SYNC_FSYNC_IDX, NETDATA_SYNC_FDATASYNC_IDX, update_every);
  457. if (local_syscalls[NETDATA_SYNC_MSYNC_IDX].enabled)
  458. ebpf_create_sync_chart(NETDATA_EBPF_MSYNC_CHART,
  459. "Monitor calls for <code>msync(2)</code>.", 21301,
  460. NETDATA_SYNC_MSYNC_IDX, NETDATA_SYNC_MSYNC_IDX, update_every);
  461. if (local_syscalls[NETDATA_SYNC_SYNC_IDX].enabled || local_syscalls[NETDATA_SYNC_SYNCFS_IDX].enabled)
  462. ebpf_create_sync_chart(NETDATA_EBPF_SYNC_CHART,
  463. "Monitor calls for <code>sync(2)</code> and <code>syncfs(2)</code>.", 21302,
  464. NETDATA_SYNC_SYNC_IDX, NETDATA_SYNC_SYNCFS_IDX, update_every);
  465. if (local_syscalls[NETDATA_SYNC_SYNC_FILE_RANGE_IDX].enabled)
  466. ebpf_create_sync_chart(NETDATA_EBPF_FILE_SEGMENT_CHART,
  467. "Monitor calls for <code>sync_file_range(2)</code>.", 21303,
  468. NETDATA_SYNC_SYNC_FILE_RANGE_IDX, NETDATA_SYNC_SYNC_FILE_RANGE_IDX, update_every);
  469. }
  470. /**
  471. * Parse Syscalls
  472. *
  473. * Parse syscall options available inside ebpf.d/sync.conf
  474. */
  475. static void ebpf_sync_parse_syscalls()
  476. {
  477. int i;
  478. for (i = 0; local_syscalls[i].syscall; i++) {
  479. local_syscalls[i].enabled = appconfig_get_boolean(&sync_config, NETDATA_SYNC_CONFIG_NAME,
  480. local_syscalls[i].syscall, CONFIG_BOOLEAN_YES);
  481. }
  482. }
  483. /**
  484. * Sync thread
  485. *
  486. * Thread used to make sync thread
  487. *
  488. * @param ptr a pointer to `struct ebpf_module`
  489. *
  490. * @return It always return NULL
  491. */
  492. void *ebpf_sync_thread(void *ptr)
  493. {
  494. netdata_thread_cleanup_push(ebpf_sync_exit, ptr);
  495. ebpf_module_t *em = (ebpf_module_t *)ptr;
  496. em->maps = sync_maps;
  497. ebpf_sync_parse_syscalls();
  498. if (!em->enabled)
  499. goto endsync;
  500. #ifdef LIBBPF_MAJOR_VERSION
  501. ebpf_adjust_thread_load(em, default_btf);
  502. #endif
  503. if (ebpf_sync_initialize_syscall(em)) {
  504. em->enabled = CONFIG_BOOLEAN_NO;
  505. goto endsync;
  506. }
  507. int algorithms[NETDATA_SYNC_IDX_END] = { NETDATA_EBPF_INCREMENTAL_IDX, NETDATA_EBPF_INCREMENTAL_IDX,
  508. NETDATA_EBPF_INCREMENTAL_IDX, NETDATA_EBPF_INCREMENTAL_IDX,
  509. NETDATA_EBPF_INCREMENTAL_IDX, NETDATA_EBPF_INCREMENTAL_IDX };
  510. ebpf_global_labels(sync_counter_aggregated_data, sync_counter_publish_aggregated,
  511. sync_counter_dimension_name, sync_counter_dimension_name,
  512. algorithms, NETDATA_SYNC_IDX_END);
  513. pthread_mutex_lock(&lock);
  514. ebpf_create_sync_charts(em->update_every);
  515. ebpf_update_stats(&plugin_statistics, em);
  516. pthread_mutex_unlock(&lock);
  517. sync_collector(em);
  518. endsync:
  519. if (!em->enabled)
  520. ebpf_update_disabled_plugin_stats(em);
  521. netdata_thread_cleanup_pop(1);
  522. return NULL;
  523. }