static void inline cpufreq_greenmax_calc_load(int j) { struct greenmax_info_s *j_this_greenmax; u64 cur_wall_time, cur_idle_time, cur_iowait_time; unsigned int idle_time, wall_time, iowait_time; unsigned int cur_load; j_this_greenmax = &per_cpu(greenmax_info, j); cur_idle_time = get_cpu_idle_time_greenmax(j, &cur_wall_time); cur_iowait_time = get_cpu_iowait_time(j, &cur_wall_time); wall_time = cur_wall_time - j_this_greenmax->prev_cpu_wall; j_this_greenmax->prev_cpu_wall = cur_wall_time; idle_time = cur_idle_time - j_this_greenmax->prev_cpu_idle; j_this_greenmax->prev_cpu_idle = cur_idle_time; iowait_time = cur_iowait_time - j_this_greenmax->prev_cpu_iowait; j_this_greenmax->prev_cpu_iowait = cur_iowait_time; if (ignore_nice) { u64 cur_nice; unsigned long cur_nice_jiffies; cur_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE] - j_this_greenmax->prev_cpu_nice; cur_nice_jiffies = (unsigned long) cputime64_to_jiffies64(cur_nice); j_this_greenmax->prev_cpu_nice = kcpustat_cpu(j).cpustat[CPUTIME_NICE]; idle_time += jiffies_to_usecs(cur_nice_jiffies); } /* * For the purpose of ondemand, waiting for disk IO is an * indication that you're performance critical, and not that * the system is actually idle. So subtract the iowait time * from the cpu idle time. */ if (io_is_busy && idle_time >= iowait_time) idle_time -= iowait_time; if (unlikely(!wall_time || wall_time < idle_time)) return; cur_load = 100 * (wall_time - idle_time) / wall_time; j_this_greenmax->cur_cpu_load = cur_load; }
static int update_average_load(unsigned int freq, unsigned int cpu) { struct cpufreq_policy cpu_policy; struct cpu_load_data *pcpu = &per_cpu(cpuload, cpu); cputime64_t cur_wall_time, cur_idle_time, cur_iowait_time; unsigned int idle_time, wall_time, iowait_time; unsigned int cur_load, load_at_max_freq; cpufreq_get_policy(&cpu_policy, cpu); /* if max freq is changed by the user this load calculator needs to adjust itself otherwise its going to be all wrong */ if (unlikely(pcpu->policy_max != cpu_policy.max)) pcpu->policy_max = cpu_policy.max; cur_idle_time = get_cpu_idle_time(cpu, &cur_wall_time); cur_iowait_time = get_cpu_iowait_time(cpu, &cur_wall_time); wall_time = (unsigned int) (cur_wall_time - pcpu->prev_cpu_wall); pcpu->prev_cpu_wall = cur_wall_time; idle_time = (unsigned int) (cur_idle_time - pcpu->prev_cpu_idle); pcpu->prev_cpu_idle = cur_idle_time; iowait_time = (unsigned int) (cur_iowait_time - pcpu->prev_cpu_iowait); pcpu->prev_cpu_iowait = cur_iowait_time; if (idle_time >= iowait_time) idle_time -= iowait_time; if (unlikely(!wall_time || wall_time < idle_time)) return 0; cur_load = 100 * (wall_time - idle_time) / wall_time; /* Calculate the scaled load across CPU */ load_at_max_freq = (cur_load * freq) / pcpu->policy_max; /* This is the first sample in this window*/ pcpu->avg_load_maxfreq = pcpu->prev_avg_load_maxfreq + load_at_max_freq; pcpu->avg_load_maxfreq /= 2; pcpu->window_size = wall_time; return 0; }
static unsigned int calc_cur_load(unsigned int cpu) { struct cpu_load_data *pcpu = &per_cpu(cpuload, cpu); u64 cur_wall_time, cur_idle_time, cur_iowait_time; unsigned int idle_time, wall_time, iowait_time; cur_idle_time = get_cpu_idle_time(cpu, &cur_wall_time); cur_iowait_time = get_cpu_iowait_time(cpu, &cur_wall_time); wall_time = (unsigned int) (cur_wall_time - pcpu->prev_cpu_wall); pcpu->prev_cpu_wall = cur_wall_time; idle_time = (unsigned int) (cur_idle_time - pcpu->prev_cpu_idle); pcpu->prev_cpu_idle = cur_idle_time; iowait_time = (unsigned int) (cur_iowait_time - pcpu->prev_cpu_iowait); pcpu->prev_cpu_iowait = cur_iowait_time; if (ignore_nice) { u64 cur_nice; unsigned long cur_nice_jiffies; cur_nice = kcpustat_cpu(cpu).cpustat[CPUTIME_NICE] - pcpu->prev_cpu_nice; cur_nice_jiffies = (unsigned long) cputime64_to_jiffies64(cur_nice); pcpu->prev_cpu_nice = kcpustat_cpu(cpu).cpustat[CPUTIME_NICE]; idle_time += jiffies_to_usecs(cur_nice_jiffies); } if (io_is_busy && idle_time >= iowait_time) idle_time -= iowait_time; if (unlikely(!wall_time || wall_time < idle_time)) return 0; return 100 * (wall_time - idle_time) / wall_time; }