Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp965482rdb; Fri, 16 Feb 2024 00:36:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX3IOnMZQVbGzh7/4/iUlR9OxDz+m7uMorwhCiljBqIsWP24sQrqzNjqY7McmVicWChcOwgFZes1OPHexGDGz/6NlMtpg0yVmzGmFS7uw== X-Google-Smtp-Source: AGHT+IEzqJUsfLRg04z8HNw5vIYXLgsdwkhqYVXPnJ2jVP8Hss5kaHgD7NyPCnl0cP834N3Y1lY2 X-Received: by 2002:a17:906:b0d1:b0:a3d:4ed8:f5bf with SMTP id bk17-20020a170906b0d100b00a3d4ed8f5bfmr3178598ejb.2.1708072608850; Fri, 16 Feb 2024 00:36:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708072608; cv=pass; d=google.com; s=arc-20160816; b=ssA1cepVdE/GzIyQzJne3gmBXTHwZ655DJNdE1oqgYpaPLMG49aUaSE3TVLDHtVv2E D0Qhaa2SDuVmtWTDXypCmr61ycbla/5L+J7B7sPVbRkZ701Od83o7hqJuIH16nLX+x57 IcFO+bxNkYwqqjp6NyoSO4R5F+PZQcMOy98jyPEOLHLH0w4Hm8jO7yzGfxeaM5BOz0PK GJinferKOUCd7LaL72ndl8PmFRAhXJ2DAMBj4aQqxF0RF+1Uqr2nO/C0UknQs2NS664r 4PXopNsRgdPnXNI7BpA7CBs/rQJdyDFahhjfoH0npYAZ0QP0iXI9cyewGEL2+sXCvGEa W/+A== 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=S/BNF5EEaAlJo9CwdNIQIcY4LDPns4htPkhbx1xhzIE=; fh=vsXTc+A87OxxPzw8nrMJDpzNxDeci757XxGoEWLRn38=; b=VMQwvjRBaHbUtHjVQ7AdXdQdsGpLQwZtPdQGcqk3KldRvGbwL9bWgTf4VlhDazgiic k7+qNeEysCikpWoUlv4FPWzYLfodWqdm8Hx1/+6iOGB4CPxkQ57awesqIlrHm7cBvoJM KUIdWJlKBNoYxuo0tbla/ehMd9i9dO79kZrwTKKWnZb2gCCJW+6XGbaATfM7Jbmwq88Q qEyvUlCLmYWHj3LHSQFUZ9t1N3JzIvAGaiGWjWiUQhuvTCYttAJlfuT304vZwFWVp51p 9ghqWO5Gd63Un7z4eqO5Av2kGTxSCJb6GYqLvYs6kE3wGH8FheSlo3XH9foHkdJ65zX9 G+lQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MIrubDwB; 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-68247-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68247-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dp21-20020a170906c15500b00a3d36da8944si1476046ejc.540.2024.02.16.00.36.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 00:36:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68247-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MIrubDwB; 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-68247-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68247-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 621801F2129D for ; Fri, 16 Feb 2024 08:36:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1444B17BBD; Fri, 16 Feb 2024 08:35:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MIrubDwB" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 AE8731B94D; Fri, 16 Feb 2024 08:35:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708072554; cv=none; b=LFgSjRgAhts54wEQ9emmjnVAywT1o6FlNX2DlvIJbU4d1RmCEl0s7JvJrwhbWiojTMQAAns9KSVDIpA30xJtYvNoadkhejQ10t/Q0C9aB6socEbeRrolnKmipuEXZXmJsCRkSKh91T52fn7c3jRZBtdXsGYsmXXQaXR8M5NyZUM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708072554; c=relaxed/simple; bh=W0vo/v6Uk1nQ4rBgma0PVflw0bD5UeCWw/hfYrDFu/Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FERr9oGQ382n88JLvrV9OTaiNn2M02GTwniZ91HS/nOR5QC0Lww+PJjiqZv8SRRYvC+M/QovOetCtDXc+83DmBcxIxFh7aZmp8EHDdYtw34UpqKgkHy1VlydgH5bKE8tBs+Rhv0YyFB8gd9/V5i0KmnvFNx5R92bS7VLdbOsMfI= 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=MIrubDwB; arc=none smtp.client-ip=198.175.65.9 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=1708072553; x=1739608553; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W0vo/v6Uk1nQ4rBgma0PVflw0bD5UeCWw/hfYrDFu/Y=; b=MIrubDwBF38oIbSoyPtcOTIoFFyJTn3SLwtdf2yRvGLfX3d8s500q91x Vw+7xXTw5ZGcHfKcDmt7OV7MWDnBY1HZeqZZTw50RsPB02jO8CG6XjILP hGFLb4BG+Uc7XTs0nPLvfjuqM7B3aIaOxsCc+Sv79khWjwWelLblVrVq0 9p82s+xc7O6zrdbj2Ax9HNu62ghQdpN952oreovl5l+V+npmVBcAnPwgp js5SjziztzKen4OE94Do5WGEmbmNFE7zszLz5kRBukYFMTZT7GewbhyMJ YT2Ot1rSyZZsh2yvtiXNK4E8UaUUqDCz3Yb6kCm8ECozca0zkzhYxQT4V Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10985"; a="24659570" X-IronPort-AV: E=Sophos;i="6.06,164,1705392000"; d="scan'208";a="24659570" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2024 00:35:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10985"; a="912327335" X-IronPort-AV: E=Sophos;i="6.06,164,1705392000"; d="scan'208";a="912327335" Received: from zprzybys-mobl.ger.corp.intel.com (HELO wieczorr-mobl1.intel.com) ([10.213.22.138]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2024 00:35:48 -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 4/5] selftests/resctrl: Add resource_info_file_exists() Date: Fri, 16 Feb 2024 09:35:41 +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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 v6: - Re-add function header to this patch. Changelog v5: - feature -> file. (Reinette) - Redo return description and path in the comment. (Reinette) Changelog v4: - Remove unnecessary new lines. - Change 'feature' -> 'file' to keep things generic. (Reinette) - Add Ilpo's reviewed-by tag. Changelog v3: - Split off the new function into this patch. (Reinette) Changelog v2: - Add this patch. tools/testing/selftests/resctrl/resctrl.h | 1 + tools/testing/selftests/resctrl/resctrlfs.c | 25 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h index 6d99ed44ec60..f434a6543b4f 100644 --- a/tools/testing/selftests/resctrl/resctrl.h +++ b/tools/testing/selftests/resctrl/resctrl.h @@ -138,6 +138,7 @@ 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 *resource, const char *feature); +bool resource_info_file_exists(const char *resource, const char *file); 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 1273e55c4a9d..1cade75176eb 100644 --- a/tools/testing/selftests/resctrl/resctrlfs.c +++ b/tools/testing/selftests/resctrl/resctrlfs.c @@ -764,6 +764,31 @@ bool resctrl_mon_feature_exists(const char *resource, 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.) + * @file: Required file. + * + * Return: True if the /sys/fs/resctrl/info/@resource/@file exists, else false. + */ +bool resource_info_file_exists(const char *resource, const char *file) +{ + char res_path[PATH_MAX]; + struct stat statbuf; + + if (!file || !resource) + return false; + + snprintf(res_path, sizeof(res_path), "%s/%s/%s", INFO_PATH, resource, + file); + + 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); -- 2.43.0