关于BUG_ON()的一点笔记

2023-05-16

关于BUG_ON()的一点笔记

最近在看isp1362的驱动经常看到这个BUG_ON()在网上找了些相关资料,现总结如下

先看代码吧:

对于blackfin来说有如下定义(现在没时间学习blackfin体系,还看不懂以后有时间在看了):

作用:一些内核调用可以用来方便标记bug,提供断言并输出信息。最常用的两个是BUG()和BUG_ON()。当被调用的时候,它们会引发oops,导致栈的回溯和错误信息的打印。为什么这些声明会导致 oops跟硬件的体系结构是相关的。大部分体系结构把BUG()和BUG_ON()定义成某种非法操作,这样自然会产生需要的oops。你可以把这些调用当作断言使用,想要断言某种情况不该发生
if (bad_thing)
BUG();
或者使用更好的形式:
BUG_ON(bad_thing);

可以用panic()引发更严重的错误。调用panic()不但会打印错误消息而且还会挂起整个系统。显然,你只应该在极端恶劣的情况下使用它:
if (terrible_thing)
       panic("foo is %ld/n", foo);

 有些时候,你只是需要在终端上打印一下栈的回溯信息来帮助你测试。此时可以使用dump_stack()。它只在终端上打印寄存器上下文和函数的跟踪线索:
if (!debug_check) {
       printk(KERN_DEBUG "provide some information.../n");
       dump_stack();
}
from:http://www.lupaworld.com/bbs/thread-36983-1-8.html


A lots of places in linux kernel we encounter the macro BUG_ON.
BUG_ON macro first checks for the condition and if condition is true then it calls BUG which do a printk of msg and call panic which halts the system.(如果BUG_ON中的条件为真就调用BUG,它输出一些信息,然后调用panic函数挂起系统。)

The unlikely in BUG_ON macro is compiler directive which ask compiler to generate assembly such that the condition mentioned in unlikely isn't going to be met most-of-the time , which reduces jumps and speeds-up things, although if condition mentioned in unlikely met then there will be a long jump and speed will be effected, so must be used carefully. Same is with likely as it is the opposite of unlikely .(据说likely一般是很少用的)

from: http://knol.google.com/k/vivek-bhadra/linux-debugging-bug-on/3c84lj4klzp0d/14#

 

这个unlikely()使我想到了之前看到过的一个宏__cold,原来这两个是同一个东西,__cold是4.3版本之后的gcc才支持的。

__cold的定义


 

 

hot
The hot attribute is used to inform the compiler that a function is a hot spot of the compiled program. The function is optimized more aggressively and on many target it is placed into special subsection of the text section so all hot functions appears close together improving locality.
When profile feedback is available, via -fprofile-use, hot functions are automatically detected and this attribute is ignored.
The hot attribute is not implemented in GCC versions earlier than 4.3.
cold
The cold attribute is used to inform the compiler that a function is unlikely executed. The function is optimized for size rather than speed and on many targets it is placed into special subsection of the text section so all cold functions appears close together improving code locality of non-cold parts of program. The paths leading to call of cold functions within code are marked as unlikely by the branch prediction mechanism. It is thus useful to mark functions used to handle unlikely conditions, such as perro r , as cold to improve optimization of hot functions that do call marked functions in rare occasions.
When profile feedback is available, via -fprofile-use, hot functions are automatically detected and this attribute is ignored.
The cold attribute is not implemented in GCC versions earlier than 4.3.

from: http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Function-Attributes.html

 

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

关于BUG_ON()的一点笔记 的相关文章

  • WGAN基本原理及Pytorch实现WGAN

    目录 1 WGAN产生背景 xff08 1 xff09 超参数敏感 xff08 2 xff09 模型崩塌 2 WGAN主要解决的问题 3 不同距离的度量方式 xff08 1 xff09 方式一 xff08 2 xff09 方式二 xff08

随机推荐

  • Pytorch框架实现WGAN-GP

    目录 1 WGAN GP产生背景 2 WGAN GP的主要成就 3 权重限制的困难 Difficulties with weight constraints xff08 1 xff09 WGAN GP算法流程 xff08 2 xff09 梯
  • Pytorch框架实现Pix2Pix(Image-to-image)

    目录 1 pix2pix研究背景 2 Pix2Pix基本原理 xff08 1 xff09 原理图 xff08 2 xff09 条件GAN cGAN xff08 3 xff09 公式原理 3 Pix2Pix网络模型 xff08 1 xff09
  • 【Microsoft COCO数据集介绍以及简单使用】

    Microsoft COCO数据集介绍以及简单使用 文前白话1 MSCOCO数据集介绍2 COCO数据集格式说明3 数据集下载4 COCO API pycocotools 其它的COCO API Reference 文前白话 本文介绍Mic
  • linux装SSH服务以及防止SSH暴力破解

    需要安装的包 xff1a openssh clients 6 6 1p1 22 el7 x86 64 openssh server 6 6 1p1 22 el7 x86 64 配置文件中常用参数的介绍 xff1a vim etc ssh s
  • 【Linux 切换 ES(elasticsearch)用户】

    Linux服务器里面有些操作不能用root用户操作ES xff0c 需要切换用户操作启动 1 切换用户命令 su 用户名 或者 ssh 用户名 64 服务器ip地址 su span class token operator span es
  • [DSA] 数字血管造影系统-硬件篇

    根据一下资料整理和增删 xff1a http www china radiology com showtopic 6451 aspx 2008年的资料 xff0c 但可以作为入门资料 xff0c 讲述了很多基本概念 http blog cs
  • QT修改QPushButton的背景色和文字颜色

    Qt中QPushButton背景颜色设置方法 不管我设置不是画笔颜色 xff0c 依然不管用 xff0c 一查才知道自己错了 因为在windows中QPushButton的颜色涉及到样式表 xff0c 所以应该设置样式表才可以 xff0c
  • anaconda释放空间

    学习内容 xff1a conda clean 后面可以跟很多超参 xff0c 不同超参有不同的功能 xff1a 可选参数 xff1a span class token operator span h span class token ope
  • Qt线程:QThread

    一 描述 一个QThread对象管理程序内的一个线程 xff0c QThreads在run 中开始执行 默认情况下 xff0c run 通过调用exec 启动事件循环 xff0c 并在线程内部运行一个Qt事件循环 可以通过使用 QObjec
  • 论文精讲 | CVPR 2022|RHFL-对抗噪声的联邦学习

    模型异构的联邦学习 xff0c 是一种每个client拥有互不相同模型的联邦学习任务 xff0c 其能够解决联邦学习中每个成员希望独立设计自己模型的需求 xff0c 但目前同样面临着来自数据层面和成员层面的各种挑战 xff0c 比如数据标记
  • Android音频简介

    1 基本概念 1 1 播放模式 xff1a Deep buffer playback Android开发中最常用的播放模式 xff0c 音乐等对时延要求不高的声音输出采用该模式 边加载边播放 xff0c 由AP进行解码 Low latenc
  • vnc显示远程桌面

    搜了很多教程 xff0c 大部分都试了还是不能正常显示Ubuntu18 04的桌面 xff0c 最后找到了一篇文章 xff1a 使用 VNC 显示 Ubuntu Server 的图形化界面 可以让我的vnc正常显示的配置 首先 在服务器终端
  • 面试中常被提到的最左前缀匹配原则

    最左前缀匹配原则 xff1a 在MySQL建立联合索引时会遵守最左前缀匹配原则 xff0c 即最左优先 xff0c 在检索数据时从联合索引的最左边开始匹配 要想理解联合索引的最左匹配原则 xff0c 先来理解下索引的底层原理 索引的底层是一
  • njupt 字典序最大的出栈序列

    题意 xff1a 给出入栈序列 A xff0c 保证 A 各个元素值各不相等 xff0c 输出字典序最大的出栈序列 如入栈序列 A 61 1 2 9 4 6 5 则字典序最大的出栈序列为9 6 5 4 2 1 栈的性质就是先进后出 xff0
  • SD-WAN设备白盒刷机

    1 启动U盘插入盒子USB接口 2 PC与盒子通过串口线连接 xff0c 波特率为115200 3 加电 4 WAN接口接入网络 xff0c 保证可以访问外网 5 cd var 6 scp 64 122 96 93 166 root Fle
  • Android手机控制ZigBee板上LED

    环境 xff1a Windows 编译器 xff1a IAREW8051 8 1 硬件 xff1a CC2530 协议栈 xff1a ZStack CC2530 2 3 0 1 4 0 手机 xff1a Android4 1 2 又重新开始
  • Windows 10 WSL2 安装Linux Xfce图形界面

    一 更新ubuntu 18 04 LTS软件源 xff0c 推荐使用国内的软件源 1 备份配置文件 xff1a cp a etc apt sources list etc apt sources list bak 2 修改sources l
  • Ubuntu终端快捷键打不开解决

    ubuntu快捷键打不开终端 问题描述 xff1a 快捷键打不开终端 xff0c 加装python3 9后 xff0c 就出现了gnome terminal报错和快捷键无法打开终端的问题 解决方法 xff1a cd usr lib pyth
  • 解决Win10 WSL2 IP地址经常变动导致docker容器无法正常访问

    前提是Win10已经安装好WSL2 xff0c 且linux发行版已经安装docker 安装wsl2host wsl2host下载地址 xff08 https github com shayne go wsl2 host releases
  • 关于BUG_ON()的一点笔记

    关于BUG ON 的一点笔记 最近在看isp1362的驱动经常看到这个BUG ON 在网上找了些相关资料 xff0c 现总结如下 先看代码吧 lt asm generic bug h gt ifndef HAVE ARCH BUG defi