stalking myspace commentshide myspace contact boxfree dark myspace layoutshacking a myspacesunset tan myspaceaustralian flag myspace layoutmyspace mobsters overdrivemyspace profile snatchermyspace and kelly lisascrollable myspace commentshappy birthday brother myspace commentsmyspace poem codescool myspace tweaks and layoutstomb raider myspace layoutmyspace sunset cliffs layoutjapanese myspace layoutmyspace hide comment boxpeace and love myspace layoutsvalentines layouts myspacemyspace over lapping text generatoremotional myspace layoutsquality myspace layoutshide song myspaceexclusive myspace layoutscop myspace graphicgangsta myspacemyspace comments funny picturesmyspace insultsouthern drive myspacefacebook mary ellen hausejay-z myspace layoutbulletins to post on myspacemyspace comments jailmyspace profile view trackermyspace romantic graphicssites to unblock myspacefacebook hottiemyspace mood codesmyspace paragraph codesneon myspace layoutmicrosoft frontpage to myspacefree myspace layout editormyspace dolphin layoutsdark love myspace layoutsmyspace usa ballroompassword recovery myspacescary graphics for myspacebulletin survey for myspacetim mcgraw myspace layoutspimp myspace pagecustom myspace bannersred bull myspace layoutbackground myspace backgroud xpmyspace hashladybug layouts for myspacemyspace picture creatersdefault myspace layout customdecorating myspace picturesvirtual myspace layoutshiding details section in myspacemyspace countried that i\'ve visitedhide comments code on myspacebackground layouts for myspacemyspace hello kitty graphicshide the details on myspaceamy taylor myspacemyspace slippagebulletin surveys for myspacecancer background myspace layoutsmyspace vampire graphicstrippy myspace backgroundsmyspace tea backgroundalyssa milano myspace pageballerina graphic myspacespiderman 3 myspace layouthappy new year myspace layoutmyspace layout megan foxhappy greetings myspace commentsamerican eagle layouts for myspaceorkut proxy sites facebookmyspace support our troops graphicsmyspace com adult r imyspace proxt sitemyspace samantha richmond kythanksgiving myspace layoutmark harmon myspacemyspace groups layoutsrock graphics for myspacegetting on myspace from schoolrebels man myspace layoutinvisible myspace countersnow myspace layoutmotorcross myspace layoutsfacebook open streamthe spirit myspace layout2.0 layouts for myspacemyspace friendship graphicsengagement graphics for myspacescrubs trivia facebook appfriendster and myspace hot layout

Anton Blanchard: Kernel hacker

Syndicate content
Just another WordPress weblog
Updated: 18 min 45 sec ago

Using perf, the Linux Performance Analysis tool on Ubuntu Karmic

Sun, 01/10/2010 - 08:57

A lot has been going on with Linux performance counters (now called performance events), but there is enough functionality in the 2.6.31 kernel that ships with Ubuntu karmic to be able to use some of the features available in perf. I recently found it useful when debugging a performance issue on my mythtv frontend.

To build perf, first install the dependencies:

sudo apt-get install libelf-dev binutils-dev

Then grab a recent kernel source tree and build perf:

wget http://www.kernel.org/pub/linux/kernel/v2.6/testing/linux-2.6.33-rc3.tar.bz2
tar xjf linux-2.6.33-rc3.tar.bz2
cd linux-2.6.33-rc3/tools/perf
make
make install

It will warn that libdwarf-dev is not installed, but the version in karmic is too old and regardless libdwarf is only required for event tracing that appeared in more recent kernels. perf installs into ~/bin/perf. You should then be able to use the top, stat, list, record, report and annotate options.

Linux Static Tracepoints

Tue, 10/06/2009 - 20:41

Linux has had dynamic trace functionality for a long time in the form of kprobes. Kprobes provides a kernel API for placing probes on kernel instructions and they can be exploited directly via a kernel module, or via systemtap which provides a high level scripting language. Dynamic tracing has a number of advantages – it has zero overhead when disabled and probes can be placed on almost any instruction in the kernel, not just where a kernel developer thinks you should.

All this flexibility does have some downsides. An executed kprobe has a significant overhead since it uses breakpoints and exception handlers. Having said that, there are patches that avoid the breakpoint and instead branch directly to the handler. Another issue is probe placement; kprobes are easily placed at function entry and exit but if you need to probe inside a function or probe local variables then you really need systemtap and a kernel compiled with CONFIG_DEBUG_INFO. On the other hand a static tracepoint can be placed anywhere in a function and can be passed any important local variables. Various static tracepoint patches have been available for Linux, but as of 2.6.32 a complete implementation is in mainline.

Adding a static tracepoint is very simple, an example can be found here. In this case I am adding to an existing trace group (irq), so I only need the tracepoint definitions and the tracepoints themselves. An explanation of the 5 parts of a tracepoint definition can be found in linux/samples/trace_events/trace-events-sample.h. For more complicated scenarios, refer to the files in linux/samples/trace_events/

Using static tracepoints

There are only a few steps to make use of static tracepoints. First ensure that debugfs is mounted. Most distros mount it on /sys/kernel/debug:

# mount | grep debugfs

debugfs on /sys/kernel/debug type debugfs (rw)

A list of available tracepoints can be found in tracing/available_events:

# cat /sys/kernel/debug/tracing/available_events

skb:skb_copy_datagram_iovec
skb:kfree_skb
block:block_rq_remap
block:block_remap
block:block_split
block:block_unplug_io
block:block_unplug_timer
...

Since we added our tracepoints to the irq group, we can find them in tracing/events/irq:

# ls /sys/kernel/debug/tracing/events/irq/

enable  irq_handler_entry  softirq_entry  tasklet_entry
filter  irq_handler_exit   softirq_exit   tasklet_exit

Enable the tasklet tracepoints:

# echo 1 >  /sys/kernel/debug/tracing/events/irq/tasklet_entry/enable
# echo 1 >  /sys/kernel/debug/tracing/events/irq/tasklet_exit/enable

And the output is available in the trace buffer:

# cat /sys/kernel/debug/tracing/trace

# tracer: nop
#
#           TASK-PID    CPU#    TIMESTAMP  FUNCTION
#              | |       |          |         |
-0     [000]   327.349213: tasklet_entry: func=.rpavscsi_task
-0     [000]   327.349217: tasklet_exit: func=.rpavscsi_task

When finished, we can disable the tracepoints. There are enable files at all levels of the hierarchy, so we can disable all tracepoints in one go:

# echo 0 > /sys/kernel/debug/tracing/events/enable

Using static tracepoints in kernel modules

Kernel modules can also make use of static tracepoints. A simple module that hooks the tasklet_entry tracepoint and printks the function name of the tasklet might look like (I’ve called it tracepoint-example.c):

#include <linux/module.h>
#include <trace/events/irq.h>

static void probe_tasklet_entry(struct tasklet_struct *t)
{
        printk("tasklet_entry %pf\n", t->func);
}

static int __init trace_init(void)
{
        WARN_ON(register_trace_tasklet_entry(probe_tasklet_entry));
        return 0;
}

static void __exit trace_exit(void)
{
        unregister_trace_tasklet_entry(probe_tasklet_entry);
}

module_init(trace_init)
module_exit(trace_exit)
MODULE_LICENSE("GPL");

If you are wondering, %pf is a printk formatter trick to pretty print a function name so you don’t have to go searching for the address in System.map.

Here is a Makefile to go with it:

obj-m := tracepoint-example.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules