且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在内核模块线程中进行上下文切换?

更新时间:2023-09-24 10:03:28

当前没有此类功能可用于切换上下文.但是,可以用不同的方式来实现相同的目的.我发现在内核中特定进程的上下文中执行任何操作的***方法是在进程上下文(wait_ *系列函数)中休眠并唤醒该线程并执行在该上下文中需要执行的任何操作.当然,这意味着您将必须通过IOCTL或其他方式将应用程序调用到内核中,并在该线程上休眠,并在需要执行任何操作时将其唤醒.这似乎是一种非常广泛使用和流行的机制.

There is no such function available currently to switch context. However, the same thing can be achieved in a different way. The best way i have found to do anything in the context of a particular process in the kernel, is to sleep in process context(wait_* family of functions) and wake up that thread and do whatever needs to be done in that context. This would ofcourse mean you would have to have the application call into the kernel via IOCTL or something and sleep on that thread and wake it up whenever you need to do something. This seems to be a very widely used and popular mechanism.