Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CPU usage of a kernel module

Tags:

linux

kernel

I need to know CPU usage of a particular kernel module (e.g., iptable_mangle) in Linux (Fedora). I know that top or mpstat shows system CPU usage which is actually total CPU usage in the kernel space. Is there any option to know CPU usage of a particular kernel object?

like image 884
Soumya Kanti Avatar asked May 01 '13 06:05

Soumya Kanti


1 Answers

Sorry to disappoint, but there is no way to accomplish what you want -- not because Linux doesn't have the capability, but by definition:

A module can "plug-in" to the kernel of two general ways: Either by installing a callback (e.g. proc or sys file, device, etc), or starting a kernel thread. In your case, iptable_mangle plugs in by setting callbacks on iptables/netfilter. This means the module code is executed as part of the network stack (in ksoftirqd context, to be more accurate).

If this had been in a kernel thread context, Linux keeps statistics. But for callbacks, that is not the case. The thread which does end up executing the module code does a lot of other things, so just isolating your module code is impractical (unless, of course, you're in possession of the source, and then you can add timing statements very easily).

One partial solution would be to use the kernel ftrace mechanism - this allows for function call tracing in the kernel - it's unbelievably powerful, and can show you statistics as per particular functions. It's not exactly what you want, but it's as close as you'll get.

like image 108
Technologeeks Avatar answered Sep 21 '22 06:09

Technologeeks