diff mbox series

[12/14] i386/cpu: Store LAPIC bus frequency in CPU structure

Message ID 20200309235411.76587-13-liran.alon@oracle.com (mailing list archive)
State New, archived
Headers show
Series : hw/i386/vmport: Bug fixes and improvements | expand

Commit Message

Liran Alon March 9, 2020, 11:54 p.m. UTC
No functional change.
This information will be used by following patches.

Reviewed-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Signed-off-by: Liran Alon <liran.alon@oracle.com>
---
 linux-headers/asm-x86/kvm.h | 4 ++++
 target/i386/cpu.h           | 1 +
 target/i386/kvm.c           | 6 +++---
 3 files changed, 8 insertions(+), 3 deletions(-)

Comments

Michael S. Tsirkin March 10, 2020, 9:29 a.m. UTC | #1
On Tue, Mar 10, 2020 at 01:54:09AM +0200, Liran Alon wrote:
> No functional change.
> This information will be used by following patches.
> 
> Reviewed-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
> Signed-off-by: Liran Alon <liran.alon@oracle.com>
> ---
>  linux-headers/asm-x86/kvm.h | 4 ++++
>  target/i386/cpu.h           | 1 +
>  target/i386/kvm.c           | 6 +++---
>  3 files changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h
> index 503d3f42da16..99eeaaf2f0b4 100644
> --- a/linux-headers/asm-x86/kvm.h
> +++ b/linux-headers/asm-x86/kvm.h
> @@ -446,4 +446,8 @@ struct kvm_pmu_event_filter {
>  #define KVM_PMU_EVENT_ALLOW 0
>  #define KVM_PMU_EVENT_DENY 1
>  
> +/* From arch/x86/kvm/lapic.h */
> +#define KVM_APIC_BUS_CYCLE_NS       1
> +#define KVM_APIC_BUS_FREQUENCY      (1000000000ULL / KVM_APIC_BUS_CYCLE_NS)
> +
>  #endif /* _ASM_X86_KVM_H */


This header is auto-generated from UAPI - you can't add
your own stuff here.


> diff --git a/target/i386/cpu.h b/target/i386/cpu.h
> index 576f309bbfc8..9c7cd7cde107 100644
> --- a/target/i386/cpu.h
> +++ b/target/i386/cpu.h
> @@ -1580,6 +1580,7 @@ typedef struct CPUX86State {
>      bool tsc_valid;
>      int64_t tsc_khz;
>      int64_t user_tsc_khz; /* for sanity check only */
> +    uint64_t apic_bus_freq;
>  #if defined(CONFIG_KVM) || defined(CONFIG_HVF)
>      void *xsave_buf;
>  #endif
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index 69eb43d796e6..00917196dffb 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -1496,6 +1496,8 @@ int kvm_arch_init_vcpu(CPUState *cs)
>          }
>      }
>  
> +    env->apic_bus_freq = KVM_APIC_BUS_FREQUENCY;
> +
>      /* Paravirtualization CPUIDs */
>      r = hyperv_handle_properties(cs, cpuid_data.entries);
>      if (r < 0) {
> @@ -1800,9 +1802,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
>          c = &cpuid_data.entries[cpuid_i++];
>          c->function = KVM_CPUID_SIGNATURE | 0x10;
>          c->eax = env->tsc_khz;
> -        /* LAPIC resolution of 1ns (freq: 1GHz) is hardcoded in KVM's
> -         * APIC_BUS_CYCLE_NS */
> -        c->ebx = 1000000;
> +        c->ebx = env->apic_bus_freq / 1000; /* Hz to KHz */
>          c->ecx = c->edx = 0;
>  
>          c = cpuid_find_entry(&cpuid_data.cpuid, kvm_base, 0);
> -- 
> 2.20.1
Liran Alon March 10, 2020, 10:53 a.m. UTC | #2
On 10/03/2020 11:29, Michael S. Tsirkin wrote:
> On Tue, Mar 10, 2020 at 01:54:09AM +0200, Liran Alon wrote:
>> No functional change.
>> This information will be used by following patches.
>>
>> Reviewed-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
>> Signed-off-by: Liran Alon <liran.alon@oracle.com>
>> ---
>>   linux-headers/asm-x86/kvm.h | 4 ++++
>>   target/i386/cpu.h           | 1 +
>>   target/i386/kvm.c           | 6 +++---
>>   3 files changed, 8 insertions(+), 3 deletions(-)
>>
>> diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h
>> index 503d3f42da16..99eeaaf2f0b4 100644
>> --- a/linux-headers/asm-x86/kvm.h
>> +++ b/linux-headers/asm-x86/kvm.h
>> @@ -446,4 +446,8 @@ struct kvm_pmu_event_filter {
>>   #define KVM_PMU_EVENT_ALLOW 0
>>   #define KVM_PMU_EVENT_DENY 1
>>   
>> +/* From arch/x86/kvm/lapic.h */
>> +#define KVM_APIC_BUS_CYCLE_NS       1
>> +#define KVM_APIC_BUS_FREQUENCY      (1000000000ULL / KVM_APIC_BUS_CYCLE_NS)
>> +
>>   #endif /* _ASM_X86_KVM_H */
>
> This header is auto-generated from UAPI - you can't add
> your own stuff here.
Oh I didn't notice that. OK, I will move definitions to somewhere else.
Is it fine by you if I will just put them then in target/i386/kvm.c 
directly?
Or do you prefer I will put them in target/i386/kvm_i386.h

-Liran
Michael S. Tsirkin March 10, 2020, 12:27 p.m. UTC | #3
On Tue, Mar 10, 2020 at 12:53:28PM +0200, Liran Alon wrote:
> 
> On 10/03/2020 11:29, Michael S. Tsirkin wrote:
> > On Tue, Mar 10, 2020 at 01:54:09AM +0200, Liran Alon wrote:
> > > No functional change.
> > > This information will be used by following patches.
> > > 
> > > Reviewed-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
> > > Signed-off-by: Liran Alon <liran.alon@oracle.com>
> > > ---
> > >   linux-headers/asm-x86/kvm.h | 4 ++++
> > >   target/i386/cpu.h           | 1 +
> > >   target/i386/kvm.c           | 6 +++---
> > >   3 files changed, 8 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h
> > > index 503d3f42da16..99eeaaf2f0b4 100644
> > > --- a/linux-headers/asm-x86/kvm.h
> > > +++ b/linux-headers/asm-x86/kvm.h
> > > @@ -446,4 +446,8 @@ struct kvm_pmu_event_filter {
> > >   #define KVM_PMU_EVENT_ALLOW 0
> > >   #define KVM_PMU_EVENT_DENY 1
> > > +/* From arch/x86/kvm/lapic.h */
> > > +#define KVM_APIC_BUS_CYCLE_NS       1
> > > +#define KVM_APIC_BUS_FREQUENCY      (1000000000ULL / KVM_APIC_BUS_CYCLE_NS)
> > > +
> > >   #endif /* _ASM_X86_KVM_H */
> > 
> > This header is auto-generated from UAPI - you can't add
> > your own stuff here.
> Oh I didn't notice that. OK, I will move definitions to somewhere else.
> Is it fine by you if I will just put them then in target/i386/kvm.c
> directly?
> Or do you prefer I will put them in target/i386/kvm_i386.h
> 
> -Liran
> 

That's Paolo's area. Myself, I don't really know what this is doing,
nor how is this supposed to work e.g. on TCG.
Liran Alon March 10, 2020, 12:29 p.m. UTC | #4
On 10/03/2020 14:27, Michael S. Tsirkin wrote:
> On Tue, Mar 10, 2020 at 12:53:28PM +0200, Liran Alon wrote:
>> On 10/03/2020 11:29, Michael S. Tsirkin wrote:
>>> On Tue, Mar 10, 2020 at 01:54:09AM +0200, Liran Alon wrote:
>>>> No functional change.
>>>> This information will be used by following patches.
>>>>
>>>> Reviewed-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
>>>> Signed-off-by: Liran Alon <liran.alon@oracle.com>
>>>> ---
>>>>    linux-headers/asm-x86/kvm.h | 4 ++++
>>>>    target/i386/cpu.h           | 1 +
>>>>    target/i386/kvm.c           | 6 +++---
>>>>    3 files changed, 8 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h
>>>> index 503d3f42da16..99eeaaf2f0b4 100644
>>>> --- a/linux-headers/asm-x86/kvm.h
>>>> +++ b/linux-headers/asm-x86/kvm.h
>>>> @@ -446,4 +446,8 @@ struct kvm_pmu_event_filter {
>>>>    #define KVM_PMU_EVENT_ALLOW 0
>>>>    #define KVM_PMU_EVENT_DENY 1
>>>> +/* From arch/x86/kvm/lapic.h */
>>>> +#define KVM_APIC_BUS_CYCLE_NS       1
>>>> +#define KVM_APIC_BUS_FREQUENCY      (1000000000ULL / KVM_APIC_BUS_CYCLE_NS)
>>>> +
>>>>    #endif /* _ASM_X86_KVM_H */
>>> This header is auto-generated from UAPI - you can't add
>>> your own stuff here.
>> Oh I didn't notice that. OK, I will move definitions to somewhere else.
>> Is it fine by you if I will just put them then in target/i386/kvm.c
>> directly?
>> Or do you prefer I will put them in target/i386/kvm_i386.h
>>
>> -Liran
>>
> That's Paolo's area. Myself, I don't really know what this is doing,
> nor how is this supposed to work e.g. on TCG.

The field will remain zero on TCG and vmport command which use it will fail.
OK, I will just move it to target/i386/kvm.c and see if Paolo objects.

-Liran
diff mbox series

Patch

diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h
index 503d3f42da16..99eeaaf2f0b4 100644
--- a/linux-headers/asm-x86/kvm.h
+++ b/linux-headers/asm-x86/kvm.h
@@ -446,4 +446,8 @@  struct kvm_pmu_event_filter {
 #define KVM_PMU_EVENT_ALLOW 0
 #define KVM_PMU_EVENT_DENY 1
 
+/* From arch/x86/kvm/lapic.h */
+#define KVM_APIC_BUS_CYCLE_NS       1
+#define KVM_APIC_BUS_FREQUENCY      (1000000000ULL / KVM_APIC_BUS_CYCLE_NS)
+
 #endif /* _ASM_X86_KVM_H */
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 576f309bbfc8..9c7cd7cde107 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1580,6 +1580,7 @@  typedef struct CPUX86State {
     bool tsc_valid;
     int64_t tsc_khz;
     int64_t user_tsc_khz; /* for sanity check only */
+    uint64_t apic_bus_freq;
 #if defined(CONFIG_KVM) || defined(CONFIG_HVF)
     void *xsave_buf;
 #endif
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index 69eb43d796e6..00917196dffb 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -1496,6 +1496,8 @@  int kvm_arch_init_vcpu(CPUState *cs)
         }
     }
 
+    env->apic_bus_freq = KVM_APIC_BUS_FREQUENCY;
+
     /* Paravirtualization CPUIDs */
     r = hyperv_handle_properties(cs, cpuid_data.entries);
     if (r < 0) {
@@ -1800,9 +1802,7 @@  int kvm_arch_init_vcpu(CPUState *cs)
         c = &cpuid_data.entries[cpuid_i++];
         c->function = KVM_CPUID_SIGNATURE | 0x10;
         c->eax = env->tsc_khz;
-        /* LAPIC resolution of 1ns (freq: 1GHz) is hardcoded in KVM's
-         * APIC_BUS_CYCLE_NS */
-        c->ebx = 1000000;
+        c->ebx = env->apic_bus_freq / 1000; /* Hz to KHz */
         c->ecx = c->edx = 0;
 
         c = cpuid_find_entry(&cpuid_data.cpuid, kvm_base, 0);