强制在Linux上从userland进行上下文切换? [英] Forcing a context switch from the userland on Linux?

查看:72
本文介绍了强制在Linux上从userland进行上下文切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以建议内核绕过调度程序逻辑立即执行上下文切换到其他线程?

例如,如果我刚刚用clone创建了一个线程/进程,并且我想立即开始执行,立即放弃当前上下文,而不是等待下一次内核重新安排时间.

For example, if I've just created a thread/process with clone and I want to begin its execution straight away, renouncing the current context immediately, instead of waiting for the next time the kernel reschedules stuff.

理想情况下,我正在寻找与Mach内核上的thread_switch调用相同的东西.

Ideally, I'm looking for something identical to the thread_switch call on the Mach kernel.

推荐答案

您不应该尝试控制上下文切换,因为内核在执行此操作时比您知道得多.特别是因为上下文切换被认为是一项昂贵的操作(主要是由于缓存失效).

You shouldn't be trying to control context switches, as the kernel probably knows much better than you when to do it. Specially since a context switch is considered a costly operation (due to cache invalidation, mostly).

但是,如果您确实需要强制调度程序周期,则可以使用

But, if you really need to force a scheduler cycle, you can use the sched_yield() system call.

这篇关于强制在Linux上从userland进行上下文切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆