From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933149AbaEGNmp (ORCPT ); Wed, 7 May 2014 09:42:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4566 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751297AbaEGNmo (ORCPT ); Wed, 7 May 2014 09:42:44 -0400 From: Denys Vlasenko To: linux-kernel@vger.kernel.org Cc: Denys Vlasenko , Frederic Weisbecker , Hidetoshi Seto , Fernando Luis Vazquez Cao , Tetsuo Handa , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Andrew Morton , Arjan van de Ven , Oleg Nesterov Subject: [PATCH 3/4 v2] nohz: Fix idle/iowait counts going backwards Date: Wed, 7 May 2014 15:41:33 +0200 Message-Id: <1399470094-8070-3-git-send-email-dvlasenk@redhat.com> In-Reply-To: <1399470094-8070-1-git-send-email-dvlasenk@redhat.com> References: <1399470094-8070-1-git-send-email-dvlasenk@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With this change, "iowait-ness" of every idle period is decided at the moment it starts: if this CPU's run-queue had tasks waiting on I/O, then this idle period's duration will be added to iowait_sleeptime. This fixes the bug where iowait and/or idle counts could go backwards, but iowait accounting is not precise (it can show more iowait that there really is). v2: Use symbolic constants for TRUE_IDLE and IOWAIT_IDLE. Signed-off-by: Denys Vlasenko Cc: Frederic Weisbecker Cc: Hidetoshi Seto Cc: Fernando Luis Vazquez Cao Cc: Tetsuo Handa Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Andrew Morton Cc: Arjan van de Ven Cc: Oleg Nesterov --- kernel/time/tick-sched.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 8f0f2ee..7d0e14a 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -406,6 +406,11 @@ static void tick_nohz_update_jiffies(ktime_t now) touch_softlockup_watchdog(); } +enum { + TRUE_IDLE = 1, + IOWAIT_IDLE = 2, +}; + static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now) { ktime_t delta; @@ -413,7 +418,7 @@ static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now) /* Updates the per cpu time idle statistics counters */ write_seqcount_begin(&ts->idle_sleeptime_seq); delta = ktime_sub(now, ts->idle_entrytime); - if (nr_iowait_cpu(smp_processor_id()) > 0) + if (ts->idle_active == IOWAIT_IDLE) ts->iowait_sleeptime = ktime_add(ts->iowait_sleeptime, delta); else ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta); @@ -429,7 +434,7 @@ static ktime_t tick_nohz_start_idle(struct tick_sched *ts) write_seqcount_begin(&ts->idle_sleeptime_seq); ts->idle_entrytime = now; - ts->idle_active = 1; + ts->idle_active = nr_iowait_cpu(smp_processor_id()) ? IOWAIT_IDLE : TRUE_IDLE; write_seqcount_end(&ts->idle_sleeptime_seq); sched_clock_idle_sleep_event(); @@ -469,7 +474,7 @@ u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time) seq = read_seqcount_begin(&ts->idle_sleeptime_seq); idle = ts->idle_sleeptime; - if (ts->idle_active && !nr_iowait_cpu(cpu)) { + if (ts->idle_active == TRUE_IDLE) { delta = ktime_sub(now, ts->idle_entrytime); idle = ktime_add(idle, delta); } @@ -511,7 +516,7 @@ u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time) seq = read_seqcount_begin(&ts->idle_sleeptime_seq); iowait = ts->iowait_sleeptime; - if (ts->idle_active && nr_iowait_cpu(cpu) > 0) { + if (ts->idle_active == IOWAIT_IDLE) { delta = ktime_sub(now, ts->idle_entrytime); iowait = ktime_add(ts->iowait_sleeptime, delta); } -- 1.8.1.4