Re: [PATCH] scripts: coccinelle: check for !(un)?likely usage

From: Denis Efremov
Date: Sun Sep 01 2019 - 13:40:01 EST




On 01.09.2019 20:24, Pavel Machek wrote:
> Hi!
>
>>> This patch adds coccinelle script for detecting !likely and !unlikely
>>> usage. It's better to use unlikely instead of !likely and vice versa.
>>
>> Please explain _why_ is it better in the changelog.
>>
>> btw: there are relatively few uses like this in the kernel.
>>
>> $ git grep -P '!\s*(?:un)?likely\s*\(' | wc -l
>> 40
>>
>> afaict: It may save 2 bytes of x86/64 object code.
>>
>> For instance:
>>
>> $ diff -urN kernel/tsacct.lst.old kernel/tsacct.lst.new|less
>> --- kernel/tsacct.lst.old 2019-08-25 09:21:39.936570183 -0700
>> +++ kernel/tsacct.lst.new 2019-08-25 09:22:20.774324886 -0700
>> @@ -24,158 +24,153 @@
>> 15: 48 89 fb mov %rdi,%rbx
>> u64 time, delta;
>>
>> - if (!likely(tsk->mm))
>> + if (unlikely(tsk->mm))
>
> Are you sure this is equivalent?
>
> Pavel

Hi,

No, it's not correct. Thanks Rasmus for clarifying the things here.
This was my mistake. As a human, I failed to parse "likely" and "!"
and made too hasty conclusions :)

The correct transformation is in v2. This will be
!likely(tsk->mm) -> unlikely(!tsk->mm)

Thanks,
Denis