Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp481431yba; Wed, 15 May 2019 04:56:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqyryQJQlgxb3BtiT8wLar3qlSjGaNBZCFjJVvX8oZD2SswJSjA0//48VOmD4h8KyYAoMDse X-Received: by 2002:a63:2b96:: with SMTP id r144mr28974102pgr.314.1557921366788; Wed, 15 May 2019 04:56:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557921366; cv=none; d=google.com; s=arc-20160816; b=hqeapQVd4re/joZud9lh5kgQp+e8Hdx+osA04YysTsX4QtcOwUtqw9QZ9EXNLKa9xR EGYJhwS/3J9jWY/OjAIlLCAmou1givtjSCcjtFRB/mmD7bnpgCBbUR+p7SsNQ735AMHN RjVpBX0CUONDopeXDeQf3X9n78e1m5UChK6Cbm5ikQWKZFwEykH8jE2hAg7UqZwag4Oh meM3DG8hfjr9kjiDnrInkt5e/TSCHAafl5X8ceGAVE5z6Yx+TdhR6boqUh1iZsOSPCnf uCQMGLdM5knfEw0rN1z+2QTv+lMYT3rjH46MrvKtwX+jYqk5myDd2Vqjdsr1Y02099Fi fLTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=2xcGTUjd96lJ07kE5POEzOXDintAjZsSecDhBd/emjQ=; b=rLphl8/2qLfMPVrtW/mID8Ub2tCg8w2OFH8WLYlAUyuE4vbWGjgyMdDUwovyuqJuxR RZACr1DmviM2MgcmtirW0jR+g4PaF1IgF6mNb8fxmKV8msyzN/sa0E1F8eLs8H2zJi9c 3ieLLg13UYDIrJzNxnteWi16g43jDArsrZqakgN3RuQIUJYtLnyqhJTLA14sRVQ5UNl8 t9loTmgQ1KoF1PYFpc1OkM0kx78Nd4XFx4CsO2j0JO42zk1uu3+ne6pQIExctKypb1Bi 3bB+YTw88rZGuxFA4wkFdfRqNGwSPxQJQnBMCOV1wur6MthC19NdigCrAyB+fbbPMio8 /Bog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d36si1670904pla.81.2019.05.15.04.55.52; Wed, 15 May 2019 04:56:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730845AbfEOLxy (ORCPT + 99 others); Wed, 15 May 2019 07:53:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:46902 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730922AbfEOLxq (ORCPT ); Wed, 15 May 2019 07:53:46 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2E504AF6E; Wed, 15 May 2019 11:53:45 +0000 (UTC) Date: Wed, 15 May 2019 13:53:44 +0200 From: Petr Mladek To: Daniel Vetter Cc: Intel Graphics Development , DRI Development , Daniel Vetter , Peter Zijlstra , Ingo Molnar , Will Deacon , Sergey Senozhatsky , Steven Rostedt , John Ogness , Chris Wilson , Linux Kernel Mailing List Subject: Re: [PATCH] kernel/locking/semaphore: use wake_q in up() Message-ID: <20190515115344.oqkei4yzkqxu2uqf@pathway.suse.cz> References: <20190509120903.28939-1-daniel.vetter@ffwll.ch> <20190509200633.19678-1-daniel.vetter@ffwll.ch> <20190510092819.elu4b7fcojzcek2q@pathway.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 2019-05-10 17:20:15, Daniel Vetter wrote: > On Fri, May 10, 2019 at 11:28 AM Petr Mladek wrote: > > > > 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. > > DEFINE_WAKE_Q does that already, and if it didn't, I'd wonder how I > managed to boot with this patch. console_lock is usally terribly > contented because thanks to fbcon we must do a full display modeset > while holding it, which takes forever. As long as anyone printks > meanwhile (guaranteed while loading drivers really) you have > contention. > -Daniel You are right. It is initialized by DEFINE_WAKE_Q. The patch looks correct to me then: Reviewed-by: Petr Mladek Best Regards, Petr