ebpf_hardirq.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "ebpf.h"
  3. #include "ebpf_hardirq.h"
  4. struct config hardirq_config = { .first_section = NULL,
  5. .last_section = NULL,
  6. .mutex = NETDATA_MUTEX_INITIALIZER,
  7. .index = { .avl_tree = { .root = NULL, .compar = appconfig_section_compare },
  8. .rwlock = AVL_LOCK_INITIALIZER } };
  9. static ebpf_local_maps_t hardirq_maps[] = {
  10. {
  11. .name = "tbl_hardirq",
  12. .internal_input = NETDATA_HARDIRQ_MAX_IRQS,
  13. .user_input = 0,
  14. .type = NETDATA_EBPF_MAP_STATIC,
  15. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED,
  16. #ifdef LIBBPF_MAJOR_VERSION
  17. .map_type = BPF_MAP_TYPE_PERCPU_HASH
  18. #endif
  19. },
  20. {
  21. .name = "tbl_hardirq_static",
  22. .internal_input = HARDIRQ_EBPF_STATIC_END,
  23. .user_input = 0,
  24. .type = NETDATA_EBPF_MAP_STATIC,
  25. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED,
  26. #ifdef LIBBPF_MAJOR_VERSION
  27. .map_type = BPF_MAP_TYPE_PERCPU_ARRAY
  28. #endif
  29. },
  30. /* end */
  31. {
  32. .name = NULL,
  33. .internal_input = 0,
  34. .user_input = 0,
  35. .type = NETDATA_EBPF_MAP_CONTROLLER,
  36. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED,
  37. #ifdef LIBBPF_MAJOR_VERSION
  38. .map_type = BPF_MAP_TYPE_PERCPU_ARRAY
  39. #endif
  40. }
  41. };
  42. #define HARDIRQ_TP_CLASS_IRQ "irq"
  43. #define HARDIRQ_TP_CLASS_IRQ_VECTORS "irq_vectors"
  44. static ebpf_tracepoint_t hardirq_tracepoints[] = {
  45. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ, .event = "irq_handler_entry"},
  46. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ, .event = "irq_handler_exit"},
  47. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "thermal_apic_entry"},
  48. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "thermal_apic_exit"},
  49. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "threshold_apic_entry"},
  50. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "threshold_apic_exit"},
  51. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "error_apic_entry"},
  52. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "error_apic_exit"},
  53. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "deferred_error_apic_entry"},
  54. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "deferred_error_apic_exit"},
  55. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "spurious_apic_entry"},
  56. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "spurious_apic_exit"},
  57. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "call_function_entry"},
  58. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "call_function_exit"},
  59. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "call_function_single_entry"},
  60. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "call_function_single_exit"},
  61. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "reschedule_entry"},
  62. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "reschedule_exit"},
  63. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "local_timer_entry"},
  64. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "local_timer_exit"},
  65. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "irq_work_entry"},
  66. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "irq_work_exit"},
  67. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "x86_platform_ipi_entry"},
  68. {.enabled = false, .class = HARDIRQ_TP_CLASS_IRQ_VECTORS, .event = "x86_platform_ipi_exit"},
  69. /* end */
  70. {.enabled = false, .class = NULL, .event = NULL}
  71. };
  72. static hardirq_static_val_t hardirq_static_vals[] = {
  73. {
  74. .idx = HARDIRQ_EBPF_STATIC_APIC_THERMAL,
  75. .name = "apic_thermal",
  76. .latency = 0
  77. },
  78. {
  79. .idx = HARDIRQ_EBPF_STATIC_APIC_THRESHOLD,
  80. .name = "apic_threshold",
  81. .latency = 0
  82. },
  83. {
  84. .idx = HARDIRQ_EBPF_STATIC_APIC_ERROR,
  85. .name = "apic_error",
  86. .latency = 0
  87. },
  88. {
  89. .idx = HARDIRQ_EBPF_STATIC_APIC_DEFERRED_ERROR,
  90. .name = "apic_deferred_error",
  91. .latency = 0
  92. },
  93. {
  94. .idx = HARDIRQ_EBPF_STATIC_APIC_SPURIOUS,
  95. .name = "apic_spurious",
  96. .latency = 0
  97. },
  98. {
  99. .idx = HARDIRQ_EBPF_STATIC_FUNC_CALL,
  100. .name = "func_call",
  101. .latency = 0
  102. },
  103. {
  104. .idx = HARDIRQ_EBPF_STATIC_FUNC_CALL_SINGLE,
  105. .name = "func_call_single",
  106. .latency = 0
  107. },
  108. {
  109. .idx = HARDIRQ_EBPF_STATIC_RESCHEDULE,
  110. .name = "reschedule",
  111. .latency = 0
  112. },
  113. {
  114. .idx = HARDIRQ_EBPF_STATIC_LOCAL_TIMER,
  115. .name = "local_timer",
  116. .latency = 0
  117. },
  118. {
  119. .idx = HARDIRQ_EBPF_STATIC_IRQ_WORK,
  120. .name = "irq_work",
  121. .latency = 0
  122. },
  123. {
  124. .idx = HARDIRQ_EBPF_STATIC_X86_PLATFORM_IPI,
  125. .name = "x86_platform_ipi",
  126. .latency = 0
  127. },
  128. };
  129. // store for "published" data from the reader thread, which the collector
  130. // thread will write to netdata agent.
  131. static avl_tree_lock hardirq_pub;
  132. #ifdef LIBBPF_MAJOR_VERSION
  133. /**
  134. * Set hash table
  135. *
  136. * Set the values for maps according the value given by kernel.
  137. *
  138. * @param obj is the main structure for bpf objects.
  139. */
  140. static inline void ebpf_hardirq_set_hash_table(struct hardirq_bpf *obj)
  141. {
  142. hardirq_maps[HARDIRQ_MAP_LATENCY].map_fd = bpf_map__fd(obj->maps.tbl_hardirq);
  143. hardirq_maps[HARDIRQ_MAP_LATENCY_STATIC].map_fd = bpf_map__fd(obj->maps.tbl_hardirq_static);
  144. }
  145. /**
  146. * Load and Attach
  147. *
  148. * Load and attach bpf software.
  149. */
  150. static inline int ebpf_hardirq_load_and_attach(struct hardirq_bpf *obj)
  151. {
  152. int ret = hardirq_bpf__load(obj);
  153. if (ret) {
  154. return -1;
  155. }
  156. return hardirq_bpf__attach(obj);
  157. }
  158. #endif
  159. /*****************************************************************
  160. *
  161. * ARAL SECTION
  162. *
  163. *****************************************************************/
  164. // ARAL vectors used to speed up processing
  165. ARAL *ebpf_aral_hardirq = NULL;
  166. /**
  167. * eBPF hardirq Aral init
  168. *
  169. * Initiallize array allocator that will be used when integration with apps is enabled.
  170. */
  171. static inline void ebpf_hardirq_aral_init()
  172. {
  173. ebpf_aral_hardirq = ebpf_allocate_pid_aral(NETDATA_EBPF_HARDIRQ_ARAL_NAME, sizeof(hardirq_val_t));
  174. }
  175. /**
  176. * eBPF hardirq get
  177. *
  178. * Get a hardirq_val_t entry to be used with a specific IRQ.
  179. *
  180. * @return it returns the address on success.
  181. */
  182. hardirq_val_t *ebpf_hardirq_get(void)
  183. {
  184. hardirq_val_t *target = aral_mallocz(ebpf_aral_hardirq);
  185. memset(target, 0, sizeof(hardirq_val_t));
  186. return target;
  187. }
  188. /**
  189. * eBPF hardirq release
  190. *
  191. * @param stat Release a target after usage.
  192. */
  193. void ebpf_hardirq_release(hardirq_val_t *stat)
  194. {
  195. aral_freez(ebpf_aral_hardirq, stat);
  196. }
  197. /*****************************************************************
  198. *
  199. * EXIT FUNCTIONS
  200. *
  201. *****************************************************************/
  202. /**
  203. * Hardirq Exit
  204. *
  205. * Cancel child and exit.
  206. *
  207. * @param ptr thread data.
  208. */
  209. static void hardirq_exit(void *ptr)
  210. {
  211. ebpf_module_t *em = (ebpf_module_t *)ptr;
  212. if (em->objects)
  213. ebpf_unload_legacy_code(em->objects, em->probe_links);
  214. for (int i = 0; hardirq_tracepoints[i].class != NULL; i++) {
  215. ebpf_disable_tracepoint(&hardirq_tracepoints[i]);
  216. }
  217. pthread_mutex_lock(&ebpf_exit_cleanup);
  218. em->enabled = NETDATA_THREAD_EBPF_STOPPED;
  219. pthread_mutex_unlock(&ebpf_exit_cleanup);
  220. }
  221. /*****************************************************************
  222. * MAIN LOOP
  223. *****************************************************************/
  224. /**
  225. * Compare hard IRQ values.
  226. *
  227. * @param a `hardirq_val_t *`.
  228. * @param b `hardirq_val_t *`.
  229. *
  230. * @return 0 if a==b, 1 if a>b, -1 if a<b.
  231. */
  232. static int hardirq_val_cmp(void *a, void *b)
  233. {
  234. hardirq_val_t *ptr1 = a;
  235. hardirq_val_t *ptr2 = b;
  236. if (ptr1->irq > ptr2->irq) {
  237. return 1;
  238. }
  239. else if (ptr1->irq < ptr2->irq) {
  240. return -1;
  241. }
  242. else {
  243. return 0;
  244. }
  245. }
  246. /**
  247. * Parse interrupts
  248. *
  249. * Parse /proc/interrupts to get names used in metrics
  250. *
  251. * @param irq_name vector to store data.
  252. * @param irq irq value
  253. *
  254. * @return It returns 0 on success and -1 otherwise
  255. */
  256. static int hardirq_parse_interrupts(char *irq_name, int irq)
  257. {
  258. static procfile *ff = NULL;
  259. static int cpus = -1;
  260. if(unlikely(!ff)) {
  261. char filename[FILENAME_MAX + 1];
  262. snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/proc/interrupts");
  263. ff = procfile_open(filename, " \t:", PROCFILE_FLAG_DEFAULT);
  264. }
  265. if(unlikely(!ff))
  266. return -1;
  267. ff = procfile_readall(ff);
  268. if(unlikely(!ff))
  269. return -1; // we return 0, so that we will retry to open it next time
  270. size_t words = procfile_linewords(ff, 0);
  271. if(unlikely(cpus == -1)) {
  272. uint32_t w;
  273. cpus = 0;
  274. for(w = 0; w < words ; w++) {
  275. if(likely(strncmp(procfile_lineword(ff, 0, w), "CPU", 3) == 0))
  276. cpus++;
  277. }
  278. }
  279. size_t lines = procfile_lines(ff), l;
  280. if(unlikely(!lines)) {
  281. collector_error("Cannot read /proc/interrupts, zero lines reported.");
  282. return -1;
  283. }
  284. for(l = 1; l < lines ;l++) {
  285. words = procfile_linewords(ff, l);
  286. if(unlikely(!words)) continue;
  287. const char *id = procfile_lineword(ff, l, 0);
  288. if (!isdigit(id[0]))
  289. continue;
  290. int cmp = str2i(id);
  291. if (cmp != irq)
  292. continue;
  293. if(unlikely((uint32_t)(cpus + 2) < words)) {
  294. const char *name = procfile_lineword(ff, l, words - 1);
  295. // On some motherboards IRQ can have the same name, so we append IRQ id to differentiate.
  296. snprintfz(irq_name, NETDATA_HARDIRQ_NAME_LEN - 1, "%d_%s", irq, name);
  297. }
  298. }
  299. return 0;
  300. }
  301. /**
  302. * Read Latency MAP
  303. *
  304. * Read data from kernel ring to user ring.
  305. *
  306. * @param mapfd hash map id.
  307. *
  308. * @return it returns 0 on success and -1 otherwise
  309. */
  310. static int hardirq_read_latency_map(int mapfd)
  311. {
  312. static hardirq_ebpf_static_val_t *hardirq_ebpf_vals = NULL;
  313. if (!hardirq_ebpf_vals)
  314. hardirq_ebpf_vals = callocz(ebpf_nprocs + 1, sizeof(hardirq_ebpf_static_val_t));
  315. hardirq_ebpf_key_t key = {};
  316. hardirq_ebpf_key_t next_key = {};
  317. hardirq_val_t search_v = {};
  318. hardirq_val_t *v = NULL;
  319. while (bpf_map_get_next_key(mapfd, &key, &next_key) == 0) {
  320. // get val for this key.
  321. int test = bpf_map_lookup_elem(mapfd, &key, hardirq_ebpf_vals);
  322. if (unlikely(test < 0)) {
  323. key = next_key;
  324. continue;
  325. }
  326. // is this IRQ saved yet?
  327. //
  328. // if not, make a new one, mark it as unsaved for now, and continue; we
  329. // will insert it at the end after all of its values are correctly set,
  330. // so that we can safely publish it to the collector within a single,
  331. // short locked operation.
  332. //
  333. // otherwise simply continue; we will only update the latency, which
  334. // can be republished safely without a lock.
  335. //
  336. // NOTE: lock isn't strictly necessary for this initial search, as only
  337. // this thread does writing, but the AVL is using a read-write lock so
  338. // there is no congestion.
  339. bool v_is_new = false;
  340. search_v.irq = key.irq;
  341. v = (hardirq_val_t *)avl_search_lock(&hardirq_pub, (avl_t *)&search_v);
  342. if (unlikely(v == NULL)) {
  343. // latency/name can only be added reliably at a later time.
  344. // when they're added, only then will we AVL insert.
  345. v = ebpf_hardirq_get();
  346. v->irq = key.irq;
  347. v->dim_exists = false;
  348. v_is_new = true;
  349. }
  350. // note two things:
  351. // 1. we must add up latency value for this IRQ across all CPUs.
  352. // 2. the name is unfortunately *not* available on all CPU maps - only
  353. // a single map contains the name, so we must find it. we only need
  354. // to copy it though if the IRQ is new for us.
  355. uint64_t total_latency = 0;
  356. int i;
  357. for (i = 0; i < ebpf_nprocs; i++) {
  358. total_latency += hardirq_ebpf_vals[i].latency/1000;
  359. }
  360. // can now safely publish latency for existing IRQs.
  361. v->latency = total_latency;
  362. // can now safely publish new IRQ.
  363. if (v_is_new) {
  364. if (hardirq_parse_interrupts(v->name, v->irq)) {
  365. ebpf_hardirq_release(v);
  366. return -1;
  367. }
  368. avl_t *check = avl_insert_lock(&hardirq_pub, (avl_t *)v);
  369. if (check != (avl_t *)v) {
  370. netdata_log_error("Internal error, cannot insert the AVL tree.");
  371. }
  372. }
  373. key = next_key;
  374. }
  375. return 0;
  376. }
  377. static void hardirq_read_latency_static_map(int mapfd)
  378. {
  379. static hardirq_ebpf_static_val_t *hardirq_ebpf_static_vals = NULL;
  380. if (!hardirq_ebpf_static_vals)
  381. hardirq_ebpf_static_vals = callocz(ebpf_nprocs + 1, sizeof(hardirq_ebpf_static_val_t));
  382. uint32_t i;
  383. for (i = 0; i < HARDIRQ_EBPF_STATIC_END; i++) {
  384. uint32_t map_i = hardirq_static_vals[i].idx;
  385. int test = bpf_map_lookup_elem(mapfd, &map_i, hardirq_ebpf_static_vals);
  386. if (unlikely(test < 0)) {
  387. continue;
  388. }
  389. uint64_t total_latency = 0;
  390. int cpu_i;
  391. int end = (running_on_kernel < NETDATA_KERNEL_V4_15) ? 1 : ebpf_nprocs;
  392. for (cpu_i = 0; cpu_i < end; cpu_i++) {
  393. total_latency += hardirq_ebpf_static_vals[cpu_i].latency/1000;
  394. }
  395. hardirq_static_vals[i].latency = total_latency;
  396. }
  397. }
  398. /**
  399. * Read eBPF maps for hard IRQ.
  400. *
  401. * @return When it is not possible to parse /proc, it returns -1, on success it returns 0;
  402. */
  403. static int hardirq_reader()
  404. {
  405. if (hardirq_read_latency_map(hardirq_maps[HARDIRQ_MAP_LATENCY].map_fd))
  406. return -1;
  407. hardirq_read_latency_static_map(hardirq_maps[HARDIRQ_MAP_LATENCY_STATIC].map_fd);
  408. return 0;
  409. }
  410. static void hardirq_create_charts(int update_every)
  411. {
  412. ebpf_create_chart(
  413. NETDATA_EBPF_SYSTEM_GROUP,
  414. "hardirq_latency",
  415. "Hardware IRQ latency",
  416. EBPF_COMMON_DIMENSION_MILLISECONDS,
  417. "interrupts",
  418. NULL,
  419. NETDATA_EBPF_CHART_TYPE_STACKED,
  420. NETDATA_CHART_PRIO_HARDIRQ_LATENCY,
  421. NULL, NULL, 0, update_every,
  422. NETDATA_EBPF_MODULE_NAME_HARDIRQ
  423. );
  424. fflush(stdout);
  425. }
  426. static void hardirq_create_static_dims()
  427. {
  428. uint32_t i;
  429. for (i = 0; i < HARDIRQ_EBPF_STATIC_END; i++) {
  430. ebpf_write_global_dimension(
  431. hardirq_static_vals[i].name, hardirq_static_vals[i].name,
  432. ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX]
  433. );
  434. }
  435. }
  436. // callback for avl tree traversal on `hardirq_pub`.
  437. static int hardirq_write_dims(void *entry, void *data)
  438. {
  439. UNUSED(data);
  440. hardirq_val_t *v = entry;
  441. // IRQs get dynamically added in, so add the dimension if we haven't yet.
  442. if (!v->dim_exists) {
  443. ebpf_write_global_dimension(
  444. v->name, v->name,
  445. ebpf_algorithms[NETDATA_EBPF_INCREMENTAL_IDX]
  446. );
  447. v->dim_exists = true;
  448. }
  449. write_chart_dimension(v->name, v->latency);
  450. return 1;
  451. }
  452. static inline void hardirq_write_static_dims()
  453. {
  454. uint32_t i;
  455. for (i = 0; i < HARDIRQ_EBPF_STATIC_END; i++) {
  456. write_chart_dimension(
  457. hardirq_static_vals[i].name,
  458. hardirq_static_vals[i].latency
  459. );
  460. }
  461. }
  462. /**
  463. * Main loop for this collector.
  464. *
  465. * @param em the main thread structure.
  466. */
  467. static void hardirq_collector(ebpf_module_t *em)
  468. {
  469. memset(&hardirq_pub, 0, sizeof(hardirq_pub));
  470. avl_init_lock(&hardirq_pub, hardirq_val_cmp);
  471. ebpf_hardirq_aral_init();
  472. // create chart and static dims.
  473. pthread_mutex_lock(&lock);
  474. hardirq_create_charts(em->update_every);
  475. hardirq_create_static_dims();
  476. ebpf_update_stats(&plugin_statistics, em);
  477. ebpf_update_kernel_memory_with_vector(&plugin_statistics, em->maps);
  478. pthread_mutex_unlock(&lock);
  479. // loop and read from published data until ebpf plugin is closed.
  480. heartbeat_t hb;
  481. heartbeat_init(&hb);
  482. int update_every = em->update_every;
  483. int counter = update_every - 1;
  484. //This will be cancelled by its parent
  485. while (!ebpf_exit_plugin) {
  486. (void)heartbeat_next(&hb, USEC_PER_SEC);
  487. if (ebpf_exit_plugin || ++counter != update_every)
  488. continue;
  489. counter = 0;
  490. if (hardirq_reader())
  491. break;
  492. pthread_mutex_lock(&lock);
  493. // write dims now for all hitherto discovered IRQs.
  494. write_begin_chart(NETDATA_EBPF_SYSTEM_GROUP, "hardirq_latency");
  495. avl_traverse_lock(&hardirq_pub, hardirq_write_dims, NULL);
  496. hardirq_write_static_dims();
  497. write_end_chart();
  498. pthread_mutex_unlock(&lock);
  499. }
  500. }
  501. /*****************************************************************
  502. * EBPF HARDIRQ THREAD
  503. *****************************************************************/
  504. /*
  505. * Load BPF
  506. *
  507. * Load BPF files.
  508. *
  509. * @param em the structure with configuration
  510. *
  511. * @return It returns 0 on success and -1 otherwise.
  512. */
  513. static int ebpf_hardirq_load_bpf(ebpf_module_t *em)
  514. {
  515. int ret = 0;
  516. if (em->load & EBPF_LOAD_LEGACY) {
  517. em->probe_links = ebpf_load_program(ebpf_plugin_dir, em, running_on_kernel, isrh, &em->objects);
  518. if (!em->probe_links) {
  519. ret = -1;
  520. }
  521. }
  522. #ifdef LIBBPF_MAJOR_VERSION
  523. else {
  524. hardirq_bpf_obj = hardirq_bpf__open();
  525. if (!hardirq_bpf_obj)
  526. ret = -1;
  527. else {
  528. ret = ebpf_hardirq_load_and_attach(hardirq_bpf_obj);
  529. if (!ret)
  530. ebpf_hardirq_set_hash_table(hardirq_bpf_obj);
  531. }
  532. }
  533. #endif
  534. return ret;
  535. }
  536. /**
  537. * Hard IRQ latency thread.
  538. *
  539. * @param ptr a `ebpf_module_t *`.
  540. * @return always NULL.
  541. */
  542. void *ebpf_hardirq_thread(void *ptr)
  543. {
  544. netdata_thread_cleanup_push(hardirq_exit, ptr);
  545. ebpf_module_t *em = (ebpf_module_t *)ptr;
  546. em->maps = hardirq_maps;
  547. if (ebpf_enable_tracepoints(hardirq_tracepoints) == 0) {
  548. goto endhardirq;
  549. }
  550. #ifdef LIBBPF_MAJOR_VERSION
  551. ebpf_define_map_type(em->maps, em->maps_per_core, running_on_kernel);
  552. ebpf_adjust_thread_load(em, default_btf);
  553. #endif
  554. if (ebpf_hardirq_load_bpf(em)) {
  555. goto endhardirq;
  556. }
  557. hardirq_collector(em);
  558. endhardirq:
  559. ebpf_update_disabled_plugin_stats(em);
  560. netdata_thread_cleanup_pop(1);
  561. return NULL;
  562. }