Skip to content

Commit 8b78cf6

Browse files
yi-y-yanglenb
authored andcommitted
cpuidle: fix cpuidle time and usage overflow
cpuidle C-state sysfs node time and usage are very easy to overflow because they are all of unsigned int type, time will overflow within about two hours, usage will take longer time to overflow, but they are increasing for ever. This patch will convert them to unsigned long long. Signed-off-by: Yi Yang <yi.y.yang@intel.com> Acked-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent 996520c commit 8b78cf6

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎drivers/cpuidle/cpuidle.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static void cpuidle_idle_call(void)
6767
/* enter the state and update stats */
6868
dev->last_residency = target_state->enter(dev, target_state);
6969
dev->last_state = target_state;
70-
target_state->time += dev->last_residency;
70+
target_state->time += (unsigned long long)dev->last_residency;
7171
target_state->usage++;
7272

7373
/* give the governor an opportunity to reflect on the outcome */

‎drivers/cpuidle/sysfs.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \
218218
return sprintf(buf, "%u\n", state->_name);\
219219
}
220220

221+
#define define_show_state_ull_function(_name) \
222+
static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \
223+
{ \
224+
return sprintf(buf, "%llu\n", state->_name);\
225+
}
226+
221227
#define define_show_state_str_function(_name) \
222228
static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \
223229
{ \
@@ -228,8 +234,8 @@ static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \
228234

229235
define_show_state_function(exit_latency)
230236
define_show_state_function(power_usage)
231-
define_show_state_function(usage)
232-
define_show_state_function(time)
237+
define_show_state_ull_function(usage)
238+
define_show_state_ull_function(time)
233239
define_show_state_str_function(name)
234240
define_show_state_str_function(desc)
235241

‎include/linux/cpuidle.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ struct cpuidle_state {
3838
unsigned int power_usage; /* in mW */
3939
unsigned int target_residency; /* in US */
4040

41-
unsigned int usage;
42-
unsigned int time; /* in US */
41+
unsigned long long usage;
42+
unsigned long long time; /* in US */
4343

4444
int (*enter) (struct cpuidle_device *dev,
4545
struct cpuidle_state *state);

0 commit comments

Comments
 (0)