From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1D8EC83F22 for ; Tue, 15 Jul 2025 20:06:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F10646B009E; Tue, 15 Jul 2025 16:06:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE79B6B009F; Tue, 15 Jul 2025 16:06:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E24D86B00A0; Tue, 15 Jul 2025 16:06:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D26486B009E for ; Tue, 15 Jul 2025 16:06:16 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9B2BE1601B0 for ; Tue, 15 Jul 2025 20:06:16 +0000 (UTC) X-FDA: 83667580752.08.088D3E9 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf02.hostedemail.com (Postfix) with ESMTP id 4145B8000C for ; Tue, 15 Jul 2025 20:06:15 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UNpu++l9; spf=pass (imf02.hostedemail.com: domain of namhyung@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=namhyung@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752609975; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9MUysgxBTlOk/2qKZEqtRGEBLe39o2485Fwfy45BhG0=; b=Oxv9WGtzJABaOEVBcNO59DuPEjCbr13ywdnsp1HDuRDR0opQSUPnpoa1pXzPPM8StNODpz IcNXdNgtxak0nBksr19VluKOgySNJTgd2fCZmeSQSq2RF8cJLAlHUX6LM4wvMy1jOJDGpm LNxZBxa80cOz409CpajM3eP73T3sGeg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752609975; a=rsa-sha256; cv=none; b=qQxD6UOrlaAdzjPGBxT+z/6GY1urHaDDoC88hQhC1SY7IOd3N6I1LWnjAjGtzYQ50tzIfH R0qUZnqVVq6OWBaVwCZK6kIwTWACyNgga9bUJnySGowGGDzujKgMpm1dxx2B8dkEYkcUyZ nKLeRsHZ6pc9aeLA46O+4cqJWdc+rPs= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UNpu++l9; spf=pass (imf02.hostedemail.com: domain of namhyung@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=namhyung@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 931B7A5726A; Tue, 15 Jul 2025 20:06:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73D98C4CEE3; Tue, 15 Jul 2025 20:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752609974; bh=xozF1Gv6XMBXHrdxPUdk15zH0lRQ4LG8HUiGBxCudEA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=UNpu++l9xEkiFcJUudJvlR6mpvFI4vrQwy4mQM/t9Ai+SDkko1kzXluA9kLKMvHyZ 8LuHGl1pQmMFYI4Ae5hQaYG7acmbntsBoCZuxq0Xg9Mb9dM47FRgZjZSzKv/InJHFX 3aEmxlgee+mM4ZFLYNDuAxk25pl6qtJiAQAmMqjqyggOYRobCsAGeoD5cBgF04MAab dV8M77wVumcmmD9nX4NlmB9yMs4erZoVWMY7/1xaTzGNuMKzG8zAq72mT4bqNPHusg pzKR4uKnRDqwJaYCFfbMx8PGZU9CV5ecXt0R0E1rcPeoaIhbxQqYcL+XDWFdcpuP7R Hsab5jji3Rurg== Date: Tue, 15 Jul 2025 13:06:12 -0700 From: Namhyung Kim To: Ankur Arora Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, akpm@linux-foundation.org, david@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, mingo@redhat.com, mjguzik@gmail.com, luto@kernel.org, peterz@infradead.org, acme@kernel.org, tglx@linutronix.de, willy@infradead.org, raghavendra.kt@amd.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com Subject: Re: [PATCH v5 03/14] perf bench mem: Move mem op parameters into a structure Message-ID: References: <20250710005926.1159009-1-ankur.a.arora@oracle.com> <20250710005926.1159009-4-ankur.a.arora@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20250710005926.1159009-4-ankur.a.arora@oracle.com> X-Rspamd-Queue-Id: 4145B8000C X-Stat-Signature: 1d3remko5kybh45af3gtme4tjex3c7yw X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1752609975-694806 X-HE-Meta: U2FsdGVkX1/QUxrFgk0BbAL1yDhGdNDs9yy+ENLOVQGEH0BsGyNtm05VXnGNCQUYi/ZB+ELEX+8i63V06yajIOwpP9MEowuYtzU/e2Bh844+MqsIDVI378OJbkocKiO+hrlO64sq8CzVcP/X1cLLn12CTmfk3sNtC1uHjDrzHMrmTJ/YOJHTS6K1JztpnwcAojZXM0Nue7RDs350bcjftFLDa8mUuhB/Nc93Cwfy4wNyOZZHMnqI0RuinPOcn6mCcYhPOtdyaMmEw5UmlEmf2Tchb7Esu5rzMjJatKLpnCoNyhELeYXrzwsFhKUQ62CTg/IlbXQpQfc1MdVoIXCJVNQUA3jt7py/k0tdlwvfvD3+4O5NH5tm/Jeh3+LQ7PopGdoD75utcjNaGIEdCZdje48YJSIPpEjCfu9aX1NzwztlZz5SfjHOpKzbLKold5qdjzyezMm/V75gDEyY7ya+w6RG+4zxevKKsrksfh4nbmP0VSC7MQm9QsPIx4mokWZJScK+eAuSDaYNteGbv0ixIk+R6ovMWdtn5WvRy9+H4th8Rw9SSaMnBsLQYzOyAjvmE8P3T8btqt7YAWbgxwO9G+GE03aBBgP/OD2j3uRtJBsN14BHARPBACn9lGmqWT/ca/NpVs0A4ykj2kp1Kx2VEmEqdvYZPTQfFvSQTMrBMsSG5T67C4p4E0XTZhnr7zX8wK2N2KQaNI4nm50a+3YVpF+Cy6So01XKr7I+gF4VvSwr+n9tKwTPRgb9VEZ9HY1OmaC55k9/488J4mo9aT2Qmo6wEKF64Rf5WbsAwgmHsC+AbwnQ76autD0TWuAx0iJdsSk3bvDiUSPUoxY3xJfgHtBxZviM9nL8IA/cmIOBLSmZoLAwCXe8bnynSrDzbL3BowSvGRZ5ED8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Jul 09, 2025 at 05:59:15PM -0700, Ankur Arora wrote: > Move benchmark function parameters in struct bench_params. > > Signed-off-by: Ankur Arora Reviewed-by: Namhyung Kim Thanks, Namhyung > --- > tools/perf/bench/mem-functions.c | 63 +++++++++++++++++--------------- > 1 file changed, 34 insertions(+), 29 deletions(-) > > diff --git a/tools/perf/bench/mem-functions.c b/tools/perf/bench/mem-functions.c > index b8f020379197..fb17d36a6f6c 100644 > --- a/tools/perf/bench/mem-functions.c > +++ b/tools/perf/bench/mem-functions.c > @@ -30,7 +30,7 @@ > > static const char *size_str = "1MB"; > static const char *function_str = "all"; > -static int nr_loops = 1; > +static unsigned int nr_loops = 1; > static bool use_cycles; > static int cycles_fd; > > @@ -42,7 +42,7 @@ static const struct option options[] = { > OPT_STRING('f', "function", &function_str, "all", > "Specify the function to run, \"all\" runs all available functions, \"help\" lists them"), > > - OPT_INTEGER('l', "nr_loops", &nr_loops, > + OPT_UINTEGER('l', "nr_loops", &nr_loops, > "Specify the number of loops to run. (default: 1)"), > > OPT_BOOLEAN('c', "cycles", &use_cycles, > @@ -56,6 +56,12 @@ union bench_clock { > struct timeval tv; > }; > > +struct bench_params { > + size_t size; > + size_t size_total; > + unsigned int nr_loops; > +}; > + > typedef void *(*memcpy_t)(void *, const void *, size_t); > typedef void *(*memset_t)(void *, int, size_t); > > @@ -134,17 +140,19 @@ static double timeval2double(struct timeval *ts) > > struct bench_mem_info { > const struct function *functions; > - union bench_clock (*do_op)(const struct function *r, size_t size, void *src, void *dst); > + union bench_clock (*do_op)(const struct function *r, struct bench_params *p, > + void *src, void *dst); > const char *const *usage; > bool alloc_src; > }; > > -static void __bench_mem_function(struct bench_mem_info *info, int r_idx, size_t size, size_t size_total) > +static void __bench_mem_function(struct bench_mem_info *info, struct bench_params *p, > + int r_idx) > { > const struct function *r = &info->functions[r_idx]; > double result_bps = 0.0; > union bench_clock rt = { 0 }; > - void *src = NULL, *dst = zalloc(size); > + void *src = NULL, *dst = zalloc(p->size); > > printf("# function '%s' (%s)\n", r->name, r->desc); > > @@ -152,7 +160,7 @@ static void __bench_mem_function(struct bench_mem_info *info, int r_idx, size_t > goto out_alloc_failed; > > if (info->alloc_src) { > - src = zalloc(size); > + src = zalloc(p->size); > if (src == NULL) > goto out_alloc_failed; > } > @@ -160,23 +168,23 @@ static void __bench_mem_function(struct bench_mem_info *info, int r_idx, size_t > if (bench_format == BENCH_FORMAT_DEFAULT) > printf("# Copying %s bytes ...\n\n", size_str); > > - rt = info->do_op(r, size, src, dst); > + rt = info->do_op(r, p, src, dst); > > switch (bench_format) { > case BENCH_FORMAT_DEFAULT: > if (use_cycles) { > - printf(" %14lf cycles/byte\n", (double)rt.cycles/(double)size_total); > + printf(" %14lf cycles/byte\n", (double)rt.cycles/(double)p->size_total); > } else { > - result_bps = (double)size_total/timeval2double(&rt.tv); > + result_bps = (double)p->size_total/timeval2double(&rt.tv); > print_bps(result_bps); > } > break; > > case BENCH_FORMAT_SIMPLE: > if (use_cycles) { > - printf("%lf\n", (double)rt.cycles/(double)size_total); > + printf("%lf\n", (double)rt.cycles/(double)p->size_total); > } else { > - result_bps = (double)size_total/timeval2double(&rt.tv); > + result_bps = (double)p->size_total/timeval2double(&rt.tv); > printf("%lf\n", result_bps); > } > break; > @@ -198,8 +206,7 @@ static void __bench_mem_function(struct bench_mem_info *info, int r_idx, size_t > static int bench_mem_common(int argc, const char **argv, struct bench_mem_info *info) > { > int i; > - size_t size; > - size_t size_total; > + struct bench_params p = { 0 }; > > argc = parse_options(argc, argv, options, info->usage, 0); > > @@ -211,17 +218,17 @@ static int bench_mem_common(int argc, const char **argv, struct bench_mem_info * > } > } > > - size = (size_t)perf_atoll((char *)size_str); > - size_total = (size_t)size * nr_loops; > - > - if ((s64)size <= 0) { > + p.nr_loops = nr_loops; > + p.size = (size_t)perf_atoll((char *)size_str); > + if ((s64)p.size <= 0) { > fprintf(stderr, "Invalid size:%s\n", size_str); > return 1; > } > + p.size_total = (size_t)p.size * p.nr_loops; > > if (!strncmp(function_str, "all", 3)) { > for (i = 0; info->functions[i].name; i++) > - __bench_mem_function(info, i, size, size_total); > + __bench_mem_function(info, &p, i); > return 0; > } > > @@ -240,7 +247,7 @@ static int bench_mem_common(int argc, const char **argv, struct bench_mem_info * > return 1; > } > > - __bench_mem_function(info, i, size, size_total); > + __bench_mem_function(info, &p, i); > > return 0; > } > @@ -257,18 +264,17 @@ static void memcpy_prefault(memcpy_t fn, size_t size, void *src, void *dst) > fn(dst, src, size); > } > > -static union bench_clock do_memcpy(const struct function *r, size_t size, > +static union bench_clock do_memcpy(const struct function *r, struct bench_params *p, > void *src, void *dst) > { > union bench_clock start, end; > memcpy_t fn = r->fn.memcpy; > - int i; > > - memcpy_prefault(fn, size, src, dst); > + memcpy_prefault(fn, p->size, src, dst); > > clock_get(&start); > - for (i = 0; i < nr_loops; ++i) > - fn(dst, src, size); > + for (unsigned int i = 0; i < p->nr_loops; ++i) > + fn(dst, src, p->size); > clock_get(&end); > > return clock_diff(&start, &end); > @@ -305,22 +311,21 @@ int bench_mem_memcpy(int argc, const char **argv) > return bench_mem_common(argc, argv, &info); > } > > -static union bench_clock do_memset(const struct function *r, size_t size, > +static union bench_clock do_memset(const struct function *r, struct bench_params *p, > void *src __maybe_unused, void *dst) > { > union bench_clock start, end; > memset_t fn = r->fn.memset; > - int i; > > /* > * We prefault the freshly allocated memory range here, > * to not measure page fault overhead: > */ > - fn(dst, -1, size); > + fn(dst, -1, p->size); > > clock_get(&start); > - for (i = 0; i < nr_loops; ++i) > - fn(dst, i, size); > + for (unsigned int i = 0; i < p->nr_loops; ++i) > + fn(dst, i, p->size); > clock_get(&end); > > return clock_diff(&start, &end); > -- > 2.43.5 >