Linked Questions

Popular Questions

Why "__tracepoint_sched_switch" is undefined

Asked by At

I want to compile and load module from this answer https://stackoverflow.com/a/29526520/9609843 There was some errors: I included <linux/sched/clock.h> because it is needed by sched_clock and I passed parameter bool ignr after void* ignore because it is needed by (un)register_trace_sched_switch. So, now my code is compiling, but there is a warning from make:

WARNING: "__tracepoint_sched_switch" [/some_path/myclock.ko] undefined!

And when I try to insmod, there is an error:

insmod: ERROR: could not insert module myclock.ko: Unknown symbol in module

So, what I have to do to make this works?

UPD: whole code I have at this moment

#include <linux/sched/clock.h>
#include <linux/sched.h>
#include <linux/module.h>
#include <linux/printk.h>
#include <linux/types.h>
#include <linux/tracepoint.h>
#include <trace/events/sched.h>


MODULE_LICENSE("GPL");
MODULE_AUTHOR("somebody");


void my_sched_switch_probe(void* ignore, bool ignr, struct task_struct* prev, struct task_struct* next) {
    printk("my_sched_switch_probe: %s -> %s at %lu\n", prev->comm, next->comm,
    (unsigned long) sched_clock());
}


int cswtracer_init(void) {
    register_trace_sched_switch(my_sched_switch_probe, 0);
    return 0;
}


void cswtracer_fini(void) {
    unregister_trace_sched_switch(my_sched_switch_probe, 0);
}


module_init(cswtracer_init);
module_exit(cswtracer_fini);

UPD: seems __tracepoint_sched_switch is not exported to be used by other modules:

$ sudo cat /proc/kallsyms | grep __tracepoint_sched_switch
ffffffff91c123a0 D __tracepoint_sched_switch
$ cat /lib/modules/`uname -r`/build/Module.symvers | grep __tracepoint_sched_switch
$ (nothing was shown)

Maybe my Makefile is wrong and there is a way to use __tracepoint_sched_switch by using some option in Makefile? Here it is:

ifneq ($(KERNELRELEASE),)
    obj-m := myclock.o
else
    CURRENT = $(shell uname -r)
    KDIR = /lib/modules/$(CURRENT)/build
    PWD = $(shell pwd)
default:
    $(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
    rm *.o
    rm *.mod.c
    rm *.symvers
    rm *.order
    rm .cache.mk
    rm .*.*.cmd
    rm -r .tmp_versions
endif

Related Questions