From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F91AC4332D for ; Fri, 20 Mar 2020 09:02:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7E91520752 for ; Fri, 20 Mar 2020 09:02:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727041AbgCTJCO (ORCPT ); Fri, 20 Mar 2020 05:02:14 -0400 Received: from mx2.suse.de ([195.135.220.15]:45570 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726979AbgCTJCO (ORCPT ); Fri, 20 Mar 2020 05:02:14 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 60CA0AECE; Fri, 20 Mar 2020 09:02:12 +0000 (UTC) Date: Fri, 20 Mar 2020 02:01:06 -0700 From: Davidlohr Bueso To: Thomas Gleixner Cc: LKML , Peter Zijlstra , Linus Torvalds , Ingo Molnar , Will Deacon , "Paul E . McKenney" , Joel Fernandes , Steven Rostedt , Randy Dunlap , Arnd Bergmann , Sebastian Andrzej Siewior , Logan Gunthorpe , Kurt Schwemmer , Bjorn Helgaas , linux-pci@vger.kernel.org, Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org, Kalle Valo , "David S. Miller" , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Oleg Nesterov , Michael Ellerman , linuxppc-dev@lists.ozlabs.org Subject: Re: [patch V2 11/15] completion: Use simple wait queues Message-ID: <20200320090106.6p2lwqvs4jedhvds@linux-p48b> References: <20200318204302.693307984@linutronix.de> <20200318204408.521507446@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200318204408.521507446@linutronix.de> User-Agent: NeoMutt/20180716 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Wed, 18 Mar 2020, Thomas Gleixner wrote: >From: Thomas Gleixner > >completion uses a wait_queue_head_t to enqueue waiters. > >wait_queue_head_t contains a spinlock_t to protect the list of waiters >which excludes it from being used in truly atomic context on a PREEMPT_RT >enabled kernel. > >The spinlock in the wait queue head cannot be replaced by a raw_spinlock >because: > > - wait queues can have custom wakeup callbacks, which acquire other > spinlock_t locks and have potentially long execution times > > - wake_up() walks an unbounded number of list entries during the wake up > and may wake an unbounded number of waiters. > >For simplicity and performance reasons complete() should be usable on >PREEMPT_RT enabled kernels. > >completions do not use custom wakeup callbacks and are usually single >waiter, except for a few corner cases. > >Replace the wait queue in the completion with a simple wait queue (swait), >which uses a raw_spinlock_t for protecting the waiter list and therefore is >safe to use inside truly atomic regions on PREEMPT_RT. > >There is no semantical or functional change: > > - completions use the exclusive wait mode which is what swait provides > > - complete() wakes one exclusive waiter > > - complete_all() wakes all waiters while holding the lock which protects > the wait queue against newly incoming waiters. The conversion to swait > preserves this behaviour. > >complete_all() might cause unbound latencies with a large number of waiters >being woken at once, but most complete_all() usage sites are either in >testing or initialization code or have only a really small number of >concurrent waiters which for now does not cause a latency problem. Keep it >simple for now. > >The fixup of the warning check in the USB gadget driver is just a straight >forward conversion of the lockless waiter check from one waitqueue type to >the other. > >Signed-off-by: Thomas Gleixner >Cc: Arnd Bergmann Reviewed-by: Davidlohr Bueso From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1351AC4332B for ; Fri, 20 Mar 2020 09:10:04 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BBB9B20752 for ; Fri, 20 Mar 2020 09:10:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BBB9B20752 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=stgolabs.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 48kHzY5TrqzDrg8 for ; Fri, 20 Mar 2020 20:10:01 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=stgolabs.net (client-ip=195.135.220.15; helo=mx2.suse.de; envelope-from=dave@stgolabs.net; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=stgolabs.net Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 48kHpf0CM6zDrNB for ; Fri, 20 Mar 2020 20:02:18 +1100 (AEDT) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 60CA0AECE; Fri, 20 Mar 2020 09:02:12 +0000 (UTC) Date: Fri, 20 Mar 2020 02:01:06 -0700 From: Davidlohr Bueso To: Thomas Gleixner Subject: Re: [patch V2 11/15] completion: Use simple wait queues Message-ID: <20200320090106.6p2lwqvs4jedhvds@linux-p48b> References: <20200318204302.693307984@linutronix.de> <20200318204408.521507446@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200318204408.521507446@linutronix.de> User-Agent: NeoMutt/20180716 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Randy Dunlap , Peter Zijlstra , linux-pci@vger.kernel.org, Sebastian Andrzej Siewior , Oleg Nesterov , Joel Fernandes , Will Deacon , Ingo Molnar , "Paul E . McKenney" , Logan Gunthorpe , Arnd Bergmann , linuxppc-dev@lists.ozlabs.org, Steven Rostedt , Bjorn Helgaas , Kurt Schwemmer , Kalle Valo , Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-wireless@vger.kernel.org, LKML , netdev@vger.kernel.org, Linus Torvalds , "David S. Miller" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Wed, 18 Mar 2020, Thomas Gleixner wrote: >From: Thomas Gleixner > >completion uses a wait_queue_head_t to enqueue waiters. > >wait_queue_head_t contains a spinlock_t to protect the list of waiters >which excludes it from being used in truly atomic context on a PREEMPT_RT >enabled kernel. > >The spinlock in the wait queue head cannot be replaced by a raw_spinlock >because: > > - wait queues can have custom wakeup callbacks, which acquire other > spinlock_t locks and have potentially long execution times > > - wake_up() walks an unbounded number of list entries during the wake up > and may wake an unbounded number of waiters. > >For simplicity and performance reasons complete() should be usable on >PREEMPT_RT enabled kernels. > >completions do not use custom wakeup callbacks and are usually single >waiter, except for a few corner cases. > >Replace the wait queue in the completion with a simple wait queue (swait), >which uses a raw_spinlock_t for protecting the waiter list and therefore is >safe to use inside truly atomic regions on PREEMPT_RT. > >There is no semantical or functional change: > > - completions use the exclusive wait mode which is what swait provides > > - complete() wakes one exclusive waiter > > - complete_all() wakes all waiters while holding the lock which protects > the wait queue against newly incoming waiters. The conversion to swait > preserves this behaviour. > >complete_all() might cause unbound latencies with a large number of waiters >being woken at once, but most complete_all() usage sites are either in >testing or initialization code or have only a really small number of >concurrent waiters which for now does not cause a latency problem. Keep it >simple for now. > >The fixup of the warning check in the USB gadget driver is just a straight >forward conversion of the lockless waiter check from one waitqueue type to >the other. > >Signed-off-by: Thomas Gleixner >Cc: Arnd Bergmann Reviewed-by: Davidlohr Bueso