如何在内核模块线程中进行上下文切换? [英] how to context switch in a kernel module thread?

查看:104
本文介绍了如何在内核模块线程中进行上下文切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道内核模块线程是否有办法切换其当前mm.内核线程通常使用在计划之前处于活动状态的最后一个mm.是否可以在内核线程中切换到特定的mm? 我正在寻找Windows中等同于KeStackAttachProcess的Linux. Context_switch()switch_mm()没有导出,所以我想知道我可以用什么来切换内核模块线程中的上下文.

I'm wondering if there is a way for a kernel module thread to switch its current mm. Kernel threads usually use the last mm that was active before it was scheduled. Is it possible to switch to a particular mm in a kernel thread? I'm looking for a linux equivalent to KeStackAttachProcess in windows. Context_switch() and switch_mm() are not exported so I'm wondering what I can use to switch context in my kernel module thread.

推荐答案

当前没有此类功能可用于切换上下文.但是,可以用不同的方式来实现相同的目的.我发现在内核中特定进程的上下文中执行任何操作的最佳方法是在进程上下文(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.

这篇关于如何在内核模块线程中进行上下文切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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