zoukankan      html  css  js  c++  java
  • smp_call_function功能

    http://blog.csdn.net/zhangxx0811/article/details/8479969


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


  • 相关阅读:
    GLUT Tutorials 9: GLUT子菜单
    GLUT Tutorials 8: GLUT菜单
    GLUT Tutorials 9: GLUT鼠标
    GLUT Tutorials 8: GLUT高级键盘控制
    GLUT Tutorials 7: GLUT高级键盘控制
    GLUT Tutorials 6: GLUT场景漫游
    gif 录制小工具
    GLUT Tutorials 5: GLUT键盘控制
    java 传址或传值
    java中如何将byte[]里面的数据转换成16进制字符串
  • 原文地址:https://www.cnblogs.com/mull/p/4477845.html
Copyright © 2011-2022 走看看