From nobody Sun Feb 8 19:40:04 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12FF9C001DD for ; Thu, 13 Jul 2023 13:22:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235260AbjGMNWl (ORCPT ); Thu, 13 Jul 2023 09:22:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234601AbjGMNVx (ORCPT ); Thu, 13 Jul 2023 09:21:53 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1715D3A9E; Thu, 13 Jul 2023 06:21:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689254473; x=1720790473; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Vd7tzwpfv1b8Vdm5xf009cWmFKxKtbsLKfgak3lNYlg=; b=lu4H+LI3fFyCfJzuuLZeE7LYvo8hDBOxV7xl1I1VyK4PFyTk0f1BTuNt ULOgrINoms2KH9g6jKTkaybwGmdWMb+rLZwtdQIWiXP6J9fdlAduMAHOU qhHTVVnvyQEQGZgW8sm+obFlx7MXtxy80pekV593P2XQxXkM4GRm+Eij6 +jK1W029R7f9YXTl1Ub5i0/D4SNGMKLmUYGG+JHH1bF84ZNIvgqUGmB9T 95nfvYirwW8lQU82Nd4gQPXdQUDKrTHFm5tMoWAGh/8hbRW6quimyuFqG /NjZX8/soyIdZ8PN4G2LaT63Xv2B2LFfeiLYWZVL/V3anx2Jj6YF+0Tqf Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="345496912" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="345496912" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:21:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="968615921" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="968615921" Received: from ijarvine-mobl2.ger.corp.intel.com ([10.251.222.39]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:21:01 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , Fenghua Yu , linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v4 14/19] selftests/resctrl: Improve parameter consistency in fill_buf Date: Thu, 13 Jul 2023 16:19:27 +0300 Message-Id: <20230713131932.133258-15-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> References: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org fill_buf's arguments can be improved in multiple ways: - Multiple functions in fill_buf have start_ptr as one of their argument which is a bit long and the extra "start" is pretty obvious when it comes to pointers. - Some of the functions take end_ptr and others size_t to indicate the end of the buffer. - Some arguments meaning buffer size are called just 's' - mem_flush() takes void * but immediately converts it to char * Cleanup the parameters to make things simpler and more consistent: - Rename start_ptr to simply buf as it's shorter. - Replace end_ptr and s parameters with buf_size and only calculate end_ptr in the functions that truly use it. - Make mem_flush() parameters to follow the same convention as the other functions in fill_buf. - convert mem_flush() char * to unsigned char *. While at it, fix also a typo in a comment. Signed-off-by: Ilpo J=C3=A4rvinen --- tools/testing/selftests/resctrl/fill_buf.c | 49 +++++++++++----------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/sel= ftests/resctrl/fill_buf.c index a5ec9c82a960..5f16c4f5dfbf 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -38,32 +38,32 @@ static void cl_flush(void *p) #endif } =20 -static void mem_flush(void *p, size_t s) +static void mem_flush(unsigned char *buf, size_t buf_size) { - char *cp =3D (char *)p; + unsigned char *cp =3D buf; size_t i =3D 0; =20 - s =3D s / CL_SIZE; /* mem size in cache llines */ + buf_size =3D buf_size / CL_SIZE; /* mem size in cache lines */ =20 - for (i =3D 0; i < s; i++) + for (i =3D 0; i < buf_size; i++) cl_flush(&cp[i * CL_SIZE]); =20 sb(); } =20 -static void *malloc_and_init_memory(size_t s) +static void *malloc_and_init_memory(size_t buf_size) { void *p =3D NULL; uint64_t *p64; size_t s64; int ret; =20 - ret =3D posix_memalign(&p, PAGE_SIZE, s); + ret =3D posix_memalign(&p, PAGE_SIZE, buf_size); if (ret < 0) return NULL; =20 p64 =3D (uint64_t *)p; - s64 =3D s / sizeof(uint64_t); + s64 =3D buf_size / sizeof(uint64_t); =20 while (s64 > 0) { *p64 =3D (uint64_t)rand(); @@ -74,12 +74,13 @@ static void *malloc_and_init_memory(size_t s) return p; } =20 -static int fill_one_span_read(unsigned char *start_ptr, unsigned char *end= _ptr) +static int fill_one_span_read(unsigned char *buf, size_t buf_size) { + unsigned char *end_ptr =3D buf + buf_size; unsigned char sum, *p; =20 sum =3D 0; - p =3D start_ptr; + p =3D buf; while (p < end_ptr) { sum +=3D *p; p +=3D (CL_SIZE / 2); @@ -88,26 +89,26 @@ static int fill_one_span_read(unsigned char *start_ptr,= unsigned char *end_ptr) return sum; } =20 -static -void fill_one_span_write(unsigned char *start_ptr, unsigned char *end_ptr) +static void fill_one_span_write(unsigned char *buf, size_t buf_size) { + unsigned char *end_ptr =3D buf + buf_size; unsigned char *p; =20 - p =3D start_ptr; + p =3D buf; while (p < end_ptr) { *p =3D '1'; p +=3D (CL_SIZE / 2); } } =20 -static int fill_cache_read(unsigned char *start_ptr, unsigned char *end_pt= r, +static int fill_cache_read(unsigned char *buf, size_t buf_size, char *resctrl_val) { int ret =3D 0; FILE *fp; =20 while (1) { - ret =3D fill_one_span_read(start_ptr, end_ptr); + ret =3D fill_one_span_read(buf, buf_size); if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR))) break; } @@ -124,11 +125,11 @@ static int fill_cache_read(unsigned char *start_ptr, = unsigned char *end_ptr, return 0; } =20 -static int fill_cache_write(unsigned char *start_ptr, unsigned char *end_p= tr, +static int fill_cache_write(unsigned char *buf, size_t buf_size, char *resctrl_val) { while (1) { - fill_one_span_write(start_ptr, end_ptr); + fill_one_span_write(buf, buf_size); if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR))) break; } @@ -138,25 +139,23 @@ static int fill_cache_write(unsigned char *start_ptr,= unsigned char *end_ptr, =20 static int fill_cache(size_t buf_size, int memflush, int op, char *resctrl= _val) { - unsigned char *start_ptr, *end_ptr; + unsigned char *buf; int ret; =20 - start_ptr =3D malloc_and_init_memory(buf_size); - if (!start_ptr) + buf =3D malloc_and_init_memory(buf_size); + if (!buf) return -1; =20 - end_ptr =3D start_ptr + buf_size; - /* Flush the memory before using to avoid "cache hot pages" effect */ if (memflush) - mem_flush(start_ptr, buf_size); + mem_flush(buf, buf_size); =20 if (op =3D=3D 0) - ret =3D fill_cache_read(start_ptr, end_ptr, resctrl_val); + ret =3D fill_cache_read(buf, buf_size, resctrl_val); else - ret =3D fill_cache_write(start_ptr, end_ptr, resctrl_val); + ret =3D fill_cache_write(buf, buf_size, resctrl_val); =20 - free(start_ptr); + free(buf); =20 if (ret) { printf("\n Error in fill cache read/write...\n"); --=20 2.30.2