Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2073199lqo; Mon, 13 May 2024 07:13:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX3QPUyDVnI4tnGf2YrmpLiq7Pd0MzflsohPFelu93ewy4vNVo5c84kT23fyIuyyNzTwzfTlntcIgIyh7PlokuWPJAE7d0+AYJRHmJH0Q== X-Google-Smtp-Source: AGHT+IGeTf9X0Ovog8zMjkWBvzSMq/YdJ2gPRaxbfyKAwPE3LmPvt6+A0DGcBCBLsKnaC/FMTNs8 X-Received: by 2002:a05:6214:3c9f:b0:6a0:c707:1bed with SMTP id 6a1803df08f44-6a16822cdd1mr103880846d6.42.1715609588689; Mon, 13 May 2024 07:13:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715609588; cv=pass; d=google.com; s=arc-20160816; b=VpLsCrFWzNE3LPRexr2B/hlj1Nm4+s9L2EWWKvviO79WDtJNCPRCQhXY5v5G08dLQ3 ehTfuCYvizNSEpSwH5hF/TFzvy6Ylhj1TLIv7MLeWvZPFb5V5tltsNkdZAPDrF3Q3WjH qMOz6dZ0sjGTMT8mn3aGdgqaYLIwbTwGW11hFoLJ4fnif/kxvRT88+pAAzyF6JLNB+lS n8PE19316K6nPMAL8GXWv874wM7I4/06IVuFCe0pyM3DqZrHa+5h5e/CLZt6TWv5y4V1 DsKpZb0PUiGwXKCHBfDMrgorDU63itEQm6Vt2DNGb2I3uGg3t97tGUIr7QhpK+aTyPZV 1ssA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=0hdTKCCj04pt0LL0tQaS1Zpm2moBRFzHZ42+JJy4qmY=; fh=DJvzpMD/2ufolVrLVZxlOc4cWqFx+bE1Ek//X+tuYM0=; b=YYrs/Fu0H7jm8DKx0DnjlT3iQUqHRFZ/exrGhw5NYnGwOzr2ZUq8bSBi69KrIMRDUL O5+wmPLkRMohXYOtKXCPaD1qhP2hsgLEh/xp9ks2/TyAtSGWzc7cBZhlu7JF20jSrThK YT+LGkK68WTGXQqGHMWQdF7dN5UNeOGR2Y6ql/PzMImVis5hreXlecD56yRncSpNCIkl zwRV0SczGVCaw3PeT4zOLmTzq4nqt6uOjVNBY7MJDDT5Py1p2x6n3i7BQEqht6f1WYq5 mwtDpEPuabE9AfkQSmeIv/eizauC12m45uG8XPpxuYs2gcSVyY7tQMFL2KJ3V6zrMaqA 8JtQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="OA0/UwP/"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-177678-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177678-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6a15f2b6013si98821616d6.397.2024.05.13.07.13.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 07:13:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177678-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="OA0/UwP/"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-177678-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177678-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C5CF11C21141 for ; Mon, 13 May 2024 14:13:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B364153830; Mon, 13 May 2024 14:12:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OA0/UwP/" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 689E2153BEF for ; Mon, 13 May 2024 14:12:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715609564; cv=none; b=RWUSDdWHyv8pu0Psr5MYNVl4Syv7FM9p6RgjfdmLa5lpaC1avH199x3Nuounq5YHZ87u4OzLRNQPgzxCRB3lXACpqWBr2p+BOok4I28RDu6jSK0mWjk3BynDTTVVrXy2TMGheUOTvYIDpUMRj4Gwep+7gL0jup8Qfzk60yH3gVw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715609564; c=relaxed/simple; bh=JiVcnFkfIWkSPdEwVC1UflSAf1GtozE2Y1Cm4v16vng=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Ze3iH4RYWcoLLUXDRNlH8FVub08UzGnvI1fo7EHa/xEaSj4u7V86WeYsvoMIEOzGiCGonSNa5s64jJwZNHE9DQKvFdqGh+KchxVsAu85/jdmHt+iC4XRjmphOGU+o2Q+w7V2S2sSKifPsuwtuWCvjRxkbHxLK1HKAO9ztM0u35I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=OA0/UwP/; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715609560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=0hdTKCCj04pt0LL0tQaS1Zpm2moBRFzHZ42+JJy4qmY=; b=OA0/UwP/9LPTVLrWco82A6HM96qjnr0stAFh6Yl/4GKZmNQP2rZsZ0dLrP5BvnMaM+2hxd gUYF5o5yu1odBMfIgNW6GyAM3Vw3i8gbgwO+Mmh10a9IoNe2zxrscoOtbRQwgQGcXNMXbM jljXCAZW3LI4qYEVCex1vmsVEINdMBo= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-179-QYAO7JcaP7G6MQKot8xnJQ-1; Mon, 13 May 2024 10:09:28 -0400 X-MC-Unique: QYAO7JcaP7G6MQKot8xnJQ-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2e3003fae2dso29075751fa.3 for ; Mon, 13 May 2024 07:09:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715609367; x=1716214167; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0hdTKCCj04pt0LL0tQaS1Zpm2moBRFzHZ42+JJy4qmY=; b=MuGbkjJF4W3kBPHuSPXC0WTlrxoISfoOab/Q8XXWTQjZTNpSejq2eTN74rZ3ZGxmSW KJslJrbNJei6IeDFGlAWKcM2vMVgKGoUuUa7RoRGWeCZ9GVTa2Umqv/0ynqyMyYraDID L9loSS3Bc+dcSfJMji4hxyCQ9rIqgH0/Colhrx7CJUfLXI3RcE66Aby2yKSwInzIXYI4 UudYIszFNqHS+ob06gJyTkJglPtwB9MCXMKRlrCRYZqMY7Zzk4ly293VVm32d+6PR9PW KWErWdozu9nUe+O8+3zZHE3VcNZJrryWs/4jfyiSa+l8L50wAqXYX6MGqlXFXYiyE4ru F/bw== X-Gm-Message-State: AOJu0Yy8lvZYsirdLfdDJQVge5FdbE+d7aV/uVbUa/vRVGAfO0rSrKjz tMayMvdBe2QN9WTHPklR/QaYsRFHvTzbAvUjFUIUFUhOkhRPRpVMtQGsP2NyvNtdTJUcyozrrEk OH1mxdFY+5cWj3vurisU/oi/8pWjoQVIzvyjxXT8ncqzKZ6fmph9gv7MmL9evgw== X-Received: by 2002:a2e:8e93:0:b0:2e4:3f51:33b0 with SMTP id 38308e7fff4ca-2e5204b1cfbmr71984341fa.43.1715609366763; Mon, 13 May 2024 07:09:26 -0700 (PDT) X-Received: by 2002:a2e:8e93:0:b0:2e4:3f51:33b0 with SMTP id 38308e7fff4ca-2e5204b1cfbmr71983771fa.43.1715609365237; Mon, 13 May 2024 07:09:25 -0700 (PDT) Received: from [192.168.10.3] ([151.95.155.52]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-41fe1ab43casm76679955e9.1.2024.05.13.07.09.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 May 2024 07:09:24 -0700 (PDT) Message-ID: <22def35f-5b8d-4424-a03b-c90e9174a14d@redhat.com> Date: Mon, 13 May 2024 16:09:22 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] sched/core: Drop spinlocks on contention iff kernel is preemptible To: Sean Christopherson , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot Cc: linux-kernel@vger.kernel.org, Valentin Schneider , Marco Elver , Frederic Weisbecker , David Matlack References: <20240110214723.695930-1-seanjc@google.com> From: Paolo Bonzini Content-Language: en-US Autocrypt: addr=pbonzini@redhat.com; keydata= xsEhBFRCcBIBDqDGsz4K0zZun3jh+U6Z9wNGLKQ0kSFyjN38gMqU1SfP+TUNQepFHb/Gc0E2 CxXPkIBTvYY+ZPkoTh5xF9oS1jqI8iRLzouzF8yXs3QjQIZ2SfuCxSVwlV65jotcjD2FTN04 hVopm9llFijNZpVIOGUTqzM4U55sdsCcZUluWM6x4HSOdw5F5Utxfp1wOjD/v92Lrax0hjiX DResHSt48q+8FrZzY+AUbkUS+Jm34qjswdrgsC5uxeVcLkBgWLmov2kMaMROT0YmFY6A3m1S P/kXmHDXxhe23gKb3dgwxUTpENDBGcfEzrzilWueOeUWiOcWuFOed/C3SyijBx3Av/lbCsHU Vx6pMycNTdzU1BuAroB+Y3mNEuW56Yd44jlInzG2UOwt9XjjdKkJZ1g0P9dwptwLEgTEd3Fo UdhAQyRXGYO8oROiuh+RZ1lXp6AQ4ZjoyH8WLfTLf5g1EKCTc4C1sy1vQSdzIRu3rBIjAvnC tGZADei1IExLqB3uzXKzZ1BZ+Z8hnt2og9hb7H0y8diYfEk2w3R7wEr+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ryEyTHQ+E42K3j2IUmOLriF dNr9NvE1QGmGyIcbw2NIVEBOK/GWxkS5+dmxM2iD4Jdaf2nSn3jlHjEXoPwpMs0KZsgdU0pP JQzMUMwmB1wM8JxovFlPYrhNT9MAEQEAAcLBMwQYAQIACQUCVEJx7gIbDAAKCRB+FRAMzTZp sadRDqCctLmYICZu4GSnie4lKXl+HqlLanpVMOoFNnWs9oRP47MbE2wv8OaYh5pNR9VVgyhD OG0AU7oidG36OeUlrFDTfnPYYSF/mPCxHttosyt8O5kabxnIPv2URuAxDByz+iVbL+RjKaGM GDph56ZTswlx75nZVtIukqzLAQ5fa8OALSGum0cFi4ptZUOhDNz1onz61klD6z3MODi0sBZN Aj6guB2L/+2ZwElZEeRBERRd/uommlYuToAXfNRdUwrwl9gRMiA0WSyTb190zneRRDfpSK5d usXnM/O+kr3Dm+Ui+UioPf6wgbn3T0o6I5BhVhs4h4hWmIW7iNhPjX1iybXfmb1gAFfjtHfL xRUr64svXpyfJMScIQtBAm0ihWPltXkyITA92ngCmPdHa6M1hMh4RDX+Jf1fiWubzp1voAg0 JBrdmNZSQDz0iKmSrx8xkoXYfA3bgtFN8WJH2xgFL28XnqY4M6dLhJwV3z08tPSRqYFm4NMP dRsn0/7oymhneL8RthIvjDDQ5ktUjMe8LtHr70OZE/TT88qvEdhiIVUogHdo4qBrk41+gGQh b906Dudw5YhTJFU3nC6bbF2nrLlB4C/XSiH76ZvqzV0Z/cAMBo5NF/w= In-Reply-To: <20240110214723.695930-1-seanjc@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/10/24 22:47, Sean Christopherson wrote: > Use preempt_model_preemptible() to detect a preemptible kernel when > deciding whether or not to reschedule in order to drop a contended > spinlock or rwlock. Because PREEMPT_DYNAMIC selects PREEMPTION, kernels > built with PREEMPT_DYNAMIC=y will yield contended locks even if the live > preemption model is "none" or "voluntary". In short, make kernels with > dynamically selected models behave the same as kernels with statically > selected models. Peter, looks like this patch fell through the cracks. Could this be applied for 6.10? There is a slightly confusing line in the commit message below, so that it reads more like an RFC; but the patch fixes a CONFIG_PREEMPT_DYNAMIC regression wrt static preemption models and has no functional change for !CONFIG_PREEMPT_DYNAMIC. > Somewhat counter-intuitively, NOT yielding a lock can provide better > latency for the relevant tasks/processes. E.g. KVM x86's mmu_lock, a > rwlock, is often contended between an invalidation event (takes mmu_lock > for write) and a vCPU servicing a guest page fault (takes mmu_lock for > read). For _some_ setups, letting the invalidation task complete even > if there is mmu_lock contention provides lower latency for *all* tasks, > i.e. the invalidation completes sooner *and* the vCPU services the guest > page fault sooner. > > But even KVM's mmu_lock behavior isn't uniform, e.g. the "best" behavior > can vary depending on the host VMM, the guest workload, the number of > vCPUs, the number of pCPUs in the host, why there is lock contention, etc. > > In other words, simply deleting the CONFIG_PREEMPTION guard (or doing the ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This should be "deleting the preempt_model_preemptible() guard" given that the patch does delete CONFIG_PREEMPTION, and only leaves preempt_model_preemptible() in place. Thanks, Paolo > opposite and removing contention yielding entirely) needs to come with a > big pile of data proving that changing the status quo is a net positive. > > Cc: Valentin Schneider > Cc: Peter Zijlstra (Intel) > Cc: Marco Elver > Cc: Frederic Weisbecker > Cc: David Matlack > Signed-off-by: Sean Christopherson > --- > include/linux/sched.h | 14 ++++++-------- > 1 file changed, 6 insertions(+), 8 deletions(-) > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index 03bfe9ab2951..51550e64ce14 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -2229,11 +2229,10 @@ static inline bool preempt_model_preemptible(void) > */ > static inline int spin_needbreak(spinlock_t *lock) > { > -#ifdef CONFIG_PREEMPTION > + if (!preempt_model_preemptible()) > + return 0; > + > return spin_is_contended(lock); > -#else > - return 0; > -#endif > } > > /* > @@ -2246,11 +2245,10 @@ static inline int spin_needbreak(spinlock_t *lock) > */ > static inline int rwlock_needbreak(rwlock_t *lock) > { > -#ifdef CONFIG_PREEMPTION > + if (!preempt_model_preemptible()) > + return 0; > + > return rwlock_is_contended(lock); > -#else > - return 0; > -#endif > } > > static __always_inline bool need_resched(void) > > base-commit: cdb3033e191fd03da2d7da23b9cd448dfa180a8e