mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Moger, Babu" <Babu.Moger@amd.com>
To: "fenghua.yu@intel.com" <fenghua.yu@intel.com>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"tony.luck@intel.com" <tony.luck@intel.com>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"reinette.chatre@intel.com" <reinette.chatre@intel.com>,
	"Moger, Babu" <Babu.Moger@amd.com>,
	"james.morse@arm.com" <james.morse@arm.com>,
	"xiaochen.shen@intel.com" <xiaochen.shen@intel.com>,
	"ravi.v.shankar@intel.com" <ravi.v.shankar@intel.com>,
	"sai.praneeth.prakhya@intel.com" <sai.praneeth.prakhya@intel.com>,
	"arshiya.hayatkhan.pathan@intel.com" 
	<arshiya.hayatkhan.pathan@intel.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-kselftest@vger.kernel.org"
	<linux-kselftest@vger.kernel.org>
Subject: [PATCH v5 11/13] selftests/resctrl: Add vendor detection mechanism
Date: Fri, 18 Jan 2019 18:27:15 +0000	[thread overview]
Message-ID: <20190118182646.16594-12-babu.moger@amd.com> (raw)
In-Reply-To: <20190118182646.16594-1-babu.moger@amd.com>

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>
---
 tools/testing/selftests/resctrl/resctrl.h       | 13 +++++
 tools/testing/selftests/resctrl/resctrl_tests.c | 68 +++++++++++++++++++++++++
 2 files changed, 81 insertions(+)

diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h
index 3da2afe..1ec97d1 100644
--- a/tools/testing/selftests/resctrl/resctrl.h
+++ b/tools/testing/selftests/resctrl/resctrl.h
@@ -63,10 +63,23 @@ struct resctrl_val_param {
 
 };
 
+/**
+ * Results of CPUID operation are stored in this structure.
+ * It consists of 4x32bits IA registers: EAX, EBX, ECX and EDX.
+ */
+struct cpuid_out {
+        uint32_t eax;
+        uint32_t ebx;
+        uint32_t ecx;
+        uint32_t edx;
+};
+
 pid_t bm_pid, ppid;
 extern char cbm_mask[256];
 extern unsigned long long_mask;
 extern char llc_occup_path[1024];
+extern int genuine_intel;
+extern int authentic_amd;
 
 int remount_resctrlfs(bool mum_resctrlfs);
 int get_resource_id(int cpu_no, int *resource_id);
diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c
index 2397c3b..e8cbcd5 100644
--- a/tools/testing/selftests/resctrl/resctrl_tests.c
+++ b/tools/testing/selftests/resctrl/resctrl_tests.c
@@ -14,6 +14,69 @@
 #define BENCHMARK_ARGS		64
 #define BENCHMARK_ARG_SIZE	64
 
+/**
+ * This variables provides information about the vendor
+ */
+int genuine_intel = 0;
+int authentic_amd = 0;
+
+void
+lcpuid(const unsigned leaf,
+       const unsigned subleaf,
+       struct cpuid_out *out)
+{
+        if (out == NULL)
+                return;
+
+#ifdef __x86_64__
+        asm volatile("mov %4, %%eax\n\t"
+                     "mov %5, %%ecx\n\t"
+                     "cpuid\n\t"
+                     "mov %%eax, %0\n\t"
+                     "mov %%ebx, %1\n\t"
+                     "mov %%ecx, %2\n\t"
+                     "mov %%edx, %3\n\t"
+                     : "=g" (out->eax), "=g" (out->ebx), "=g" (out->ecx),
+                       "=g" (out->edx)
+                     : "g" (leaf), "g" (subleaf)
+                     : "%eax", "%ebx", "%ecx", "%edx");
+#else
+        asm volatile("push %%ebx\n\t"
+                     "mov %4, %%eax\n\t"
+                     "mov %5, %%ecx\n\t"
+                     "cpuid\n\t"
+                     "mov %%eax, %0\n\t"
+                     "mov %%ebx, %1\n\t"
+                     "mov %%ecx, %2\n\t"
+                     "mov %%edx, %3\n\t"
+                     "pop %%ebx\n\t"
+                     : "=g" (out->eax), "=g" (out->ebx), "=g" (out->ecx),
+                       "=g" (out->edx)
+                     : "g" (leaf), "g" (subleaf)
+                     : "%eax", "%ecx", "%edx");
+#endif
+}
+
+int detect_vendor(void)
+{
+        int ret = 0;
+        struct cpuid_out vendor;
+
+        lcpuid(0x0, 0x0, &vendor);
+        if (vendor.ebx == 0x756e6547 && vendor.edx == 0x49656e69 &&
+            vendor.ecx == 0x6c65746e) {
+                genuine_intel = 1;
+        } else if (vendor.ebx == 0x68747541 && vendor.edx == 0x69746E65 &&
+                   vendor.ecx ==   0x444D4163) {
+                authentic_amd = 1;
+        } else {
+                ret = -EFAULT;
+        }
+
+        return ret;
+}
+
+
 static void cmd_help(void)
 {
 	printf("usage: resctrl_tests [-h] [-b \"benchmark_cmd [options]\"] [-t test list] [-n no_of_bits]\n");
@@ -109,6 +172,11 @@ int main(int argc, char **argv)
 		return errno;
 	}
 
+	/*
+         * Detect vendor 
+	 */
+	detect_vendor();
+
 	if (has_ben) {
 		/* Extract benchmark command from command line. */
 		for (i = ben_ind; i < argc; i++) {
-- 
1.8.3.1


  parent reply	other threads:[~2019-01-18 18:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-18 18:27 [PATCH v5 00/13] selftests/resctrl: Add resctrl selftest Moger, Babu
2019-01-18 18:27 ` [PATCH v5 01/13] selftests/resctrl: Add README for resctrl tests Moger, Babu
2019-01-18 18:27 ` [PATCH v5 02/13] selftests/resctrl: Add basic resctrl file system operations and data Moger, Babu
2019-01-18 18:27 ` [PATCH v5 03/13] selftests/resctrl: Read memory bandwidth from perf IMC counter and from resctrl file system Moger, Babu
2019-01-18 18:27 ` [PATCH v5 04/13] selftests/resctrl: Add callback to start a benchmark Moger, Babu
2019-01-18 18:27 ` [PATCH v5 05/13] selftests/resctrl: Add built in benchmark Moger, Babu
2019-01-18 18:27 ` [PATCH v5 06/13] selftests/resctrl: Add MBM test Moger, Babu
2019-01-18 18:27 ` [PATCH v5 07/13] selftests/resctrl: Add MBA test Moger, Babu
2019-01-18 18:27 ` [PATCH v5 08/13] selftests/resctrl Add Cache QoS Monitoring (CQM) selftest Moger, Babu
2019-01-18 18:27 ` [PATCH v5 09/13] selftests/resctrl: Add Cache Allocation Technology (CAT) selftest Moger, Babu
2019-01-18 18:27 ` [PATCH v5 10/13] selftests/resctrl: Add the test in MAINTAINERS Moger, Babu
2019-01-18 18:27 ` Moger, Babu [this message]
2019-01-18 18:27 ` [PATCH v5 12/13] selftests/resctrl: Use cache index3 id for AMD schemata masks Moger, Babu
2019-01-18 18:27 ` [PATCH v5 13/13] selftests/resctrl: Disable MBA and MBM tests for AMD Moger, Babu

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=20190118182646.16594-12-babu.moger@amd.com \
    --to=babu.moger@amd.com \
    --cc=arshiya.hayatkhan.pathan@intel.com \
    --cc=fenghua.yu@intel.com \
    --cc=hpa@zytor.com \
    --cc=james.morse@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=ravi.v.shankar@intel.com \
    --cc=reinette.chatre@intel.com \
    --cc=sai.praneeth.prakhya@intel.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=xiaochen.shen@intel.com \
    /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

all inboxes | Powered by JetHome®