From patchwork Mon Oct 23 08:09:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yajun Deng X-Patchwork-Id: 156716 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1143763vqx; Mon, 23 Oct 2023 01:10:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7F6OhmqCu/xRhJhb8sIArikLnucfQ+KJ46sQXuMM6HdUlzFXmYR9ysXv35acBUT7+X3i6 X-Received: by 2002:a05:6a00:27a0:b0:690:c306:151a with SMTP id bd32-20020a056a0027a000b00690c306151amr6460279pfb.0.1698048629337; Mon, 23 Oct 2023 01:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698048629; cv=none; d=google.com; s=arc-20160816; b=oAfApwlwChosOs6gWaI6vEPBVmMnrzNkLy5m7B/K0fN7lqeV4wGnEz4FztgliEWCUB pg7AQzX1Mc0SzaHAnxV4XSDb5SzInMm6SW55QzdN4mJCdBst+SEaWM/h4qTtPERoVlGT ClNkw78nUsXIPCdboDZpPOQlFkh3EqWyL5ZTR3m0gbOBIb4xNvXEGXbg1XE5W8EPmRpi o4gFs5SucivYGgvGzTVgSP+CIWsJenEciN+FaEkU8MiAZxZEoYfTp+k0G0HcLDlb2v4B yKuTyduKJUFSkuWSP3kJ/vEdK+7eaLX6x1vV09o3vUiE8EzoiozsCU4yfx8zRadU3/RT NC2w== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=OZo8VSwhkKBAcb8XFz5ejDDhW5571Hea2aGRDnsLDFA=; fh=kY5sJNvn29qhEh2SatEVpXE2cTkcQ8AnU+xu9Bnn8Ic=; b=bWoaVoWsmP8NrWGzCYTi2Uf8YoJE5rvOuV1nN8Q97kHqWKzTlUpWqIpsy6tSI5uQ+8 26+KpnuEpxHCllOHJ50/bg6rX/5mEAWLJLHCodPg+S2I49/TjsKICFzWeQCZKVNea8Yv d29P/nLRPOFjSTrJ8Qwkr1DooNtPyxd8WMBCoPqL8idsI6shDK81ik+Mw0UxLwdLNr31 dhIfN2hH8mcsa3baKySSQL0ESAYWFfTjp1nUtum/K0Eu81x1z1TolhddvA2ETln4oEOs XOB+KB4bZ6BHhRIy/jJLDSazd/c4R69Is+8Xz8kyeqYVy3yWbuD+UI/w5a2nPOYpBOGM Vfjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Y1fsLn4T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id 199-20020a6300d0000000b00563e283786esi5805830pga.104.2023.10.23.01.10.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 01:10:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Y1fsLn4T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id AB586806235D; Mon, 23 Oct 2023 01:10:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229498AbjJWIKR (ORCPT + 26 others); Mon, 23 Oct 2023 04:10:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjJWIKQ (ORCPT ); Mon, 23 Oct 2023 04:10:16 -0400 Received: from out-210.mta0.migadu.com (out-210.mta0.migadu.com [91.218.175.210]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0385CA1 for ; Mon, 23 Oct 2023 01:10:14 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1698048613; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=OZo8VSwhkKBAcb8XFz5ejDDhW5571Hea2aGRDnsLDFA=; b=Y1fsLn4TadGxgdC5oUPAcBq39c+IUbfLzv53epHivnG2+eTgD7gGkPL9nwreL6tzas3s4b b51YfMfCAsjY2m5T6wiSzsA6S+FoGG9GSXAN91u/96IAfJxjqIw0eoUI9UboCQLtDcfvbW QeW6Zvglty70EMuxB3GkQGluNkYwHHQ= From: Yajun Deng To: 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 Cc: linux-kernel@vger.kernel.org, Yajun Deng Subject: [PATCH v2] sched/rt: Account execution time for cgroup and thread group if rt entity is task Date: Mon, 23 Oct 2023 16:09:54 +0800 Message-Id: <20231023080954.1628449-1-yajun.deng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Mon, 23 Oct 2023 01:10:24 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780528287373868280 X-GMAIL-MSGID: 1780533039783034881 The rt entity can be a task group. Like the fair scheduler class, we don't need to account execution time for cgroup and thread group if the rt entity isn't a task. Check the scheduler class of the task and make sure that the rt entity is a task. Signed-off-by: Yajun Deng --- v2: Add the missing '#endif'. v1: https://lore.kernel.org/all/20231023065418.1548239-1-yajun.deng@linux.dev/ --- kernel/sched/rt.c | 4 ---- kernel/sched/sched.h | 13 +++++++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 6aaf0a3d6081..ccded5670b61 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -165,8 +165,6 @@ static void destroy_rt_bandwidth(struct rt_bandwidth *rt_b) hrtimer_cancel(&rt_b->rt_period_timer); } -#define rt_entity_is_task(rt_se) (!(rt_se)->my_q) - static inline struct task_struct *rt_task_of(struct sched_rt_entity *rt_se) { #ifdef CONFIG_SCHED_DEBUG @@ -283,8 +281,6 @@ int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent) #else /* CONFIG_RT_GROUP_SCHED */ -#define rt_entity_is_task(rt_se) (1) - static inline struct task_struct *rt_task_of(struct sched_rt_entity *rt_se) { return container_of(rt_se, struct task_struct, rt); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 65cad0e5729e..95d696e23a89 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -779,6 +779,12 @@ static inline long se_runnable(struct sched_entity *se) } #endif +#ifdef CONFIG_RT_GROUP_SCHED +#define rt_entity_is_task(rt_se) (!(rt_se)->my_q) +#else +#define rt_entity_is_task(rt_se) (1) +#endif + #ifdef CONFIG_SMP /* * XXX we want to get rid of these helpers and use the full load resolution. @@ -3266,9 +3272,12 @@ static inline void update_current_exec_runtime(struct task_struct *curr, u64 now, u64 delta_exec) { curr->se.sum_exec_runtime += delta_exec; - account_group_exec_runtime(curr, delta_exec); - curr->se.exec_start = now; + + if (curr->sched_class == &rt_sched_class && !rt_entity_is_task(&curr->rt)) + return; + + account_group_exec_runtime(curr, delta_exec); cgroup_account_cputime(curr, delta_exec); }