Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1313304pxb; Thu, 16 Sep 2021 05:01:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNyHvvpf4fFqAziwrtXeRiTQ7D2hUz90av5SPWsSvyVwG8M8pl7SHOPrllhSuD+3qR+bN2 X-Received: by 2002:a92:cccc:: with SMTP id u12mr3695012ilq.189.1631793664362; Thu, 16 Sep 2021 05:01:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631793664; cv=none; d=google.com; s=arc-20160816; b=tp9A5BKEfj5z14LWv7H+0Ai7J5qtfQXH7pAwWTkVGHi6y6szPdhux3xCbZgZkFD0LD LKbIwn8GEhynG+1iStN+ckgzzTMiSvfupics0G1mUvVlpfOK63ov7ZeJJsCE/D1ZJPrR BpNxouHjYk4D3IeeXT9yPXQZF6JtWr1sP2AnplIiz6s86nJTux0+RfhDwTDypvVZQTD8 icD/f3YkKJkNMEd5QojBU+DM3M0xdoERUHC8Fo8zJrzZlR73vopwwjaISxYe7fgC7RFK UgJNaTnId1cLYvO2P9dbJLwICu0ow4IYbAL1ZPTD9P17QsdfQ/dOA/iBDibZUzX4qD6M FDcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=9SGe3EnvZQEcxtBXpqOweHUvG3htiUIiwq3ApHseWOY=; b=Op1W3DsfFVu+s1pnwy95D2qrFWq3yp1ZECmgvdi/6Uxg25SH/pcSORo/wd+6EKfAAg 7LqW0mkVW8AWT8xvE7a5mSmI27SxwNgia8Lqodm6FaBL6aRtbqY0StwfZw2OnpcGbN0X UttnulrunDNvhx3kC49jGDcDZ9vjupNec2wC+Jn/Z7TlZolKrXgRA7XehrAg6UPuoQoH oHazXYrMAq338/7Dbm1WTQNDbEqyfp96hMs20KVQoJOXZk9y3ZOLqZJ0L4T+Qs3jSAa+ SbUDena9hRWy5j0RsmshMn+zjWlICcSi7o9Nb0fe07sNTah13pFEMcI72n+9jnHZPQUw Mvaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QrU4ZYxu; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=vUTlf+22; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w5si2494794ilc.127.2021.09.16.05.00.51; Thu, 16 Sep 2021 05:01:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QrU4ZYxu; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=vUTlf+22; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238665AbhIPMBC (ORCPT + 99 others); Thu, 16 Sep 2021 08:01:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238720AbhIPMAt (ORCPT ); Thu, 16 Sep 2021 08:00:49 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31B7FC061574; Thu, 16 Sep 2021 04:59:29 -0700 (PDT) Date: Thu, 16 Sep 2021 11:59:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1631793567; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9SGe3EnvZQEcxtBXpqOweHUvG3htiUIiwq3ApHseWOY=; b=QrU4ZYxuMlWtW0TxtpAJ6jWnNxBTCPM8azYWdjjNLWWjhQz4078mu8dYKFr9+gj1IdxTEc +ZBu2QIqwvZRlkVimXGHV3UIBSgfLIwsMJibB5bNnE1bZ4wYAk3W9wFzaZjADE0xmoc9oC rHts5UsE0CDSW1AMksziCZl5BjpRKMVc3mVQ0cpJTkeJ6HGAo5iXZh7r1xTJZR1kaEUmoD CoLg1QH1hlHr0oLIjaUgEihZcNOOU5tqs+7Iypxu18cehI7nb0G7ZctXbSxzmtrKCgyYjN /ldD/7xUDGHNmGOJO6/uOf3llRIWYlEdw2DQX+1QnlmNf/zMUQkd3+5qCNczAA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1631793567; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9SGe3EnvZQEcxtBXpqOweHUvG3htiUIiwq3ApHseWOY=; b=vUTlf+224z0Adq3AUuLqt1DuWkNTtTACTNdi951EL4Zp/HVMchq/ZgzydECrPfdRzK1/iZ pXJmhzpXpcPnEkDA== From: "tip-bot2 for Yafang Shao" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/dl: Support schedstats for deadline sched class Cc: Yafang Shao , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210905143547.4668-9-laoar.shao@gmail.com> References: <20210905143547.4668-9-laoar.shao@gmail.com> MIME-Version: 1.0 Message-ID: <163179356710.25758.12784818846589422128.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: fce7dd1e9c19be245c565d1544db0dcafb230711 Gitweb: https://git.kernel.org/tip/fce7dd1e9c19be245c565d1544db0dcafb230711 Author: Yafang Shao AuthorDate: Sun, 05 Sep 2021 14:35:47 Committer: Peter Zijlstra CommitterDate: Wed, 15 Sep 2021 17:49:00 +02:00 sched/dl: Support schedstats for deadline sched class After we make the struct sched_statistics and the helpers of it independent of fair sched class, we can easily use the schedstats facility for deadline sched class. The schedstat usage in DL sched class is similar with fair sched class, for example, fair deadline enqueue update_stats_enqueue_fair update_stats_enqueue_dl dequeue update_stats_dequeue_fair update_stats_dequeue_dl put_prev_task update_stats_wait_start update_stats_wait_start_dl set_next_task update_stats_wait_end update_stats_wait_end_dl The user can get the schedstats information in the same way in fair sched class. For example, fair deadline /proc/[pid]/sched /proc/[pid]/sched The output of a deadline task's schedstats as follows, $ cat /proc/69662/sched ... se.sum_exec_runtime : 3067.696449 se.nr_migrations : 0 sum_sleep_runtime : 720144.029661 sum_block_runtime : 0.547853 wait_start : 0.000000 sleep_start : 14131540.828955 block_start : 0.000000 sleep_max : 2999.974045 block_max : 0.283637 exec_max : 1.000269 slice_max : 0.000000 wait_max : 0.002217 wait_sum : 0.762179 wait_count : 733 iowait_sum : 0.547853 iowait_count : 3 nr_migrations_cold : 0 nr_failed_migrations_affine : 0 nr_failed_migrations_running : 0 nr_failed_migrations_hot : 0 nr_forced_migrations : 0 nr_wakeups : 246 nr_wakeups_sync : 2 nr_wakeups_migrate : 0 nr_wakeups_local : 244 nr_wakeups_remote : 2 nr_wakeups_affine : 0 nr_wakeups_affine_attempts : 0 nr_wakeups_passive : 0 nr_wakeups_idle : 0 ... The sched:sched_stat_{wait, sleep, iowait, blocked} tracepoints can be used to trace deadlline tasks as well. Signed-off-by: Yafang Shao Signed-off-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/20210905143547.4668-9-laoar.shao@gmail.com --- kernel/sched/deadline.c | 93 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 73fb33e..d2c072b 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -1474,6 +1474,82 @@ static inline bool __dl_less(struct rb_node *a, const struct rb_node *b) return dl_time_before(__node_2_dle(a)->deadline, __node_2_dle(b)->deadline); } +static inline struct sched_statistics * +__schedstats_from_dl_se(struct sched_dl_entity *dl_se) +{ + return &dl_task_of(dl_se)->stats; +} + +static inline void +update_stats_wait_start_dl(struct dl_rq *dl_rq, struct sched_dl_entity *dl_se) +{ + struct sched_statistics *stats; + + if (!schedstat_enabled()) + return; + + stats = __schedstats_from_dl_se(dl_se); + __update_stats_wait_start(rq_of_dl_rq(dl_rq), dl_task_of(dl_se), stats); +} + +static inline void +update_stats_wait_end_dl(struct dl_rq *dl_rq, struct sched_dl_entity *dl_se) +{ + struct sched_statistics *stats; + + if (!schedstat_enabled()) + return; + + stats = __schedstats_from_dl_se(dl_se); + __update_stats_wait_end(rq_of_dl_rq(dl_rq), dl_task_of(dl_se), stats); +} + +static inline void +update_stats_enqueue_sleeper_dl(struct dl_rq *dl_rq, struct sched_dl_entity *dl_se) +{ + struct sched_statistics *stats; + + if (!schedstat_enabled()) + return; + + stats = __schedstats_from_dl_se(dl_se); + __update_stats_enqueue_sleeper(rq_of_dl_rq(dl_rq), dl_task_of(dl_se), stats); +} + +static inline void +update_stats_enqueue_dl(struct dl_rq *dl_rq, struct sched_dl_entity *dl_se, + int flags) +{ + if (!schedstat_enabled()) + return; + + if (flags & ENQUEUE_WAKEUP) + update_stats_enqueue_sleeper_dl(dl_rq, dl_se); +} + +static inline void +update_stats_dequeue_dl(struct dl_rq *dl_rq, struct sched_dl_entity *dl_se, + int flags) +{ + struct task_struct *p = dl_task_of(dl_se); + + if (!schedstat_enabled()) + return; + + if ((flags & DEQUEUE_SLEEP)) { + unsigned int state; + + state = READ_ONCE(p->__state); + if (state & TASK_INTERRUPTIBLE) + __schedstat_set(p->stats.sleep_start, + rq_clock(rq_of_dl_rq(dl_rq))); + + if (state & TASK_UNINTERRUPTIBLE) + __schedstat_set(p->stats.block_start, + rq_clock(rq_of_dl_rq(dl_rq))); + } +} + static void __enqueue_dl_entity(struct sched_dl_entity *dl_se) { struct dl_rq *dl_rq = dl_rq_of_se(dl_se); @@ -1504,6 +1580,8 @@ enqueue_dl_entity(struct sched_dl_entity *dl_se, int flags) { BUG_ON(on_dl_rq(dl_se)); + update_stats_enqueue_dl(dl_rq_of_se(dl_se), dl_se, flags); + /* * If this is a wakeup or a new instance, the scheduling * parameters of the task might need updating. Otherwise, @@ -1600,6 +1678,9 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags) return; } + check_schedstat_required(); + update_stats_wait_start_dl(dl_rq_of_se(&p->dl), &p->dl); + enqueue_dl_entity(&p->dl, flags); if (!task_current(rq, p) && p->nr_cpus_allowed > 1) @@ -1608,6 +1689,7 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags) static void __dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags) { + update_stats_dequeue_dl(&rq->dl, &p->dl, flags); dequeue_dl_entity(&p->dl); dequeue_pushable_dl_task(rq, p); } @@ -1827,7 +1909,12 @@ static void start_hrtick_dl(struct rq *rq, struct task_struct *p) static void set_next_task_dl(struct rq *rq, struct task_struct *p, bool first) { + struct sched_dl_entity *dl_se = &p->dl; + struct dl_rq *dl_rq = &rq->dl; + p->se.exec_start = rq_clock_task(rq); + if (on_dl_rq(&p->dl)) + update_stats_wait_end_dl(dl_rq, dl_se); /* You can't push away the running task */ dequeue_pushable_dl_task(rq, p); @@ -1884,6 +1971,12 @@ static struct task_struct *pick_next_task_dl(struct rq *rq) static void put_prev_task_dl(struct rq *rq, struct task_struct *p) { + struct sched_dl_entity *dl_se = &p->dl; + struct dl_rq *dl_rq = &rq->dl; + + if (on_dl_rq(&p->dl)) + update_stats_wait_start_dl(dl_rq, dl_se); + update_curr_dl(rq); update_dl_rq_load_avg(rq_clock_pelt(rq), rq, 1);