LKML Archive on lore.kernel.org help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com> To: Daniel Vetter <daniel.vetter@ffwll.ch> Cc: Intel Graphics Development <intel-gfx@lists.freedesktop.org>, DRI Development <dri-devel@lists.freedesktop.org>, Daniel Vetter <daniel.vetter@intel.com>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Will Deacon <will.deacon@arm.com>, Sergey Senozhatsky <sergey.senozhatsky@gmail.com>, Steven Rostedt <rostedt@goodmis.org>, John Ogness <john.ogness@linutronix.de>, Chris Wilson <chris@chris-wilson.co.uk>, linux-kernel@vger.kernel.org Subject: Re: [PATCH] kernel/locking/semaphore: use wake_q in up() Date: Fri, 10 May 2019 11:28:19 +0200 [thread overview] Message-ID: <20190510092819.elu4b7fcojzcek2q@pathway.suse.cz> (raw) In-Reply-To: <20190509200633.19678-1-daniel.vetter@ffwll.ch> On Thu 2019-05-09 22:06:33, Daniel Vetter wrote: > console_trylock, called from within printk, can be called from pretty > much anywhere. Including try_to_wake_up. Note that this isn't common, > usually the box is in pretty bad shape at that point already. But it > really doesn't help when then lockdep jumps in and spams the logs, > potentially obscuring the real backtrace we're really interested in. > One case I've seen (slightly simplified backtrace): > > Fix this specific locking recursion by moving the wake_up_process out > from under the semaphore.lock spinlock, using wake_q as recommended by > Peter Zijlstra. It might make sense to mention also the optimization effect mentioned by Peter. > diff --git a/kernel/locking/semaphore.c b/kernel/locking/semaphore.c > index 561acdd39960..7a6f33715688 100644 > --- a/kernel/locking/semaphore.c > +++ b/kernel/locking/semaphore.c > @@ -169,6 +169,14 @@ int down_timeout(struct semaphore *sem, long timeout) > } > EXPORT_SYMBOL(down_timeout); > > +/* Functions for the contended case */ > + > +struct semaphore_waiter { > + struct list_head list; > + struct task_struct *task; > + bool up; > +}; > + > /** > * up - release the semaphore > * @sem: the semaphore to release > @@ -179,24 +187,25 @@ EXPORT_SYMBOL(down_timeout); > void up(struct semaphore *sem) > { > unsigned long flags; > + struct semaphore_waiter *waiter; > + DEFINE_WAKE_Q(wake_q); We need to call wake_q_init(&wake_q) to make sure that it is empty. Best Regards, Petr > raw_spin_lock_irqsave(&sem->lock, flags); > - if (likely(list_empty(&sem->wait_list))) > + if (likely(list_empty(&sem->wait_list))) { > sem->count++; > - else > - __up(sem); > + } else { > + waiter = list_first_entry(&sem->wait_list, > + struct semaphore_waiter, list); > + list_del(&waiter->list); > + waiter->up = true; > + wake_q_add(&wake_q, waiter->task); > + } > raw_spin_unlock_irqrestore(&sem->lock, flags); > + > + wake_up_q(&wake_q); > } > EXPORT_SYMBOL(up); > > -/* Functions for the contended case */ > - > -struct semaphore_waiter { > - struct list_head list; > - struct task_struct *task; > - bool up; > -}; > - > /* > * Because this function is inlined, the 'state' parameter will be > * constant, and thus optimised away by the compiler. Likewise the
next prev parent reply other threads:[~2019-05-10 9:28 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-05-09 12:09 [PATCH] RFC: console: hack up console_lock more v3 Daniel Vetter 2019-05-09 12:21 ` Chris Wilson 2019-05-09 12:31 ` Peter Zijlstra 2019-05-09 13:06 ` Daniel Vetter 2019-05-09 13:36 ` Peter Zijlstra 2019-05-09 14:56 ` Petr Mladek 2019-05-09 16:43 ` Daniel Vetter 2019-05-10 9:15 ` Petr Mladek 2019-05-10 9:51 ` Sergey Senozhatsky 2019-05-10 15:05 ` Daniel Vetter 2019-05-09 20:06 ` [PATCH] kernel/locking/semaphore: use wake_q in up() Daniel Vetter 2019-05-10 5:50 ` Sergey Senozhatsky 2019-05-10 7:51 ` Daniel Vetter 2019-05-10 9:28 ` Petr Mladek [this message] 2019-05-10 15:20 ` Daniel Vetter 2019-05-15 11:53 ` Petr Mladek
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190510092819.elu4b7fcojzcek2q@pathway.suse.cz \ --to=pmladek@suse.com \ --cc=chris@chris-wilson.co.uk \ --cc=daniel.vetter@ffwll.ch \ --cc=daniel.vetter@intel.com \ --cc=dri-devel@lists.freedesktop.org \ --cc=intel-gfx@lists.freedesktop.org \ --cc=john.ogness@linutronix.de \ --cc=linux-kernel@vger.kernel.org \ --cc=mingo@redhat.com \ --cc=peterz@infradead.org \ --cc=rostedt@goodmis.org \ --cc=sergey.senozhatsky@gmail.com \ --cc=will.deacon@arm.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).