1.likely && unlikely
分支声明
对于条件选择语句,gcc内建了一条指令用于优化,在一个条件经常出现,或者该条件很少出现的时候,编译器可以根据这条指令对条件分支选择进行优化。内核把这条指令封装成了宏,比如likely()和unlikely(),这样使用起来比较方便。例如,下面是一个条件选择语句:if (foo) { /* .. */}如果想要把这个选择标记成绝少发生的分支:/* 我们认为foo绝大多数时间都会为0.. */if (unlikely(foo)) { /* .. */}相反,如果我们想把一个分支标记为通常为真的选择:/* 我们认为foo通常都不会为0 */if(likely(foo)) { /* .. */}
需要注意的是:likely与unlikely并没有改变程序逻辑,仅仅是对分支预测提供一定的依据。
2.__read_mostly
__read_mostly是内核链接时使用的, 与体系结构的cache机制密切相关. 在linux kernel里定义在x86,
ia64, powerpc, parisc, s390, sh, sparc 体系结构的 asm/cache.h中:
#define __read_mostly __attribute__((__section__(".data.read_mostly")))
|
从定义的字面意思可以理解为将需要经常读取的数据链接进内核的 .data.read_mostly段. 在x86, ia64, powerpc, parisc, s390, sh, sparc 的链接脚本里(arch/xxx/kernel/vmlinux.lds.S)有关于 .data.read_mostly的定义, 就是指定 .data.read_mostly段的数据在内核加载时放到CPU的cache中.
在那些没有cache的体系结构上, __read_mostly被定义为空, 即:
分享到:
相关推荐
linux内核中的likely和unlikely.pdf
不太可能 GCC 分支预测宏。 安装 使用安装: $ clib install clibs/file 应用程序接口 likely (expr) unlikely(expr)
FAQ gnu C likely unlikely statement explain. Compiler optize C language code.
粒子群优化(Particle Swarm Optimization, PSO),又称微粒群算法,是由J. Kennedy和R. C. Eberhart等于1995年开发的一种演化计算技术,来源于对一个简化社会模型的
可配置选项包括:C_arch RISC-V或MIPS ISAC_big_endian总线端C_mult_enable合成乘法单位C_branch_likely支持分支延迟时隙取消C_sign_extend支持符号扩展指令C_movn_movz支持条件移动指令C_ll_sc支持原子读 - 修改 - ...
一台电脑上tcpip通信的,地址和端口可以配置
用python爬取网站的农产品数据,然后保存为csv,最后对数据进行分析
信息安全_数据安全_What you most likely did not kno 安全体系 漏洞挖掘 数据分析 系统安全 金融安全
Data Structures & Algorithms Interview Questions You'll Most Likely Be Asked 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
heres of code for optimization. the method that i use is partical swarm of optimization
How to Read and Do Proofs also explains when each technique is likely to be used, based on certain key words that appear in the problem under consideration. Doing so enables students to choose a ...
以流水线的眼光来看,分支并不是高速公路上两个目的地的选择,如果预测失败,将是直接拐向出口处的收费站,还是不带ETC的。...有很多办法可以帮助我们优化分支,除了套用一个likely()/unlikely()这种熟知的方式之外
Likely 不寒碜的社交分享按钮。 标签:Likely
one ore <br>more qusetions will be asked about what was both the conversation and the questions will be spoken only once,After each <br>question there will be a pause.you must read the four ...
delphi10.4用到的控件,需要的请下载! delphi10.4用到的控件,需要的请下载! delphi10.4用到的控件,需要的请下载!
The more factors you have on your side, the more likely you are to succeed, and positive attitude is just one of those factors. Here are seven additional factors that are also important.
Data Structures & Algorithms Interview Questions You'll Most Likely Be Asked 英文mobi 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
Before starting to use the dpm function you should have read the corresponding publication [2] and understand the examples provided on our webpage. If you encounter any problems with the dpm function...
Read the source of AviWriter_2.pas (in AviPack) to get help on what the procedures and properties do. **Current version: AviWriter_2 ver 1.0.0.4 Changes: Finally got On-the-fly compression working ...