From: Dario Faggioli Subject: [PATCH 2/4] xen: sched: factor code that moves a vcpu to a new pcpu in a function Date: Fri, 03 Jul 2015 17:49:23 +0200 Message-ID: <20150703154923.23194.96957.stgit@Solace.station> References: <20150703152743.23194.15530.stgit@Solace.station> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZB3DT-0002rx-EL for xen-devel@lists.xenproject.org; Fri, 03 Jul 2015 15:49:27 +0000 Received: by wgjx7 with SMTP id x7so91408688wgj.2 for ; Fri, 03 Jul 2015 08:49:25 -0700 (PDT) In-Reply-To: <20150703152743.23194.15530.stgit@Solace.station> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: George Dunlap List-Id: xen-devel@lists.xenproject.org No functional change intended. Signed-off-by: Dario Faggioli --- Cc: George Dunlap --- xen/common/schedule.c | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 26e8430..e83c666 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -451,6 +451,34 @@ void vcpu_unblock(struct vcpu *v) vcpu_wake(v); } +/* + * Do the actual movemet of a vcpu from old to new CPU. Locks for *both* + * CPUs needs to have been taken already when calling this! + */ +static void vcpu_move(struct vcpu *v, unsigned int old_cpu, + unsigned int new_cpu) +{ + /* + * Transfer urgency status to new CPU before switching CPUs, as + * once the switch occurs, v->is_urgent is no longer protected by + * the per-CPU scheduler lock we are holding. + */ + if ( unlikely(v->is_urgent) && (old_cpu != new_cpu) ) + { + atomic_inc(&per_cpu(schedule_data, new_cpu).urgent_count); + atomic_dec(&per_cpu(schedule_data, old_cpu).urgent_count); + } + + /* + * Actual CPU switch to new CPU. This is safe because the lock + * pointer cant' change while the current lock is held. + */ + if ( VCPU2OP(v)->migrate ) + SCHED_OP(VCPU2OP(v), migrate, v, new_cpu); + else + v->processor = new_cpu; +} + static void vcpu_migrate(struct vcpu *v) { unsigned long flags; @@ -515,25 +543,7 @@ static void vcpu_migrate(struct vcpu *v) return; } - /* - * Transfer urgency status to new CPU before switching CPUs, as once - * the switch occurs, v->is_urgent is no longer protected by the per-CPU - * scheduler lock we are holding. - */ - if ( unlikely(v->is_urgent) && (old_cpu != new_cpu) ) - { - atomic_inc(&per_cpu(schedule_data, new_cpu).urgent_count); - atomic_dec(&per_cpu(schedule_data, old_cpu).urgent_count); - } - - /* - * Switch to new CPU, then unlock new and old CPU. This is safe because - * the lock pointer cant' change while the current lock is held. - */ - if ( VCPU2OP(v)->migrate ) - SCHED_OP(VCPU2OP(v), migrate, v, new_cpu); - else - v->processor = new_cpu; + vcpu_move(v, old_cpu, new_cpu); sched_spin_unlock_double(old_lock, new_lock, flags);