smp_call_function 功能

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 看下输出. 


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值