Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:yukoff:openSUSE:Leap:42.1:Backports
powerpc-utils
powerpc-utils-fix_integer_to_float_cast.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File powerpc-utils-fix_integer_to_float_cast.patch of Package powerpc-utils
commit c61535c62111d04a886a2b4d7613b7006d5fe209 Author: John Allen <jallen@linux.vnet.ibm.com> Date: Thu Aug 11 16:30:12 2016 -0400 lparstat: Fix bad cast from integer to float Fix a bug where the cpu stats (%user, %sys, %wait, and %idle) do not add up to 100%. The problem was that we were casting the cpu stats and the total cpu time to floats from ints. For large integer values, this would cause the floating point representation to be truncated. This solution avoids the casts and stores the cpu stats as long longs and only casts 'total' to a long double in order to perform floating point division. Additionally, this patch parses the proc stat values as long longs as on systems that have been running for a long time, these values can exceed the maximum 32 bit integer limit. Signed-off-by: John Allen <jallen@linux.vnet.ibm.com> diff --git a/src/lparstat.c b/src/lparstat.c index ebe0d13..bd4ff58 100644 --- a/src/lparstat.c +++ b/src/lparstat.c @@ -264,11 +264,11 @@ int parse_proc_stat() statvals[0] = 0; value = line; for (i = 1; i <= (entries - 1); i++) { - int v; + long long v; value = strchr(value, ' ') + 1; if (i == 1) value++; - v = atoi(value); + v = atoll(value); statvals[i] = v; statvals[0] += v; } @@ -465,13 +465,13 @@ long long get_cpu_time_diff() void get_cpu_stat(struct sysentry *se, char *buf) { - float total, percent; - float old_val, new_val; + float percent; + long long total, old_val, new_val; total = get_cpu_time_diff(); - new_val = atoi(se->value); - old_val = atoi(se->old_value); - percent = (float)((new_val - old_val)/total) * 100; + new_val = atoll(se->value); + old_val = atoll(se->old_value); + percent = ((new_val - old_val)/(long double)total) * 100; sprintf(buf, "%.2f", percent); }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor