[PATCH v3] cpuidle: Fix last_residency division
Shreyas B Prabhu
shreyas at linux.vnet.ibm.com
Wed Jun 29 18:59:36 AEST 2016
>>
>> +/*
>> + * Used for calculating last_residency in usec. Optimized for case
>> + * where last_residency in nsecs is < INT_MAX/2 by using faster
>> + * approximation. Approximated value has less than 1% error.
>> + */
>> +static inline int convert_nsec_to_usec(u64 nsec)
>> +{
>> + if (likely(nsec < INT_MAX / 2)) {
>
> UINT_MAX ?
I don't think I can use UINT_MAX here since usec += usec >> 5 can
overflow. Also using INT_MAX / 2 instead of INT_MAX since potentially
usec += usec >> 5 can be negative and usec >> 10 will retain the sign bit.
>
>> + int usec = (int)nsec;
>> +
>> + usec += usec >> 5;
>> + usec = usec >> 10;
>> + return usec;
>> + } else {
>> + u64 usec = div_u64(nsec, 1000);
>> +
>> + if (usec > INT_MAX)
>> + usec = INT_MAX;
>> + return (int)usec;
>> + }
>> +}
>
Thanks,
Shreyas
More information about the Linuxppc-dev
mailing list