Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp965710rdb; Fri, 16 Feb 2024 00:37:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXqF5gHj4W/6XiFV9TFYK2yECdVL7n4unZkn1DUIVrZDX7rYHdbRzVvq8uygucM3oR96Qa2JTfO6z8gts0kSUKqbs4ofZAHWxHcsNipAg== X-Google-Smtp-Source: AGHT+IGfMT2bwewPklaHx1qpyCnUGvmtyP+PdEiW5GvVVn1KYgoVTgWlK78GUI/1bmRK0wtmz0P6 X-Received: by 2002:a05:6a21:9207:b0:19b:81be:34e4 with SMTP id tl7-20020a056a21920700b0019b81be34e4mr5577960pzb.50.1708072652542; Fri, 16 Feb 2024 00:37:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708072652; cv=pass; d=google.com; s=arc-20160816; b=OQ3KAk7/7z2pIdgevuR+tvpLzYaoR6Prblx03qZ6KoTeijrj0w0zPJgXEeBae0xJXw LxEsNab/+Bd20+dGZpoUy/8Fzy7g54pM3X3VIWkTmjUbSlWfcaQja8zctXxGT1ZxBXAc 9P/YA2Id8mNAXZG/R/RfOpbmALWEGtldtlpF9zcsRQVST3XKdf+pKP/f8Y7/oylR5MeI iIs70kjvulh7jLSK+lEavjsVSW2MkyJkfPV7os1FmN4reHQu6TAsge37FVqwbBxsWQYE ytTXEbeM6vqgI8JKZu8VUacwnqTvZklF1zJetqH9lW2/QfacC0lHu/QJj0Hb0v7VUDK2 KAGA== 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=1bxyQJKMXSo9Hdqa9dFeR1HfwV0zvRjYKiJP9Yl2wWk=; fh=vsXTc+A87OxxPzw8nrMJDpzNxDeci757XxGoEWLRn38=; b=vBpyYpD53j5FqVn8LHKH1i3x0Ywa9wvdwfg/DqlrFh2NiyLl6gOnFIBhtH03xv8YZq qy0nIN0CxsNz6cdv9f262IIZ1DHHa8KcVMcsfGC2kp9q2m7txloLbyIHo2k6P3UvC8X9 t80HSu7BLW4pnSpn66tnxuQ1xL+fd3VMkGCCJp2HVy30Jkwozavji58tyylwtHA4O1eH /VHEltxi6961JaAr4AOfA6rNPF36mwn/EHzpf/JHQ/scvNPhTA5fDKaUx0s8vcj6WZ4s /2grqVsQOxYJt6qOu6bP84G7jR/PGLLDneBz3WOawC3UzoeyYXG/3GZtSluNdHJMqRPV gBXA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="AlKu/K9R"; 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-68248-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68248-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n12-20020a170902f60c00b001db71681d59si2683220plg.391.2024.02.16.00.37.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 00:37:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68248-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="AlKu/K9R"; 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-68248-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68248-linux.lists.archive=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 11056284DFD for ; Fri, 16 Feb 2024 08:37:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 880821864D; Fri, 16 Feb 2024 08:36:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AlKu/K9R" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 1C44E1B95D; Fri, 16 Feb 2024 08:36:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708072567; cv=none; b=Vd+RxgcjWBFC/xMaI7o2wwH+yWmtkevoDAmbOr82Jjo3b/5sg6JI5xzN7WmFP/xTRy/WiH81uFtlKiy4YpRC8O5iL7TJtHxjAOsCq2DUHWKODUBcknCGXKtwTyyZoeYf0heZq/GBuK1iimVno7idcBhGyANPgo8aVfPFDZKWKgs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708072567; c=relaxed/simple; bh=nqKgBCODw1Bb8mDKIw1PVJb65tpUTI+7WSaoC2AXT4I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ea2r6MB/MeXPdtLQ3PZv0sC5awC3jAFXNiPtoz7tpFMtjEMWog84/fCx2BOr9FESDDskYrf7DPzU6ky+Njkt5gNX3BXvLOIORYjWlSfOL7GAK8+BBDq8Y1FUk3BMZ8vB7M17/i8KFjeyu11LROb8M6FZ14S+eh0moIKBPBC3X3s= 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=AlKu/K9R; arc=none smtp.client-ip=192.198.163.17 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=1708072565; x=1739608565; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nqKgBCODw1Bb8mDKIw1PVJb65tpUTI+7WSaoC2AXT4I=; b=AlKu/K9Rs/x/WS1E5RmhgtUYnYMNZ4F/z8LyHPFXgouaWif9KZdv6kX1 uFrd1UjbEu/3JJXx3QuwGB3/TJkb9AhnavBhb3jBdbuA8QMifKpQSlN3b XxzU8cOwQjPLuhtO5tNepq94U/s2HT8CyoiyWz3cf51d2i0aSvdGNwATN WOhgK7m16mLxHlhmrLGLfhx/4mjcSw4iAw0vb7yImIfyAUK5Nw8e5zAB9 krEV4LuS/E+MCydokaT1ctGH9iCFgRDbzJ9FqYKvk3PGwt1X89rb0P6VB eFZt10SeEtI0AkhLCMLALaJmou7uZRhD1orv6pNrIkb+FaQCe4Va6HbQG A==; X-IronPort-AV: E=McAfee;i="6600,9927,10985"; a="2067421" X-IronPort-AV: E=Sophos;i="6.06,164,1705392000"; d="scan'208";a="2067421" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2024 00:36:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,164,1705392000"; d="scan'208";a="3801546" Received: from zprzybys-mobl.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.213.22.138]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2024 00:36:02 -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 v6 5/5] selftests/resctrl: Add non-contiguous CBMs CAT test Date: Fri, 16 Feb 2024 09:35:52 +0100 Message-ID: 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 Content-Transfer-Encoding: 8bit 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 --- Changelog v6: - Change ret to int type for proper error returns. (Reinette) - Add a check for bit_center variable to verify the CBM width isn't too small. Also add a comment to explain the check. (Reinette) 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 | 89 +++++++++++++++++++ tools/testing/selftests/resctrl/resctrl.h | 2 + .../testing/selftests/resctrl/resctrl_tests.c | 2 + 3 files changed, 93 insertions(+) diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c index 39fc9303b8e8..4cb991be8e31 100644 --- a/tools/testing/selftests/resctrl/cat_test.c +++ b/tools/testing/selftests/resctrl/cat_test.c @@ -294,6 +294,79 @@ 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, sparse_masks; + int bit_center, ret; + char schemata[64]; + + /* 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; + + /* + * The bit_center needs to be at least 3 to properly calculate the CBM + * hole in the noncont_mask. If it's smaller return an error since the + * cache mask is too short and that shouldn't happen. + */ + if (bit_center < 3) + return -EINVAL; + 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 +374,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) -- 2.43.0