xen/sched: rework and rename vcpu_force_reschedule()
PATCH v3 1/1 xen/sched: rework and rename vcpu_force_reschedule()
vcpu_force_reschedule() is only used for modifying the periodic timer of a vcpu. Forcing a vcpu to give up the physical cpu for that purpose is kind of brutal.
So instead of doing the reschedule dance just operate on the timer directly. By protecting periodic timer modifications against concurrent timer activation via a per-vcpu lock it is even no longer required to bother the target vcpu at all for updating its timer.
Even with the additional lock there is not more serialization involved compared to the current solution, as today's de-scheduling the vcpu is requiring to take the schedule lock, which has a much higher contention probability than the new lock.
Rename the function to vcpu_set_periodic_timer() as this now reflects the functionality.
---
- Carved out from my core scheduling series
- Reworked to avoid deadlock when 2 vcpus are trying to modify each others periodic timers, leading to address all comments by Jan Beulich.
V2:
- test periodic_period again in vcpu_periodic_timer_work() when lock obtained (Jan Beulich)
V3:
- extended commit message
--- xen/arch/x86/pv/shim.c | 4 +--- xen/common/domain.c | 6 ++---- xen/common/schedule.c | 53 ++++++++++++++++++++++++++++--------------------- xen/include/xen/sched.h | 3 ++- 4 files changed, 35 insertions(+), 31 deletions(-)
xen/arch/x86/pv/shim.c +1 -3
@@ -410,7 +410,7 @@ int pv_shim_shutdown(uint8_t reason)unmap_vcpu_info (v);/* Reset the periodic timer to the default value. */ - v->periodic_period =MILLISECS (10 ); +vcpu_set_periodic_timer (v,MILLISECS (10 ));/* Stop the singleshot timer. */ stop_timer (&v->singleshot_timer);
@@ -419,8 +419,6 @@ int pv_shim_shutdown(uint8_t reason)if ( v != current )vcpu_unpause_by_systemcontroller (v); -else -vcpu_force_reschedule (v); }return 0 ;
xen/common/domain.c +2 -4
@@ -1508,15 +1508,13 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)if ( set.period_ns >STIME_DELTA_MAX )return -EINVAL ; - v->periodic_period = set.period_ns; -vcpu_force_reschedule (v); +vcpu_set_periodic_timer (v, set.period_ns);break ; }case VCPUOP_stop_periodic_timer: - v->periodic_period =0 ; -vcpu_force_reschedule (v); +vcpu_set_periodic_timer (v,0 );break ;case VCPUOP_set_singleshot_timer:
xen/common/schedule.c +30 -23
84 lines not on this page · raw message
xen/include/xen/sched.h +2 -1
@@ -153,6 +153,7 @@ struct vcpustruct vcpu *next_in_list; +spinlock_t periodic_timer_lock;s_time_t periodic_period;s_time_t periodic_last_event;struct timer periodic_timer;
@@ -864,7 +865,7 @@ struct scheduler *scheduler_get_default(void);struct scheduler *scheduler_alloc (unsigned int sched_id,int *perr);void scheduler_free (struct scheduler *sched);int schedule_cpu_switch (unsigned int cpu,struct cpupool *c); -void vcpu_force_reschedule (struct vcpu *v); +void vcpu_set_periodic_timer (struct vcpu *v,s_time_t value);int cpu_disable_scheduler (unsigned int cpu);/* We need it in dom0_setup_vcpu */ void sched_set_affinity(struct vcpu *v, const cpumask_t *hard,
Signature · 7 lines
2.16.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel