The LatSched Kernel Patch 2.5.0-0.3 / 2.5.1-pre11-0.5

The LatSched Kernel Patch is a kernel patch that enables a fine grained scheduler timing measurement.
The LatSched Kernel Patch is a kernel patch that enables a fine grained scheduler timing measurement by using the kernel function get_cycles() that, on x86 cpu families, uses the rdtsc instruction to fetch the CPU cycle counter. A new character device /dev/latsched (MAJOR = 10 - MINOR = 117) has been introduced to control the behaviour and to fetch data from the kernel scheduler measure code. Other then measuring the scheduler latency this patch can be used to study process scheduling and migration between CPUs.

To use the patch a new kernel must be built (with the patch applied) and the new character device /dev/latsched must be created with :

# mknod /dev/latsched c 10 117

The code that will make use of the LatSched patch must open the device with :

if ((lsfd = open("/dev/latsched", O_RDWR)) == -1) {

The next step is to set the size of the sample ( circular ) buffer with :

if ((res = ioctl(lsfd, LS_SAMPLES, samples))) {

Then the code will have to instruct to sampler to start collecting scheduler timings with :

if ((res = ioctl(lsfd, LS_START, 0))) {

To stop the sampling process a new ioctl() call is necessary :

if ((res = ioctl(lsfd, LS_STOP, 0))) {

At this point collected data is held inside the scheduler data buffers and must be fetched with something like this :

int cpu, ncpus, ii;
struct lsctl_getdata lsgd;

ncpus = sysconf(_SC_NPROCESSORS_CONF);

memset(&lsgd, 0, sizeof(lsgd));
lsgd.size = samples; = (struct latsched_sample *) malloc(samples * sizeof(struct latsched_sample));

for (cpu = 0; cpu < ncpus; cpu++) {
lsgd.cpu = cpu;
lsgd.size = samples;

if ((res = ioctl(lsfd, LS_FETCH, &lsgd))) {

for (ii = 0; ii < lsgd.rsize; ii++) {

last updated on:
April 8th, 2008, 10:40 GMT
developed by:
LatSched Team
license type:
GPL (GNU General Public License) 
ROOT \ System \ Operating Systems \ Kernels


In a hurry? Add it to your Download Basket!

user rating 14



Add your review!