[RAMEN9610-9418][COMMON] sched: frt: Fix zero dividing bug
authorYoungtae Lee <yt0729.lee@samsung.com>
Mon, 15 Oct 2018 06:21:01 +0000 (15:21 +0900)
committerCosmin Tanislav <demonsingur@gmail.com>
Mon, 22 Apr 2024 17:24:57 +0000 (20:24 +0300)
Change-Id: Id738b19174de909113aa8c5224a3e57f1762073d
Signed-off-by: Youngtae Lee <yt0729.lee@samsung.com>
kernel/sched/rt.c

index da5b42c1ab6bb0e92aa8cf57c3741eb1d51f4070..b998cf02d4ed1bda7e1f4853c6a504c337ffa0a5 100644 (file)
@@ -39,7 +39,9 @@ DEFINE_RAW_SPINLOCK(frt_lock);
 DEFINE_PER_CPU_SHARED_ALIGNED(struct frt_dom *, frt_rqs);
 
 static struct kobject *frt_kobj;
+#define RATIO_SCALE_SHIFT      10
 #define cpu_util(rq) (rq->cfs.avg.util_avg + rq->rt.avg.util_avg)
+#define ratio_scale(v, r) (((v) * (r) * 10) >> RATIO_SCALE_SHIFT)
 
 static int frt_set_coverage_ratio(int cpu);
 static int frt_set_active_ratio(int cpu);
@@ -149,12 +151,12 @@ static int frt_set_active_ratio(int cpu)
        unsigned long capacity;
        struct frt_dom *dom = per_cpu(frt_rqs, cpu);
 
-       if (!dom)
+       if (!dom || !cpu_active(cpu))
                return -1;
 
        capacity = get_cpu_max_capacity(cpu) *
                        cpumask_weight(cpu_coregroup_mask(cpu));
-       dom->active_thr = (capacity * dom->active_ratio) / 100;
+       dom->active_thr = ratio_scale(capacity, dom->active_ratio);
 
        return 0;
 }
@@ -164,10 +166,11 @@ static int frt_set_coverage_ratio(int cpu)
        unsigned long capacity;
        struct frt_dom *dom = per_cpu(frt_rqs, cpu);
 
-       if (!dom)
+       if (!dom || !cpu_active(cpu))
                return -1;
+
        capacity = get_cpu_max_capacity(cpu);
-       dom->coverage_thr = (capacity * dom->coverage_ratio) / 100;
+       dom->coverage_thr = ratio_scale(capacity, dom->coverage_ratio);
 
        return 0;
 }
@@ -193,6 +196,7 @@ static void update_activated_cpus(void)
        list_for_each_entry_reverse(dom, &frt_list, list) {
                unsigned long dom_util_sum = 0;
                unsigned long dom_active_thr = 0;
+               unsigned long capacity;
                struct cpumask active_cpus;
                int first_cpu, cpu;
 
@@ -206,8 +210,9 @@ static void update_activated_cpus(void)
                        struct rq *rq = cpu_rq(cpu);
                        dom_util_sum += cpu_util(rq);
                }
-               dom_active_thr = (get_cpu_max_capacity(first_cpu) *
-                       cpumask_weight(&active_cpus) * dom->active_ratio) / 100;
+
+               capacity = get_cpu_max_capacity(first_cpu) * cpumask_weight(&active_cpus);
+               dom_active_thr = ratio_scale(capacity, dom->active_ratio);
 
                /* domain is idle */
                if (dom_util_sum < dom_active_thr) {