BACKPORT: sched: loadavg: consolidate LOAD_INT, LOAD_FRAC, CALC_LOAD
authorJohannes Weiner <hannes@cmpxchg.org>
Fri, 26 Oct 2018 22:06:11 +0000 (15:06 -0700)
committerwangwang <wangwang1@lenovo.com>
Wed, 13 Nov 2019 02:34:38 +0000 (10:34 +0800)
There are several Defenderinitions of those functions/macros in places that
mess with fixed-point load averages.  Provide an official version.

[akpm@linux-foundation.org: fix missed conversion in block/blk-iolatency.c]
Link: http://lkml.kernel.org/r/20180828172258.3185-5-hannes@cmpxchg.org
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Suren Baghdasaryan <surenb@google.com>
Tested-by: Daniel Drake <drake@endlessm.com>
Cc: Christopher Lameter <cl@linux.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Johannes Weiner <jweiner@fb.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Enderborg <peter.enderborg@sony.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Vinayak Menon <vinmenon@codeaurora.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 8508cf3ffad4Defendera202b303e5b6379efc4cd9054)

Conflicts:
        block/blk-iolatency.c

(1. skipped changes in block/blk-iolatency.c as file does not exist in 4.14)

Bug: 127712811
Test: lmkd in PSI mode
Change-Id: Ifb7e12280b2aa4d379df29e24bbeab3e82a0bff8
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
arch/powerpc/platforms/cell/cpufreq_spudemand.c
arch/powerpc/platforms/cell/spufs/sched.c
arch/s390/appldata/appldata_os.c
drivers/cpuidle/governors/menu.c
fs/proc/loadavg.c
include/linux/sched/loadavg.h
kernel/debug/kdb/kdb_main.c
kernel/sched/loadavg.c

index 882944c36ef571c21132c21c2429f65bd3ccea7b..5d8e8b6bb1cc9a7bcfd1ecb735e023221c1b0df7 100644 (file)
@@ -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);
 
index 1fbb5da17dd27ffa2ceb26e09614111e0955a3a9..509cf67091318dfd027afabec8c331bfcbc9c2b5 100644 (file)
@@ -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(unsigned long data)
@@ -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;
index 45b3178200abc184ef790458d7d9c44d717379df..a8aac17e1e82db5a3babe425fd555a5928605524 100644 (file)
 
 #include "appldata.h"
 
-
-#define LOAD_INT(x) ((x) >> FSHIFT)
-#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
-
 /*
  * OS data
  *
index 58c103b5892b2924976bf3d5cedfeecdbed4e932..55f55aec6ccb347d5061f80f9c5221b35482fd9f 100644 (file)
@@ -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;
index 9bc5c58c00ee7a97964482ccd0ad78fd73a4406c..b3c0475f88de08474a2b886fdac6b2341c982502 100644 (file)
@@ -10,9 +10,6 @@
 #include <linux/seqlock.h>
 #include <linux/time.h>
 
-#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];
index 80bc84ba5d2a937e6860414f25c6351fb681e95d..cc9cc62bb1f86a5a27f77fa62cdfca37f53c7204 100644 (file)
@@ -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);
 
index 993db6b2348e7decd168992d0dfd3a62e1c7f295..3083df2a783e9f4d551a5239f20ed2dae1b2e6da 100644 (file)
@@ -2586,16 +2586,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"
index 89a989e4d75876e38ca704854145dc98c71f2ffe..d37eb9fe8aa8a292bbb3404bdca636bfe06923e8 100644 (file)
@@ -95,21 +95,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.