From patchwork Fri Mar 29 15:09:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 10877253 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 859AC1708 for ; Fri, 29 Mar 2019 15:11:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CAFC28B47 for ; Fri, 29 Mar 2019 15:11:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AB3E29864; Fri, 29 Mar 2019 15:11:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EA65C28A56 for ; Fri, 29 Mar 2019 15:11:31 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h9t8w-0004CX-Aj; Fri, 29 Mar 2019 15:10:06 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h9t8j-0003jb-Bm for xen-devel@lists.xenproject.org; Fri, 29 Mar 2019 15:09:53 +0000 X-Inumbo-ID: b2ca71b6-5234-11e9-bc90-bc764e045a96 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id b2ca71b6-5234-11e9-bc90-bc764e045a96; Fri, 29 Mar 2019 15:09:50 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id EF671B033; Fri, 29 Mar 2019 15:09:49 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 29 Mar 2019 16:09:21 +0100 Message-Id: <20190329150934.17694-37-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190329150934.17694-1-jgross@suse.com> References: <20190329150934.17694-1-jgross@suse.com> Subject: [Xen-devel] [PATCH RFC 36/49] 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_Pau_Monn=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. In case we are modifying the timer of the currently running vcpu we can just do that. In case it is for a foreign vcpu we should pause it for that purpose like we do for all other vcpu state modifications. Rename the function to vcpu_set_periodic_timer() as this now reflects the functionality. Signed-off-by: Juergen Gross --- xen/arch/x86/pv/shim.c | 4 +--- xen/common/domain.c | 6 ++---- xen/common/schedule.c | 23 +++++++++++++---------- xen/include/xen/sched.h | 2 +- 4 files changed, 17 insertions(+), 18 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); /* 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; diff --git a/xen/common/domain.c b/xen/common/domain.c index 2773a21129..b448d20d40 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1442,15 +1442,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: diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 0a94505b89..7c7735bf33 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -833,21 +833,24 @@ static void vcpu_migrate_finish(struct vcpu *v) } /* - * Force a VCPU through a deschedule/reschedule path. - * For example, using this when setting the periodic timer period means that - * most periodic-timer state need only be touched from within the scheduler - * which can thus be done without need for synchronisation. + * Set the periodic timer of a vcpu. */ -void vcpu_force_reschedule(struct vcpu *v) +void vcpu_set_periodic_timer(struct vcpu *v, s_time_t value) { - spinlock_t *lock = item_schedule_lock_irq(v->sched_item); + s_time_t now = NOW(); - if ( vcpu_running(v) ) - vcpu_migrate_start(v); + if ( v != current ) + vcpu_pause(v); + else + stop_timer(&v->periodic_timer); - item_schedule_unlock_irq(lock, v->sched_item); + v->periodic_period = value; + v->periodic_last_event = now; - vcpu_migrate_finish(v); + if ( v != current ) + vcpu_unpause(v); + else if ( value != 0 ) + set_timer(&v->periodic_timer, now + value); } void restore_vcpu_affinity(struct domain *d) diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index f7eb138d86..873a903977 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -857,7 +857,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,