Skip to contentSkip to conversation

perf stat: Fix duration_time value for higher intervals

PATCH Applied Jiri Olsa 3 participants 3 messages May 18, 2020 perf events

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/1 perf stat: Fix duration_time value for higher intervals

Joakim reported wrong duration_time value for interval bigger than 4000 [1].

The problem is in the interval value we pass to update_stats function, which is typed as 'unsigned int' and overflows when we get over 2^32 (happens between intervals 4000 and 5000).

Retyping the passed value to unsigned long long.

[1] https://www.spinics.net/lists/linux-perf-users/msg11777.html

---
 tools/perf/builtin-stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-stat.c +1 -1
index e0c1ad23c768..4deb2d46a343 100644
@@ -367,7 +367,7 @@ static void process_interval(void)
 	}
 
 	init_stats(&walltime_nsecs_stats);
-	update_stats(&walltime_nsecs_stats, stat_config.interval * 1000000);
+	update_stats(&walltime_nsecs_stats, stat_config.interval * 1000000ULL);
 	print_counters(&rs, 0, NULL);
 }
 
Signature · 1 line
2.25.4
#1 lore raw

Em Mon, May 18, 2020 at 03:14:45PM +0200, Jiri Olsa escreveu:

Quoted 8 lines

Joakim reported wrong duration_time value for interval bigger than 4000 [1].

The problem is in the interval value we pass to update_stats function, which is typed as 'unsigned int' and overflows when we get over 2^32 (happens between intervals 4000 and 5000).

Retyping the passed value to unsigned long long.

Thanks, applied and added this:

Fixes b90f1333ef08 ("perf stat: Update walltime_nsecs_stats in interval mode")

Ok?

- Arnaldo

Quoted 24 lines

[1] https://www.spinics.net/lists/linux-perf-users/msg11777.html

---
 tools/perf/builtin-stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-stat.c +1 -1
index e0c1ad23c768..4deb2d46a343 100644
@@ -367,7 +367,7 @@ static void process_interval(void)
 	}
 
 	init_stats(&walltime_nsecs_stats);
-	update_stats(&walltime_nsecs_stats, stat_config.interval * 1000000);
+	update_stats(&walltime_nsecs_stats, stat_config.interval * 1000000ULL);
 	print_counters(&rs, 0, NULL);
 }
 
Signature · 1 line
2.25.4
Signature · 1 line
- Arnaldo
#2 lore raw
Quoted 8 lines · Arnaldo Carvalho de Melo

Em Mon, May 18, 2020 at 03:14:45PM +0200, Jiri Olsa escreveu:

Quoted 7 lines

Joakim reported wrong duration_time value for interval bigger than 4000 [1].

The problem is in the interval value we pass to update_stats function, which is typed as 'unsigned int' and overflows when we get over 2^32 (happens between intervals 4000 and 5000).

Quoted 7 lines
Quoted 1 line

Retyping the passed value to unsigned long long.

Thanks, applied and added this:

Fixes b90f1333ef08 ("perf stat: Update walltime_nsecs_stats in interval mode")

Ok?

yep, thanks
jirka

Quoted 32 lines

- Arnaldo

Quoted 24 lines

[1] https://www.spinics.net/lists/linux-perf-users/msg11777.html

---
 tools/perf/builtin-stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-stat.c +1 -1
index e0c1ad23c768..4deb2d46a343 100644
@@ -367,7 +367,7 @@ static void process_interval(void)
 	}
 
 	init_stats(&walltime_nsecs_stats);
-	update_stats(&walltime_nsecs_stats, stat_config.interval * 1000000);
+	update_stats(&walltime_nsecs_stats, stat_config.interval * 1000000ULL);
 	print_counters(&rs, 0, NULL);
 }
 
Signature · 1 line
2.25.4
Signature · 1 line
- Arnaldo