Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp84981lqb; Tue, 28 May 2024 09:26:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXAGo8dQG93CZgT5414dPM3ToL1abYV5QdfnVheImi6Z6nUW/XUAohXZxoRDuS1y3IbZIf+MkhMxXerM7Nd++kCRwPizXifOg1WwO2zCQ== X-Google-Smtp-Source: AGHT+IFhDU5eiYC6hxYgEM7XT3BmldqBNWK+DcWfazAYiriPCy5JzHrBb+lSALMBeS8kKbTF0x2/ X-Received: by 2002:a05:6512:313a:b0:51d:9808:6645 with SMTP id 2adb3069b0e04-52966e9aff7mr10865839e87.50.1716913600030; Tue, 28 May 2024 09:26:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716913600; cv=pass; d=google.com; s=arc-20160816; b=b2RpQW0zzq/NDM1Flw7LL64uSw+KYjjUH2mCqq8ecyueKy95AZqd0FOIO30VyOLxuT TMW/QlYkDJHQ7H2TUboXgWwavwwNg0FgywbfP0UDdQkRPoi1XHp5N/MIIBfPK9CzLLji 46k++fvo+hczZSq9ILElSiokNgCj6b4ZqH6Lpligs5xdJ53/6b2bHZMtPc5boFgfyBFe A704IAPE13TL5Wi7ocKL7i5yVZ4lcOtnOBqVdbdw9aI2HYfkZJ3Lar6QAcLhzghMRuWB 1VxQVDSZH/iD7KK5hqbpA9DdkD9KoBCAcYNETTEKK6/7B5h9L5zCxbyaDWupk5sLI3wB YH7A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=wSXL2SlOjEvveaaFF85+qhUrKzO5LhurNd/gv2GGsio=; fh=E6nMY2SCCK07HbGulrZp7JUfPuXw9pDP0AaUuxDtGK0=; b=wwaHav3Zx48RnxuvM2puV8YWZ7yZGCDTGG0pbCx1rORChJn3BDDZlQSPsTp19YQihV RYeFeK14I3yFv3pyOr7M1JRyF7TH38WPU2PyF+uVCpIjTFCt3/N3dshBn5NHFcUwj6Bn Of8ADKUk/zIVbDnkeMlXPXJ+X12LyWOI2rDbWqYKxrhwjaioQY6PVFjpFFQkXAsry8yk +c877sxZPxVWtMm9AvyLYuZDn0KiXxxhUz1HVUyInBnMEvfOiJX8cVogghLHhUnn5uXa MpiT27eSd+lweqO8vxOrC+aVdurzYJTOqH2Vn6nwCF/RYt6ul9NfpYbF+fkOFQwaVDPz fX4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=T5s+JUTi; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-192750-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192750-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626c7fef54si519729166b.8.2024.05.28.09.26.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 09:26:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192750-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=T5s+JUTi; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-192750-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192750-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 970F31F224C5 for ; Tue, 28 May 2024 16:26:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0FA67172BB6; Tue, 28 May 2024 16:26:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="T5s+JUTi" Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 C475316F91D for ; Tue, 28 May 2024 16:26:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716913590; cv=none; b=DhgjvBi8mUID/LNUhPPXXzFDTJwEgc7W12kdHSFDGunmPxaMfD6K14+1l6aziPF/Fe9KYmisLoaWlplCPDl4W/VHy9EWNNKNTEgDZEQhpKVblKR7Tab6HPb72CIT3D7qimI0i7WroNvOBYqOeZ5J3Fa2Vdli1wZ+S/tQeTEtgf4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716913590; c=relaxed/simple; bh=T+N5NCYcb/1CJ58rc8kq2NIC8cRUS+4Az8GxC7eQp3o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KbqFGZQ3U22dbBcWzKvFj9fQVVqc3MipXuL1o+dROHOcyg2ufiZmn8bgwXdF50EBSa6LFuk/qA5jHW6eU5flU9V4gxd0+zBw2FOHfzeMnpuXhfoaOh6tSd+w//m4MEK4HEZqgjHNbq2xHQY6J3JWdARrh67w8ksTVrMeucmbEKM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=T5s+JUTi; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=wSXL2SlOjEvveaaFF85+qhUrKzO5LhurNd/gv2GGsio=; b=T5s+JUTi6lcAVjA5PIaUX1c/mz C4tyNT9U3VRd7tFO5C9kEAPPexiEFVxeiJgF4WBLwiSamy0fY6VrpjjX6/szW6ONJdbHQQr7v/Z07 ik0cFPlB63q7W7E7Jlw7F+UxwmcewSwNfsMDKe5SWmiJXr0MaQ2UB8cCObBkxlq64k0WMzyu9DN8N cTvva43gOk/MK0lIY4t7vA907WVqcu2/qjl/cMij6AG7PFmU4LT6dz5yUtEXiP6S/oKkGizP0xZNM ZtRVl9t0r0L6d0WdWwLqLHkW3852Un4IVhDeQ0e9NMz+LNFQFMuN+kLdrha1olomSSc9k8BM7MVhV WN3KIGxQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sBzdn-0000000Bjaz-1Hfx; Tue, 28 May 2024 16:25:53 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id AFC3B30058E; Tue, 28 May 2024 18:25:34 +0200 (CEST) Date: Tue, 28 May 2024 18:25:34 +0200 From: Peter Zijlstra To: Ankur Arora Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org, paulmck@kernel.org, rostedt@goodmis.org, mark.rutland@arm.com, juri.lelli@redhat.com, joel@joelfernandes.org, raghavendra.kt@amd.com, sshegde@linux.ibm.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com, Ingo Molnar , Vincent Guittot Subject: Re: [PATCH v2 12/35] sched: separate PREEMPT_DYNAMIC config logic Message-ID: <20240528162534.GG26599@noisy.programming.kicks-ass.net> References: <20240528003521.979836-1-ankur.a.arora@oracle.com> <20240528003521.979836-13-ankur.a.arora@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240528003521.979836-13-ankur.a.arora@oracle.com> On Mon, May 27, 2024 at 05:34:58PM -0700, Ankur Arora wrote: > Pull out the PREEMPT_DYNAMIC setup logic to allow other preemption > models to dynamically configure preemption. Uh what ?!? What's the point of creating back-to-back #ifdef sections ? > Cc: Ingo Molnar > Cc: Peter Zijlstra > Cc: Juri Lelli > Cc: Vincent Guittot > Signed-off-by: Ankur Arora > --- > kernel/sched/core.c | 165 +++++++++++++++++++++++--------------------- > 1 file changed, 86 insertions(+), 79 deletions(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 0c26b60c1101..349f6257fdcd 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -8713,6 +8713,89 @@ int __cond_resched_rwlock_write(rwlock_t *lock) > } > EXPORT_SYMBOL(__cond_resched_rwlock_write); > > +#if defined(CONFIG_PREEMPT_DYNAMIC) > + > +#define PREEMPT_MODE "Dynamic Preempt" > + > +enum { > + preempt_dynamic_undefined = -1, > + preempt_dynamic_none, > + preempt_dynamic_voluntary, > + preempt_dynamic_full, > +}; > + > +int preempt_dynamic_mode = preempt_dynamic_undefined; > +static DEFINE_MUTEX(sched_dynamic_mutex); > + > +int sched_dynamic_mode(const char *str) > +{ > + if (!strcmp(str, "none")) > + return preempt_dynamic_none; > + > + if (!strcmp(str, "voluntary")) > + return preempt_dynamic_voluntary; > + > + if (!strcmp(str, "full")) > + return preempt_dynamic_full; > + > + return -EINVAL; > +} > + > +static void __sched_dynamic_update(int mode); > +void sched_dynamic_update(int mode) > +{ > + mutex_lock(&sched_dynamic_mutex); > + __sched_dynamic_update(mode); > + mutex_unlock(&sched_dynamic_mutex); > +} > + > +static void __init preempt_dynamic_init(void) > +{ > + if (preempt_dynamic_mode == preempt_dynamic_undefined) { > + if (IS_ENABLED(CONFIG_PREEMPT_NONE)) { > + sched_dynamic_update(preempt_dynamic_none); > + } else if (IS_ENABLED(CONFIG_PREEMPT_VOLUNTARY)) { > + sched_dynamic_update(preempt_dynamic_voluntary); > + } else { > + /* Default static call setting, nothing to do */ > + WARN_ON_ONCE(!IS_ENABLED(CONFIG_PREEMPT)); > + preempt_dynamic_mode = preempt_dynamic_full; > + pr_info("%s: full\n", PREEMPT_MODE); > + } > + } > +} > + > +static int __init setup_preempt_mode(char *str) > +{ > + int mode = sched_dynamic_mode(str); > + if (mode < 0) { > + pr_warn("%s: unsupported mode: %s\n", PREEMPT_MODE, str); > + return 0; > + } > + > + sched_dynamic_update(mode); > + return 1; > +} > +__setup("preempt=", setup_preempt_mode); > + > +#define PREEMPT_MODEL_ACCESSOR(mode) \ > + bool preempt_model_##mode(void) \ > + { \ > + WARN_ON_ONCE(preempt_dynamic_mode == preempt_dynamic_undefined); \ > + return preempt_dynamic_mode == preempt_dynamic_##mode; \ > + } \ > + EXPORT_SYMBOL_GPL(preempt_model_##mode) > + > +PREEMPT_MODEL_ACCESSOR(none); > +PREEMPT_MODEL_ACCESSOR(voluntary); > +PREEMPT_MODEL_ACCESSOR(full); > + > +#else /* !CONFIG_PREEMPT_DYNAMIC */ > + > +static inline void preempt_dynamic_init(void) { } > + > +#endif /* !CONFIG_PREEMPT_DYNAMIC */ > + > #ifdef CONFIG_PREEMPT_DYNAMIC > > #ifdef CONFIG_GENERIC_ENTRY > @@ -8749,29 +8832,6 @@ EXPORT_SYMBOL(__cond_resched_rwlock_write); > * irqentry_exit_cond_resched <- irqentry_exit_cond_resched > */ > > -enum { > - preempt_dynamic_undefined = -1, > - preempt_dynamic_none, > - preempt_dynamic_voluntary, > - preempt_dynamic_full, > -}; > - > -int preempt_dynamic_mode = preempt_dynamic_undefined; > - > -int sched_dynamic_mode(const char *str) > -{ > - if (!strcmp(str, "none")) > - return preempt_dynamic_none; > - > - if (!strcmp(str, "voluntary")) > - return preempt_dynamic_voluntary; > - > - if (!strcmp(str, "full")) > - return preempt_dynamic_full; > - > - return -EINVAL; > -} > - > #if defined(CONFIG_HAVE_PREEMPT_DYNAMIC_CALL) > #define preempt_dynamic_enable(f) static_call_update(f, f##_dynamic_enabled) > #define preempt_dynamic_disable(f) static_call_update(f, f##_dynamic_disabled) > @@ -8782,7 +8842,6 @@ int sched_dynamic_mode(const char *str) > #error "Unsupported PREEMPT_DYNAMIC mechanism" > #endif > > -static DEFINE_MUTEX(sched_dynamic_mutex); > static bool klp_override; > > static void __sched_dynamic_update(int mode) > @@ -8807,7 +8866,7 @@ static void __sched_dynamic_update(int mode) > preempt_dynamic_disable(preempt_schedule_notrace); > preempt_dynamic_disable(irqentry_exit_cond_resched); > if (mode != preempt_dynamic_mode) > - pr_info("Dynamic Preempt: none\n"); > + pr_info("%s: none\n", PREEMPT_MODE); > break; > > case preempt_dynamic_voluntary: > @@ -8818,7 +8877,7 @@ static void __sched_dynamic_update(int mode) > preempt_dynamic_disable(preempt_schedule_notrace); > preempt_dynamic_disable(irqentry_exit_cond_resched); > if (mode != preempt_dynamic_mode) > - pr_info("Dynamic Preempt: voluntary\n"); > + pr_info("%s: voluntary\n", PREEMPT_MODE); > break; > > case preempt_dynamic_full: > @@ -8829,20 +8888,13 @@ static void __sched_dynamic_update(int mode) > preempt_dynamic_enable(preempt_schedule_notrace); > preempt_dynamic_enable(irqentry_exit_cond_resched); > if (mode != preempt_dynamic_mode) > - pr_info("Dynamic Preempt: full\n"); > + pr_info("%s: full\n", PREEMPT_MODE); > break; > } > > preempt_dynamic_mode = mode; > } > > -void sched_dynamic_update(int mode) > -{ > - mutex_lock(&sched_dynamic_mutex); > - __sched_dynamic_update(mode); > - mutex_unlock(&sched_dynamic_mutex); > -} > - > #ifdef CONFIG_HAVE_PREEMPT_DYNAMIC_CALL > > static int klp_cond_resched(void) > @@ -8873,51 +8925,6 @@ void sched_dynamic_klp_disable(void) > > #endif /* CONFIG_HAVE_PREEMPT_DYNAMIC_CALL */ > > -static int __init setup_preempt_mode(char *str) > -{ > - int mode = sched_dynamic_mode(str); > - if (mode < 0) { > - pr_warn("Dynamic Preempt: unsupported mode: %s\n", str); > - return 0; > - } > - > - sched_dynamic_update(mode); > - return 1; > -} > -__setup("preempt=", setup_preempt_mode); > - > -static void __init preempt_dynamic_init(void) > -{ > - if (preempt_dynamic_mode == preempt_dynamic_undefined) { > - if (IS_ENABLED(CONFIG_PREEMPT_NONE)) { > - sched_dynamic_update(preempt_dynamic_none); > - } else if (IS_ENABLED(CONFIG_PREEMPT_VOLUNTARY)) { > - sched_dynamic_update(preempt_dynamic_voluntary); > - } else { > - /* Default static call setting, nothing to do */ > - WARN_ON_ONCE(!IS_ENABLED(CONFIG_PREEMPT)); > - preempt_dynamic_mode = preempt_dynamic_full; > - pr_info("Dynamic Preempt: full\n"); > - } > - } > -} > - > -#define PREEMPT_MODEL_ACCESSOR(mode) \ > - bool preempt_model_##mode(void) \ > - { \ > - WARN_ON_ONCE(preempt_dynamic_mode == preempt_dynamic_undefined); \ > - return preempt_dynamic_mode == preempt_dynamic_##mode; \ > - } \ > - EXPORT_SYMBOL_GPL(preempt_model_##mode) > - > -PREEMPT_MODEL_ACCESSOR(none); > -PREEMPT_MODEL_ACCESSOR(voluntary); > -PREEMPT_MODEL_ACCESSOR(full); > - > -#else /* !CONFIG_PREEMPT_DYNAMIC */ > - > -static inline void preempt_dynamic_init(void) { } > - > #endif /* #ifdef CONFIG_PREEMPT_DYNAMIC */ > > /** > -- > 2.31.1 >