Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1763150rda; Tue, 24 Oct 2023 02:27:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGNY9j9So2ZnHiCLRh9pX73GGQ96U+OFaIXXlE964pNTYgzCgc+JShb8BWvlqayg2DVbvOA X-Received: by 2002:a17:902:fb83:b0:1ca:731a:23e4 with SMTP id lg3-20020a170902fb8300b001ca731a23e4mr10519951plb.40.1698139676601; Tue, 24 Oct 2023 02:27:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139676; cv=none; d=google.com; s=arc-20160816; b=aEP1IZOxriSa24h9224/jmMLjq/kAxwTQLCDNTdL6qrNwZJRcdYmiuryfS1fnwXlbn sAFwGnh1yLZK9C5k1GxP/zAZqcrHDS5aV+TBoVB85bqWhywwkPgd8IoI+BY/DyjJQQj7 ZqJ2XqFzNaeVDDOB1J9v9Kr4fjLpcE6RIXWU+RNOh95jAaEgUhPORVn68x+UJPDWJaP/ eck80B/L9t4ErVrUn56fVJVzqzNlONA35GefsIT166poMituDcN5XUWG3olbz37pdDAC Nd9C2icTVVJEPJqvPtZ4W0XxgisUqzUuAOd6Sw5h+YT+TbuTJ7EBJYpPQDUsZzqosyh4 vCMA== 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=nqAKDF7YrQdPuEFmpixmT/FX14jkan2huphYvYuOei0=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=Ih/WihLCyyjTg8bSAvcq5Nj3i+MvDPWmGZkQTRqQKVnk709MU5if5J6OStYmFYhMXL J4gLfW2O0aUnyygyGDdLVTGRY380NfXS4Fz45shOZERwvki/1QmwsZfr/0d9umzBB1WE 1PHS/K9RePmZCkizqivvt+BWK/Z6Djkkhllba4Sey63Vr5YUoElMSuAYw5IjtjkQlJah yZKUyxgIOnWf60QgIZ0J66SORiTgt3hLS47mPNjZiQAhqXMSe/VdHVbGJCbdKjoc1juD WN8v1eV6NH3C5Cr0hiKlk3D32rLFc9mWhr4KlmHY6dZaaUR1186mHWQt0yKrtvFaIt+c gkCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S9b8biNV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id g9-20020a1709026b4900b001c7347e993esi7962719plt.17.2023.10.24.02.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:27:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S9b8biNV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id C6EA6808D4BD; Tue, 24 Oct 2023 02:27:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234101AbjJXJ1r (ORCPT + 99 others); Tue, 24 Oct 2023 05:27:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234165AbjJXJ1e (ORCPT ); Tue, 24 Oct 2023 05:27:34 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43D4C170E; Tue, 24 Oct 2023 02:27:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139626; x=1729675626; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R45F98fHakdxYxWQJb3bOvle17ofixaT3HcQ0/a68KM=; b=S9b8biNV/tOwtYAbvBxr5jYezvIhlnTKLWGBq0zXn7qGueQmixuIcuVS tHPOiNYHDomZljermy5heL7eJUSZUno6kxnd/0J4yRS1RO7tmVehRaLYA imjWOPWotFzmajowkAUDGYmqA7U/rOd4Gb/7bHEvYz9fe2UegS/uiMZ+X 86ER0gmmsR4F9PIG4WOvmpFeYK8azY7oOa/mdEdpMhTcqvSyA8w2D0bSm tocM30nmBPjm8T48w5cyPa5SlvoF1nxs/n2RRRLoIopKjN/GZFBsOXCJL +JBYBm5yut2oXCY5Ympjhp0DWEIYdT+9o6NaLwx8tF33CQNSQE68r6cYu w==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="366363883" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="366363883" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:27:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="882061125" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="882061125" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:27:02 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , =?UTF-8?q?Maciej=20Wiecz=C3=B3r-Retman?= , Fenghua Yu Cc: linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH 02/24] selftests/resctrl: Refactor fill_buf functions Date: Tue, 24 Oct 2023 12:26:12 +0300 Message-Id: <20231024092634.7122-3-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231024092634.7122-1-ilpo.jarvinen@linux.intel.com> References: <20231024092634.7122-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:27:54 -0700 (PDT) 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'. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/fill_buf.c | 58 +++++++--------------- tools/testing/selftests/resctrl/resctrl.h | 2 +- 2 files changed, 20 insertions(+), 40 deletions(-) diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index f9893edda869..9d0b0bf4b85a 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,20 +114,33 @@ 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 *p = NULL; + uint64_t *p64; + size_t s64; + int ret; - buf = malloc_and_init_memory(buf_size); - if (!buf) + ret = posix_memalign(&p, PAGE_SIZE, buf_size); + if (ret < 0) return NULL; + /* Initialize the buffer */ + 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)); + } + /* Flush the memory before using to avoid "cache hot pages" effect */ if (memflush) - mem_flush(buf, buf_size); + mem_flush(p, buf_size); - return buf; + return p; } -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); -- 2.30.2