From: Daniel.Thibault@drdc-rddc.gc.ca (Thibault, Daniel)
Subject: [lttng-dev] Instrumenting a module?
Date: Mon, 10 Feb 2014 17:10:37 +0000 [thread overview]
Message-ID: <48CF5AC71E61DB46B70D0F388054EFFD267E3ED9@VAL-E-01.valcartier.drdc-rddc.gc.ca> (raw)
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/>
next reply other threads:[~2014-02-10 17:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-10 17:10 Thibault, Daniel [this message]
2014-02-11 16:45 Thibault, Daniel
2014-02-12 15:41 Thibault, Daniel
2014-02-12 17:55 Thibault, Daniel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48CF5AC71E61DB46B70D0F388054EFFD267E3ED9@VAL-E-01.valcartier.drdc-rddc.gc.ca \
--to=daniel.thibault@drdc-rddc.gc.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox