From patchwork Thu Jan 25 11:12:44 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: 192036 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1576562dyi; Thu, 25 Jan 2024 03:41:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IGtFefT9eGwCBx/lh/tz9ZnYGPNGmPJA8+2tWhQ852x38E5bVdk+Bo5B3odd2fAciQECn0x X-Received: by 2002:a17:902:aa4b:b0:1d6:f493:b219 with SMTP id c11-20020a170902aa4b00b001d6f493b219mr633778plr.137.1706182900959; Thu, 25 Jan 2024 03:41:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706182900; cv=pass; d=google.com; s=arc-20160816; b=pPYesp4jo/OIA0fNmWBaS62Br1iPPUFlLkW0GKIpCpuf3YL3OPSBnguWX1WqROu43e 9NJ9eXxXDkjVtBG8B1rvfZzi4B7CfWCXh1zdsl3m3nyteVKSEsTytBYwEJb03oFUiosJ yvoZ//Gb4ewlyXTNfdVFPZwV4UgYDLO67Coip75ceMMsRhipYsbsY6A1maR1isy6zock pcdx0cGh5bfoiko6xSb0xvVZfn3XV7A5IYf4f+KN2wa9q3KOCqw1Y5ql4vXUxJ4ICaNv g+tfgcxixbrlUSUlm3ASoleATzHcXwcZxSrSwAnWavwKzn4QKcrimDTyYfk0siebETW3 /qKw== 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=kR3kO8rJeyaYG7Bvs9hNyBFZpFeLxQ/gPa47a4FsZYk=; fh=eNkS6XcMxBX7jqqaCWKBjHPfznBhZVo4Re/mvAqqtp8=; b=hXkCuIS24QwZ4gDIN/Ma4laDTyNtw/xKaxmww6x4Ur68SMxFZUclI5NF/1gFuuz78d vkjr/fLwxx+tP3LQ9Usu2GCAGCzMD50ngDiZYTzMru5zVJi8rnzeA6Wy5EWqQ7vFK4SX dKIAKB49t8bSbVFlqpwXFNhEEcTID7t7r5eW9XTnyWH224RDjhrd8AwUoeuVPGAK4Npc 3TALLw6VFlkRc1Kepzio0Ezb7gcDRgKPMjMU9Th/89T1DZeOCQcEk/6Qe7Zbl/Y6kPUj vnCHZvkYybERSih4TSZkXo8d5ePoaG6B2Rr7RlVlDPC8dO1qGTKf3AVh26VaOAwcNvqr Uh0g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Vn3NfZf4; 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-38491-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38491-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id h15-20020a170902680f00b001d3f1b7685esi12986575plk.547.2024.01.25.03.41.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 03:41:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38491-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Vn3NfZf4; 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-38491-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38491-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4CADFB31A27 for ; Thu, 25 Jan 2024 11:17:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 952EB54BE5; Thu, 25 Jan 2024 11:13:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Vn3NfZf4" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (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 8594A54BC0; Thu, 25 Jan 2024 11:13:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706181182; cv=none; b=f5crJA5wJ+oiw+v6c5SImW3VCI0WpjswrEKT6j5BR5GFi89NAhHN/cdcgiNvxk2ZPbHknJYzKna1DcH0YFgjkDFlF4oc09GLawMhLWaeXasUveoB4OiYUuI/OuaxqTN0ioNv7WP9vayTC9O+dAnEnd9thm9MmOXVi26hlWzLp8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706181182; c=relaxed/simple; bh=SxRU7/I2LYttjmLWpA1g2TAp7MIA5p+HKBajTxhEzJs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lGBifd8nUus7qBZDhAxIQAPd5cxSG8HQreIQtbZtEnwt9ad7zY9IfUyXcJ0WIi4ninAcxzqjN21sGBusbnp4jpElowbWwmE9JOa/5wxrBFaLJpm0ovC2B+KosgMohuZAi84MQJF+Wl8LqaFmerIrSYXXAMAYjP+nZAlQoQUKP10= 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=Vn3NfZf4; arc=none smtp.client-ip=192.55.52.120 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=1706181180; x=1737717180; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SxRU7/I2LYttjmLWpA1g2TAp7MIA5p+HKBajTxhEzJs=; b=Vn3NfZf4itAM/jGnV5273rCZEb6G7jXlC2qR69Zwp8dd8LChKxkgVvom fIhwPdquFkGsTE0PFmFhe0U1LqNi2kfwU35kiQwymmWmROrnEJ8Oiw4ZA fLMzVflcPYFCwSy9bSM8T96wWbAxOCm4+4v1tc/apYmLZAj213X6WncrH dszCTcMD2gAfH/NMKC5P3JU7fgCdTNQ9m5kiSUBAiVoexXX8oWJlrjsIk JZY/wlTjAmZAnsj4EwICtkgw5Nogu/6KgUyTnGm+Ygf4+ggM6KkQkFxhM mXhjYGUykNnYBZzc9P8nlA5t/KAFc9kDzIFmfefn+rEWXlrSpPhpml3aZ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="400987627" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="400987627" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jan 2024 03:12:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="909968606" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="909968606" Received: from apejovix-mobl1.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.213.0.239]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jan 2024 03:12:57 -0800 From: Maciej Wieczor-Retman To: reinette.chatre@intel.com, shuah@kernel.org, fenghua.yu@intel.com Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, ilpo.jarvinen@linux.intel.com Subject: [PATCH v3 4/5] selftests/resctrl: Add resource_info_file_exists() Date: Thu, 25 Jan 2024 12:12:44 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789062441767741061 X-GMAIL-MSGID: 1789062441767741061 Feature checking done by resctrl_mon_feature_exists() covers features represented by the feature name presence inside the 'mon_features' file in /sys/fs/resctrl/info/L3_MON directory. There exists a different way to represent feature support and that is by the presence of 0 or 1 in a single file in the info/resource directory. In this case the filename represents what feature support is being indicated. Add a generic function to check file presence in the /sys/fs/resctrl/info/ directory. Signed-off-by: Maciej Wieczor-Retman Reviewed-by: Ilpo Järvinen --- Changelog v3: - Split off the new function into this patch. (Reinette) Changelog v2: - Add this patch. tools/testing/selftests/resctrl/resctrl.h | 2 ++ tools/testing/selftests/resctrl/resctrlfs.c | 26 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 4603b215b97e..c39105f46da9 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -138,6 +138,8 @@ int umount_resctrlfs(void); int validate_bw_report_request(char *bw_report); bool resctrl_resource_exists(const char *resource); bool resctrl_mon_feature_exists(const char *feature); +bool resource_info_file_exists(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, cpu_set_t *old_affinity); diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c index e4ba8614fb7b..a6427732e0ad 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -763,6 +763,32 @@ bool resctrl_mon_feature_exists(const char *feature) return !!res; } +/* + * resource_info_file_exists - Check if a file is present inside + * /sys/fs/resctrl/info/RESOURCE. + * @resource: Required resource (Eg: MB, L3, L2, etc.) + * @feature: Required feature. + * + * Return: True if the file exists, else false. + */ +bool resource_info_file_exists(const char *resource, + const char *feature) +{ + char res_path[PATH_MAX]; + struct stat statbuf; + + if (!feature || !resource) + return false; + + snprintf(res_path, sizeof(res_path), "%s/%s/%s", INFO_PATH, resource, + feature); + + if (stat(res_path, &statbuf)) + return false; + + return true; +} + bool test_resource_feature_check(const struct resctrl_test *test) { return resctrl_resource_exists(test->resource);