BPF perf event: runq length

Raga lahari


I am trying to write a BPF perf event program to get CPU runq length.  The Following is the code snippet. I am observing that a big integer (len is 2839296536 ) as queue length in trace output for some instances.

Can someone please let me know that  whether this approach helps to get length? 

struct cfs_rq_partial {

    struct load_weight load;

    unsigned long runnable_weight;

    unsigned int nr_running;

    unsigned int h_nr_running;


#define _(P) ({typeof(P) val = 0; bpf_probe_read(&val, sizeof(val), &P); val;}) 


int do_sample(struct bpf_perf_event_data *ctx)



        struct cfs_rq_partial *my_q = NULL;

        struct task_struct *task = NULL;

        unsigned int len;


        task = (struct task_struct *)bpf_get_current_task();

        my_q = _(task->se.cfs_rq);

        len = _(my_q->nr_running);

        bpf_printk("len is %u", len);




I have tested with another program and confirmed that cfs_rq has runnable_weight filed.


Join iovisor-dev@lists.iovisor.org to automatically receive all group messages.