From patchwork Mon Nov 20 11:13:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 167059 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp2124445vqn; Mon, 20 Nov 2023 03:14:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHA4QuwiZ656tkb/XI5u/68TtrCKG7/BBcF+LIniB0LE2SFxgQsyYXG56P/6iZ1wWom3N9b X-Received: by 2002:a17:903:32c2:b0:1cc:36fb:22ae with SMTP id i2-20020a17090332c200b001cc36fb22aemr11295257plr.2.1700478892015; Mon, 20 Nov 2023 03:14:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700478892; cv=none; d=google.com; s=arc-20160816; b=DpnHpqkoMZv4z5V7ISW35dmGLCWdKxaSQX7+el0RJQ45IzKx+s6ITvYD68D5gUAUKd mucWOadwEWwctorSUdQGC5v1+weWm2wJFeGo2C0CbVJfGlkM/HfqhsECCcRhNj5Stt2o qbG10Aa8K326MRLDEghXFUwq3k8BHOqYDe/nn8rAOMOz/eCv2eI+mihEIF6irCVXWw25 B+FprozJF/BSUK0WXwqCuxAbdVxv1mQdWyuf6FRVpL2/IDib/lefwnmfnznh2bRll9vL jUnNM/ZsPKC+MkiohJ9e+YsDp6fEF8Sgx2qeLnW7l8YbcO1a1dNSAx39WtHGNB8FXsgb HLWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LPAdpFWIpVbuEb58pgIvAV/UfE6l/IBwNV5g9V7q9K4=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=QfFbWNi5W7bALBHl//hi6ptssMFjhsPO3K8UOAs0hvkhcTZscDIoK1kF/C8VkjNgKI Ah1SsyU9DON9I9EmSLR2uAdHMtH2BsS2Zg5r5XcWhY4TXpvLbl07Y6THuP4X4kOGZkUZ /myz9uioeZOtAY3/VhQ4OK28lJ6cjtiasIod90ye8F57F0DmWFHnWGxlKP7THG+TNxNe 5TPVmaR9Q1QRNFg/6q5qYsNcz28lBqxeMK/CnRom/j7LPqdg6Sq/vzqrtOuuWoTgzULT Kmk4WGKunY4eccolgtMU2MSUPPwXL+eehdXJxjBGjvNXqBEecqSCga0ZaleZoDpRbSsh 30cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Wj32Lvqr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id w6-20020a170902904600b001a6ef92d441si7354141plz.599.2023.11.20.03.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 03:14:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Wj32Lvqr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id DCD7280A5642; Mon, 20 Nov 2023 03:14:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232984AbjKTLO3 (ORCPT + 27 others); Mon, 20 Nov 2023 06:14:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232947AbjKTLOW (ORCPT ); Mon, 20 Nov 2023 06:14:22 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3D4BEB; Mon, 20 Nov 2023 03:14:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700478858; x=1732014858; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oPd148SmWp/iUjrfvXH7JtKA59KsnXMqvq4QV8VYIOI=; b=Wj32LvqrBJItBLlrsMJSCegGaKe/SGOaCDm90XovIF24q5ehmCwJNLzj 3nEQjBksuWRj670FcFDO0SBrWVc2+DkUfmYuOmAIkXI+37GavWnbZOHuS XYw9sR+b9UHUxUBknxO1nAC7aHG/5/+XZb27rQS31EmB2+F2pcFh+YH4t UdGac9C3Zf9UIBAkcmQ5rIbzeGQFz1NJgyF4yXPSaWbZZaAMZfQoVvRNS qeEgDhiaIi7J5zxKolAs84DG27B5bfan6/zF3kx+PFVuZD0ySZFYcnI9R HeeN72W3G4uH/V1jaSV3blIZooSE8HDQWDzCWJjMKV6ClYwhDKhZw9huN Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="458095894" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="458095894" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 03:14:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="716179315" X-IronPort-AV: E=Sophos;i="6.04,213,1695711600"; d="scan'208";a="716179315" Received: from sc9itsct4906.amr.corp.intel.com (HELO localhost) ([10.249.46.107]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 03:14:15 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , =?utf-8?q?Maciej_Wiecz=C3=B3r-R?= =?utf-8?q?etman?= , Fenghua Yu Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v2 03/26] selftests/resctrl: Refactor fill_buf functions Date: Mon, 20 Nov 2023 13:13:17 +0200 Message-Id: <20231120111340.7805-4-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231120111340.7805-1-ilpo.jarvinen@linux.intel.com> References: <20231120111340.7805-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 20 Nov 2023 03:14:44 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783081354640051976 X-GMAIL-MSGID: 1783081354640051976 There are unnecessary nested calls in fill_buf.c: - run_fill_buf() calls fill_cache() - alloc_buffer() calls malloc_and_init_memory() Simplify the code flow and remove those unnecessary call levels by moving the called code inside the calling function. Resolve the difference in run_fill_buf() and fill_cache() parameter name into 'buf_size' which is more descriptive than 'span'. Also, while moving the allocation related code, rename 'p' into 'buf' to be consistent in naming the variables. Signed-off-by: Ilpo Järvinen Reviewed-by: Reinette Chatre --- tools/testing/selftests/resctrl/fill_buf.c | 54 +++++++--------------- tools/testing/selftests/resctrl/resctrl.h | 2 +- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index 6f32f44128e1..b9303a9d819b 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -51,29 +51,6 @@ static void mem_flush(unsigned char *buf, size_t buf_size) sb(); } -static void *malloc_and_init_memory(size_t buf_size) -{ - void *p = NULL; - uint64_t *p64; - size_t s64; - int ret; - - ret = posix_memalign(&p, PAGE_SIZE, buf_size); - if (ret < 0) - return NULL; - - p64 = (uint64_t *)p; - s64 = buf_size / sizeof(uint64_t); - - while (s64 > 0) { - *p64 = (uint64_t)rand(); - p64 += (CL_SIZE / sizeof(uint64_t)); - s64 -= (CL_SIZE / sizeof(uint64_t)); - } - - return p; -} - static int fill_one_span_read(unsigned char *buf, size_t buf_size) { unsigned char *end_ptr = buf + buf_size; @@ -137,12 +114,25 @@ static int fill_cache_write(unsigned char *buf, size_t buf_size, bool once) static unsigned char *alloc_buffer(size_t buf_size, int memflush) { - unsigned char *buf; + void *buf = NULL; + uint64_t *p64; + size_t s64; + int ret; - buf = malloc_and_init_memory(buf_size); - if (!buf) + ret = posix_memalign(&buf, PAGE_SIZE, buf_size); + if (ret < 0) return NULL; + /* Initialize the buffer */ + p64 = buf; + s64 = buf_size / sizeof(uint64_t); + + while (s64 > 0) { + *p64 = (uint64_t)rand(); + p64 += (CL_SIZE / sizeof(uint64_t)); + s64 -= (CL_SIZE / sizeof(uint64_t)); + } + /* Flush the memory before using to avoid "cache hot pages" effect */ if (memflush) mem_flush(buf, buf_size); @@ -150,7 +140,7 @@ static unsigned char *alloc_buffer(size_t buf_size, int memflush) return buf; } -static int fill_cache(size_t buf_size, int memflush, int op, bool once) +int run_fill_buf(size_t buf_size, int memflush, int op, bool once) { unsigned char *buf; int ret; @@ -164,16 +154,6 @@ static int fill_cache(size_t buf_size, int memflush, int op, bool once) else ret = fill_cache_write(buf, buf_size, once); free(buf); - - return ret; -} - -int run_fill_buf(size_t span, int memflush, int op, bool once) -{ - size_t cache_size = span; - int ret; - - ret = fill_cache(cache_size, memflush, op, once); if (ret) { printf("\n Error in fill cache\n"); return -1; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index a33f414f6019..08b95b5a4949 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -92,7 +92,7 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, char *resctrl_val); int perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags); -int run_fill_buf(size_t span, int memflush, int op, bool once); +int run_fill_buf(size_t buf_size, int memflush, int op, bool once); int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *param); int mbm_bw_change(int cpu_no, const char * const *benchmark_cmd); void tests_cleanup(void);