From patchwork Thu Oct 4 07:42:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 148106 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp618748lji; Thu, 4 Oct 2018 00:42:20 -0700 (PDT) X-Google-Smtp-Source: ACcGV62scUTnguzPL1Gn2Feld8XAlbaBH+s2wx/SkQY+mTz4jqH5N6eL3re+WS2CUPCom5uaQ0ZN X-Received: by 2002:a63:e05:: with SMTP id d5-v6mr4597414pgl.272.1538638939884; Thu, 04 Oct 2018 00:42:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538638939; cv=none; d=google.com; s=arc-20160816; b=pYLbvey6hx8ba8vIDZ8+tIdfcnlxUGC8WZNVl6pTHViK5VpRYu55R6iJhaioCN7Dc6 hdpUAFnLU3AwH/vVNFGMeS2X5IyQnKdFvuTKtJIWD89RnR1rEAAntYJbjAT+fEUpIWIP YP3JM25oJqtmU8p+HwHF3nZN8nKXwtFHla+JTTDXLX+yU6G+sMJcBl+S5A7wah8WjkxF 6oaSHWUiJxwHduTA4wZ8qvdwbXCTbd5zfaM9c7rQeJ5P4e11hqCxA5kw2AKNE6ZCp/+S CZ/qrfdqvLhLOa9YBMeGrgVi74muzVeie3UMRRlV1XfF5843goYnWoU4lsIaditLnh2w R11A== 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=G8KE0KJrHfkVSbRNTnKXaz2S9vIBp4IhY5kWUCvJkJ0=; b=ZVvCmv5o+DwZTQ9ts3nfSPQsUa2ZGkaDrkbjJQfklDlfeI9uksT4yEqwxfAjBQEW5W TnV/vA4HE7NiVZNp6S4e1xE0157y7v83+g6nY8EhnEeYckRIsaJuR2fENeTrOvObuSvi wmATpz3SmnEc+n0s55Nl9LSDzt4Up3yd5rPqzsA1ze9ZArJo1e9RfDp6LqjGbrCOj1hG aXW/4cks6DnciJbZIzWxem49wN3iYhzplE66zj6J7GDXbA3hSijtKrN4JeUsi1oyayC3 m3PtMmw48nozLhZsMdpxghS62U4mPQ0RZO1kzfPnIVIcz9pBo0TUgIdNpRRmbfiiGbjo 9DFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="YwIkZU5/"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e3-v6si3889249pgg.530.2018.10.04.00.42.19; Thu, 04 Oct 2018 00:42:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=@linaro.org header.s=google header.b="YwIkZU5/"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727477AbeJDOeM (ORCPT + 10 others); Thu, 4 Oct 2018 10:34:12 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:41548 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727264AbeJDOeM (ORCPT ); Thu, 4 Oct 2018 10:34:12 -0400 Received: by mail-wr1-f68.google.com with SMTP id x12-v6so8736734wru.8 for ; Thu, 04 Oct 2018 00:42:17 -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=G8KE0KJrHfkVSbRNTnKXaz2S9vIBp4IhY5kWUCvJkJ0=; b=YwIkZU5/OolhcvzAXeCYyF0DsU1328A0Iagqn37qvWYimqLwH1Esl0Z2HVGQ+ohfiS 5xCMZHcbu8N+wswCi/A7ZvRFRpg6+kFejCjVaeLJo5XRlQ+2r8IKsIcF3m275EF3kk7u h88oQlbeoAOClDWaSa8RDGB0nZBs9xybVnLVQ= 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=G8KE0KJrHfkVSbRNTnKXaz2S9vIBp4IhY5kWUCvJkJ0=; b=qpnVGPAfXRTIPHDXoPQsqs5cY6Zvk9moAVfjo62NKYQm9A3UdsTjCrcBckFCmY1OR0 Vi8YeF4RJZ6rLu0q+LInPraQowZdmEZjV2Sqn16tbJSpeeA7dONmDOtcUYVIllmxUVQe wWwFqQ831emJf9Z3GGXh+I1RxdvhtWTn/YFE5+LsIC8ODui2yQC2NiGqw1jLx0xm+hxa wypK+hnB/re9kFMzeVC8aEq/rqe53uxILbOrWQBtw1k7DPw3ypoUTdXm6qcUnRcV+sD/ N/UWsflg8tlslevnh1QWKT65YIoWsqq0ngJjkGKZXjkWjik4EWk0sV9Nnq6LBn0IEeQM Y5FQ== X-Gm-Message-State: ABuFfojyDBZRxX0rKuRrHE3TlsNVfwNouAY/ezla5qKeVWDX2TUyi3L0 wAuG8XwhRWbsFYYDCO99ZiZIq8lA4cg= X-Received: by 2002:a5d:404b:: with SMTP id w11-v6mr3564889wrp.147.1538638936523; Thu, 04 Oct 2018 00:42:16 -0700 (PDT) Received: from localhost.localdomain (225.182.88.92.rev.sfr.net. [92.88.182.225]) by smtp.gmail.com with ESMTPSA id t82-v6sm651579wme.30.2018.10.04.00.42.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 00:42:15 -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 1/2] sched: Factor out nr_iowait and nr_iowait_cpu Date: Thu, 4 Oct 2018 09:42:06 +0200 Message-Id: <1538638927-26846-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 The function nr_iowait_cpu() can be used directly by nr_iowait() instead of duplicating code. Call nr_iowait_cpu() from nr_iowait() Signed-off-by: Daniel Lezcano --- kernel/sched/core.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) -- 2.7.4 Reviewed-by: Rafael J. Wysocki diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 625bc98..b88a145 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2873,6 +2873,24 @@ unsigned long long nr_context_switches(void) 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) +{ + 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). @@ -2909,31 +2927,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 07:42:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 148107 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp618847lji; Thu, 4 Oct 2018 00:42:26 -0700 (PDT) X-Google-Smtp-Source: ACcGV63YMtdDqNMzAWq1UMf2K/4/Uuhs3LZodNzwCrUhtsGdkugF6ofOZ2mun7EuqrIvf6NWHgqs X-Received: by 2002:a63:8a41:: with SMTP id y62-v6mr4559893pgd.420.1538638946538; Thu, 04 Oct 2018 00:42:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538638946; cv=none; d=google.com; s=arc-20160816; b=Tic1C6ofnq5loDYfs81znhdZcbYS+8KHNNeGM8ZlQ71ycGLmjrFlh/LvF5Pb3faZbe eTFAGjb4EqE3loOKyRRr6605y7YMYmd8irYsz065cIiq63Kovt13ri3K1j0DMT7bd3YO miSgTmi/j6GVQmM9FDSgki7okxzgyx0jrJavsNJ/+XMlYlSUs7G325RIYzw66Zi4hA9B CP45cz/h83ad1at2sAl1XLOlc52yXhQtcWQ2KF+F6fg8NUpCa8d3Q+E28mKMciRrM+ze 2w9jIzaJZjnbPvXlVj6Mmf4BPitohadNDqWpHxEs8IeiAOv/xqNHQP/DtH6boq/8dh7Z I63w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=+3jnIbu0V272vA/+ZsYlslEHmE6GhIp6KPEwTTEGjsk=; b=dvM9071RTLLyVLwe9+UGtwPk/h90+9FHRFLUPcaKHapMbk5LFVVK/bKZd6ozI+u8UM fA2WuMe7KC0sshNp4x6lx0raVMM2YnWnxKELQgFop3XzJPVU4EmNwbe51Qw13ncWPLKz 95dIKwVhWv/NFPa2h3jfqmvUyQGG04wqvRSz07BUx/baiymVb6oORC85NhWS2isTe6l7 FCArxTcKTAdL7wBFeduvF1ySXjZnp1EPwgWuZhQQGdlGoIB1eOj+MyffuaHuUHaEBlti yaIedoKKRX0vn/aqIXjmFkgd3OLbKtseqdPOdSc6QKBlbhAqfzGCSspebmasF/RbjwOl GBrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Hin/hrrQ"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 28-v6si3458823pgy.68.2018.10.04.00.42.26; Thu, 04 Oct 2018 00:42:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=@linaro.org header.s=google header.b="Hin/hrrQ"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727589AbeJDOeT (ORCPT + 10 others); Thu, 4 Oct 2018 10:34:19 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:45485 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727476AbeJDOeT (ORCPT ); Thu, 4 Oct 2018 10:34:19 -0400 Received: by mail-wr1-f65.google.com with SMTP id q5-v6so8717327wrw.12 for ; Thu, 04 Oct 2018 00:42:23 -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=+3jnIbu0V272vA/+ZsYlslEHmE6GhIp6KPEwTTEGjsk=; b=Hin/hrrQVqPBkwPHlwr8JN8H2LNlB1uFgrzOUjAHMARGey2vKLUaurn0roaJeZqNbO 8zHxI9dLsTqimVNecome89PSYKoW1ZcPQNfSm4ZB0prZuUcHQxzp4OQR55d+UP8VlKnc OM7WQt96RiGmxUGW2kuyCBrtTKndRaziQgbxs= 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=+3jnIbu0V272vA/+ZsYlslEHmE6GhIp6KPEwTTEGjsk=; b=ZHbDmyLHoGA3L4svWs3TnuYqXdLNLx26SAoxneN+rfWfiS/cdrziPcff+pXUL5yQcZ SG9yGw0xS5OpVIFML83L97Vbvj8fbmvmDx1S9mCgLiZb9VnQQ4WF7AoxKdAgb47lEW/q 6PgsTFiUyW8Gc6S5G4dXUHBRjza/Ko27TKHQGfJ6OVjph4S2Qqu7fe+q4NFEAxKGu54r WUlPXz43LObIRsXrLZ4I/kQOVJZJuU4frAJi8HWF7gVubliMCgDYUvsFhHCItdfTrnJa CGNMhJOM7wyg0SiEAPc/GUFddeAuXkSkv1pUC+hT4qaXOSeb6YS9Ri7k4CoZlZPIf+AT cdrA== X-Gm-Message-State: ABuFfohXx/t8eIFnHT2DrHgomMnJLhbAs0WMDTV3IVga5aDypxKMRiLb wzSTdeXcfRAobRzx47q8wqdocw== X-Received: by 2002:adf:f6c4:: with SMTP id y4-v6mr1973961wrp.79.1538638942782; Thu, 04 Oct 2018 00:42:22 -0700 (PDT) Received: from localhost.localdomain (225.182.88.92.rev.sfr.net. [92.88.182.225]) by smtp.gmail.com with ESMTPSA id t82-v6sm651579wme.30.2018.10.04.00.42.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 00:42:22 -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 , Philippe Ombredanne , Thomas Gleixner , Greg Kroah-Hartman , Kate Stewart , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 2/2] cpuidle/drivers/menu: Remove get_loadavg in the performance multiplier Date: Thu, 4 Oct 2018 09:42:07 +0200 Message-Id: <1538638927-26846-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1538638927-26846-1-git-send-email-daniel.lezcano@linaro.org> References: <1538638927-26846-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 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 --- drivers/cpuidle/governors/menu.c | 26 +++++++------------------- include/linux/sched/stat.h | 1 - kernel/sched/core.c | 13 ------------- 3 files changed, 7 insertions(+), 33 deletions(-) -- 2.7.4 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 b88a145..5605f03 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2873,25 +2873,12 @@ unsigned long long nr_context_switches(void) 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) { 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). *