selftests/resctrl: Add vendor detection mechanism
authorBabu Moger <babu.moger@amd.com>
Thu, 16 Jan 2020 21:32:43 +0000 (13:32 -0800)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 11 Feb 2020 01:43:17 +0000 (18:43 -0700)
RESCTRL feature is supported both on Intel and AMD now. Some features
are implemented differently. Add vendor detection mechanism. Use the vendor
check where there are differences.

Signed-off-by: Babu Moger <babu.moger@amd.com>
Co-developed-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/resctrl/resctrl.h
tools/testing/selftests/resctrl/resctrl_tests.c

index e8399389f3add5a6f8f3bff1e6f03ac3f8727c49..39bf59c6b9c569c1af96bcc2090c77389f309fcf 100644 (file)
@@ -66,6 +66,7 @@ pid_t bm_pid, ppid;
 int tests_run;
 
 char llc_occup_path[1024];
+bool is_amd;
 
 bool check_resctrlfs_support(void);
 int filter_dmesg(void);
index 7f75b0b01bb59fa7284fb8c0dc758a66e72c0602..884e918b1e97a999f33b2b7aedeab5cfbd6f9a2e 100644 (file)
 #define BENCHMARK_ARGS         64
 #define BENCHMARK_ARG_SIZE     64
 
+bool is_amd;
+
+void detect_amd(void)
+{
+       FILE *inf = fopen("/proc/cpuinfo", "r");
+       char *res;
+
+       if (!inf)
+               return;
+
+       res = fgrep(inf, "vendor_id");
+
+       if (res) {
+               char *s = strchr(res, ':');
+
+               is_amd = s && !strcmp(s, ": AuthenticAMD\n");
+               free(res);
+       }
+       fclose(inf);
+}
+
 static void cmd_help(void)
 {
        printf("usage: resctrl_tests [-h] [-b \"benchmark_cmd [options]\"] [-t test list] [-n no_of_bits]\n");
@@ -107,6 +128,9 @@ int main(int argc, char **argv)
        if (geteuid() != 0)
                printf("# WARNING: not running as root, tests may fail.\n");
 
+       /* Detect AMD vendor */
+       detect_amd();
+
        if (has_ben) {
                /* Extract benchmark command from command line. */
                for (i = ben_ind; i < argc; i++) {