Skip to contentSkip to conversation

KVM guest cpu L3 cache and cpufreq

Qemu-devel Benoît Canet 3 participants 12 messages Aug 13, 2013 – Aug 27, 2013

lore
Share & tools
lore
#0 lore raw

Hi,

I noticed that the l3 cache size of a guest /proc/cpuinfo is not the same as the l3 cache size of the host.

I did not found any references to this in the qemu and KVM code.

Is the size of the guest L3 cache fixed in hardware ?

Can a patch be written to set it ?

Similarly I noticed that the frequency in the guest was not reflecting the frequency scaling of the host.

Could anything be done for this ?

Best regards

Benoît

#1 lore raw
Quoted 10 lines · Benoît Canet

Hi,

I noticed that the l3 cache size of a guest /proc/cpuinfo is not the same as the l3 cache size of the host.

I did not found any references to this in the qemu and KVM code.

Is the size of the guest L3 cache fixed in hardware ?

No, it is hardcoded somewhere in qemu cpuid code.

Quoted 2 lines

Can a patch be written to set it ?

Yes.

Quoted 3 lines

Similarly I noticed that the frequency in the guest was not reflecting the frequency scaling of the host.

Not sure what you mean here. Frequency as seen where?

Quoted 5 lines

Could anything be done for this ?

Best regards

Benoît

--
Gleb.

#2 lore raw

Hi,

Thanks for the answer.

Quoted 9 lines · Benoît Canet
Quoted 8 lines

Hi,

I noticed that the l3 cache size of a guest /proc/cpuinfo is not the same as the l3 cache size of the host.

I did not found any references to this in the qemu and KVM code.

Quoted 7 lines
Quoted 2 lines

Is the size of the guest L3 cache fixed in hardware ?

No, it is hardcoded somewhere in qemu cpuid code.

Quoted 2 lines

Can a patch be written to set it ?

Yes.

Ok I'll try to do that.

Quoted 5 lines
Quoted 4 lines

Similarly I noticed that the frequency in the guest was not reflecting the frequency scaling of the host.

Not sure what you mean here. Frequency as seen where?

The frequency seen in the host /proc/cpuinfo and the guest /proc/cpuinfo differs when a governor kick the cpu frequency scaling: the guest still show the maximum frequency of the cpu.

Could this value be reflected dynamically ?

Best regards

Benoît

Quoted 9 lines
Quoted 6 lines

Could anything be done for this ?

Best regards

Benoît

--
Gleb.

#3 lore raw
Quoted 16 lines · Benoît Canet

Hi,

Thanks for the answer.

Quoted 11 lines · Benoît Canet
Quoted 10 lines

Hi,

I noticed that the l3 cache size of a guest /proc/cpuinfo is not the same as the l3 cache size of the host.

I did not found any references to this in the qemu and KVM code.

Is the size of the guest L3 cache fixed in hardware ?

Quoted 8 lines
Quoted 5 lines

No, it is hardcoded somewhere in qemu cpuid code.

Quoted 2 lines

Can a patch be written to set it ?

Yes.

Ok I'll try to do that.

Talk to Eduardo since this is related to cpuid configuration and he is an expert.

Quoted 10 lines
Quoted 5 lines
Quoted 4 lines

Similarly I noticed that the frequency in the guest was not reflecting the frequency scaling of the host.

Not sure what you mean here. Frequency as seen where?

The frequency seen in the host /proc/cpuinfo and the guest /proc/cpuinfo differs when a governor kick the cpu frequency scaling: the guest still show the maximum frequency of the cpu.

KVM does not emulate frequency scaling. It does not make sense for a guest.

Quoted 2 lines

Could this value be reflected dynamically ?

Not sure frequency scaling can be implemented only for read.

--
Gleb.

#4 lore raw
Quoted 2 lines

Talk to Eduardo since this is related to cpuid configuration and he is an expert.

I found the following in target-i386/cpu.c

    case 0x80000006:
        /* cache info (L2 cache) */
        *eax = 0;
        *ebx = 0x42004200;
        *ecx = 0x02008140;
        *edx = 0;
        break;
Quoted 1 line

From the AMD cpuid book it look like the L3 settings are not defined (edx).

Eduardo: A user I know want to be able to set the size of the guest L3 cache. I am ok to write a patch to do so.

Do you have some recommandations regarding the other fields of the edx register ? What would be an acceptable user interface to set this ?

Best regards

Benoît

#5 lore raw
Quoted 13 lines · Benoît Canet
Quoted 2 lines

Talk to Eduardo since this is related to cpuid configuration and he is an expert.

I found the following in target-i386/cpu.c

    case 0x80000006:
        /* cache info (L2 cache) */
        *eax = 0;
        *ebx = 0x42004200;
        *ecx = 0x02008140;
        *edx = 0;
        break;
Quoted 6 lines

From the AMD cpuid book it look like the L3 settings are not defined (edx).

Eduardo: A user I know want to be able to set the size of the guest L3 cache. I am ok to write a patch to do so.

Do you have some recommandations regarding the other fields of the edx register ?

Probably it will be a good idea to let each CPU model have their own defaults for the cache information.

Quoted 1 line

What would be an acceptable user interface to set this ?

Things I can remember from the top of my head:

* It would be interesting to redo this patch, before doing anything else:
https://github.com/ehabkost/qemu-hacks/commit/10b675fa1269a65a553586545fdbcd95ace79d65
* We need to keep compatibility on existing machine-types (not change the cache size);
* If some information is reported on multiple CPUID leaves, we need to keep them consistent with each other (see the FIXME comments on the URL above);
* Please use QOM properties to allow the cache sizes/topologies to be set.

Signature · 1 line
Eduardo
#6 lore raw

Hello Eduardo,

I read a bit about caches on wikipedia.

If I understand correctly changing the CPUID L3 cache infos in QEMU will change the value displayed in the guest /proc/cpuinfo but will not change the size of the l3 cache used by the hardware. So I am chasing a cosmetic bug. If it right ?

Quoted 4 lines
Quoted 1 line

Do you have some recommandations regarding the other fields of the edx register ?

Probably it will be a good idea to let each CPU model have their own defaults for the cache information.

Do you mean querying the host CPUID registers and forwarding the values to the guest ?

Quoted 5 lines
Quoted 2 lines

What would be an acceptable user interface to set this ?

Things I can remember from the top of my head:

Quoted 7 lines

* It would be interesting to redo this patch, before doing anything else:

   https://github.com/ehabkost/qemu-hacks/commit/10b675fa1269a65a553586545fdbcd95ace79d65

* We need to keep compatibility on existing machine-types (not change the cache size);
* If some information is reported on multiple CPUID leaves, we need to keep them consistent with each other (see the FIXME comments on the URL above);

I could write a patch to fix broken CPUID leaves.

But how would it work regarding compatibility ? Is it right to just fix the leaves or does the machine type rule apply here ?

Best regards

Benoît

#7 lore raw
Quoted 10 lines · Benoît Canet

Hello Eduardo,

I read a bit about caches on wikipedia.

If I understand correctly changing the CPUID L3 cache infos in QEMU will change the value displayed in the guest /proc/cpuinfo but will not change the size of the l3 cache used by the hardware. So I am chasing a cosmetic bug. If it right ?

Right.

--
Gleb.

#8 lore raw
Quoted 4 lines · Gleb Natapov
Quoted 3 lines · Benoît Canet

Hello Eduardo,

Quoted 9 lines
Quoted 7 lines

I read a bit about caches on wikipedia.

If I understand correctly changing the CPUID L3 cache infos in QEMU will change the value displayed in the guest /proc/cpuinfo but will not change the size of the l3 cache used by the hardware. So I am chasing a cosmetic bug. If it right ?

Right.

Well, actually not entirely. An application can query cache sizes and adjust its algorithms accordingly in which case performance can be suboptimal if information in a guest is not accurate.

--
Gleb.

#9 lore raw
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines

If I understand correctly changing the CPUID L3 cache infos in QEMU will change the value displayed in the guest /proc/cpuinfo but will not change the size of the l3 cache used by the hardware. So I am chasing a cosmetic bug. If it right ?

Right.

Well, actually not entirely. An application can query cache sizes and adjust its algorithms accordingly in which case performance can be suboptimal if information in a guest is not accurate.

So maybe what is missing is a CPUID passthrough mode triggered when -cpu host is used ?

Best regards

Benoît

#10 lore raw
Quoted 5 lines · Benoît Canet
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

If I understand correctly changing the CPUID L3 cache infos in QEMU will change the value displayed in the guest /proc/cpuinfo but will not change the size of the l3 cache used by the hardware. So I am chasing a cosmetic bug. If it right ?

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Right.

Well, actually not entirely. An application can query cache sizes and adjust its algorithms accordingly in which case performance can be suboptimal if information in a guest is not accurate.

So maybe what is missing is a CPUID passthrough mode triggered when -cpu host is used ?

That is missing too, but it should not be default with other CPU models.

--
Gleb.

#11 lore raw
In reply to Benoît Canet

On Tue, Aug 27, 2013 at 03:18:16PM +0200, Benoît Canet wrote:
[...]

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Do you have some recommandations regarding the other fields of the edx register ?

Probably it will be a good idea to let each CPU model have their own defaults for the cache information.

Do you mean querying the host CPUID registers and forwarding the values to the guest ?

No, I mean that it would make sense to have "-cpu 486" expose a different cache topology from "-cpu Haswell" by default.

But a "forward host cache information to guest" mode may be useful, too, and it could be the default mode for "-cpu host".

Quoted 13 lines
Quoted 6 lines
Quoted 3 lines

What would be an acceptable user interface to set this ?

Things I can remember from the top of my head:

Quoted 7 lines

* It would be interesting to redo this patch, before doing anything else:

   https://github.com/ehabkost/qemu-hacks/commit/10b675fa1269a65a553586545fdbcd95ace79d65

* We need to keep compatibility on existing machine-types (not change the cache size);
* If some information is reported on multiple CPUID leaves, we need to keep them consistent with each other (see the FIXME comments on the URL above);

Quoted 4 lines

I could write a patch to fix broken CPUID leaves.

But how would it work regarding compatibility ? Is it right to just fix the leaves or does the machine type rule apply here ?

Yes, if you change anything guest-visible, you need to keep compatibility on older machine-types.

Signature · 1 line
Eduardo