Skip to content

Commit

Permalink
[CPUFREQ] ondemand: add a check to avoid negative load calculation
Browse files Browse the repository at this point in the history
Due to rounding and inexact jiffy accounting, idle_ticks can sometimes
be higher than total_ticks. Make sure those cases are handled as
zero load case.

Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Signed-off-by: Dave Jones <davej@redhat.com>
  • Loading branch information
Venki Pallipadi authored and Dave Jones committed Jun 21, 2007
1 parent c7f652e commit 0af99b1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/cpufreq/cpufreq_ondemand.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ static struct attribute_group dbs_attr_group = {
static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info)
{
unsigned int idle_ticks, total_ticks;
unsigned int load;
unsigned int load = 0;
cputime64_t cur_jiffies;

struct cpufreq_policy *policy;
Expand Down Expand Up @@ -370,7 +370,8 @@ static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info)
if (tmp_idle_ticks < idle_ticks)
idle_ticks = tmp_idle_ticks;
}
load = (100 * (total_ticks - idle_ticks)) / total_ticks;
if (likely(total_ticks > idle_ticks))
load = (100 * (total_ticks - idle_ticks)) / total_ticks;

/* Check for frequency increase */
if (load > dbs_tuners_ins.up_threshold) {
Expand Down

0 comments on commit 0af99b1

Please sign in to comment.