Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kernel module parameters changes (using /sys/module)

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.

like image 318
MOHAMED Avatar asked Jun 14 '12 10:06

MOHAMED


People also ask

What is the difference between insmod and modprobe?

insmod is similar to modprobe: it can insert a module into the Linux kernel. Unlike modprobe, however, insmod does not read its modules from a set location, automatically insert them, and manage any dependencies. insmod can insert a single module from any location, and does not consider dependencies when doing so.

What are the parameters of kernel?

The kernel parameter sem consists of four tokens, SEMMSL, SEMMNS, SEMOPM, and SEMMNI. SEMMNS is the result of SEMMSL multiplied by SEMMNI. The database manager requires that the number of arrays (SEMMNI) be increased as necessary.

What is SYS module in Linux?

This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It is always available.


3 Answers

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.

like image 149
Cong Wang Avatar answered Sep 24 '22 12:09

Cong Wang


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/

like image 33
MOHAMED Avatar answered Sep 26 '22 12:09

MOHAMED


"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

like image 40
Bryan Wilcutt Avatar answered Sep 26 '22 12:09

Bryan Wilcutt