Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5727831rdb; Wed, 13 Dec 2023 18:47:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTV8PH9OQfrsv1TIdHOA7MIXhkdWyl5AXbylK4uQUDiuwx9jC7Ha3Sw7crQjeam0XrGyOI X-Received: by 2002:a17:902:7ed0:b0:1d1:cc09:50ac with SMTP id p16-20020a1709027ed000b001d1cc0950acmr7182752plb.108.1702522067619; Wed, 13 Dec 2023 18:47:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702522067; cv=none; d=google.com; s=arc-20160816; b=XRulb9iqgtltoxE9LadiH+89VZLU99KtfwDuAmK+eCPisunh+ea+69ENh4cFAIMSgX dve2+OPvcGF9+0NM0EliA9Zy6HYZCrqLrcDWZWUpClDdaUQJcqby3YuxDnmVQFXVwCmO +gWUzdxFGbNQRkLY119oTQZEt7oPYM0hfUFLkr15KE40dJNDJ4Vp8nrczQyE0ehMSwK8 0qqd3D7rrrZ4lTnQ2sXEDkWBSMBfcJP2p8hyQ3+/4nqlTuICAVpkhClY7wplZ3ORUihy ARLZP+p/9UUN207sC0rA7NI+C+W7YE89fT77XDZeGmfTlEe3ZBFYlcBSZplRRnXuKXBb rMRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lIavbINZh5nYTp8Oo+UkDFK4yofTsKFYo/9aAWUfbh4=; fh=Hbu4MRXj4Q94vUKfDX1mjGpHBSdmtBc1IGlS5ymJxtY=; b=qsSTebZXDT66dvkz0suwkKa/mVXbbWX2hGfKpqYnoFnzSjaS26W6z87dQos664kCZQ Pr9uWsIfDbcUUo9CnqhGTmB4PzCuUyDETgdO0bwIP2NoBCnJVGF7Uf/EyfJ0JxaJojne hZz5ot6Tgzk1EkRV3x7aKf1lwQrvVKnkHDNaBQJ7LuxhaLM5u938PdzuTzFKXXp6lBxI +j5RmuQZw7vJyKmWfaCs9cYrxHtWa6zmusaf9dLlbqrM1FxvzxzoOwwBUaBrejDMv7mb EDMtK4E+xK62VL6M1zAjPCnKIsDHJ97NeMNJfS8pPhgonA+aIJToHvG4JGuCRibCgxMC gYIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bitbyteword.org header.s=google header.b=pyaRSrZE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id p3-20020a1709028a8300b001cfbd3f391bsi10158339plo.226.2023.12.13.18.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 18:47:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@bitbyteword.org header.s=google header.b=pyaRSrZE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 43F5580C65FC; Wed, 13 Dec 2023 18:47:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235191AbjLNCrc (ORCPT + 99 others); Wed, 13 Dec 2023 21:47:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234176AbjLNCra (ORCPT ); Wed, 13 Dec 2023 21:47:30 -0500 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F399F7 for ; Wed, 13 Dec 2023 18:47:36 -0800 (PST) Received: by mail-qt1-x82a.google.com with SMTP id d75a77b69052e-4258026a9fdso46758941cf.0 for ; Wed, 13 Dec 2023 18:47:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitbyteword.org; s=google; t=1702522055; x=1703126855; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lIavbINZh5nYTp8Oo+UkDFK4yofTsKFYo/9aAWUfbh4=; b=pyaRSrZE9bUbL1v6wRSTh/KrGJhVI/H81tqlpUnSBayz57AhzMTxw5v7ZKAw2Qrbm4 8/1K/8T10ZhhTHu4BcZqfttWcaylyFiHInRdINWJtnoaBoJDQW0DWkk8qS4enaJO5zZ3 xrGMo4CskepCFD/mNh7c+6AZ961di3QTiuzBnAB41nTbCqr1sRfcXuNjYaMoK9t0VRd4 JGq6CI6L7jmAIxKhMYJBFHL+Q/2lz2pKlI0tcAwsV+ds+HHJeo6EAjPxVaiIGp5F1+P9 v5ONl1fej1S+bJWAAy84U2xfxD67IVTP+PHXvWufjaPiVLiEl+sCgzVANIX/MCs+vE1r Qj4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702522055; x=1703126855; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lIavbINZh5nYTp8Oo+UkDFK4yofTsKFYo/9aAWUfbh4=; b=rEHqJM/M8MNU64I5ouMChREwUZazxLQr9jW3lAb6x4TDF5qe/PQ+V6tjy1ri1mgiyS AyQ1693vK1F0Vwgu7qMV9gVNtDpmCrPiDb0sp6ZqeD2+TMlwJWTkr7GWAc6+GpgBPWpX RvYKQuMUvtOs/WmQs45W+DLBsKVWo7hujuBzKTNQdxa/jo7wtTllqYhAc40Van8JN0n3 UfR0CFFx6CEfXUUrGSXxvPbijq15FO/t1MoGZMqK3n8mc5NK8ky1fIcEfF3gEm7+DauJ bwhwoCgC8qpGsfWvyhSmxoPjKqnbfCK0LC2XjFM3ZZlas6yea1VDH+M+zbdLTtsHgpfO 2ITg== X-Gm-Message-State: AOJu0YzLBdydomF/xFMEltvT3BFLjgPOI/6aE5M5qfxT7QIHKVnBP7Dn a5Sy3NZUArJ5tfQoXLo4etTNTg== X-Received: by 2002:a05:622a:8d:b0:425:4043:29fc with SMTP id o13-20020a05622a008d00b00425404329fcmr12342292qtw.119.1702522055644; Wed, 13 Dec 2023 18:47:35 -0800 (PST) Received: from vinp3lin.lan (c-73-143-21-186.hsd1.vt.comcast.net. [73.143.21.186]) by smtp.gmail.com with ESMTPSA id fh3-20020a05622a588300b00425b356b919sm4240208qtb.55.2023.12.13.18.47.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 18:47:35 -0800 (PST) From: "Vineeth Pillai (Google)" To: Ben Segall , Borislav Petkov , Daniel Bristot de Oliveira , Dave Hansen , Dietmar Eggemann , "H . Peter Anvin" , Ingo Molnar , Juri Lelli , Mel Gorman , Paolo Bonzini , Andy Lutomirski , Peter Zijlstra , Sean Christopherson , Steven Rostedt , Thomas Gleixner , Valentin Schneider , Vincent Guittot , Vitaly Kuznetsov , Wanpeng Li Cc: "Vineeth Pillai (Google)" , Suleiman Souhlal , Masami Hiramatsu , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Joel Fernandes Subject: [RFC PATCH 2/8] sched/core: sched_setscheduler_pi_nocheck for interrupt context usage Date: Wed, 13 Dec 2023 21:47:19 -0500 Message-ID: <20231214024727.3503870-3-vineeth@bitbyteword.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231214024727.3503870-1-vineeth@bitbyteword.org> References: <20231214024727.3503870-1-vineeth@bitbyteword.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 13 Dec 2023 18:47:46 -0800 (PST) __sched_setscheduler takes an argument 'pi' so as to allow its usage in interrupt context when PI is not used. But this is not exported and cannot be used outside of scheduler code. sched_setscheduler_nocheck is exported but it doesn't allow that flexibility. Introduce sched_setscheduler_pi_nocheck to allow for the flexibility to call from interrupt context Co-developed-by: Joel Fernandes (Google) Signed-off-by: Joel Fernandes (Google) Signed-off-by: Vineeth Pillai (Google) --- include/linux/sched.h | 2 ++ kernel/sched/core.c | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 609bde814cb0..de7382f149cf 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1908,6 +1908,8 @@ extern int idle_cpu(int cpu); extern int available_idle_cpu(int cpu); extern int sched_setscheduler(struct task_struct *, int, const struct sched_param *); extern int sched_setscheduler_nocheck(struct task_struct *, int, const struct sched_param *); +extern int sched_setscheduler_pi_nocheck(struct task_struct *p, int policy, + const struct sched_param *sp, bool pi); extern void sched_set_fifo(struct task_struct *p); extern void sched_set_fifo_low(struct task_struct *p); extern void sched_set_normal(struct task_struct *p, int nice); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index e8f73ff12126..b47f72b6595f 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7850,8 +7850,8 @@ static int __sched_setscheduler(struct task_struct *p, return retval; } -static int _sched_setscheduler(struct task_struct *p, int policy, - const struct sched_param *param, bool check) +static int _sched_setscheduler_pi(struct task_struct *p, int policy, + const struct sched_param *param, bool check, bool pi) { struct sched_attr attr = { .sched_policy = policy, @@ -7866,8 +7866,15 @@ static int _sched_setscheduler(struct task_struct *p, int policy, attr.sched_policy = policy; } - return __sched_setscheduler(p, &attr, check, true); + return __sched_setscheduler(p, &attr, check, pi); +} + +static inline int _sched_setscheduler(struct task_struct *p, int policy, + const struct sched_param *param, bool check) +{ + return _sched_setscheduler_pi(p, policy, param, check, true); } + /** * sched_setscheduler - change the scheduling policy and/or RT priority of a thread. * @p: the task in question. @@ -7916,6 +7923,27 @@ int sched_setscheduler_nocheck(struct task_struct *p, int policy, return _sched_setscheduler(p, policy, param, false); } +/** + * sched_setscheduler_pi_nocheck - change the scheduling policy and/or RT priority of a thread from kernelspace. + * @p: the task in question. + * @policy: new policy. + * @param: structure containing the new RT priority. + * @pi: boolean flag stating if pi validation needs to be performed. + * + * A flexible version of sched_setcheduler_nocheck which allows for specifying + * whether PI context validation needs to be done or not. set_scheduler_nocheck + * is not allowed in interrupt context as it assumes that PI is used. + * This function allows interrupt context call by specifying pi = false. + * + * Return: 0 on success. An error code otherwise. + */ +int sched_setscheduler_pi_nocheck(struct task_struct *p, int policy, + const struct sched_param *param, bool pi) +{ + return _sched_setscheduler_pi(p, policy, param, false, pi); +} +EXPORT_SYMBOL_GPL(sched_setscheduler_pi_nocheck); + /* * SCHED_FIFO is a broken scheduler model; that is, it is fundamentally * incapable of resource management, which is the one thing an OS really should -- 2.43.0