I've been made some study in System Management Interrupts (SMI) using Linux. Looking into lwn.net, I found a module called "Hardware Latency Detector (formerly SMI detector)" written by Jon Masters a few years ago, as Jon says (http://lwn.net/Articles/337018/):

"This is a loadable module that grabs the CPU for configurable periods of time (all under stop_machine()) and samples the TSC looking for discontinuity. If observed latencies exceed a threshold (for example caused by an System Management Interrupt or similar) then the event is recorded in a global ring_buffer, readable via debugfs."

I modified the module to grab the TSC directly as you can see in the "get_sample" code below:

Running this code in kernel 2.6.37.6 (Slackware 13.37) there is a huge discontinuity, (diff = (s64)(tsc[1] - tsc[0])), about 25000 cycles, just when I run this code with a msleep_interruptible() in the kernel thread. When I remove it, the problem disappears. Moreover, the discontinuity appears always in the same time in the get_sample's while and never in the first execution of the kthread_fn's while. The kernel trace doesn't shows get_sample to be interrupted.

My question, is possible to some kernel code run inside stop_machine? In other words, why get_sample seems to be interrupted when I use a sleep?