From nobody Mon Apr 29 04:18:49 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1568376975; cv=none; d=zoho.com; s=zohoarc; b=flrJhJE7jUdyon1KlbCyAvMWw/xlc2AB59bgBGPVSKqd+00+VpdlEKksy1h4HMkNgEVvKe9pr6nnFMh/UUwkFFC4ZAGLCLHtHasgdmaR1XKCXaOTZ5ReYnJZdioqj8nd4T9k01SzPbj+LkeT2CFKgydmsR9TJJovkRD0sA+A0Vs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568376975; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=JOC7siRp0Nr+7H2eEW549qUchxkphk9cIHYw9xJgfMY=; b=kltkf9Sqz2KDCf++gcqzGyuN44zgX09shP4PDvioGX+AUXjKDoGBYKNd5n6ZtYUDkjOq2piR4Aut3/IJ8/ddga5G9R+/2kstU9debsanICSO1gaXuMOTCUXg6fF0c8HDUV7hH5Jller/XH0/AHVY8rj+QKDJ5T1t03Wk29yD6GE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1568376975054640.6361823598897; Fri, 13 Sep 2019 05:16:15 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8kTe-0008SE-5R; Fri, 13 Sep 2019 12:15:02 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i8kTc-0008S9-Js for xen-devel@lists.xenproject.org; Fri, 13 Sep 2019 12:15:00 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1a8e5ac0-d620-11e9-95aa-12813bfff9fa; Fri, 13 Sep 2019 12:14:59 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D7401AFF1; Fri, 13 Sep 2019 12:14:57 +0000 (UTC) X-Inumbo-ID: 1a8e5ac0-d620-11e9-95aa-12813bfff9fa X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 13 Sep 2019 14:14:00 +0200 Message-Id: <20190913121400.23263-1-jgross@suse.com> X-Mailer: git-send-email 2.16.4 Subject: [Xen-devel] [PATCH] xen/sched: rework and rename vcpu_force_reschedule() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Dario Faggioli , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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. Rename the function to vcpu_set_periodic_timer() as this now reflects the functionality. Signed-off-by: Juergen Gross --- - 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. --- xen/arch/x86/pv/shim.c | 4 +--- xen/common/domain.c | 6 ++---- xen/common/schedule.c | 52 +++++++++++++++++++++++++++------------------= ---- xen/include/xen/sched.h | 3 ++- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/xen/arch/x86/pv/shim.c b/xen/arch/x86/pv/shim.c index 324ca27f93..5edbcd9ac5 100644 --- a/xen/arch/x86/pv/shim.c +++ b/xen/arch/x86/pv/shim.c @@ -410,7 +410,7 @@ int pv_shim_shutdown(uint8_t reason) unmap_vcpu_info(v); =20 /* Reset the periodic timer to the default value. */ - v->periodic_period =3D MILLISECS(10); + vcpu_set_periodic_timer(v, MILLISECS(10)); /* Stop the singleshot timer. */ stop_timer(&v->singleshot_timer); =20 @@ -419,8 +419,6 @@ int pv_shim_shutdown(uint8_t reason) =20 if ( v !=3D current ) vcpu_unpause_by_systemcontroller(v); - else - vcpu_force_reschedule(v); } =20 return 0; diff --git a/xen/common/domain.c b/xen/common/domain.c index 9a48b2504b..0cff749bbe 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1494,15 +1494,13 @@ long do_vcpu_op(int cmd, unsigned int vcpuid, XEN_G= UEST_HANDLE_PARAM(void) arg) if ( set.period_ns > STIME_DELTA_MAX ) return -EINVAL; =20 - v->periodic_period =3D set.period_ns; - vcpu_force_reschedule(v); + vcpu_set_periodic_timer(v, set.period_ns); =20 break; } =20 case VCPUOP_stop_periodic_timer: - v->periodic_period =3D 0; - vcpu_force_reschedule(v); + vcpu_set_periodic_timer(v, 0); break; =20 case VCPUOP_set_singleshot_timer: diff --git a/xen/common/schedule.c b/xen/common/schedule.c index fdeec10c3b..6447662b85 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -312,6 +312,7 @@ int sched_init_vcpu(struct vcpu *v, unsigned int proces= sor) v->processor =3D processor; =20 /* Initialise the per-vcpu timers. */ + spin_lock_init(&v->periodic_timer_lock); init_timer(&v->periodic_timer, vcpu_periodic_timer_fn, v, v->processor); init_timer(&v->singleshot_timer, vcpu_singleshot_timer_fn, @@ -724,24 +725,6 @@ static void vcpu_migrate_finish(struct vcpu *v) vcpu_wake(v); } =20 -/* - * Force a VCPU through a deschedule/reschedule path. - * For example, using this when setting the periodic timer period means th= at - * most periodic-timer state need only be touched from within the scheduler - * which can thus be done without need for synchronisation. - */ -void vcpu_force_reschedule(struct vcpu *v) -{ - spinlock_t *lock =3D vcpu_schedule_lock_irq(v); - - if ( v->is_running ) - vcpu_migrate_start(v); - - vcpu_schedule_unlock_irq(lock, v); - - vcpu_migrate_finish(v); -} - void restore_vcpu_affinity(struct domain *d) { unsigned int cpu =3D smp_processor_id(); @@ -1458,14 +1441,11 @@ long sched_adjust_global(struct xen_sysctl_schedule= r_op *op) return rc; } =20 -static void vcpu_periodic_timer_work(struct vcpu *v) +static void vcpu_periodic_timer_work_locked(struct vcpu *v) { s_time_t now; s_time_t periodic_next_event; =20 - if ( v->periodic_period =3D=3D 0 ) - return; - now =3D NOW(); periodic_next_event =3D v->periodic_last_event + v->periodic_period; =20 @@ -1476,10 +1456,36 @@ static void vcpu_periodic_timer_work(struct vcpu *v) periodic_next_event =3D now + v->periodic_period; } =20 - migrate_timer(&v->periodic_timer, smp_processor_id()); + migrate_timer(&v->periodic_timer, v->processor); set_timer(&v->periodic_timer, periodic_next_event); } =20 +static void vcpu_periodic_timer_work(struct vcpu *v) +{ + if ( v->periodic_period =3D=3D 0 ) + return; + + spin_lock(&v->periodic_timer_lock); + vcpu_periodic_timer_work_locked(v); + spin_unlock(&v->periodic_timer_lock); +} + +/* + * Set the periodic timer of a vcpu. + */ +void vcpu_set_periodic_timer(struct vcpu *v, s_time_t value) +{ + spin_lock(&v->periodic_timer_lock); + + stop_timer(&v->periodic_timer); + + v->periodic_period =3D value; + if ( value ) + vcpu_periodic_timer_work_locked(v); + + spin_unlock(&v->periodic_timer_lock); +} + /* * The main function * - deschedule the current domain (scheduler independent). diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index e3601c1935..40097ff334 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -153,6 +153,7 @@ struct vcpu =20 struct vcpu *next_in_list; =20 + 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, --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel