Using Markers

What are markers?

Here is some text taken from the kernel documentation that describes markers:

What do markers in kernel code look like?

#include <linux/marker.h>
//...
int kfunc(int mask)
{
        int rc = 0;        // return code
        trace_mark(kfunc_entry, "mask %d", mask);

        //... bulk of kfunc() here...

        trace_mark(kfunc_exit, "rc %d", rc);
        return(rc);
}

This function (named 'kfunc'), has 2 markers present in it. The first one has a subsystem_event of "kfunc_entry" and the second marker has a subsystem_event of "kfunc_exit". The kernel documentation suggests treating the first argument of trace_mark as having 2 parts: a 'subsystem' and an 'event'. In our example, the name of the function is used as the subsystem, and 'entry' and 'exit' are used as the events. As you can see, the second argument to trace_mark() is a format string (similar to one used by printk()), and the rest of the arguments depend on the format string.

How do I turn on marker support in my kernel?

The marker subsystem and the kernel markers themselves must be compiled into your kernel. Initial marker support is present in 2.6.24, but at this time you must also add 3 patches from the -mm tree to get full marker functionality.

linux-kernel-markers-create-modpost-file.patch: adds support for multiple probes per markers.

linux-kernel-markers-support-multiple-probes-update.patch: updates the previous patch.

linux-kernel-markers-support-multiple-probes.patch: adds support for creating a file called Module.markers which lists all markers present in a kernel and its modules (similar to the Module.symvers file).

After those patches have been applied to your kernel source, when running "make menuconfig", besides the normal options needed by systemtap, you'll also need to enable markers.

Instrumentation Support  --->
    [*] Activate markers

Selecting this option turns on the CONFIG_MAKERS define.

How do I use markers in systemtap?

To hook up a systemtap probe to a kernel marker, your systemtap script would look like this:

probe kernel.mark("kfunc_entry") { print("kfunc_entry marker hit\n") }
probe kernel.mark("kfunc_exit") { print("kfunc_exit marker hit\n") }