Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3936645imb; Wed, 6 Mar 2019 00:59:06 -0800 (PST) X-Google-Smtp-Source: APXvYqwxaf909bLkGu5KNQ1cfl4hdYO6WIS5PgYK5UVeX7ab2BftVWTVNMd0WO1xFoPWQfL52DAo X-Received: by 2002:a62:4287:: with SMTP id h7mr6338567pfd.110.1551862746808; Wed, 06 Mar 2019 00:59:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551862746; cv=none; d=google.com; s=arc-20160816; b=LKFaC89E6ndsvEC0FaRE5lIhnOeSCAvko5nFRrLOQn/jRIz7GTFbOexyQRH3KBbw8A ouf2eH5LaaCMeL4PAl3zzrZGWh4g5kB97tVjCgHtN2+mw6rAGOTgPNQ/yUXqk1XoYdtH zbhVbjGXuL1WxnkamSQzXKu30EudGfy9Ww8lP7SuKlSqgalGjN3pohRT4cBjWwTPf2yt flKpFmO5dKoGVOWG+UVAVJbvq0oWl5Pb4MmSKhXAQB1lD0mTOMStIWEuzOhLh3WdetZg WY8KkUdckBZAr5hRXtkk+GCxOeEhJzPrbrJSwEYVeq8EQgWHKTHgDLKYJ6DyjJGGj4le ffkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=1vh7hA17yADLWVoUXDA26oBLsTHTn0FsDrfCzKugJug=; b=gh/gLwmSSwA0yY1kWhF+H7l0asoCgIjl7qcxFXl0cbv6L20kDWO4oTkb2McSp4Q11Z EnhaMWEktbQT2zc+1jKKzUlsghCICrY+JNHDBvcZGw902Q4iJ4mq1WbO+yBWn+2PnomR /AkUd50xcJexMBtF7PLyFLhbToZ6N6Q8FhUyEHnD1g69eC5jf0KkZ9eQFyqsJ7tPia1K gRvvlR70hkav3P4oi/DKjAkH7Elw25fwKWUVCLvnnOcvamCJEF7pLeI1ftmJgnmTQPsX hncUkn77NX6jPNlzCnsjzDmFpXXZMn47zANpv78m8tBOEPz8vyJ7TKz1i16mmilDhVOI i2nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="kX/9wWbd"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d127si956884pgc.303.2019.03.06.00.58.51; Wed, 06 Mar 2019 00:59:06 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="kX/9wWbd"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729485AbfCFIoB (ORCPT + 99 others); Wed, 6 Mar 2019 03:44:01 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35799 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729067AbfCFIoB (ORCPT ); Wed, 6 Mar 2019 03:44:01 -0500 Received: by mail-pg1-f193.google.com with SMTP id e17so7833997pgd.2 for ; Wed, 06 Mar 2019 00:44:00 -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; bh=1vh7hA17yADLWVoUXDA26oBLsTHTn0FsDrfCzKugJug=; b=kX/9wWbdMl6UmRPN3n34xXStb9+lTTM55Opwuk6yDNuvsvEVms3ztmIwlWgGtvn1Af Yf5KBb6ya2f4KEml8Z7QVAVOH/Wrf+OLR7AvxQcSiRElTicMg1dGMoiGRMcwpZjeKxmP G0MAlVkeGMph6GadkSjDzTf9eO5LT3GjqoNX0ec6Hyim46VfzzB8IPeeq/NcepJW1bR4 rQUU6PAIalOJrWT4JwKO2P0kBmDyBJ1iSLnwtzLdmWnSpLqaleSoW4BcuKNdqgTjCO6c 3rIbDwOCPtl53fSoFi76lbm1ah8J0BU8h/SHcfhE70DS8YgpDn79sAPvpsxavrIG8UlZ 12rQ== 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; bh=1vh7hA17yADLWVoUXDA26oBLsTHTn0FsDrfCzKugJug=; b=lJxUhOyqSdxsUGfsEw0afwQxIxoqn6ytUwvxC1Ykm781FiLPlhiAmYNEskLs9pAjL6 qLElnzv4fKkQg5j/J1JPHQ+kpYD6YX5OUHfoEaikGmzAjCWKMh92teAju9AyPCJEXeGO ERZDo9SVBonzBMUqAiMP4lSVb08BJpvdNP/Zsn76HpTxewyLiWZanhC0InWFB1Xhin72 e0gtrpD3xKptmDtW7433PBCrDu7s76OkslyLdXpjsJuKIFivPEO5OsvP203j8FC4hyeO KtYz++FoizCAr1R0n301S8E2glcv1kjjcFCRekkQVnmDMORV955ketnq8DOPGtUvS0Cj FdMQ== X-Gm-Message-State: APjAAAX5jGWVxRnFTd1e18fL49hRnWsz6j4rbmA+Fmd+yTjl9lfUDvY0 OIA+2KYBAvtjViOOHbhp7x5INiEz+KQ= X-Received: by 2002:a62:1981:: with SMTP id 123mr6114826pfz.69.1551861840392; Wed, 06 Mar 2019 00:44:00 -0800 (PST) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id k12sm1757273pfk.109.2019.03.06.00.43.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 00:43:59 -0800 (PST) From: Yafang Shao To: mingo@redhat.com, peterz@infradead.org Cc: linux-kernel@vger.kernel.org, shaoyafang@didiglobal.com, Yafang Shao Subject: [PATCH] sched: fair: fix missed CONFIG_SCHEDSTATS Date: Wed, 6 Mar 2019 16:43:46 +0800 Message-Id: <1551861826-12592-1-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When I'm using trace_sched_stat_{iowait, blocked, wait, sleep} to measure how long the processes are stalled, there's always no output from trace_pipe while there're really some tasks in uninterruptible sleep state. That makes me confused, so I try to investigate why. Finally I find the reason is that CONFIG_SCHEDSTATS is not set. To avoid such kind of confusion, we should not expose these tracepoints if CONFIG_SCHEDSTATS is not set. Signed-off-by: Yafang Shao --- include/trace/events/sched.h | 3 ++- kernel/sched/fair.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index 9a4bdfa..a261da8 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -336,6 +336,7 @@ static inline long __trace_sched_switch_state(bool preempt, struct task_struct * __entry->pid, __entry->old_pid) ); +#ifdef CONFIG_SCHEDSTATS /* * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE * adding sched_stat support to SCHED_FIFO/RR would be welcome. @@ -363,7 +364,6 @@ static inline long __trace_sched_switch_state(bool preempt, struct task_struct * (unsigned long long)__entry->delay) ); - /* * Tracepoint for accounting wait time (time the task is runnable * but not actually running due to scheduler contention). @@ -394,6 +394,7 @@ static inline long __trace_sched_switch_state(bool preempt, struct task_struct * DEFINE_EVENT(sched_stat_template, sched_stat_blocked, TP_PROTO(struct task_struct *tsk, u64 delay), TP_ARGS(tsk, delay)); +#endif /* * Tracepoint for accounting runtime (time the task is executing diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 8213ff6..a8006c9 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -855,6 +855,7 @@ static void update_curr_fair(struct rq *rq) static inline void update_stats_wait_start(struct cfs_rq *cfs_rq, struct sched_entity *se) { +#ifdef CONFIG_SCHEDSTATS u64 wait_start, prev_wait_start; if (!schedstat_enabled()) @@ -868,11 +869,13 @@ static void update_curr_fair(struct rq *rq) wait_start -= prev_wait_start; __schedstat_set(se->statistics.wait_start, wait_start); +#endif } static inline void update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se) { +#ifdef CONFIG_SCHEDSTATS struct task_struct *p; u64 delta; @@ -900,11 +903,13 @@ static void update_curr_fair(struct rq *rq) __schedstat_inc(se->statistics.wait_count); __schedstat_add(se->statistics.wait_sum, delta); __schedstat_set(se->statistics.wait_start, 0); +#endif } static inline void update_stats_enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se) { +#ifdef CONFIG_SCHEDSTATS struct task_struct *tsk = NULL; u64 sleep_start, block_start; @@ -968,6 +973,7 @@ static void update_curr_fair(struct rq *rq) account_scheduler_latency(tsk, delta >> 10, 0); } } +#endif } /* @@ -976,6 +982,7 @@ static void update_curr_fair(struct rq *rq) static inline void update_stats_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) { +#ifdef CONFIG_SCHEDSTATS if (!schedstat_enabled()) return; @@ -988,12 +995,13 @@ static void update_curr_fair(struct rq *rq) if (flags & ENQUEUE_WAKEUP) update_stats_enqueue_sleeper(cfs_rq, se); +#endif } static inline void update_stats_dequeue(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) { - +#ifdef CONFIG_SCHEDSTATS if (!schedstat_enabled()) return; @@ -1014,6 +1022,7 @@ static void update_curr_fair(struct rq *rq) __schedstat_set(se->statistics.block_start, rq_clock(rq_of(cfs_rq))); } +#endif } /* @@ -4090,6 +4099,7 @@ static void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se) update_stats_curr_start(cfs_rq, se); cfs_rq->curr = se; +#ifdef CONFIG_SCHEDSTATS /* * Track our maximum slice length, if the CPU's load is at * least twice that of our own weight (i.e. dont track it @@ -4100,6 +4110,7 @@ static void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se) max((u64)schedstat_val(se->statistics.slice_max), se->sum_exec_runtime - se->prev_sum_exec_runtime)); } +#endif se->prev_sum_exec_runtime = se->sum_exec_runtime; } -- 1.8.3.1