From: Anastasia Lyupa Date: Tue, 17 Dec 2013 08:45:24 +0000 (+0400) Subject: [FIX] negative values in system feature variables X-Git-Tag: Tizen_SDK_2.3~99 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F55%2F13855%2F4;p=platform%2Fcore%2Fsystem%2Fswap-manager.git [FIX] negative values in system feature variables send new value instead of difference if the difference is negative Change-Id: I28d28a1a5c87035dfb09551428a95c32b1f14fce Signed-off-by: Anastasia Lyupa --- diff --git a/daemon/sys_stat.c b/daemon/sys_stat.c index 65a98e9..86be67b 100644 --- a/daemon/sys_stat.c +++ b/daemon/sys_stat.c @@ -88,6 +88,9 @@ #define CAMCORDER_FILE "/usr/etc/mmfw_camcorder.ini" #define CAMERA_COUNT_STR "DeviceCount" +// define for correct difference of system feature vars +#define val_diff(v_new, v_old) ((v_new < v_old) ? v_new : v_new - v_old) + enum PROCESS_DATA { PROCDATA_STAT, @@ -1962,11 +1965,11 @@ static void peek_network_stat_diff(uint32_t *recv, uint32_t *send) get_network_stat(recv, send); tmp = *recv; - *recv = tmp - irecv_old; + *recv = val_diff(tmp, irecv_old); irecv_old = tmp; tmp = *send; - *send = tmp - isend_old; + *send = val_diff(tmp, isend_old); isend_old = tmp; } @@ -2089,19 +2092,19 @@ static void peek_disk_stat_diff(uint32_t *reads, uint32_t *sec_reads, get_disk_stat(reads, sec_reads, writes, sec_writes); tmp = *reads; - *reads = tmp - reads_old; + *reads = val_diff(tmp, reads_old); reads_old = tmp; tmp = *writes; - *writes = tmp - writes_old; + *writes = val_diff(tmp, writes_old); writes_old = tmp; tmp = *sec_reads; - *sec_reads = tmp - sec_reads_old; + *sec_reads = val_diff(tmp, sec_reads_old); sec_reads_old = tmp; tmp = *sec_writes; - *sec_writes = tmp - sec_writes_old; + *sec_writes = val_diff(tmp, sec_writes_old); sec_writes_old = tmp; } @@ -2175,19 +2178,19 @@ static uint32_t pop_sys_energy_per_device(enum supported_device dev) case DEVICE_CPU: cpu_new = swap_read_int64(cpu_idle/system) + swap_read_int64(cpu_running/system); - cpu_diff = cpu_new - cpu_old; + cpu_diff = val_diff(cpu_new, cpu_old); cpu_old = cpu_new; return (uint32_t)cpu_diff; case DEVICE_FLASH: flash_new = swap_read_int64(flash_read/system) + swap_read_int64(flash_write/system); - flash_diff = flash_new - flash_old; + flash_diff = val_diff(flash_new, flash_old); flash_old = flash_new; return (uint32_t)flash_diff; case DEVICE_LCD: lcd_new = get_system_lcd_energy(); - lcd_diff = lcd_new - lcd_old; + lcd_diff = val_diff(lcd_new, lcd_old); lcd_old = lcd_new; return (uint32_t)lcd_diff; default: @@ -2207,13 +2210,13 @@ static uint32_t pop_app_energy_per_device(enum supported_device dev) switch (dev) { case DEVICE_CPU: cpu_new = swap_read_int64(cpu_running/apps); - cpu_diff = cpu_new - cpu_old; + cpu_diff = val_diff(cpu_new, cpu_old); cpu_old = cpu_new; return (uint32_t)cpu_diff; case DEVICE_FLASH: flash_new = swap_read_int64(flash_read/apps) + swap_read_int64(flash_write/apps); - flash_diff = flash_new - flash_old; + flash_diff = val_diff(flash_new, flash_old); flash_old = flash_new; return (uint32_t)flash_diff; case DEVICE_LCD: