简体   繁体   English

我可以在INSMOD或MODPROBE期间将参数传递给驱动程序吗?

[英]Can I pass parameter to driver during INSMOD or MODPROBE?

I currently worte a USB device driver in which I created a Kthread from probe() function. 我目前在一个USB设备驱动程序中使用probe()函数创建了一个Kthread。 The general kthread_create() function creates thread on the CPU which is least busy. 一般的kthread_create()函数在最不忙的CPU上创建线程。

What I want to do is create kthread on a particular CPU (kthread_create_on_cpu()), so that I can assign seperate core to device threads dealing with output devices. 我想要做的是在特定的CPU上创建kthread(kthread_create_on_cpu()),这样我就可以将单独的内核分配给处理输出设备的设备线程。
How can I pass the CPU number to module when the module/driver is being loaded. 如何在加载模块/驱动程序时将CPU编号传递给模块。

Either I can use a global variable which will be set once when the system boots up and will be read by drivers OR pass CPU number to module while it's being loaded. 我可以使用一个全局变量,它将在系统启动时设置一次,并由驱动程序读取或在加载时将CPU编号传递给模块。

Please suggest which method will be more feasible to use and implement. 请建议使用和实施哪种方法更可行。

Thanks and Regards, 谢谢并恭祝安康,
Mitesh G Mitesh G

You can pass command line arguments. 您可以传递命令行参数。 For this you have to add module_param or module_param_array in module. 为此,您必须在模块中添加module_parammodule_param_array

Add these lines in your modules of course according to your requirements 根据您的要求,在您的模块中添加这些行

int myintdata = 100; module_param(myintdata, int, 0);

char mychardata = 'A'; module_param(mychardata, char, 0);

int myarray[2]; module_param_array(myarray, int, NULL, 0);

static char *name; module_param(name, charp, 0); // here you have to mention charp as data type //这里你必须提到charp作为数据类型

or module_param_string(name, string, len, perm); module_param_string(name, string, len, perm); for String 对于String

while inserting modules 插入模块时

insmod module_name.ko myintdata=5 mychardata = 'X' name= "xyz" myarray =99,100 ` insmod module_name.ko myintdata=5 mychardata = 'X' name= "xyz" myarray =99,100

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

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