Skip to content

Commit

Permalink
cpuidle: menu: Use shifts when calculating averages where possible
Browse files Browse the repository at this point in the history
We use do_div even though the divisor will usually be a power-of-two
unless there are unusual outliers. Use shifts where possible

Signed-off-by: Mel Gorman <mgorman@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Mel Gorman authored and Rafael J. Wysocki committed Aug 6, 2014
1 parent dd38c9d commit ae77930
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions drivers/cpuidle/governors/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
* The default values do not overflow.
*/
#define BUCKETS 12
#define INTERVALS 8
#define INTERVAL_SHIFT 3
#define INTERVALS (1UL << INTERVAL_SHIFT)
#define RESOLUTION 1024
#define DECAY 8
#define MAX_INTERESTING 50000
Expand Down Expand Up @@ -227,7 +228,10 @@ static void get_typical_interval(struct menu_device *data)
max = value;
}
}
do_div(avg, divisor);
if (divisor == INTERVALS)
avg >>= INTERVAL_SHIFT;
else
do_div(avg, divisor);

/* Then try to determine standard deviation */
stddev = 0;
Expand All @@ -238,7 +242,11 @@ static void get_typical_interval(struct menu_device *data)
stddev += diff * diff;
}
}
do_div(stddev, divisor);
if (divisor == INTERVALS)
stddev >>= INTERVAL_SHIFT;
else
do_div(stddev, divisor);

/*
* The typical interval is obtained when standard deviation is small
* or standard deviation is small compared to the average interval.
Expand Down

0 comments on commit ae77930

Please sign in to comment.