LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: Fenghua Yu <fenghua.yu@intel.com>
Cc: "Thomas Gleixner" <tglx@linutronix.de>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>, "H Peter Anvin" <hpa@zytor.com>,
	"Tony Luck" <tony.luck@intel.com>,
	"Reinette Chatre" <reinette.chatre@intel.com>,
	"Ravi V Shankar" <ravi.v.shankar@intel.com>,
	"Xiaochen Shen" <xiaochen.shen@intel.com>,
	"Arshiya Hayatkhan Pathan" <arshiya.hayatkhan.pathan@intel.com>,
	"Sai Praneeth Prakhya" <sai.praneeth.prakhya@intel.com>,
	"Babu Moger" <babu.moger@amd.com>,
	"linux-kernel" <linux-kernel@vger.kernel.org>,
	James Morse <James.Morse@arm.com>
Subject: Re: [PATCH v7 10/13] selftests/resctrl: Add vendor detection mechanism
Date: Fri, 10 May 2019 18:39:09 +0100	[thread overview]
Message-ID: <20190510183909.65732a67@donnerap.cambridge.arm.com> (raw)
In-Reply-To: <1549767042-95827-11-git-send-email-fenghua.yu@intel.com>

On Sat,  9 Feb 2019 18:50:39 -0800
Fenghua Yu <fenghua.yu@intel.com> wrote:

Hi,

> From: Babu Moger <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.

I don't think vendor detection is the right approach. The Linux userland
interface should be even architecture agnostic, not to speak of different
vendors.

But even if we need this for some reason ...

> 
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
> ---
>  tools/testing/selftests/resctrl/resctrl.h       | 13 +++++
>  tools/testing/selftests/resctrl/resctrl_tests.c | 63 +++++++++++++++++++++++++
>  2 files changed, 76 insertions(+)
> 
> diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h
> index dadbb3d0cad8..974ec2de5fee 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;

There are more CPU vendors than that ;-)
And to not encourage this kind of vendor specific tests, I'd keep this exposure to a minimum.

In my version I have a simple is_amd() function, to cover the L3 vs. physical pacakges differences.

>  
>  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 3959b2b0671a..1d9adcfbdb4c 100644
> --- a/tools/testing/selftests/resctrl/resctrl_tests.c
> +++ b/tools/testing/selftests/resctrl/resctrl_tests.c
> @@ -14,6 +14,66 @@
>  #define BENCHMARK_ARGS		64
>  #define BENCHMARK_ARG_SIZE	64
>  
> +/**
> + * This variables provides information about the vendor
> + */
> +int genuine_intel;
> +int authentic_amd;
> +
> +void lcpuid(const unsigned int leaf, const unsigned int subleaf,
> +	    struct cpuid_out *out)

There is a much easier way to detect the vendor, without resorting to
(unchecked) inline assembly in userland:
I changed this to scan /proc/cpuinfo for a line starting with vendor_id,
then use the information there. This should work everywhere.

Cheers,
Andre

> +{
> +	if (!out)
> +		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)
> +{
> +	struct cpuid_out vendor;
> +	int ret = 0;
> +
> +	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");
> @@ -110,6 +170,9 @@ 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++) {


WARNING: multiple messages have this Message-ID
From: Andre Przywara <andre.przywara@arm.com>
To: Fenghua Yu <fenghua.yu@intel.com>
Cc: "Thomas Gleixner" <tglx@linutronix.de>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>, "H Peter Anvin" <hpa@zytor.com>,
	"Tony Luck" <tony.luck@intel.com>,
	"Reinette Chatre" <reinette.chatre@intel.com>,
	"Ravi V Shankar" <ravi.v.shankar@intel.com>,
	"Xiaochen Shen" <xiaochen.shen@intel.com>,
	"Arshiya Hayatkhan Pathan" <arshiya.hayatkhan.pathan@intel.com>,
	"Sai Praneeth Prakhya" <sai.praneeth.prakhya@intel.com>,
	"Babu Moger" <babu.moger@amd.com>,
	"linux-kernel" <linux-kernel@vger.kernel.org>,
	James Morse <James.Morse@arm.com>
Subject: Re: [PATCH v7 10/13] selftests/resctrl: Add vendor detection mechanism
Date: Fri, 10 May 2019 18:40:01 +0100	[thread overview]
Message-ID: <20190510183909.65732a67@donnerap.cambridge.arm.com> (raw)
Message-ID: <20190510174001.INihKPyzUlBV5wl3vi6VTUNhf8NhzmH3J-We1VUt7cw@z> (raw)
In-Reply-To: <1549767042-95827-11-git-send-email-fenghua.yu@intel.com>

On Sat,  9 Feb 2019 18:50:39 -0800
Fenghua Yu <fenghua.yu@intel.com> wrote:

Hi,

> From: Babu Moger <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.

I don't think vendor detection is the right approach. The Linux userland
interface should be even architecture agnostic, not to speak of different
vendors.

But even if we need this for some reason ...

> 
> Signed-off-by: Babu Moger <babu.moger@amd.com>
> Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
> ---
>  tools/testing/selftests/resctrl/resctrl.h       | 13 +++++
>  tools/testing/selftests/resctrl/resctrl_tests.c | 63 +++++++++++++++++++++++++
>  2 files changed, 76 insertions(+)
> 
> diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h
> index dadbb3d0cad8..974ec2de5fee 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;

There are more CPU vendors than that ;-)
And to not encourage this kind of vendor specific tests, I'd keep this exposure to a minimum.

In my version I have a simple is_amd() function, to cover the L3 vs. physical pacakges differences.

>  
>  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 3959b2b0671a..1d9adcfbdb4c 100644
> --- a/tools/testing/selftests/resctrl/resctrl_tests.c
> +++ b/tools/testing/selftests/resctrl/resctrl_tests.c
> @@ -14,6 +14,66 @@
>  #define BENCHMARK_ARGS		64
>  #define BENCHMARK_ARG_SIZE	64
>  
> +/**
> + * This variables provides information about the vendor
> + */
> +int genuine_intel;
> +int authentic_amd;
> +
> +void lcpuid(const unsigned int leaf, const unsigned int subleaf,
> +	    struct cpuid_out *out)

There is a much easier way to detect the vendor, without resorting to
(unchecked) inline assembly in userland:
I changed this to scan /proc/cpuinfo for a line starting with vendor_id,
then use the information there. This should work everywhere.
http://linux-arm.org/git?p=linux-ap.git;a=commitdiff;h=ce9c9f3a40e52

Cheers,
Andre

> +{
> +	if (!out)
> +		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)
> +{
> +	struct cpuid_out vendor;
> +	int ret = 0;
> +
> +	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");
> @@ -110,6 +170,9 @@ 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++) {


  reply	other threads:[~2019-05-10 17:39 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-10  2:50 [PATCH v7 00/13] selftests/resctrl: Add resctrl selftest Fenghua Yu
2019-02-10  2:50 ` [PATCH v7 01/13] selftests/resctrl: Add README for resctrl tests Fenghua Yu
2019-02-10  2:50 ` [PATCH v7 02/13] selftests/resctrl: Add basic resctrl file system operations and data Fenghua Yu
2019-05-10 17:36   ` Andre Przywara
2019-05-10 19:00     ` Yu, Fenghua
2019-05-10 17:41   ` Borislav Petkov
2019-05-10 19:01     ` Yu, Fenghua
2019-02-10  2:50 ` [PATCH v7 03/13] selftests/resctrl: Read memory bandwidth from perf IMC counter and from resctrl file system Fenghua Yu
2019-02-10  2:50 ` [PATCH v7 04/13] selftests/resctrl: Add callback to start a benchmark Fenghua Yu
2019-05-10 17:37   ` Andre Przywara
2019-02-10  2:50 ` [PATCH v7 05/13] selftests/resctrl: Add built in benchmark Fenghua Yu
2019-05-10 17:37   ` Andre Przywara
2019-02-10  2:50 ` [PATCH v7 06/13] selftests/resctrl: Add MBM test Fenghua Yu
2019-05-10 17:37   ` Andre Przywara
2019-02-10  2:50 ` [PATCH v7 07/13] selftests/resctrl: Add MBA test Fenghua Yu
2019-05-10 17:37   ` Andre Przywara
2019-02-10  2:50 ` [PATCH v7 08/13] selftests/resctrl: Add Cache QoS Monitoring (CQM) selftest Fenghua Yu
2019-05-10 17:38   ` Andre Przywara
2019-02-10  2:50 ` [PATCH v7 09/13] selftests/resctrl: Add Cache Allocation Technology (CAT) selftest Fenghua Yu
2019-05-10 17:38   ` Andre Przywara
2019-02-10  2:50 ` [PATCH v7 10/13] selftests/resctrl: Add vendor detection mechanism Fenghua Yu
2019-05-10 17:39   ` Andre Przywara [this message]
2019-05-10 17:40     ` Andre Przywara
2019-05-14 17:20     ` James Morse
2019-05-14 19:40       ` André Przywara
2019-05-15  9:08         ` James Morse
2019-02-10  2:50 ` [PATCH v7 11/13] selftests/resctrl: Use cache index3 id for AMD schemata masks Fenghua Yu
2019-02-10  2:50 ` [PATCH v7 12/13] selftests/resctrl: Disable MBA and MBM tests for AMD Fenghua Yu
2019-05-10 17:40   ` Andre Przywara
2019-05-10 19:29     ` Yu, Fenghua
2019-05-14 17:17       ` Moger, Babu
2019-02-10  2:50 ` [PATCH v7 13/13] selftests/resctrl: Add the test in MAINTAINERS Fenghua Yu
2019-02-14 14:56 ` [PATCH v7 00/13] selftests/resctrl: Add resctrl selftest Fenghua Yu
2019-03-06 20:55   ` Moger, Babu
2019-02-27 18:07 ` Moger, Babu
2019-05-10 17:35 ` Andre Przywara
2019-05-10 19:20   ` Yu, Fenghua
2019-05-14 17:20     ` James Morse

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=20190510183909.65732a67@donnerap.cambridge.arm.com \
    --to=andre.przywara@arm.com \
    --cc=James.Morse@arm.com \
    --cc=arshiya.hayatkhan.pathan@intel.com \
    --cc=babu.moger@amd.com \
    --cc=bp@alien8.de \
    --cc=fenghua.yu@intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --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 \
    --subject='Re: [PATCH v7 10/13] selftests/resctrl: Add vendor detection mechanism' \
    /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

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).