Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1485627pxu; Fri, 27 Nov 2020 08:16:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYa9BZLln3jLVXZJzjyPAJu8C0jj5zZ4Xu4jJpzMXdaPtjB+ENlt+ap/bDREulqvunZcTQ X-Received: by 2002:a17:906:60d4:: with SMTP id f20mr8806720ejk.156.1606493769776; Fri, 27 Nov 2020 08:16:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606493769; cv=none; d=google.com; s=arc-20160816; b=XEvpj5oWPXGsecifhxiYiZEzByzrHhLF8++r95vjkWSu0oMW/C2uBATHWPJSmMDvn/ r6GwTFB5SIkaHPWWWEjSdvoTusmq+TJ6dU+3kqw8PoXbgAkinTYYyId429TWChu76gUt pC82IINuA8itS52HZ7OpEsa70S2gWoIigTYrCYce8gC/Zfwdcck8p84/uWiTpwkDB6xi o3GRrPr+okzrTEPbpXXMgNSpBEOvZYCpvh091QXwotz/rtr5lbSJzYdJw8HJT8vZxojM FN3w/uBE6jgJSyatBXSEqmNf4RKs/xLowjAgUnpc3fTkX0W4upGJuG+6l0ZCYyQWyRzq pAXg== 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=2TL8KQ54wkv9B/Yxs0RIOT3jGAuhhdh5kFSYV9oX00I=; b=MVqNv+BB0cQlgf+q8QVrnn4wdX+03Zi/mtiXY1nebWYWJLiBdTtct5XlHSg4slmkfm 2RoTL385m0pt/nz9dxUpuurnwjMQkoBO6V8jBfbA5esTEopEKQuf/KYVP2DPL1EdUZc/ QCP5NCJ3qRl2LKQBHwj3qoGUKvFP1qcsfC1uLUX0u6dI2o7OiBGZqoG6eE4CmvQkJEBW LwsTo586excPdjvUGUNQFY1Eba/dwxeXGAR4qMZwW3C5xRA+rRbU6kDurC5h8fbjteIy nGBmH6d4JvIscGteVlD3FFZGtWZvJsTVSbGAXR3a+cgaosJk/qCPOYu8j4SY37uQk/HV w76A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SCvWFlIk; 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 m14si5327776ejr.448.2020.11.27.08.15.46; Fri, 27 Nov 2020 08:16:09 -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=SCvWFlIk; 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 S1731305AbgK0QM5 (ORCPT + 99 others); Fri, 27 Nov 2020 11:12:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731150AbgK0QM5 (ORCPT ); Fri, 27 Nov 2020 11:12:57 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC0B5C0613D1; Fri, 27 Nov 2020 08:12:56 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id n137so4982610pfd.3; Fri, 27 Nov 2020 08:12:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2TL8KQ54wkv9B/Yxs0RIOT3jGAuhhdh5kFSYV9oX00I=; b=SCvWFlIkhit55pRVpYXDApHZKpRq6cFW03mHL/4SQ8IB/P/BzXEckVbX2+5D7wCERF NVsh+LUHfAelgCMfmXkqkAZIyUZ/sLWJlLYs9n/D7OuauH2d7eTRby3GDMyjhsWYWDyc gyVUYEKQaO1YIyjBfPidnx1xAa9jHBboQl9vQMF26oG68b58zCq1kBcVE7Pp42lvLHCf euvQUKlpLG7bYyq1bPVqbPspzx8xnqBiy1qHuc8cDY/4PY8YZQuK+T2z/7EKxtF6mkri hCC5N4Ix5ru3FCUG8tSPeb6LrwimTzxtH9FWMsQA9qGT6lwJwBvut+zOEZWEVaAF4g0T Zn1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2TL8KQ54wkv9B/Yxs0RIOT3jGAuhhdh5kFSYV9oX00I=; b=sPiYM7WhsRBfPaVC4vS5QwRu9t7g6SiEaAuWF0sPLH95/cUxIJopsCo4gPcTy6nGjL Yjz1qNhMtSgldkqF4GxvnSao31DcYg5mo1Zityg64zw3mxbSFv8sXP15j5zyFyAqjodJ ISEKEc8yCHuATCs3R4nBrqWRnoYweztdwlteQj7yTc3vdRpAZ4k/b+VHSfwWNMZ1VD0O +tr3Ozp0QgQphXcLgFqWhSC0lwoaI3n2UHMUZ+iZoDMJsxp3jnv5L5lkNmn3wQlNHzH6 L3qJgcrsADryKe1N3Aebp6Lakz05DbFG5hzCQ6+TZOle3GrN304U8XUuKIUz78mss5qq GEoQ== X-Gm-Message-State: AOAM532YDzLolzY5n6b24Nxzj4lUYC3Q8M5Q6X0R2vcWoBVT/x7vmTF5 +QTxu8PJT6pdGKIsRrVATi8= X-Received: by 2002:a63:5d05:: with SMTP id r5mr7129700pgb.442.1606493576330; Fri, 27 Nov 2020 08:12:56 -0800 (PST) Received: from localhost.localdomain ([115.192.120.179]) by smtp.gmail.com with ESMTPSA id v126sm7992715pfb.137.2020.11.27.08.12.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Nov 2020 08:12:55 -0800 (PST) From: Yafang Shao 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, qianjun.kernel@gmail.com Cc: linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org, Yafang Shao Subject: [RFC PATCH v3 0/5] sched: support schedstats for RT sched class Date: Sat, 28 Nov 2020 00:12:24 +0800 Message-Id: <20201127161229.19336-1-laoar.shao@gmail.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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