From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel.Thibault@drdc-rddc.gc.ca (Thibault, Daniel) Date: Mon, 10 Feb 2014 17:10:37 +0000 Subject: [lttng-dev] Instrumenting a module? Message-ID: <48CF5AC71E61DB46B70D0F388054EFFD267E3ED9@VAL-E-01.valcartier.drdc-rddc.gc.ca> I'm trying to find out the recipe for instrumenting a kernel module with some custom LTTng tracepoints. Oddly, writing the LTTng tracepoint provider kernel module turned out not too bad (the READMEs help), but I have seen no documentation of the process of instrumenting a module. Here is a simple module and its Makefile. The module works as expected, adding events to the dmesg kernel log buffer upon being loaded and unloaded. ###### hello.c ###### #include // included for all kernel modules #include // included for KERN_INFO #include // included for __init and __exit macros //Module meta-data MODULE_LICENSE("GPL"); MODULE_AUTHOR("Your name here"); MODULE_DESCRIPTION("A simple module"); //Module initialization static int __init hello_init(void) { printk(KERN_INFO "Hello!\n"); return 0; // Any other return value means the module couldn't be loaded. } //Module finalization static void __exit hello_cleanup(void) { printk(KERN_INFO "Cleaning up hello module.\n"); } //Identify the initialization and finalization handlers module_init(hello_init); module_exit(hello_cleanup); ###### Makefile ###### obj-m += hello.o all: @echo "~~~~~~Copying hello.h to linux-headers:" gksudo cp hello.h /usr/src/linux-headers-3.2.0-53/include/trace/events/hello.h @echo "~~~~~~Copying hello.h to lttng-modules/instrumentation/events/lttng-module:" sudo cp hello-module.h /usr/src/lttng-modules-2.3.0/instrumentation/events/lttng-module/hello.h @echo "~~~~~~Copying lttng-probe-hello.c to lttng-modules/probes:" sudo cp lttng-probe-hello.c /usr/src/lttng-modules-2.3.0/probes/lttng-probe-hello.c @echo "~~~~~~Making hello.ko:" make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean hello.h defines the tracepoints for my custom LTTng module (lttng-probe-hello). hello-module.h is hello.h "translated" for the lttng-module directory. lttng-probe-hello was added to the probes Makefile. lttng-modules makes and installs it just fine, and once I manually insmod lttng-probe-hello.ko, LTTng reports the new kernel tracepoints in 'lttng list -k'. I instrument hello.c by adding: ###### hello.c ###### #include // included for all kernel modules #include // included for KERN_INFO #include // included for __init and __exit macros #include ... static int __init hello_init(void) { trace_hello_init("Hello!"); printk(KERN_INFO "Hello!\n"); ... static void __exit hello_cleanup(void) { trace_hello_exit("Bye!"); printk(KERN_INFO "Cleaning up hello module.\n"); ... I get a couple of warnings when I make the instrumented hello module: WARNING: "__tracepoint_hello_exit" [/home/daniel/module/hello.ko] undefined! WARNING: "__tracepoint_hello_init" [/home/daniel/module/hello.ko] undefined! And hello.ko refuses to insmod as a consequence: $ sudo insmod hello.ko insmod: error inserting 'hello.ko': -1 Unknown symbol in module Assuming I got the LTTng tracepoint provider kernel module right, what am I doing wrong with the instrumented module? I suspect a missing define flag. Daniel U. Thibault Protection des syst?mes et contremesures (PSC) | Systems Protection & Countermeasures (SPC) Cyber s?curit? pour les missions essentielles (CME) | Mission Critical Cyber Security (MCCS) R & D pour la d?fense Canada - Valcartier (RDDC Valcartier) | Defence R&D Canada - Valcartier (DRDC Valcartier) 2459 route de la Bravoure Qu?bec QC? G3J 1X5 CANADA Vox?: (418) 844-4000 x4245 Fax?: (418) 844-4538 NAC?: 918V QSDJ Gouvernement du Canada?| Government of Canada