]> xenbits.xensource.com Git - legacy/linux-2.6.18-xen.git/commitdiff
cpufreq: Fix the ondemand driver for Xen. No 64-bit division allowed
authorKeir Fraser <keir@xensource.com>
Sat, 10 Nov 2007 10:18:28 +0000 (10:18 +0000)
committerKeir Fraser <keir@xensource.com>
Sat, 10 Nov 2007 10:18:28 +0000 (10:18 +0000)
in a 32-bit kernel except in special circumstances.
Signed-off-by: Keir Fraser <keir@xensource.com>
drivers/cpufreq/cpufreq_ondemand.c

index b08b9556bf8e5fe3ac634884f7c0e77894abed97..466ebe9b5f6f5aedf9e9c38e92cd0ac4cd48368a 100644 (file)
@@ -296,7 +296,7 @@ static int dbs_calc_load(struct cpu_dbs_info_s *this_dbs_info)
                cputime64_t total_idle_nsecs, tmp_idle_nsecs;
                cputime64_t total_wall_nsecs, tmp_wall_nsecs;
                struct cpu_dbs_info_s *j_dbs_info;
-               unsigned long tmp_load;
+               unsigned long tmp_load, tmp_wall_msecs, tmp_idle_msecs;
 
                j_dbs_info = &per_cpu(cpu_dbs_info, j);
                total_idle_nsecs = idletime[j];
@@ -312,8 +312,18 @@ static int dbs_calc_load(struct cpu_dbs_info_s *this_dbs_info)
                j_dbs_info->prev_cpu_wall = total_wall_nsecs;
                j_dbs_info->prev_cpu_idle = total_idle_nsecs;
 
-               tmp_load = (100 * (tmp_wall_nsecs - tmp_idle_nsecs)) /
-                               tmp_wall_nsecs;
+               /* Convert nsecs to msecs and clamp times to sane values. */
+               do_div(tmp_wall_nsecs, 1000000);
+               tmp_wall_msecs = tmp_wall_nsecs;
+               do_div(tmp_idle_nsecs, 1000000);
+               tmp_idle_msecs = tmp_idle_nsecs;
+               if (tmp_wall_msecs == 0)
+                       tmp_wall_msecs = 1;
+               if (tmp_idle_msecs < tmp_wall_msecs)
+                       tmp_idle_msecs = tmp_wall_msecs;
+
+               tmp_load = (100 * (tmp_wall_msecs - tmp_idle_msecs)) /
+                               tmp_wall_msecs;
                load = max(load, min(100, (int) tmp_load));
        }
        return load;