Skip to content

Commit

Permalink
load statistics: Fix a bunch of integer overflow bugs
Browse files Browse the repository at this point in the history
Most of the summed up load statistics were skewed by a factor of 10, due
to a series of integer multiplications which was overflowing the 32-bit
result holder.

load, load1m, load10m before this patch (16 processes, 3 fully loaded):
12 99 9
12 99 9
12 101 10
13 103 10
13 104 10
12 106 10

... and after:

12 9 0
11 10 1
12 10 1
13 10 1

Fixes #1650

(cherry picked from commit 7f14b6a)
(cherry picked from commit 319b1ba)
  • Loading branch information
liviuchircu committed May 31, 2019
1 parent 96199dd commit 6009742
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pt_load.c
Expand Up @@ -274,7 +274,7 @@ unsigned int pt_get_1m_load(int _)
summed_procs++;
}

return (used*100/(LT_WINDOW_TIME*summed_procs*LT_1m_RATIO));
return (used*100/((long long)LT_WINDOW_TIME*summed_procs*LT_1m_RATIO));
}


Expand All @@ -295,7 +295,7 @@ unsigned int pt_get_10m_load(int _)
summed_procs++;
}

return (used*100/(LT_WINDOW_TIME*summed_procs));
return (used*100/((long long)LT_WINDOW_TIME*summed_procs));
}


Expand All @@ -316,7 +316,7 @@ unsigned int pt_get_rt_loadall(int _)
summed_procs++;
}

return (used*100/(ST_WINDOW_TIME*summed_procs));
return (used*100/((long long)ST_WINDOW_TIME*summed_procs));
}


Expand All @@ -337,7 +337,7 @@ unsigned int pt_get_1m_loadall(int _)
summed_procs++;
}

return (used*100/(LT_WINDOW_TIME*summed_procs*LT_1m_RATIO));
return (used*100/((long long)LT_WINDOW_TIME*summed_procs*LT_1m_RATIO));
}


Expand All @@ -358,7 +358,7 @@ unsigned int pt_get_10m_loadall(int _)
summed_procs++;
}

return (used*100/(LT_WINDOW_TIME*summed_procs));
return (used*100/((long long)LT_WINDOW_TIME*summed_procs));
}


Expand Down

0 comments on commit 6009742

Please sign in to comment.