Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp36131904rwd; Mon, 10 Jul 2023 18:46:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlGzkvZ4m6MzGU6PUc747tK79UemuNkmjo7MkF5pnnVSs1OCbyyU2/nkpdob/+IDRof7jDG5 X-Received: by 2002:a17:906:4dce:b0:991:e17c:f8fa with SMTP id f14-20020a1709064dce00b00991e17cf8famr11885737ejw.61.1689039966258; Mon, 10 Jul 2023 18:46:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689039966; cv=none; d=google.com; s=arc-20160816; b=zzDW58HwGyrYbLAGQjSeO08K3rRf6T/T8xjyuo8ncqB6fRB89kp9n+c2EswVd2cFCv b5CClQ9XXQjtg5GuoPJPIhYEiSL0u515y72l7Ck3kj1QipzZ2dmMIm0jbTw1BMPcxCIG lh9MRgJm0/AdaY/rFH9+05yzwnvdazFsXXMUp+L8R1i/Nxk5d5vG9mJChap0279LMP1v v8QbIewJpcTA2WAoJuELiFKJTaSIwVvhrenrccR/dZP6532dIGU+Lx2k2n2dciNsSmgN HRXETHZynqj63zR4STbMXsfEIVREVLjvA+QXJ9oeSCm2nSkOveKM/6559nQN/o81vjZD 2tsA== 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:sender :dkim-signature; bh=+tYps2k7FntAJcDgxrMW3BMcrEpXH1yKukKcIVwMfEs=; fh=5bvFqXZy/VrzcWOXnXaaKVCt2r2P+2FQUI6EKkM71t8=; b=eG44feddp2B6lTknNyZwL3P2bjEDxvyz1bVnSAvNk36/xAGjML+aqcPleMLHN3ovrQ h/5Qz82Ym/rchvi6iYGECV/NPmu9kCyZ2GK+vv7fm/2pFQW0X0kocN65nSvIb6nHWhwe jxUOIE4LhY2UONWJB6qcqLirGRQyg5LBJGj83Hz1GbWbhQDCzfNXS72tZDNDuxPc8jVn 92Ro5Pbqw36tAdRTpmUJfQb9al9biB+RF2z62bLIZ34C9vNjtju1R2q6drQ9uJ+DeSXp MGSF6NWJdoGTCrIuyVazXS+3XfoB9pw7DtuRZO6xNlPprIY+KMu6IRzuBJMPfeHLLyXF 11OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=LQ5hYeAY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s19-20020a170906169300b0098e1627c0e4si925340ejd.777.2023.07.10.18.45.41; Mon, 10 Jul 2023 18:46:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=LQ5hYeAY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231556AbjGKBPj (ORCPT + 99 others); Mon, 10 Jul 2023 21:15:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231361AbjGKBPV (ORCPT ); Mon, 10 Jul 2023 21:15:21 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91106E6F; Mon, 10 Jul 2023 18:14:45 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6689430d803so2674357b3a.0; Mon, 10 Jul 2023 18:14:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689038084; x=1691630084; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=+tYps2k7FntAJcDgxrMW3BMcrEpXH1yKukKcIVwMfEs=; b=LQ5hYeAYtfLNdodZiytb8PmLv/7pqQYriIk9XN9F0YoCZOBRtpBG6s5q7rHnDTJHkK +1GzxaM82IuCps5Bi3JbhDdo5DAWdOwQwj98wtDOxA+k0EIX5SsTpE0IuRwe8Ar1Mwmi vpDfUbqdEEPVMxx+4KYrvSe45OY3KeKGJtcoHwTLoBaoQxjtBCNibkZ34Vky7o3aGXV0 qCSwnjx8biI7SXKgDTkWbjfgZZMKLgwDvCBB8EZkj0fOUj+cPWhI185p+ZmVfYUkI46y 4c+OAf58QQcy/vm/Id5ZU7a6/JM6v+KFvm3+NqjPrGuJ2jCG7W4Iboj7C5TSAacE2xjv P/ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689038084; x=1691630084; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=+tYps2k7FntAJcDgxrMW3BMcrEpXH1yKukKcIVwMfEs=; b=VwtIT2FGZZCRyDVCx6zAK44TilKzkviz0Wzb10MP28b0yH0+L6vGe0FE+MLtMZsbE5 wEdoBcv/474RZFIL9D36ypIvleE3cns7GAZUuhKxkZl6Zi1K7WEWoDE3msKRHEkeTmP2 Ay4WiuNi4tnIrmrOxKm7Ru0/CbIAiDFF00de7fnZjkK2NEc2Vk962JQCJ1IRr1PZ8IMG ENDQx62DG/j/lz0DmH19mbn41QBhe1bBoJ4XAkl6QFnWMWj2Yxdwpxfjoa1Q8XMjR1nB um7Him3KJLceezzE6iHSmSD2OIIIisSOsL9r3VzE//aYzwVIpK1mvulyk9jJE676ucAl 7+iA== X-Gm-Message-State: ABy/qLb/C9bEWqvFU4hG31BL9TZLXWuSFL5Ej7s6tXYTLTumkrRaf+Ag THcDsqW8Ws4nHEg5qMKxy5I= X-Received: by 2002:a05:6a00:80f:b0:67f:e74a:d309 with SMTP id m15-20020a056a00080f00b0067fe74ad309mr14388426pfk.30.1689038084289; Mon, 10 Jul 2023 18:14:44 -0700 (PDT) Received: from localhost ([2620:10d:c090:400::5:e2fe]) by smtp.gmail.com with ESMTPSA id m16-20020aa79010000000b006579b062d5dsm421669pfo.21.2023.07.10.18.14.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 18:14:43 -0700 (PDT) Sender: Tejun Heo From: Tejun Heo To: torvalds@linux-foundation.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org, joshdon@google.com, brho@google.com, pjt@google.com, derkling@google.com, haoluo@google.com, dvernet@meta.com, dschatzberg@meta.com, dskarlat@cs.cmu.edu, riel@surriel.com Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, kernel-team@meta.com, Tejun Heo Subject: [PATCH 14/34] sched_ext: Add sysrq-S which disables the BPF scheduler Date: Mon, 10 Jul 2023 15:13:32 -1000 Message-ID: <20230711011412.100319-15-tj@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230711011412.100319-1-tj@kernel.org> References: <20230711011412.100319-1-tj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 This enables the admin to abort the BPF scheduler and revert to CFS anytime. Signed-off-by: Tejun Heo Reviewed-by: David Vernet Acked-by: Josh Don Acked-by: Hao Luo Acked-by: Barret Rhoden --- drivers/tty/sysrq.c | 1 + include/linux/sched/ext.h | 1 + kernel/sched/build_policy.c | 1 + kernel/sched/ext.c | 20 ++++++++++++++++++++ 4 files changed, 23 insertions(+) diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index b6e70c5cfa17..ddfcdb6aecd7 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -520,6 +520,7 @@ static const struct sysrq_key_op *sysrq_key_table[62] = { NULL, /* P */ NULL, /* Q */ NULL, /* R */ + /* S: May be registered by sched_ext for resetting */ NULL, /* S */ NULL, /* T */ NULL, /* U */ diff --git a/include/linux/sched/ext.h b/include/linux/sched/ext.h index 92011a63cc15..2f24642bbf2e 100644 --- a/include/linux/sched/ext.h +++ b/include/linux/sched/ext.h @@ -55,6 +55,7 @@ enum scx_exit_type { SCX_EXIT_DONE, SCX_EXIT_UNREG = 64, /* BPF unregistration */ + SCX_EXIT_SYSRQ, /* requested by 'S' sysrq */ SCX_EXIT_ERROR = 1024, /* runtime error, error msg contains details */ SCX_EXIT_ERROR_BPF, /* ERROR but triggered through scx_bpf_error() */ diff --git a/kernel/sched/build_policy.c b/kernel/sched/build_policy.c index 4c658b21f603..005025f55bea 100644 --- a/kernel/sched/build_policy.c +++ b/kernel/sched/build_policy.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 51d77459d208..f33df61c24cb 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -1971,6 +1971,9 @@ static void scx_ops_disable_workfn(struct kthread_work *work) case SCX_EXIT_UNREG: reason = "BPF scheduler unregistered"; break; + case SCX_EXIT_SYSRQ: + reason = "disabled by sysrq-S"; + break; case SCX_EXIT_ERROR: reason = "runtime error"; break; @@ -2593,6 +2596,21 @@ struct bpf_struct_ops bpf_sched_ext_ops = { .name = "sched_ext_ops", }; +static void sysrq_handle_sched_ext_reset(int key) +{ + if (scx_ops_helper) + scx_ops_disable(SCX_EXIT_SYSRQ); + else + pr_info("sched_ext: BPF scheduler not yet used\n"); +} + +static const struct sysrq_key_op sysrq_sched_ext_reset_op = { + .handler = sysrq_handle_sched_ext_reset, + .help_msg = "reset-sched-ext(S)", + .action_msg = "Disable sched_ext and revert all tasks to CFS", + .enable_mask = SYSRQ_ENABLE_RTNICE, +}; + void __init init_sched_ext_class(void) { int cpu; @@ -2616,6 +2634,8 @@ void __init init_sched_ext_class(void) init_dsq(&rq->scx.local_dsq, SCX_DSQ_LOCAL); } + + register_sysrq_key('S', &sysrq_sched_ext_reset_op); } -- 2.41.0