0

I have timer created with a function timer_create(CLOCK_REALTIME, &events, &timer), where timer is a unique per process timer ID (according to man).

Now there is sched_setaffinity function to set affinity for a given PID.

How can I set affinity for my timer? Not the whole program, but only the timer thread. I am not sure that timer ID is the same thing as PID.

zupazt3
  • 966
  • 9
  • 30
  • 1
    does anyone read documentation any more? see here: https://linux.die.net/man/2/timer_create note the option SIGEV_THREAD_ID – Richard Hodges Mar 21 '17 at 17:02

1 Answers1

0

Ok, I got the answer.

One way to do this is like that:

  1. Create a new thread using pthread.
  2. Set affinity for this new thread.
  3. In the entry routine of the new thread, initialize the timer (create and set). We can use SIGEV_THREAD as it is convenient to use.
  4. The POSIX timer thread, as well as threads created when the timer overflows, will inherit affinity from our thread created in step 1.
  5. Join the thread from step 1 with the main thread. This thread will cease to exist, but its child thread (timer) will persist.
zupazt3
  • 966
  • 9
  • 30