在 Linux 内核中使用可能/不可能作为 return 参数
只看linux内核中的这个结构,我不明白它是什么意思。
110 return unlikely(sl->sequence != start);
我知道 likely
/unlikely
是用此处描述的 __builtin_expect 函数创建的: http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins。 html
您可以使用 __builtin_expect 为编译器提供分支预测信息。
但是无条件分支可能有什么样的分支预测提示?
Just see this construction in the linux kernel, and I can't get what does it mean.
110 return unlikely(sl->sequence != start);
I know that likely
/unlikely
are made with __builtin_expect
function described here:
http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
You may use __builtin_expect to provide the compiler with branch prediction information.
But what kind of branch prediction hints is possible for unconditional branch??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是在这里猜测,但想象一下该函数是由编译器内联的,并且您在调用代码中有这样的内容:
然后分支预测记录提示是完全合理的。
Just guessing here, but imagine the function is inlined by the compiler, and you have this in the calling code:
then it's entirely reasonable for the branch prediction to take note of the hint.
“不太可能”并不给出从函数返回的可能性,而是给出返回值的预期值。我的猜测是该函数是内联的,因此这是优化函数调用者的提示。
The "unlikely" does not give a likelyhood for returning from the function, but rather an expected value for the return value. My guess is that the function is inlineable, so this is a hint for optimizing the function's caller.