I'm trying to export a per-cpu symbol "x86_cpu_to_logical_apicid" from kernel so that my kernel module can access it. In "arch/x86/kernel/apic/x2apic_cluster.c", I did
我正在尝试从内核导出per-cpu符号“x86_cpu_to_logical_apicid”,以便我的内核模块可以访问它。在“arch / x86 / kernel / apic / x2apic_cluster.c”中,我做到了
//static DEFINE_PER_CPU(u32, x86_cpu_to_logical_apicid);
DEFINE_PER_CPU(u32, x86_cpu_to_logical_apicid); //I remove static
EXPORT_PER_CPU_SYMBOL(x86_cpu_to_logical_apicid); // I add this
And after I recompile the kernel, the /proc/kallsyms shows
在我重新编译内核后,/ proc / kallsyms显示
0000000000011fc0 V x86_cpu_to_logical_apicid
0000000000012288 V x86_cpu_to_node_map
ffffffff8187df50 r __ksymtab_x86_cpu_to_apicid
Then I try to access the "x86_cpu_to_logical_apicid" in my kernel module, by using
然后我尝试通过使用来访问我的内核模块中的“x86_cpu_to_logical_apicid”
int apicid = per_cpu(x86_cpu_to_logical_apicid, 2)
However, when I loaded it, it fails to load it due to "Unknown symbol in module". The flag "V" means weak object, however I'm not sure whether this is the reason I fails to export the symbol. Can anyone give me some suggestions? Thank you!
但是,当我加载它时,由于“模块中的未知符号”,它无法加载它。标志“V”表示弱对象,但我不确定这是否是我无法导出符号的原因。谁能给我一些建议?谢谢!
1 个解决方案
#1
1
I realize that the OP perhaps is not interested in the answer anymore, but today I had a similar issue, and I thought it might help others as well.
我意识到OP可能不再对答案感兴趣,但今天我遇到了类似的问题,我认为它也可能对其他人有所帮助。
Before using an exported per_cpu variable in a module, you have to declare it first. For your case:
在模块中使用导出的per_cpu变量之前,必须先声明它。对于你的情况:
DECLARE_PER_CPU(u32, x86_cpu_to_logical_apicid);
Then you can use get_cpu_var and put_cpu_var to safely access the current processor's copy of the variable. You can read more here.
然后,您可以使用get_cpu_var和put_cpu_var安全地访问当前处理器的变量副本。你可以在这里阅读更多。
#1
1
I realize that the OP perhaps is not interested in the answer anymore, but today I had a similar issue, and I thought it might help others as well.
我意识到OP可能不再对答案感兴趣,但今天我遇到了类似的问题,我认为它也可能对其他人有所帮助。
Before using an exported per_cpu variable in a module, you have to declare it first. For your case:
在模块中使用导出的per_cpu变量之前,必须先声明它。对于你的情况:
DECLARE_PER_CPU(u32, x86_cpu_to_logical_apicid);
Then you can use get_cpu_var and put_cpu_var to safely access the current processor's copy of the variable. You can read more here.
然后,您可以使用get_cpu_var和put_cpu_var安全地访问当前处理器的变量副本。你可以在这里阅读更多。