本文主要是介绍smp_call_function 功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
转自:
http://blog.csdn.net/zhangxx0811/article/details/8479969
crash_kexec -> machine_crash_shutdown -> smp_call_function(machine_crash_nonpanic_core, NULL, false);
当一个CPU crash 后,通知其他CPU stop doing anything useful.
void machine_crash_nonpanic_core(void *unused)
{
struct pt_regs regs;
crash_setup_regs(®s, NULL);
printk(KERN_DEBUG "CPU %u will stop doing anything useful since another CPU has crashed\n",
smp_processor_id());
crash_save_cpu(®s, smp_processor_id());
flush_cache_all();
atomic_dec(&waiting_for_crash_ipi);
while (1)
cpu_relax();
}
int smp_call_function(smp_call_func_t func, void *info, int wait);
在 smp机器上,除了正在调用smp_call_function之外的所有核调用 func .
例子.
#include <linux/kernel.h>
#include <linux/module.h>
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include<linux/modversions.h>
#endif
#include <asm/uaccess.h>
#include <linux/ctype.h>
#include <linux/smp.h>
int print_id(int cpuid)
{
int cpu=smp_processor_id();
// if(cpuid==smp_processor_id())
{
printk("myid %d\n",cpu);
}
return 0;
}
MODULE_LICENSE("GPL");
int init_module()
{
//printk("hello.word-this is the kernel speaking\n");
int cpu=0;
if(cpu==smp_processor_id())
{
printk("myid is %d\n",0);
}
else
{
smp_call_function(print_id,&cpu,1);
}
return 0;
}
void cleanup_module()
{
int cpu=0;
printk("Short is the life of a kernel module\n");
if(cpu==smp_processor_id())
{
printk("myid is %d\n",0);
}
else
{
smp_call_function(print_id,&cpu,1);
}
}
代码就这些
看下 makefile
obj-m := smptest_module.o
smptest_module-objs := test_printk.o
---------------------------------------------------------------------------------------------
make -C /usr/src/kernels/3.6.10-2.fc16.x86_64/ M=`pwd` modules
然后安装模块
sudo insmod smptest_module.ko
dmesg 看下输出.
这篇关于smp_call_function 功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!