Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4690496rdb; Tue, 12 Dec 2023 06:54:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGSDg/7rUFgHsCY76O5UezeX/LORtJABpHtqM2gTMu4bIAyZMYanYOjVlQmpE1jicJOdeW X-Received: by 2002:a05:6a00:21d3:b0:6cd:f50c:32aa with SMTP id t19-20020a056a0021d300b006cdf50c32aamr8153885pfj.13.1702392842221; Tue, 12 Dec 2023 06:54:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702392842; cv=none; d=google.com; s=arc-20160816; b=xZK/rCw3zauoViJibqdzMhOEZttGcLEc7fdJoiyyaJuOPWjml8DqsDvQxrxArR0EjS ZyuwV+yOH57KgCo4tC6Z1ROLipZ5EMCEtlt/EAbfDs3xvMAga9rLwkr6O5PbHRlemel6 3TU2b1+yXhgkBTTeIkTh5oejLvb2Q6KKgxXhU5AsCjeE/SRMb5aDYJiKcCvdQbyfheta 4fEO6PySTk7rMQfH4I9vv0CViYqCxieSe+dh3RGRpJdAJ1nC8r4eFHyxJ1xF7489OKaW upqvLaw6OQbsntoeMIxqJxNAJ4mqAgNGa9M5+e9ymy5bsmrja3WYnzNH/EQ/Ur2PHfQL 7LXQ== 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=1Md5q/rpb2tD6nWzrnbcj1gJcjRgdejubCdHraAdKG4=; fh=/pACME0x50g4vorTSG5vEdNwgU981WFvy8LGbk4DPBk=; b=ZxGt1Lq96UiYfIiDBR9EnR1PmTioy5jWLsclQEOBL1oT7OFpLUeW48H8ditCEQV1Cz GgGFxPuOX68ViLCb7ud1XISa7cUYwWgC1hffOakBuPrqzR3BMwOL1L5kjXc4BuZXq40N 5smg+czorLwKZPndS3bEYIgov7fsL/gZRB1VVu08LKolLoA+XwwV2zvV3tFxjcvoLnZp 0JWAyz1tp3zTsKr08H7bz9xKFJJk487/fS9/zG7odMLY8IYlpYqM7aDeB3Cj7UT1Vrci d6AAwwMorEWOnhpZvDaMwSpTie6cWZbS0jXGBEkfRHGc6ltDBoUJu+/F8ivbVAXPaPQp TjKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bKZhKxy1; 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 Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id s12-20020a056a0008cc00b006cdd0109833si7870496pfu.154.2023.12.12.06.54.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 06:54:02 -0800 (PST) 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=bKZhKxy1; 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 B4AD08026DA1; Tue, 12 Dec 2023 06:53:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377058AbjLLOxj (ORCPT + 99 others); Tue, 12 Dec 2023 09:53:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377011AbjLLOxc (ORCPT ); Tue, 12 Dec 2023 09:53:32 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09734EA; Tue, 12 Dec 2023 06:53:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702392818; x=1733928818; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wTLiPs7DM2XKGHCN7FGTKAU1Kd3MFxHMnL+sAIX2BfA=; b=bKZhKxy1kfWYdt4iVQBOFb7KDb/pohtLqS6er0pNgn7/1e+U+f4vlOOt 1jLBDKR4JmZ8w9+ZJ6zmjxWzMYXQNcSLYuJJ2zjwn8XfeAZNi3thswz4z 7NbVD9ncoU/rBhlEBnKAJkBDMXA+0/K7UOPTq2OQ+RjUXZdzPAxfUiRS+ gcc3w6Y2TjnwqyQPWMYjXw4yzL5Mtk1NGFQkFWergQMgJccw39dJB6pqm 9hDw3+cLWSdKWR3UnuP3kDg9Gsdg94R/W8aCw3FRMskAMwtHDY3SKwkGr u1qqXYU51soGkMuB2C7sVFyXK7YEhKSWZ5pyNDrKucIuQwM850aet5Txk g==; X-IronPort-AV: E=McAfee;i="6600,9927,10922"; a="481014360" X-IronPort-AV: E=Sophos;i="6.04,270,1695711600"; d="scan'208";a="481014360" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2023 06:53:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,270,1695711600"; d="scan'208";a="15024023" Received: from mdabrows-mobl1.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.213.5.65]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2023 06:53:34 -0800 From: Maciej Wieczor-Retman To: Fenghua Yu , Reinette Chatre , Shuah Khan Cc: ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 4/4] selftests/resctrl: Add non-contiguous CBMs CAT test Date: Tue, 12 Dec 2023 15:52:54 +0100 Message-ID: <10c3afd7f62c63db31a3d4af86529144a5d7bbf9.1702392177.git.maciej.wieczor-retman@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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, 12 Dec 2023 06:53:58 -0800 (PST) Add tests for both L2 and L3 CAT to verify the return values generated by writing non-contiguous CBMs don't contradict the reported non-contiguous support information. Use a logical XOR to confirm return value of write_schemata() and non-contiguous CBMs support information match. Signed-off-by: Maciej Wieczor-Retman --- Changelog v2: - Redo the patch message. (Ilpo) - Tidy up __cpuid_count calls. (Ilpo) - Remove redundant AND in noncont_mask calculations (Ilpo) - Fix bit_center offset. - Add newline before function return. (Ilpo) - Group non-contiguous tests with CAT tests. (Ilpo) - Use a helper for reading sparse_masks file. (Ilpo) - Make get_cache_level() available in other source files. (Ilpo) tools/testing/selftests/resctrl/cat_test.c | 75 +++++++++++++++++++ tools/testing/selftests/resctrl/resctrl.h | 3 + .../testing/selftests/resctrl/resctrl_tests.c | 2 + tools/testing/selftests/resctrl/resctrlfs.c | 2 +- 4 files changed, 81 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 7dc7206b3b99..ecf553a89aae 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -292,6 +292,65 @@ static int cat_run_test(const struct resctrl_test *test, const struct user_param return ret; } +static int noncont_cat_run_test(const struct resctrl_test *test, + const struct user_params *uparams) +{ + unsigned long full_cache_mask, cont_mask, noncont_mask; + unsigned int eax, ebx, ecx, edx, ret; + int level, bit_center, sparse_masks; + char schemata[64]; + + /* Check to compare sparse_masks content to cpuid output. */ + sparse_masks = read_info_res_file(test->resource, "sparse_masks"); + if (sparse_masks < 0) + return sparse_masks; + + level = get_cache_level(test->resource); + if (level < 0) + return -EINVAL; + __cpuid_count(0x10, 4 - level, eax, ebx, ecx, edx); + + if (sparse_masks != ((ecx >> 3) & 1)) + return -1; + + /* Write checks initialization. */ + ret = get_full_cbm(test->resource, &full_cache_mask); + if (ret < 0) + return ret; + bit_center = count_bits(full_cache_mask) / 2; + cont_mask = full_cache_mask >> bit_center; + + /* Contiguous mask write check. */ + snprintf(schemata, sizeof(schemata), "%lx", cont_mask); + ret = write_schemata("", schemata, uparams->cpu, test->resource); + if (ret) + return ret; + + /* + * Non-contiguous mask write check. CBM has a 0xf hole approximately in the middle. + * Output is compared with support information to catch any edge case errors. + */ + noncont_mask = ~(0xf << (bit_center - 2)) & full_cache_mask; + snprintf(schemata, sizeof(schemata), "%lx", noncont_mask); + ret = write_schemata("", schemata, uparams->cpu, test->resource); + if (ret && sparse_masks) + ksft_print_msg("Non-contiguous CBMs supported but write failed\n"); + else if (ret && !sparse_masks) + ksft_print_msg("Non-contiguous CBMs not supported and write failed as expected\n"); + else if (!ret && !sparse_masks) + ksft_print_msg("Non-contiguous CBMs not supported but write succeeded\n"); + + return !ret == !sparse_masks; +} + +static bool noncont_cat_feature_check(const struct resctrl_test *test) +{ + if (!resctrl_resource_exists(test->resource)) + return false; + + return resctrl_cache_feature_exists(test->resource, "sparse_masks"); +} + struct resctrl_test l3_cat_test = { .name = "L3_CAT", .group = "CAT", @@ -299,3 +358,19 @@ struct resctrl_test l3_cat_test = { .feature_check = test_resource_feature_check, .run_test = cat_run_test, }; + +struct resctrl_test l3_noncont_cat_test = { + .name = "L3_NONCONT_CAT", + .group = "CAT", + .resource = "L3", + .feature_check = noncont_cat_feature_check, + .run_test = noncont_cat_run_test, +}; + +struct resctrl_test l2_noncont_cat_test = { + .name = "L2_NONCONT_CAT", + .group = "CAT", + .resource = "L2", + .feature_check = noncont_cat_feature_check, + .run_test = noncont_cat_run_test, +}; diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 74041a35d4ba..7b7a48d1fddd 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -165,6 +165,7 @@ unsigned int count_contiguous_bits(unsigned long val, unsigned int *start); int get_full_cbm(const char *cache_type, unsigned long *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); +int get_cache_level(const char *cache_type); int read_info_res_file(const char *resource, const char *filename); void ctrlc_handler(int signum, siginfo_t *info, void *ptr); int signal_handler_register(void); @@ -201,5 +202,7 @@ 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 l3_noncont_cat_test; +extern struct resctrl_test l2_noncont_cat_test; #endif /* RESCTRL_H */ diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index 3044179ee6e9..f3dc1b9696e7 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -19,6 +19,8 @@ static struct resctrl_test *resctrl_tests[] = { &mba_test, &cmt_test, &l3_cat_test, + &l3_noncont_cat_test, + &l2_noncont_cat_test, }; static int detect_vendor(void) diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index 8546421f0940..8bd30973fec3 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -100,7 +100,7 @@ int umount_resctrlfs(void) * * Return: cache level as integer or -1 if @cache_type is invalid. */ -static int get_cache_level(const char *cache_type) +int get_cache_level(const char *cache_type) { if (!strcmp(cache_type, "L3")) return 3; -- 2.43.0