From patchwork Fri Feb 9 14:02:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maciej Wieczor-Retman X-Patchwork-Id: 198883 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp870716dyd; Fri, 9 Feb 2024 06:03:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVRAamEv3MzeOB58HRdK4VUD+69lZmSQuzjg3vIh5T6DqDsae8KNPkMPZzZDrx/t95SVtdztJSnSbncKSaEwszzs/8phg== X-Google-Smtp-Source: AGHT+IGlUNpz4ZiWJziy0En4mtZxrqFhxh0aLu+YYNc2nWnynRQc3L0WEmEhwxkE3Ki/BBauMNsm X-Received: by 2002:a17:906:40cc:b0:a3b:ebb3:29fc with SMTP id a12-20020a17090640cc00b00a3bebb329fcmr1152585ejk.21.1707487393982; Fri, 09 Feb 2024 06:03:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707487393; cv=pass; d=google.com; s=arc-20160816; b=zn+0FKBl5LLGCNkmTlOPG+/HEEoOgjlUG+fqnQywvGBw5BjiCzckam6OHA4vsVSwWg zreBUd07P5fwpW6LyES27i2vQf5D82o8NeobhfRDiEx7Gof6wJrLL2ILKxKMDByjd5v1 CgcjGBQA4216lA6Hzy/sXSpHhA6ZGZWHWqHxCd2zPctQ3RxU4sfUnicia6W8oJ4YQhtD V9/s0PvZthP5fJPd0hmPFFNFRZzkfSk86o8o0JiAgE6nhjxYws2qGjBRK2cIkeg8zIS9 NKTNfAd9s5LlZ08AXVlSGRQ8+PiutSH5GkXYTLqHqV0ixlDOokqzujybtB2usmyMlb1r guUA== ARC-Message-Signature: i=2; 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=csQPsJtNT+RO7QuFTrv/cLo1gYHccexYSDrJ+t1utEU=; fh=TBCj+OoDcVzv0TEminjQASGPny/h4gYrFv/7iXuHNFc=; b=hDpeFB5OGwXbevcXZdRvnCQ+yeplBdy196Ccry47jlRQ6aGHjqRM8BPZ0HC/Ftrwdg VrvytjBuz8QsOb9QuMMLyHnIoMc9I82teFZx0eytQT1WHgI3U+AbRiEnG91gyL5S5Z+B mArtrLkeTaP6M/QXgj+wPmvjEElfBrLrxq5Wzjz/JzlKltQoLgRBLZBD7JbfCvEQyuui 5LQn2glNBVnJmuY8WM0ajwXfoHDIWv7AlYjY1vT0ZTLXvixbt5uvPaAjT0xvJKqpalYE 1WAS0f/PHwv8yboYlBx4jXd+VvZwglNtQheFuwW5mxfHXa3y63oqun9N+fv77o4/IhdO UcxQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="lbgpae4/"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-59407-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59407-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCXD0DCSYbCKjcgBA7YZYnqztwll/ed88cV27nFdH7HKxwy1hx9ixuO5LkmIt7+djt0L8Kndtqgg9T2kO3OWQ6YzbFIR4A== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id qk35-20020a1709077fa300b00a3857cf0301si972461ejc.452.2024.02.09.06.03.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 06:03:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59407-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="lbgpae4/"; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-59407-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59407-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 65FAF1F21B53 for ; Fri, 9 Feb 2024 14:03:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1241692E1; Fri, 9 Feb 2024 14:02:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lbgpae4/" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 EB76157326; Fri, 9 Feb 2024 14:02:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707487353; cv=none; b=HZnw6IXNq6HWXINtrd9OQYTIcJ40VA9XStC/6/2f4C9ozw1VhFEpdXO8dWJ++AW2V3rtycbZc8AnyOM6+CZA6CcP3PwzViAQIXZiCRRmU1TIhks7S19kOMa+ImD3inCnI8AL7khFLGYjaNyCRBEj4nO6Pd5LrXIJGk3FdwfpTKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707487353; c=relaxed/simple; bh=K6rMMQZvXeXM/c2DLOoBYHOlEwO+LI0vLpSgjCF0MuA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cGLC3ReKZyoCafNFDO/mdBcuetAgQI3p96kX522K5nHZ6R1FlOqtCL8/34T+R6x7CTgRMI/OFCuZuKY04Krw5PQM4V/iMSMWeCDF7DyHboC1abDc0c23CZkW245Bn6F7aIFeBuam/Xp9RhcVe+YyfF9GGSj7WNDYirpvh9ywOcg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=lbgpae4/; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707487352; x=1739023352; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=K6rMMQZvXeXM/c2DLOoBYHOlEwO+LI0vLpSgjCF0MuA=; b=lbgpae4/7ZA3SRc0b7PMn5ohVWISk5IOQiN1ftIPZ5PoEOpLIfmZFUSH 1jvWDPG9Cj2EUQwiJGxWfwR+1SSWmIrgVQ0RNU1+/SLmci1OPxyd1/hUc bQuKJIgMW+y+1iR6bclVu5wOib0FZ/DBLk3oJ/AKbWMUZszEJ/36nKJxL +7Ou45VCOKsicrnT8jV0gP6xriYd98bP42CzUEC95o/NrRUTkA1KFcF5f FlkmnzbMbHtL/OWsR0pkJ5NbV2CD+vNVbwp2lsB6iYWIO2+1UEd24Jtut HjJ86QM/CWLxHuguQ+SVP3GfcaAzfbf+AchMe+3LdyCtIvx6KwhxYI6X9 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10978"; a="1328896" X-IronPort-AV: E=Sophos;i="6.05,257,1701158400"; d="scan'208";a="1328896" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2024 06:02:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,257,1701158400"; d="scan'208";a="6596724" Received: from ldziemin-mobl1.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.213.2.218]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2024 06:02:29 -0800 From: Maciej Wieczor-Retman To: reinette.chatre@intel.com, shuah@kernel.org, fenghua.yu@intel.com Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, ilpo.jarvinen@linux.intel.com Subject: [PATCH v5 5/5] selftests/resctrl: Add non-contiguous CBMs CAT test Date: Fri, 9 Feb 2024 15:02:18 +0100 Message-ID: <2c1011e7630605365b67caa6ddfe4e8ee2ba5bff.1707487039.git.maciej.wieczor-retman@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: 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: 1790430301652525460 X-GMAIL-MSGID: 1790430301652525460 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 Reviewed-by: Reinette Chatre Reviewed-by: Ilpo Järvinen --- Changelog v5: - Add Reinette's reviewed-by tag. - Make 0xf UL in case the CBMs get bigger in the future. (Ilpo) Changelog v4: - Return failure instead of error on check of cpuid against sparse_masks and on contiguous write_schemata fail. (Reinette) Changelog v3: - Roll back __cpuid_count part. (Reinette) - Update function name to read sparse_masks file. - Roll back get_cache_level() changes. - Add ksft_print_msg() to contiguous schemata write error handling (Reinette). 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 | 81 +++++++++++++++++++ tools/testing/selftests/resctrl/resctrl.h | 2 + .../testing/selftests/resctrl/resctrl_tests.c | 2 + 3 files changed, 85 insertions(+) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 39fc9303b8e8..d4b7bf8a6780 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -294,6 +294,71 @@ 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, sparse_masks; + char schemata[64]; + int bit_center; + + /* Check to compare sparse_masks content to CPUID output. */ + ret = resource_info_unsigned_get(test->resource, "sparse_masks", &sparse_masks); + if (ret) + return ret; + + if (!strcmp(test->resource, "L3")) + __cpuid_count(0x10, 1, eax, ebx, ecx, edx); + else if (!strcmp(test->resource, "L2")) + __cpuid_count(0x10, 2, eax, ebx, ecx, edx); + else + return -EINVAL; + + if (sparse_masks != ((ecx >> 3) & 1)) { + ksft_print_msg("CPUID output doesn't match 'sparse_masks' file content!\n"); + 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) { + ksft_print_msg("Write of contiguous CBM failed\n"); + return 1; + } + + /* + * 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 = ~(0xfUL << (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 of non-contiguous CBM failed\n"); + else if (ret && !sparse_masks) + ksft_print_msg("Non-contiguous CBMs not supported and write of non-contiguous CBM failed as expected\n"); + else if (!ret && !sparse_masks) + ksft_print_msg("Non-contiguous CBMs not supported but write of non-contiguous CBM 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 resource_info_file_exists(test->resource, "sparse_masks"); +} + struct resctrl_test l3_cat_test = { .name = "L3_CAT", .group = "CAT", @@ -301,3 +366,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 f434a6543b4f..2051bd135e0d 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -209,5 +209,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)