BUG: scheduling while atomic: swapper/0/0/0x00010000

出现此错误的原因是: 在中断上下文中不能进行进程的调度。

下面用一个例子验证下:
在我们的按键中断中调用了信号量的 down方法,由于down会引起当前进程休眠,所以会报错。

#include <linux/uaccess.h>
#include <linux/fs.h>
#include <linux/stat.h>
#include <linux/cdev.h>
#include <linux/io.h>
#include <linux/gpio.h>
#include <linux/interrupt.h>
#include <linux/init.h> /* Needed for the macros */
#include <linux/kernel.h> /* Needed for pr_info() */
#include <linux/module.h> /* Needed by all modules */#include <linux/gpio/driver.h>#include <linux/platform_device.h>#include <linux/slab.h>//void* kmalloc(size_t size, int flags);//sudo mknod /dev/mycdev001 c  403 0/*** make* make scp** test ok on tinkerboard.** need to get major number from /proc/devices** sudo mknod /dev/mydev1012 c 238 0****sudo cat /proc/iomemff720000-ff7200ff : /pinctrl/gpio0@ff720000ff730000-ff7300ff : /pinctrl/gpio1@ff730000ff780000-ff7800ff : /pinctrl/gpio2@ff780000ff788000-ff7880ff : /pinctrl/gpio3@ff788000ff790000-ff7900ff : /pinctrl/gpio4@ff790000RK3399 has 5 groups of GPIO banks: GPIO0~GPIO4, and each group is distinguished by numbers A0~A7, B0~B7, C0~C7, D0~D7.地址:GPIO0 : FF72_0000GPIO1 : FF73_0000GPIO2 : FF78_0000GPIO3 : FF78_8000GPIO4 : FF79_0000OffsetGPIO_SWPORTA_DR  : 0x0000GPIO_SWPORTA_DDR : 0x0004GPIO_1_A7Interrupts :46       gpio0_int47       gpio1_int48       gpio2_intr49       gpio3_intr50       gpio4_intrWhenever Port A is configured for interrupts, the data direction must be set to Inputunsigned long probe_irq_on(void);int probe_irq_off(unsigned long);show_interrupts()**///#define MY_MAJOR       499
#define GPIO_1_BASE  0xFF730000
#define  GPIO1_SWPORTA_DR GPIO_1_BASE
#define  GPIO1_SWPORTA_DDR  0xFF730004#define  GPIO_INTEN   (GPIO_1_BASE + 0x0030)
//CPU number
#define  GPIO_PIN  39#define LOCATION  7//#define GPIO_1_A7  0x1//#define  DIRECTION_OUT 255
//
//#define  LED1_ON    255#define MY_MAX_MINORS  3
#define   DEVICE_NAME  "device name 499"DEFINE_SEMAPHORE(mysema);struct my_device_data {struct cdev cdev;char *desc;char *content;
};/***  cat /sys/module/a2/parameters/name*///module_param(name, charp, S_IRUGO);struct my_device_data devs[MY_MAX_MINORS];irqreturn_t key_handler(int irq, void *dev_id) {pr_err("key_handler \n");down(&mysema);return IRQ_HANDLED;
}
char *ff;
static int my_open(struct inode *inode, struct file *file) {struct my_device_data *p;// pr_err(" data %d \n",d);
//  pr_err(" data 1 or 0 ? : %d \n",(d & (GPIO_1_A7 << LOCATION)) >> LOCATION);pr_info("a3 my_open  1330 \n");//    writel(readl(data) | (GPIO_1_A7 << LOCATION), data);//    switch(MINOR(inode->i_cdev)){//  default :
//      file->private_data =
//
//  }p = container_of(inode->i_cdev, struct my_device_data, cdev);p->desc = "my dec 789";file->private_data = p;//    p->content = (char*) kmalloc(1024, GFP_KERNEL);
//  memcpy(p->content,
//          "The kmalloc allocation engine is a powerful tool and easily learned because of its similarity to malloc. "
//                  "The function is fast (unless it blocks) and doesn’t clear the memory it obtains; the allocated region still holds its previous content.[1] "
//                  "The allocated region is also contiguous in physical memory",
//          1024);
//
//  pr_err("content: %s\n", p->content);return 0;
}static unsigned char mem[100];unsigned int num;static ssize_t my_write(struct file *filp, const char __user *user_buffer,size_t size, loff_t *offset) {size_t my_size = 100;ssize_t len = min(my_size - (ssize_t )*offset, size);pr_info("a3 my_write\n");pr_info("write");if (len <= 0)return 0;
///* read data from user buffer to my_data->buffer */if (copy_from_user(mem + *offset, user_buffer, len))return -EFAULT;*offset += len;pr_info("r: %s", mem);return len;
}static ssize_t my_read(struct file *filp, char __user *buffer, size_t count,loff_t *offset) {int p = *offset;uint8_t *data = "haha,1012\n";size_t datalen = strlen(data);struct my_device_data *device_data = filp->private_data;pr_info("desc: %s\n", device_data->desc);if (p > datalen) {return 0;}if (count > datalen - p) {count = datalen - p;}if (copy_to_user(buffer, data + *offset, count)) {return -EFAULT;}*offset += count;return count;
}int my_close(struct inode *inode, struct file *file) {pr_info("a3 my_close\n");return 0;
}const struct file_operations my_fops = { .owner = THIS_MODULE, .open = my_open,.read = my_read, .write = my_write, .release = my_close,};static dev_t mydev;static __init int my_init(void) {int ret,i,err;unsigned int __iomem *direction = ioremap(GPIO1_SWPORTA_DDR, 4);unsigned int a = readl(direction);unsigned int __iomem *irq = ioremap(GPIO_INTEN, 4);// set direction inwritel(readl(direction) & (~(1 << LOCATION)), direction);//just checka = readl(direction);pr_err("direction: %d \n", a);pr_err("direction 1 or 0  ? : %d \n", (a & (1 << LOCATION)) >> LOCATION);// enable Interruptwritel(readl(irq) | (1 << LOCATION), irq);pr_err("Interrupt 1 or 0  ? : %d \n",(readl(irq) & (1 << LOCATION)) >> LOCATION);num = gpio_to_irq(GPIO_PIN);pr_info("irq_num:%d\n",num);ret = request_irq(num, key_handler, IRQF_TRIGGER_FALLING,"my_key_driver", NULL);if (ret < 0) {pr_err("request_irq  failed \n");return ret;}pr_info("a3 init_module\n");err = alloc_chrdev_region(&mydev, 0, MY_MAX_MINORS, DEVICE_NAME);if (err != 0) {return err;}for (i = 0; i < MY_MAX_MINORS; i++) {/* initialize devs[i] fields */cdev_init(&devs[i].cdev, &my_fops);cdev_add(&devs[i].cdev, MKDEV(MAJOR(mydev), i)
, 1);}return 0;
}static void __exit my_exit(void) {int i;free_irq(num, NULL);pr_info("a3 cleanup_module\n");for (i = 0; i < MY_MAX_MINORS; i++) {/* release devs[i] fields */cdev_del(&devs[i].cdev);}unregister_chrdev_region(mydev, MY_MAX_MINORS);
}module_init(my_init);
module_exit(my_exit);MODULE_LICENSE("GPL");
MODULE_AUTHOR("Andy");
MODULE_DESCRIPTION("andy one-key driver");
MODULE_ALIAS("one-key");

第129行调用了down方法,导致了此错误的出现。

另外 互斥量也不能使用在中断上下文中。

msleep ssleep 睡眠函数也不行。
mdelay udelay可以使用。

BUG: scheduling while atomic: swapper/0/0/0x00010000相关推荐

  1. 【Linux】【Kernel】BUG: scheduling while atomic问题分析

    内核模块local_clients用于监听DHCP包,并把主机名字,IP,MAC等信息写到文件/proc/local_clients/local_clients_info,然后webserver解析这 ...

  2. [Kernel_exception6] BUG: scheduling while atomic

    一.实际问题: 1.开机出现原子上下文调度的bug: [ 6.290494] <1>.(1)[285:init]BUG: scheduling while atomic: init/285 ...

  3. [crash分析]“Kernel panic - not syncing: Aiee, killing interrupt handler”“BUG: scheduling while atomic“

    crash的直接提示信息"Kernel panic - not syncing: Aiee, killing interrupt handler!",不太常见.crash栈也没太多 ...

  4. BUG: scheduling while atomic 分析 and 为什么中断不能睡眠

    遇到一个BUG: scheduling while atomic: kworker/0:2/370/0x00000002:看了这篇文章BUG: scheduling while atomic 分析,是 ...

  5. redis client 2.0.0 pipeline 的list的rpop bug

    描写叙述: redis client 2.0.0 pipeline 的list的rpop 存在严重bug,rpop list的时候,假设list已经为空的时候,rpop出来的Response依旧不为n ...

  6. pip 10.0.0 BUG 解决方案Traceback (most recent call last): File /usr/bin/pip3, line 9, in module...

    使用pip3 出现以下错误: Traceback (most recent call last): File "/usr/bin/pip3", line 9, in from pi ...

  7. nacos2.0.0版本bug记录一下

    开头 之前个人在使用nacos 2.0.0版本作为注册中心时,发现在nacos客户端查询注册成功且非default_group组的服务时会响应500. 刚开始我还以为是我项目有配置错误,后来检查本地配 ...

  8. MariaDB: ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111 Connection refused)

    MariaDB : ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111 "Connection ref ...

  9. 开源一年,阿里轻量级AI推理引擎MNN 1.0.0正式发布

    在经过充分的行业调研后,阿里淘系技术部认为当时的推理引擎如TFLite不足以满足手机淘宝这样一个亿级用户与日活的超级App. 于是,他们从零开始自己搭建了属于阿里巴巴的推理引擎MNN.1年前,MNN在 ...

最新文章

  1. 小程序 url 对象转字符串编码传参 url 字符串转对象解码接收参数
  2. SAP RETAIL 通过自动补货功能触发的采购申请有些啥特殊的地方?
  3. 关于libnmap 的一些应用
  4. oracle 日结 数据量大,如何对一个oracle11gsql语
  5. 从零开始入门 K8s | Kubernetes API 编程范式
  6. 计算机二级高级应用这么难,计算机二级考试越来越难的实锤!真实数据告诉你到底难在哪里?...
  7. 目前微型计算机中常用的鼠标器有什么两类,2009年计算机一级考试真题及答案...
  8. 计划任务中使用NT AUTHORITY\SYSTEM用户和普通管理员用户有什么差别
  9. sas 服务器版安装文件,安装SAS怎样配置服务器
  10. ic卡c语言程序,sle4442程序(ic卡程序,C语 - 控制/MCU - 电子发烧友网
  11. 基于java的客户关系管理系统
  12. 支持向量回归(SVR)数据预测
  13. 复变函数总结一:复变函数
  14. 基于nginx tomcat redis分布式web应用的session共享配置
  15. 多元线性回归—多重共线性
  16. K8S建立ipv6集群
  17. 峰哥教你如何在B站学大数据(建议收藏)
  18. 网页中嵌入视频播放器代码
  19. 国外可以免费发布供求信息的网站(转)
  20. 通过边界代理一路打到三层内网+后渗透通用手法

热门文章

  1. 1 + “X“ 网络系统 建设与运维(中级)
  2. mysql 索引设计_MySQL 索引原理及设计
  3. pyg与graphgym
  4. “长短令牌三验证”的JWT令牌续签策略(兼顾安全、性能的综合性方案)
  5. MT【137】多少个?
  6. 心绪不宁的时候就该写点东西,审视一下自己的内心吧
  7. Halcon 金属疤痕检测(图像增强、区域排序、灰度扩张)
  8. easyswoole数据库连接池_easyswoole快速实现一个网站的api接口程序
  9. 网格布局之合并单元格
  10. 无法连接wifi或找不到wifi信息