[PATCH v3] benchtest: malloc tcache hotpath benchtest.
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Thu May 8 15:30:00 GMT 2025
Hi Cupertino,
This looks much better, a few minor comments below. A question, how solid are
the results of repeated runs on your system? If it still varies a bit, you could try
adding bench_start () from bench-util.c/h - this is used to increase frequency if
you didn't disable frequency scaling.
Cheers,
Wilco
+/* Benchmark duration in seconds. */
+#define BENCHMARK_DURATION 10
10 seconds is excessive, I'd reduce this to 2-3 seconds.
+/* Allocate and free blocks in a random order. */
+static size_t
+malloc_benchmark_loop (void)
+{
+ size_t iters = 0;
+ void *elem = NULL;
+
+ while (!timeout)
+ {
+ elem = TEST_FUNC (alloc_size);
+ free (elem);
+ iters++;
+ }
+
+ return iters;
+}
So this measures latency of dependent malloc/free - I think it is more
realistic to measure throughput. It's best to unroll this and either do
4x malloc, 4x free or 4x malloc+free of different block sizes.
+static void usage(const char *name)
+{
+ fprintf (stderr, "%s: <alloc_size>\n", name);
+ exit (1);
+}
Missing line break.
+int
+main (int argc, char **argv)
+{
+ timing_t cur;
+ size_t iters = 0;
+ json_ctx_t json_ctx;
+ double d_total_s, d_total_i;
+ struct sigaction act;
+
+ if (argc == 1)
+ alloc_size = 1024;
+ else if (argc == 2)
+ {
+ long ret;
+
+ errno = 0;
+ ret = strtol(argv[1], NULL, 10);
Space before '('
+
+ if (errno || ret == 0)
+ usage(argv[0]);
And here
+ alloc_size = ret;
+ }
+ else
+ usage(argv[0]);
And here
+ json_init (&json_ctx, 0, stdout);
+
+ json_document_begin (&json_ctx);
+
+ json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
+
+ json_attr_object_begin (&json_ctx, "functions");
+
+ json_attr_object_begin (&json_ctx, TEST_NAME);
+
+ json_attr_object_begin (&json_ctx, "");
+
+ memset (&act, 0, sizeof (act));
+ act.sa_handler = &alarm_handler;
+
+ sigaction (SIGALRM, &act, NULL);
+
+ alarm (BENCHMARK_DURATION);
+
+ cur = do_benchmark (&iters);
+
+ struct rusage usage;
+ getrusage(RUSAGE_SELF, &usage);
Dead code...
+ d_total_s = cur;
+ d_total_i = iters;
+
+ json_attr_double (&json_ctx, "duration", d_total_s);
+ json_attr_double (&json_ctx, "iterations", d_total_i);
+ json_attr_double (&json_ctx, "time_per_iteration", d_total_s / d_total_i);
+
+ json_attr_object_end (&json_ctx);
+
+ json_attr_object_end (&json_ctx);
+
+ json_attr_object_end (&json_ctx);
+
+ json_document_end (&json_ctx);
+
+ return 0;
+}
--
2.39.5
More information about the Libc-alpha
mailing list