[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <877dgpp852.ffs@tglx>
Date: Fri, 13 Aug 2021 19:27:37 +0200
From: Thomas Gleixner <tglx@...utronix.de>
To: Waiman Long <llong@...hat.com>,
Xiaoming Ni <nixiaoming@...wei.com>,
linux-kernel@...r.kernel.org, peterz@...radead.org,
mingo@...hat.com, will@...nel.org, boqun.feng@...il.com
Cc: wangle6@...wei.com, xiaoqian9@...wei.com, shaolexi@...wei.com
Subject: Re: [PATCH] semaphore: Add might_sleep() to down_*() family
On Sun, Aug 08 2021 at 23:01, Waiman Long wrote:
> On 8/8/21 10:12 PM, Xiaoming Ni wrote:
>> Semaphore is sleeping lock. Add might_sleep() to down*() family
>> (with exception of down_trylock()) to detect atomic context sleep.
>> @@ -157,6 +160,7 @@ int down_timeout(struct semaphore *sem, long timeout)
>> unsigned long flags;
>> int result = 0;
>>
>> + might_sleep();
>> raw_spin_lock_irqsave(&sem->lock, flags);
>> if (likely(sem->count > 0))
>> sem->count--;
>
> I think it is simpler to just put a "might_sleep()" in __down_common()
> which is the function where sleep can actually happen.
No. Putting it in __down_common() is wrong, because that covers only the
contended case.
But we want to cover the potential sleep, i.e. checking even in the
non-contended case, which is what might_sleep() is about.
Thanks,
tglx
Powered by blists - more mailing lists