From patchwork Thu Oct 4 12:04:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 10626045 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 695E615A6 for ; Thu, 4 Oct 2018 12:04:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5AE6728F5D for ; Thu, 4 Oct 2018 12:04:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F59428F5A; Thu, 4 Oct 2018 12:04:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFAD028F56 for ; Thu, 4 Oct 2018 12:04:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727370AbeJDS5M (ORCPT ); Thu, 4 Oct 2018 14:57:12 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:36796 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727322AbeJDS5M (ORCPT ); Thu, 4 Oct 2018 14:57:12 -0400 Received: by mail-wm1-f65.google.com with SMTP id a8-v6so4753578wmf.1 for ; Thu, 04 Oct 2018 05:04:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=x4J7xQAH031mjKHecE55aBySuA5+RK8ZxvbBGd/a5Lg=; b=kXKUDqF1MBWFEBNw+mIUqUAZqpJ+WENtc/vqic+3IR/vuAtf6dwWz7RkrBN8axWJYu 223pXr+fxONGIiXE1sDrqKq2MbbqOyIBcdmvagLOetrW2eGvqULHxh67bqL+hJ9vg8// 74xOxLT2bVn8O34hKuVgMtV7ylDsUymiLvCTA= 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=x4J7xQAH031mjKHecE55aBySuA5+RK8ZxvbBGd/a5Lg=; b=V0cksImV+G7UHYEnrwXANnXQF+RT5oOk/O2Czp4e4iQQ9XGzOn2N7dDqM2bfU2sJuX bkcZyuKBPEm9DhPkFde+PVln3j4zBBo497HFpJ9vdqYYGC6c+7XIeWfCZwUJj8nVOMrq yOgz+TsNybRF94vj/NTcV7n/q3Z/ajlwfUB8l8trAjHxtID4hXBEpcpKT6oLZKa2Idl5 CZUQvIz2vjdjrDjy9Qh16ZlqkIQ4VwgLnD2mgfpYucVn63UlkRkycNdrnoNYwl04wybl legnrV44m/q92OJrQXM82tGxBY8HhPw0C84Atky3BlcnX7fkgDxXHmYnjklAPc+46lfS Jl/g== X-Gm-Message-State: ABuFfoiOoS8QtLKH68+WhEr99UXQsWFJDD1VgDgtU0ree0Pn4h2G3Ig/ R8KgjWyEEKr8IX4GuR36Jm9jUg== X-Google-Smtp-Source: ACcGV61ckI2zNfd7HPWQOnopKq3Iq1VLlicRHcBYh2ZvqhPMjrvX/N29TK/OdpHhdCyQeGZyWmYYsw== X-Received: by 2002:a1c:c784:: with SMTP id x126-v6mr4757189wmf.90.1538654652811; Thu, 04 Oct 2018 05:04:12 -0700 (PDT) Received: from localhost.localdomain (101.142.88.92.rev.sfr.net. [92.88.142.101]) by smtp.gmail.com with ESMTPSA id p11-v6sm4477132wrd.74.2018.10.04.05.04.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 05:04:12 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: rjw@rjwysocki.net, linux-pm@vger.kernel.org, Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org (open list:SCHEDULER) Subject: [PATCH V2 1/2] sched: Factor out nr_iowait and nr_iowait_cpu Date: Thu, 4 Oct 2018 14:04:02 +0200 Message-Id: <1538654644-32705-1-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The function nr_iowait_cpu() can be used directly by nr_iowait() instead of duplicating code. Call nr_iowait_cpu() from nr_iowait() Reviewed-by: Rafael J. Wysocki Signed-off-by: Daniel Lezcano Acked-by: Peter Zijlstra (Intel) --- kernel/sched/core.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 625bc98..43efb74 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2875,6 +2875,25 @@ unsigned long long nr_context_switches(void) } /* + * Consumers of these two interfaces, like for example the cpufreq menu + * governor are using nonsensical data. Boosting frequency for a CPU that has + * IO-wait which might not even end up running the task when it does become + * runnable. + */ + +unsigned long nr_iowait_cpu(int cpu) +{ + return atomic_read(&cpu_rq(cpu)->nr_iowait); +} + +void get_iowait_load(unsigned long *nr_waiters, unsigned long *load) +{ + struct rq *rq = this_rq(); + *nr_waiters = atomic_read(&rq->nr_iowait); + *load = rq->load.weight; +} + +/* * IO-wait accounting, and how its mostly bollocks (on SMP). * * The idea behind IO-wait account is to account the idle time that we could @@ -2909,31 +2928,11 @@ unsigned long nr_iowait(void) unsigned long i, sum = 0; for_each_possible_cpu(i) - sum += atomic_read(&cpu_rq(i)->nr_iowait); + sum += nr_iowait_cpu(i); return sum; } -/* - * Consumers of these two interfaces, like for example the cpufreq menu - * governor are using nonsensical data. Boosting frequency for a CPU that has - * IO-wait which might not even end up running the task when it does become - * runnable. - */ - -unsigned long nr_iowait_cpu(int cpu) -{ - struct rq *this = cpu_rq(cpu); - return atomic_read(&this->nr_iowait); -} - -void get_iowait_load(unsigned long *nr_waiters, unsigned long *load) -{ - struct rq *rq = this_rq(); - *nr_waiters = atomic_read(&rq->nr_iowait); - *load = rq->load.weight; -} - #ifdef CONFIG_SMP /* From patchwork Thu Oct 4 12:04:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 10626047 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB54915A6 for ; Thu, 4 Oct 2018 12:04:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB9CA28F2F for ; Thu, 4 Oct 2018 12:04:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D930628F60; Thu, 4 Oct 2018 12:04:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A68128F66 for ; Thu, 4 Oct 2018 12:04:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727325AbeJDS5U (ORCPT ); Thu, 4 Oct 2018 14:57:20 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37319 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727415AbeJDS5T (ORCPT ); Thu, 4 Oct 2018 14:57:19 -0400 Received: by mail-wm1-f68.google.com with SMTP id 185-v6so8791662wmt.2 for ; Thu, 04 Oct 2018 05:04:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OGHug1XeN4tV030dZreKI6j+zq3kMpiVWtIizPDMgzc=; b=UD+UNGE8TOCehJc7k1YIt25sqZRDnAWdeNV65zygb45J0ljOkaSB0+xz/+yNl6TN9a Wfq/mXojmTGxEX99uc/WslItA3lW9RTWB/w6d9tjMVqEN7Ejg/tw7qydGwnRBux14WCh a/ciaZ9Em61jNKCoHoWXNVtTNtv6ylCyZ1hNA= 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:in-reply-to :references; bh=OGHug1XeN4tV030dZreKI6j+zq3kMpiVWtIizPDMgzc=; b=i95INM2JJWhj5TgyY+pBnHKhpEFR5Ueta/ofLJwiR58SlKHvcUzTXsi9SlANaIPOJW dn+2m87esg9H7AxMRe9puARqxORPpwUsCWSJ0xwql4uRquhar26Is7gIxZABlPZL5YQ+ hUFUTAjRNaB0aFrUUCZfjMIDScESx/GsbGGdlyxXd+Rhm7oAjRkl6OWbwB/Mw2ARoCMu 8zzzdJ53uMZwmQlQhdcYpG+F9QtcIXiKoWRj9T+7m1yhXy1+ypdoeNygFoYnOWJX1C3A Q3Fv16tdbRRylmOpk73ljR0vkC2bdXX9/ftEb9fk+OO+mRNxdb6p9cijhb+T0b+aimRd XuqA== X-Gm-Message-State: ABuFfoglK7RKqwtxfiq0qNWeLHMh/cfkgzev+AjtN4XM/bJUrf/C3oid ngrgkPdQI2YztAzsIV1vERQROA== X-Google-Smtp-Source: ACcGV63ZAMgdWR3dfssHApdKJTvdeHWTls1JksJ+63f6ZanlfpNnjAPPplNmBOF9BjyTP9FVgA1Vfw== X-Received: by 2002:a1c:f4e:: with SMTP id 75-v6mr4352729wmp.79.1538654659174; Thu, 04 Oct 2018 05:04:19 -0700 (PDT) Received: from localhost.localdomain (101.142.88.92.rev.sfr.net. [92.88.142.101]) by smtp.gmail.com with ESMTPSA id p11-v6sm4477132wrd.74.2018.10.04.05.04.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 05:04:18 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: rjw@rjwysocki.net, linux-pm@vger.kernel.org, Peter Zijlstra , Todd Kjos , Joel Fernandes , Colin Cross , Ramesh Thomas , Mel Gorman , Ingo Molnar , "Rafael J. Wysocki" , Alex Shi , Thomas Gleixner , Philippe Ombredanne , Greg Kroah-Hartman , Kate Stewart , linux-kernel@vger.kernel.org (open list) Subject: [PATCH V2 2/2] cpuidle/drivers/menu: Remove get_loadavg in the performance multiplier Date: Thu, 4 Oct 2018 14:04:03 +0200 Message-Id: <1538654644-32705-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1538654644-32705-1-git-send-email-daniel.lezcano@linaro.org> References: <1538654644-32705-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The function get_loadavg() returns almost always zero. To be more precise, statistically speaking for a total of 1023379 times passing in the function, the load is equal to zero 1020728 times, greater than 100, 610 times, the remaining is between 0 and 5. In 2011, the get_loadavg() was removed from the Android tree because of the above [1]. At this time, the load was: unsigned long this_cpu_load(void) { struct rq *this = this_rq(); return this->cpu_load[0]; } In 2014, the code was changed by commit 372ba8cb46b2 (cpuidle: menu: Lookup CPU runqueues less) and the load is: void get_iowait_load(unsigned long *nr_waiters, unsigned long *load) { struct rq *rq = this_rq(); *nr_waiters = atomic_read(&rq->nr_iowait); *load = rq->load.weight; } with the same result. Both measurements show using the load in this code path does no matter anymore. Removing it. [1] https://android.googlesource.com/kernel/common/+/4dedd9f124703207895777ac6e91dacde0f7cc17 Cc: Peter Zijlstra Cc: Todd Kjos Cc: Joel Fernandes Cc: Colin Cross Cc: Ramesh Thomas Cc: Mel Gorman Signed-off-by: Daniel Lezcano Acked-by: Mel Gorman Reviewed-by: Rafael J. Wysocki Acked-by: Peter Zijlstra (Intel) --- drivers/cpuidle/governors/menu.c | 26 +++++++------------------- include/linux/sched/stat.h | 1 - kernel/sched/core.c | 7 ------- 3 files changed, 7 insertions(+), 27 deletions(-) diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index e26a409..066b01f 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -135,11 +135,6 @@ struct menu_device { #define LOAD_INT(x) ((x) >> FSHIFT) #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) -static inline int get_loadavg(unsigned long load) -{ - return LOAD_INT(load) * 10 + LOAD_FRAC(load) / 10; -} - static inline int which_bucket(unsigned int duration, unsigned long nr_iowaiters) { int bucket = 0; @@ -173,18 +168,10 @@ static inline int which_bucket(unsigned int duration, unsigned long nr_iowaiters * to be, the higher this multiplier, and thus the higher * the barrier to go to an expensive C state. */ -static inline int performance_multiplier(unsigned long nr_iowaiters, unsigned long load) +static inline int performance_multiplier(unsigned long nr_iowaiters) { - int mult = 1; - - /* for higher loadavg, we are more reluctant */ - - mult += 2 * get_loadavg(load); - - /* for IO wait tasks (per cpu!) we add 5x each */ - mult += 10 * nr_iowaiters; - - return mult; + /* for IO wait tasks (per cpu!) we add 10x each */ + return 1 + 10 * nr_iowaiters; } static DEFINE_PER_CPU(struct menu_device, menu_devices); @@ -290,7 +277,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, int idx; unsigned int interactivity_req; unsigned int expected_interval; - unsigned long nr_iowaiters, cpu_load; + unsigned long nr_iowaiters; ktime_t delta_next; if (data->needs_update) { @@ -307,7 +294,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, /* determine the expected residency time, round up */ data->next_timer_us = ktime_to_us(tick_nohz_get_sleep_length(&delta_next)); - get_iowait_load(&nr_iowaiters, &cpu_load); + nr_iowaiters = nr_iowait_cpu(dev->cpu); data->bucket = which_bucket(data->next_timer_us, nr_iowaiters); /* @@ -359,7 +346,8 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, * Use the performance multiplier and the user-configurable * latency_req to determine the maximum exit latency. */ - interactivity_req = data->predicted_us / performance_multiplier(nr_iowaiters, cpu_load); + interactivity_req = data->predicted_us / + performance_multiplier(nr_iowaiters); if (latency_req > interactivity_req) latency_req = interactivity_req; } diff --git a/include/linux/sched/stat.h b/include/linux/sched/stat.h index 04f1321..f30954c 100644 --- a/include/linux/sched/stat.h +++ b/include/linux/sched/stat.h @@ -20,7 +20,6 @@ extern unsigned long nr_running(void); extern bool single_task_running(void); extern unsigned long nr_iowait(void); extern unsigned long nr_iowait_cpu(int cpu); -extern void get_iowait_load(unsigned long *nr_waiters, unsigned long *load); static inline int sched_info_on(void) { diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 43efb74..48a786a 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2886,13 +2886,6 @@ unsigned long nr_iowait_cpu(int cpu) return atomic_read(&cpu_rq(cpu)->nr_iowait); } -void get_iowait_load(unsigned long *nr_waiters, unsigned long *load) -{ - struct rq *rq = this_rq(); - *nr_waiters = atomic_read(&rq->nr_iowait); - *load = rq->load.weight; -} - /* * IO-wait accounting, and how its mostly bollocks (on SMP). *