[lttng-dev] Instrumenting a module?
Thibault, Daniel
Daniel.Thibault at drdc-rddc.gc.ca
Mon Feb 10 12:10:37 EST 2014
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 <linux/module.h> // included for all kernel modules
#include <linux/kernel.h> // included for KERN_INFO
#include <linux/init.h> // 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 <linux/module.h> // included for all kernel modules
#include <linux/kernel.h> // included for KERN_INFO
#include <linux/init.h> // included for __init and __exit macros
#include <trace/events/hello.h>
...
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 <http://www.travelgis.com/map.asp?addr=918V%20QSDJ>
Gouvernement du Canada | Government of Canada
<http://www.valcartier.drdc-rddc.gc.ca/>
More information about the lttng-dev
mailing list