Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1263518lqd; Thu, 25 Apr 2024 10:06:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXtPoh55MYP3A1L6joFS0bDYkGnoJf4bp/nbcOWkViRbVc+gmWVt+s8VpyfqUMgxmdqLRxPohwDNJx1ZzcWpV4+6i1b4aI9cHnrySIHrQ== X-Google-Smtp-Source: AGHT+IE2n/xdWzkIO3QynH4sSTpoo7POYha9Ojt3+DpmU2oKt6laQMlbqdKXFKA260k4+FL1nMYG X-Received: by 2002:a05:6e02:160f:b0:36c:f61:7648 with SMTP id t15-20020a056e02160f00b0036c0f617648mr433646ilu.13.1714064818181; Thu, 25 Apr 2024 10:06:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714064818; cv=pass; d=google.com; s=arc-20160816; b=1HZgQ61LyQJ9RqKSrnPP+cWTGwy5QxIbRm/zmcT+L297Q3Qh/W9h4DS15B9H4W2frD Af4Xgsgfd9ecHAMFZr14OVHHQnsM16N+SevHyLYDLjUhxnqQ2a3r4KN/ihHO7bpMlW0q M7zxD6WJD42WDzjTOjOwSSvK7Bi7WRmerRcU0kBSRfFWz0czWhCgvc9iCo8+460wSYya DhsDXhAmMRc66wQhHbUfa3Q1evjcPvm4xIo0QVkkG0DFSsZGTBpPLRp7dMLEP3xo/WfN DKLt11V2BUmVc2l2kBAsI3cedgSvGNpA1123s8/Ct0Vo2KRxgOzkBobyOCX6DiZOnxf4 bU/Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=yUi3/+xNdVFJEzzlh8zAE5pQn6TguDhgQbf8j/v/Q+k=; fh=6qsWYlxOLucmkQzOF9rPYfjmrXxdBIyQUe8Rj98kly4=; b=Sm9hQEHA33TBsxDM+pKQWN/ihf/u8GSdu1RUmus6lwbcFDF3+Vg9KBnjnfS0mPFWao 6KNxnCVgsNjKgDF4FLvPSNuIfWs8R9voMQjY1uoF9s+JScYprp3LhMsLSUsYnG3GaKAL DTBNuZuRcDa95bs3SW6OwsmDci9CkJD2EqHTRiz7WTXMODRt+efcfBrldCn6BN/YPiSe iMqLc0Hu5dsKwvXD2uBxYfd+avbmaIfx+s8A6g7hyYrSelqrh/38+rNdi7OzFV4CZo34 MEUBE19/IeG/9U1DGPhSSEkdNg5llWTNUGn3OXIfnxeph1+HB4Bjz0FKmg8BB1EUi6ck VqXQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=kbmLg2A4; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-158927-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158927-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id l73-20020a633e4c000000b005f77b2c2f5esi13663471pga.293.2024.04.25.10.06.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 10:06:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158927-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=kbmLg2A4; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-158927-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158927-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 580E6B24B65 for ; Thu, 25 Apr 2024 16:48:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0EE014D6EB; Thu, 25 Apr 2024 16:47:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kbmLg2A4" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B388614B083 for ; Thu, 25 Apr 2024 16:47:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714063676; cv=none; b=Fvv6YoyqACUTF3S3hq9IOCBPkfuRPzx3gOtB0ywDeoUe+BF5WWXCfkl0hsWZ6Sh1NYRvEBSCMvEEFVEFfri+F2APPJchmjoBmll62Dvg9J11cpvgytzPHvFcISR3fBI33Ut+5Jg5xpBjIGml5U9zrIaTza9/Eo6M6NptPz0ekIY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714063676; c=relaxed/simple; bh=mpfNiz5ay5zCRSFe3zz3PlriOfJFIhumbATm0QJYobU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eWlkRidx82tnwKwZx3KJHV7WCFk+pVun9bmlA2zyeGCM7bblmbT8RauCQlzXyoVfdPRX2s75vhOIAFO/N35liigc7uoUXEG/D0v8uLRrjsY411EwZfpwpH1hu8XuPFJwtX9EvRAa4OT/5H3Rwqb98YJ75/ob24Iy8QBYg5bL8vk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=kbmLg2A4; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6dbdcfd39so2542280276.2 for ; Thu, 25 Apr 2024 09:47:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714063673; x=1714668473; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yUi3/+xNdVFJEzzlh8zAE5pQn6TguDhgQbf8j/v/Q+k=; b=kbmLg2A4qxM9q4P2jYqlaMTX+nsJtgfcVbTUJB0INZmllPPwkzgk0s/c1VQG3PdcYu vd3n0NvHpyhysShoRe6opm79Q23ee7MvPXdp6xhNE33oylvJq0D8S+kX1GJMSJrF00On ah3xqlEkdFGda3ykeeMMzHltyCLa3p9BNqXA+Uv4X2NJEW98BEI134ASODJua4slkX8K 7bYim1AySp0CCbYJHZ9n+kosfKgBreDgWdhvbuTO8ier01QQr0/W6UDzMJhRCpC4GMhz wtShJ9hAzIVnHOkm34VkU6fV6O0zdbK6rbuNN/Uk1Y+SJooEPFK1czYKtCM2l2r0A2dU /ijw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714063673; x=1714668473; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yUi3/+xNdVFJEzzlh8zAE5pQn6TguDhgQbf8j/v/Q+k=; b=tn/3lc1t2NKBEXlLLX6QHUKDoLSyqV2QlYG7lEZRekUJrWe6WTvcasY+oihDP6nRhS jLHHICk1ukBjJ+fUOJR6IFudxEIft/2tQmFFmQtvP4jsumqRv0v8o3mlTWP/oGK/J1fE JVSEn3DkME7gV48Dx9hVQCtA+UJ3krm+FAsZn/vFr8j6zSYqjFhbb1ACkAdL6StNwSV0 w7BAjW5xzoeyVKr/WkxHf9WtVMslb+Msx1LFvekvKvuL2oA6IZhINxhPop5yeOv1TjDu RXsijUPGp+BlwP6UMXYrKEmO/s2cZAxpby6HlgIeAY2dhDpAclaqoHLIhh1hwHvRckev KrVg== X-Forwarded-Encrypted: i=1; AJvYcCVnWDoab813BHjI/kx7BfDp9PlblQhkGqRdL32G7FVSScbj2mBR/F4ewfti7hAvWT7p9wEIn+RfmlVsKqIVp4zUmxuGCmdkjiO/RA+1 X-Gm-Message-State: AOJu0Yyh5CtbN6KTr2jyFyPTjdgzK82vnPYLTdeQ8IWHfc1cqawAVa7c v1H8Z97RV6QD1Oi7mV9h14VtHA4zBvG5g0PEhKHe9os+tjdzF6OkHRPPtbOHRgY+kQEwBwsmNjI zPQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:f81:b0:de4:7bae:3333 with SMTP id ft1-20020a0569020f8100b00de47bae3333mr41295ybb.3.1714063673677; Thu, 25 Apr 2024 09:47:53 -0700 (PDT) Date: Thu, 25 Apr 2024 09:47:52 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240312193911.1796717-1-seanjc@google.com> <20240312193911.1796717-3-seanjc@google.com> Message-ID: Subject: Re: [PATCH v2 2/2] sched/core: Drop spinlocks on contention iff kernel is preemptible From: Sean Christopherson To: Chen Yu Cc: Jonathan Corbet , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Will Deacon , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Valentin Schneider , Marco Elver , Frederic Weisbecker , David Matlack , Friedrich Weber , Ankur Arora , Thomas Gleixner Content-Type: text/plain; charset="us-ascii" On Thu, Apr 25, 2024, Chen Yu wrote: > Hi Sean, > > On 2024-03-12 at 12:39:11 -0700, 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 > > It took me a while to wonder why PREEMPT_DYNAMIC selects PREEMPTION > in Kconfig, then I assume that you mean the static config is CONFIG_PREEMPTION, > but the live preemption model is "none" or "voluntary", which makes the > static check of CONFIG_PREEMPTION in spin_needbreak() and rwlock_needbreak() > invalid? Yep, exactly. > > diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h > > index 3fcd20de6ca8..63dd8cf3c3c2 100644 > > --- a/include/linux/spinlock.h > > +++ b/include/linux/spinlock.h > > @@ -462,11 +462,10 @@ static __always_inline int spin_is_contended(spinlock_t *lock) > > */ > > static inline int spin_needbreak(spinlock_t *lock) > > { > > -#ifdef CONFIG_PREEMPTION > > + if (!preempt_model_preemptible()) > > The old version checks against static CONFIG_PREEMPTION, now we check > the live CONFIG_PREEMPTION and static CONFIG_PREEMPT_RT, just wonder > if the rt check is needed here? It's required, as CONFIG_PREEMPT_RT=y doesn't imply CONFIG_PREEMPT, and CONFIG_PREEMPT_RT=y is mutually exclusive with CONFIG_PREEMPT_DYNAMIC. I.e. a CONFIG_PREEMPT_RT=y kernel will look yield: CONFIG_PREEMPT_RT=y CONFIG_PREEMPT_DYNAMIC=n CONFIG_PREEMPT=n which in turn generates: static inline bool preempt_model_full(void) { return IS_ENABLED(CONFIG_PREEMPT); } and so just checking preempt_model_full() would incorrectly return false for CONFIG_PREEMPT_RT=y.