Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp983010imm; Wed, 1 Aug 2018 08:20:15 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfDrFQ5N4DzqJvOiTrl1xrzROLGHlobJ8ruspzjDbwovM0rESnmLCUZy71zjtITxC1Bfr53 X-Received: by 2002:a17:902:8645:: with SMTP id y5-v6mr25133812plt.334.1533136815369; Wed, 01 Aug 2018 08:20:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533136815; cv=none; d=google.com; s=arc-20160816; b=auC21zMXtH2bu6A6d9X7EoROg6M3sxdwZ9NBfet5EjiQ8a5b6uH1ouB+omJ5GevbYv OnoPrXxddAINehZ7l9XvXaB6tkErS7ygPguOfB3RPukyBnjth9GIanmpyy9CgoXi4rUx OP1lsySLj06o0+NIzsO+hK6eLuu2UdFuKvt91eEau7DdJYfXrNmQ7M5vT0S0HC0GX8YD CHLkZEZqoyeUWpbzi9nFifWznUVsoZt92Jpu/TGqbk9DsSjkzByEMOYOx7mmIV+ALljg AgE/yU+PXnIfXHHwz/YmGe1GcXNSjFStifONTCn+099RMZ1QZaiBj2pJVnYAX8atokQo HYPw== 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:arc-authentication-results; bh=eqQ2drM6ZB7t7xA4Vh6Us/fahKGTELhOpcUpFPV0E1Y=; b=eTSMY8PJjJWX7eB/x7Ajnvs0dt3K07o036LuJZEC5Ij+Blo0ve7ABz5ZOFNY5uXSMT tKFR6CEp5dNzWOvJyMeYeMS05UqpZgV9IYBL5Rllr9BJcOpApN0OXnyjAHTnr1v6t2xc 5+K1/t/GQKY2QlC3kCqy/Lbcyle1GMlyh2ftUm0yk+XwF9+OIoZCvcZvKJ3nMauLZg35 QuxgLkNNGR3Se47bXodKq/Una90S+xjlzOTxSIUw1jNMrD6qIJMXLaz8mPsX+I/N5Vej s87EI7jhLIBkU/V1DZp4FLlypg/UKj2c/5ebxvW5NX1Ooyeq5/Qdk/jmuag3VGpnYi/N spBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=wuHK9XyX; 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=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z8-v6si17752682pgr.260.2018.08.01.08.20.00; Wed, 01 Aug 2018 08:20:15 -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; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=wuHK9XyX; 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=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389788AbeHARDk (ORCPT + 99 others); Wed, 1 Aug 2018 13:03:40 -0400 Received: from mail-qt0-f194.google.com ([209.85.216.194]:42026 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389762AbeHARDj (ORCPT ); Wed, 1 Aug 2018 13:03:39 -0400 Received: by mail-qt0-f194.google.com with SMTP id z8-v6so20251490qto.9 for ; Wed, 01 Aug 2018 08:17:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eqQ2drM6ZB7t7xA4Vh6Us/fahKGTELhOpcUpFPV0E1Y=; b=wuHK9XyXw0rF+Tp2cArx0YiZqM/GjpVtqcyTSrQeYiIS+B02zaDa+3gDsB8r9chs3T 6wcThnIY0N8pzjRHhlNIQmTU5fh8GLb1Fob9wXWMv6gFP3uQOPlmNiGg2Qz9i9fA5lkb ZPH7f5zg6kA7DgSYXrtNJpKGKXGNX+Z6D+ZdxZKzPFWjB+ggK2J+dnxyxU7IUO0ZxL5+ 2puJqTqNlCwmu7rM/O+vUSEyll0576DLkwWzoaTZmgg3Uk2/ZhM9cvbgvz7MtV3Dubji 3c2eic5pUxlRK8eO79t1PVgcoesY4Tit5dLqNm8JpVfd6pV/ndmwAc89/ZZkZzj9+HRB tgkw== 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=eqQ2drM6ZB7t7xA4Vh6Us/fahKGTELhOpcUpFPV0E1Y=; b=Frs1K3WGlJiRzuzNoIHwzuf6LnimkuA24ZEcPfMLcgk2SLvLXtu20mULcc9Pml7tEC iIYVPkk3SmzpDZLzIimQTur2Sb1hA1ioDMTlyqfFozU/fA5vXs3U+5REBmbA5fktwnTz kBJ49cuLvmcvZca2XILxT2TwsumgpDo/HPL7Z1sq5FV2F6qRAhxWDxOKyFYEeYBLYsFB FDNEj5Xb0s3b9O+M6Y28FoKbA1Sc14aAkqvb+gMkokHMI+vfJZxVaWOL4blXlHe6Zs/N 6AVefIOU4dwO9Bt24ULRs8/zZxJ4q12xV6MLk08DNB3XdL+g/BHn4cXXbUB80+3MWZRe vMTw== X-Gm-Message-State: AOUpUlEjylF0ebNdyot8FJOdx3WqZQ1hpwV5Iksh7P/vpQTxwBbHor1g NoW3TEJkVgZzi89/400gZtIlYQ== X-Received: by 2002:a0c:fa4e:: with SMTP id k14-v6mr23408603qvo.35.1533136647891; Wed, 01 Aug 2018 08:17:27 -0700 (PDT) Received: from localhost (216.49.36.201.res-cmts.bus.ptd.net. [216.49.36.201]) by smtp.gmail.com with ESMTPSA id v4-v6sm11040590qth.23.2018.08.01.08.17.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Aug 2018 08:17:26 -0700 (PDT) From: Johannes Weiner To: Ingo Molnar , Peter Zijlstra , Andrew Morton , Linus Torvalds Cc: Tejun Heo , Suren Baghdasaryan , Daniel Drake , Vinayak Menon , Christopher Lameter , Mike Galbraith , Shakeel Butt , Peter Enderborg , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 4/9] sched: loadavg: consolidate LOAD_INT, LOAD_FRAC, CALC_LOAD Date: Wed, 1 Aug 2018 11:19:53 -0400 Message-Id: <20180801151958.32590-5-hannes@cmpxchg.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801151958.32590-1-hannes@cmpxchg.org> References: <20180801151958.32590-1-hannes@cmpxchg.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are several definitions of those functions/macros in places that mess with fixed-point load averages. Provide an official version. Signed-off-by: Johannes Weiner --- .../platforms/cell/cpufreq_spudemand.c | 2 +- arch/powerpc/platforms/cell/spufs/sched.c | 9 +++----- arch/s390/appldata/appldata_os.c | 4 ---- drivers/cpuidle/governors/menu.c | 4 ---- fs/proc/loadavg.c | 3 --- include/linux/sched/loadavg.h | 21 +++++++++++++++---- kernel/debug/kdb/kdb_main.c | 7 +------ kernel/sched/loadavg.c | 15 ------------- 8 files changed, 22 insertions(+), 43 deletions(-) diff --git a/arch/powerpc/platforms/cell/cpufreq_spudemand.c b/arch/powerpc/platforms/cell/cpufreq_spudemand.c index 882944c36ef5..5d8e8b6bb1cc 100644 --- a/arch/powerpc/platforms/cell/cpufreq_spudemand.c +++ b/arch/powerpc/platforms/cell/cpufreq_spudemand.c @@ -49,7 +49,7 @@ static int calc_freq(struct spu_gov_info_struct *info) cpu = info->policy->cpu; busy_spus = atomic_read(&cbe_spu_info[cpu_to_node(cpu)].busy_spus); - CALC_LOAD(info->busy_spus, EXP, busy_spus * FIXED_1); + info->busy_spus = calc_load(info->busy_spus, EXP, busy_spus * FIXED_1); pr_debug("cpu %d: busy_spus=%d, info->busy_spus=%ld\n", cpu, busy_spus, info->busy_spus); diff --git a/arch/powerpc/platforms/cell/spufs/sched.c b/arch/powerpc/platforms/cell/spufs/sched.c index ccc421503363..70101510b19d 100644 --- a/arch/powerpc/platforms/cell/spufs/sched.c +++ b/arch/powerpc/platforms/cell/spufs/sched.c @@ -987,9 +987,9 @@ static void spu_calc_load(void) unsigned long active_tasks; /* fixed-point */ active_tasks = count_active_contexts() * FIXED_1; - CALC_LOAD(spu_avenrun[0], EXP_1, active_tasks); - CALC_LOAD(spu_avenrun[1], EXP_5, active_tasks); - CALC_LOAD(spu_avenrun[2], EXP_15, active_tasks); + spu_avenrun[0] = calc_load(spu_avenrun[0], EXP_1, active_tasks); + spu_avenrun[1] = calc_load(spu_avenrun[1], EXP_5, active_tasks); + spu_avenrun[2] = calc_load(spu_avenrun[2], EXP_15, active_tasks); } static void spusched_wake(struct timer_list *unused) @@ -1071,9 +1071,6 @@ void spuctx_switch_state(struct spu_context *ctx, } } -#define LOAD_INT(x) ((x) >> FSHIFT) -#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) - static int show_spu_loadavg(struct seq_file *s, void *private) { int a, b, c; diff --git a/arch/s390/appldata/appldata_os.c b/arch/s390/appldata/appldata_os.c index 433a994b1a89..54f375627532 100644 --- a/arch/s390/appldata/appldata_os.c +++ b/arch/s390/appldata/appldata_os.c @@ -25,10 +25,6 @@ #include "appldata.h" - -#define LOAD_INT(x) ((x) >> FSHIFT) -#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) - /* * OS data * diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index 1bfe03ceb236..3738b670df7a 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -133,10 +133,6 @@ struct menu_device { int interval_ptr; }; - -#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; diff --git a/fs/proc/loadavg.c b/fs/proc/loadavg.c index b572cc865b92..8bee50a97c0f 100644 --- a/fs/proc/loadavg.c +++ b/fs/proc/loadavg.c @@ -10,9 +10,6 @@ #include #include -#define LOAD_INT(x) ((x) >> FSHIFT) -#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) - static int loadavg_proc_show(struct seq_file *m, void *v) { unsigned long avnrun[3]; diff --git a/include/linux/sched/loadavg.h b/include/linux/sched/loadavg.h index 80bc84ba5d2a..cc9cc62bb1f8 100644 --- a/include/linux/sched/loadavg.h +++ b/include/linux/sched/loadavg.h @@ -22,10 +22,23 @@ extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift); #define EXP_5 2014 /* 1/exp(5sec/5min) */ #define EXP_15 2037 /* 1/exp(5sec/15min) */ -#define CALC_LOAD(load,exp,n) \ - load *= exp; \ - load += n*(FIXED_1-exp); \ - load >>= FSHIFT; +/* + * a1 = a0 * e + a * (1 - e) + */ +static inline unsigned long +calc_load(unsigned long load, unsigned long exp, unsigned long active) +{ + unsigned long newload; + + newload = load * exp + active * (FIXED_1 - exp); + if (active >= load) + newload += FIXED_1-1; + + return newload / FIXED_1; +} + +#define LOAD_INT(x) ((x) >> FSHIFT) +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) extern void calc_global_load(unsigned long ticks); diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index e405677ee08d..a8f5aca5eb5e 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c @@ -2556,16 +2556,11 @@ static int kdb_summary(int argc, const char **argv) } kdb_printf("%02ld:%02ld\n", val.uptime/(60*60), (val.uptime/60)%60); - /* lifted from fs/proc/proc_misc.c::loadavg_read_proc() */ - -#define LOAD_INT(x) ((x) >> FSHIFT) -#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) kdb_printf("load avg %ld.%02ld %ld.%02ld %ld.%02ld\n", LOAD_INT(val.loads[0]), LOAD_FRAC(val.loads[0]), LOAD_INT(val.loads[1]), LOAD_FRAC(val.loads[1]), LOAD_INT(val.loads[2]), LOAD_FRAC(val.loads[2])); -#undef LOAD_INT -#undef LOAD_FRAC + /* Display in kilobytes */ #define K(x) ((x) << (PAGE_SHIFT - 10)) kdb_printf("\nMemTotal: %8lu kB\nMemFree: %8lu kB\n" diff --git a/kernel/sched/loadavg.c b/kernel/sched/loadavg.c index a171c1258109..54fbdfb2d86c 100644 --- a/kernel/sched/loadavg.c +++ b/kernel/sched/loadavg.c @@ -91,21 +91,6 @@ long calc_load_fold_active(struct rq *this_rq, long adjust) return delta; } -/* - * a1 = a0 * e + a * (1 - e) - */ -static unsigned long -calc_load(unsigned long load, unsigned long exp, unsigned long active) -{ - unsigned long newload; - - newload = load * exp + active * (FIXED_1 - exp); - if (active >= load) - newload += FIXED_1-1; - - return newload / FIXED_1; -} - #ifdef CONFIG_NO_HZ_COMMON /* * Handle NO_HZ for the global load-average. -- 2.18.0