All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/2] [RFC] Make vmport report the processor speed
Date: Wed, 07 Jan 2009 10:46:18 -0600	[thread overview]
Message-ID: <4964DC5A.50802@codemonkey.ws> (raw)
In-Reply-To: <1231171871-2320-2-git-send-email-agraf@suse.de>

Alexander Graf wrote:
> If VMware ESX finds itself virtualized (read: inside VMware), it reads the TSC speed
> from its backdoor, because measuring the TSC inside a VM is not exact.
>
> This patch implements a hacky way to detect the TSC speed and passes that through to
> the VM. I am open to suggestions on how to improve the behavior.
> It also adds a magic return value of 2 on the version return, which is required by
> VMware ESX.
>
> WARNING: This implementation breaks on non-x86 hosts!
>   

BTW, this is very broken because of CPU migration or TSC frequency 
scaling.  In general, there's no way to do this correctly from 
userspace.  Looking at /proc/cpuinfo bogomips is probably more accurate.

Regards,

Anthony Liguori

> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
>  hw/vmport.c |   22 ++++++++++++++++++++++
>  1 files changed, 22 insertions(+), 0 deletions(-)
>
> diff --git a/hw/vmport.c b/hw/vmport.c
> index 884af3f..825fd92 100644
> --- a/hw/vmport.c
> +++ b/hw/vmport.c
> @@ -28,6 +28,7 @@
>  
>  //#define VMPORT_DEBUG
>  
> +#define VMPORT_CMD_GETPROCSPEED 0x01
>  #define VMPORT_CMD_GETVERSION 0x0a
>  #define VMPORT_CMD_GETRAMSIZE 0x14
>  
> @@ -87,6 +88,7 @@ static uint32_t vmport_cmd_get_version(void *opaque, uint32_t addr)
>  {
>      CPUState *env = cpu_single_env;
>      env->regs[R_EBX] = VMPORT_MAGIC;
> +    env->regs[R_ECX] = 2;
>      return 6;
>  }
>  
> @@ -97,6 +99,25 @@ static uint32_t vmport_cmd_ram_size(void *opaque, uint32_t addr)
>      return ram_size;
>  }
>  
> +
> +static inline int64_t rdtsc(void)
> +{
> +    int64_t val;
> +    asm volatile ("rdtsc" : "=A" (val));
> +    return val;
> +}
> +
> +static uint32_t vmport_cmd_proc_speed(void *opaque, uint32_t addr)
> +{
> +    static uint64_t tsc = 0;
> +    if ( tsc == 0 ) {
> +        tsc = rdtsc();
> +        usleep(100000);
> +        tsc = (rdtsc() - tsc) / 100000;
> +    }
> +    return (tsc / 66) * 66;
> +}
> +
>  void vmport_init(void)
>  {
>      register_ioport_read(0x5658, 1, 4, vmport_ioport_read, &port_state);
> @@ -105,4 +126,5 @@ void vmport_init(void)
>      /* Register some generic port commands */
>      vmport_register(VMPORT_CMD_GETVERSION, vmport_cmd_get_version, NULL);
>      vmport_register(VMPORT_CMD_GETRAMSIZE, vmport_cmd_ram_size, NULL);
> +    vmport_register(VMPORT_CMD_GETPROCSPEED, vmport_cmd_proc_speed, NULL);
>  }
>   

      parent reply	other threads:[~2009-01-07 16:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-05 16:11 [Qemu-devel] [PATCH 0/2] VMware ESX guest bringup (partial) Alexander Graf
2009-01-05 16:11 ` [Qemu-devel] [PATCH 1/2] [RFC] Make vmport report the processor speed Alexander Graf
2009-01-05 16:11   ` [Qemu-devel] [PATCH 2/2] Add phenom CPU descriptor Alexander Graf
2009-01-09 23:16     ` Alexander Graf
2009-01-09 23:36       ` Anthony Liguori
2009-01-05 16:37   ` [Qemu-devel] [PATCH 1/2] [RFC] Make vmport report the processor speed Anthony Liguori
2009-01-07  6:58     ` Alexander Graf
2009-01-06  4:24   ` François Revol
2009-01-06  4:56     ` Anthony Liguori
2009-01-06 22:33   ` Jamie Lokier
2009-01-07  6:29     ` Alexander Graf
2009-01-07 10:23       ` François Revol
2009-01-07 11:15         ` Alexander Graf
2009-01-07 11:32           ` François Revol
2009-01-07 14:34             ` Alexander Graf
2009-01-07 14:48               ` François Revol
2009-01-07 15:44                 ` Alexander Graf
2009-01-07 16:46   ` Anthony Liguori [this message]

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=4964DC5A.50802@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.