From patchwork Sat Jan 28 00:16:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 13119568 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D1FAC38142 for ; Sat, 28 Jan 2023 00:18:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232786AbjA1AS0 (ORCPT ); Fri, 27 Jan 2023 19:18:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232778AbjA1AR5 (ORCPT ); Fri, 27 Jan 2023 19:17:57 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D851C8CC4A; Fri, 27 Jan 2023 16:17:20 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id be8so6561006plb.7; Fri, 27 Jan 2023 16:17:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=wECB+kv9zmbuEsGDrXMjNkxOFX+6xuQqOVDwucXIlds=; b=jNoXXkGxSM+6YWVkc9Dt3d7uFesca5+fVGhkhaDuDvKXiOvs7lOj6qfm2IxpYO1pGl iRXines4P7kAb6S7AewwaZPmyo5N3/AIdGxbLulvd1oJQQoVc2cAfs3QN8Eo3Oh+UHus bGEaCRKONAEFKN1jBnDypZmzzhCnsPsU3RfNKJdHgpapKL+3R9bmZmd2gh4vzxKjQb41 5og991aR31OxVY/DOL0iVdiFetUSoL7oC6opdXUNgfRp3Ji4yvMVIc5O4b0NPkipNPSb pg/EOiVs7LC2QfuYgfK9SLJSU2vJ9XPAQU+YBAiFOHSjYbpG1KrC/7WXAwJy8RB3CDdz HD3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=wECB+kv9zmbuEsGDrXMjNkxOFX+6xuQqOVDwucXIlds=; b=4EzHcKlCKvXqkKS2OuHNTlO9zuSlO++9LZ9UtyRY7CFSzHntJl2CepOuppq+67gksR 8OdzTCWFsAV1yn3ytzcmykl0O8z1KE0DlWgOFH7HgstWDMjE7xxZ2+kL73GRLjR6ycE7 SsQwW+LsseiMy6LMT39bjb2A+2ONeX4UAPe1PJ6UYk2N/GbGpvw8QCNi1PGWmuQfUA56 hqGZngB2Yt19vk7VuFJAcNMWSAqifc+svfOiciSe9BY4U587zTnwO/2mcPvkw9dsfYoy kKGgxUDn6n26R8kClmwtJpfO5eUz8cWfZl9ap+5Ukjp+FRaPi6ZPwaR2iTwWsjo92DwA 81eg== X-Gm-Message-State: AFqh2koVUPowjovX6lsceh/ZQLCGlNeQ0mpWTdYtlatJb2e4b5OuOF/H a/l7mLVo+5OC7PpbqN+vTd8= X-Google-Smtp-Source: AMrXdXsNaHzO+J5iBJWnXXCJfT+FiSmHPvvbQwE3Elh1mIzfrn+xJrCkPJKQtNwFS/yAjY+yoObe9g== X-Received: by 2002:a05:6a20:8f0f:b0:b8:5515:9004 with SMTP id b15-20020a056a208f0f00b000b855159004mr55584650pzk.8.1674865039784; Fri, 27 Jan 2023 16:17:19 -0800 (PST) Received: from localhost (2603-800c-1a02-1bae-a7fa-157f-969a-4cde.res6.spectrum.com. [2603:800c:1a02:1bae:a7fa:157f:969a:4cde]) by smtp.gmail.com with ESMTPSA id q13-20020a17090a304d00b0022908f1398dsm3270995pjl.32.2023.01.27.16.17.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 16:17:19 -0800 (PST) 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 15/30] sched_ext: Add sysrq-S which disables the BPF scheduler Date: Fri, 27 Jan 2023 14:16:24 -1000 Message-Id: <20230128001639.3510083-16-tj@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230128001639.3510083-1-tj@kernel.org> References: <20230128001639.3510083-1-tj@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@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 8894b6a9977d..988d1e30e26c 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 38786d36a356..ebbf3f3c1cf7 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -1881,6 +1881,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; @@ -2490,6 +2493,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; @@ -2513,6 +2531,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); }