简体   繁体   English

内核模块参数更改(使用/ sys / module)

[英]kernel module parameters changes (using /sys/module)

I have some questions concerning the /sys/module/ in linux 我对linux中的/sys/module/有一些疑问

  1. Does the /sys/module contain all modules of kernel /sys/module是否包含内核的所有模块

  2. Does the /sys/module/xxx/parameters contains all parameters of the kernel module xxxx /sys/module/xxx/parameters包含内核模块xxxx的所有参数

  3. Does the /sys/module/xxx/parameters/yyyy contain realtime values of the parameter yyyy of the kernel module xxxx /sys/module/xxx/parameters/yyyy包含内核模块xxxx的参数yyyy的实时值

  4. if a parameter is changed in a giving kernel module, how to detect this change in RealTime? 如果在给定内核模块中更改参数,如何在RealTime中检测此更改? I want to develop a C application (user space) or a shell script which detect the change of a giving kernel module parameter in real time. 我想开发一个C应用程序(用户空间)或shell脚本,它实时检测给定内核模块参数的变化。

1) Yes, /sys/module indeed has all the modules. 1)是的,/ sys / module确实拥有所有模块。

2) No, /sys/module/xxx/parameters only has the parameters the module wants to export, that is to say if you want to export some kernel module parameter from your module, you should use: 2)不,/ sys / module / xxx / parameters只有模块要导出的参数,也就是说如果你想从模块中导出一些内核模块参数,你应该使用:

module_param(test, bool, 0600);

where the last parameter is non-zero, which means the permission of the file "/sys/module/xxx/parameters/test". 其中最后一个参数是非零,这意味着文件“/ sys / module / xxx / parameters / test”的权限。

3) No, the value of the kernel module parameter is almost static, rarely changed by other places. 3)不,内核模块参数的值几乎是静态的,很少被其他地方改变。

4) Your kernel module shall notify the userspace application. 4)您的内核模块应通知用户空间应用程序。

Parameters are input values and not state values. 参数是输入值而不是状态值。 You can not change a parameter after the recipient of the parameter has started. 参数的收件人启动后,您无法更改参数。

If you want to change the behavior of the kernel at run time you have to use /proc/sys. 如果要在运行时更改内核的行为,则必须使用/ proc / sys。 See here: http://tournasdimitrios1.wordpress.com/2011/02/07/passing-parameters-to-the-kernel-at-run-time-time-on-linux/ 见这里: http//tournasdimitrios1.wordpress.com/2011/02/07/passing-parameters-to-the-kernel-at-run-time-time-on-linux/

"Finally (and this one's kind of important), if you choose to define writable parameters and really do write to them while your module is loaded, your module is not informed that the value has changed. That is, there is no callback or notification mechanism for modified parameters; the value will quietly change in your module while your code keeps running, oblivious to the fact that there's a new value in that variable. “最后(这一点很重要),如果您选择定义可写参数并且在加载模块时确实写入它们,则不会通知您的模块值已更改。即,没有回调或通知修改参数的机制;当代码保持运行时,值将在模块中悄然发生变化,忽略了该变量中有新值的事实。

If you truly need write access to your module and some sort of notification mechanism, you probably don't want to use parameters. 如果您确实需要对模块的写访问权以及某种通知机制,则可能不希望使用参数。 There are better ways to get that functionality." [1] 有更好的方法来获得这种功能。“[1]

Basically, you'll need a mechanism to constantly poll for changes or you should just develop an IOCtl approach and register your device as a char device simultaneous to whatever else you are registering it as (Linux is psychotic in that respect). 基本上,您需要一种机制来不断轮询更改,或者您应该开发一种IOCtl方法,并将您的设备注册为char设备,同时将其注册为其他任何内容(Linux在这方面是精神病的)。

Bryan Wilcutt "Linux is free if you don't value your own time." Bryan Wilcutt“如果你不重视自己的时间,Linux就是免费的。” -- Unknown - 未知

[1] https://www.linux.com/learn/linux-training/28065-the-kernel-newbie-corner-everything-you-wanted-to-know-about-module-parameters [1] https://www.linux.com/learn/linux-training/28065-the-kernel-newbie-corner-everything-you-wanted-to-know-about-module-parameters

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM