Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1336158
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v3] lock/semaphore: Avoid an unnecessary deadlock within up() |
| Date | 2016-02-17 10:30 +0100 |
| Message-ID | <r36AO-4lp-1@gated-at.bofh.it> (permalink) |
| References | <r36r7-4hD-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
* Byungchul Park <byungchul.park@lge.com> wrote:
> diff --git a/kernel/locking/semaphore.c b/kernel/locking/semaphore.c
> index b8120ab..6634b68 100644
> --- a/kernel/locking/semaphore.c
> +++ b/kernel/locking/semaphore.c
> @@ -130,13 +130,14 @@ EXPORT_SYMBOL(down_killable);
> int down_trylock(struct semaphore *sem)
> {
> unsigned long flags;
> - int count;
> + int count = -1;
>
> - raw_spin_lock_irqsave(&sem->lock, flags);
> - count = sem->count - 1;
> - if (likely(count >= 0))
> - sem->count = count;
> - raw_spin_unlock_irqrestore(&sem->lock, flags);
> + if (raw_spin_trylock_irqsave(&sem->lock, flags)) {
> + count = sem->count - 1;
> + if (likely(count >= 0))
> + sem->count = count;
> + raw_spin_unlock_irqrestore(&sem->lock, flags);
> + }
I still don't really like it: two parallel trylocks will cause one of them to fail
- while with the previous code they would both succeed.
None of these changes are necessary with all the printk robustification
changes/enhancements we talked about, right?
Thanks,
Ingo
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v3] lock/semaphore: Avoid an unnecessary deadlock within up() Byungchul Park <byungchul.park@lge.com> - 2016-02-17 10:20 +0100
Re: [PATCH v3] lock/semaphore: Avoid an unnecessary deadlock within up() Ingo Molnar <mingo@kernel.org> - 2016-02-17 10:30 +0100
Re: [PATCH v3] lock/semaphore: Avoid an unnecessary deadlock within up() Byungchul Park <byungchul.park@lge.com> - 2016-02-18 09:10 +0100
Re: [PATCH v3] lock/semaphore: Avoid an unnecessary deadlock within up() Peter Zijlstra <peterz@infradead.org> - 2016-02-17 11:50 +0100
Re: [PATCH v3] lock/semaphore: Avoid an unnecessary deadlock within up() Byungchul Park <byungchul.park@lge.com> - 2016-02-18 09:20 +0100
csiph-web