2

I am trying to make a custom bpf program with bpftrace in Linux, according to the book BPF Performance Tools. I tried to include some files from the path linux/kernel/sched/sched.h. How can I include them? (not only the /include folder but also from the linux/kernel/* folder in Linux?)

I'm trying to incorporate #include /kernel/sched/sched.h in order to use "struct rq".

The example of my program is:

#!/usr/local/bin/bpftrace

#include <kernel/sched/sched.h>

kprobe:load_balance
{
     $rq = (struct rq *)arg1;
     printf("-------------------\n");
     printf("\n");
     printf("load_balance: %s pid: %d\n", comm, pid);
     printf("-------------------\n");
}
pchaigno
  • 11,313
  • 2
  • 29
  • 54

1 Answers1

2

That header isn't exposed, so you'll have to copy the rq structure definition in your own program if you want to use it or any of its fields.

This sort of definition copies are already present in bpftrace's examples, for example for struct cfs_rq_partial.

pchaigno
  • 11,313
  • 2
  • 29
  • 54
  • Thank you! But is there a way to use the path '/kernel/sched/sched.h' in order to make use of the 'struct rq' inside the sched.h in my BPF program? – Panagiotis Papoulidis Apr 12 '20 at 15:50
  • Basically, I want to dynamically (kprobe) use the function (load_balance) and use all the arguments(arg0, arg1, arg2 ...) of this function. The prototype of this function is: static int load_balance(int this_cpu, struct *this_rq, struct sched_domain *sd, emum cpu_idle_type idle, int *continue_balancing) – Panagiotis Papoulidis Apr 12 '20 at 16:22
  • Ah, sorry. I read a bit too quickly there. I've updated my answer. – pchaigno Apr 12 '20 at 19:14