Skip to contentSkip to conversation

mmx sse emulation

DISCUSSION Ashish Bijlani 3 participants 8 messages Nov 5, 2008 – Nov 6, 2008 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hi,

I want to emulate mmx/sse for hvm guests when applications inside hvm guests are compiled for mmx/sse but the underlying hardware doesn't support mmx/sse. What is the best place to do this? i'm looking at x86_emulate but i dunno if that is the best place to put the emulation layer. any suggestions?? also, currently movq emulation is present in x86_emulate for handling mmio. however, i realized that get_fpu fails if the hardware doesn't have mmx capability. is it true or am i missing something here?

Thanks,
Ashish

#1 lore raw
Quoted 9 lines · Ashish Bijlani

I want to emulate mmx/sse for hvm guests when applications inside hvm guests are compiled for mmx/sse but the underlying hardware doesn't support mmx/sse. What is the best place to do this? i'm looking at x86_emulate but i dunno if that is the best place to put the emulation layer. any suggestions?? also, currently movq emulation is present in x86_emulate for handling mmio. however, i realized that get_fpu fails if the hardware doesn't have mmx capability. is it true or am i missing something here?

x86_emulate() does its work by using the actual underlying processor instructions (really it is a system emulator rather than an instruction emulator). This wouldn't necessarily stop you adding full emulation for certain instructions like SSE/MMX though, and it's probably the right place to put that sort of thing.

-- Keir

#2 lore raw

Hi Keir,

Thanks for the help. I've one more doubt though.

Calling x86_emulate from do_device_not_available after validating the EM flag would work? Of course provided MMX/SS emulation code reside in x86_emulate. Please lemme know.

Thanks,
Ashish

Quoted 22 lines · Keir Fraser
Quoted 9 lines · Ashish Bijlani

I want to emulate mmx/sse for hvm guests when applications inside hvm guests are compiled for mmx/sse but the underlying hardware doesn't support mmx/sse. What is the best place to do this? i'm looking at x86_emulate but i dunno if that is the best place to put the emulation layer. any suggestions?? also, currently movq emulation is present in x86_emulate for handling mmio. however, i realized that get_fpu fails if the hardware doesn't have mmx capability. is it true or am i missing something here?

x86_emulate() does its work by using the actual underlying processor instructions (really it is a system emulator rather than an instruction emulator). This wouldn't necessarily stop you adding full emulation for certain instructions like SSE/MMX though, and it's probably the right place to put that sort of thing.

-- Keir

#3 lore raw
Quoted 7 lines · Ashish Bijlani

Hi Keir,

Thanks for the help. I've one more doubt though.

Calling x86_emulate from do_device_not_available after validating the EM flag would work? Of course provided MMX/SS emulation code reside in x86_emulate. Please lemme know.

Sounds about right to me.

-- Keir

#4 lore raw
In reply to Ashish Bijlani
Quoted 5 lines · Ashish Bijlani

Hi,

I want to emulate mmx/sse for hvm guests when applications inside hvm guests are compiled for mmx/sse but the underlying hardware doesn't support mmx/sse.

First: HVM guests require a virtualization capable processor. AFAIK all these processors support at least SSE2 (if not SSE3). So why do you want to emulate these instructions?
Second: Applications should check the CPUID bit before using instruction set extension. So, if the host processor does not support MMX/SSE, the guest shouldn't see this bit, too. And I doubt that you are faster with emulating SSE compared to legacy x87-FPU executed natively.

So, what is the use-case of your proposal? Or am I missing something here?

Regards,
Andre.

Quoted 9 lines

What is the best place to do this? i'm looking at x86_emulate but i dunno if that is the best place to put the emulation layer. any suggestions?? also, currently movq emulation is present in x86_emulate for handling mmio. however, i realized that get_fpu fails if the hardware doesn't have mmx capability. is it true or am i missing something here?

Thanks,
Ashish

Signature · 3 lines
Andre Przywara
AMD-OSRC (Dresden)
Tel: x84917
#5 lore raw

Hi Andre,

You are absolutely right. All hardware virtualization capable machines have recent simd technology built-in. However, I'm just trying to evaluate a case when HVM guests rely on the virtual hardware platform and not on the actual hardware platform. Precisely, what would be the performance gain/loss if hypervisor has to emulate the functionality.

-Ashish

Quoted 38 lines · Andre Przywara
Quoted 6 lines · Ashish Bijlani

Hi,

I want to emulate mmx/sse for hvm guests when applications inside hvm guests are compiled for mmx/sse but the underlying hardware doesn't support mmx/sse.

First: HVM guests require a virtualization capable processor. AFAIK all these processors support at least SSE2 (if not SSE3). So why do you want to emulate these instructions?
Second: Applications should check the CPUID bit before using instruction set extension. So, if the host processor does not support MMX/SSE, the guest shouldn't see this bit, too. And I doubt that you are faster with emulating SSE compared to legacy x87-FPU executed natively.

So, what is the use-case of your proposal? Or am I missing something here?

Regards,
Andre.

Quoted 10 lines

What is the best place to do this? i'm looking at

x86_emulate but i dunno if that is the best place to put the emulation layer. any suggestions?? also, currently movq emulation is present in x86_emulate for handling mmio. however, i realized that get_fpu fails if the hardware doesn't have mmx capability. is it true or am i missing something here?

Thanks,
Ashish

--
Andre Przywara
AMD-OSRC (Dresden)
Tel: x84917

#6 lore raw

If I'm not wrong, Bochs emulates SSE/MMX instructions and qemu uses dynamic translation. Does this mean that I use SSE/MMX emulation code from Bochs to put under x86_emulate? or am I missing something? Thanks.

Quoted 50 lines · Ashish Bijlani

Hi Andre,

You are absolutely right. All hardware virtualization capable machines have recent simd technology built-in. However, I'm just trying to evaluate a case when HVM guests rely on the virtual hardware platform and not on the actual hardware platform. Precisely, what would be the performance gain/loss if hypervisor has to emulate the functionality.

-Ashish

Quoted 38 lines · Andre Przywara
Quoted 6 lines · Ashish Bijlani

Hi,

I want to emulate mmx/sse for hvm guests when applications inside hvm guests are compiled for mmx/sse but the underlying hardware doesn't support mmx/sse.

First: HVM guests require a virtualization capable processor. AFAIK all these processors support at least SSE2 (if not SSE3). So why do you want to emulate these instructions?
Second: Applications should check the CPUID bit before using instruction set extension. So, if the host processor does not support MMX/SSE, the guest shouldn't see this bit, too. And I doubt that you are faster with emulating SSE compared to legacy x87-FPU executed natively.

So, what is the use-case of your proposal? Or am I missing something here?

Regards,
Andre.

Quoted 10 lines

What is the best place to do this? i'm looking at

x86_emulate but i dunno if that is the best place to put the emulation layer. any suggestions?? also, currently movq emulation is present in x86_emulate for handling mmio. however, i realized that get_fpu fails if the hardware doesn't have mmx capability. is it true or am i missing something here?

Thanks,
Ashish

--
Andre Przywara
AMD-OSRC (Dresden)
Tel: x84917

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

in an attempt to emulate mmx/sse instructions from within xen, i tried setting EM and NE bit in CR0 to have mmx/sse instructions fault into xen. however, the hvm guest doesn't boot after that. also, i don't get any "device_not_available_fault" any ideas what could be wrong? am i missing something?

this is what i've done :-

int hvm_set_cr0(unsigned long value) {
...
value &= ~HVM_CR0_GUEST_RESERVED_BITS;

value |= (X86_CR0_EM | X86_CR0_NE); // EMULATE FPU

/* ET is reserved and should be always be 1. */

    value |= X86_CR0_ET;

...
}

I run system with dom0 4 vcpus on 0-2 cpu cores and hvm 1 vcpu on the 3rd cpu core

-Ashish

Quoted 88 lines · mats petersson

2008/11/5 Ashish Bijlani <[email protected]>

Quoted 15 lines

If I'm not wrong, Bochs emulates SSE/MMX instructions and qemu uses dynamic translation. Does this mean that I use SSE/MMX emulation code from Bochs to put under x86_emulate? or am I missing something? Thanks.

Quoted 7 lines · Ashish Bijlani

Hi Andre,

You are absolutely right. All hardware virtualization capable machines have recent simd technology built-in. However, I'm just trying to evaluate a case when HVM guests rely on the virtual hardware platform and not on the actual hardware platform. Precisely, what would be the performance gain/loss if hypervisor has to emulate the functionality.

The performance loss would be HUGE. First of all, you'd fall into the hypervisor and get back out again, which takes a fair few cycles (like more than 100x or more that of a single instruction). Then you have to emulate the actual instruction itself, which will be the small part of the ovehead.

Many SSE/MMX/3DNow! instructions execute in 1-2 clockcycles. My guess would be that it would reduce any SSE optimized code to a crawl (like in the order of 100-1000x slower). Such an application would be much better off running in x87 mode.

I was looking at doing SSE/MMX emulation in x86_emulate a long time ago, but the purpose of that wasn't to emulate SSE/MMX as such, but rather allow SSE/MMX to access emulated hardware (such as video memory).

--
Mats

Quoted 48 lines

-Ashish

Quoted 42 lines · Andre Przywara
Quoted 6 lines · Ashish Bijlani

Hi,

I want to emulate mmx/sse for hvm guests when applications inside hvm guests are compiled for mmx/sse but the underlying hardware doesn't support mmx/sse.

First: HVM guests require a virtualization capable processor. AFAIK all these processors support at least SSE2 (if not SSE3). So why do you want to
emulate these instructions?
Second: Applications should check the CPUID bit before using instruction set
extension. So, if the host processor does not support MMX/SSE, the guest shouldn't see this bit, too. And I doubt that you are faster with emulating
SSE compared to legacy x87-FPU executed natively.

So, what is the use-case of your proposal? Or am I missing something here?

Regards,
Andre.

Quoted 10 lines

What is the best place to do this? i'm looking at

x86_emulate but i dunno if that is the best place to put the emulation layer. any suggestions?? also, currently movq emulation is present in x86_emulate for handling mmio. however, i realized that get_fpu fails if the hardware doesn't have mmx capability. is it true or am i missing something here?

Thanks,
Ashish

--
Andre Przywara
AMD-OSRC (Dresden)
Tel: x84917

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel