x86: hyperv_stimer: test direct mode
v2 cover x86: hyperv_stimer: test direct mode
Changes since v1:
- Minor cosmetic changes. v1 was sent in October, 2019 and I completely forgot about it. Time to dust it off!
Original description:
Testing 'direct' mode requires us to add 'hv_stimer_direct' CPU flag to QEMU, create a new entry in unittests.cfg to not lose the ability to test stimers in 'VMbus message' mode.
Vitaly Kuznetsov (4):
x86: hyperv_stimer: keep SINT number parameter in 'struct stimer'
x86: hyperv_stimer: define union hv_stimer_config
x86: hyperv_stimer: don't require hyperv-testdev
x86: hyperv_stimer: add direct mode tests
x86/hyperv.h | 29 ++++++-- x86/hyperv_stimer.c | 159 +++++++++++++++++++++++++++++++++++--------- x86/unittests.cfg | 8 ++- 3 files changed, 157 insertions(+), 39 deletions(-)
Signature · 1 line
2.29.2
PATCH v2 1/4 x86: hyperv_stimer: keep SINT number parameter in 'struct stimer'
As a preparation to enabling direct synthetic timers support stop passing SINT number to stimer_start.
--- x86/hyperv_stimer.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
x86/hyperv_stimer.c +19 -9
@@ -161,11 +161,10 @@ static void stimer_isr_auto_eoi(isr_regs_t *regs)static void stimer_start (struct stimer *timer,bool auto_enable,bool periodic, -u64 tick_100ns,int sint) +u64 tick_100ns) {u64 config, count; - timer->sint = sint;atomic_set (&timer->fire_count,0 ); config =0 ;
@@ -173,7 +172,7 @@ static void stimer_start(struct stimer *timer, config |=HV_STIMER_PERIODIC ; } - config |= ((u8)(sint &0xFF )) <<16 ; + config |= ((u8)(timer->sint &0xFF )) <<16 ; config |=HV_STIMER_ENABLE ;if (auto_enable) { config |=HV_STIMER_AUTOENABLE ;
@@ -218,18 +217,29 @@ static void synic_disable(void)static void stimer_test_prepare (void *ctx) { +int vcpu =smp_id (); +struct svcpu *svcpu = &g_synic_vcpu[vcpu]; +struct stimer *timer1, *timer2; +write_cr3 ((ulong )ctx);synic_enable (); +synic_sint_create (SINT1_NUM ,SINT1_VEC , false);synic_sint_create (SINT2_NUM ,SINT2_VEC , true); + + timer1 = &svcpu->timer[0 ]; + timer2 = &svcpu->timer[1 ]; + + timer1->sint =SINT1_NUM ; + timer2->sint =SINT2_NUM ; }static void stimer_test_periodic (int vcpu,struct stimer *timer1,struct stimer *timer2) {/* Check periodic timers */ -stimer_start (timer1, false, true,ONE_MS_IN_100NS ,SINT1_NUM ); -stimer_start (timer2, false, true,ONE_MS_IN_100NS ,SINT2_NUM ); +stimer_start (timer1, false, true,ONE_MS_IN_100NS ); +stimer_start (timer2, false, true,ONE_MS_IN_100NS );while ((atomic_read (&timer1->fire_count) <1000 ) || (atomic_read (&timer2->fire_count) <1000 )) {pause ();
@@ -242,7 +252,7 @@ static void stimer_test_periodic(int vcpu, struct stimer *timer1,static void stimer_test_one_shot (int vcpu,struct stimer *timer) {/* Check one-shot timer */ -stimer_start (timer, false, false,ONE_MS_IN_100NS ,SINT1_NUM ); +stimer_start (timer, false, false,ONE_MS_IN_100NS );while (atomic_read (&timer->fire_count) <1 ) {pause (); }
@@ -253,7 +263,7 @@ static void stimer_test_one_shot(int vcpu, struct stimer *timer)static void stimer_test_auto_enable_one_shot (int vcpu,struct stimer *timer) {/* Check auto-enable one-shot timer */ -stimer_start (timer, true, false,ONE_MS_IN_100NS ,SINT1_NUM ); +stimer_start (timer, true, false,ONE_MS_IN_100NS );while (atomic_read (&timer->fire_count) <1 ) {pause (); }
@@ -265,7 +275,7 @@ static void stimer_test_auto_enable_one_shot(int vcpu, struct stimer *timer)static void stimer_test_auto_enable_periodic (int vcpu,struct stimer *timer) {/* Check auto-enable periodic timer */ -stimer_start (timer, true, true,ONE_MS_IN_100NS ,SINT1_NUM ); +stimer_start (timer, true, true,ONE_MS_IN_100NS );while (atomic_read (&timer->fire_count) <1000 ) {pause (); }
@@ -282,7 +292,7 @@ static void stimer_test_one_shot_busy(int vcpu, struct stimer *timer) msg->header.message_type =HVMSG_TIMER_EXPIRED ;wmb (); -stimer_start (timer, false, false,ONE_MS_IN_100NS ,SINT1_NUM ); +stimer_start (timer, false, false,ONE_MS_IN_100NS ); do rmb();
Signature · 1 line
2.29.2
PATCH v2 2/4 x86: hyperv_stimer: define union hv_stimer_config
In reply to Vitaly KuznetsovAs a preparation to enabling direct synthetic timers properly define hv_stimer_config.
--- x86/hyperv.h | 22 +++++++++++++++++----- x86/hyperv_stimer.c | 21 ++++++++------------- 2 files changed, 25 insertions(+), 18 deletions(-)
x86/hyperv.h +17 -5
@@ -60,11 +60,23 @@#define HV_SYNIC_SINT_VECTOR_MASK (0xFF)#define HV_SYNIC_SINT_COUNT 16 -#define HV_STIMER_ENABLE (1ULL << 0) -#define HV_STIMER_PERIODIC (1ULL << 1) -#define HV_STIMER_LAZY (1ULL << 2) -#define HV_STIMER_AUTOENABLE (1ULL << 3) -#define HV_STIMER_SINT (config) (__u8)(((config) >> 16) & 0x0F) +/* +* Synthetic timer configuration. +*/ +union hv_stimer_config { +u64 as_uint64; +struct { +u64 enable:1 ; +u64 periodic:1 ; +u64 lazy:1 ; +u64 auto_enable:1 ; +u64 apic_vector:8 ; +u64 direct_mode:1 ; +u64 reserved_z0:3 ; +u64 sintx:4 ; +u64 reserved_z1:44 ; + }; +};#define HV_SYNIC_STIMER_COUNT (4)
x86/hyperv_stimer.c +8 -13
@@ -163,20 +163,15 @@ static void stimer_start(struct stimer *timer, bool auto_enable, bool periodic, u64 tick_100ns) { - u64 config, count; + u64 count; +union hv_stimer_config config = {.as_uint64 =0 };atomic_set (&timer->fire_count,0 ); - config =0 ; -if (periodic) { - config |=HV_STIMER_PERIODIC ; - } - - config |= ((u8)(timer->sint &0xFF )) <<16 ; - config |=HV_STIMER_ENABLE ; -if (auto_enable) { - config |=HV_STIMER_AUTOENABLE ; - } + config.periodic = periodic; + config.enable =1 ; + config.auto_enable = auto_enable; + config.sintx = timer->sint;if (periodic) { count = tick_100ns;
@@ -186,9 +181,9 @@ static void stimer_start(struct stimer *timer,if (!auto_enable) {wrmsr (HV_X64_MSR_STIMER0_COUNT + timer->index*2 , count); -wrmsr (HV_X64_MSR_STIMER0_CONFIG + timer->index*2 , config); +wrmsr (HV_X64_MSR_STIMER0_CONFIG + timer->index*2 , config.as_uint64); }else { -wrmsr (HV_X64_MSR_STIMER0_CONFIG + timer->index*2 , config); +wrmsr (HV_X64_MSR_STIMER0_CONFIG + timer->index*2 , config.as_uint64);wrmsr (HV_X64_MSR_STIMER0_COUNT + timer->index*2 , count); } }
Signature · 1 line
2.29.2
PATCH v2 3/4 x86: hyperv_stimer: don't require hyperv-testdev
In reply to Vitaly Kuznetsov'hyperv-testdev' is completely superfluous for stimer tests.
--- x86/unittests.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
x86/unittests.cfg +1 -1
@@ -361,7 +361,7 @@ groups = hyperv [hyperv_stimer] file = hyperv_stimer.flat smp = 2 -extra_params = -cpu kvm64,hv_vpindex,hv_time,hv_synic,hv_stimer -device hyperv-testdev +extra_params = -cpu kvm64,hv_vpindex,hv_time,hv_synic,hv_stimer groups = hyperv [hyperv_clock]
Signature · 1 line
2.29.2
PATCH v2 4/4 x86: hyperv_stimer: add direct mode tests
In reply to Vitaly KuznetsovAll tests but stimer_test_one_shot_busy() are applicable, make them run in both 'message' and 'direct' modes.
--- x86/hyperv.h | 7 +++ x86/hyperv_stimer.c | 116 ++++++++++++++++++++++++++++++++++++++------ x86/unittests.cfg | 6 +++ 3 files changed, 115 insertions(+), 14 deletions(-)
x86/hyperv.h +7 -0
@@ -10,6 +10,8 @@#define HV_X64_MSR_SYNIC_AVAILABLE (1 << 2)#define HV_X64_MSR_SYNTIMER_AVAILABLE (1 << 3) +#define HV_STIMER_DIRECT_MODE_AVAILABLE (1 << 19) +#define HV_X64_MSR_GUEST_OS_ID 0x40000000#define HV_X64_MSR_HYPERCALL 0x40000001
@@ -205,6 +207,11 @@ static inline bool stimer_supported(void)return cpuid (HYPERV_CPUID_FEATURES ).a &HV_X64_MSR_SYNIC_AVAILABLE ; } +static inline bool stimer_direct_supported (void ) +{ +return cpuid (HYPERV_CPUID_FEATURES ).d &HV_STIMER_DIRECT_MODE_AVAILABLE ; +} +static inline bool hv_time_ref_counter_supported (void ) {return cpuid (HYPERV_CPUID_FEATURES ).a &HV_X64_MSR_TIME_REF_COUNT_AVAILABLE ;
x86/hyperv_stimer.c +102 -14
183 lines not on this page · raw message
x86/unittests.cfg +6 -0
@@ -364,6 +364,12 @@ smp = 2 extra_params = -cpu kvm64,hv_vpindex,hv_time,hv_synic,hv_stimer groups = hyperv +[hyperv_stimer_direct] +file = hyperv_stimer.flat +smp = 2 +extra_params = -cpu kvm64,hv_vpindex,hv_time,hv_synic,hv_stimer,hv_stimer_direct +groups = hyperv + [hyperv_clock] file = hyperv_clock.flat smp = 2
Signature · 1 line
2.29.2
Quoted 3 lines · Vitaly Kuznetsov
Changes since v1:
- Minor cosmetic changes. v1 was sent in October, 2019 and I completely forgot about it. Time to dust it off!
Ping) Patches should still apply to 'master' with no issues.
Quoted 17 lines
Original description:
Testing 'direct' mode requires us to add '
hv_stimer_direct' CPU flag to QEMU, create a new entry in unittests.cfg to not lose the ability to test stimers in 'VMbus message' mode.Vitaly Kuznetsov (4):
x86:hyperv_stimer: keep SINT number parameter in 'struct stimer'
x86:hyperv_stimer: define unionhv_stimer_config
x86:hyperv_stimer: don't require hyperv-testdev
x86:hyperv_stimer: add direct mode testsx86/hyperv.h | 29 ++++++-- x86/hyperv_stimer.c | 159 +++++++++++++++++++++++++++++++++++--------- x86/unittests.cfg | 8 ++- 3 files changed, 157 insertions(+), 39 deletions(-)
Signature · 1 line
Vitaly