qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [6567] KVM: Get all cpuid values from function 2 (Amit Shah)
@ 2009-02-09 15:50 Anthony Liguori
  2009-02-09 16:06 ` Avi Kivity
  0 siblings, 1 reply; 5+ messages in thread
From: Anthony Liguori @ 2009-02-09 15:50 UTC (permalink / raw)
  To: qemu-devel

Revision: 6567
          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6567
Author:   aliguori
Date:     2009-02-09 15:50:36 +0000 (Mon, 09 Feb 2009)

Log Message:
-----------
KVM: Get all cpuid values from function 2 (Amit Shah)

cpuid function 2 can have multiple values to describe cache behaviour.
Loop till we have fetched all the values.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

Modified Paths:
--------------
    trunk/target-i386/kvm.c

Modified: trunk/target-i386/kvm.c
===================================================================
--- trunk/target-i386/kvm.c	2009-02-09 15:50:31 UTC (rev 6566)
+++ trunk/target-i386/kvm.c	2009-02-09 15:50:36 UTC (rev 6567)
@@ -51,6 +51,32 @@
         struct kvm_cpuid_entry2 *c = &cpuid_data.entries[cpuid_i++];
 
         switch (i) {
+        case 2: {
+            /* Keep reading function 2 till all the input is received */
+            int times;
+
+            cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx);
+            times = eax & 0xff;
+
+            c->function = i;
+            c->flags |= KVM_CPUID_FLAG_STATEFUL_FUNC;
+            c->flags |= KVM_CPUID_FLAG_STATE_READ_NEXT;
+            c->eax = eax;
+            c->ebx = ebx;
+            c->ecx = ecx;
+            c->edx = edx;
+
+            for (j = 1; j < times; ++j) {
+                cpu_x86_cpuid(env, i, 0, &eax, &ebx, &ecx, &edx);
+                c->function = i;
+                c->flags |= KVM_CPUID_FLAG_STATEFUL_FUNC;
+                c->eax = eax;
+                c->ebx = ebx;
+                c->ecx = ecx;
+                c->edx = edx;
+            }
+            break;
+        }
         case 4:
         case 0xb:
         case 0xd:

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [6567] KVM: Get all cpuid values from function 2 (Amit Shah)
  2009-02-09 15:50 [Qemu-devel] [6567] KVM: Get all cpuid values from function 2 (Amit Shah) Anthony Liguori
@ 2009-02-09 16:06 ` Avi Kivity
  2009-02-09 16:46   ` Anthony Liguori
  0 siblings, 1 reply; 5+ messages in thread
From: Avi Kivity @ 2009-02-09 16:06 UTC (permalink / raw)
  To: qemu-devel

Anthony Liguori wrote:
> Revision: 6567
>           http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6567
> Author:   aliguori
> Date:     2009-02-09 15:50:36 +0000 (Mon, 09 Feb 2009)
>
> Log Message:
> -----------
> KVM: Get all cpuid values from function 2 (Amit Shah)
>
> cpuid function 2 can have multiple values to describe cache behaviour.
> Loop till we have fetched all the values.
>   

Note that if we are rescheduled on another cpu, or if another process 
calls cpuid 2 during the loop on the same cpu, this will break.

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [6567] KVM: Get all cpuid values from function 2 (Amit Shah)
  2009-02-09 16:06 ` Avi Kivity
@ 2009-02-09 16:46   ` Anthony Liguori
  2009-02-09 17:03     ` Amit Shah
  2009-02-09 18:27     ` Avi Kivity
  0 siblings, 2 replies; 5+ messages in thread
From: Anthony Liguori @ 2009-02-09 16:46 UTC (permalink / raw)
  To: qemu-devel

Avi Kivity wrote:
> Anthony Liguori wrote:
>> Revision: 6567
>>           http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6567
>> Author:   aliguori
>> Date:     2009-02-09 15:50:36 +0000 (Mon, 09 Feb 2009)
>>
>> Log Message:
>> -----------
>> KVM: Get all cpuid values from function 2 (Amit Shah)
>>
>> cpuid function 2 can have multiple values to describe cache behaviour.
>> Loop till we have fetched all the values.
>>   
>
> Note that if we are rescheduled on another cpu, or if another process 
> calls cpuid 2 during the loop on the same cpu, this will break.

That's unfortunate.  If cpuid values can differ for individual 
processors, than I don't see a great way to avoid this problem in general.

Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [6567] KVM: Get all cpuid values from function 2 (Amit Shah)
  2009-02-09 16:46   ` Anthony Liguori
@ 2009-02-09 17:03     ` Amit Shah
  2009-02-09 18:27     ` Avi Kivity
  1 sibling, 0 replies; 5+ messages in thread
From: Amit Shah @ 2009-02-09 17:03 UTC (permalink / raw)
  To: qemu-devel

On (Mon) Feb 09 2009 [10:46:25], Anthony Liguori wrote:
> Avi Kivity wrote:
>> Anthony Liguori wrote:
>>> Revision: 6567
>>>           http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6567
>>> Author:   aliguori
>>> Date:     2009-02-09 15:50:36 +0000 (Mon, 09 Feb 2009)
>>>
>>> Log Message:
>>> -----------
>>> KVM: Get all cpuid values from function 2 (Amit Shah)
>>>
>>> cpuid function 2 can have multiple values to describe cache behaviour.
>>> Loop till we have fetched all the values.
>>>   
>>
>> Note that if we are rescheduled on another cpu, or if another process  
>> calls cpuid 2 during the loop on the same cpu, this will break.
>
> That's unfortunate.  If cpuid values can differ for individual  
> processors, than I don't see a great way to avoid this problem in 
> general.

No, it won't differ for individual processors, but these values are
stateful. cpuid 2 output depends on how many times it gets called.

I can use sched_getaffinity() and then sched_setaffinity() if it's not
pinned to one cpu to avoid the process jumping around; but can't think
of how it can be avoided across scheduling points. Maybe a new ioctl(!)
to return a struct with all these values?

In any case, no current CPU has multiple values for cpuid fn 2.

Amit

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [6567] KVM: Get all cpuid values from function 2 (Amit Shah)
  2009-02-09 16:46   ` Anthony Liguori
  2009-02-09 17:03     ` Amit Shah
@ 2009-02-09 18:27     ` Avi Kivity
  1 sibling, 0 replies; 5+ messages in thread
From: Avi Kivity @ 2009-02-09 18:27 UTC (permalink / raw)
  To: qemu-devel

Anthony Liguori wrote:
>>
>> Note that if we are rescheduled on another cpu, or if another process 
>> calls cpuid 2 during the loop on the same cpu, this will break.
>
> That's unfortunate.  If cpuid values can differ for individual 
> processors, than I don't see a great way to avoid this problem in 
> general.

The problem is not mismatched cpus, it's hidden state within the cpu.

If you look at the code, it just calls cpuid(2) repeatedly, and expects 
different results for the same inputs.  That means the cpuid code in the 
cpu looks something like this:

    if (function == 2) {
        switch (hidden_function_2_state++) {
              // return different results
        }
    }

this hidden state is of course not maintained across context switches.  
Only the kernel can extract this information reliably.  Note that we 
also need save this hidden state as part of savevm.

The word "unfortunate" doesn't even begin to describe it, even if one 
favors understatements.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-02-09 18:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-09 15:50 [Qemu-devel] [6567] KVM: Get all cpuid values from function 2 (Amit Shah) Anthony Liguori
2009-02-09 16:06 ` Avi Kivity
2009-02-09 16:46   ` Anthony Liguori
2009-02-09 17:03     ` Amit Shah
2009-02-09 18:27     ` Avi Kivity

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