Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1477145
  • 博文数量: 108
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 997
  • 用 户 组: 普通用户
  • 注册时间: 2013-06-29 09:58
个人简介

兴趣是坚持一件事永不衰竭的动力

文章分类

全部博文(108)

文章存档

2021年(1)

2020年(10)

2019年(19)

2018年(9)

2016年(23)

2015年(43)

2013年(3)

我的朋友

分类: LINUX

2020-07-04 19:55:26

set_cpus_allowed_ptr(task0, cpumask_of(0));
---------------------------

点击(此处)折叠或打开

  1. #include<linux/kernel.h>
  2. #include<linux/module.h>
  3. #include<linux/kthread.h>

  4. struct task_struct *task0;
  5. static spinlock_t spinlock;
  6. int val;

  7. int task(void *arg)
  8. {
  9.     printk(KERN_INFO "%s:%d\n",__func__,__LINE__);
  10.     /* To generate panic uncomment following */
  11.     /* panic("softlockup: hung tasks"); */

  12.     while(!kthread_should_stop()) {
  13.         printk(KERN_INFO "%s:%d\n",__func__,__LINE__);
  14.         spin_lock(&spinlock);
  15.         /* busy loop in critical section */
  16.         while(1) {
  17.             printk(KERN_INFO "%s:%d\n",__func__,__LINE__);
  18.         }

  19.         spin_unlock(&spinlock);
  20.     }

  21.     return val;
  22. }

  23. static int softlockup_init(void)
  24. {
  25.     printk(KERN_INFO "%s:%d\n",__func__,__LINE__);

  26.     val = 1;
  27.     spin_lock_init(&spinlock);
  28.     task0 = kthread_run(&task,(void *)val,"softlockup_thread");
  29.     set_cpus_allowed_ptr(task0, cpumask_of(0));

  30.     return 0;
  31. }

  32. static void softlockup_exit(void)
  33. {
  34.     printk(KERN_INFO "%s:%d\n",__func__,__LINE__);
  35.     kthread_stop(task0);
  36. }

  37. module_init(softlockup_init);
  38. module_exit(softlockup_exit)

阅读(6267) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~