From patchwork Tue Oct 24 09:26:11 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: 157324 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1819532vqx; Tue, 24 Oct 2023 02:28:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHh2qvFOaP+8UnK2W7hFs/XKzW3IiphcX2Ln70mRrDs1XAA+Rs5dOxFVF/VsqliK35mDfzl X-Received: by 2002:a05:6808:910:b0:3ab:843f:76fd with SMTP id w16-20020a056808091000b003ab843f76fdmr12767825oih.19.1698139685722; Tue, 24 Oct 2023 02:28:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139685; cv=none; d=google.com; s=arc-20160816; b=UABlmiXsWW+UmnFm6cGTTJorEo3EN+8aLUMzWFYDqVcBBCZ5RNz8TR4hzjq6DGt+KZ E3TZoRUPnDzkTZxOhOmxWKGodBVE8sm3WO1YeeOTI+vnfbrzBOPnetL/9dAuWWSeZ8Zh 3fB1PlPJ9HU9dKqGguC8Pjb8rmoCA8nkjoyP1Gc8tnatqrdDbzkBrDqB2dcOIz3qDWJE qumvLzj1ABx0U9rHjp4yqZpnxubCWQWpttCjiSI8wjDHmzVJljByF1xk+LXX+rRNnEKP um7syTkAYqNPp7WjJp6NyEFIdEaTbhVFEEBf0ZAUp2wee9Sw1sF9Oy7Fu+HwTGKOxY+T fYhw== 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=EeVkC7n0FTQAo2uxO4Cs256xalKJH69zSMy7OWB7hbA=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=uLU15DJorziI6G2+nljXZU7yLPOFBY3s7SWuUWIx41RsJqFj7xZ8MCNXeF68qvMkiL 6jBDfXn4gWjCM+p0qMFf6U/XOclCk9WIliP+2wSkmJgnaYcosRMqwEwJ7pT/qNnb3wbs +elytd+3GlrYXvPGyrmE9uxhdiZdtXcuex6jrvJtb0SeG5rRWc30qHsa43jim4kM6cGP HmpQsUzzxDmsRVF13PLz2egKVfCdUp5b2atUAdepoJgqBP+8LDDmwPGBL3zwcC+r7bc7 t3gRiQf/5qYx2A4vZ/vVygYpt7Lbb711F49ZadXMP+li907XvhSYGe6NRxAakb/Q7bee LQbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=i6+7XX4K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id h69-20020a636c48000000b005648d3f2031si7591491pgc.362.2023.10.24.02.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:28:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=i6+7XX4K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id AC4B680569AC; Tue, 24 Oct 2023 02:28:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234210AbjJXJ1f (ORCPT + 26 others); Tue, 24 Oct 2023 05:27:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234149AbjJXJ1V (ORCPT ); Tue, 24 Oct 2023 05:27:21 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 984771FE1; Tue, 24 Oct 2023 02:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139618; x=1729675618; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JMN9aahDdQAcKor/PtXdQYhZXLxsC0uS+tKkhuZPS0s=; b=i6+7XX4KggrwIiaXnGqRjcB0BrTvLhTJdYbWiWrNMJ0/YRtg95uWHEt2 0WydlUJFDEyGi6SudwC4h3NvbNd+9VC5qkJbrOyg2UukpT/uVjlrXtnFn cTtu11M8Cv98Qt2jiEuLaJ/Ez5qfVTHG7mPemQgN5DOZenhCaZbAEie52 ieapV7ODL5O/3PRBkovwb17BFic151e/CDB6hJr2UgctjmjklBt+lJtVr 6WCDtbMWMbZBKRUAg+3m2QXq65YMRu3ZMQUuHRfNc7GkMaogvcmEC+66V Bs+nURVqwTXYbV6nmm1FdtGWODMi6nNjcAqNQuERroM8HZ10W9ocIHBwB A==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="8570095" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="8570095" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:26:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="708223418" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="708223418" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:26:53 -0700 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 01/24] selftests/resctrl: Split fill_buf to allow tests finer-grained control Date: Tue, 24 Oct 2023 12:26:11 +0300 Message-Id: <20231024092634.7122-2-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 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 groat.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 (groat.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:28:02 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628518800370013 X-GMAIL-MSGID: 1780628518800370013 MBM, MBA and CMT test cases use run_fill_buf() to loop indefinitely around the buffer. CAT test case is different and doesn't want to loop around the buffer continuously. Split fill_cache() so that both the use cases are easier to control by creating separate functions for buffer allocation and looping around the buffer. Make those functions available for tests. The new interface is based on returning/passing pointers instead of the startptr global pointer variable that can now be removed. The deallocation can use free() directly. This change is part of preparation for new CAT test which allocates a buffer and does multiple passes over the same buffer (but not in an infinite loop). Co-developed-by: Fenghua Yu Signed-off-by: Fenghua Yu Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/fill_buf.c | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index 0d425f26583a..f9893edda869 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -135,33 +135,37 @@ static int fill_cache_write(unsigned char *buf, size_t buf_size, bool once) return 0; } -static int fill_cache(size_t buf_size, int memflush, int op, bool once) +static unsigned char *alloc_buffer(size_t buf_size, int memflush) { unsigned char *buf; - int ret; buf = malloc_and_init_memory(buf_size); if (!buf) - return -1; + return NULL; /* Flush the memory before using to avoid "cache hot pages" effect */ if (memflush) mem_flush(buf, buf_size); + return buf; +} + +static int fill_cache(size_t buf_size, int memflush, int op, bool once) +{ + unsigned char *buf; + int ret; + + buf = alloc_buffer(buf_size, memflush); + if (buf == NULL) + return -1; + if (op == 0) ret = fill_cache_read(buf, buf_size, once); else ret = fill_cache_write(buf, buf_size, once); - free(buf); - if (ret) { - printf("\n Error in fill cache read/write...\n"); - return -1; - } - - - return 0; + return ret; } int run_fill_buf(size_t span, int memflush, int op, bool once) From patchwork Tue Oct 24 09:26:12 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: 157326 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1819706vqx; Tue, 24 Oct 2023 02:28:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2kQaGyeoiV9aYuXcgBCjlA+mUvmiTp1SFRhVsov+FsvRjNQSR2IKc03hv1x2emolraHXg X-Received: by 2002:a17:903:11c7:b0:1bb:77a2:edda with SMTP id q7-20020a17090311c700b001bb77a2eddamr12577937plh.36.1698139724743; Tue, 24 Oct 2023 02:28:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139724; cv=none; d=google.com; s=arc-20160816; b=MLLMwruyHVSAHZdjIMtSBweQjtv1JAyK8i6ah4QkZC60K5ozvzpYUR7ZUjvxbSsWIK sbkw8idgz7DDqlHrSWjTEjTPosigW+loAsI8KZYa6uJp9g+ErHnMqbImynN+q8VE5mBj PLfenLmGTI9KENA7LWAKdBfX+/Y7tSq4WboKyr3TWNsKpPvTC7kyWVIM3X1NMft8vBA/ 1DQAL2Csim33T94/SD8d/46Bzu1QOUd/kV4m4PweSvZT29hSU6t4V73E9V79vbw0HYa1 MVFC8LNmoXZ8Apsjj1tx94OLnxU0/gzCqAG4ocSha4PpU8svqxLytMkoTloMQQxon3AO 3tog== 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.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id j16-20020a170902759000b001c6223e5675si7683626pll.188.2023.10.24.02.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:28:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; 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.34 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 howler.vger.email (Postfix) with ESMTP id 51DDC8082065; Tue, 24 Oct 2023 02:28:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234169AbjJXJ1r (ORCPT + 26 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_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 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 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 howler.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 (howler.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:28:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628559979613617 X-GMAIL-MSGID: 1780628559979613617 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); From patchwork Tue Oct 24 09:26:13 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: 157334 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1820298vqx; Tue, 24 Oct 2023 02:30:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEzt+Ith9KosaQ7M6yRoU0PVQ2gb3cTWBrRVbBomVlSOkk8Uy6PLLHYIt86gkVfKuLzNw1N X-Received: by 2002:a17:902:e54e:b0:1c9:ddd8:9950 with SMTP id n14-20020a170902e54e00b001c9ddd89950mr15280532plf.21.1698139809706; Tue, 24 Oct 2023 02:30:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139809; cv=none; d=google.com; s=arc-20160816; b=TCK0dtPBnNoOvG1XDhDonvWgUVhAqi0CTbOHhcqsPxSA+SDDKu8bG96fZaJN8+EgVv O/mQXlFUaZBuf/ISMPiNzqZz7LuGfevTk8QFDOMsZ4eRjcDHRak0/YLJMIWMs2HImVlg YPWow6JrNl/ZiclXv1Mwbw0zeuIIDWEQSz8GCfYAtfEzHQUfdShF1NpNtRDkR5q1hKc8 j6Yf3vBlG2BYyIeY2BxySjN9L4Vyc5RCuELpgpXk896I+N+69Ti9hhTIawH/Rq3TsG0n czkzSL3mWBuUvrCYLc0C8hslmG/sGGTWHqWCJP7xZhhWS1VlVMtrighiRDFhFeP7pmGy rVEg== 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=88fS2I1NPyaJ4eUK29evjb3q64BmZAjisFDm4ZU4Ci8=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=REutt9lJ3baLHn3pp60wb8BCOgNgHGVXr2eeeIPhWrAs55Kj2yUKpSMA6YLocg8vtA 0GJ6KceHCISN5VtUR4KFTxSkz8eTBGdKIdFNMmHOXoYjmknKboFyHJ96Tbi3oIIjatwA 99SqDzx0+zfYP7Z7TcGUOAjf0lQCoj0yinNwlZtFlNsQjy7ytKptMjBjnIxrqec7gILD GmTZFJzbd8ZOhgg+1mMzhO5cBamzC/KGGQ6pupXe/q5jdMLWAZb4YNYCpjCT85fzcm4q 3u7xSBDcEKbrEHViJO97Ez3yizJnAH2tuHh7BsIUCXnf7fnBfw4GAdMOsnEj+AVmg13N aW/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TWzz67uK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id p3-20020a170902a40300b001bb809b68a8si7749427plq.229.2023.10.24.02.30.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:30:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TWzz67uK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 453B08041C18; Tue, 24 Oct 2023 02:29:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234151AbjJXJ1z (ORCPT + 26 others); Tue, 24 Oct 2023 05:27:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234140AbjJXJ1l (ORCPT ); Tue, 24 Oct 2023 05:27:41 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76FD4171F; Tue, 24 Oct 2023 02:27:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139634; x=1729675634; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UIg76DZLH2Ux1hgHN9LvU2UkvHlgr3jlI5rvomAofZk=; b=TWzz67uKJnZ2gRI0VmVoGxXVP/f2R/KCLmirXlADT5+SjQbeSi8XunHq 4LKr0OyIy4QZjjA2VgmTNvUHoW2ZhCj0upegSkHOf9o5B+IF61wxNqlnN OkpN30s2AFtLAhcVyara5yGa9YpPqDhkTKh09Qi5H4g5K1oikYZ1aEUeo xASN2h/qqnIMFySz13H1tFoX9wVZbNnqJE1py7elI9G2MoezFjwx1/kvt Z2sCrCXSpV3xWIDePFhk3XLEE/CNAZzZUk1wD0lHyV2zIqxk4sDL3hxX2 Qhu8JoevxKk8RUp0zr0Kw7gCQ4nEL0+Aoaa9SmzgNGZyIYQWfa//0Xu/0 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="8570103" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="8570103" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:27:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="708223433" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="708223433" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:27:10 -0700 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 03/24] selftests/resctrl: Refactor get_cbm_mask() Date: Tue, 24 Oct 2023 12:26:13 +0300 Message-Id: <20231024092634.7122-4-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 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 pete.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 (pete.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:29:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628648902408530 X-GMAIL-MSGID: 1780628648902408530 Callers of get_cbm_mask() are required to pass a string into which the CBM bit mask is read. Neither CAT nor CMT tests need the mask as string but just convert it into an unsigned long value. The bit mask reader can only read .../cbm_mask files. Generalize the bit mask reading function into get_bit_mask() such that it can be used to handle other files besides the .../cbm_mask and handle the unsigned long conversion within get_bit_mask() using fscanf(). Alter get_cbm_mask() to construct the filename for get_bit_mask(). Also mark cache_type const while at it. Co-developed-by: Fenghua Yu Signed-off-by: Fenghua Yu Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cat_test.c | 5 +-- tools/testing/selftests/resctrl/cmt_test.c | 5 +-- tools/testing/selftests/resctrl/resctrl.h | 2 +- tools/testing/selftests/resctrl/resctrlfs.c | 50 +++++++++++++++------ 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 224ba8544d8a..4852bbda2e71 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -93,18 +93,15 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) int ret, pipefd[2], sibling_cpu_no; unsigned long cache_size = 0; unsigned long long_mask; - char cbm_mask[256]; int count_of_bits; char pipe_message; size_t span; /* Get default cbm mask for L3/L2 cache */ - ret = get_cbm_mask(cache_type, cbm_mask); + ret = get_cbm_mask(cache_type, &long_mask); if (ret) return ret; - long_mask = strtoul(cbm_mask, NULL, 16); - /* Get L3/L2 cache size */ ret = get_cache_size(cpu_no, cache_type, &cache_size); if (ret) diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c index 50bdbce9fba9..a6c79edc33cd 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -75,17 +75,14 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd) unsigned long cache_size = 0; unsigned long long_mask; char *span_str = NULL; - char cbm_mask[256]; int count_of_bits; size_t span; int ret, i; - ret = get_cbm_mask("L3", cbm_mask); + ret = get_cbm_mask("L3", &long_mask); if (ret) return ret; - long_mask = strtoul(cbm_mask, NULL, 16); - ret = get_cache_size(cpu_no, "L3", &cache_size); if (ret) return ret; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 08b95b5a4949..e95121a113f3 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -99,7 +99,7 @@ void tests_cleanup(void); void mbm_test_cleanup(void); int mba_schemata_change(int cpu_no, const char * const *benchmark_cmd); void mba_test_cleanup(void); -int get_cbm_mask(char *cache_type, char *cbm_mask); +int get_cbm_mask(const char *cache_type, unsigned long *mask); int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size); void ctrlc_handler(int signum, siginfo_t *info, void *ptr); int signal_handler_register(void); diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 5ebd43683876..220dc83748ca 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -196,30 +196,29 @@ int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size) #define CORE_SIBLINGS_PATH "/sys/bus/cpu/devices/cpu" /* - * get_cbm_mask - Get cbm mask for given cache - * @cache_type: Cache level L2/L3 - * @cbm_mask: cbm_mask returned as a string + * get_bit_mask - Get bit mask from given file + * @filename: File containing the mask + * @mask: The bit mask returned as unsigned long * * Return: = 0 on success, < 0 on failure. */ -int get_cbm_mask(char *cache_type, char *cbm_mask) +static int get_bit_mask(const char *filename, unsigned long *mask) { - char cbm_mask_path[1024]; FILE *fp; - if (!cbm_mask) + if (!filename || !mask) return -1; - sprintf(cbm_mask_path, "%s/%s/cbm_mask", INFO_PATH, cache_type); - - fp = fopen(cbm_mask_path, "r"); + fp = fopen(filename, "r"); if (!fp) { - perror("Failed to open cache level"); - + fprintf(stderr, "Failed to open bit mask file '%s': %s\n", + filename, strerror(errno)); return -1; } - if (fscanf(fp, "%s", cbm_mask) <= 0) { - perror("Could not get max cbm_mask"); + + if (fscanf(fp, "%lx", mask) <= 0) { + fprintf(stderr, "Could not read bit mask file '%s': %s\n", + filename, strerror(errno)); fclose(fp); return -1; @@ -229,6 +228,31 @@ int get_cbm_mask(char *cache_type, char *cbm_mask) return 0; } +/* + * get_cbm_mask - Get cbm bit mask + * @cache_type: Cache level L2/L3 + * @mask: cbm_mask returned as unsigned long + * + * Return: = 0 on success, < 0 on failure. + */ +int get_cbm_mask(const char *cache_type, unsigned long *mask) +{ + char cbm_mask_path[1024]; + int ret; + + if (!cache_type) + return -1; + + snprintf(cbm_mask_path, sizeof(cbm_mask_path), "%s/%s/cbm_mask", + INFO_PATH, cache_type); + + ret = get_bit_mask(cbm_mask_path, mask); + if (ret) + return -1; + + return 0; +} + /* * get_core_sibling - Get sibling core id from the same socket for given CPU * @cpu_no: CPU number From patchwork Tue Oct 24 09:26:14 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: 157339 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1821088vqx; Tue, 24 Oct 2023 02:31:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHGqr6CIyItqI/WCmZo4FujMic80N1wE293rhZ1WQESQW+jlAvrrMY6dnhD40oBC4Xqt2eR X-Received: by 2002:a05:6a20:7487:b0:16b:74db:8fe1 with SMTP id p7-20020a056a20748700b0016b74db8fe1mr2203723pzd.29.1698139916463; Tue, 24 Oct 2023 02:31:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139916; cv=none; d=google.com; s=arc-20160816; b=Z3H3qc+s3qeeSuNw/v+yMVtE1/05hBZCPD2r8N151/iY8nug6MPFa4yV6uFB/WhH1G H81S/h43irJscVV5cNpYxLqlaEDK7mf+j6tNQOnXveJ0kugXh4OwsbQ1ljQJdPse2tjn xxTUV2NkPOGSb0+eJL4TOIkND5eE6Yvww0lEhcBEQfonn/qpQf8KjHq03Etq6PPJXC25 Bx1JuDHuIRC81zbG5fohJu/9Mfylvocw/OPQ8B23mxPJzqCLBAKUSvudm5/XSkwpyr9d cDvc/dtPdz2G3cDdlFJ5r2WaTwJqlUWK6Mky6LYPc5AK3cviJOs9gpfsIhpvQqHdXpTd Y2kg== 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=iX00C25aX18+BpG8rP40uJnVD1fjjjB8G8FjH6yBTiw=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=W1eMMsIHaa7QuDJGuYbzWJ4VnvKLWZYzmo+6lJoORch/srwvHxhfTnIlD7wIgSGn2f BRBLJzCcmemHFGjVA4+vdZ4I4iLKCgj6EfNjENcbBTL12AySRU+V7O6OQCT8fGYGt1uB VQmGz1WNMlyRO2TveIP93vI7JW7duC/fdPxx16fZL4gtPV7LKndi+UlMRUPbeFUeQYiJ lr33yrtgqVhufwRa33ea0eE2WpQzU+LTXm2ReWHPSB/dBG+ByTObONBw4lohYbeopXRz zXvKsBbkHjwcwYhvTgjRT/5KIXHR1L45AhRqhar5tlNYIizPkjVzYpCFSlzwOFyKQs3C /a6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VtCDMOwO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id y17-20020a637d11000000b005b2cbc049cdsi8243739pgc.307.2023.10.24.02.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:31:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VtCDMOwO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 80D0B8073DCB; Tue, 24 Oct 2023 02:31:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234116AbjJXJ2G (ORCPT + 26 others); Tue, 24 Oct 2023 05:28:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234152AbjJXJ1q (ORCPT ); Tue, 24 Oct 2023 05:27:46 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEB861998; Tue, 24 Oct 2023 02:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139642; x=1729675642; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+4ID6L9EUqCaz0idLUa+6bfvdG7Emg+ZFtrDA3juAok=; b=VtCDMOwOJNxAxY4IR0rl7wXHYscM7XjF/Lpk/+Q0qpilUNMX0DK7Hg+S 8UBevG+kLoM5Cu1KlCLNLlFZJI/E9sT6cNmWhPIIfQRduz1WwJ/57B7rl PQmGXt12n6tX8AZ9C/1LKU+HlkmeUOeZnilxABbRUrgBxokIbhUV2JYmT 566ABM5EcNPgGayuSS8qZmkihid94fNufvxhvumOQJYqHhX61+3uj3Cpm kbJ8NX6azzXb7CexaxfITBG5fAb3jBE0hFTdZCjxg4CZH4OhRUaqm83Ju OPRoOwUKuyZgRJXIOBY8goGKW8NaHRWKJGdkS4fRpalewdfjKJJdu5sxj Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="366363898" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="366363898" 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:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="882061150" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="882061150" 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:18 -0700 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 04/24] selftests/resctrl: Mark get_cache_size() cache_type const Date: Tue, 24 Oct 2023 12:26:14 +0300 Message-Id: <20231024092634.7122-5-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 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 pete.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 (pete.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:31:36 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628760928484908 X-GMAIL-MSGID: 1780628760928484908 get_cache_size() does not modify cache_type so it could be const. Mark cache_type const so that const char * can be passed to it. This prevents warnings once many of the test parameters are marked const. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/resctrl.h | 2 +- tools/testing/selftests/resctrl/resctrlfs.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index e95121a113f3..2f3f0ee439d8 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -100,7 +100,7 @@ void mbm_test_cleanup(void); int mba_schemata_change(int cpu_no, const char * const *benchmark_cmd); void mba_test_cleanup(void); int get_cbm_mask(const char *cache_type, unsigned long *mask); -int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size); +int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size); void ctrlc_handler(int signum, siginfo_t *info, void *ptr); int signal_handler_register(void); void signal_handler_unregister(void); diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 220dc83748ca..46fb0441818d 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -138,7 +138,7 @@ int get_resource_id(int cpu_no, int *resource_id) * * Return: = 0 on success, < 0 on failure. */ -int get_cache_size(int cpu_no, char *cache_type, unsigned long *cache_size) +int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size) { char cache_path[1024], cache_str[64]; int length, i, cache_num; From patchwork Tue Oct 24 09:26:15 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: 157325 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1819682vqx; Tue, 24 Oct 2023 02:28:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMtO6uwjxCPb6kkJsaMCiKBiTB32TYgqbENoEo9sJM4W3p8xniHoFqqNCYxm6ZrHakroha X-Received: by 2002:a05:6a21:99a9:b0:166:6582:a7d5 with SMTP id ve41-20020a056a2199a900b001666582a7d5mr2088381pzb.3.1698139718926; Tue, 24 Oct 2023 02:28:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139718; cv=none; d=google.com; s=arc-20160816; b=U5Htn/HqruSJmrh3uZet+6TPfEtlM2PT7tsFbEny5LTJABF40NVCyKobyT3615lPfW B9QG0Bw8xQYfvOqM3S0YG/O1DazyOVzTdMZ4A9VVqL05JeSBTlmDGNjOW12CrrNgAOGi OB0BzE9t9NcYOXIG7JrO/nUVG34qIau+PaemnyC20hcj84TxCybBdsnx9vm+66DQOEEA gnZ0ooZPy3C2OtBoSXpP5u+uzYYulG0InhQP6DXJ/uzh34H91Lhv98VdirnuSFl7icQq UZjfdBpLShig40xc+Px8SRocRyZliE6ek2zmTXL5H4DIEf4BBdbfbNZ9D7dYcdvSD4sc hNmw== 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=fc+VLEM4WFlbS+NQtnjCfu9EMXzBDLk3VJaUBzRJgfk=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=X38hofVgk9idZxo3FDkHD4cp8rncNXO/ywShqha65qSVwGMXRRknTxOnzhen4dYJzC h4di3i61xFFf2ZE6kWHeIAeT9gCnRgySQPnYLUEAMZJSyqdt6FD1tjCFgwJ8uv4mYTL/ Bl33PqsIfrcew+1E+0OGWesY1tnFzkEi5VjwbD9CvTG6LYB/bBRaXDWeRmtjqOd+QWo/ GjyoeeAPWo1haJ/OZB202vJ3JdmeGuydHDBdDKIcv7yk0dWfQn4qPdSmee7vOwgYP1zl H8WxF5s1fDAQ3JdWvo4qRNMpPZymDmIhsyW53lJr/at3wpb5ErQtTwy5+c0jzCbJpRky qSfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=d+l5n9Ag; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id k15-20020a170902c40f00b001a6ef92d441si8761365plk.599.2023.10.24.02.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:28:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=d+l5n9Ag; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 73231804238B; Tue, 24 Oct 2023 02:28:36 -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 S234234AbjJXJ2S (ORCPT + 26 others); Tue, 24 Oct 2023 05:28:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234066AbjJXJ1y (ORCPT ); Tue, 24 Oct 2023 05:27:54 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 945281BC2; Tue, 24 Oct 2023 02:27:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139651; x=1729675651; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+7gRKcJ0CvY7ckOs0uWSoDBGK4mY5SuoxJXfmAWuV8Y=; b=d+l5n9Ag8qFrCpMDIOF4melsBr1eveH9WegakHLJwwfAxoFkXAgRqVzG 22D5h1q/PPEHLxKmNQfC2kNsHGkydJnJ2E1iiDAgRWG+ivaLZfqm/1TiD X3wyrVeEK1Du8FJF9sW9cM/H02kiht2fgGfxN9ngB4mDraBUW9MWcPfyS pKZoCZEaW3PzI2F0lcJECcvSIVF2ty+IJxCCS2tgXxqHe88hyIxqdENHB pUt4EmtGyE2yCkuANnViReOgs3tvPlPEMbpoO0HRCsGDlSx4BJk7XV4UA RAsWGtIGUKJ9/wQpTk2beu/NwmYHNC/5u3jVFMbwVIuOjCxYVQ/PU/X0x w==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="386829480" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="386829480" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:27:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="751939081" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="751939081" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:27:27 -0700 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 05/24] selftests/resctrl: Create cache_size() helper Date: Tue, 24 Oct 2023 12:26:15 +0300 Message-Id: <20231024092634.7122-6-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 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:28:36 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628554014264802 X-GMAIL-MSGID: 1780628554014264802 CAT and CMT tests calculate the span size from the n-bits cache allocation on their own. Add cache_size() helper which calculates size of the cache portion for the given number of bits and use it to replace the existing span calculations. This also prepares for the new CAT test that will need to determine the size of the cache portion also during results processing. cache_size local variables were renamed out of the way to cache_total_size. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cat_test.c | 10 +++++----- tools/testing/selftests/resctrl/cmt_test.c | 8 ++++---- tools/testing/selftests/resctrl/resctrl.h | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 4852bbda2e71..80861c362a53 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -91,7 +91,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) { unsigned long l_mask, l_mask_1; int ret, pipefd[2], sibling_cpu_no; - unsigned long cache_size = 0; + unsigned long cache_total_size = 0; unsigned long long_mask; int count_of_bits; char pipe_message; @@ -103,10 +103,10 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) return ret; /* Get L3/L2 cache size */ - ret = get_cache_size(cpu_no, cache_type, &cache_size); + ret = get_cache_size(cpu_no, cache_type, &cache_total_size); if (ret) return ret; - ksft_print_msg("Cache size :%lu\n", cache_size); + ksft_print_msg("Cache size :%lu\n", cache_total_size); /* Get max number of bits from default-cabm mask */ count_of_bits = count_bits(long_mask); @@ -138,7 +138,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) /* Set param values for parent thread which will be allocated bitmask * with (max_bits - n) bits */ - span = cache_size * (count_of_bits - n) / count_of_bits; + span = cache_size(cache_total_size, l_mask, long_mask); strcpy(param.ctrlgrp, "c2"); strcpy(param.mongrp, "m2"); strcpy(param.filename, RESULT_FILE_NAME2); @@ -160,7 +160,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) param.mask = l_mask_1; strcpy(param.ctrlgrp, "c1"); strcpy(param.mongrp, "m1"); - span = cache_size * n / count_of_bits; + span = cache_size(cache_total_size, l_mask_1, long_mask); strcpy(param.filename, RESULT_FILE_NAME1); param.num_of_runs = 0; param.cpu_no = sibling_cpu_no; diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c index a6c79edc33cd..e8997ff5bc04 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -72,7 +72,7 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd) { const char * const *cmd = benchmark_cmd; const char *new_cmd[BENCHMARK_ARGS]; - unsigned long cache_size = 0; + unsigned long cache_total_size = 0; unsigned long long_mask; char *span_str = NULL; int count_of_bits; @@ -83,10 +83,10 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd) if (ret) return ret; - ret = get_cache_size(cpu_no, "L3", &cache_size); + ret = get_cache_size(cpu_no, "L3", &cache_total_size); if (ret) return ret; - ksft_print_msg("Cache size :%lu\n", cache_size); + ksft_print_msg("Cache size :%lu\n", cache_total_size); count_of_bits = count_bits(long_mask); @@ -107,7 +107,7 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd) .setup = cmt_setup, }; - span = cache_size * n / count_of_bits; + span = cache_size(cache_total_size, param.mask, long_mask); if (strcmp(cmd[0], "fill_buf") == 0) { /* Duplicate the command to be able to replace span in it */ diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 2f3f0ee439d8..da06b2d492f9 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -117,4 +117,18 @@ int show_cache_info(unsigned long sum_llc_val, int no_of_bits, unsigned long max_diff_percent, unsigned long num_of_runs, bool platform, bool cmt); +/* + * cache_size - Calculate the size of a cache portion + * @cache_size: Cache size in bytes + * @mask: Cache portion mask + * @cache_mask: Full bitmask for the cache + * + * Return: The size of the cache portion in bytes. + */ +static inline int cache_size(unsigned long cache_size, unsigned long mask, + unsigned long cache_mask) +{ + return cache_size * count_bits(mask) / count_bits(cache_mask); +} + #endif /* RESCTRL_H */ From patchwork Tue Oct 24 09:26:16 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: 157327 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1819795vqx; Tue, 24 Oct 2023 02:28:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCInviAPyWHN9+au+LVXJMxbJzvU6s5rNVcK3tV7SteqNbR8YdbFYhvH4bFxsmCgytLXJs X-Received: by 2002:a17:90b:701:b0:27d:5679:9fa1 with SMTP id s1-20020a17090b070100b0027d56799fa1mr9172194pjz.17.1698139735443; Tue, 24 Oct 2023 02:28:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139735; cv=none; d=google.com; s=arc-20160816; b=P0wEJnXPmQVCj3hVrItQcyemlhN2LVqURw0dWb+ZbeCX5ohrWqQj0b2Jo8xJQ+SQ1C G3SF+kk9TQFUD/x650GB6lX26OXgyee11F1njwzD1DhIXf3sawa6wjPjE1rlEydPFiAy N0bAmOYlRVRTwJY8zoIz5ft7hfUs/CT2eUpiS9L3x9yE/Qo+ldjqga5J0xZuNvYN1YcB vBmMUwiUDHlL+dSmbT9e/RYmvDefnkqeLu2L/NBhDFFoh8uJ4tHfTIv5nw6S3SAA4i6o 1MKNloMPItlIGPXmrMFdIUH4kpPSkrYrLY4yUZ5oUdSw1a1ce70Bhb/7EX8PgXupYQT3 yhKw== 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=mGANny4y8CGYoykeW2xeo7vBK20iKrLzVU2TSAQZew0=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=DP6BNmhUy3tbcfZAym8aznRZ5eVbVpSOq6k2I7Bs75KGQIoj/TVdOcO1eFbGZ1gEK6 HIAi14pXXFyIzRtpeOLoPQOk2xmylb0Tws7RR+L3RRxq0ghWwSIq50504sWbP/AoSfHn PkbeSK6kmxJmyHuqqFAiYGZLS6X80Ix+pdRBZPJwNNC5P4dd83bKk6Vf3u3aA8oyzU4r mJwGwjXb4fJ9t/MsG9QNcWKKmo9wwXR363bU4YfiuulnvZG+LqdF9a1Z+fzD7XItxB27 Z0LvAFlDKP3Gy3ghX7K/+twS+qcK0cOzHSavSPtrMMeeJKaougp7+8mafFiEUlHHiwk9 D9PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=f5z9ZfdU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id s16-20020a17090aad9000b0027cfa8df932si10686052pjq.59.2023.10.24.02.28.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:28:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=f5z9ZfdU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id CC1D88082065; Tue, 24 Oct 2023 02:28:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234030AbjJXJ2d (ORCPT + 26 others); Tue, 24 Oct 2023 05:28:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234203AbjJXJ2E (ORCPT ); Tue, 24 Oct 2023 05:28:04 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E69CD10D3; Tue, 24 Oct 2023 02:27:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139660; x=1729675660; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pRrfeDvzObabdr4Kkn6XywKNNHArQKcAo1CjdGoVdCk=; b=f5z9ZfdUG6+ptFHoJ4XnvcsgygXuWBcf54geVAa5GOkZ7S2zQq7DmQHn 87JxJ+JsKDAj43xM/RKSlZi4CTFcy2ZXqCJllMYLFn7Q15E66PgejPaVe i6HsRQ5XYXZllmERmIOPOZIcb450BN35nQfbb/SW/cOlnl2pQDV0KcQZq I1LnxuNyMCTWy93X73kAG5v4CUUK1B3d5jMWQURCeDVVTtxYRPV26qnhG hrfwbVF4IlISftUuwF1xw77iBuROsSgoEil2BMicqqBKci/AZ39UOqZqc H8mfZRJlR95cReubvfTt0LREj1/TH4wk/WKAJPDjXxalvnU63TXCsnwtP w==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="8570145" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="8570145" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:27:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="6112228" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:26:18 -0700 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 06/24] selftests/resctrl: Exclude shareable bits from schemata in CAT test Date: Tue, 24 Oct 2023 12:26:16 +0300 Message-Id: <20231024092634.7122-7-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 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 howler.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 (howler.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:28:51 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628571215151266 X-GMAIL-MSGID: 1780628571215151266 CAT test doesn't take shareable bits into account, i.e., the test might be sharing cache with some devices (e.g., graphics). Introduce get_mask_no_shareable() and use it to provision an environment for CAT test where the allocated LLC is isolated better. Excluding shareable_bits may create hole(s) into the cbm_mask, thus add a new helper count_contiguous_bits() to find the longest contiguous set of CBM bits. create_bit_mask() is needed by an upcoming CAT test rewrite so make it available in resctrl.h right away. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cat_test.c | 12 ++- tools/testing/selftests/resctrl/resctrl.h | 3 + tools/testing/selftests/resctrl/resctrlfs.c | 84 +++++++++++++++++++++ 3 files changed, 95 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 80861c362a53..e5861e7cba7e 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -92,13 +92,17 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) unsigned long l_mask, l_mask_1; int ret, pipefd[2], sibling_cpu_no; unsigned long cache_total_size = 0; - unsigned long long_mask; + unsigned long full_cache_mask, long_mask; int count_of_bits; char pipe_message; size_t span; /* Get default cbm mask for L3/L2 cache */ - ret = get_cbm_mask(cache_type, &long_mask); + ret = get_cbm_mask(cache_type, &full_cache_mask); + if (ret) + return ret; + /* Get the exclusive portion of the cache */ + ret = get_mask_no_shareable(cache_type, &long_mask); if (ret) return ret; @@ -138,7 +142,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) /* Set param values for parent thread which will be allocated bitmask * with (max_bits - n) bits */ - span = cache_size(cache_total_size, l_mask, long_mask); + span = cache_size(cache_total_size, l_mask, full_cache_mask); strcpy(param.ctrlgrp, "c2"); strcpy(param.mongrp, "m2"); strcpy(param.filename, RESULT_FILE_NAME2); @@ -160,7 +164,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) param.mask = l_mask_1; strcpy(param.ctrlgrp, "c1"); strcpy(param.mongrp, "m1"); - span = cache_size(cache_total_size, l_mask_1, long_mask); + span = cache_size(cache_total_size, l_mask_1, full_cache_mask); strcpy(param.filename, RESULT_FILE_NAME1); param.num_of_runs = 0; param.cpu_no = sibling_cpu_no; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index da06b2d492f9..10fd3161e63a 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -99,7 +99,10 @@ void tests_cleanup(void); void mbm_test_cleanup(void); int mba_schemata_change(int cpu_no, const char * const *benchmark_cmd); void mba_test_cleanup(void); +unsigned long create_bit_mask(unsigned int start, unsigned int len); int get_cbm_mask(const char *cache_type, unsigned long *mask); +int get_shareable_mask(const char *cache_type, unsigned long *shareable_mask); +int get_mask_no_shareable(const char *cache_type, unsigned long *mask); int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size); void ctrlc_handler(int signum, siginfo_t *info, void *ptr); int signal_handler_register(void); diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 46fb0441818d..02b04878121f 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -228,6 +228,44 @@ static int get_bit_mask(const char *filename, unsigned long *mask) return 0; } +/* + * create_bit_mask- Create bit mask from start,len pair + * @start: LSB of the mask + * @len Number of bits in the mask + */ +unsigned long create_bit_mask(unsigned int start, unsigned int len) +{ + return ((1UL << len) - 1UL) << start; +} + +/* + * count_contiguous_bits - Returns the longest train of bits in a bit mask + * @val A bit mask + * @start The location of the least-significant bit of the longest train + * + * Return: The length of the contiguous bits in the longest train of bits + */ +static unsigned int count_contiguous_bits(unsigned long val, unsigned int *start) +{ + unsigned long last_val; + int count = 0; + + while (val) { + last_val = val; + val &= (val >> 1); + count++; + } + + if (start) { + if (count) + *start = ffsl(last_val) - 1; + else + *start = 0; + } + + return count; +} + /* * get_cbm_mask - Get cbm bit mask * @cache_type: Cache level L2/L3 @@ -253,6 +291,52 @@ int get_cbm_mask(const char *cache_type, unsigned long *mask) return 0; } +/* + * get_shareable_mask - Get shareable mask from shareable_bits for given cache + * @cache_type: Cache level L2/L3 + * @shareable_mask: shareable mask returned as unsigned long + * + * Return: = 0 on success, < 0 on failure. + */ +int get_shareable_mask(const char *cache_type, unsigned long *shareable_mask) +{ + char mask_path[1024]; + + if (!cache_type) + return -1; + + snprintf(mask_path, sizeof(mask_path), "%s/%s/shareable_bits", + INFO_PATH, cache_type); + + return get_bit_mask(mask_path, shareable_mask); +} + +/* + * get_mask_no_shareable - Get CBM mask without shareable_bits for given cache + * @cache_type: Cache level L2/L3 + * @mask: mask returned as unsigned long + * + * Return: = 0 on success, < 0 on failure. + */ +int get_mask_no_shareable(const char *cache_type, unsigned long *mask) +{ + unsigned long full_mask, shareable_mask; + unsigned int start, len; + + if (get_cbm_mask(cache_type, &full_mask) < 0) + return -1; + if (get_shareable_mask(cache_type, &shareable_mask) < 0) + return -1; + + len = count_contiguous_bits(full_mask & ~shareable_mask, &start); + if (!len) + return -1; + + *mask = create_bit_mask(start, len); + + return 0; +} + /* * get_core_sibling - Get sibling core id from the same socket for given CPU * @cpu_no: CPU number From patchwork Tue Oct 24 09:26: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: 157330 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1819980vqx; Tue, 24 Oct 2023 02:29:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5hiBQ51alFRJeWIyl2trhmPeMJjWVLWmg4Fww4pbMVsKY310+UMSZp0adb6UGpPUzLJBw X-Received: by 2002:a05:6a21:998d:b0:17e:2afd:407b with SMTP id ve13-20020a056a21998d00b0017e2afd407bmr2587608pzb.9.1698139762967; Tue, 24 Oct 2023 02:29:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139762; cv=none; d=google.com; s=arc-20160816; b=GUM+i2EFVBTp+3koYogVlmL1f1TntNuP/tBQGOlWzt9pwhGolrQsHnGCBl6TORRKHF bI8rvW4pIv4hLcqc66kE9VtJDPTcJ18ORKCR/asQ8vhXh+io+kNvRQtnPu4xtxGGoHD/ CVvUnsuC8Y0t45rtr9dDN7GFfQaFmCmZjtLzs2iMHrqqFvp5YhfainLi9T/3dP2Su4ZK n5IAcDPQ5RjHC4iS8un6S8OTBPE7SakLRnri5RBzbTzslx+h2jz01oULeI2jxUpZSYcP KVmC/Wtptbxt73UdjbcF3gmfRqPMB1fY7RqPwhTAcl5GHf6A6uXGiscLGyf/99Xeqi80 W/xw== 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=rQFRIxqsi2m2crJK+3cGWPRZ3MOgzyPfZTUZZfw2pn4=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=ZB86BAEAXgomoUlZn1S5KGHSUZpLLCdDIy0A+VUci42vBcVeVFnnqJ16YH/2kGwuYN joh74jNVRJj2oEK4uWfXEsb+djQMEUue1UgC6chCKOBqA9CHwIidWakjOUFiQR7zApQ7 bGrovriVBkYPn/NOVkAP6A7UADNqAkiLxU9UCXa2fhrAEkKaRistZYWijM0gSqx/aisc 7x9OxpL5IqEQAjqTBd4lrKWn1mdKf+o1aPQ6Ci98+l0ZX8JkmEAYUMidAB/WRq7jrQHK 0OIJ9TtlGGv2JJVFVLvp3N0uFFS/rBG9cWFQ+L7cNVAN7PwQh+cr3sM8bo5Oh2J7qiyW g6OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GpQsKIZD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id j1-20020a170902690100b001c4743e4a60si7891340plk.197.2023.10.24.02.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:29:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GpQsKIZD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 7FC3280569BA; Tue, 24 Oct 2023 02:29:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234225AbjJXJ2h (ORCPT + 26 others); Tue, 24 Oct 2023 05:28:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234223AbjJXJ2R (ORCPT ); Tue, 24 Oct 2023 05:28:17 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24896F9; Tue, 24 Oct 2023 02:27:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139668; x=1729675668; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iXxHTqJrXVaGB5EYZWuORQMkSW5xHXnb5vc8EVQCUGk=; b=GpQsKIZDSX84wk77EYyplM8hYGyr78V8/4LoK7GW2Deentx1/VZCcqrN be7/yNYw8y5O7t1QMLWNKgXD+7+JEI/320JMPbpX2YmbPdpXpR2ICmRv2 mNyC8H8/9jDRHe/WbLkFJbxnytSGqRDIbHytgAV/9PBIQfk4fO5bKCAvc l8/FOeWXysVo771qK8M6BDgkTzP+RxTPBuI4fNclUrebM1PmgfbYSHqQc M5TDSU2Wd0vUewxa4LGwf2wHBafmE2BgvXm0/Il6HKrGMtEZy3AM+1f8C Wi+isqo0zrrD7CxLOp2aSHudPupFfCiZlgzPNToc0LF2cvoQkJ+cLS7Lh w==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="386829500" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="386829500" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:27:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="751939155" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="751939155" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:27:43 -0700 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 07/24] selftests/resctrl: Split measure_cache_vals() function Date: Tue, 24 Oct 2023 12:26:17 +0300 Message-Id: <20231024092634.7122-8-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 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 groat.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 (groat.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:29:17 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628599802982704 X-GMAIL-MSGID: 1780628599802982704 The measure_cache_vals() function does a different thing depending on the test case that called it: - For CAT, it measures LLC perf misses. - For CMT, it measures LLC occupancy through resctrl. Split these two functionalities into own functions the CAT and CMT tests can call directly. Co-developed-by: Fenghua Yu Signed-off-by: Fenghua Yu Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 37 ++++++++++--------- tools/testing/selftests/resctrl/resctrl.h | 2 +- tools/testing/selftests/resctrl/resctrl_val.c | 2 +- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index bcbca356d56a..299d9508221f 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -170,35 +170,36 @@ static int print_results_cache(char *filename, int bm_pid, return 0; } -int measure_cache_vals(struct resctrl_val_param *param, int bm_pid) +static int measure_llc_perf(struct resctrl_val_param *param, int bm_pid) { - unsigned long llc_perf_miss = 0, llc_occu_resc = 0, llc_value = 0; + unsigned long llc_perf_miss = 0; int ret; /* * Measure cache miss from perf. */ - if (!strncmp(param->resctrl_val, CAT_STR, sizeof(CAT_STR))) { - ret = get_llc_perf(&llc_perf_miss); - if (ret < 0) - return ret; - llc_value = llc_perf_miss; - } + ret = get_llc_perf(&llc_perf_miss); + if (ret < 0) + return ret; + + ret = print_results_cache(param->filename, bm_pid, llc_perf_miss); + return ret; +} + +int measure_llc_resctrl(struct resctrl_val_param *param, int bm_pid) +{ + unsigned long llc_occu_resc = 0; + int ret; /* * Measure llc occupancy from resctrl. */ - if (!strncmp(param->resctrl_val, CMT_STR, sizeof(CMT_STR))) { - ret = get_llc_occu_resctrl(&llc_occu_resc); - if (ret < 0) - return ret; - llc_value = llc_occu_resc; - } - ret = print_results_cache(param->filename, bm_pid, llc_value); - if (ret) + ret = get_llc_occu_resctrl(&llc_occu_resc); + if (ret < 0) return ret; - return 0; + ret = print_results_cache(param->filename, bm_pid, llc_occu_resc); + return ret; } /* @@ -253,7 +254,7 @@ int cat_val(struct resctrl_val_param *param, size_t span) } sleep(1); - ret = measure_cache_vals(param, bm_pid); + ret = measure_llc_perf(param, bm_pid); if (ret) goto pe_close; } diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 10fd3161e63a..56afdc190727 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -114,7 +114,7 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd); unsigned int count_bits(unsigned long n); void cmt_test_cleanup(void); int get_core_sibling(int cpu_no); -int measure_cache_vals(struct resctrl_val_param *param, int bm_pid); +int measure_llc_resctrl(struct resctrl_val_param *param, int bm_pid); int show_cache_info(unsigned long sum_llc_val, int no_of_bits, size_t cache_span, unsigned long max_diff, unsigned long max_diff_percent, unsigned long num_of_runs, diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index 88789678917b..43ca026c6e0f 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -830,7 +830,7 @@ int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *par break; } else if (!strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) { sleep(1); - ret = measure_cache_vals(param, bm_pid); + ret = measure_llc_resctrl(param, bm_pid); if (ret) break; } From patchwork Tue Oct 24 09:26:18 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: 157329 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1819963vqx; Tue, 24 Oct 2023 02:29:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXXY+JM1YklUHBJjmMGs/5sKAdmLSHAzqIrNheQQlJTnsSAlsQtOHmhnN1AAzHOJ6ryeKE X-Received: by 2002:a17:90b:51c9:b0:27f:c7d9:1f08 with SMTP id sf9-20020a17090b51c900b0027fc7d91f08mr1600151pjb.25.1698139760768; Tue, 24 Oct 2023 02:29:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139760; cv=none; d=google.com; s=arc-20160816; b=rx4KQkSe5T6VShPaiSaB4JqBE0KYuENkWWJiylT+m1FfDEUoQFpnZoGzhE+6oRzgHl 2TNHB2W76NVkoykrpcoXE1pr+ms4XYdBnO0lrwateUoF50slWpQzlIp60dNq2oZSD0iu DOiESqbND+/6IsaHJcPZ6RlMs7XNvE6ghe1sso9LKapdhq1XZYFCA88/stRcyKyOu26c 4l0lqKRdGXoMk4LaJoo4+61jDMDNlFlck6HGw8oXuHb9QhBp6GpQ2/XRBVJTAiMVP0AQ awVSOKtt8oS+nA10TiC0/gA4RPlM/M1TJTSCYUstT7nv5LBZm0RGoX8x6oWrr3SAbfJO V/1g== 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=/siMt0z42hUMqz9rcKD5UFLh8r0CUBYLcTp5oN1Pymo=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=JoggZsctUZspKxdjeFvp493MJHaAl0VY3d4mK+7Q8nNmbRJ1srxmziJ9+Hep064scH ll3EVLFNWWI+zGWA8U8BuBC0HAKKNGWpOBNz+E7c0YoJOT0zGmrVnyTw8iwENtly1Ng5 Ks/ytH07U0CJXnvymKXVR820AQV/1yoyReVKAw6SA6A/CVvLty/AlatGzPXVcYfbtrDn LXf0OehA1Mm54zR90dGYW4LsBs7vZDovCJQeroSjweBJj/JJUFWImJ4ILQvXkvA46/5P +G9iX9gseu575f2o219eemRdQK4IrcqsAkNR0mcw+SP86oJHsvhb5obt4rE2gyEO+JAt VKbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CUdQfvRX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id nu10-20020a17090b1b0a00b002772ff87ee4si11126581pjb.82.2023.10.24.02.29.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:29:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CUdQfvRX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 6D8478079ADF; Tue, 24 Oct 2023 02:29:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234103AbjJXJ3H (ORCPT + 26 others); Tue, 24 Oct 2023 05:29:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234149AbjJXJ2c (ORCPT ); Tue, 24 Oct 2023 05:28:32 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C726E173C; Tue, 24 Oct 2023 02:28:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139682; x=1729675682; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zx+TTV+xgsnirHp9g41dGRTJTzQ2ajkH0rygD6gjLLQ=; b=CUdQfvRX2X/hItp7G/jF7owiQcQKb96rCkatcicBTFVAtxypO4I7Pk/J QR7xqImYymBHIwjLFjbiPk2MmYvJjgHdZ4Xm/XFG/DIc/vj67/pseSIK7 c/s91MfSFMTx9C7rqejc3G4JjjDxArpv0xbEGnyK1uhEWSDwrrL2mCwdY BKFwGlxt9l3miUoziXWeR6Bw6CtLh5GicGT6ZaSsffy6pguIU697jCiM3 aWP9HDgl4xgyFuy+NGK5MS7Qa9+X1GYfbjvbH8ou9VwmZTxa1V3x8qYVa cFp0Yg0sceRCZo8C7HM9ZgJf43YXP3cDJfwRCLDrU1bjGYSPJCNYHYgTc A==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="8570184" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="8570184" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:27:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="6112288" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:26:35 -0700 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 08/24] selftests/resctrl: Split show_cache_info() to test specific and generic parts Date: Tue, 24 Oct 2023 12:26:18 +0300 Message-Id: <20231024092634.7122-9-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 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 morse.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 (morse.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:29:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628597799544437 X-GMAIL-MSGID: 1780628597799544437 show_cache_info() calculates results and provides generic cache information. This makes it hard to alter pass/fail conditions. Separate the test specific checks into CAT and CMT test files and leave only the generic information part into show_cache_info(). Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 40 ++++------------------ tools/testing/selftests/resctrl/cat_test.c | 30 ++++++++++++++-- tools/testing/selftests/resctrl/cmt_test.c | 32 +++++++++++++++-- tools/testing/selftests/resctrl/resctrl.h | 6 ++-- 4 files changed, 65 insertions(+), 43 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index 299d9508221f..95489d4b42b7 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -267,43 +267,17 @@ int cat_val(struct resctrl_val_param *param, size_t span) } /* - * show_cache_info: show cache test result information - * @sum_llc_val: sum of LLC cache result data + * show_cache_info: show generic cache test information * @no_of_bits: number of bits - * @cache_span: cache span in bytes for CMT or in lines for CAT - * @max_diff: max difference - * @max_diff_percent: max difference percentage - * @num_of_runs: number of runs - * @platform: show test information on this platform - * @cmt: CMT test or CAT test - * - * Return: 0 on success. non-zero on failure. + * @avg_llc_val: avg of LLC cache result data + * @cache_span: cache span + * @lines: cache span in lines or bytes */ -int show_cache_info(unsigned long sum_llc_val, int no_of_bits, - size_t cache_span, unsigned long max_diff, - unsigned long max_diff_percent, unsigned long num_of_runs, - bool platform, bool cmt) +void show_cache_info(int no_of_bits, unsigned long avg_llc_val, + size_t cache_span, bool lines) { - unsigned long avg_llc_val = 0; - float diff_percent; - long avg_diff = 0; - int ret; - - avg_llc_val = sum_llc_val / num_of_runs; - avg_diff = (long)abs(cache_span - avg_llc_val); - diff_percent = ((float)cache_span - avg_llc_val) / cache_span * 100; - - ret = platform && abs((int)diff_percent) > max_diff_percent && - (cmt ? (abs(avg_diff) > max_diff) : true); - - ksft_print_msg("%s Check cache miss rate within %lu%%\n", - ret ? "Fail:" : "Pass:", max_diff_percent); - - ksft_print_msg("Percent diff=%d\n", abs((int)diff_percent)); ksft_print_msg("Number of bits: %d\n", no_of_bits); ksft_print_msg("Average LLC val: %lu\n", avg_llc_val); - ksft_print_msg("Cache span (%s): %zu\n", cmt ? "bytes" : "lines", + ksft_print_msg("Cache span (%s): %zu\n", !lines ? "bytes" : "lines", cache_span); - - return ret; } diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index e5861e7cba7e..32f6d612a3e7 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -41,6 +41,30 @@ static int cat_setup(struct resctrl_val_param *p) return ret; } +static int show_results_info(unsigned long sum_llc_val, int no_of_bits, + unsigned long cache_span, unsigned long max_diff, + unsigned long max_diff_percent, unsigned long num_of_runs, + bool platform) +{ + unsigned long avg_llc_val = 0; + float diff_percent; + int ret; + + avg_llc_val = sum_llc_val / num_of_runs; + diff_percent = ((float)cache_span - avg_llc_val) / cache_span * 100; + + ret = platform && abs((int)diff_percent) > max_diff_percent; + + ksft_print_msg("%s Check cache miss rate within %lu%%\n", + ret ? "Fail:" : "Pass:", max_diff_percent); + + ksft_print_msg("Percent diff=%d\n", abs((int)diff_percent)); + + show_cache_info(no_of_bits, avg_llc_val, cache_span, true); + + return ret; +} + static int check_results(struct resctrl_val_param *param, size_t span) { char *token_array[8], temp[512]; @@ -76,9 +100,9 @@ static int check_results(struct resctrl_val_param *param, size_t span) fclose(fp); no_of_bits = count_bits(param->mask); - return show_cache_info(sum_llc_perf_miss, no_of_bits, span / 64, - MAX_DIFF, MAX_DIFF_PERCENT, runs - 1, - get_vendor() == ARCH_INTEL, false); + return show_results_info(sum_llc_perf_miss, no_of_bits, span / 64, + MAX_DIFF, MAX_DIFF_PERCENT, runs - 1, + get_vendor() == ARCH_INTEL); } void cat_test_cleanup(void) diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c index e8997ff5bc04..702ea87cd473 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -27,6 +27,33 @@ static int cmt_setup(struct resctrl_val_param *p) return 0; } +static int show_results_info(unsigned long sum_llc_val, int no_of_bits, + unsigned long cache_span, unsigned long max_diff, + unsigned long max_diff_percent, unsigned long num_of_runs, + bool platform) +{ + unsigned long avg_llc_val = 0; + float diff_percent; + long avg_diff = 0; + int ret; + + avg_llc_val = sum_llc_val / num_of_runs; + avg_diff = (long)abs(cache_span - avg_llc_val); + diff_percent = ((float)cache_span - avg_llc_val) / cache_span * 100; + + ret = platform && abs((int)diff_percent) > max_diff_percent && + abs(avg_diff) > max_diff; + + ksft_print_msg("%s Check cache miss rate within %lu%%\n", + ret ? "Fail:" : "Pass:", max_diff_percent); + + ksft_print_msg("Percent diff=%d\n", abs((int)diff_percent)); + + show_cache_info(no_of_bits, avg_llc_val, cache_span, false); + + return ret; +} + static int check_results(struct resctrl_val_param *param, size_t span, int no_of_bits) { char *token_array[8], temp[512]; @@ -58,9 +85,8 @@ static int check_results(struct resctrl_val_param *param, size_t span, int no_of } fclose(fp); - return show_cache_info(sum_llc_occu_resc, no_of_bits, span, - MAX_DIFF, MAX_DIFF_PERCENT, runs - 1, - true, true); + return show_results_info(sum_llc_occu_resc, no_of_bits, span, + MAX_DIFF, MAX_DIFF_PERCENT, runs - 1, true); } void cmt_test_cleanup(void) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 56afdc190727..c7655714b23f 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -115,10 +115,8 @@ unsigned int count_bits(unsigned long n); void cmt_test_cleanup(void); int get_core_sibling(int cpu_no); int measure_llc_resctrl(struct resctrl_val_param *param, int bm_pid); -int show_cache_info(unsigned long sum_llc_val, int no_of_bits, - size_t cache_span, unsigned long max_diff, - unsigned long max_diff_percent, unsigned long num_of_runs, - bool platform, bool cmt); +void show_cache_info(int no_of_bits, unsigned long avg_llc_val, + size_t cache_span, bool lines); /* * cache_size - Calculate the size of a cache portion From patchwork Tue Oct 24 09:26:19 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: 157342 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1821257vqx; Tue, 24 Oct 2023 02:32:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxPrtos5FvPVslwfNi/HCA0Au1N27D2j8AxxVnk2Yh9K+nE9CBTo0pESxqFoq/UlQR+TTo X-Received: by 2002:a05:6a00:24d1:b0:6be:2720:16a5 with SMTP id d17-20020a056a0024d100b006be272016a5mr15017040pfv.33.1698139941419; Tue, 24 Oct 2023 02:32:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139941; cv=none; d=google.com; s=arc-20160816; b=wEZkM/HXHInaJIht7uLiU/TETVSf3gW+ZZgHSqh4TaIdAX9jVRzT2fBcIacIYZRgzb OaDGuGbMBtykKNjC2bvrTtVse/4fHjlQjIHD0Bo+s5I++1voCQ40fP5KLx9GmPip5U7n V/KXjSwsLVPfVgUxnWfAbMBbAThgxBIlrmBNRvT6XFBoCXEVZBr4VloJ0a4rrXi2v0F2 Y9/2BzHmawpfZAhkB8JovjFgiPGASfkFenZW5oMFTAfbKpoSYYI2g8PKiihDpkfwGIDE bKdVZO5zkvDhJghjq3VglhYcs3gUiwM5uO7OpT4vbqFcyeXB/jFpA5QyeOVcZYuO6Dut ILfA== 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=izMfrYYs0qBcH0HlPsA5TpYzAJOwtrm3z/x8W22L0ls=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=Kr4Mbe7mT4HSGP34QScRUkYG/ekCXyR1G2AHUR/XDfQXuSAegGkVmxpOVvK/G9p3+e U9F9rhcN2YMiL0YhDDcXdSiLQuo08ChIwhnzrDOQ/h7vr9Z+FVI1muaexunBdgiKXnbi FPV0oBzcB08vrIaxqYjtTvHddMg5YN4yPwyaTTGkel0bMwMC0WLQKMWqEymZ8fJdljc1 Z7C8IuM9ETo2N4FbFGoCmMfxkal/UXk06SOkhZuDBQXVtFuksUKkKfpTcYcyRwHx+Bqz hCJa2SvIpQl6k4o0q9w6SvFif8HUvuCEhjPtCzE854qNsVTodpNIYgziy7JmdtFH8QQ/ wITA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cEDWO9Wq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id p23-20020a639517000000b005b43f17562fsi8055882pgd.266.2023.10.24.02.32.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:32:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cEDWO9Wq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id DE62A808BCAF; Tue, 24 Oct 2023 02:32:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233721AbjJXJcF (ORCPT + 26 others); Tue, 24 Oct 2023 05:32:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234200AbjJXJ2e (ORCPT ); Tue, 24 Oct 2023 05:28:34 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5564C198B; Tue, 24 Oct 2023 02:28:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139685; x=1729675685; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xQ4Iamz+/JmjBX3VE4Wk06Rysb+pZgl6ZLrtubjENSo=; b=cEDWO9Wq6P+6UOptHf4mtm620h3vYsQOXc8JiHv+G4Q8iW+1k6yCVmdh dK/sW7vJyr36LhHC+7YHL2hcG6JAdnw3PqE1ZTamHWyKw/qZFuMCS57I3 Vv7KF03slkuwO/1DikChzA7Os5AYPV874DE6/N1WbTD+bwuCCIwggYGJu BMM9M5w5CtVMzK18sULRcdRcKGiA7JWQlnnF5y1fSbZlncp/s1OxzHVUY uoOMwQbit90KxJd4hvViCohWcU3zIj36Sgn/n0VzotcwtUPZI/afDWLku KTdYeKklUOieN2d3CY1FAi9K5t2VIgEN933c93e8FYUuz6lN2qXZFGdoo Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="451251781" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="451251781" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:28:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="1089785972" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="1089785972" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:28:00 -0700 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 09/24] selftests/resctrl: Remove unnecessary __u64 -> unsigned long conversion Date: Tue, 24 Oct 2023 12:26:19 +0300 Message-Id: <20231024092634.7122-10-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 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 howler.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 (howler.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:32:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628787288570693 X-GMAIL-MSGID: 1780628787288570693 Perf counters are __u64 but the code converts them to unsigned long before printing them out. Remove unnecessary type conversion and the potential loss of meaningful bits due to different sizes of types. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 21 ++++++++------------- tools/testing/selftests/resctrl/cat_test.c | 8 ++++---- tools/testing/selftests/resctrl/resctrl.h | 3 +-- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index 95489d4b42b7..d39ef4eebc37 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -84,9 +84,8 @@ static int reset_enable_llc_perf(pid_t pid, int cpu_no) * * Return: =0 on success. <0 on failure. */ -static int get_llc_perf(unsigned long *llc_perf_miss) +static int get_llc_perf(__u64 *llc_perf_miss) { - __u64 total_misses; int ret; /* Stop counters after one span to get miss rate */ @@ -99,8 +98,7 @@ static int get_llc_perf(unsigned long *llc_perf_miss) return -1; } - total_misses = rf_cqm.values[0].value; - *llc_perf_miss = total_misses; + *llc_perf_miss = rf_cqm.values[0].value; return 0; } @@ -148,14 +146,12 @@ static int get_llc_occu_resctrl(unsigned long *llc_occupancy) * * Return: 0 on success. non-zero on failure. */ -static int print_results_cache(char *filename, int bm_pid, - unsigned long llc_value) +static int print_results_cache(char *filename, int bm_pid, __u64 llc_value) { FILE *fp; if (strcmp(filename, "stdio") == 0 || strcmp(filename, "stderr") == 0) { - printf("Pid: %d \t LLC_value: %lu\n", bm_pid, - llc_value); + printf("Pid: %d \t LLC_value: %llu\n", bm_pid, llc_value); } else { fp = fopen(filename, "a"); if (!fp) { @@ -163,7 +159,7 @@ static int print_results_cache(char *filename, int bm_pid, return errno; } - fprintf(fp, "Pid: %d \t llc_value: %lu\n", bm_pid, llc_value); + fprintf(fp, "Pid: %d \t llc_value: %llu\n", bm_pid, llc_value); fclose(fp); } @@ -172,7 +168,7 @@ static int print_results_cache(char *filename, int bm_pid, static int measure_llc_perf(struct resctrl_val_param *param, int bm_pid) { - unsigned long llc_perf_miss = 0; + __u64 llc_perf_miss = 0; int ret; /* @@ -273,11 +269,10 @@ int cat_val(struct resctrl_val_param *param, size_t span) * @cache_span: cache span * @lines: cache span in lines or bytes */ -void show_cache_info(int no_of_bits, unsigned long avg_llc_val, - size_t cache_span, bool lines) +void show_cache_info(int no_of_bits, __u64 avg_llc_val, size_t cache_span, bool lines) { ksft_print_msg("Number of bits: %d\n", no_of_bits); - ksft_print_msg("Average LLC val: %lu\n", avg_llc_val); + ksft_print_msg("Average LLC val: %llu\n", avg_llc_val); ksft_print_msg("Cache span (%s): %zu\n", !lines ? "bytes" : "lines", cache_span); } diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 32f6d612a3e7..2106cc3601d9 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -41,12 +41,12 @@ static int cat_setup(struct resctrl_val_param *p) return ret; } -static int show_results_info(unsigned long sum_llc_val, int no_of_bits, +static int show_results_info(__u64 sum_llc_val, int no_of_bits, unsigned long cache_span, unsigned long max_diff, unsigned long max_diff_percent, unsigned long num_of_runs, bool platform) { - unsigned long avg_llc_val = 0; + __u64 avg_llc_val = 0; float diff_percent; int ret; @@ -68,7 +68,7 @@ static int show_results_info(unsigned long sum_llc_val, int no_of_bits, static int check_results(struct resctrl_val_param *param, size_t span) { char *token_array[8], temp[512]; - unsigned long sum_llc_perf_miss = 0; + __u64 sum_llc_perf_miss = 0; int runs = 0, no_of_bits = 0; FILE *fp; @@ -93,7 +93,7 @@ static int check_results(struct resctrl_val_param *param, size_t span) * setup transition phase. */ if (runs > 0) - sum_llc_perf_miss += strtoul(token_array[3], NULL, 0); + sum_llc_perf_miss += strtoull(token_array[3], NULL, 0); runs++; } diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index c7655714b23f..033c49784581 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -115,8 +115,7 @@ unsigned int count_bits(unsigned long n); void cmt_test_cleanup(void); int get_core_sibling(int cpu_no); int measure_llc_resctrl(struct resctrl_val_param *param, int bm_pid); -void show_cache_info(int no_of_bits, unsigned long avg_llc_val, - size_t cache_span, bool lines); +void show_cache_info(int no_of_bits, __u64 avg_llc_val, size_t cache_span, bool lines); /* * cache_size - Calculate the size of a cache portion From patchwork Tue Oct 24 09:26:20 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: 157328 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1819951vqx; Tue, 24 Oct 2023 02:29:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGY78DrI245dqBTBmvHvYgWJ1TH4RdjkQfZLqSfh4Udz71p0OMzwiz+4AoMnVkIuYwNRu0d X-Received: by 2002:a05:6359:6182:b0:168:d4c3:3447 with SMTP id sb2-20020a056359618200b00168d4c33447mr5970890rwb.1.1698139759595; Tue, 24 Oct 2023 02:29:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139759; cv=none; d=google.com; s=arc-20160816; b=wbDJnl0i1gsHnHp9q/Fl8yPnFvpJCjU/a2gLjsW0XLztnYQRfyYWVapUryNHToMxwC jXQAaOAHmeGZEJYnS5vcC9pZLTMSUg7VwcCaJPB+C3IePVxDkeP3fGPmiypLKlIiVxzP 9k0wOXD+eCPuKzJIkzQjxxcs/yIJxgmlLIDbzJUNva3l0EJouYkmD3eQuS5Gea7QSclg 3q+Ig8lAAzQER7InupLgMVs5WvGw34/mumMZQWYvn1iK83iaO0hBbiwRA/1AsOvudBHL cY4Q36m7qJC+b5AEJ/7nzbjJC0o6gxBvSgU9OyslEeRBw6F0RBO5NJZ7O2zw7dNHKjNd Jnmw== 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=2At1K2VcA9T51MCv9xgM3+4gmbU8tClz+AXeho67RWE=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=qDbZ6nUsP0KWyLKo9UtDv/zSH5xxnWbj5fhhYHF5IakAfEL9sDTYfylSPFbrF1LHU+ uJQHfsfdDQmkMI2WkwV8jdWjceU0552akKHI0Y8sTyuvROXv2II/kHqfwz/o3Alr+i6I pCGSYZ+uxXEujmkyEfW8B5tNp0D1bFrcTi5SpSZxVM5mFNhTc158bD+Vm1VRlPTC3eeI HAn94NogSay+NY3sfyOOT8snKM3wDkr0IhigjY3K2pcqh3LZRdtSQ2HePKwGaiBqBVfh Y1AQnN3QFWhCZ2yHWfhFoLC9hL60XuSt4qR2DDri239YPxePUCzyO1WVp+smhxnDEF98 iTSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=oKSi2gAJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id fa8-20020a056a002d0800b006be0559d029si8211110pfb.109.2023.10.24.02.29.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:29:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=oKSi2gAJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id D889D80309E8; Tue, 24 Oct 2023 02:29:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234209AbjJXJ3J (ORCPT + 26 others); Tue, 24 Oct 2023 05:29:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234320AbjJXJ2z (ORCPT ); Tue, 24 Oct 2023 05:28:55 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DC5019A7; Tue, 24 Oct 2023 02:28:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139693; x=1729675693; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8FKUtvRYnvzaa3K/57t7W2HJhIgi4sQgl8n8AtOFcZo=; b=oKSi2gAJZtd5PyXGojM8jAB8MMhuwDDeVhYcVlt5Iq1NGDJO4UhREKI0 Ss6HQmdeDKCynhn3TDn9HVoVwVtECixm1C0sWZj8TjQL7Ea/3FjuJG8F0 opAkW2ugpEHkB5gDoo1SH08QFHbga705LiWESMihSOSDGhpqTXhacEsy+ N8xNZVqJPGYPks64Mh5Yf2ddt6kIBiIJMOXo1kTDRRS5W0LabTFHfNL5Y fvkl/s8ee5/1PRX1ChM1V05AL96eLUMwaDkxAQY7TwOxrsRs+AdyoKRwX Bw8Gzx4TTdH+qnJV2ZiblY9sEFVmSwXSHa8qU+fTrigVHnXR3+Djqx3xX w==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="386829532" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="386829532" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:28:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="828754659" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="828754659" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:28:09 -0700 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 10/24] selftests/resctrl: Remove nested calls in perf event handling Date: Tue, 24 Oct 2023 12:26:20 +0300 Message-Id: <20231024092634.7122-11-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 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:29:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628596527739701 X-GMAIL-MSGID: 1780628596527739701 Perf event handling has functions that are the sole caller of another perf event handling related function: - reset_enable_llc_perf() calls perf_event_open_llc_miss() - reset_enable_llc_perf() calls ioctl_perf_event_ioc_reset_enable() - measure_llc_perf() calls get_llc_perf() Remove the extra layer of calls to make the code easier to follow by moving the code into the calling function. In addition, converts print_results_cache() unsigned long parameter to __u64 that matches the type coming from perf. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 86 +++++++------------------ 1 file changed, 25 insertions(+), 61 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index d39ef4eebc37..208af1ecae28 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -29,25 +29,6 @@ static void initialize_perf_event_attr(void) pea_llc_miss.disabled = 1; } -static void ioctl_perf_event_ioc_reset_enable(void) -{ - ioctl(fd_lm, PERF_EVENT_IOC_RESET, 0); - ioctl(fd_lm, PERF_EVENT_IOC_ENABLE, 0); -} - -static int perf_event_open_llc_miss(pid_t pid, int cpu_no) -{ - fd_lm = perf_event_open(&pea_llc_miss, pid, cpu_no, -1, - PERF_FLAG_FD_CLOEXEC); - if (fd_lm == -1) { - perror("Error opening leader"); - ctrlc_handler(0, NULL, NULL); - return -1; - } - - return 0; -} - static void initialize_llc_perf(void) { memset(&pea_llc_miss, 0, sizeof(struct perf_event_attr)); @@ -63,42 +44,16 @@ static void initialize_llc_perf(void) static int reset_enable_llc_perf(pid_t pid, int cpu_no) { - int ret = 0; - - ret = perf_event_open_llc_miss(pid, cpu_no); - if (ret < 0) - return ret; - - /* Start counters to log values */ - ioctl_perf_event_ioc_reset_enable(); - - return 0; -} - -/* - * get_llc_perf: llc cache miss through perf events - * @llc_perf_miss: LLC miss counter that is filled on success - * - * Perf events like HW_CACHE_MISSES could be used to validate number of - * cache lines allocated. - * - * Return: =0 on success. <0 on failure. - */ -static int get_llc_perf(__u64 *llc_perf_miss) -{ - int ret; - - /* Stop counters after one span to get miss rate */ - - ioctl(fd_lm, PERF_EVENT_IOC_DISABLE, 0); - - ret = read(fd_lm, &rf_cqm, sizeof(struct read_format)); - if (ret == -1) { - perror("Could not get llc misses through perf"); + fd_lm = perf_event_open(&pea_llc_miss, pid, cpu_no, -1, PERF_FLAG_FD_CLOEXEC); + if (fd_lm == -1) { + perror("Error opening leader"); + ctrlc_handler(0, NULL, NULL); return -1; } - *llc_perf_miss = rf_cqm.values[0].value; + /* Start counters to log values */ + ioctl(fd_lm, PERF_EVENT_IOC_RESET, 0); + ioctl(fd_lm, PERF_EVENT_IOC_ENABLE, 0); return 0; } @@ -166,20 +121,29 @@ static int print_results_cache(char *filename, int bm_pid, __u64 llc_value) return 0; } +/* + * measure_llc_perf: measure perf events + * @bm_pid: child pid that runs benchmark + * + * Measure things like cache misses from perf events. + * + * Return: =0 on success. <0 on failure. + */ static int measure_llc_perf(struct resctrl_val_param *param, int bm_pid) { - __u64 llc_perf_miss = 0; int ret; - /* - * Measure cache miss from perf. - */ - ret = get_llc_perf(&llc_perf_miss); - if (ret < 0) - return ret; + /* Stop counters after one span to get miss rate */ + ioctl(fd_lm, PERF_EVENT_IOC_DISABLE, 0); - ret = print_results_cache(param->filename, bm_pid, llc_perf_miss); - return ret; + ret = read(fd_lm, &rf_cqm, sizeof(struct read_format)); + close(fd_lm); + if (ret == -1) { + perror("Could not get perf value"); + return -1; + } + + return print_results_cache(param->filename, bm_pid, rf_cqm.values[0].value); } int measure_llc_resctrl(struct resctrl_val_param *param, int bm_pid) From patchwork Tue Oct 24 09:26:21 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: 157335 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1820797vqx; Tue, 24 Oct 2023 02:31:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHX4AABAqkxqmK1CyOlROevYa+xKS2zW/F6Q/1UfArW4PPNL4MxM8U4dsasgUIGzQ2MZwP/ X-Received: by 2002:a17:90a:1996:b0:27c:fa10:fc82 with SMTP id 22-20020a17090a199600b0027cfa10fc82mr8846106pji.28.1698139871936; Tue, 24 Oct 2023 02:31:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139871; cv=none; d=google.com; s=arc-20160816; b=0O9VEXYUQ3bjtDQH9mDtYJz1rfMtzmAui5vzbSra9UZHnWNq3EgabaP8kJzZvVmt9l 92jSB4hfI8lqeqLYjPP3jO+lL/I7c5bO9PKc0hY51Yb3ZRitgrqTa/dUOHJpeg/6a4r4 VpqQQlCI7TdQFZDrDik4MMaV4pcJNJ69dosmXoi3AycRCQM6nPCekgJfDHix0xXqZKpo yKkF/sFfFS0k1z9xUHHLXWEoJZrqQBOczbvF5T0HmUNsVYNEXAibvK76Disfe1GuEmG3 JV4QMi55UhlQAffupL9XOAJ4PHe9g6b2LfsGJ/JVQNv1+lLL1oqWbBjKdBc61Eg1C0cR uKVA== 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=yPA0OacYfBWPZxX+ayIuiK4blTvY+TrdE5zRPbL75UY=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=OOVLPwnQz5sVys/1Sid6PE3+WdORa2HyRp+i3weGtO/OtTxKD+UeFuNRn8kPH5XaZK +aoOQuvkU7D2rLw9/YLA1vA9Zt1W/yONlYdgpkqF7D2cJjrXFR63SMMUsdz02u9LDvmn D2fTcHSe49MCUEfc4AL/+4Hr69LE2bnEqPGkqGB+kI7cx72MTWXzcD/uvbY4tikRNyYI ffS0DP9QDtA6CulSVgO0nHJaIvNpK2lPqZa1Bv3NJzhGOK5xdsf6aLEOBPW0eLtKVTXM uqcXSuTT6SgU8djFNrNgjUtIJqQdMsgRiyuj9q9e3prsEjlQZkHfbbl7rA6NFBCaoAJj AVBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="C8In/bdk"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id s2-20020a170902ea0200b001c77674ea97si8250591plg.423.2023.10.24.02.31.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:31:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="C8In/bdk"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 8206D808577E; Tue, 24 Oct 2023 02:30:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234276AbjJXJ3U (ORCPT + 26 others); Tue, 24 Oct 2023 05:29:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234404AbjJXJ3B (ORCPT ); Tue, 24 Oct 2023 05:29:01 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 883F81BF6; Tue, 24 Oct 2023 02:28:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139701; x=1729675701; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5TJ7qV+EW+iJ9ZdFNVeU3a2hKS++KMxkkRhcp+n3/fI=; b=C8In/bdkTbVNTYjrBrv2zquYbqHWiYNDvMaWpJxfHqNM//1LDQp24Xm4 ninDaDRoMrCQsy4WQxW0TGEzbZv42m1wX5gEhDMKy9Lhbvag2zFvSyvga gelF8RjL0JzmmH8r2qvAQY90Mg0GuGxQjXG9Kcee4ScYCBLQ1AGXpY2kN Sc7zxXfqawgPj5xO9MFEkhn9WwVbzW1B0cfxN1/JAes1BzCef7HJ9vIwW /QHhTnqDiUsL6hvvEQSOjcE5GWiUm2gHK3hlgkg75YqzIjnimQRJ/KYNY 7vpaB7N0DEzcuRTEzWVaJ5tGNyIg9KQ+Tgimw/rqk/k4JjJmNoU6blQUi w==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="386829543" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="386829543" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:28:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="828754667" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="828754667" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:28:17 -0700 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 11/24] selftests/resctrl: Consolidate naming of perf event related things Date: Tue, 24 Oct 2023 12:26:21 +0300 Message-Id: <20231024092634.7122-12-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 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 pete.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 (pete.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:30:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628714330473608 X-GMAIL-MSGID: 1780628714330473608 Naming for perf event related functions, types, and variables is currently inconsistent. Make struct read_format and all functions related to perf events start with perf_event. Adjust variable names towards the same direction but use shorter names for variables where appropriate (pe prefix). Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 46 ++++++++++++------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index 208af1ecae28..a70ace82e76e 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -3,7 +3,7 @@ #include #include "resctrl.h" -struct read_format { +struct perf_event_read { __u64 nr; /* The number of events */ struct { __u64 value; /* The value of the event */ @@ -11,11 +11,11 @@ struct read_format { }; static struct perf_event_attr pea_llc_miss; -static struct read_format rf_cqm; -static int fd_lm; +static struct perf_event_read pe_read; +static int pe_fd; char llc_occup_path[1024]; -static void initialize_perf_event_attr(void) +static void perf_event_attr_initialize(void) { pea_llc_miss.type = PERF_TYPE_HARDWARE; pea_llc_miss.size = sizeof(struct perf_event_attr); @@ -29,31 +29,31 @@ static void initialize_perf_event_attr(void) pea_llc_miss.disabled = 1; } -static void initialize_llc_perf(void) +static void perf_event_initialize(void) { memset(&pea_llc_miss, 0, sizeof(struct perf_event_attr)); - memset(&rf_cqm, 0, sizeof(struct read_format)); + memset(&pe_read, 0, sizeof(struct perf_event_read)); /* Initialize perf_event_attr structures for HW_CACHE_MISSES */ - initialize_perf_event_attr(); + perf_event_attr_initialize(); pea_llc_miss.config = PERF_COUNT_HW_CACHE_MISSES; - rf_cqm.nr = 1; + pe_read.nr = 1; } -static int reset_enable_llc_perf(pid_t pid, int cpu_no) +static int perf_event_reset_enable(pid_t pid, int cpu_no) { - fd_lm = perf_event_open(&pea_llc_miss, pid, cpu_no, -1, PERF_FLAG_FD_CLOEXEC); - if (fd_lm == -1) { + pe_fd = perf_event_open(&pea_llc_miss, pid, cpu_no, -1, PERF_FLAG_FD_CLOEXEC); + if (pe_fd == -1) { perror("Error opening leader"); ctrlc_handler(0, NULL, NULL); return -1; } /* Start counters to log values */ - ioctl(fd_lm, PERF_EVENT_IOC_RESET, 0); - ioctl(fd_lm, PERF_EVENT_IOC_ENABLE, 0); + ioctl(pe_fd, PERF_EVENT_IOC_RESET, 0); + ioctl(pe_fd, PERF_EVENT_IOC_ENABLE, 0); return 0; } @@ -122,28 +122,28 @@ static int print_results_cache(char *filename, int bm_pid, __u64 llc_value) } /* - * measure_llc_perf: measure perf events + * perf_event_measure: measure perf events * @bm_pid: child pid that runs benchmark * * Measure things like cache misses from perf events. * * Return: =0 on success. <0 on failure. */ -static int measure_llc_perf(struct resctrl_val_param *param, int bm_pid) +static int perf_event_measure(struct resctrl_val_param *param, int bm_pid) { int ret; /* Stop counters after one span to get miss rate */ - ioctl(fd_lm, PERF_EVENT_IOC_DISABLE, 0); + ioctl(pe_fd, PERF_EVENT_IOC_DISABLE, 0); - ret = read(fd_lm, &rf_cqm, sizeof(struct read_format)); - close(fd_lm); + ret = read(pe_fd, &pe_read, sizeof(struct perf_event_read)); + close(pe_fd); if (ret == -1) { perror("Could not get perf value"); return -1; } - return print_results_cache(param->filename, bm_pid, rf_cqm.values[0].value); + return print_results_cache(param->filename, bm_pid, pe_read.values[0].value); } int measure_llc_resctrl(struct resctrl_val_param *param, int bm_pid) @@ -192,7 +192,7 @@ int cat_val(struct resctrl_val_param *param, size_t span) if (ret) return ret; - initialize_llc_perf(); + perf_event_initialize(); /* Test runs until the callback setup() tells the test to stop. */ while (1) { @@ -203,7 +203,7 @@ int cat_val(struct resctrl_val_param *param, size_t span) } if (ret < 0) break; - ret = reset_enable_llc_perf(bm_pid, param->cpu_no); + ret = perf_event_reset_enable(bm_pid, param->cpu_no); if (ret) break; @@ -214,7 +214,7 @@ int cat_val(struct resctrl_val_param *param, size_t span) } sleep(1); - ret = measure_llc_perf(param, bm_pid); + ret = perf_event_measure(param, bm_pid); if (ret) goto pe_close; } @@ -222,7 +222,7 @@ int cat_val(struct resctrl_val_param *param, size_t span) return ret; pe_close: - close(fd_lm); + close(pe_fd); return ret; } From patchwork Tue Oct 24 09:26:22 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: 157331 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1820134vqx; Tue, 24 Oct 2023 02:29:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFiH0SlPHmSvzkzGPU2IyAD+PoGirm8/ExIwahPCAHd2THb1Hdr7IFuKs4ZBTHicFrAKpM8 X-Received: by 2002:a05:6a20:e127:b0:160:83e1:712f with SMTP id kr39-20020a056a20e12700b0016083e1712fmr2675065pzb.23.1698139788075; Tue, 24 Oct 2023 02:29:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139788; cv=none; d=google.com; s=arc-20160816; b=ANVJvsG/rwgGM7/iOXlZqmX+pHbbe/sqHaJhm9nOlWfQ1nYuxSDR8xgSN+ORZL6nEi URa74lQOsChvmgYDHMsUbD9tmU2iZHapR9bqeuhkDvFV6+MPDofw6pjHGyyB+1KTzWnZ lKlMOr050OCW8J8B6M2QvTNexwW+yfuPe+XAT8j8lX8rgWexgmnfOj338tpn+gTNAoAh HoiUuXmr2IxI1Iyrhpb5dlcZX4nLqpb1JalFUruEHJzQelOU5/fe8qqaedTCcDEf7VsB fEBOopS1glXr52N1ywLsqYlrgLvCg8ar5SCIlbPEmqd7JsolmoARi52vAGrctPtbJ+jt DgsQ== 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=xZf6SFbjJFrWttcjIOgs5F34vcyDhJ6oqo0tLlfAacQ=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=kkVvRU75+B/yEohKGLu6IyMFXXm75SBGvo3+QWVXIaZ1NyvzjUNkdtwQH6GXy5Tys1 2BMf/Jc7qEIR+laun9Y8uNHHDsxxTNoEk6203zfMUoMhkCuNi0E3Le12xa6/qYJDdskm HvrBWDKDCBCDPH25X/pesZVHCgGpalPqEGIcGsaMpNr1RBdXXp0yQ9ywNPu+lGBdr22+ 5o9r4/puGUX54k51s5oVxBJ49eAee9iogcJ6p2Jnj5EBj2cFcd4I/HaOgQPp2zD0grgA pCvzrpdnosUA7lAoDEp3I7XKvBnwHud/C935Stbq8P/2Iz+Qe2E1pRcHX8QDR9LAS0Ju 5iEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HB2EnfV3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id i26-20020aa796fa000000b006bf8421f0e7si4161552pfq.211.2023.10.24.02.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:29:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HB2EnfV3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 4BA6380BD752; Tue, 24 Oct 2023 02:29:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234197AbjJXJ3e (ORCPT + 26 others); Tue, 24 Oct 2023 05:29:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234134AbjJXJ3H (ORCPT ); Tue, 24 Oct 2023 05:29:07 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE2B81FC1; Tue, 24 Oct 2023 02:28:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139709; x=1729675709; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CwVbuYCXjjmS1wYgCO7ZGGdahtlDKGYkkf8/AfncZ54=; b=HB2EnfV3CRcRQ3WcLzJJ/TUGJKZK4Ccxx3yMN4HcovuhVIUDTyd9vzh4 VlF7gma3NuLTB6+JNbLdsjaS4a7WA4RndDHw0EcJWCAezWgKKVVUUZdH3 fpoW7ZU/mjrLIP8kPEMcCA6N9iPLyvuwwZBryKfsOPmf6VqBXptfMfPFB h/D5oY5SxzedlzuaKLjOETpYpDs6BltDmfrXEzciKimgtmSlOyxIj/6JT C30HMOPL6NMJihXyK8s/62liOcCoI2KI1hEPvXhqQf3qP4zzBWfzTtVph cbXUJFstPHQd9t1P1sGmKA0jGNWA5aF3KGW2SsG6CMfZBhYfT2hE5E1sW Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="386829566" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="386829566" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:28:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="828754682" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="828754682" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:28:25 -0700 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 12/24] selftests/resctrl: Improve perf init Date: Tue, 24 Oct 2023 12:26:22 +0300 Message-Id: <20231024092634.7122-13-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 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 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]); Tue, 24 Oct 2023 02:29:45 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628626531387663 X-GMAIL-MSGID: 1780628626531387663 struct perf_event_attr initialization is spread into perf_event_initialize() and perf_event_attr_initialize() and setting ->config is hardcoded by the deepest level. perf_event_attr init belongs to perf_event_attr_initialize() so move it entirely there. Rename the other function perf_event_initialized_read_format(). Call each init function directly from the test as they will take different parameters (especially tue after the perf related global variables are moved to local variables). Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index a70ace82e76e..a84679a4ac0c 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -15,8 +15,9 @@ static struct perf_event_read pe_read; static int pe_fd; char llc_occup_path[1024]; -static void perf_event_attr_initialize(void) +static void perf_event_attr_initialize(__u64 config) { + memset(&pea_llc_miss, 0, sizeof(struct perf_event_attr)); pea_llc_miss.type = PERF_TYPE_HARDWARE; pea_llc_miss.size = sizeof(struct perf_event_attr); pea_llc_miss.read_format = PERF_FORMAT_GROUP; @@ -27,18 +28,12 @@ static void perf_event_attr_initialize(void) pea_llc_miss.inherit = 1; pea_llc_miss.exclude_guest = 1; pea_llc_miss.disabled = 1; + pea_llc_miss.config = config; } -static void perf_event_initialize(void) +static void perf_event_initialize_read_format(void) { - memset(&pea_llc_miss, 0, sizeof(struct perf_event_attr)); memset(&pe_read, 0, sizeof(struct perf_event_read)); - - /* Initialize perf_event_attr structures for HW_CACHE_MISSES */ - perf_event_attr_initialize(); - - pea_llc_miss.config = PERF_COUNT_HW_CACHE_MISSES; - pe_read.nr = 1; } @@ -192,7 +187,8 @@ int cat_val(struct resctrl_val_param *param, size_t span) if (ret) return ret; - perf_event_initialize(); + perf_event_attr_initialize(PERF_COUNT_HW_CACHE_MISSES); + perf_event_initialize_read_format(); /* Test runs until the callback setup() tells the test to stop. */ while (1) { From patchwork Tue Oct 24 09:26:23 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: 157332 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1820165vqx; Tue, 24 Oct 2023 02:29:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEqgrxQ/IUXTcbAuDFcBP3dGXFNQWQmCWpbCh1BwZMdl51TUuSDiSxY+bEDJm/TMWTNjvH X-Received: by 2002:a05:6a00:986:b0:68f:d44c:22f8 with SMTP id u6-20020a056a00098600b0068fd44c22f8mr16599945pfg.1.1698139793516; Tue, 24 Oct 2023 02:29:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139793; cv=none; d=google.com; s=arc-20160816; b=W1F60LSUqawyZ9CsMl4l6L1BZ9lofK6tD6sAQLPEkDyjiljAmmupTFZ8ocRDNADA+l XM4fLlaCG9ZIFNx3AkeKC+EgBdmX9l087DQEig9xnPH8iT3YXP35Es1RJxNpnhjTskoc wGxeNIkWOOMwLNCKlK+v2VhvikdeCiN9hUXH2jLFglHx1o/dedAZynvdkMbbjgdcqKul IXOOHOdPZhyBQAj9MBm8Yvbx9mZbi6KKZVi0uGqXdhk9Jnm6A5qPQshGGLtuqmBGfGkJ 4vAle/sWEVQdkjquqvARNzlAX1KvD0jZB59mQcnqK5ZaZB4niGhIyhZ5+RDIxzBDaoMi usoQ== 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=TwjmGjsxa90dUiB+7rXt/0wX5rEEUI5//Z2TjtuHWEs=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=hg3/5l/JTPXRBFLf9YYTLSe7slsXoGxozfWOt/e6HGSfq3vpD961Zk01SUc60613/v TYS3wko1eEEqDJc2xc+BIg1kPG2/M2LhY7+h+KFP8gZA1suC05l+Ks09reEsbPC9V7jx 9beya/Dcu1Va1mMr48h0iSeGFv1ce847GGrKiVF6tPvy27VXps8lCiLEI+/O/y39gIr3 oF4ZL9H2pO5gRfr3fXaU3woKwrb+xn1+l0B5Am7qLMRBT67cp9IXncns4J2h0fR2UJon IMvto3IYiX3aAP7YiA8T+OmCN3h7BEP9Ks+/FUQHxL584PYxiU0JICQxGQbRezNeBlWs BJIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gkd7rTTj; 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 p16-20020a631e50000000b00584ca25959csi8049562pgm.540.2023.10.24.02.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:29:53 -0700 (PDT) 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=gkd7rTTj; 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 695C080BD766; Tue, 24 Oct 2023 02:29:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234195AbjJXJ3h (ORCPT + 26 others); Tue, 24 Oct 2023 05:29:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234237AbjJXJ3R (ORCPT ); Tue, 24 Oct 2023 05:29:17 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E8F01712; Tue, 24 Oct 2023 02:28:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139718; x=1729675718; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mFZKHeamlLZ+ycNh2qTCIXTUBPT6HqNoVKwHnY1lXRs=; b=gkd7rTTjEWHFcjw3PQX9QHOR96ApYFhZfM/48N+xOXLiHn73RFRl5RkH rk8xxg46uPqZBp+YDWqTPGmOyChal6ptypxcLIbbCb0voIENOiGCsQOm6 uA6FPdTtolC428z8R9XsANL+aR8BiKWzSp5cLVK5dHGTON50nA7kxVyyh pLnNxOEj9r5aQ5YNOcOvLn2af236un9f1DgvLldlhsWD4XHqdReAhI9c5 /Ez8AoBknJXY8hexvcqlBEF32HBALQ7bfYh6zWuk2J5LOtYAscJ4Q9UAI 6x6cGBIh+nkdGPmEBY8ltxVUm4bkfogauEuhpweZ2ATOBFQ36STRgRsYu Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="386829582" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="386829582" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:28:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="828754688" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="828754688" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:28:34 -0700 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 13/24] selftests/resctrl: Convert perf related globals to locals Date: Tue, 24 Oct 2023 12:26:23 +0300 Message-Id: <20231024092634.7122-14-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 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 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]); Tue, 24 Oct 2023 02:29:50 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628632435396015 X-GMAIL-MSGID: 1780628632435396015 Perf related variables pea_llc_miss, pe_read, and pe_fd are globals in cache.c. Convert them to locals for better scoping and make pea_llc_miss simpler by renaming it to pea. Make close(pe_fd) handling easier to understand by doing it inside cat_val(). Make also sizeof()s use safer way determine the right struct. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 69 ++++++++++++++----------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index a84679a4ac0c..a65e2e35c33c 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -10,36 +10,35 @@ struct perf_event_read { } values[2]; }; -static struct perf_event_attr pea_llc_miss; -static struct perf_event_read pe_read; -static int pe_fd; char llc_occup_path[1024]; -static void perf_event_attr_initialize(__u64 config) +static void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config) { - memset(&pea_llc_miss, 0, sizeof(struct perf_event_attr)); - pea_llc_miss.type = PERF_TYPE_HARDWARE; - pea_llc_miss.size = sizeof(struct perf_event_attr); - pea_llc_miss.read_format = PERF_FORMAT_GROUP; - pea_llc_miss.exclude_kernel = 1; - pea_llc_miss.exclude_hv = 1; - pea_llc_miss.exclude_idle = 1; - pea_llc_miss.exclude_callchain_kernel = 1; - pea_llc_miss.inherit = 1; - pea_llc_miss.exclude_guest = 1; - pea_llc_miss.disabled = 1; - pea_llc_miss.config = config; + memset(pea, 0, sizeof(*pea)); + pea->type = PERF_TYPE_HARDWARE; + pea->size = sizeof(struct perf_event_attr); + pea->read_format = PERF_FORMAT_GROUP; + pea->exclude_kernel = 1; + pea->exclude_hv = 1; + pea->exclude_idle = 1; + pea->exclude_callchain_kernel = 1; + pea->inherit = 1; + pea->exclude_guest = 1; + pea->disabled = 1; + pea->config = config; } -static void perf_event_initialize_read_format(void) +static void perf_event_initialize_read_format(struct perf_event_read *pe_read) { - memset(&pe_read, 0, sizeof(struct perf_event_read)); - pe_read.nr = 1; + memset(pe_read, 0, sizeof(*pe_read)); + pe_read->nr = 1; } -static int perf_event_reset_enable(pid_t pid, int cpu_no) +static int perf_event_reset_enable(struct perf_event_attr *pea, pid_t pid, int cpu_no) { - pe_fd = perf_event_open(&pea_llc_miss, pid, cpu_no, -1, PERF_FLAG_FD_CLOEXEC); + int pe_fd; + + pe_fd = perf_event_open(pea, pid, cpu_no, -1, PERF_FLAG_FD_CLOEXEC); if (pe_fd == -1) { perror("Error opening leader"); ctrlc_handler(0, NULL, NULL); @@ -50,7 +49,7 @@ static int perf_event_reset_enable(pid_t pid, int cpu_no) ioctl(pe_fd, PERF_EVENT_IOC_RESET, 0); ioctl(pe_fd, PERF_EVENT_IOC_ENABLE, 0); - return 0; + return pe_fd; } /* @@ -124,21 +123,21 @@ static int print_results_cache(char *filename, int bm_pid, __u64 llc_value) * * Return: =0 on success. <0 on failure. */ -static int perf_event_measure(struct resctrl_val_param *param, int bm_pid) +static int perf_event_measure(int pe_fd, struct perf_event_read *pe_read, + struct resctrl_val_param *param, int bm_pid) { int ret; /* Stop counters after one span to get miss rate */ ioctl(pe_fd, PERF_EVENT_IOC_DISABLE, 0); - ret = read(pe_fd, &pe_read, sizeof(struct perf_event_read)); - close(pe_fd); + ret = read(pe_fd, pe_read, sizeof(*pe_read)); if (ret == -1) { perror("Could not get perf value"); return -1; } - return print_results_cache(param->filename, bm_pid, pe_read.values[0].value); + return print_results_cache(param->filename, bm_pid, pe_read->values[0].value); } int measure_llc_resctrl(struct resctrl_val_param *param, int bm_pid) @@ -169,7 +168,10 @@ int cat_val(struct resctrl_val_param *param, size_t span) { int memflush = 1, operation = 0, ret = 0; char *resctrl_val = param->resctrl_val; + static struct perf_event_read pe_read; + struct perf_event_attr pea; pid_t bm_pid; + int pe_fd; if (strcmp(param->filename, "") == 0) sprintf(param->filename, "stdio"); @@ -187,8 +189,8 @@ int cat_val(struct resctrl_val_param *param, size_t span) if (ret) return ret; - perf_event_attr_initialize(PERF_COUNT_HW_CACHE_MISSES); - perf_event_initialize_read_format(); + perf_event_attr_initialize(&pea, PERF_COUNT_HW_CACHE_MISSES); + perf_event_initialize_read_format(&pe_read); /* Test runs until the callback setup() tells the test to stop. */ while (1) { @@ -199,9 +201,12 @@ int cat_val(struct resctrl_val_param *param, size_t span) } if (ret < 0) break; - ret = perf_event_reset_enable(bm_pid, param->cpu_no); - if (ret) + + pe_fd = perf_event_reset_enable(&pea, bm_pid, param->cpu_no); + if (pe_fd < 0) { + ret = -1; break; + } if (run_fill_buf(span, memflush, operation, true)) { fprintf(stderr, "Error-running fill buffer\n"); @@ -210,9 +215,11 @@ int cat_val(struct resctrl_val_param *param, size_t span) } sleep(1); - ret = perf_event_measure(param, bm_pid); + ret = perf_event_measure(pe_fd, &pe_read, param, bm_pid); if (ret) goto pe_close; + + close(pe_fd); } return ret; From patchwork Tue Oct 24 09:26:24 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: 157333 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1820225vqx; Tue, 24 Oct 2023 02:30:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEh1VDHTgLWZFiLRmQENnCxv0QGow6v1jIjsCrHurb0owLIKd130qcjPLwASfSGpZIUtYoC X-Received: by 2002:a05:6a20:e126:b0:17a:fe0a:c66c with SMTP id kr38-20020a056a20e12600b0017afe0ac66cmr3098555pzb.2.1698139801062; Tue, 24 Oct 2023 02:30:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139801; cv=none; d=google.com; s=arc-20160816; b=yjl/RmvWk4KlEaVJfKUM9u6e4NwLS67cSx8q+F6YpKSNo8Ow+Ldthd9JrYQ1XOh3nW +SwwQSZipPNbmHM+XNDQH6QhRztPKrwY1emc7cA4WxW015u1j54n1vtIQMwgckzf+OHK 8ep3z2FssuMCpLONoJMu8HUNCPeg5TiASAFZtvldoa6ZeSwoGDvVNgiqHsuUG2AXwAkM VXtCd7jp+41qrzmGHRwGhv+XI8NWJrHcp/2bOco08b40c18BNeqdrsmAJKkIlhEYpG19 I2oh7GCxpGEcvDipnLA4pWsKeTPRhSPslCe+bZBhKY332ajSEj5IgNf2fODrgRHBzBVh FzVg== 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=oZYc3IdepLlV8OqVIgSBP7Z+Cq6Buft65XztnQFAuYA=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=FNlbHZJ/7xzpY9EzhtZH8mdXzse6swy+7CwrP7MJ1wgjqXnnLMPbacfqSnTqRoryQz J2iGpxbD+KgtMAkmPhtM/aYk86PNSevrf3ieSLtS4rxO+7WBHcj1c2BujY9EFntpQsy8 YqQbCjC39cwP1ypzsHTa9yAyfQ7Yl9YR6yoUobHEHuyBvLQ0Kmc1VegViaAq4kpxsmGh I1xD/W720s4Kiedl9V9KGflh9xcUt+6sNRGvqzYVsqTDWZYt/DHj8XMgFLRSOkHs96fW c9+pdWTvWaUSx6TpISX+KXNf43a2tBJi+bAGAal+7f9wF1WpeyyXB661sGZ8W223O9gi Idog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="RGv06/Rb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id g1-20020a636b01000000b005ac61b76914si8250316pgc.93.2023.10.24.02.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:30:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="RGv06/Rb"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 8951980C281A; Tue, 24 Oct 2023 02:29:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234332AbjJXJ3u (ORCPT + 26 others); Tue, 24 Oct 2023 05:29:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234327AbjJXJ31 (ORCPT ); Tue, 24 Oct 2023 05:29:27 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FFE12127; Tue, 24 Oct 2023 02:28:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139726; x=1729675726; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oOoE9qnQgl0vvUYTiHnIQ0tgq/pyCy/rUFRqG5gIceQ=; b=RGv06/RbvmSrMuXdBq0Ei1EYmiA0Tm1ZM2eMGbaHBRDS5HihlUia4FJU y3lvQTHXl3AwrZtGe16+HWBh3eswrN0+5qoOpFe+LXdxEwCN4RxM5PYU/ +DWZfD4GaEqiNDKZx1kyGHnP3d5frq6hXNnmxSu5CL5xESwDx7p/Vv2vy wzVajT7YOpjUTXHvLmhugDZk7I5VqMkBbus9ilXJcAAsRdEdcfcbpAPNj i4v1KTszbiEJHCNSky9UM0Nc1m6suakuW0k8Fw88Uvp3Ydw6obXd5P2I0 /+HNLmtLjRs2ceUkIHENTDTyuZBE/L+Kd9J3cNOoUl6C5oEmISBSNfZm1 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="384218894" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="384218894" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:28:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="6397763" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:28:36 -0700 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 14/24] selftests/resctrl: Move cat_val() to cat_test.c and rename to cat_test() Date: Tue, 24 Oct 2023 12:26:24 +0300 Message-Id: <20231024092634.7122-15-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 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 morse.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 (morse.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:29:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628639753596498 X-GMAIL-MSGID: 1780628639753596498 The main CAT test function is called cat_val() and resides in cache.c which is illogical. Rename the function to cat_test() and move it into cat_test.c. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cache.c | 90 ++-------------------- tools/testing/selftests/resctrl/cat_test.c | 73 +++++++++++++++++- tools/testing/selftests/resctrl/resctrl.h | 14 +++- 3 files changed, 90 insertions(+), 87 deletions(-) diff --git a/tools/testing/selftests/resctrl/cache.c b/tools/testing/selftests/resctrl/cache.c index a65e2e35c33c..c4cb3cb8c2c9 100644 --- a/tools/testing/selftests/resctrl/cache.c +++ b/tools/testing/selftests/resctrl/cache.c @@ -3,16 +3,9 @@ #include #include "resctrl.h" -struct perf_event_read { - __u64 nr; /* The number of events */ - struct { - __u64 value; /* The value of the event */ - } values[2]; -}; - char llc_occup_path[1024]; -static void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config) +void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config) { memset(pea, 0, sizeof(*pea)); pea->type = PERF_TYPE_HARDWARE; @@ -28,13 +21,13 @@ static void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config pea->config = config; } -static void perf_event_initialize_read_format(struct perf_event_read *pe_read) +void perf_event_initialize_read_format(struct perf_event_read *pe_read) { memset(pe_read, 0, sizeof(*pe_read)); pe_read->nr = 1; } -static int perf_event_reset_enable(struct perf_event_attr *pea, pid_t pid, int cpu_no) +int perf_event_reset_enable(struct perf_event_attr *pea, pid_t pid, int cpu_no) { int pe_fd; @@ -123,8 +116,8 @@ static int print_results_cache(char *filename, int bm_pid, __u64 llc_value) * * Return: =0 on success. <0 on failure. */ -static int perf_event_measure(int pe_fd, struct perf_event_read *pe_read, - struct resctrl_val_param *param, int bm_pid) +int perf_event_measure(int pe_fd, struct perf_event_read *pe_read, + struct resctrl_val_param *param, int bm_pid) { int ret; @@ -156,79 +149,6 @@ int measure_llc_resctrl(struct resctrl_val_param *param, int bm_pid) return ret; } -/* - * cache_val: execute benchmark and measure LLC occupancy resctrl - * and perf cache miss for the benchmark - * @param: parameters passed to cache_val() - * @span: buffer size for the benchmark - * - * Return: 0 on success. non-zero on failure. - */ -int cat_val(struct resctrl_val_param *param, size_t span) -{ - int memflush = 1, operation = 0, ret = 0; - char *resctrl_val = param->resctrl_val; - static struct perf_event_read pe_read; - struct perf_event_attr pea; - pid_t bm_pid; - int pe_fd; - - if (strcmp(param->filename, "") == 0) - sprintf(param->filename, "stdio"); - - bm_pid = getpid(); - - /* Taskset benchmark to specified cpu */ - ret = taskset_benchmark(bm_pid, param->cpu_no); - if (ret) - return ret; - - /* Write benchmark to specified con_mon grp, mon_grp in resctrl FS*/ - ret = write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp, - resctrl_val); - if (ret) - return ret; - - perf_event_attr_initialize(&pea, PERF_COUNT_HW_CACHE_MISSES); - perf_event_initialize_read_format(&pe_read); - - /* Test runs until the callback setup() tells the test to stop. */ - while (1) { - ret = param->setup(param); - if (ret == END_OF_TESTS) { - ret = 0; - break; - } - if (ret < 0) - break; - - pe_fd = perf_event_reset_enable(&pea, bm_pid, param->cpu_no); - if (pe_fd < 0) { - ret = -1; - break; - } - - if (run_fill_buf(span, memflush, operation, true)) { - fprintf(stderr, "Error-running fill buffer\n"); - ret = -1; - goto pe_close; - } - - sleep(1); - ret = perf_event_measure(pe_fd, &pe_read, param, bm_pid); - if (ret) - goto pe_close; - - close(pe_fd); - } - - return ret; - -pe_close: - close(pe_fd); - return ret; -} - /* * show_cache_info: show generic cache test information * @no_of_bits: number of bits diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 2106cc3601d9..e71690a9bbb3 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -111,6 +111,77 @@ void cat_test_cleanup(void) remove(RESULT_FILE_NAME2); } +/* + * cat_test: execute CAT benchmark and measure LLC cache misses + * @param: parameters passed to cat_test() + * @span: buffer size for the benchmark + * + * Return: 0 on success. non-zero on failure. + */ +static int cat_test(struct resctrl_val_param *param, size_t span) +{ + int memflush = 1, operation = 0, ret = 0; + char *resctrl_val = param->resctrl_val; + static struct perf_event_read pe_read; + struct perf_event_attr pea; + pid_t bm_pid; + int pe_fd; + + if (strcmp(param->filename, "") == 0) + sprintf(param->filename, "stdio"); + + bm_pid = getpid(); + + /* Taskset benchmark to specified cpu */ + ret = taskset_benchmark(bm_pid, param->cpu_no); + if (ret) + return ret; + + /* Write benchmark to specified con_mon grp, mon_grp in resctrl FS*/ + ret = write_bm_pid_to_resctrl(bm_pid, param->ctrlgrp, param->mongrp, + resctrl_val); + if (ret) + return ret; + + perf_event_attr_initialize(&pea, PERF_COUNT_HW_CACHE_MISSES); + perf_event_initialize_read_format(&pe_read); + + /* Test runs until the callback setup() tells the test to stop. */ + while (1) { + ret = param->setup(param); + if (ret == END_OF_TESTS) { + ret = 0; + break; + } + if (ret < 0) + break; + pe_fd = perf_event_reset_enable(&pea, bm_pid, param->cpu_no); + if (pe_fd < 0) { + ret = -1; + break; + } + + if (run_fill_buf(span, memflush, operation, true)) { + fprintf(stderr, "Error-running fill buffer\n"); + ret = -1; + goto pe_close; + } + + sleep(1); + ret = perf_event_measure(pe_fd, &pe_read, param, bm_pid); + if (ret) + goto pe_close; + + close(pe_fd); + } + + return ret; + +pe_close: + close(pe_fd); + return ret; +} + int cat_perf_miss_val(int cpu_no, int n, char *cache_type) { unsigned long l_mask, l_mask_1; @@ -196,7 +267,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) remove(param.filename); - ret = cat_val(¶m, span); + ret = cat_test(¶m, span); if (ret == 0) ret = check_results(¶m, span); diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 033c49784581..ee3cee74a69c 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -67,6 +67,13 @@ struct resctrl_val_param { int (*setup)(struct resctrl_val_param *param); }; +struct perf_event_read { + __u64 nr; /* The number of events */ + struct { + __u64 value; /* The value of the event */ + } values[2]; +}; + #define MBM_STR "mbm" #define MBA_STR "mba" #define CMT_STR "cmt" @@ -107,13 +114,18 @@ int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size void ctrlc_handler(int signum, siginfo_t *info, void *ptr); int signal_handler_register(void); void signal_handler_unregister(void); -int cat_val(struct resctrl_val_param *param, size_t span); void cat_test_cleanup(void); int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type); int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd); unsigned int count_bits(unsigned long n); void cmt_test_cleanup(void); int get_core_sibling(int cpu_no); + +void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config); +void perf_event_initialize_read_format(struct perf_event_read *pe_read); +int perf_event_reset_enable(struct perf_event_attr *pea, pid_t pid, int cpu_no); +int perf_event_measure(int pe_fd, struct perf_event_read *pe_read, + struct resctrl_val_param *param, int bm_pid); int measure_llc_resctrl(struct resctrl_val_param *param, int bm_pid); void show_cache_info(int no_of_bits, __u64 avg_llc_val, size_t cache_span, bool lines); From patchwork Tue Oct 24 09:26:25 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: 157338 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1820987vqx; Tue, 24 Oct 2023 02:31:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEpqHTqdszycCdbBPbMgVuWktJOUULpevA66N2utexWibk9zxfQ8pGJjPiVs/Zo5YCvA5As X-Received: by 2002:a05:6a21:4887:b0:15e:d84:1c5e with SMTP id av7-20020a056a21488700b0015e0d841c5emr2141294pzc.38.1698139897651; Tue, 24 Oct 2023 02:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139897; cv=none; d=google.com; s=arc-20160816; b=gFVmSgLIxGJU9kvaQwJ6Konu+C29KTDQR99YchlHiadVAN7F1ky/RP4UvXTjZMwoaI 1+YSIaLeSvAcQ/CqGD19ThVEQ5jYogylBkslh6wi+ZvbWUxflxPmrzqwxF4EeMI32EK8 9NGYq/ULxW5FA2i80QpQDZ5dxsj/ECvW1XNLkB/tvE2ax8DxDC5md5CjLKKZLGKy20Uw 0FhnqEhfajXGyikwJ+eumn8EZdX16e19rAD58KsMW61nMTbJFQ/2LfRLMAIPNi/7JQG1 s7gVzWF5n65nvbX3slUJeM531Eoa+J3MYfmUKbcuqwnyxD9QUu3A44QhmDuXnLXP6N06 kVZQ== 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=tukJiYoE+JoVbcAOLzY6dzGTtdmqO1g/81ZAlLFqiOM=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=qwrNhRhpIocHSvbh7/2sPCEM4I65Wm5zJG79w4tR/GhgRGHguSdegQxAwMNvw7siaW vSt+JBGW05jgqkdV4Q4YZAagCVEdWz3xMhbRRFmvwFEtlUdks9yCEXeUIUfkp0CQ7E48 nwC9Kngj/IGTJZdcnHOBjb9/HceR3xuZBwv3C2ai7vmUYNSw/Y3JJaCi92iFqA4VY4xF CBF52KohhbVMP9Jl7IMRhyRDn/eyU9QyRlsZgMvm4gTEL0y97hNgEHv6ZGb7MRk4rJsT YOkdJgGAaNj2y7Z2VNaXJm2SGS5srFFA6kt4LG0gq3xetRssmYewkc//EANdeAG0OmIZ AGlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aMtvfXym; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id a13-20020a056a000c8d00b0069d1639f09esi8347911pfv.190.2023.10.24.02.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:31:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aMtvfXym; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 77FDF806D7C1; Tue, 24 Oct 2023 02:30:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234261AbjJXJaM (ORCPT + 26 others); Tue, 24 Oct 2023 05:30:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234236AbjJXJ3g (ORCPT ); Tue, 24 Oct 2023 05:29:36 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF27C1729; Tue, 24 Oct 2023 02:28:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139735; x=1729675735; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bqHDSFhKyH5O4q+WlQcPjHBDU9dNxKX/Zht0fn5lHcg=; b=aMtvfXymGwsc9tLQQCSu9gvp6/91FilF7HER6ERPLVwFJ5T1AcE6Dhxf z2Dx9kuZCtOyaXGizSNXlpbR4/FCecoHuLGZ6w1eNaZjFMSHSfdmvMgkU ife3J+PF0NYhu44xW0y4ZiOyjfImuUqXCawW8cjWTv1QrYkV+gWqot4Dq qPr5Jpep0LxOIFpARMvBxB7xl9pml10n12CvPLHucA/sMoHQnBo//Kiwj RYBJHsLbt0MWNAzgsinfRydDEyaycTz5f5pXEBCEZrA8REA+MAMCxa2Bu 0yZkDRkc1ULLOdeo0Gbsts+eNe2quhe76F1j+mtRCgz0258EsOSRpeqQx A==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="384218902" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="384218902" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:28:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="6397798" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:28:44 -0700 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 15/24] selftests/resctrl: Read in less obvious order to defeat prefetch optimizations Date: Tue, 24 Oct 2023 12:26:25 +0300 Message-Id: <20231024092634.7122-16-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 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 groat.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 (groat.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:30:31 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628741318932094 X-GMAIL-MSGID: 1780628741318932094 When reading memory in order, HW prefetching optimizations will interfere with measuring how caches and memory are being accessed. This adds noise into the results. Change the fill_buf reading loop to not use an obvious in-order access using multiply by a prime and modulo. Using a prime multiplier with modulo ensures the entire buffer is eventually read. 23 is small enough that the reads are spread out but wrapping does not occur very frequently (wrapping too often can trigger L2 hits more frequently which causes noise to the test because getting the data from LLC is not required). It was discovered that not all primes work equally well and some can cause wildly unstable results (e.g., in an earlier version of this patch, the reads were done in reversed order and 59 was used as the prime resulting in unacceptably high and unstable results in MBA and MBM test on some architectures). Link: https://lore.kernel.org/linux-kselftest/TYAPR01MB6330025B5E6537F94DA49ACB8B499@TYAPR01MB6330.jpnprd01.prod.outlook.com/ Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/fill_buf.c | 38 +++++++++++++++++----- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index 9d0b0bf4b85a..326d530425d0 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -51,16 +51,38 @@ static void mem_flush(unsigned char *buf, size_t buf_size) sb(); } +/* + * Buffer index step advance to workaround HW prefetching interfering with + * the measurements. + * + * Must be a prime to step through all indexes of the buffer. + * + * Some primes work better than others on some architectures (from MBA/MBM + * result stability point of view). + */ +#define FILL_IDX_MULT 23 + static int fill_one_span_read(unsigned char *buf, size_t buf_size) { - unsigned char *end_ptr = buf + buf_size; - unsigned char sum, *p; - - sum = 0; - p = buf; - while (p < end_ptr) { - sum += *p; - p += (CL_SIZE / 2); + unsigned int size = buf_size / (CL_SIZE / 2); + unsigned int i, idx = 0; + unsigned char sum = 0; + + /* + * Read the buffer in an order that is unexpected by HW prefetching + * optimizations to prevent them interfering with the caching pattern. + * + * The read order is (in terms of halves of cachelines): + * i * FILL_IDX_MULT % size + * The formula is open-coded below to avoiding modulo inside the loop + * as it improves MBA/MBM result stability on some architectures. + */ + for (i = 0; i < size; i++) { + sum += buf[idx * (CL_SIZE / 2)]; + + idx += FILL_IDX_MULT; + while (idx >= size) + idx -= size; } return sum; From patchwork Tue Oct 24 09:26:26 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: 157336 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1820892vqx; Tue, 24 Oct 2023 02:31:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHmUL8PiVVB3YpHOsZUKx9CHEFYPxtRxo2P/iHE/KvqQiMMh/VmYz4+yG0iI4a9boERYvyU X-Received: by 2002:a17:90a:7887:b0:274:6839:6a8c with SMTP id x7-20020a17090a788700b0027468396a8cmr8958782pjk.6.1698139884271; Tue, 24 Oct 2023 02:31:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139884; cv=none; d=google.com; s=arc-20160816; b=xY4+SfI0qq9uPLrPo3fBdTSXsFvYyK5aJWQO7apipBCw1zvIuLfjtFv/VsIy4P50vF ETmEH2KaznBIMyqxjg1qfqxICbrMxCMHih1FMlkqnyvE7ihLjRR7p0KDZ+EfI0EPmvpn tgmB1ZJvG+AW5nAMJvq3MBtqtWp6el/WKfh8xrcMErxi5kIcd6ZcD6I0JKvxwGoJXBvz YRbSZLd4OcOudbA7dm9doGOayZCU2Woiy00HI8IogWTtq5zWBlw99wHWF1iyQhI2px5q 0mcZUcZqo5K5N3mEqDk6ju5tuPeFpRLSwCZk4m8XG8Sg3NG6CbUpeFEVgrNr3xzRqflX 4j+w== 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=cUcurNsl9Qom7vQNWV2TqpWIiTV07LtH7s2iJofcPyI=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=KPIkR8EYJQTLLCkczfNOH5XcfwgLoFvWxsmX16iuGBuC3f4J5TkrbTIPU4oqUnQQni 4u4ZDRWtebOjryd/XWkz+AmOoUsFvccgf6fQsLFQTMIApa+JvH/Zs9uVXteTYoRJMTJ/ 050Re6b0Fsaaxk3ZHigG9hLaMpsS64xciDqLRNNHk4G0NjLVUnlzfljm0E2BgJbl3d9z FDuTn3Fv6zK1YHrebtQcfWu+XSg8nvJFHZe+LXUICAMiea+RU4TgQvmbwpKVjliosuiz ETJr8lAYEXyTRJnF5y+ces89qOkwBp8sJE5vi0VhcIH6F56c0juG0MqHsbsgaBAbQOjn ur1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="G6Z0RHh/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id h24-20020a17090aa89800b0027ced9acac0si10760193pjq.2.2023.10.24.02.31.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:31:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="G6Z0RHh/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 85F4F8072156; Tue, 24 Oct 2023 02:31:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234234AbjJXJbF (ORCPT + 26 others); Tue, 24 Oct 2023 05:31:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234390AbjJXJab (ORCPT ); Tue, 24 Oct 2023 05:30:31 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4ACF51FD3; Tue, 24 Oct 2023 02:29:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139770; x=1729675770; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bsQLK+vSeD8JEj8tn54DGxbsLyoZN/n1gbL0pSe8EwU=; b=G6Z0RHh/Yc/1WKcN+tIrKXmXEVyqVnaB+MFGVcTedvF7huNyGOqY2maC ZFWy0W7ce0dV/vwN4Zd6zfga6/qjvJG4RlaXFVQ4CgQoJRdPgHjplo+zM 0dfRz5zT0K6TOYe9I6bZ+E5wTHOGg4GLgPpHZi7m+QsRmLfpVtTx0SgQb 9ch0TKartHfMcesrV7PFfXaCkrcCuepIuFqDXZulxpXqlxpExShYskL5z uip60/od0TAWidssWH6rDPs2V+YzcSi818pJLKwzcDg3IIYYX/xDBbakd 9F5sPRv/rR4QjBUBZg1gnYC7Lp4T8Lyzy3PTrIoLwXzZKN/QkXjUMtOHO g==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="418145170" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="418145170" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="734972516" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="734972516" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:28:59 -0700 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 16/24] selftests/resctrl: Rewrite Cache Allocation Technology (CAT) test Date: Tue, 24 Oct 2023 12:26:26 +0300 Message-Id: <20231024092634.7122-17-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 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:31:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628727468504784 X-GMAIL-MSGID: 1780628727468504784 CAT test spawns two processes into two different control groups with exclusive schemata. Both the processes alloc a buffer from memory matching their allocated LLC block size and flush the entire buffer out of caches. Since the processes are reading through the buffer only once during the measurement and initially all the buffer was flushed, the test isn't testing CAT. Rewrite the CAT test to allocate a buffer sized to half of LLC. Then perform a sequence of tests with different LLC alloc sizes starting from half of the CBM bits down to 1-bit CBM. Flush the buffer before each test and read the buffer twice. Observe the LLC misses on the second read through the buffer. As the allocated LLC block gets smaller and smaller, the LLC misses will become larger and larger giving a strong signal on CAT working properly. The new CAT test is using only a single process because it relies on measured effect against another run of itself rather than another process adding noise. The rest of the system is allocated the CBM bits not used by the CAT test to keep the test isolated. Replace count_bits() with count_contiguous_bits() to get the first bit position in order to be able to calculate masks based on it. This change has been tested with a number of systems from different generations. Suggested-by: Reinette Chatre Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cat_test.c | 286 +++++++++----------- tools/testing/selftests/resctrl/fill_buf.c | 6 +- tools/testing/selftests/resctrl/resctrl.h | 5 +- tools/testing/selftests/resctrl/resctrlfs.c | 44 +-- 4 files changed, 137 insertions(+), 204 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index e71690a9bbb3..7518c520c5cc 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -11,65 +11,68 @@ #include "resctrl.h" #include -#define RESULT_FILE_NAME1 "result_cat1" -#define RESULT_FILE_NAME2 "result_cat2" +#define RESULT_FILE_NAME "result_cat" #define NUM_OF_RUNS 5 -#define MAX_DIFF_PERCENT 4 -#define MAX_DIFF 1000000 /* - * Change schemata. Write schemata to specified - * con_mon grp, mon_grp in resctrl FS. - * Run 5 times in order to get average values. + * Minimum difference in LLC misses between a test with n+1 bits CBM mask to + * the test with n bits. With e.g. 5 vs 4 bits in the CBM mask, the minimum + * difference must be at least MIN_DIFF_PERCENT_PER_BIT * (4 - 1) = 3 percent. + * + * The relationship between number of used CBM bits and difference in LLC + * misses is not expected to be linear. With a small number of bits, the + * margin is smaller than with larger number of bits. For selftest purposes, + * however, linear approach is enough because ultimately only pass/fail + * decision has to be made and distinction between strong and stronger + * signal is irrelevant. */ -static int cat_setup(struct resctrl_val_param *p) -{ - char schemata[64]; - int ret = 0; - - /* Run NUM_OF_RUNS times */ - if (p->num_of_runs >= NUM_OF_RUNS) - return END_OF_TESTS; - - if (p->num_of_runs == 0) { - sprintf(schemata, "%lx", p->mask); - ret = write_schemata(p->ctrlgrp, schemata, p->cpu_no, - p->resctrl_val); - } - p->num_of_runs++; - - return ret; -} +#define MIN_DIFF_PERCENT_PER_BIT 1 static int show_results_info(__u64 sum_llc_val, int no_of_bits, - unsigned long cache_span, unsigned long max_diff, - unsigned long max_diff_percent, unsigned long num_of_runs, - bool platform) + unsigned long cache_span, long min_diff_percent, + unsigned long num_of_runs, bool platform, + __s64 *prev_avg_llc_val) { __u64 avg_llc_val = 0; - float diff_percent; - int ret; + float avg_diff; + int ret = 0; avg_llc_val = sum_llc_val / num_of_runs; - diff_percent = ((float)cache_span - avg_llc_val) / cache_span * 100; + if (*prev_avg_llc_val) { + float delta = (__s64)(avg_llc_val - *prev_avg_llc_val); - ret = platform && abs((int)diff_percent) > max_diff_percent; + avg_diff = delta / *prev_avg_llc_val; + ret = platform && (avg_diff * 100) < (float)min_diff_percent; - ksft_print_msg("%s Check cache miss rate within %lu%%\n", - ret ? "Fail:" : "Pass:", max_diff_percent); + ksft_print_msg("%s Check cache miss rate changed more than %.1f%%\n", + ret ? "Fail:" : "Pass:", (float)min_diff_percent); - ksft_print_msg("Percent diff=%d\n", abs((int)diff_percent)); + ksft_print_msg("Percent diff=%.1f\n", avg_diff * 100); + } + *prev_avg_llc_val = avg_llc_val; show_cache_info(no_of_bits, avg_llc_val, cache_span, true); return ret; } -static int check_results(struct resctrl_val_param *param, size_t span) +/* Remove one bit from the consecutive cbm mask */ +static unsigned long next_mask(unsigned long current_mask) +{ + return current_mask & (current_mask >> 1); +} + +static int check_results(struct resctrl_val_param *param, const char *cache_type, + unsigned long cache_total_size, unsigned long full_cache_mask, + unsigned long current_mask) { char *token_array[8], temp[512]; __u64 sum_llc_perf_miss = 0; - int runs = 0, no_of_bits = 0; + unsigned long alloc_size; + __s64 prev_avg_llc_val = 0; + int runs = 0; + int fail = 0; + int ret; FILE *fp; ksft_print_msg("Checking for pass/fail\n"); @@ -83,49 +86,71 @@ static int check_results(struct resctrl_val_param *param, size_t span) while (fgets(temp, sizeof(temp), fp)) { char *token = strtok(temp, ":\t"); int fields = 0; + int bits; while (token) { token_array[fields++] = token; token = strtok(NULL, ":\t"); } - /* - * Discard the first value which is inaccurate due to monitoring - * setup transition phase. - */ - if (runs > 0) - sum_llc_perf_miss += strtoull(token_array[3], NULL, 0); + + sum_llc_perf_miss += strtoull(token_array[3], NULL, 0); runs++; + + if (runs < NUM_OF_RUNS) + continue; + + if (!current_mask) { + ksft_print_msg("Unexpected empty cache mask\n"); + break; + } + + alloc_size = cache_size(cache_total_size, current_mask, full_cache_mask); + + bits = count_bits(current_mask); + + ret = show_results_info(sum_llc_perf_miss, bits, + alloc_size / 64, + MIN_DIFF_PERCENT_PER_BIT * (bits - 1), runs, + get_vendor() == ARCH_INTEL, + &prev_avg_llc_val); + if (ret) + fail = 1; + + runs = 0; + sum_llc_perf_miss = 0; + current_mask = next_mask(current_mask); } fclose(fp); - no_of_bits = count_bits(param->mask); - return show_results_info(sum_llc_perf_miss, no_of_bits, span / 64, - MAX_DIFF, MAX_DIFF_PERCENT, runs - 1, - get_vendor() == ARCH_INTEL); + return fail; } void cat_test_cleanup(void) { - remove(RESULT_FILE_NAME1); - remove(RESULT_FILE_NAME2); + remove(RESULT_FILE_NAME); } /* * cat_test: execute CAT benchmark and measure LLC cache misses * @param: parameters passed to cat_test() * @span: buffer size for the benchmark + * @current_mask start mask for the first iteration + * + * Run CAT test, bits are removed one-by-one from the current_mask for each + * subsequent test. * - * Return: 0 on success. non-zero on failure. + * Return: 0 on success. non-zero on failure. */ -static int cat_test(struct resctrl_val_param *param, size_t span) +static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long current_mask) { - int memflush = 1, operation = 0, ret = 0; char *resctrl_val = param->resctrl_val; static struct perf_event_read pe_read; struct perf_event_attr pea; + unsigned char *buf; + char schemata[64]; + int ret, i, pe_fd; pid_t bm_pid; - int pe_fd; if (strcmp(param->filename, "") == 0) sprintf(param->filename, "stdio"); @@ -143,54 +168,64 @@ static int cat_test(struct resctrl_val_param *param, size_t span) if (ret) return ret; + buf = alloc_buffer(span, 1); + if (buf == NULL) + return -1; + perf_event_attr_initialize(&pea, PERF_COUNT_HW_CACHE_MISSES); perf_event_initialize_read_format(&pe_read); - /* Test runs until the callback setup() tells the test to stop. */ - while (1) { - ret = param->setup(param); - if (ret == END_OF_TESTS) { - ret = 0; - break; - } - if (ret < 0) - break; - pe_fd = perf_event_reset_enable(&pea, bm_pid, param->cpu_no); - if (pe_fd < 0) { - ret = -1; - break; - } + while (current_mask) { + snprintf(schemata, sizeof(schemata), "%lx", param->mask & ~current_mask); + ret = write_schemata("", schemata, param->cpu_no, param->resctrl_val); + if (ret) + goto free_buf; + snprintf(schemata, sizeof(schemata), "%lx", current_mask); + ret = write_schemata(param->ctrlgrp, schemata, param->cpu_no, param->resctrl_val); + if (ret) + goto free_buf; + + for (i = 0; i < NUM_OF_RUNS; i++) { + mem_flush(buf, span); + ret = fill_cache_read(buf, span, true); + if (ret) + goto free_buf; + + pe_fd = perf_event_reset_enable(&pea, bm_pid, param->cpu_no); + if (pe_fd < 0) { + ret = -1; + goto free_buf; + } - if (run_fill_buf(span, memflush, operation, true)) { - fprintf(stderr, "Error-running fill buffer\n"); - ret = -1; - goto pe_close; - } + fill_cache_read(buf, span, true); - sleep(1); - ret = perf_event_measure(pe_fd, &pe_read, param, bm_pid); - if (ret) - goto pe_close; + ret = perf_event_measure(pe_fd, &pe_read, param, bm_pid); + if (ret) + goto pe_close; - close(pe_fd); + close(pe_fd); + } + current_mask = next_mask(current_mask); } +free_buf: + free(buf); + return ret; pe_close: close(pe_fd); - return ret; + goto free_buf; } int cat_perf_miss_val(int cpu_no, int n, char *cache_type) { - unsigned long l_mask, l_mask_1; - int ret, pipefd[2], sibling_cpu_no; + unsigned long long_mask, start_mask, full_cache_mask; unsigned long cache_total_size = 0; - unsigned long full_cache_mask, long_mask; + unsigned int start; int count_of_bits; - char pipe_message; size_t span; + int ret; /* Get default cbm mask for L3/L2 cache */ ret = get_cbm_mask(cache_type, &full_cache_mask); @@ -207,8 +242,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) return ret; ksft_print_msg("Cache size :%lu\n", cache_total_size); - /* Get max number of bits from default-cabm mask */ - count_of_bits = count_bits(long_mask); + count_of_bits = count_contiguous_bits(long_mask, &start); if (!n) n = count_of_bits / 2; @@ -219,88 +253,26 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) count_of_bits - 1); return -1; } - - /* Get core id from same socket for running another thread */ - sibling_cpu_no = get_core_sibling(cpu_no); - if (sibling_cpu_no < 0) - return -1; + start_mask = create_bit_mask(start, n); struct resctrl_val_param param = { .resctrl_val = CAT_STR, .cpu_no = cpu_no, - .setup = cat_setup, + .ctrlgrp = "c1", + .filename = RESULT_FILE_NAME, + .num_of_runs = 0, }; - - l_mask = long_mask >> n; - l_mask_1 = ~l_mask & long_mask; - - /* Set param values for parent thread which will be allocated bitmask - * with (max_bits - n) bits - */ - span = cache_size(cache_total_size, l_mask, full_cache_mask); - strcpy(param.ctrlgrp, "c2"); - strcpy(param.mongrp, "m2"); - strcpy(param.filename, RESULT_FILE_NAME2); - param.mask = l_mask; - param.num_of_runs = 0; - - if (pipe(pipefd)) { - perror("# Unable to create pipe"); - return errno; - } - - fflush(stdout); - bm_pid = fork(); - - /* Set param values for child thread which will be allocated bitmask - * with n bits - */ - if (bm_pid == 0) { - param.mask = l_mask_1; - strcpy(param.ctrlgrp, "c1"); - strcpy(param.mongrp, "m1"); - span = cache_size(cache_total_size, l_mask_1, full_cache_mask); - strcpy(param.filename, RESULT_FILE_NAME1); - param.num_of_runs = 0; - param.cpu_no = sibling_cpu_no; - } + param.mask = long_mask; + span = cache_size(cache_total_size, start_mask, full_cache_mask); remove(param.filename); - ret = cat_test(¶m, span); - if (ret == 0) - ret = check_results(¶m, span); - - if (bm_pid == 0) { - /* Tell parent that child is ready */ - close(pipefd[0]); - pipe_message = 1; - if (write(pipefd[1], &pipe_message, sizeof(pipe_message)) < - sizeof(pipe_message)) - /* - * Just print the error message. - * Let while(1) run and wait for itself to be killed. - */ - perror("# failed signaling parent process"); - - close(pipefd[1]); - while (1) - ; - } else { - /* Parent waits for child to be ready. */ - close(pipefd[1]); - pipe_message = 0; - while (pipe_message != 1) { - if (read(pipefd[0], &pipe_message, - sizeof(pipe_message)) < sizeof(pipe_message)) { - perror("# failed reading from child process"); - break; - } - } - close(pipefd[0]); - kill(bm_pid, SIGKILL); - } + ret = cat_test(¶m, span, start_mask); + if (ret) + goto out; + ret = check_results(¶m, cache_type, cache_total_size, full_cache_mask, start_mask); +out: cat_test_cleanup(); return ret; diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index 326d530425d0..3dbb71371715 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -38,7 +38,7 @@ static void cl_flush(void *p) #endif } -static void mem_flush(unsigned char *buf, size_t buf_size) +void mem_flush(unsigned char *buf, size_t buf_size) { unsigned char *cp = buf; size_t i = 0; @@ -100,7 +100,7 @@ static void fill_one_span_write(unsigned char *buf, size_t buf_size) } } -static int fill_cache_read(unsigned char *buf, size_t buf_size, bool once) +int fill_cache_read(unsigned char *buf, size_t buf_size, bool once) { int ret = 0; FILE *fp; @@ -134,7 +134,7 @@ static int fill_cache_write(unsigned char *buf, size_t buf_size, bool once) return 0; } -static unsigned char *alloc_buffer(size_t buf_size, int memflush) +unsigned char *alloc_buffer(size_t buf_size, int memflush) { void *p = NULL; uint64_t *p64; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index ee3cee74a69c..927f696e0ab7 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -99,6 +99,9 @@ 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); +unsigned char *alloc_buffer(size_t buf_size, int memflush); +void mem_flush(unsigned char *buf, size_t buf_size); +int fill_cache_read(unsigned char *buf, size_t buf_size, 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); @@ -107,6 +110,7 @@ void mbm_test_cleanup(void); int mba_schemata_change(int cpu_no, const char * const *benchmark_cmd); void mba_test_cleanup(void); unsigned long create_bit_mask(unsigned int start, unsigned int len); +unsigned int count_contiguous_bits(unsigned long val, unsigned int *start); int get_cbm_mask(const char *cache_type, unsigned long *mask); int get_shareable_mask(const char *cache_type, unsigned long *shareable_mask); int get_mask_no_shareable(const char *cache_type, unsigned long *mask); @@ -119,7 +123,6 @@ int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type); int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd); unsigned int count_bits(unsigned long n); void cmt_test_cleanup(void); -int get_core_sibling(int cpu_no); void perf_event_attr_initialize(struct perf_event_attr *pea, __u64 config); void perf_event_initialize_read_format(struct perf_event_read *pe_read); diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 02b04878121f..c8fbbd96311d 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -245,7 +245,7 @@ unsigned long create_bit_mask(unsigned int start, unsigned int len) * * Return: The length of the contiguous bits in the longest train of bits */ -static unsigned int count_contiguous_bits(unsigned long val, unsigned int *start) +unsigned int count_contiguous_bits(unsigned long val, unsigned int *start) { unsigned long last_val; int count = 0; @@ -337,48 +337,6 @@ int get_mask_no_shareable(const char *cache_type, unsigned long *mask) return 0; } -/* - * get_core_sibling - Get sibling core id from the same socket for given CPU - * @cpu_no: CPU number - * - * Return: > 0 on success, < 0 on failure. - */ -int get_core_sibling(int cpu_no) -{ - char core_siblings_path[1024], cpu_list_str[64]; - int sibling_cpu_no = -1; - FILE *fp; - - sprintf(core_siblings_path, "%s%d/topology/core_siblings_list", - CORE_SIBLINGS_PATH, cpu_no); - - fp = fopen(core_siblings_path, "r"); - if (!fp) { - perror("Failed to open core siblings path"); - - return -1; - } - if (fscanf(fp, "%s", cpu_list_str) <= 0) { - perror("Could not get core_siblings list"); - fclose(fp); - - return -1; - } - fclose(fp); - - char *token = strtok(cpu_list_str, "-,"); - - while (token) { - sibling_cpu_no = atoi(token); - /* Skipping core 0 as we don't want to run test on core 0 */ - if (sibling_cpu_no != 0 && sibling_cpu_no != cpu_no) - break; - token = strtok(NULL, "-,"); - } - - return sibling_cpu_no; -} - /* * taskset_benchmark - Taskset PID (i.e. benchmark) to a specified cpu * @bm_pid: PID that should be binded From patchwork Tue Oct 24 09:26:27 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: 157343 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1821259vqx; Tue, 24 Oct 2023 02:32:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4uvIQMIIUWL9DUdsop6EWpVh9A+g67T9Qcj0QL/wtH13MLpPC2TGWlE23E2ghAm4KoOVb X-Received: by 2002:a05:6358:9782:b0:168:eb1c:366b with SMTP id f2-20020a056358978200b00168eb1c366bmr3265956rwb.21.1698139941560; Tue, 24 Oct 2023 02:32:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139941; cv=none; d=google.com; s=arc-20160816; b=KRX5LeNDODklsMylvuRFgzAaVP8yvh1cRmmBKnLUYmv6ZwTqP4K8TmfMCopyfnc+tX PyLoEATudPI59uKNN3DaefUGdpJcIniSmemPlpNcyF5Yc1r5MWyPz2EL4HEQhFE3NQ9G o9hf0/J9w/zN0ZuEQJf4gJXJuMJES9DnxzB9Nc8QhWYFMWH1xA2VZRDyRFh7Zwg0GseB zWxK0wIdBEDnJkoytAoWx7tiORUawDjecGEmBEZJZ0q0/KBge20QmRHywQ8bHmmzi9B8 R8LTsk8AHTRdbsMFICfCvTfuC9MViM0ANre+yjWnuMv0Y61vhp1wg5XuIVM/hsZjp6+H 8c+Q== 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=f3e1x1Save1nsOgy1kNGuZp96ebX2Fr6FVfYXvo7E7E=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=pFrEWTXDH2sk2VjILwLfxYnj7qkT/k2f/p0F6skE62lJWq53Ge5O35WZssAiNfDoW/ ycZAPjOTiQvxl345MRoQNUTimy+1QXqu0Y5dxlA5v56FcmmDMCgMt21P1ge3yaEsdL0T 2G0rIb5tYQ8inYyb95q+SxpllQ07IMgZolzH1hGLHqL8/U8TYMBSyjHeebjMXDdApKWC Wpt6Ak8+P//2csH1NidSPBQFv+h2eabVYodL1Kt8wQPY7YvctXGHreZTOy6lOhOk4h1v 6AniD+00y4d4b2dmW11c4T4AyLUMnG0xZGAU4y6AY5pnu6fgoBf0jlnY5U69EUS/TAm8 ehyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nARDwO7K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id i186-20020a639dc3000000b005b8f38f9973si374678pgd.730.2023.10.24.02.32.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:32:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nARDwO7K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 0C1168079731; Tue, 24 Oct 2023 02:32:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234353AbjJXJa3 (ORCPT + 26 others); Tue, 24 Oct 2023 05:30:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234337AbjJXJ3z (ORCPT ); Tue, 24 Oct 2023 05:29:55 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43A3719AB; Tue, 24 Oct 2023 02:29:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139751; x=1729675751; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XAy9JLZLFdPN+zWsbpxTCeTUfVLXEcxxERlTjO5oCI0=; b=nARDwO7Kbl1QDFr6yAFOnp8ml4+gvF8rp/o3hqyodJROS51qZDmqj+Cc MxGP4oSmGbc16R25na/9BAEx7pRhGqFnd8jnAft3QoBsPbrKtdSsoSaz1 aP8IoJP4CaQXHfAOzT857pTf/CU3g2J6FqJQbTR38o7U907RuY1fV0u5E QMuuIfmfyXs5jOCNTc26ZuXh3TjKK2tfiN0003hkM7pdEil3fRLNIt0Nm /U/j5f8AswCp6r7aOhk2jsCxzlwBQbeTzymCh+lIUS+HLFzjcMtUk37cC KyWzyiEn3k189N/AAJYwqDf2IlB3zfaYgxncxas+jbsRNTT4bTM0gb3oE Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="384218933" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="384218933" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="6397892" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:01 -0700 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 17/24] selftests/resctrl: Create struct for input parameter Date: Tue, 24 Oct 2023 12:26:27 +0300 Message-Id: <20231024092634.7122-18-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 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 pete.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 (pete.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:32:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628787421254211 X-GMAIL-MSGID: 1780628787421254211 resctrl_tests reads a set of parameters and passes them individually for each tests. The way the parameters passed varies between tests. Add struct input_params to hold are input parameters. It can be easily passed to every test without varying the call signature. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cat_test.c | 7 ++- tools/testing/selftests/resctrl/cmt_test.c | 13 ++-- tools/testing/selftests/resctrl/mba_test.c | 6 +- tools/testing/selftests/resctrl/mbm_test.c | 6 +- tools/testing/selftests/resctrl/resctrl.h | 20 ++++-- .../testing/selftests/resctrl/resctrl_tests.c | 61 +++++++++++-------- 6 files changed, 67 insertions(+), 46 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 7518c520c5cc..1a70c69e5f7c 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -218,10 +218,11 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long goto free_buf; } -int cat_perf_miss_val(int cpu_no, int n, char *cache_type) +int cat_perf_miss_val(const struct user_params *uparams, char *cache_type) { unsigned long long_mask, start_mask, full_cache_mask; unsigned long cache_total_size = 0; + int n = uparams->bits; unsigned int start; int count_of_bits; size_t span; @@ -237,7 +238,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) return ret; /* Get L3/L2 cache size */ - ret = get_cache_size(cpu_no, cache_type, &cache_total_size); + ret = get_cache_size(uparams->cpu, cache_type, &cache_total_size); if (ret) return ret; ksft_print_msg("Cache size :%lu\n", cache_total_size); @@ -257,7 +258,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) struct resctrl_val_param param = { .resctrl_val = CAT_STR, - .cpu_no = cpu_no, + .cpu_no = uparams->cpu, .ctrlgrp = "c1", .filename = RESULT_FILE_NAME, .num_of_runs = 0, diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c index 702ea87cd473..f5561b79629f 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -94,11 +94,12 @@ void cmt_test_cleanup(void) remove(RESULT_FILE_NAME); } -int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd) +int cmt_resctrl_val(const struct user_params *uparams) { - const char * const *cmd = benchmark_cmd; + const char * const *cmd = uparams->benchmark_cmd; const char *new_cmd[BENCHMARK_ARGS]; unsigned long cache_total_size = 0; + int n = uparams->bits ? : 5; unsigned long long_mask; char *span_str = NULL; int count_of_bits; @@ -109,7 +110,7 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd) if (ret) return ret; - ret = get_cache_size(cpu_no, "L3", &cache_total_size); + ret = get_cache_size(uparams->cpu, "L3", &cache_total_size); if (ret) return ret; ksft_print_msg("Cache size :%lu\n", cache_total_size); @@ -126,7 +127,7 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd) .resctrl_val = CMT_STR, .ctrlgrp = "c1", .mongrp = "m1", - .cpu_no = cpu_no, + .cpu_no = uparams->cpu, .filename = RESULT_FILE_NAME, .mask = ~(long_mask << n) & long_mask, .num_of_runs = 0, @@ -137,8 +138,8 @@ int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd) if (strcmp(cmd[0], "fill_buf") == 0) { /* Duplicate the command to be able to replace span in it */ - for (i = 0; benchmark_cmd[i]; i++) - new_cmd[i] = benchmark_cmd[i]; + for (i = 0; uparams->benchmark_cmd[i]; i++) + new_cmd[i] = uparams->benchmark_cmd[i]; new_cmd[i] = NULL; ret = asprintf(&span_str, "%zu", span); diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c index d3bf4368341e..5157a3f74fee 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -141,13 +141,13 @@ void mba_test_cleanup(void) remove(RESULT_FILE_NAME); } -int mba_schemata_change(int cpu_no, const char * const *benchmark_cmd) +int mba_schemata_change(const struct user_params *uparams) { struct resctrl_val_param param = { .resctrl_val = MBA_STR, .ctrlgrp = "c1", .mongrp = "m1", - .cpu_no = cpu_no, + .cpu_no = uparams->cpu, .filename = RESULT_FILE_NAME, .bw_report = "reads", .setup = mba_setup @@ -156,7 +156,7 @@ int mba_schemata_change(int cpu_no, const char * const *benchmark_cmd) remove(RESULT_FILE_NAME); - ret = resctrl_val(benchmark_cmd, ¶m); + ret = resctrl_val(uparams->benchmark_cmd, ¶m); if (ret) goto out; diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c index 741533f2b075..98df9d151941 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -109,13 +109,13 @@ void mbm_test_cleanup(void) remove(RESULT_FILE_NAME); } -int mbm_bw_change(int cpu_no, const char * const *benchmark_cmd) +int mbm_bw_change(const struct user_params *uparams) { struct resctrl_val_param param = { .resctrl_val = MBM_STR, .ctrlgrp = "c1", .mongrp = "m1", - .cpu_no = cpu_no, + .cpu_no = uparams->cpu, .filename = RESULT_FILE_NAME, .bw_report = "reads", .setup = mbm_setup @@ -124,7 +124,7 @@ int mbm_bw_change(int cpu_no, const char * const *benchmark_cmd) remove(RESULT_FILE_NAME); - ret = resctrl_val(benchmark_cmd, ¶m); + ret = resctrl_val(uparams->benchmark_cmd, ¶m); if (ret) goto out; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 927f696e0ab7..ec6efd36f60a 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -45,6 +45,18 @@ exit(EXIT_FAILURE); \ } while (0) +/* + * user_params: User supplied parameters + * @cpu: CPU number to which the benchmark will be bound to + * @bits: Number of bits used for cache allocation size + * @benchmark_cmd: Benchmark command to run during (some of the) tests + */ +struct user_params { + int cpu; + int bits; + const char *benchmark_cmd[BENCHMARK_ARGS]; +}; + /* * resctrl_val_param: resctrl test parameters * @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc) @@ -104,10 +116,10 @@ void mem_flush(unsigned char *buf, size_t buf_size); int fill_cache_read(unsigned char *buf, size_t buf_size, 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); +int mbm_bw_change(const struct user_params *uparams); void tests_cleanup(void); void mbm_test_cleanup(void); -int mba_schemata_change(int cpu_no, const char * const *benchmark_cmd); +int mba_schemata_change(const struct user_params *uparams); void mba_test_cleanup(void); unsigned long create_bit_mask(unsigned int start, unsigned int len); unsigned int count_contiguous_bits(unsigned long val, unsigned int *start); @@ -119,8 +131,8 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr); int signal_handler_register(void); void signal_handler_unregister(void); void cat_test_cleanup(void); -int cat_perf_miss_val(int cpu_no, int no_of_bits, char *cache_type); -int cmt_resctrl_val(int cpu_no, int n, const char * const *benchmark_cmd); +int cat_perf_miss_val(const struct user_params *uparams, char *cache_type); +int cmt_resctrl_val(const struct user_params *uparams); unsigned int count_bits(unsigned long n); void cmt_test_cleanup(void); diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 2bbe3045a018..8e00ccc2b2f6 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -92,7 +92,7 @@ static void test_cleanup(void) signal_handler_unregister(); } -static void run_mbm_test(const char * const *benchmark_cmd, int cpu_no) +static void run_mbm_test(const struct user_params *uparams) { int res; @@ -110,7 +110,7 @@ static void run_mbm_test(const char * const *benchmark_cmd, int cpu_no) goto cleanup; } - res = mbm_bw_change(cpu_no, benchmark_cmd); + res = mbm_bw_change(uparams); ksft_test_result(!res, "MBM: bw change\n"); if ((get_vendor() == ARCH_INTEL) && res) ksft_print_msg("Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n"); @@ -119,7 +119,7 @@ static void run_mbm_test(const char * const *benchmark_cmd, int cpu_no) test_cleanup(); } -static void run_mba_test(const char * const *benchmark_cmd, int cpu_no) +static void run_mba_test(const struct user_params *uparams) { int res; @@ -137,14 +137,14 @@ static void run_mba_test(const char * const *benchmark_cmd, int cpu_no) goto cleanup; } - res = mba_schemata_change(cpu_no, benchmark_cmd); + res = mba_schemata_change(uparams); ksft_test_result(!res, "MBA: schemata change\n"); cleanup: test_cleanup(); } -static void run_cmt_test(const char * const *benchmark_cmd, int cpu_no) +static void run_cmt_test(const struct user_params *uparams) { int res; @@ -161,7 +161,7 @@ static void run_cmt_test(const char * const *benchmark_cmd, int cpu_no) goto cleanup; } - res = cmt_resctrl_val(cpu_no, 5, benchmark_cmd); + res = cmt_resctrl_val(uparams); ksft_test_result(!res, "CMT: test\n"); if ((get_vendor() == ARCH_INTEL) && res) ksft_print_msg("Intel CMT may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n"); @@ -170,7 +170,7 @@ static void run_cmt_test(const char * const *benchmark_cmd, int cpu_no) test_cleanup(); } -static void run_cat_test(int cpu_no, int no_of_bits) +static void run_cat_test(const struct user_params *uparams) { int res; @@ -186,22 +186,29 @@ static void run_cat_test(int cpu_no, int no_of_bits) goto cleanup; } - res = cat_perf_miss_val(cpu_no, no_of_bits, "L3"); + res = cat_perf_miss_val(uparams, "L3"); ksft_test_result(!res, "CAT: test\n"); cleanup: test_cleanup(); } +static void init_user_params(struct user_params *uparams) +{ + uparams->cpu = 1; + uparams->bits = 0; +} + int main(int argc, char **argv) { bool mbm_test = true, mba_test = true, cmt_test = true; - const char *benchmark_cmd[BENCHMARK_ARGS] = {}; - int c, cpu_no = 1, i, no_of_bits = 0; + struct user_params uparams = {}; char *span_str = NULL; bool cat_test = true; int tests = 0; - int ret; + int ret, c, i; + + init_user_params(&uparams); while ((c = getopt(argc, argv, "ht:b:n:p:")) != -1) { char *token; @@ -219,8 +226,8 @@ int main(int argc, char **argv) /* Extract benchmark command from command line. */ for (i = 0; i < argc - optind; i++) - benchmark_cmd[i] = argv[i + optind]; - benchmark_cmd[i] = NULL; + uparams.benchmark_cmd[i] = argv[i + optind]; + uparams.benchmark_cmd[i] = NULL; goto last_arg; case 't': @@ -252,11 +259,11 @@ int main(int argc, char **argv) } break; case 'p': - cpu_no = atoi(optarg); + uparams.cpu = atoi(optarg); break; case 'n': - no_of_bits = atoi(optarg); - if (no_of_bits <= 0) { + uparams.bits = atoi(optarg); + if (uparams.bits <= 0) { printf("Bail out! invalid argument for no_of_bits\n"); return -1; } @@ -291,32 +298,32 @@ int main(int argc, char **argv) filter_dmesg(); - if (!benchmark_cmd[0]) { + if (!uparams.benchmark_cmd[0]) { /* If no benchmark is given by "-b" argument, use fill_buf. */ - benchmark_cmd[0] = "fill_buf"; + uparams.benchmark_cmd[0] = "fill_buf"; ret = asprintf(&span_str, "%u", DEFAULT_SPAN); if (ret < 0) ksft_exit_fail_msg("Out of memory!\n"); - benchmark_cmd[1] = span_str; - benchmark_cmd[2] = "1"; - benchmark_cmd[3] = "0"; - benchmark_cmd[4] = "false"; - benchmark_cmd[5] = NULL; + uparams.benchmark_cmd[1] = span_str; + uparams.benchmark_cmd[2] = "1"; + uparams.benchmark_cmd[3] = "0"; + uparams.benchmark_cmd[4] = "false"; + uparams.benchmark_cmd[5] = NULL; } ksft_set_plan(tests ? : 4); if (mbm_test) - run_mbm_test(benchmark_cmd, cpu_no); + run_mbm_test(&uparams); if (mba_test) - run_mba_test(benchmark_cmd, cpu_no); + run_mba_test(&uparams); if (cmt_test) - run_cmt_test(benchmark_cmd, cpu_no); + run_cmt_test(&uparams); if (cat_test) - run_cat_test(cpu_no, no_of_bits); + run_cat_test(&uparams); free(span_str); ksft_finished(); From patchwork Tue Oct 24 09:26:28 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: 157337 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1820915vqx; Tue, 24 Oct 2023 02:31:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfEEqnrWWVLNqJ5cVoPpO3zP96tb7m3wEW1Xgh1w0B892JWZNFj4vwjLuQDkDyVKZ2weE5 X-Received: by 2002:a05:6830:910:b0:6b9:c4b1:7a86 with SMTP id v16-20020a056830091000b006b9c4b17a86mr15145837ott.3.1698139888665; Tue, 24 Oct 2023 02:31:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139888; cv=none; d=google.com; s=arc-20160816; b=XQqc2bj4boAU/lU6Bqq8K5svtzwIQT9wTkOjcV2cXoBu7UFQR2yN9fZLO1Q9ffHzvB qcqOMjSjMbxnMU6tCprESF9TeVtX/AcoPrRm7XOhcStWvExqvNoaBiYq2TK9DIe0LNuT KVhF6+y4GMuQEQQSe7N23Z7KepF3Xx+Tcxzp8Q1O4oSroIi+XRAT4qvJkky+KDzydN2B 2Yg+Q4Gsx6m2NQwInTO7QJyjhsMkiN6TkIjIp+n236mbIxGoV/MoxW87QUym3gj6PRxq xCP+3zQeaeYQYJucyQsrc+0zvbEojrOl5WTffOC0+BKN9hjHvk0s5QifN6zDgEKZXdjH P84Q== 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=rXAyZVRNmPjXKBLRRvbOmWA2VrzP+G89Qt/cjv7tqK8=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=QiB80Kw8GsMC9zE4cIJJ8ichbgnL02j8oAhU0IBKoQN+RbM5z1aJb1CKMkuzmzHF+v AnC3zT2whE/bApd8wUP6YmvBOt6t5hfnQDUVymcRucWYXezWZEQ4L4XmldIY0P9Z/sbh RbYkI43YTiMgsUsBm7vM5FMjQCIkLg2LgfE8UGPtQHfUkEx90bekHJVjzvM7jIZH4R6U G8opHeGra1jL4nPbdTxNN2JB8FCliGNuoy4rC375pWXeQkZtoWQkM1JJNKpfec50TH4T 0SRapChzfxXFJBaU/FvOKRfgPNElbbN6ylAUKsHGYLeHk1uWVciV/L3a6DB5WrFYuWNl LPVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GvGdPVOr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id e22-20020a633716000000b005898d64820esi7885069pga.322.2023.10.24.02.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:31:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GvGdPVOr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id C66A980A73DD; Tue, 24 Oct 2023 02:31:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234216AbjJXJam (ORCPT + 26 others); Tue, 24 Oct 2023 05:30:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234344AbjJXJaL (ORCPT ); Tue, 24 Oct 2023 05:30:11 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D25741BFE; Tue, 24 Oct 2023 02:29:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139760; x=1729675760; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PNbEoz6PsZZon68ieYxIqS4az+Y7/8ZTMsZomZlq2P0=; b=GvGdPVOriRysUx3pMchhVFGlnlnp8qA7U+8gOQhYOXJ89uaSDKEYwlXr gqWjXuQF+O9n2jAtAcA8nhdQIuSRkC9XTTCp4YamPkTVdaOCO4LQn9nu9 49xTywhKv5wPHvLT1L4x2PQV2bWv7JFU8uInnfQDXySQmFywXExb4N0D5 AN+w1Eis4Ke123qSAQLI6T6B7x9HK9HBQ0nggnt0ElJcT/wTxsASlCf0b DBSyjBWIg+cv5qGNywo1Ed+ycMCnj6V4c1sgI5GKm6JYCYDx1JlPqko4o bPnKt4QMmj5t0cIHVlmm3m2PZ1QY2T6V6B4wcaH7E0CvJpjL8adx+bcl7 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="386829675" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="386829675" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="793425148" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="793425148" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:16 -0700 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 18/24] selftests/resctrl: Introduce generalized test framework Date: Tue, 24 Oct 2023 12:26:28 +0300 Message-Id: <20231024092634.7122-19-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 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 morse.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 (morse.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:31:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628731432564480 X-GMAIL-MSGID: 1780628731432564480 Each test currently has a "run test" function in per test file and another resctrl_tests.c. The functions in resctrl_tests.c are almost identical. Generalize the one in resctrl_tests.c such that it can be shared between all of the tests. It makes adding new tests easier and removes the per test if () forests. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cat_test.c | 18 +- tools/testing/selftests/resctrl/cmt_test.c | 17 +- tools/testing/selftests/resctrl/mba_test.c | 16 +- tools/testing/selftests/resctrl/mbm_test.c | 18 +- tools/testing/selftests/resctrl/resctrl.h | 31 +++- .../testing/selftests/resctrl/resctrl_tests.c | 160 ++++++------------ tools/testing/selftests/resctrl/resctrlfs.c | 5 + 7 files changed, 144 insertions(+), 121 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 1a70c69e5f7c..aa16fb36d0d4 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -218,7 +218,7 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long goto free_buf; } -int cat_perf_miss_val(const struct user_params *uparams, char *cache_type) +static int cat_run_test(const struct resctrl_test *test, const struct user_params *uparams) { unsigned long long_mask, start_mask, full_cache_mask; unsigned long cache_total_size = 0; @@ -229,16 +229,16 @@ int cat_perf_miss_val(const struct user_params *uparams, char *cache_type) int ret; /* Get default cbm mask for L3/L2 cache */ - ret = get_cbm_mask(cache_type, &full_cache_mask); + ret = get_cbm_mask(test->resource, &full_cache_mask); if (ret) return ret; /* Get the exclusive portion of the cache */ - ret = get_mask_no_shareable(cache_type, &long_mask); + ret = get_mask_no_shareable(test->resource, &long_mask); if (ret) return ret; /* Get L3/L2 cache size */ - ret = get_cache_size(uparams->cpu, cache_type, &cache_total_size); + ret = get_cache_size(uparams->cpu, test->resource, &cache_total_size); if (ret) return ret; ksft_print_msg("Cache size :%lu\n", cache_total_size); @@ -272,9 +272,17 @@ int cat_perf_miss_val(const struct user_params *uparams, char *cache_type) if (ret) goto out; - ret = check_results(¶m, cache_type, cache_total_size, full_cache_mask, start_mask); + ret = check_results(¶m, test->resource, + cache_total_size, full_cache_mask, start_mask); out: cat_test_cleanup(); return ret; } + +struct resctrl_test l3_cat_test = { + .name = "CAT", + .resource = "L3", + .feature_check = test_resource_feature_check, + .run_test = cat_run_test, +}; diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c index f5561b79629f..353c4bae2cfe 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -94,7 +94,7 @@ void cmt_test_cleanup(void) remove(RESULT_FILE_NAME); } -int cmt_resctrl_val(const struct user_params *uparams) +static int cmt_run_test(const struct resctrl_test *test, const struct user_params *uparams) { const char * const *cmd = uparams->benchmark_cmd; const char *new_cmd[BENCHMARK_ARGS]; @@ -156,6 +156,8 @@ int cmt_resctrl_val(const struct user_params *uparams) goto out; ret = check_results(¶m, span, n); + if (ret && (get_vendor() == ARCH_INTEL)) + ksft_print_msg("Intel CMT may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n"); out: cmt_test_cleanup(); @@ -163,3 +165,16 @@ int cmt_resctrl_val(const struct user_params *uparams) return ret; } + +static bool cmt_feature_check(const struct resctrl_test *test) +{ + return validate_resctrl_feature_request("L3_MON", "llc_occupancy") && + validate_resctrl_feature_request("L3", NULL); +} + +struct resctrl_test cmt_test = { + .name = "CMT", + .resource = "L3", + .feature_check = cmt_feature_check, + .run_test = cmt_run_test, +}; diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c index 5157a3f74fee..722f94013cb9 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -141,7 +141,7 @@ void mba_test_cleanup(void) remove(RESULT_FILE_NAME); } -int mba_schemata_change(const struct user_params *uparams) +static int mba_run_test(const struct resctrl_test *test, const struct user_params *uparams) { struct resctrl_val_param param = { .resctrl_val = MBA_STR, @@ -167,3 +167,17 @@ int mba_schemata_change(const struct user_params *uparams) return ret; } + +static bool mba_feature_check(const struct resctrl_test *test) +{ + return test_resource_feature_check(test) && + validate_resctrl_feature_request("L3_MON", "mbm_local_bytes"); +} + +struct resctrl_test mba_test = { + .name = "MBA", + .resource = "MB", + .vendor_specific = ARCH_INTEL, + .feature_check = mba_feature_check, + .run_test = mba_run_test, +}; diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c index 98df9d151941..943f4f14a499 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -109,7 +109,7 @@ void mbm_test_cleanup(void) remove(RESULT_FILE_NAME); } -int mbm_bw_change(const struct user_params *uparams) +static int mbm_run_test(const struct resctrl_test *test, const struct user_params *uparams) { struct resctrl_val_param param = { .resctrl_val = MBM_STR, @@ -129,9 +129,25 @@ int mbm_bw_change(const struct user_params *uparams) goto out; ret = check_results(DEFAULT_SPAN); + if (ret && (get_vendor() == ARCH_INTEL)) + ksft_print_msg("Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n"); out: mbm_test_cleanup(); return ret; } + +static bool mbm_feature_check(const struct resctrl_test *test) +{ + return validate_resctrl_feature_request("L3_MON", "mbm_total_bytes") && + validate_resctrl_feature_request("L3_MON", "mbm_local_bytes"); +} + +struct resctrl_test mbm_test = { + .name = "MBM", + .resource = "MB", + .vendor_specific = ARCH_INTEL, + .feature_check = mbm_feature_check, + .run_test = mbm_run_test, +}; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index ec6efd36f60a..e017adf1390d 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -37,6 +37,8 @@ #define DEFAULT_SPAN (250 * MB) +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + #define PARENT_EXIT(err_msg) \ do { \ perror(err_msg); \ @@ -57,6 +59,25 @@ struct user_params { const char *benchmark_cmd[BENCHMARK_ARGS]; }; +/* + * resctrl_test: resctrl test definition + * @name: Test name + * @resource: Resource to test (e.g., MB, L3, L2, etc.) + * @vendor_specific: Bitmask for vendor-specific tests (can be 0 for universal tests) + * @disabled: Test is disabled + * @feature_check: Callback to check required resctrl features + * @run_test: Callback to run the test + */ +struct resctrl_test { + const char *name; + const char *resource; + unsigned int vendor_specific; + bool disabled; + bool (*feature_check)(const struct resctrl_test *test); + int (*run_test)(const struct resctrl_test *test, + const struct user_params *uparams); +}; + /* * resctrl_val_param: resctrl test parameters * @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc) @@ -103,6 +124,7 @@ int mount_resctrlfs(void); int umount_resctrlfs(void); int validate_bw_report_request(char *bw_report); bool validate_resctrl_feature_request(const char *resource, const char *feature); +bool test_resource_feature_check(const struct resctrl_test *test); char *fgrep(FILE *inf, const char *str); int taskset_benchmark(pid_t bm_pid, int cpu_no); int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, @@ -116,10 +138,8 @@ void mem_flush(unsigned char *buf, size_t buf_size); int fill_cache_read(unsigned char *buf, size_t buf_size, 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(const struct user_params *uparams); void tests_cleanup(void); void mbm_test_cleanup(void); -int mba_schemata_change(const struct user_params *uparams); void mba_test_cleanup(void); unsigned long create_bit_mask(unsigned int start, unsigned int len); unsigned int count_contiguous_bits(unsigned long val, unsigned int *start); @@ -131,8 +151,6 @@ void ctrlc_handler(int signum, siginfo_t *info, void *ptr); int signal_handler_register(void); void signal_handler_unregister(void); void cat_test_cleanup(void); -int cat_perf_miss_val(const struct user_params *uparams, char *cache_type); -int cmt_resctrl_val(const struct user_params *uparams); unsigned int count_bits(unsigned long n); void cmt_test_cleanup(void); @@ -158,4 +176,9 @@ static inline int cache_size(unsigned long cache_size, unsigned long mask, return cache_size * count_bits(mask) / count_bits(cache_mask); } +extern struct resctrl_test mbm_test; +extern struct resctrl_test mba_test; +extern struct resctrl_test cmt_test; +extern struct resctrl_test l3_cat_test; + #endif /* RESCTRL_H */ diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 8e00ccc2b2f6..7846260e3f68 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -10,6 +10,13 @@ */ #include "resctrl.h" +static struct resctrl_test *resctrl_tests[] = { + &mbm_test, + &mba_test, + &cmt_test, + &l3_cat_test, +}; + static int detect_vendor(void) { FILE *inf = fopen("/proc/cpuinfo", "r"); @@ -49,11 +56,16 @@ int get_vendor(void) static void cmd_help(void) { + int i; + printf("usage: resctrl_tests [-h] [-t test list] [-n no_of_bits] [-b benchmark_cmd [option]...]\n"); printf("\t-b benchmark_cmd [option]...: run specified benchmark for MBM, MBA and CMT\n"); printf("\t default benchmark is builtin fill_buf\n"); printf("\t-t test list: run tests specified in the test list, "); printf("e.g. -t mbm,mba,cmt,cat\n"); + printf("\t\tSupported tests:\n"); + for (i = 0; i < ARRAY_SIZE(resctrl_tests); i++) + printf("\t\t\t%s\n", resctrl_tests[i]->name); printf("\t-n no_of_bits: run cache tests using specified no of bits in cache bit mask\n"); printf("\t-p cpu_no: specify CPU number to run the test. 1 is default\n"); printf("\t-h: help\n"); @@ -92,102 +104,41 @@ static void test_cleanup(void) signal_handler_unregister(); } -static void run_mbm_test(const struct user_params *uparams) +static bool test_vendor_specific_check(const struct resctrl_test *test) { - int res; - - ksft_print_msg("Starting MBM BW change ...\n"); - - if (test_prepare()) { - ksft_exit_fail_msg("Abnormal failure when preparing for the test\n"); - return; - } - - if (!validate_resctrl_feature_request("L3_MON", "mbm_total_bytes") || - !validate_resctrl_feature_request("L3_MON", "mbm_local_bytes") || - (get_vendor() != ARCH_INTEL)) { - ksft_test_result_skip("Hardware does not support MBM or MBM is disabled\n"); - goto cleanup; - } - - res = mbm_bw_change(uparams); - ksft_test_result(!res, "MBM: bw change\n"); - if ((get_vendor() == ARCH_INTEL) && res) - ksft_print_msg("Intel MBM may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n"); + if (!test->vendor_specific) + return true; -cleanup: - test_cleanup(); + return get_vendor() & test->vendor_specific; } -static void run_mba_test(const struct user_params *uparams) +static void run_single_test(const struct resctrl_test *test, const struct user_params *uparams) { - int res; - - ksft_print_msg("Starting MBA Schemata change ...\n"); + int ret; - if (test_prepare()) { - ksft_exit_fail_msg("Abnormal failure when preparing for the test\n"); + if (test->disabled) return; - } - if (!validate_resctrl_feature_request("MB", NULL) || - !validate_resctrl_feature_request("L3_MON", "mbm_local_bytes") || - (get_vendor() != ARCH_INTEL)) { - ksft_test_result_skip("Hardware does not support MBA or MBA is disabled\n"); - goto cleanup; - } - - res = mba_schemata_change(uparams); - ksft_test_result(!res, "MBA: schemata change\n"); - -cleanup: - test_cleanup(); -} - -static void run_cmt_test(const struct user_params *uparams) -{ - int res; - - ksft_print_msg("Starting CMT test ...\n"); - - if (test_prepare()) { - ksft_exit_fail_msg("Abnormal failure when preparing for the test\n"); + if (!test_vendor_specific_check(test)) { + ksft_test_result_skip("Hardware does not support %s\n", test->name); return; } - if (!validate_resctrl_feature_request("L3_MON", "llc_occupancy") || - !validate_resctrl_feature_request("L3", NULL)) { - ksft_test_result_skip("Hardware does not support CMT or CMT is disabled\n"); - goto cleanup; - } - - res = cmt_resctrl_val(uparams); - ksft_test_result(!res, "CMT: test\n"); - if ((get_vendor() == ARCH_INTEL) && res) - ksft_print_msg("Intel CMT may be inaccurate when Sub-NUMA Clustering is enabled. Check BIOS configuration.\n"); - -cleanup: - test_cleanup(); -} - -static void run_cat_test(const struct user_params *uparams) -{ - int res; - - ksft_print_msg("Starting CAT test ...\n"); + ksft_print_msg("Starting %s test ...\n", test->name); if (test_prepare()) { ksft_exit_fail_msg("Abnormal failure when preparing for the test\n"); return; } - if (!validate_resctrl_feature_request("L3", NULL)) { - ksft_test_result_skip("Hardware does not support CAT or CAT is disabled\n"); + if (!test->feature_check(test)) { + ksft_test_result_skip("Hardware does not support %s or %s is disabled\n", + test->name, test->name); goto cleanup; } - res = cat_perf_miss_val(uparams, "L3"); - ksft_test_result(!res, "CAT: test\n"); + ret = test->run_test(test, uparams); + ksft_test_result(!ret, "%s: test\n", test->name); cleanup: test_cleanup(); @@ -201,11 +152,10 @@ static void init_user_params(struct user_params *uparams) int main(int argc, char **argv) { - bool mbm_test = true, mba_test = true, cmt_test = true; + int tests = ARRAY_SIZE(resctrl_tests); struct user_params uparams = {}; + bool test_param_seen = false; char *span_str = NULL; - bool cat_test = true; - int tests = 0; int ret, c, i; init_user_params(&uparams); @@ -233,25 +183,26 @@ int main(int argc, char **argv) case 't': token = strtok(optarg, ","); - mbm_test = false; - mba_test = false; - cmt_test = false; - cat_test = false; + if (!test_param_seen) { + for (i = 0; i < ARRAY_SIZE(resctrl_tests); i++) + resctrl_tests[i]->disabled = true; + tests = 0; + test_param_seen = true; + } while (token) { - if (!strncmp(token, MBM_STR, sizeof(MBM_STR))) { - mbm_test = true; - tests++; - } else if (!strncmp(token, MBA_STR, sizeof(MBA_STR))) { - mba_test = true; - tests++; - } else if (!strncmp(token, CMT_STR, sizeof(CMT_STR))) { - cmt_test = true; - tests++; - } else if (!strncmp(token, CAT_STR, sizeof(CAT_STR))) { - cat_test = true; - tests++; - } else { - printf("invalid argument\n"); + bool found = false; + + for (i = 0; i < ARRAY_SIZE(resctrl_tests); i++) { + if (!strcasecmp(token, resctrl_tests[i]->name)) { + if (resctrl_tests[i]->disabled) + tests++; + resctrl_tests[i]->disabled = false; + found = true; + } + } + + if (!found) { + printf("invalid test: %s\n", token); return -1; } @@ -311,19 +262,10 @@ int main(int argc, char **argv) uparams.benchmark_cmd[5] = NULL; } - ksft_set_plan(tests ? : 4); - - if (mbm_test) - run_mbm_test(&uparams); - - if (mba_test) - run_mba_test(&uparams); - - if (cmt_test) - run_cmt_test(&uparams); + ksft_set_plan(tests); - if (cat_test) - run_cat_test(&uparams); + for (i = 0; i < ARRAY_SIZE(resctrl_tests); i++) + run_single_test(resctrl_tests[i], &uparams); free(span_str); ksft_finished(); diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index c8fbbd96311d..2851ffe64b56 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -673,6 +673,11 @@ bool validate_resctrl_feature_request(const char *resource, const char *feature) return !!res; } +bool test_resource_feature_check(const struct resctrl_test *test) +{ + return validate_resctrl_feature_request(test->resource, NULL); +} + int filter_dmesg(void) { char line[1024]; From patchwork Tue Oct 24 09:26:29 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: 157341 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1821213vqx; Tue, 24 Oct 2023 02:32:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgGItSQ9EtVpEWdAYkWWHttQBgym7r8fBKyX1yM8i5NXT62MaeWCzkQMl6v85aznBKNux2 X-Received: by 2002:a17:902:f550:b0:1ca:8541:e1ea with SMTP id h16-20020a170902f55000b001ca8541e1eamr10141948plf.0.1698139933482; Tue, 24 Oct 2023 02:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139933; cv=none; d=google.com; s=arc-20160816; b=wZQQomfbdIis8nI50x2EEiWuEgYG+Fg+p5SanK0jmkRrD9Ucq7llZ9rSlOOeXqqpCc GgFMggltLnqlueVV+3C6pIc81ejHxdDxjSal1VhdJ4NkYCFPJiUEdWudcdpClKsRXArW ymw1A2I5pGD0JEXMNa5oc55YGIpYFCy8EownQ4Qg3DW4mdZxyZIGH31Woh8pxDthOeyU 0KZWgP4wMbFnhGuDBiX9Lc3ohaCOjBCsBrmd+3LGNGAywDALO6WyFQ+LISVckCJCvKGF Y0wMCohhTy9kSSTSlDlzpbOFeLqmiQKdYn9ncaB+ID4hAgZo/ekHe7wb7b6vQoEtiDzl 596Q== 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=VDLn3UB3McjjD3OX/iwGk5ioPJR23p5T++Nc2TMekmc=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=pYGSXa8CHEqWiGhxHlaPvkbR81D2+VPB2LPFnaJzt6ux1ZeFN3iXykV7kbqU9vDj/D +HfsbWJxLgf+50mmd4Lf+oEUVWOswT5XmUzD3MiOy2UpDt/U3z/4p4cQ6g1znfa0qvJN 4hPk07zi0FnGY2RVngoO+wrwhZCLRiICvA8nggrmVke8Ks51XPRgdxt+qUmVwdxttuHK +5EnMeaAHwHanYeCU4g6jCwJTxyciYZeXGYyHbSE9Z6fHZOArXI6xiK19souf3Sx/+ro YUaJJAkuUBfdLBPoi1IPvmTyODR2Zw0OXszgtpD1BEDRZauQW7F7kW1QwWozDf2y+4Ws D14g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VPJvU8tv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id j13-20020a170903024d00b001c9ad75c067si8483673plh.149.2023.10.24.02.32.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:32:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VPJvU8tv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id E21D2806E173; Tue, 24 Oct 2023 02:32:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234365AbjJXJbC (ORCPT + 26 others); Tue, 24 Oct 2023 05:31:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234097AbjJXJaa (ORCPT ); Tue, 24 Oct 2023 05:30:30 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3843E171B; Tue, 24 Oct 2023 02:29:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139770; x=1729675770; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1dKoblTeQO3QQEOUxi7HkAa6k1k7lIw733imvwKBgio=; b=VPJvU8tveLQl7rvkAnFy5PMVNuPCJbUYyyROnFIhp80DJ8LmVSfY9Oud MaCFcvrVkfUEzmE+3mlDKYcL184blhwtdum4zQsbpRkyU3Dq5/P3Kq/a5 /Vq2QiW5VWrXhY+3m4snj5o61UHychoHnPDwh6Pz1fLkzwKjPzqqyWFbm Hx9WVwFVP321ZnZrZBJ1KUkVJe+cndob5BqOk7vKWJJR4ssht3aM8j/SP YD34NWGU9A5MJXZJOee7uiaCxhb1Y+S/Z8J7jmhM1FjUVrI4BMCH6yrBc hyVjkWw7oUSo4rwlV5kl37DLJ4V19cYT6aTkI1GILRCawze9yUICNkmVG A==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="418145199" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="418145199" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="734972643" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="734972643" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:24 -0700 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 19/24] selftests/resctrl: Pass write_schemata() resource instead of test name Date: Tue, 24 Oct 2023 12:26:29 +0300 Message-Id: <20231024092634.7122-20-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 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 howler.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 (howler.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:32:09 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628778737647155 X-GMAIL-MSGID: 1780628778737647155 write_schemata() currently takes the test name as an argument and determines the relevant resource based on the test name. L2 CAT test needs to set schemata for both L3 and L2 CAT which would get complicated using the current approach. Pass a resource instead of test name to write_schemata() to allow more than one resource be set per test name. While touching the sprintf(), move the unnecessary %c that is always '=' directly into the format string. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cat_test.c | 9 +++++---- tools/testing/selftests/resctrl/cmt_test.c | 1 + tools/testing/selftests/resctrl/mba_test.c | 4 ++-- tools/testing/selftests/resctrl/mbm_test.c | 4 ++-- tools/testing/selftests/resctrl/resctrl.h | 5 +++-- tools/testing/selftests/resctrl/resctrlfs.c | 22 +++++---------------- 6 files changed, 18 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index aa16fb36d0d4..1ef047cadf4c 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -142,7 +142,8 @@ void cat_test_cleanup(void) * * Return: 0 on success. non-zero on failure. */ -static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long current_mask) +static int cat_test(struct resctrl_val_param *param, const char *resource, + size_t span, unsigned long current_mask) { char *resctrl_val = param->resctrl_val; static struct perf_event_read pe_read; @@ -177,11 +178,11 @@ static int cat_test(struct resctrl_val_param *param, size_t span, unsigned long while (current_mask) { snprintf(schemata, sizeof(schemata), "%lx", param->mask & ~current_mask); - ret = write_schemata("", schemata, param->cpu_no, param->resctrl_val); + ret = write_schemata("", schemata, param->cpu_no, resource); if (ret) goto free_buf; snprintf(schemata, sizeof(schemata), "%lx", current_mask); - ret = write_schemata(param->ctrlgrp, schemata, param->cpu_no, param->resctrl_val); + ret = write_schemata(param->ctrlgrp, schemata, param->cpu_no, resource); if (ret) goto free_buf; @@ -268,7 +269,7 @@ static int cat_run_test(const struct resctrl_test *test, const struct user_param remove(param.filename); - ret = cat_test(¶m, span, start_mask); + ret = cat_test(¶m, test->resource, span, start_mask); if (ret) goto out; diff --git a/tools/testing/selftests/resctrl/cmt_test.c b/tools/testing/selftests/resctrl/cmt_test.c index 353c4bae2cfe..b0825d654dcf 100644 --- a/tools/testing/selftests/resctrl/cmt_test.c +++ b/tools/testing/selftests/resctrl/cmt_test.c @@ -125,6 +125,7 @@ static int cmt_run_test(const struct resctrl_test *test, const struct user_param struct resctrl_val_param param = { .resctrl_val = CMT_STR, + .resource = "L3", .ctrlgrp = "c1", .mongrp = "m1", .cpu_no = uparams->cpu, diff --git a/tools/testing/selftests/resctrl/mba_test.c b/tools/testing/selftests/resctrl/mba_test.c index 722f94013cb9..a14b7f4466e5 100644 --- a/tools/testing/selftests/resctrl/mba_test.c +++ b/tools/testing/selftests/resctrl/mba_test.c @@ -40,8 +40,7 @@ static int mba_setup(struct resctrl_val_param *p) sprintf(allocation_str, "%d", allocation); - ret = write_schemata(p->ctrlgrp, allocation_str, p->cpu_no, - p->resctrl_val); + ret = write_schemata(p->ctrlgrp, allocation_str, p->cpu_no, p->resource); if (ret < 0) return ret; @@ -145,6 +144,7 @@ static int mba_run_test(const struct resctrl_test *test, const struct user_param { struct resctrl_val_param param = { .resctrl_val = MBA_STR, + .resource = "MB", .ctrlgrp = "c1", .mongrp = "m1", .cpu_no = uparams->cpu, diff --git a/tools/testing/selftests/resctrl/mbm_test.c b/tools/testing/selftests/resctrl/mbm_test.c index 943f4f14a499..1ad2c1a7fddb 100644 --- a/tools/testing/selftests/resctrl/mbm_test.c +++ b/tools/testing/selftests/resctrl/mbm_test.c @@ -96,8 +96,7 @@ static int mbm_setup(struct resctrl_val_param *p) /* Set up shemata with 100% allocation on the first run. */ if (p->num_of_runs == 0 && validate_resctrl_feature_request("MB", NULL)) - ret = write_schemata(p->ctrlgrp, "100", p->cpu_no, - p->resctrl_val); + ret = write_schemata(p->ctrlgrp, "100", p->cpu_no, p->resource); p->num_of_runs++; @@ -113,6 +112,7 @@ static int mbm_run_test(const struct resctrl_test *test, const struct user_param { struct resctrl_val_param param = { .resctrl_val = MBM_STR, + .resource = "MB", .ctrlgrp = "c1", .mongrp = "m1", .cpu_no = uparams->cpu, diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index e017adf1390d..99fbce4794bc 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -81,6 +81,7 @@ struct resctrl_test { /* * resctrl_val_param: resctrl test parameters * @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc) + * @resource: Resource to test (e.g., MB, L3, L2, etc.) * @ctrlgrp: Name of the control monitor group (con_mon grp) * @mongrp: Name of the monitor group (mon grp) * @cpu_no: CPU number to which the benchmark would be binded @@ -90,6 +91,7 @@ struct resctrl_test { */ struct resctrl_val_param { char *resctrl_val; + char *resource; char ctrlgrp[64]; char mongrp[64]; int cpu_no; @@ -127,8 +129,7 @@ bool validate_resctrl_feature_request(const char *resource, const char *feature) bool test_resource_feature_check(const struct resctrl_test *test); char *fgrep(FILE *inf, const char *str); int taskset_benchmark(pid_t bm_pid, int cpu_no); -int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, - char *resctrl_val); +int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, const char *resource); 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, diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 2851ffe64b56..7d72bea3ed58 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -496,23 +496,17 @@ int write_bm_pid_to_resctrl(pid_t bm_pid, char *ctrlgrp, char *mongrp, * @ctrlgrp: Name of the con_mon grp * @schemata: Schemata that should be updated to * @cpu_no: CPU number that the benchmark PID is binded to - * @resctrl_val: Resctrl feature (Eg: mbm, mba.. etc) + * @resource: Resctrl resource (Eg: MB, L3, L2, etc.) * * Update schemata of a con_mon grp *only* if requested resctrl feature is * allocation type * * Return: 0 on success, non-zero on failure */ -int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val) +int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, const char *resource) { char controlgroup[1024], reason[128], schema[1024] = {}; - int resource_id, fd, schema_len = -1, ret = 0; - - if (strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)) && - strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR)) && - strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR)) && - strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) - return -ENOENT; + int resource_id, fd, schema_len, ret = 0; if (!schemata) { ksft_print_msg("Skipping empty schemata update\n"); @@ -532,14 +526,8 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, char *resctrl_val) else sprintf(controlgroup, "%s/schemata", RESCTRL_PATH); - if (!strncmp(resctrl_val, CAT_STR, sizeof(CAT_STR)) || - !strncmp(resctrl_val, CMT_STR, sizeof(CMT_STR))) - schema_len = snprintf(schema, sizeof(schema), "%s%d%c%s\n", - "L3:", resource_id, '=', schemata); - if (!strncmp(resctrl_val, MBA_STR, sizeof(MBA_STR)) || - !strncmp(resctrl_val, MBM_STR, sizeof(MBM_STR))) - schema_len = snprintf(schema, sizeof(schema), "%s%d%c%s\n", - "MB:", resource_id, '=', schemata); + schema_len = snprintf(schema, sizeof(schema), "%s:%d=%s\n", + resource, resource_id, schemata); if (schema_len < 0 || schema_len >= sizeof(schema)) { snprintf(reason, sizeof(reason), "snprintf() failed with return value : %d", schema_len); From patchwork Tue Oct 24 09:26:30 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: 157345 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1821379vqx; Tue, 24 Oct 2023 02:32:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH72M3MoIxDIlJkqbG9gyFBJHag0WGJ+ozslQBTnhH6Ep1OilvDUc92fsgo6J/RsoI11nQf X-Received: by 2002:a17:902:d502:b0:1c9:dd73:dc9e with SMTP id b2-20020a170902d50200b001c9dd73dc9emr8858594plg.44.1698139957645; Tue, 24 Oct 2023 02:32:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139957; cv=none; d=google.com; s=arc-20160816; b=vpDiHFOSPF3KpiWMTqu6zUdytg1FKANJomWzCufsrBSw4lkLXRCP30jtVLirkJ2C7V A/Ed/L+pPMCSHO9Neo0p6sMXmPGgrtHBlbuh+mKzLmqF9RLdaRG/xDjJWsCBghddUYnJ nQH3YMLLQI3YTfg6BfqdNoCy+BpWsLGTNgLL9tNR9rat9yM0feS+dNdKI9kTdosNnFdM zKJREkmxK0z6L7Kf/11bqhs0R2EcONZU5Uf5g8sXQg6O4KtlShdkWMAUIChl0pFMydVt /P/7oKw3mxgU/R65gpa5P6m0Z53l0JmjzTi2q/n7fkU+HTzK6xrXqk8YsaNSh9BnA2LI Nlag== 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=T15KGgFfJzBK/PeAvviq25UxeKBNz9dIM9srLo0F8CQ=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=BVFq2/KTYB9+rLL0bDbvrXHbIAjzXR9HOiImXbcA8YDKI8AIUpC0ZshKbxaxRcxFOi +qe6i4QtaNvvrD01+bTgtYw//rpJHVL0GraLqs4PBJLMojkh5U9GoLPO998pu1BfPXUB 8RVbqTw8kYJA7H4tatRMRFLuDuhihj/nzdxInDvoR3Jo5Mdj78YyQ2Pr3hog7UCFUQ66 kDaBKiffiIk2Cxf6boOmoiHfr7FvMPN8yBLBGQwCYfUGigMdhSC/S0mBDS71jaIcEL6K q+i6Koc+J6e0bArXZdLN3MmSnMHvZmio4WqFVry+9q76yZ8luicSmpIF1NprtD7h4q0q l59g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DewtULf3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id o17-20020a170902d4d100b001c0cbaf6970si8168418plg.501.2023.10.24.02.32.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:32:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DewtULf3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 90AAB806E4FE; Tue, 24 Oct 2023 02:32:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234267AbjJXJbZ (ORCPT + 26 others); Tue, 24 Oct 2023 05:31:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234308AbjJXJaz (ORCPT ); Tue, 24 Oct 2023 05:30:55 -0400 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AB12171E; Tue, 24 Oct 2023 02:29:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139777; x=1729675777; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3vy9fAeuuxL3PMPYGchCQGLED1dgGOCzucRm1jFBvV8=; b=DewtULf3PDupkB1w4Ti8UBZOcYO8gIWvF3Atv3MCzQpJYPceQN4Y3e+7 jByE4taRbnB5JQ068flvqeO+cxWtQN1jQnDQF8jFC2pzcTXbyOs4IG5Ub BZtFEYBWrVNVvm6XY7AJilKqR+I4wxrV2D+dJ5qndJf+jM9Cc4Yo7WQq6 KYacQmJqtEjh+ZxruGvJ971QLzIkw9FWNeGxM63kjKARHR365EouNeH41 k/YAC9DkWEghKYMmt0DfrjnibltCxXhbnKxlnRN3eGbJ1uD+FQQMd6HIC 6/xdfNv/AI1qfgl1XKoXlYEpfwLjlWJ5MJLC+dEXihBunBIc4nDBn/OXm w==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="5644362" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="5644362" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="758410117" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="758410117" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:33 -0700 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 20/24] selftests/resctrl: Add helper to convert L2/3 to integer Date: Tue, 24 Oct 2023 12:26:30 +0300 Message-Id: <20231024092634.7122-21-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 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 groat.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 (groat.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:32:30 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628804006498409 X-GMAIL-MSGID: 1780628804006498409 "L2"/"L3" conversion to integer in embedded into get_cache_size() which prevents reuse. Create a helper for the cache string to integer conversion to make it reusable. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/resctrlfs.c | 28 +++++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 7d72bea3ed58..b98d88f7cbc4 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -94,6 +94,23 @@ int umount_resctrlfs(void) return 0; } +/* + * get_cache_level - Convert cache level from string to integer + * @cache_type: Cache level as string + * + * Return: cache level as integer or -1 if @cache_type is invalid. + */ +static int get_cache_level(const char *cache_type) +{ + if (!strcmp(cache_type, "L3")) + return 3; + if (!strcmp(cache_type, "L2")) + return 2; + + perror("Invalid cache level"); + return -1; +} + /* * get_resource_id - Get socket number/l3 id for a specified CPU * @cpu_no: CPU number @@ -144,14 +161,9 @@ int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size int length, i, cache_num; FILE *fp; - if (!strcmp(cache_type, "L3")) { - cache_num = 3; - } else if (!strcmp(cache_type, "L2")) { - cache_num = 2; - } else { - perror("Invalid cache level"); - return -1; - } + cache_num = get_cache_level(cache_type); + if (cache_num < 0) + return cache_num; sprintf(cache_path, "/sys/bus/cpu/devices/cpu%d/cache/index%d/size", cpu_no, cache_num); From patchwork Tue Oct 24 09:26:31 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: 157344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1821368vqx; Tue, 24 Oct 2023 02:32:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFOkhOpGwFP+59qufcVe+PIs94uDcMj2iiCaVGuAUi+H4WU1Aef/Rzw9rNLSuWRZicwabVp X-Received: by 2002:a05:6a00:2ea3:b0:6be:23dd:d62c with SMTP id fd35-20020a056a002ea300b006be23ddd62cmr12587492pfb.2.1698139956568; Tue, 24 Oct 2023 02:32:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139956; cv=none; d=google.com; s=arc-20160816; b=nm3i+UujE6KUI3nPn2edRkHOXVQ44lmGYfyv5bRU9YjrLwQJbeNZlFrBsAXGJF6et+ fK6hExp9EV5gL2HPHakSuGvlq4t2TIUt18g0KRMGIeiPTTEyUaryn1+Rg3jyW8wcOklZ CyesTZZWiHSQ6IDnf/NKIc1Clh/yUWtXtfuR7pONOLc4OQogbHUFdDPainpa4r0mScnM BaCJOrD670jyAzN2bDG115Txc1uYPcyAvWGtWN1AY1HtnWYnlnTzDQl82GjiZ1YBbL/c 7TXZwWskTGE7rVsBcly7eUPgkB4rdGjb9QuotQXM0SsegapVCTsGXyGSl+YLfGNQkZIv 1Nvg== 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=yIwQxDG3aXxcB/+OSSu40N1Uk2v/xLdfeLIP2UAQzIg=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=xqSQGotjKeolofDEKCbXRlsapsn9jbU3wbRsdzLVB6WHBVMeDFbYbt0ZpGc+fIYM+L bIzE7Ejh1Y9rAQqoXTHoBvWiSYfZXjNEFo6Te/U10eFP0dW0li991wlu76b0NQxnvgdj iMpoyBBqK4kSjaZ6ahxrOMsmZeo+Ph3A47KzXzoB9Ds7xRO+7WFHhpFVmQZ8I8uqW74c So35U0SrR/scxlwcPwu3LaiBignx0EWL3mdj3ADbP07Dsn5Di+cgEueV2/yJJ1My0q1O 9LmcMfMw0ZCooZqDIgEKu+VAvYZq+WEBTKODXEtSt3j6UahsKyvuimax740TmfXaCDv3 p/PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Y8omNJPD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id z9-20020aa78889000000b006bc2ccb8256si8398893pfe.257.2023.10.24.02.32.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:32:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Y8omNJPD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 0D4FB80423A6; Tue, 24 Oct 2023 02:32:32 -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 S234181AbjJXJcM (ORCPT + 26 others); Tue, 24 Oct 2023 05:32:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234327AbjJXJa6 (ORCPT ); Tue, 24 Oct 2023 05:30:58 -0400 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9F442120; Tue, 24 Oct 2023 02:29:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139786; x=1729675786; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dO957Gz95d7/4Jry4ZIpp1kdFHUE2wJg6pXZJbwLlmY=; b=Y8omNJPDWX/dyTJpI0/STA7GKxc92HMDZh6uBBEyqNLQPqkME/KM0i2U tOyNTYJYt38UXEbTTWRx/0+wQlLNLPG+DT96ZNFidBBEnbRYSgZ4u4jmM baJFsUeEZxk943otd5D477IFadYGV7AvOHg0sKXgdAlqcSGKbjL4f3H+/ 8tT8FP37e3bP4dBRFsM8kPyHMaquewkBpsQzAvc+0Pg7Vec7asgkEMb8z Uj409o97zwlpsUHKB1aC00Fb8uA2XXmpCCkiR+uiViixBHZawBwedIbzB wiPhgV4oF6ItQuelPvgImBAXFonexpOqwlsYyaybZQLtMoEnNNzu6FdKR Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="5644376" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="5644376" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="758410152" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="758410152" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:41 -0700 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 21/24] selftests/resctrl: Get resource id from cache id Date: Tue, 24 Oct 2023 12:26:31 +0300 Message-Id: <20231024092634.7122-22-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 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:32:32 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628803184041768 X-GMAIL-MSGID: 1780628803184041768 Resource id is acquired differently depending on CPU. AMD tests use id from L3 cache, whereas CPUs from other vendors base the id on topology package id. In order to support L2 CAT test, this has to be generalized. The driver side code seems to get the resource ids from cache ids so the approach used by the AMD branch seems to match the kernel-side code. It will also work with L2 resource IDs as long as the cache level is generalized. Using the topology id was always fragile due to mismatch with the kernel-side way to acquire the resource id. It got incorrect resource id, e.g., when Cluster-on-Die (CoD) is enabled for CPU (but CoD is not well suited for resctrl in the first place so it has not been a big issues if test don't work correctly with it). Taking all the above into account, generalize the resource id calculation by taking it from the cache id and do not hard-code the cache level. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/resctrl.h | 2 +- tools/testing/selftests/resctrl/resctrl_val.c | 4 +-- tools/testing/selftests/resctrl/resctrlfs.c | 31 ++++++++++++------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 99fbce4794bc..c148998bf6ad 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -121,7 +121,7 @@ extern char llc_occup_path[1024]; int get_vendor(void); bool check_resctrlfs_support(void); int filter_dmesg(void); -int get_resource_id(int cpu_no, int *resource_id); +int get_resource_id(const char *resource, int cpu_no, int *resource_id); int mount_resctrlfs(void); int umount_resctrlfs(void); int validate_bw_report_request(char *bw_report); diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index 43ca026c6e0f..d210daafc5af 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -415,7 +415,7 @@ static void initialize_mem_bw_resctrl(const char *ctrlgrp, const char *mongrp, { int resource_id; - if (get_resource_id(cpu_no, &resource_id) < 0) { + if (get_resource_id("MB", cpu_no, &resource_id) < 0) { perror("Could not get resource_id"); return; } @@ -584,7 +584,7 @@ static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *mongrp, { int resource_id; - if (get_resource_id(cpu_no, &resource_id) < 0) { + if (get_resource_id("L3", cpu_no, &resource_id) < 0) { perror("# Unable to resource_id"); return; } diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index b98d88f7cbc4..8e79b646d7cb 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -111,24 +111,33 @@ static int get_cache_level(const char *cache_type) return -1; } +static int get_resource_cache_level(const char *resource) +{ + /* "MB" use L3 (LLC) resource id */ + if (!strcmp(resource, "MB")) + return 3; + return get_cache_level(resource); +} + /* - * get_resource_id - Get socket number/l3 id for a specified CPU - * @cpu_no: CPU number - * @resource_id: Socket number or l3_id + * get_resource_id - Get resctrl resource id for a specified CPU + * @resource: resource + * @cpu_no: CPU number + * @resource_id: resource id (cache id; for MB, L3 cache id) * * Return: >= 0 on success, < 0 on failure. */ -int get_resource_id(int cpu_no, int *resource_id) +int get_resource_id(const char *resource, int cpu_no, int *resource_id) { char phys_pkg_path[1024]; + int cache_num; FILE *fp; - if (get_vendor() == ARCH_AMD) - sprintf(phys_pkg_path, "%s%d/cache/index3/id", - PHYS_ID_PATH, cpu_no); - else - sprintf(phys_pkg_path, "%s%d/topology/physical_package_id", - PHYS_ID_PATH, cpu_no); + cache_num = get_resource_cache_level(resource); + if (cache_num < 0) + return cache_num; + + sprintf(phys_pkg_path, "%s%d/cache/index%d/id", PHYS_ID_PATH, cpu_no, cache_num); fp = fopen(phys_pkg_path, "r"); if (!fp) { @@ -526,7 +535,7 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, const char *resour return -1; } - if (get_resource_id(cpu_no, &resource_id) < 0) { + if (get_resource_id(resource, cpu_no, &resource_id) < 0) { sprintf(reason, "Failed to get resource id"); ret = -1; From patchwork Tue Oct 24 09:26:32 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: 157348 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1821535vqx; Tue, 24 Oct 2023 02:33:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtw0xhepXdgZ2LYajhlT9cAZuutwGyGWn9RVItmddikILZoAQygIN23uTImd3jnNHNpdRg X-Received: by 2002:a17:90a:196:b0:27d:3d1e:1a98 with SMTP id 22-20020a17090a019600b0027d3d1e1a98mr16730950pjc.16.1698139982314; Tue, 24 Oct 2023 02:33:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139982; cv=none; d=google.com; s=arc-20160816; b=jPyRHgx2Fwupqz1TjO9lFNIWBErfYx9s1yciQVFdQATcLi90+GekdyBdGfrGmCAKR1 igi5/iCq6DeOXlnTFdl/XR4BdzN6ZaT/rAgQa+VH4cEtO7yB/WG5tKxhldlwEfCuIMRe 7+qe6gBchVM03FMdQcVjpiAEOXGxuGg6zYf7+N1id/jgQm/gIL+Zhx/rMF2+n1ohUlRb fUpvgMXu6fpcc5gN2+IIJSgFP1K0OTAWd+eiTUisNcEWqgz7ednhcGyAFJIvOT2FhxG/ J98skHGaLlKJYsp+ylKk6z0XNFY96QUAUiLFJZEWcxgSXFbhVe3F7R2CawdWa2UC7cuj gA9w== 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=arD9ICiG9rKGU1TC/Us1CdJ/HwacxdFw/8qTiXJvxCw=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=YUu1RWdVUgeivkuuMS0jtsytEuOFSTLxbsrIRotdFkuIXeyRA5h67B5I6qds9aga2Z NkxeCu2lm5UM40QZhix3qnaituGhem5+Q2G2R75iS0wysEBUpOf/gYYfe7p6qY5lVFrO qm+WfSRCYDeYRfiXvjAgLVEhoU7K40mcEc3/oR6OfPmsjBhQ3ELiDdY6d9bGqO0wu1y+ yWfkQy8r7kb3m3KRIFSUVLO1GKJOLhVvRhXOmYk6O6udwIHxQblj++sL/Hp+c7iwde6/ FlHB/llzehY4XAdB7fvtnoTbL1y4oeRjeya5m9HybAhRc6yBXpRMQ1PR6o51oxZCw1QW 2apw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="jZTkEc/q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id c10-20020a170902c1ca00b001ca4e2a35efsi7842121plc.45.2023.10.24.02.33.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:33:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="jZTkEc/q"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 52DCD804BC1C; Tue, 24 Oct 2023 02:32:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234204AbjJXJcR (ORCPT + 26 others); Tue, 24 Oct 2023 05:32:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234182AbjJXJbP (ORCPT ); Tue, 24 Oct 2023 05:31:15 -0400 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3780C2705; Tue, 24 Oct 2023 02:29:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139794; x=1729675794; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZIUmCvVW4L+pkZbqBv4Kna6ZMFqvsl2rUCxsV99jydw=; b=jZTkEc/q2oDnapkTvXlQ45KmEFAbL7TLrWR2KaagbnJU/rLtzYaNUKPQ OkYsLF0RydkZtQK0Ta3VPPhVJKJI2wXsF4p2DlADJskga8L7aE2bo23pt HFQ9Twnc2fxSubOIboKx6XSuB0UKfhhC4Pjtt3OIugE9OVNdq4Lvqy833 B9rIwxqSo+EV+Vq634w6g1BdJSPNaBWTeESHMtJEgqqu9voj3r+C/Kq/1 F/2BneIk6Vr5AFciNgqfFNGKGv7Q6wQYY3N+lipZvH+WwF0ikGCccsl8U eISLofR75PCwcN2fxthTXusf+UFVal7T3ZjWhhRJ5zmF5lXzLsIb/HFoX Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="5644386" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="5644386" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="758410182" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="758410182" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:50 -0700 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 22/24] selftests/resctrl: Add test groups and name L3 CAT test L3_CAT Date: Tue, 24 Oct 2023 12:26:32 +0300 Message-Id: <20231024092634.7122-23-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 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 howler.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 (howler.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:32:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628829794514037 X-GMAIL-MSGID: 1780628829794514037 To select test to run -t parameter can be used. However, -t cat currently maps to L3 CAT test which is confusing after L2 CAT test is be the next change. Allow selecting tests as groups and call L3 CAT test L3_CAT, "CAT" group will enable to both L3 and L2 CAT tests. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cat_test.c | 3 ++- tools/testing/selftests/resctrl/resctrl.h | 2 ++ tools/testing/selftests/resctrl/resctrl_tests.c | 16 +++++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 1ef047cadf4c..48a96acd9e31 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -282,7 +282,8 @@ static int cat_run_test(const struct resctrl_test *test, const struct user_param } struct resctrl_test l3_cat_test = { - .name = "CAT", + .name = "L3_CAT", + .group = "CAT", .resource = "L3", .feature_check = test_resource_feature_check, .run_test = cat_run_test, diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index c148998bf6ad..f9a4cfd981f8 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -62,6 +62,7 @@ struct user_params { /* * resctrl_test: resctrl test definition * @name: Test name + * @group: Test group (e.g., L2 and L3 CAT test belong to CAT group), can be NULL * @resource: Resource to test (e.g., MB, L3, L2, etc.) * @vendor_specific: Bitmask for vendor-specific tests (can be 0 for universal tests) * @disabled: Test is disabled @@ -70,6 +71,7 @@ struct user_params { */ struct resctrl_test { const char *name; + const char *group; const char *resource; unsigned int vendor_specific; bool disabled; diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 7846260e3f68..d89179541d7b 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -61,11 +61,15 @@ static void cmd_help(void) printf("usage: resctrl_tests [-h] [-t test list] [-n no_of_bits] [-b benchmark_cmd [option]...]\n"); printf("\t-b benchmark_cmd [option]...: run specified benchmark for MBM, MBA and CMT\n"); printf("\t default benchmark is builtin fill_buf\n"); - printf("\t-t test list: run tests specified in the test list, "); + printf("\t-t test list: run tests/groups specified by the list, "); printf("e.g. -t mbm,mba,cmt,cat\n"); - printf("\t\tSupported tests:\n"); - for (i = 0; i < ARRAY_SIZE(resctrl_tests); i++) - printf("\t\t\t%s\n", resctrl_tests[i]->name); + printf("\t\tSupported tests (group):\n"); + for (i = 0; i < ARRAY_SIZE(resctrl_tests); i++) { + if (resctrl_tests[i]->group) + printf("\t\t\t%s (%s)\n", resctrl_tests[i]->name, resctrl_tests[i]->group); + else + printf("\t\t\t%s\n", resctrl_tests[i]->name); + } printf("\t-n no_of_bits: run cache tests using specified no of bits in cache bit mask\n"); printf("\t-p cpu_no: specify CPU number to run the test. 1 is default\n"); printf("\t-h: help\n"); @@ -193,7 +197,9 @@ int main(int argc, char **argv) bool found = false; for (i = 0; i < ARRAY_SIZE(resctrl_tests); i++) { - if (!strcasecmp(token, resctrl_tests[i]->name)) { + if (!strcasecmp(token, resctrl_tests[i]->name) || + (resctrl_tests[i]->group && + !strcasecmp(token, resctrl_tests[i]->group))) { if (resctrl_tests[i]->disabled) tests++; resctrl_tests[i]->disabled = false; From patchwork Tue Oct 24 09:26:33 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: 157347 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1821500vqx; Tue, 24 Oct 2023 02:32:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0aJpLUs8jOQUhmW9Iu0ia5CA/UiSFQhWOTjrfZg+omSr9TR1sW1fkHUANaPw1DcHnOezs X-Received: by 2002:a05:6358:f55:b0:168:e366:6139 with SMTP id c21-20020a0563580f5500b00168e3666139mr3921108rwj.11.1698139977249; Tue, 24 Oct 2023 02:32:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139977; cv=none; d=google.com; s=arc-20160816; b=ILcH6HQGe9ce5r+S1oZ7LI6cs48RLsWfSh7fScMtKDbke03F1n5vkaFRruTIabr1NP w3qUnaC2TdfZbHq9I5CgOawJPCJjz/OBra7yje/1KO3+xEwIPyXu8lQlvLKY1Xm7Hno2 ZPvLb+CaariYoZI6HS+UdGGGaryzVs/IkIDmggwRVs4c5r2Ps5fN9nL0/vHguy1zmTwS 57xYC+68UQWtfuhKeiH3AwMMAXeijAqjnpUYLnsOO6WxGRPvsKt1EvLcFfbz0n1nCitJ hSee5O4AdkZA3WIyUbWWCmymZPnfRFqkjkmkyDKk1CFldi2riJF1W12xRvzS2BgTYDwS mGWQ== 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=PKJ3nY5sHKbXVB5w7Iag1A74CQ9qJftWaMYqnB60Y+Q=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=NxuyfN1KewkCpyI8p+75CKxlSkl87QXzDiv6pFgEGdh7kQxuoxFRdEHencWJ+peL5P /hDm8Y9Gs9NjACpdTd6cR6ByCtU47Kic2X2F//XsAy4yGjPc3hXU3L+3WT/dIvcHr7r0 za2sXbe6JxTH4EseUrLz3ZuofX7r+4Jgc/5lq7OHYEJxg4PslPMD8x4o1SojZwIppPVr vWF5MJ9oLs36S2b3Y6UxEehJcoWgr3Ofk2zHZJnZBrNKC1I5qKy6dOLCjJR3tuZmEmdB ZAqfOABHi6Pb1Y7DEjXswgo/vejWf67qbfzyEGgrFmqb0rNCKyPkppUy41nPSPDHxj3Q rLjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jbyamRI2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id fi39-20020a056a0039a700b006be1885fb85si8141200pfb.79.2023.10.24.02.32.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:32:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jbyamRI2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 6884280859AA; Tue, 24 Oct 2023 02:32:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232908AbjJXJcX (ORCPT + 26 others); Tue, 24 Oct 2023 05:32:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234440AbjJXJbc (ORCPT ); Tue, 24 Oct 2023 05:31:32 -0400 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 034BF1711; Tue, 24 Oct 2023 02:30:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139803; x=1729675803; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ocn2/9r+kzf8EjPiilW7216EKf/6BlgU2VvF1iWWBGI=; b=jbyamRI21ZmtsbzyRrkw/oQTuNZMjZBjV9LvAv4l4DZJeRg3dY98S/ny fPkLCZDj16vsY3fkqLQfEfsIQ86jLnuYBjg50h5Y6OdJE0ln3wVpn+n8w BUcnBS5ZRYX6i4JY/sfE5TueHJcggKCDrPaS69+1FyXsY3On/aEf2q/c4 LkUwR+Eq4jSybOgKr5Syv+Z4gedutRh3g77fpFKci7Ri+CH8mwSZ22lv5 7TdB6ctUd1Rk46s8rKGt2bNmjU9x6sPtgkjxQ5ph+UmmkQLZocp4G0FyK 2OKk9lCEIVYVbIAiIQlmv3cT9kr++prqYVgVlWfoZZiqO2mu0SI8uCQFl g==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="5644406" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="5644406" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:30:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="758410209" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="758410209" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:29:58 -0700 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 23/24] selftests/resctrl: Add L2 CAT test Date: Tue, 24 Oct 2023 12:26:33 +0300 Message-Id: <20231024092634.7122-24-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 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 groat.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 (groat.vger.email [0.0.0.0]); Tue, 24 Oct 2023 02:32:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628824568048175 X-GMAIL-MSGID: 1780628824568048175 CAT selftests only cover L3 but some newer CPUs come also with L2 CAT support. Add L2 CAT selftest. As measuring L2 misses is not easily available with perf, use L3 accesses as a proxy for L2 CAT working or not. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cat_test.c | 68 +++++++++++++++++-- tools/testing/selftests/resctrl/resctrl.h | 1 + .../testing/selftests/resctrl/resctrl_tests.c | 1 + 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 48a96acd9e31..a9c72022bb5a 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -131,8 +131,47 @@ void cat_test_cleanup(void) remove(RESULT_FILE_NAME); } +/* + * L2 CAT test measures L2 misses indirectly using L3 accesses as a proxy + * because perf cannot directly provide the number of L2 misses (there are + * only platform specific ways to get the number of L2 misses). + * + * This function sets up L3 CAT to reduce noise from other processes during + * L2 CAT test. + */ +int l3_proxy_prepare(const struct resctrl_test *test, struct resctrl_val_param *param, int cpu) +{ + unsigned long l3_mask, split_mask; + unsigned int start; + int count_of_bits; + char schemata[64]; + int n, ret; + + if (!validate_resctrl_feature_request("L3", NULL)) { + ksft_print_msg("%s test results may contain noise because L3 CAT is not available!\n", + test->name); + return 0; + } + + ret = get_mask_no_shareable("L3", &l3_mask); + if (ret) + return ret; + count_of_bits = count_contiguous_bits(l3_mask, &start); + n = count_of_bits / 2; + split_mask = create_bit_mask(start, n); + + snprintf(schemata, sizeof(schemata), "%lx", l3_mask & ~split_mask); + ret = write_schemata("", schemata, cpu, "L3"); + if (ret) + return ret; + + snprintf(schemata, sizeof(schemata), "%lx", split_mask); + return write_schemata(param->ctrlgrp, schemata, cpu, "L3"); +} + /* * cat_test: execute CAT benchmark and measure LLC cache misses + * @test: test information structure * @param: parameters passed to cat_test() * @span: buffer size for the benchmark * @current_mask start mask for the first iteration @@ -142,9 +181,10 @@ void cat_test_cleanup(void) * * Return: 0 on success. non-zero on failure. */ -static int cat_test(struct resctrl_val_param *param, const char *resource, +static int cat_test(const struct resctrl_test *test, struct resctrl_val_param *param, size_t span, unsigned long current_mask) { + __u64 pea_config = PERF_COUNT_HW_CACHE_MISSES; char *resctrl_val = param->resctrl_val; static struct perf_event_read pe_read; struct perf_event_attr pea; @@ -169,20 +209,26 @@ static int cat_test(struct resctrl_val_param *param, const char *resource, if (ret) return ret; + if (!strcmp(test->resource, "L2")) { + ret = l3_proxy_prepare(test, param, param->cpu_no); + if (ret) + return ret; + pea_config = PERF_COUNT_HW_CACHE_REFERENCES; + } + perf_event_attr_initialize(&pea, pea_config); + perf_event_initialize_read_format(&pe_read); + buf = alloc_buffer(span, 1); if (buf == NULL) return -1; - perf_event_attr_initialize(&pea, PERF_COUNT_HW_CACHE_MISSES); - perf_event_initialize_read_format(&pe_read); - while (current_mask) { snprintf(schemata, sizeof(schemata), "%lx", param->mask & ~current_mask); - ret = write_schemata("", schemata, param->cpu_no, resource); + ret = write_schemata("", schemata, param->cpu_no, test->resource); if (ret) goto free_buf; snprintf(schemata, sizeof(schemata), "%lx", current_mask); - ret = write_schemata(param->ctrlgrp, schemata, param->cpu_no, resource); + ret = write_schemata(param->ctrlgrp, schemata, param->cpu_no, test->resource); if (ret) goto free_buf; @@ -269,7 +315,7 @@ static int cat_run_test(const struct resctrl_test *test, const struct user_param remove(param.filename); - ret = cat_test(¶m, test->resource, span, start_mask); + ret = cat_test(test, ¶m, span, start_mask); if (ret) goto out; @@ -288,3 +334,11 @@ struct resctrl_test l3_cat_test = { .feature_check = test_resource_feature_check, .run_test = cat_run_test, }; + +struct resctrl_test l2_cat_test = { + .name = "L2_CAT", + .group = "CAT", + .resource = "L2", + .feature_check = test_resource_feature_check, + .run_test = cat_run_test, +}; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index f9a4cfd981f8..fffeb442c173 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -183,5 +183,6 @@ extern struct resctrl_test mbm_test; extern struct resctrl_test mba_test; extern struct resctrl_test cmt_test; extern struct resctrl_test l3_cat_test; +extern struct resctrl_test l2_cat_test; #endif /* RESCTRL_H */ diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index d89179541d7b..9e254bca6c25 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -15,6 +15,7 @@ static struct resctrl_test *resctrl_tests[] = { &mba_test, &cmt_test, &l3_cat_test, + &l2_cat_test, }; static int detect_vendor(void) From patchwork Tue Oct 24 09:26:34 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: 157346 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1821468vqx; Tue, 24 Oct 2023 02:32:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWdhfa8x9tDlhh8AU90zF4aJ26nrVUp4yDNMUVPdcb3iogNB4wrRH1A4LrHXn9FNo1e5ai X-Received: by 2002:a05:6a00:1a90:b0:690:2ad9:1454 with SMTP id e16-20020a056a001a9000b006902ad91454mr14421902pfv.33.1698139971816; Tue, 24 Oct 2023 02:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698139971; cv=none; d=google.com; s=arc-20160816; b=HZgBmIcf4WXIJoSX+3RGwUfgbj0wx2VFpInZparLdZUoYTzHrMVz1km37pDiqJ4wD5 sblySbzT7wAQELgJeCr0F3lPtpH7nXWo50pCQdV0iBaeJaGxvtwq/J5CjMachMb1EaXZ S19TGy1CYRMC/t8DC53f+cMmAegSk6ji8z49yZ5Dx9dnMDVfkKsW3OSWlE9Aex8agMyz /OYo/qzRUjs7jGvP3Uw6U7nAMAtRDY4IVbTTTBGhFxKwaL0wr+p/hUYpLWvGdOysu1kd 4IBjStx4CIV42UGkgURlWtTaVQHXByzH8I+2Bbdi57P+HWhJCKlotK7zpsFT9NdgFupn S3Zw== 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=K/06NA3Um1N+gUzTiTgal6sxginCiZnUioyie0nJBVc=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=TZUyl7DAnFlz9ab5I1231msmFRzCpdODQ8r1+A4CcrKsqUXj2zfVfKT4LcW6oRuWhK XBJJM/oVhq1/H8Qtg2YtGk+pbuJaa8u5A7b95pU4bKTBZIx8WVZb6NGsRHlybbIP9wFU kj41kQg9Zns3CJ3Seh+EpR36SVrlwASgywtC/MGUFm4fHG7rPzdQdlscRwT0HlMghFgh 1jmETTZPK+wk1diSTbYkX4+3zABzJb2DABFSl5OraHuzL0X05FUl+PmrNijmRYvIVJUu rR9J8XAIqEYqc4ligReK1ojLsU65cRm150v2fWlptNDVIqQEVT59UxEu00itCuUQMLjE U0Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=A07DuuYp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id x11-20020a634a0b000000b005b82de74216si7842592pga.901.2023.10.24.02.32.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 02:32:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=A07DuuYp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 86444804239D; Tue, 24 Oct 2023 02:32:49 -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 S234235AbjJXJc2 (ORCPT + 26 others); Tue, 24 Oct 2023 05:32:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234489AbjJXJbh (ORCPT ); Tue, 24 Oct 2023 05:31:37 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC12A1BC7; Tue, 24 Oct 2023 02:30:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698139812; x=1729675812; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1rS7dOlEZmpZ+PuUamvzhE47459WoiCsJ336xs2d7Tc=; b=A07DuuYp1ggXcBt3Sbsggr9IqcL2L/E53wJvPzeguo/eRpFsSCwpUjZg xV3tYbujAHQ6UTvxQr547FlmlhyXCTsQQ8PSF12rGpGcZa3aT2YeMaKfH BZuqLe1zGuFvqD9yd0TjaiIPR/YYfkP7DmoLiE85tuEXqtFEdkYLc6HWr n2gXRfhbjsZ0Hoqm5171TDPUWhavfQtx0pOMnve3nXCg4k2XFLLNddijF ebfBVw7rNmwQryYSrJJrP0Krb0ptI1hq4+2XXvKaYsblDeddlo4dkTxs7 R33DSU76lef2v1Csffvns6mijYPijr9rv+I3OUtiqW65e8RanY+6AVMCH g==; X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="366364219" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="366364219" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:30:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10872"; a="849076026" X-IronPort-AV: E=Sophos;i="6.03,247,1694761200"; d="scan'208";a="849076026" Received: from hprosing-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.219]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Oct 2023 02:30:07 -0700 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 24/24] selftests/resctrl: Ignore failures from L2 CAT test with <= 2 bits Date: Tue, 24 Oct 2023 12:26:34 +0300 Message-Id: <20231024092634.7122-25-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 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:32:49 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780628819190853190 X-GMAIL-MSGID: 1780628819190853190 L2 CAT test with low number of bits tends to occasionally fail because of what seems random variation. The margin is quite small to begin with for <= 2 bits in CBM. At times, the result can even become negative. While it would be possible to allow negative values for those cases, it would be more confusing to user. Ignore failures from the tests where <= 2 were used to avoid false negative results. Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/cat_test.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index a9c72022bb5a..bc88eb891f35 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -28,7 +28,7 @@ */ #define MIN_DIFF_PERCENT_PER_BIT 1 -static int show_results_info(__u64 sum_llc_val, int no_of_bits, +static int show_results_info(__u64 sum_llc_val, int no_of_bits, bool ignore_fail, unsigned long cache_span, long min_diff_percent, unsigned long num_of_runs, bool platform, __s64 *prev_avg_llc_val) @@ -40,12 +40,18 @@ static int show_results_info(__u64 sum_llc_val, int no_of_bits, avg_llc_val = sum_llc_val / num_of_runs; if (*prev_avg_llc_val) { float delta = (__s64)(avg_llc_val - *prev_avg_llc_val); + char *res_str; avg_diff = delta / *prev_avg_llc_val; ret = platform && (avg_diff * 100) < (float)min_diff_percent; + res_str = ret ? "Fail:" : "Pass:"; + if (ret && ignore_fail) { + res_str = "Pass (failure ignored):"; + ret = 0; + } ksft_print_msg("%s Check cache miss rate changed more than %.1f%%\n", - ret ? "Fail:" : "Pass:", (float)min_diff_percent); + res_str, (float)min_diff_percent); ksft_print_msg("Percent diff=%.1f\n", avg_diff * 100); } @@ -85,6 +91,7 @@ static int check_results(struct resctrl_val_param *param, const char *cache_type while (fgets(temp, sizeof(temp), fp)) { char *token = strtok(temp, ":\t"); + bool ignore_fail = false; int fields = 0; int bits; @@ -108,7 +115,15 @@ static int check_results(struct resctrl_val_param *param, const char *cache_type bits = count_bits(current_mask); - ret = show_results_info(sum_llc_perf_miss, bits, + /* + * L2 CAT test with low number of bits has too small margin to + * always remain positive. As negative values would be confusing + * for the user, ignore failure instead. + */ + if (bits <= 2 && !strcmp(cache_type, "L2")) + ignore_fail = true; + + ret = show_results_info(sum_llc_perf_miss, bits, ignore_fail, alloc_size / 64, MIN_DIFF_PERCENT_PER_BIT * (bits - 1), runs, get_vendor() == ARCH_INTEL,