实现 include/sched.h 函数
我想研究如何将线程手动分配给多核计算机上的特定核心。我发现 include/sched.h 定义了一些可以帮助解决此问题的宏和函数(sched_setaffinity 等)。然而,这些函数是外部的,我找不到它们的定义。这些功能在任何地方都实现了吗?如果是,在哪里以及是否可以覆盖默认实现?如果不是,我该如何实施它们?
添加新的实现是否意味着我必须重新编译我的 Linux 内核?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
sched_setaffinity 的代码在内核中。头文件只是提供调用它的原型,满足它的库只是将调用转发给系统。
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.
检查 BFS 的代码,它应该向您展示如何实现您的自己的CPU调度器。
//edit yes 添加一个新的调度程序 impl 意味着您必须重新编译内核,但是您始终可以使用 qemu -kernel /path/to/new/kerenl -initrd Something 来测试它,以确保您的在真机上测试之前,代码不会立即崩溃。
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.