Skip to content

Commit a9a274f

Browse files
committed
Fix BPF tests on linux v6.8 by ensuring NSEC_PER_SEC is defined on 6.8 and later kernels
Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
1 parent 70d3a5c commit a9a274f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/stirling/bpf_tools/bcc_bpf/task_struct_utils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525

2626
#include <linux/sched.h>
2727

28+
// Between linux v6.1 and v6.8, NSEC_PER_SEC is no longer defined by including
29+
// linux/sched.h. This ifndef covers newer kernels that won't have it defined.
30+
// libbpf provides a trace_helpers.h header that provides NSEC_PER_SEC, so it seems
31+
// tools are moving towards defining their own instead of using a linux header for it.
32+
#ifndef NSEC_PER_SEC
33+
#define NSEC_PER_SEC 1000000000ULL
34+
#endif
35+
2836
#include "src/stirling/bpf_tools/bcc_bpf/utils.h"
2937

3038
// This is how Linux converts nanoseconds to clock ticks.

src/stirling/source_connectors/dynamic_tracer/dynamic_tracing/code_gen.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,11 @@ std::vector<std::string> GenIncludes() {
896896
return {
897897
// For struct task_struct.
898898
"#include <linux/sched.h>",
899+
// NSEC_PER_SEC is not defined within linux/sched.h for
900+
// 6.x kernels, so we define it here.
901+
"#ifndef NSEC_PER_SEC",
902+
"#define NSEC_PER_SEC 1000000000ULL",
903+
"#endif",
899904
};
900905
}
901906

0 commit comments

Comments
 (0)