Skip to content

Commit 07e2572

Browse files
terminusacmel
authored andcommitted
perf bench mem: Defer type munging of size to float
Do type conversion to double at the point of use. Reviewed-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: David Hildenbrand <david@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Mateusz Guzik <mjguzik@gmail.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Raghavendra K T <raghavendra.kt@amd.com> Cc: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20250917152418.4077386-3-ankur.a.arora@oracle.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 79a0194 commit 07e2572

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tools/perf/bench/mem-functions.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ struct bench_mem_info {
139139
bool alloc_src;
140140
};
141141

142-
static void __bench_mem_function(struct bench_mem_info *info, int r_idx, size_t size, double size_total)
142+
static void __bench_mem_function(struct bench_mem_info *info, int r_idx, size_t size, size_t size_total)
143143
{
144144
const struct function *r = &info->functions[r_idx];
145145
double result_bps = 0.0;
@@ -165,18 +165,18 @@ static void __bench_mem_function(struct bench_mem_info *info, int r_idx, size_t
165165
switch (bench_format) {
166166
case BENCH_FORMAT_DEFAULT:
167167
if (use_cycles) {
168-
printf(" %14lf cycles/byte\n", (double)rt.cycles/size_total);
168+
printf(" %14lf cycles/byte\n", (double)rt.cycles/(double)size_total);
169169
} else {
170-
result_bps = size_total/timeval2double(&rt.tv);
170+
result_bps = (double)size_total/timeval2double(&rt.tv);
171171
print_bps(result_bps);
172172
}
173173
break;
174174

175175
case BENCH_FORMAT_SIMPLE:
176176
if (use_cycles) {
177-
printf("%lf\n", (double)rt.cycles/size_total);
177+
printf("%lf\n", (double)rt.cycles/(double)size_total);
178178
} else {
179-
result_bps = size_total/timeval2double(&rt.tv);
179+
result_bps = (double)size_total/timeval2double(&rt.tv);
180180
printf("%lf\n", result_bps);
181181
}
182182
break;
@@ -199,7 +199,7 @@ static int bench_mem_common(int argc, const char **argv, struct bench_mem_info *
199199
{
200200
int i;
201201
size_t size;
202-
double size_total;
202+
size_t size_total;
203203

204204
argc = parse_options(argc, argv, options, info->usage, 0);
205205

@@ -212,7 +212,7 @@ static int bench_mem_common(int argc, const char **argv, struct bench_mem_info *
212212
}
213213

214214
size = (size_t)perf_atoll((char *)size_str);
215-
size_total = (double)size * nr_loops;
215+
size_total = size * nr_loops;
216216

217217
if ((s64)size <= 0) {
218218
fprintf(stderr, "Invalid size:%s\n", size_str);

0 commit comments

Comments
 (0)