diff mbox

[1/2] show hypervisor information on cpuinfo

Message ID 1233859341-10419-2-git-send-email-glommer@redhat.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Glauber Costa Feb. 5, 2009, 6:42 p.m. UTC
From: Glauber Costa <gcosta@redhat.com>

It is useful to easily grab information about whether or not
we're running on top of a hypervisor. And in case affirmative,
which one.

This patch shows it in a newly added "hypervisor" field to cpuinfo.
This seems to me like the best suited place for this.

We currently differentiate between vmware and none.

Signed-off-by: Glauber Costa <gcosta@redhat.com>
---
 arch/x86/include/asm/hypervisor.h |    1 +
 arch/x86/kernel/cpu/hypervisor.c  |    8 ++++++++
 arch/x86/kernel/cpu/proc.c        |    8 ++++++--
 3 files changed, 15 insertions(+), 2 deletions(-)

Comments

Alok Kataria Feb. 5, 2009, 6:53 p.m. UTC | #1
I am all for it.

Just one nit, below.

>  
> +char * __cpuinit hypervisor_str(struct cpuinfo_x86 *c)
> +{
> +	if (c->x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE)
> +		return "VMWare";

Better to have "VMware" string instead.

Thanks,
Alok

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ingo Molnar Feb. 5, 2009, 7:02 p.m. UTC | #2
* Glauber Costa <glommer@redhat.com> wrote:

> +char * __cpuinit hypervisor_str(struct cpuinfo_x86 *c)
> +{
> +	if (c->x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE)
> +		return "VMWare";
> +	else
> +		return "none";
> +}

i'd suggest these variants instead:

 virtualization:	native kernel
 virtualization:	KVM guest
 virtualization:	VMWare guest
 virtualization:	Linux guest

	Ingo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Chris Wright Feb. 5, 2009, 7:05 p.m. UTC | #3
* Ingo Molnar (mingo@elte.hu) wrote:
>  virtualization:	Linux guest

That's confusing.  Meaning lguest?  These are all Linux guests ;-)
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Anthony Liguori Feb. 5, 2009, 7:08 p.m. UTC | #4
Ingo Molnar wrote:
> * Glauber Costa <glommer@redhat.com> wrote:
>
>   
>> +char * __cpuinit hypervisor_str(struct cpuinfo_x86 *c)
>> +{
>> +	if (c->x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE)
>> +		return "VMWare";
>> +	else
>> +		return "none";
>> +}
>>     
>
> i'd suggest these variants instead:
>
>  virtualization:	native kernel
>   

I don't think "native kernel" really ports well to other architectures 
(like s390 or PPC) that always have hypervisors present in some form.  I 
think "none" makes more sense in the case of bare metal x86.

Regards,

Anthony Liguori

>  virtualization:	KVM guest
>  virtualization:	VMWare guest
>  virtualization:	Linux guest
>
> 	Ingo
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>   

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/arch/x86/include/asm/hypervisor.h b/arch/x86/include/asm/hypervisor.h
index 369f5c5..a0c0b0f 100644
--- a/arch/x86/include/asm/hypervisor.h
+++ b/arch/x86/include/asm/hypervisor.h
@@ -22,5 +22,6 @@ 
 
 extern unsigned long get_hypervisor_tsc_freq(void);
 extern void init_hypervisor(struct cpuinfo_x86 *c);
+extern char *hypervisor_str(struct cpuinfo_x86 *c);
 
 #endif
diff --git a/arch/x86/kernel/cpu/hypervisor.c b/arch/x86/kernel/cpu/hypervisor.c
index fb5b86a..8c3fca7 100644
--- a/arch/x86/kernel/cpu/hypervisor.c
+++ b/arch/x86/kernel/cpu/hypervisor.c
@@ -51,6 +51,14 @@  hypervisor_set_feature_bits(struct cpuinfo_x86 *c)
 	}
 }
 
+char * __cpuinit hypervisor_str(struct cpuinfo_x86 *c)
+{
+	if (c->x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE)
+		return "VMWare";
+	else
+		return "none";
+}
+
 void __cpuinit init_hypervisor(struct cpuinfo_x86 *c)
 {
 	detect_hypervisor_vendor(c);
diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c
index 01b1244..3700607 100644
--- a/arch/x86/kernel/cpu/proc.c
+++ b/arch/x86/kernel/cpu/proc.c
@@ -4,6 +4,8 @@ 
 #include <linux/seq_file.h>
 #include <linux/cpufreq.h>
 
+#include <asm/hypervisor.h>
+
 /*
  *	Get CPU information for use by the procfs.
  */
@@ -90,12 +92,14 @@  static int show_cpuinfo(struct seq_file *m, void *v)
 		   "vendor_id\t: %s\n"
 		   "cpu family\t: %d\n"
 		   "model\t\t: %u\n"
-		   "model name\t: %s\n",
+		   "model name\t: %s\n"
+		   "hypervisor\t: %s\n",
 		   cpu,
 		   c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
 		   c->x86,
 		   c->x86_model,
-		   c->x86_model_id[0] ? c->x86_model_id : "unknown");
+		   c->x86_model_id[0] ? c->x86_model_id : "unknown",
+		   hypervisor_str(c));
 
 	if (c->x86_mask || c->cpuid_level >= 0)
 		seq_printf(m, "stepping\t: %d\n", c->x86_mask);