From: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
To: shuah@kernel.org, skhan@linuxfoundation.org,
linux-kselftest@vger.kernel.org
Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
tony.luck@intel.com, reinette.chatre@intel.com,
babu.moger@amd.com, james.morse@arm.com,
ravi.v.shankar@intel.com, fenghua.yu@intel.com, x86@kernel.org,
linux-kernel@vger.kernel, dan.carpenter@oracle.com,
dcb314@hotmail.com,
Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Subject: [PATCH V2 07/19] selftests/resctrl: Use resctrl/info for feature detection
Date: Mon, 18 May 2020 15:08:27 -0700 [thread overview]
Message-ID: <f314626e53fb97c6cde732a72dc41f9b983fe21e.1589835155.git.sai.praneeth.prakhya@intel.com> (raw)
In-Reply-To: <cover.1589835155.git.sai.praneeth.prakhya@intel.com>
RDT features could be enabled or disabled through kernel command line
parameters. This is not reflected in /proc/cpuinfo i.e. cpuinfo always
shows the features supported by H/W whereas user could selectively enable
or disable some of these features. So, before running a requested test,
/proc/cpuinfo cannot be used to check if the system supports the
requested RDT feature.
A more appropriate place to check for this is resctrl/info. Directories
like L3, MB and L3_MON are populated only if the respective feature is
enabled. Hence, use resctrl/info for feature detection instead of
/proc/cpuinfo.
Please note that, presently, only L3_CAT, L3_CMT, MBA and MBM are
supported. L2 and CDP variants of L3 are not yet supported.
Fixes: 591a6e8588fc ("selftests/resctrl: Add basic resctrl file system operations and data")
Reported-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
---
tools/testing/selftests/resctrl/resctrl.h | 6 ++-
tools/testing/selftests/resctrl/resctrlfs.c | 51 ++++++++++++++++-----
2 files changed, 45 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h
index 814d0dd517a4..65ca24bf3eac 100644
--- a/tools/testing/selftests/resctrl/resctrl.h
+++ b/tools/testing/selftests/resctrl/resctrl.h
@@ -28,6 +28,10 @@
#define RESCTRL_PATH "/sys/fs/resctrl"
#define PHYS_ID_PATH "/sys/devices/system/cpu/cpu"
#define CBM_MASK_PATH "/sys/fs/resctrl/info"
+#define L3_PATH "/sys/fs/resctrl/info/L3"
+#define MB_PATH "/sys/fs/resctrl/info/MB"
+#define L3_MON_PATH "/sys/fs/resctrl/info/L3_MON"
+#define L3_MON_FEATURES_PATH "/sys/fs/resctrl/info/L3_MON/mon_features"
#define PARENT_EXIT(err_msg) \
do { \
@@ -74,7 +78,7 @@ int remount_resctrlfs(bool mum_resctrlfs);
int get_resource_id(int cpu_no, int *resource_id);
int umount_resctrlfs(void);
int validate_bw_report_request(char *bw_report);
-bool validate_resctrl_feature_request(char *resctrl_val);
+bool validate_resctrl_feature_request(const char *resctrl_val);
char *fgrep(FILE *inf, const char *str);
int taskset_benchmark(pid_t bm_pid, int cpu_no);
void run_benchmark(int signum, siginfo_t *info, void *ucontext);
diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c
index e43ddebd1aa4..67d775d03271 100644
--- a/tools/testing/selftests/resctrl/resctrlfs.c
+++ b/tools/testing/selftests/resctrl/resctrlfs.c
@@ -618,26 +618,55 @@ char *fgrep(FILE *inf, const char *str)
* validate_resctrl_feature_request - Check if requested feature is valid.
* @resctrl_val: Requested feature
*
- * Return: 0 on success, non-zero on failure
+ * Return: True if the feature is supported, else false
*/
-bool validate_resctrl_feature_request(char *resctrl_val)
+bool validate_resctrl_feature_request(const char *resctrl_val)
{
- FILE *inf = fopen("/proc/cpuinfo", "r");
+ struct stat statbuf;
bool found = false;
char *res;
+ FILE *inf;
- if (!inf)
+ if (!resctrl_val)
return false;
- res = fgrep(inf, "flags");
-
- if (res) {
- char *s = strchr(res, ':');
+ if (remount_resctrlfs(false))
+ return false;
- found = s && !strstr(s, resctrl_val);
- free(res);
+ if (!strcmp(resctrl_val, "cat")) {
+ if (!stat(L3_PATH, &statbuf))
+ return true;
+ } else if (!strcmp(resctrl_val, "mba")) {
+ if (!stat(MB_PATH, &statbuf))
+ return true;
+ } else if (!strcmp(resctrl_val, "mbm") || !strcmp(resctrl_val, "cmt")) {
+ if (!stat(L3_MON_PATH, &statbuf)) {
+ inf = fopen(L3_MON_FEATURES_PATH, "r");
+ if (!inf)
+ return false;
+
+ if (!strcmp(resctrl_val, "cmt")) {
+ res = fgrep(inf, "llc_occupancy");
+ if (res) {
+ found = true;
+ free(res);
+ }
+ }
+
+ if (!strcmp(resctrl_val, "mbm")) {
+ res = fgrep(inf, "mbm_total_bytes");
+ if (res) {
+ free(res);
+ res = fgrep(inf, "mbm_local_bytes");
+ if (res) {
+ found = true;
+ free(res);
+ }
+ }
+ }
+ fclose(inf);
+ }
}
- fclose(inf);
return found;
}
--
2.19.1
next prev parent reply other threads:[~2020-05-18 22:13 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-18 22:08 [PATCH V2 00/19] Miscellaneous fixes for resctrl selftests Sai Praneeth Prakhya
2020-05-18 22:08 ` [PATCH V2 01/19] selftests/resctrl: Rename CQM test as CMT test Sai Praneeth Prakhya
2020-05-18 22:08 ` [PATCH V2 02/19] selftests/resctrl: Fix typo Sai Praneeth Prakhya
2020-05-18 22:08 ` [PATCH V2 03/19] selftests/resctrl: Fix typo in help text Sai Praneeth Prakhya
2020-05-18 22:08 ` [PATCH V2 04/19] selftests/resctrl: Declare global variables as extern Sai Praneeth Prakhya
2020-05-18 22:08 ` [PATCH V2 05/19] selftests/resctrl: Return if resctrl file system is not supported Sai Praneeth Prakhya
2020-05-18 22:08 ` [PATCH V2 06/19] selftests/resctrl: Check for resctrl mount point only if resctrl FS is supported Sai Praneeth Prakhya
2020-05-18 22:08 ` Sai Praneeth Prakhya [this message]
2020-05-18 22:08 ` [PATCH V2 08/19] selftests/resctrl: Ensure sibling CPU is not same as original CPU Sai Praneeth Prakhya
2020-05-18 22:08 ` [PATCH V2 09/19] selftests/resctrl: Fix missing options "-n" and "-p" Sai Praneeth Prakhya
2020-05-18 22:08 ` [PATCH V2 10/19] selftests/resctrl: Fix MBA/MBM results reporting format Sai Praneeth Prakhya
2020-05-18 22:08 ` [PATCH V2 11/19] selftests/resctrl: Abort running tests if not root user Sai Praneeth Prakhya
2020-05-18 22:08 ` [PATCH V2 12/19] selftests/resctrl: Enable gcc checks to detect buffer overflows Sai Praneeth Prakhya
2020-05-18 22:08 ` [PATCH V2 13/19] selftests/resctrl: Dynamically select buffer size for CAT test Sai Praneeth Prakhya
2020-05-18 22:08 ` [PATCH V2 14/19] selftests/resctrl: Skip the test if requested resctrl feature is not supported Sai Praneeth Prakhya
2020-05-20 23:46 ` Reinette Chatre
2020-05-21 17:12 ` Prakhya, Sai Praneeth
2020-05-18 22:08 ` [PATCH V2 15/19] selftests/resctrl: Change return type of umount_resctrlfs() to void Sai Praneeth Prakhya
2020-05-20 23:52 ` Reinette Chatre
2020-05-21 17:19 ` Prakhya, Sai Praneeth
2020-05-21 18:15 ` Reinette Chatre
2020-05-18 22:08 ` [PATCH V2 16/19] selftests/resctrl: Umount resctrl FS only if mounted Sai Praneeth Prakhya
2020-05-18 22:08 ` [PATCH V2 17/19] selftests/resctrl: Unmount resctrl FS after running all tests Sai Praneeth Prakhya
2020-05-18 22:08 ` [PATCH V2 18/19] selftests/resctrl: Fix incorrect parsing of iMC counters Sai Praneeth Prakhya
2020-05-18 22:08 ` [PATCH V2 19/19] selftests/resctrl: Fix checking for < 0 for unsigned values Sai Praneeth Prakhya
2020-05-21 16:12 ` [PATCH V2 00/19] Miscellaneous fixes for resctrl selftests Reinette Chatre
2020-05-21 17:28 ` Prakhya, Sai Praneeth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f314626e53fb97c6cde732a72dc41f9b983fe21e.1589835155.git.sai.praneeth.prakhya@intel.com \
--to=sai.praneeth.prakhya@intel.com \
--cc=babu.moger@amd.com \
--cc=bp@alien8.de \
--cc=dan.carpenter@oracle.com \
--cc=dcb314@hotmail.com \
--cc=fenghua.yu@intel.com \
--cc=james.morse@arm.com \
--cc=linux-kernel@vger.kernel \
--cc=linux-kselftest@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=ravi.v.shankar@intel.com \
--cc=reinette.chatre@intel.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).