0

I wanted to study how threads can be assigned manually to specific cores on a multi core machine. I found that include/sched.h defines some macros and functions (sched_setaffinity, etc.)that can help for this. However, the functions are extern'ed and I can't find their definitions. Are those functions implemented anywhere? If yes, where and is it possible to override the default implementation? If no, how can I implement them?

And would adding new implementation imply that I have to recompile my Linux kernel?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Aastha
  • 91
  • 8
  • Possibly duplicate: http://stackoverflow.com/questions/766395/how-does-sched-setaffinity-work - The implementation is here http://lxr.linux.no/linux+v2.6.36/kernel/sched.c#L4858 – jweyrich Dec 14 '10 at 19:20
  • sched_setaffinity() - try looking into that call, it is used in threading as well. – jim mcnamara Dec 14 '10 at 19:21

2 Answers2

0

Check the code for BFS which should show you how to implement your own CPU scheduler.

//edit yes adding a new scheduler impl means you have to recompile your kernel, however you can always just test it with qemu -kernel /path/to/new/kerenl -initrd something to make sure your code doesn't crash right away before testing it on the real machine.

OneOfOne
  • 95,033
  • 20
  • 184
  • 185
  • Testing in qemu only tests if the new code crashes, though. The host system scheduler will interfere with any timing measurements. You cannot get any form of proper performance metrics unless you try it out on a real machine. – thkala Dec 14 '10 at 19:27
  • Agreed, I meant for testing if his code doesn't crash, I didn't word it right. – OneOfOne Dec 14 '10 at 19:42
0

The code for sched_setaffinity is in the kernel. The header file just provides the prototype to call it, and the library which satisfies it just forwards the call to the system.

wallyk
  • 56,922
  • 16
  • 83
  • 148