LatSched Kernel Patch measures scheduler timing with fine granularity, and can be used as a powerful tool in software development.
A new character device, /dev/latsched (MAJOR = 10 - MINOR = 117), has been introduced to control the behavior and extract data from the kernel scheduler measurement code. This patch has the capacity to study process scheduling and migration between CPUs, in addition to measuring the scheduler latency.
To use the patch, a new kernel must be built with the patch applied, and the new character device /dev/latsched must be created using the command “# mknod /dev/latsched c 10 117”.
The code that will employ the LatSched patch should open the device using “if ((lsfd = open("/dev/latsched", O_RDWR)) == -1) { ... }”. Next, the sample (circular) buffer size must be set using “if ((res = ioctl(lsfd, LS_SAMPLES, samples))) { ... }”.
Finally, the code will have to instruct the sampler to start collecting scheduler timings using “if ((res = ioctl(lsfd, LS_START, 0))) { ... }”. To stop the sampling process, a new ioctl() call is necessary, which can be achieved through “if ((res = ioctl(lsfd, LS_STOP, 0))) { ... }”.
After these steps, the collected data is held inside the scheduler data buffers and must be fetched using something like this: “int cpu, ncpus, ii; struct lsctl_getdata lsgd; ncpus = sysconf(_SC_NPROCESSORS_CONF); memset(&lsgd, 0, sizeof(lsgd)); lsgd.size = samples; lsgd.data = (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++) { ... } }”.
In conclusion, LatSched Kernel Patch is an indispensable tool for fine-grained scheduler timing measurement, scheduler latency measurement, and studying the process scheduling and migration between CPUs. It requires a few simple steps to set up and is highly effective in its execution.
Version 2.5.0-0.3 / 2.5.1-pre11-0.5: N/A