Skip to content

Commit

Permalink
Fix BPF tests on linux v6.8 by ensuring NSEC_PER_SEC is defined on 6.…
Browse files Browse the repository at this point in the history
…8 and later kernels

Signed-off-by: Dom Del Nano <[email protected]>
  • Loading branch information
ddelnano committed Aug 27, 2024
1 parent 70d3a5c commit a9a274f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/stirling/bpf_tools/bcc_bpf/task_struct_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@

#include <linux/sched.h>

// Between linux v6.1 and v6.8, NSEC_PER_SEC is no longer defined by including
// linux/sched.h. This ifndef covers newer kernels that won't have it defined.
// libbpf provides a trace_helpers.h header that provides NSEC_PER_SEC, so it seems
// tools are moving towards defining their own instead of using a linux header for it.
#ifndef NSEC_PER_SEC
#define NSEC_PER_SEC 1000000000ULL
#endif

#include "src/stirling/bpf_tools/bcc_bpf/utils.h"

// This is how Linux converts nanoseconds to clock ticks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,11 @@ std::vector<std::string> GenIncludes() {
return {
// For struct task_struct.
"#include <linux/sched.h>",
// NSEC_PER_SEC is not defined within linux/sched.h for
// 6.x kernels, so we define it here.
"#ifndef NSEC_PER_SEC",
"#define NSEC_PER_SEC 1000000000ULL",
"#endif",
};
}

Expand Down

0 comments on commit a9a274f

Please sign in to comment.