Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3539059imm; Mon, 2 Jul 2018 00:32:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcLzzKCoicBHCw4MlD9fZc9NqH76Z2id73B9NmVLHJiWEnJunJhyW1fTaj8qlWautPoQrgD X-Received: by 2002:a63:440a:: with SMTP id r10-v6mr104888pga.27.1530516754215; Mon, 02 Jul 2018 00:32:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530516754; cv=none; d=google.com; s=arc-20160816; b=bPtpffEFyuUPcnUU018ho67+2ZcCHvNkTZkZalyEkb/NEjHv/k3jlmaTkeJWlM4EUD T1uMD5goN4I7dyOso4ssDHOiAraKqChCnNnC/++BBiJh+vzBQvoDp9TMypPXBeWBFmC6 R7iFnNR2j8cwfZRFQnVAcH03Az0fA8KG5K8/bgQRxdDkEKY0uNg4rkBytiIzyyvxcQUY aGbWUaEEFECNN1M055chYFhaV9+DT0qmcaQxLVc2uB4KsDafDZ6voB1USI/FL+pvK+mq WPhn/hdp6dWz1kthVrGhC5bl8wd2blbe0OSk9u84Oi793DP//uuAkxo1g0v9wI4i/29r AFBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:subject :from:to:arc-authentication-results; bh=dNJJiEhPvqpbPOXJYheaLXCN0Dn+0nXWqdVURdIpgjI=; b=Lqw/ioI1ccJrj2IXTAD8jTou5+XjKmtTczXnQODvbFLl5Yu2tw2znZb7kaf9Lq18go 7ofDdS7dCCBOLOKHzznSgAv65UHT9kx4rRw8Ic5CHZ6VnR4HJIs3pRVu9Dn66lVNvdE3 JAGbosPSq4Hbn+m9ako3+xwW32mDGvjgKnZ1umWD7kc3+IDqGJOW3LBRd0KNHyo5h7+V 6LLQPixSeMJrksvLjP3f58RHfsX9OnY/PMBxHqWQJUQ/LBsHaE6O6gw60UumrdJgdv8e NrdI2PIIHlC5yx/Z9hvQKrnu3f33m+dQPX6ZBZyslg6GONxNdtO32uvGkaiM6VWuXo76 cJfQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d30-v6si15434523pla.110.2018.07.02.00.32.20; Mon, 02 Jul 2018 00:32:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753941AbeGBH37 (ORCPT + 99 others); Mon, 2 Jul 2018 03:29:59 -0400 Received: from out30-133.freemail.mail.aliyun.com ([115.124.30.133]:60196 "EHLO out30-133.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753354AbeGBH36 (ORCPT ); Mon, 2 Jul 2018 03:29:58 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R581e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07402;MF=yun.wang@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0T3mQfo7_1530516579; Received: from testdeMacBook-Pro.local(mailfrom:yun.wang@linux.alibaba.com fp:SMTPD_---0T3mQfo7_1530516579) by smtp.aliyun-inc.com(127.0.0.1); Mon, 02 Jul 2018 15:29:40 +0800 To: Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org From: =?UTF-8?B?546L6LSH?= Subject: [RFC PATCH] tg: count the sum wait time of an task group Message-ID: <5c4c978d-e8fb-4bcb-b942-3c6d3dcfc13e@linux.alibaba.com> Date: Mon, 2 Jul 2018 15:29:39 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Although we can rely on cpuacct to present the cpu usage of task group, it is hard to tell how intense the competition is between these groups on cpu resources. Monitoring the wait time of each process could cost too much, and there is no good way to accurately represent the conflict with these info, we need the wait time on group dimension. Thus we introduced group's wait_sum provided by kernel to represent the conflict between task groups, whenever a group's cfs_rq ends waiting, it's wait time accounted to the sum. The cpu.stat is modified to show the new statistic, like: nr_periods 0 nr_throttled 0 throttled_time 0 wait_sum 2035098795584 Now we can monitor the changing on wait_sum to tell how suffering a task group is in the fight of cpu resources. Signed-off-by: Michael Wang --- kernel/sched/core.c | 2 ++ kernel/sched/fair.c | 4 ++++ kernel/sched/sched.h | 1 + 3 files changed, 7 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 78d8fac..ac27b8d 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6787,6 +6787,8 @@ static int cpu_cfs_stat_show(struct seq_file *sf, void *v) seq_printf(sf, "nr_periods %d\n", cfs_b->nr_periods); seq_printf(sf, "nr_throttled %d\n", cfs_b->nr_throttled); seq_printf(sf, "throttled_time %llu\n", cfs_b->throttled_time); + if (schedstat_enabled()) + seq_printf(sf, "wait_sum %llu\n", tg->wait_sum); return 0; } diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 1866e64..ef82ceb 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -862,6 +862,7 @@ static void update_curr_fair(struct rq *rq) static inline void update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se) { + struct task_group *tg; struct task_struct *p; u64 delta; @@ -882,6 +883,9 @@ static void update_curr_fair(struct rq *rq) return; } trace_sched_stat_wait(p, delta); + } else { + tg = group_cfs_rq(se)->tg; + __schedstat_add(tg->wait_sum, delta); } __schedstat_set(se->statistics.wait_max, diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 6601baf..bb9b4fb 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -358,6 +358,7 @@ struct task_group { /* runqueue "owned" by this group on each CPU */ struct cfs_rq **cfs_rq; unsigned long shares; + u64 wait_sum; #ifdef CONFIG_SMP /* -- 1.8.3.1