1

I would like to be able to 'capture' an hrtimer interrupt with a linux kernel module and replay the interrupt at a later period in time. Any thoughts on how to go about doing this?

Use case: A program that calls sleep(1). My module will grab the hrtimer interrupt when it fires after 1 second, wait for 'x' amount of time, then re-fire the interrupt, waking the process.

Note: I do not want to hook the sleep system call.

Thanks!

Jereme Lamps
  • 159
  • 2
  • 9
  • I would argue that *everything* is possible. What I can't tell you is what it would take to do something like that without messing up the perception of time for the rest of the kernel. If you told us *why* you want to delay that program like that we might be able to help you more - maybe even with a userspace-only solution. – thkala Mar 20 '14 at 08:43
  • For clarification, say I only want to grab the hrtimer interrupt for a specific PID, so I will not mess up the perception of time for the entire kernel, but only the process with a specific PID. As for 'why', assume I have a process running where I know it calls sleep() frequently. I want to slow down its execution time, by increasing the amount of time it sleeps. – Jereme Lamps Mar 20 '14 at 16:58
  • Have you tried just overridding the `sleep()` C library functions with an LD_PRELOAD-ed library? – thkala Mar 20 '14 at 17:04

1 Answers1

0

Quite honestly, writing a Linux kernel module just to modify the behavior of sleep() for a single application sounds like overkill.

For most cases you should be able to use a preloadable shared object to intercept/override the sleep() function family with your own implementations. The application will call your implementation and your code may then call the real function with a modified parameter list.

This method is much simpler and less intrusive than anything involving kernel programming, although it will not work if your application is statically linked or if it uses direct system calls instead of library functions.

Community
  • 1
  • 1
thkala
  • 84,049
  • 23
  • 157
  • 201