From patchwork Fri Dec 15 15:05: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: 179377 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9350322dys; Fri, 15 Dec 2023 07:17:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGS17BNfIN2O9No+JGxdeuAc8KGDRwe7CamIOgM4f2O+l5p+Pf4r9KkSdb7ZsuGxbNnPL0E X-Received: by 2002:a05:6a21:99a0:b0:193:fbb8:466a with SMTP id ve32-20020a056a2199a000b00193fbb8466amr372474pzb.29.1702653425375; Fri, 15 Dec 2023 07:17:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702653425; cv=none; d=google.com; s=arc-20160816; b=HqrSksOZRbIWhqC83qZN4hW2ww63hBtumLioeQiEsSbIbqUeFJgB9DewRqerRcjqGq iwQ5EadCu0om2fbvWWsL8vZr9QSRYvtsSYEDnGbNdTZWhrDBSqj6WUKWrOqeNgYIWRbu fsrJDganI+0k60TEVHzqVavtTPZpuv/fF4HjvVQ63XGRnr479fjL1JRJfibv00w7Ym56 QEg7XTvAlgyRwcP6+2eFT1iaD5j4rthpoIGdsKsvZ2o9dak8DXVQM6WxVr/CcSEAhn5D Y3JWqh4Xf6cVgOpCT4Uf9e0UJ7jHjzJKnQqN1kaAiDuyqo3A5U9iMYnwU8Ilw7QEbsVs k81w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ig5ejlE2Pn5j5a9asFGKcSv+X5RUxKAo54SHumyAtCk=; fh=gPQ6jqLSfsDb5bE3yrtO+AlT5R4d75RXkjC5xckz7Dk=; b=nRdlL65X0xq/kznUgxX8Jke3uiWOUNxXOQVPvPCHxjcYdYgEgAD+BMW3ZyfRPBai+g VtoT7CS+GiaAFQ5Y8wUKs2A6T2+oB6UvP+GMCyy+XPgPdXAAYrWzvCcIE6f6xYCnOuR1 7IaLSRLh9Rc2ScJWbKQ7n1BoRNYqqBTDBcE6PQsJdXUSf0KSpDae7MhcmSo9jW1AdWzG JHam/BSXWA8EmsYzk+gIv1ECJMlT6RHgedx29nXf10ANSKcxx7u+77KfqpmDvyV5KqUM +IEzi/PSxS8EjzeQf+vvznS+137w8Dyb3PYwSUmdpQgPR1ODQJ8Jp0VxLOV7AlMWXA4c vthg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=h0ovr8IU; spf=pass (google.com: domain of linux-kernel+bounces-1182-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1182-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 4-20020a631744000000b005bd2b354a42si13261624pgx.207.2023.12.15.07.17.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 07:17:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1182-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=h0ovr8IU; spf=pass (google.com: domain of linux-kernel+bounces-1182-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1182-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 7DC0028699A for ; Fri, 15 Dec 2023 15:14:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF15846446; Fri, 15 Dec 2023 15:10:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="h0ovr8IU" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7B8747786; Fri, 15 Dec 2023 15:10:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702653004; x=1734189004; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ywRDd44vKPDZAVx18BFxwm4wvIVelDye2XAYp2fu2Go=; b=h0ovr8IUWtsNlKhi2tyJnL/XXRiQiHBJclpzbM1MhV4Ncs6OzFYwewkl RvXEX+W2oPSjic/qGqw71dIOYK1wVyIPHOAAongbukPuhmEe7GSluThjc ajDHFta3RfO1ie6ND5mokB0eLgeYzpXe3LOpAKTrIYMI8jBuPchS4pEAS wAfMnmKKI6Hn9yJlEdajl10dbhkgwiRv4npo6ylMPeTnIsipLulxN80Lc dIK3BRwae0CrnoMX/tIiW3vW8JHe/69ehQmRLDSFooSas6isGj4XpgE/6 aILrYRJ3fDJLuKFnUj/0ZG7dJYMGXs2T5hYRvc+ZS1CkEAKdcf+CctyR3 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="2454158" X-IronPort-AV: E=Sophos;i="6.04,279,1695711600"; d="scan'208";a="2454158" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2023 07:09:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="809001718" X-IronPort-AV: E=Sophos;i="6.04,279,1695711600"; d="scan'208";a="809001718" Received: from ijarvine-desk1.ger.corp.intel.com (HELO localhost) ([10.246.49.116]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2023 07:09:54 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , =?utf-8?q?Maciej_Wiecz=C3=B3r-R?= =?utf-8?q?etman?= , Fenghua Yu Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v4 29/29] selftests/resctrl: Get domain id from cache id Date: Fri, 15 Dec 2023 17:05:15 +0200 Message-Id: <20231215150515.36983-30-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231215150515.36983-1-ilpo.jarvinen@linux.intel.com> References: <20231215150515.36983-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785361518380075364 X-GMAIL-MSGID: 1785361518380075364 Domain 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 domain 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 domain 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 domain id. It got incorrect domain 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 issue if tests don't work correctly with it). Taking all the above into account, generalize acquiring the domain id by taking it from the cache id and do not hard-code the cache level. Signed-off-by: Ilpo Järvinen Reviewed-by: Reinette Chatre --- tools/testing/selftests/resctrl/resctrl.h | 2 +- tools/testing/selftests/resctrl/resctrl_val.c | 4 +-- tools/testing/selftests/resctrl/resctrlfs.c | 27 ++++++++++++------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index d4eef20723fc..c52eaf46f24d 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -129,7 +129,7 @@ extern char llc_occup_path[1024]; int get_vendor(void); bool check_resctrlfs_support(void); int filter_dmesg(void); -int get_domain_id(int cpu_no, int *domain_id); +int get_domain_id(const char *resource, int cpu_no, int *domain_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 631e5f055694..5a49f07a6c85 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 domain_id; - if (get_domain_id(cpu_no, &domain_id) < 0) { + if (get_domain_id("MB", cpu_no, &domain_id) < 0) { ksft_print_msg("Could not get domain ID\n"); return; } @@ -584,7 +584,7 @@ static void initialize_llc_occu_resctrl(const char *ctrlgrp, const char *mongrp, { int domain_id; - if (get_domain_id(cpu_no, &domain_id) < 0) { + if (get_domain_id("L3", cpu_no, &domain_id) < 0) { ksft_print_msg("Could not get domain ID\n"); return; } diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index f29dc65d8b30..5750662cce57 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -111,28 +111,37 @@ static int get_cache_level(const char *cache_type) return -1; } +static int get_resource_cache_level(const char *resource) +{ + /* "MB" use L3 (LLC) as resource */ + if (!strcmp(resource, "MB")) + return 3; + return get_cache_level(resource); +} + /* * get_domain_id - Get resctrl domain ID for a specified CPU + * @resource: resource name * @cpu_no: CPU number * @domain_id: domain ID (cache ID; for MB, L3 cache ID) * * Return: >= 0 on success, < 0 on failure. */ -int get_domain_id(int cpu_no, int *domain_id) +int get_domain_id(const char *resource, int cpu_no, int *domain_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) { - ksft_perror("Failed to open physical_package_id"); + ksft_perror("Failed to open cache id file"); return -1; } @@ -559,7 +568,7 @@ int write_schemata(char *ctrlgrp, char *schemata, int cpu_no, const char *resour return -1; } - if (get_domain_id(cpu_no, &domain_id) < 0) { + if (get_domain_id(resource, cpu_no, &domain_id) < 0) { sprintf(reason, "Failed to get domain ID"); ret = -1;