Re: [PATCH] locking/lock_events: Use this_cpu_add() when necessary
From: Waiman Long
Date: Fri May 24 2019 - 13:03:24 EST
On 5/23/19 10:58 AM, Will Deacon wrote:
> On Wed, May 22, 2019 at 12:54:13PM -0700, Linus Torvalds wrote:
>> On Wed, May 22, 2019 at 8:40 AM Waiman Long <longman@xxxxxxxxxx> wrote:
>>> +#if defined(CONFIG_PREEMPT) && \
>>> + (defined(CONFIG_DEBUG_PREEMPT) || !defined(CONFIG_X86))
>>> +#define lockevent_percpu_inc(x) this_cpu_inc(x)
>>> +#define lockevent_percpu_add(x, v) this_cpu_add(x, v)
>> Why that CONFIG_X86 special case?
>>
>> On x86, the regular non-underscore versionm is perfectly fine, and the
>> underscore is no faster or simpler.
>>
>> So just make it be
>>
>> #if defined(CONFIG_PREEMPT)
>> .. non-underscore versions..
>> #else
>> .. underscore versions ..
>> #endif
>>
>> and realize that x86 simply doesn't _care_. On x86, it will be one
>> single instruction regardless.
>>
>> Non-x86 may prefer the underscore versions for the non-preempt case.
> To be honest, given this depends on LOCK_EVENT_COUNTS, I'd be inclined to
> keep things simple and drop the underscore versions entirely. Saves having
> to worry about things like "could I take an interrupt during the add?".
>
I have sent out the v2 patch that simplifies the condition. Now the
underscore versions will be used for !preempt kernel and non-underscore
version used in preempt kernel. The non-underscore versions may generate
a lot more unnecessary code when CONFIG_PREEMPT_COUNT is defined.
Cheers,
Longman