From bee8d36060fa6c5a6887c263ff6c1bc07f639794 Mon Sep 17 00:00:00 2001 From: Sasha Goldshtein Date: Thu, 30 Jun 2016 10:46:27 -0700 Subject: [PATCH] cpudist: Protect against potentially negative time deltas It seems from experimentation that the calculated timestamps between on- and off-CPU switch events can produce incorrect results, with a later event having a smaller timestamp. Discard events when the resulting delta time would be negative. --- tools/cpudist.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/cpudist.py b/tools/cpudist.py index 6a0e04b..40ccfa0 100755 --- a/tools/cpudist.py +++ b/tools/cpudist.py @@ -82,6 +82,11 @@ static inline void update_hist(u32 tgid, u32 pid, u64 ts) if (tsp == 0) return; + if (ts < *tsp) { + // Probably a clock issue where the recorded on-CPU event had a + // timestamp later than the recorded off-CPU event, or vice versa. + return; + } u64 delta = ts - *tsp; FACTOR STORE -- 2.7.4