Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp657133pxx; Wed, 28 Oct 2020 13:37:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwm3VQDk9pGdpO5GWkkLfTYC1wcM1LNUoDVvsd6JjNwb2Rsxt/XfHc7honG+4QYbMVgB32F X-Received: by 2002:a17:906:3087:: with SMTP id 7mr836728ejv.375.1603917431593; Wed, 28 Oct 2020 13:37:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603917431; cv=none; d=google.com; s=arc-20160816; b=0DAwraclV8FT2rAYCpzewL/f+MfJL6rHJ/oZOIf8oXYqhH7XaVFcZt1XFBzjJld5bq mbYyRctQ0ojh1NUn5k1xxgjiwuCmZZt0ipH3ENOtQH9nD6ESoC3TmS3QpT4ZubhDlXte UrP5jIKCsF9INkt1ZJrTpSymjn43ZYx7IO9OAxWx2D+yRBR+RODmNVN4ueFf+g5C0ETT yEQtl+fuTvrN8iE5qFvfFPtlmSIfSAgwjvwp8cKfpx8B6gYh9l4YZcKOqr3FBhi7ew4r cXnKhCDfnY2Rk6FT4aVLfllI775XaaCyr3Ysxdie0+AThvp/mdm8SYnUYtsfG3LMGiPX IxrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=p1hEPodUXDXuSQzasXYwrS2God+lcKGnVUZasxbSQxY=; b=Lg95s7y+Aqr26r7RI7cnOK2r0GsChGZqVIHVUfyPK7aS8yKwD46RaIy5iDuYDfd5up X6W2Z+ixfbivbKsjj/BguSUUQXuoB5xwpQgNRM6vkFy4PlUC/AGyZWKzlqj3R22mpMI3 72tHXz0PRCKH1sZKZKPt/24loRyEzbAUZV7ne1gcH9wauTri6jIzdpQ5f2br5zN3bO7s nG34iHUodIc8jrTp94brBdBUKjHeBGE6WajSQJdPMl8XGKQkkVWFwmnyyfk24YL9sVGj d3hy2Loe4Os5DS3QDlq8Kk0/iJGu1g+LSxCwOkfhwxseYOWVkmUXfNtvHBDRiaT4s+IR 8lxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=cdxDu3ox; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j6si24427edq.236.2020.10.28.13.36.48; Wed, 28 Oct 2020 13:37:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=cdxDu3ox; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1829586AbgJ0TRa (ORCPT + 99 others); Tue, 27 Oct 2020 15:17:30 -0400 Received: from merlin.infradead.org ([205.233.59.134]:55048 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1818516AbgJ0TRU (ORCPT ); Tue, 27 Oct 2020 15:17:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=p1hEPodUXDXuSQzasXYwrS2God+lcKGnVUZasxbSQxY=; b=cdxDu3oxrBK4H243uvi9iaApqN OHvlk6JIrx3YcHGxzINSmqLO7PVWeLJHMV3OtLPc2ojslPnjipWNQCWRMQQalw+icSFCM4pRO8uTg aOizBQcGY7focMzkxdS44gU+M8acA2ZcOmRH1P1WyEMjSQaJ3VleyvXRczD6iq7BXw5mDmXNBMn8+ zFm1f48f56RhOKszhZ3Ubq1PIQU6a8j7vmFt+JCkBAfM+ekMIrn+Y4iCanRtmhtH7u0OyhzLI8VSi 9JgcSpuMC4/GN+wL2sHd/HFguHZyJXkxrvrWZsUSL/XcJnTbVYpPIqvPnOlm/ICapBcfkMyJasbnB /0BZYQQA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXUT2-0003P2-OC; Tue, 27 Oct 2020 19:17:12 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 4A92C307A7F; Tue, 27 Oct 2020 20:17:11 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 32968203C2679; Tue, 27 Oct 2020 20:17:11 +0100 (CET) Date: Tue, 27 Oct 2020 20:17:11 +0100 From: Peter Zijlstra To: Sean Christopherson Cc: Ben Gardon , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Peter Shier , Ingo Molnar , Will Deacon , Waiman Long , Davidlohr Bueso Subject: Re: [PATCH 3/3] sched: Add cond_resched_rwlock Message-ID: <20201027191711.GP2628@hirez.programming.kicks-ass.net> References: <20201027164950.1057601-1-bgardon@google.com> <20201027164950.1057601-3-bgardon@google.com> <20201027175634.GI1021@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201027175634.GI1021@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 27, 2020 at 10:56:36AM -0700, Sean Christopherson wrote: > On Tue, Oct 27, 2020 at 09:49:50AM -0700, Ben Gardon wrote: > > Rescheduling while holding a spin lock is essential for keeping long > > running kernel operations running smoothly. Add the facility to > > cond_resched rwlocks. > > This adds two new exports and two new macros without any in-tree users, which > is generally frowned upon. You and I know these will be used by KVM's new > TDP MMU, but the non-KVM folks, and more importantly the maintainers of this > code, are undoubtedly going to ask "why". I.e. these patches probably belong > in the KVM series to switch to a rwlock for the TDP MMU. I was informed about this ;-) > Regarding the code, it's all copy-pasted from the spinlock code and darn near > identical. It might be worth adding builder macros for these. I considered mentioning them; I'm typically a fan of them, but I'm not quite sure it's worth the effort here. > > +int __cond_resched_rwlock_read(rwlock_t *lock) > > +{ > > + int resched = should_resched(PREEMPT_LOCK_OFFSET); > > + int ret = 0; > > + > > + lockdep_assert_held(lock); > > + > > + if (rwlock_needbreak(lock) || resched) { > > + read_unlock(lock); > > + if (resched) > > + preempt_schedule_common(); > > + else > > + cpu_relax(); > > + ret = 1; > > AFAICT, this rather odd code flow from __cond_resched_lock() is an artifact of > code changes over the years and not intentionally weird. IMO, it would be > cleaner and easier to read as: > > int resched = should_resched(PREEMPT_LOCK_OFFSET); > > lockdep_assert_held(lock); lockdep_assert_held_read() :-) > > if (!rwlock_needbreak(lock) && !resched) > return 0; > > read_unlock(lock); > if (resched) > preempt_schedule_common(); > else > cpu_relax(); > read_lock(lock) > return 1; > I suppose that works, but then also change the existing one.