Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1898373pxu; Fri, 27 Nov 2020 19:18:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJxTf2ygN+zeLPn/DpUWemf+RT3bb5SIaG4jHd4nNR+ZysAO/mwJgTqr8+fwoax+G4LLIOrb X-Received: by 2002:a17:906:3958:: with SMTP id g24mr10846660eje.360.1606533511350; Fri, 27 Nov 2020 19:18:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606533511; cv=none; d=google.com; s=arc-20160816; b=U2y0JL3pz173bAkWIJ5KbAk+dlzcVC1L7qsA+B6mJvbD7pvJ+hZXVjdKYOP2K4QFbc FlS3RM6mVIIhdhUZoKvb113Rt+DrECx7CM2O9NYrGpjYvBkLZ39bg9Gk68+bKkMhc3/M WDpSQyKA1ApXB9VpUo59yO+TcWB41zkADL+kICZvu5la9hlEZ3nm2SFWCrO4q2Xw7/yV YsUBiSHtemuFEUwbrdzm7t1TY5eauEgEyVFETv4bPlgq6uqQCsOIdVhYW+RGloNka5Lp j3e3lbqGvCQHhDnI4t58MuQY+tKXyth/vfcVIsVkxePd8DnXPGR63qHG6f76dLRA5gJo UwMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=dbqk6fkQ9N7vOdYQCsQVKy+jkNB2WegUijRwuAKX+1I=; b=sOMvsy6v4CaikvHhhvPLEAfBQ9QgoBv9SzzsuPY6ZCPIV/Iwj5oFtqlaEZyXRBeDpO COMljq1+HRPlGDCgmXEcnz7scxIxjBVOITaOL5+5Ikal9SAO7W2rVmNs/l5nZ0d0EYzM sS5xW0wrpMk/yWD7C1TJ80i9rOFShvAIoMFi83UDQfPlZKAgREY52x1CTyufnF8Uk77C hZSB9mZUwxyAWJwk8eCyaKZow4vJfdMp5pWpCiMcDhBqmoahT8auMQGXs/PUZTfkghbd Lr5UiTP94lGKBt8kn5JcCG8QShVoahXvRdTeFBAZgu37BYabuONqFL7IxmKMmf6ssMVE CF9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QmbkriXe; 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=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c95si8322347edf.197.2020.11.27.19.17.49; Fri, 27 Nov 2020 19:18:31 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=QmbkriXe; 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=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729604AbgK1DMO (ORCPT + 99 others); Fri, 27 Nov 2020 22:12:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729019AbgK1DJn (ORCPT ); Fri, 27 Nov 2020 22:09:43 -0500 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46B84C0613D1; Fri, 27 Nov 2020 19:09:20 -0800 (PST) Received: by mail-io1-xd44.google.com with SMTP id i9so6479718ioo.2; Fri, 27 Nov 2020 19:09:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dbqk6fkQ9N7vOdYQCsQVKy+jkNB2WegUijRwuAKX+1I=; b=QmbkriXetoIAO7mIOUOdfd38AMJXvvcNwuQbnT+Nf5lruzncsaknPJD7Ak6WQYEkya 0qprZbf8dvVUkJuPn8uxYflqfmykBQ9NRw1/GwPRv43RbRaCrANluOs7FQlFmtwq+6H1 BEEhSxz2Tn0KUoJ5f8yHH5V/DyWNho4NW2nEV3snGTGtQA/L2RYmd8SHpfLmRqWdzt7o iYdGZkz2lP0Xvv8scOmTz9/MohfHND8DxzcNdXAcHLho3x1Mc+4hLvW+3CTa9ET1lDuK aQERoog6kqrKew5qiaacfKQPfnlgpLS9qbYCwFFqS+Za68xg+blqDUSTn+JEn7/lroMF laZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dbqk6fkQ9N7vOdYQCsQVKy+jkNB2WegUijRwuAKX+1I=; b=c8GB+V0DZGXq8y2Mu4dzW+khVx1H61V1qurl7dcSd65UtB3TrWJY4YMRQMFlb7maVv Pxe+Y/1WAGDjRI5qzb1wGHvEM6FhxSkrPaiOTMXN+DOi2gcefH6uBLzYPJBcPLBKcHT5 d39JUnC0NwhOu3LRH5uolmR9JeRQdmNl1pFXdjEHKjC2Sc+8mg29M2q+hqWRA0ZeUnjZ H939kUQ7tZ6GzjFgBpSEG7L5aiXGF9J599XIEEk3/3wSvywIhUItqAsZJORJUjSxKCLM QFuqC8Y0RkXw1Hh0ca7xRbKHPJ0ON0gJVjRQYd8XgnDWZp46bgT20WzV2dweqA1v2c4q 7vBw== X-Gm-Message-State: AOAM531fZYNwCzaDGqsMZqzCD0kCroN5Xkp73jKGJFA5a+o24hQELOj2 Xl63MVmtghK4IVPDr0LApgeLzedu4HkVlBJDfOg= X-Received: by 2002:a02:ccbc:: with SMTP id t28mr10016301jap.97.1606532959688; Fri, 27 Nov 2020 19:09:19 -0800 (PST) MIME-Version: 1.0 References: <20201127161229.19336-1-laoar.shao@gmail.com> In-Reply-To: <20201127161229.19336-1-laoar.shao@gmail.com> From: Yafang Shao Date: Sat, 28 Nov 2020 11:08:43 +0800 Message-ID: Subject: Re: [RFC PATCH v3 0/5] sched: support schedstats for RT sched class To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Benjamin Segall , Mel Gorman , bristot@redhat.com, jun qian Cc: LKML , linux-rt-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Nov 28, 2020 at 12:12 AM Yafang Shao wrote: > > We want to measure the latency of RT tasks in our production > environment with schedstats facility, but currently schedstats is only > supported for fair sched class. This patch enable it for RT sched class > as well. > > - Structure > > Before we make schedstats available for RT sched class, we should make > struct sched_statistics independent of fair sched class first. > > > The struct sched_statistics is the schedular statistics of a task_struct > or a task_group. So we can move it into struct task_struct and > struct task_group to achieve the goal. > > Below is the detailed explaination of the change in the structs. > > The struct before this patch: > > struct task_struct { |-> struct sched_entity { > ... | ... > struct sched_entity *se; ---| struct sched_statistics statistics; > struct sched_rt_entity *rt; ... > ... ... > }; }; > > struct task_group { |--> se[0]->statistics : schedstats of CPU0 > ... | > #ifdef CONFIG_FAIR_GROUP_SCHED | > struct sched_entity **se; --|--> se[1]->statistics : schedstats of CPU1 > | > #endif | > |--> se[N]->statistics : schedstats of CPUn > > #ifdef CONFIG_FAIR_GROUP_SCHED > struct sched_rt_entity **rt_se; (N/A) > #endif > ... > }; > > The '**se' in task_group is allocated in the fair sched class, which is > hard to be reused by other sched class. > > The struct after this patch: > struct task_struct { > ... > struct sched_statistics statistics; > ... > struct sched_entity *se; > struct sched_rt_entity *rt; > ... > }; > > struct task_group { |---> stats[0] : of CPU0 > ... | > struct sched_statistics **stats; --|---> stats[1] : of CPU1 > ... | > |---> stats[n] : of CPUn > #ifdef CONFIG_FAIR_GROUP_SCHED > struct sched_entity **se; > #endif > #ifdef CONFIG_RT_GROUP_SCHED > struct sched_rt_entity **rt_se; > #endif > ... > }; > > After the patch it is clearly that both of se or rt_se can easily get the > sched_statistics by a task_struct or a task_group. > > - Function Interface > > The original prototype of the schedstats helpers are > > update_stats_wait_*(struct cfs_rq *cfs_rq, struct sched_entity *se) > > The cfs_rq in these helpers is used to get the rq_clock, and the se is > used to get the struct sched_statistics and the struct task_struct. In > order to make these helpers available by all sched classes, we can pass > the rq, sched_statistics and task_struct directly. > > Then the new helpers are > > update_stats_wait_*(struct rq *rq, struct task_struct *p, > struct sched_statistics *stats) > > which are independent of fair sched class. > > To avoid vmlinux growing too large or introducing ovehead when > !schedstat_enabled(), some new helpers after schedstat_enabled() are also > introduced, Suggested by Mel. These helpers are in sched/stats.c, > > __update_stats_wait_*(struct rq *rq, struct task_struct *p, > struct sched_statistics *stats) > > - Implementation > > 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 RT sched class. > > The schedstat usage in RT sched class is similar with fair sched class, > for example, > fair RT > enqueue update_stats_enqueue_fair update_stats_enqueue_rt > dequeue update_stats_dequeue_fair update_stats_dequeue_rt > put_prev_task update_stats_wait_start update_stats_wait_start > set_next_task update_stats_wait_end update_stats_wait_end > > - Usage > > The user can get the schedstats information in the same way in fair sched > class. For example, > fair RT > task show /proc/[pid]/sched /proc/[pid]/sched > group show cpu.stat in cgroup cpu.stat in cgroup > > The sched:sched_stat_{wait, sleep, iowait, blocked} tracepoints can > be used to trace RT tasks as well. sched_stat_runtime can also be > supported in the future if it is helpful. > > Yafang Shao (5): > sched: don't include stats.h in sched.h > sched, fair: use __schedstat_set() in set_next_entity() > sched: make struct sched_statistics independent of fair sched class > sched: make schedstats helpers independent of fair sched class > sched, rt: support schedstats for RT sched class > > include/linux/sched.h | 3 +- > kernel/sched/core.c | 25 +++-- > kernel/sched/deadline.c | 5 +- > kernel/sched/debug.c | 82 +++++++-------- > kernel/sched/fair.c | 209 +++++++++++++++------------------------ > kernel/sched/idle.c | 1 + > kernel/sched/rt.c | 178 ++++++++++++++++++++++++++++++++- > kernel/sched/sched.h | 13 ++- > kernel/sched/stats.c | 105 ++++++++++++++++++++ > kernel/sched/stats.h | 80 +++++++++++++++ > kernel/sched/stop_task.c | 5 +- > 11 files changed, 517 insertions(+), 189 deletions(-) > > -- > 2.18.4 > Ah, the patch #5 is missed,pls ignore this patchset. I will resend them. -- Thanks Yafang