ITKeyword,专注技术干货聚合推荐

注册 | 登录

解决c - kernel module parameters changes (using /sys/module)

itPublisher 分享于

2020腾讯云双十一活动,全年最低!!!(领取3500元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1073

【阿里云】双十一活动,全年抄底价,限时3天!(老用户也有),
入口地址https://www.aliyun.com/1111/home

推荐:Linux kernel & module program

Linux内核/模块开发常见问题集(FAQ)(转载) 1. 请推荐一些好的Linux内核参考书? a.《Linux Device Drivers, 2nd Edition》,有中文译本   b.《Understanding the

I have some questions concerning the /sys/module/ in linux

1) Does the /sys/module contain all modules of kernel

2) Does the /sys/module/xxx/parameters contains all parameters of the kernel module xxxx

3) Does the /sys/module/xxx/parameters/yyyy contain realtime values of the parameter yyyy of the kernel module xxxx

4) if a parameter is changed in a giving kernel module, how to detect this change in 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 linux linux-kernel kernel-module
|
  this question
edited Jun 14 '12 at 14:28 asked Jun 14 '12 at 10:52 MOHAMED 16.4k 22 81 144      Parameters are input values and not state values. You can not change a parameter after the recipient of the parameter has started. –  ceving Jun 14 '12 at 15:42      @ceving so all parameters in the /sys/module/xxx/parameters folder are only ibput parameters ? So they could not be modified by the module in the running time ? there is no state parameters in thoses parameters? –  MOHAMED Jun 14 '12 at 16:24 1   If you want to change the behavior of the kernel at run time you have to use /proc/sys. See here: tournasdimitrios1.wordpress.com/2011/02/07/… –  ceving Jun 15 '12 at 8:18      good link. Thanks. Does the kernel send a signal to the user space if a parameter is changed by the kernel? This is useful because it will allow to detect the change of a parameter by the kernel in real time –  MOHAMED Jun 15 '12 at 9:27

 | 

3 Answers
3

1) Yes, /sys/module indeed has all the modules.

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:

module_param(test, bool, 0600);

where the last parameter is non-zero, which means the permission of the file "/sys/module/xxx/parameters/test".

3) No, the value of the kernel module parameter is almost static, rarely changed by other places.

4) Your kernel module shall notify the userspace application.

推荐:The Linux Kernel Module Programming Guide

原文地址:http://tldp.org/LDP/lkmpg/2.6/html/   Table of Contents Foreword 1. Authorship 2. Versioning and Notes 3. Acknowledgements 1. Introduction 1


|
  this answer
answered Nov 13 '12 at 6:02 Cong Wang 1,533 7 10

 |  解决方法

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. See here: http://tournasdimitrios1.wordpress.com/2011/02/07/passing-parameters-to-the-kernel-at-run-time-time-on-linux/


|
  this answer
answered Nov 7 '12 at 8:26 MOHAMED 16.4k 22 81 144 3   Then.. how does the following work: writing (0/N/n=disable) to /sys/module/printk/parameters/time will stop giving the timestamp, which looks like this -> [ 1915.150953]. Then writing 1/Y/y=enable will enable it back. All this during runtime. HOW ?? –  user2327702 Oct 19 '13 at 8:51

 | 

"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]

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).

Bryan Wilcutt "Linux is free if you don't value your own time." -- Unknown

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


|
  this answer
edited Nov 24 '15 at 19:44 answered Nov 11 '15 at 16:22 Bryan Wilcutt 24 6

 | 

推荐:Linux Debugging 8 - Kernel Module

refer to http://tldp.org/LDP/lkmpg/2.6/html/   The Linux Kernel Module Programming Guide    


相关阅读排行


相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。