From patchwork Fri Apr 7 00:33:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9668669 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2D32060146 for ; Fri, 7 Apr 2017 00:36:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33AD9204C1 for ; Fri, 7 Apr 2017 00:36:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 274E8285EC; Fri, 7 Apr 2017 00:36:10 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C390B204C1 for ; Fri, 7 Apr 2017 00:36:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwHqg-0005h4-7v; Fri, 07 Apr 2017 00:33:58 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwHqe-0005gr-Kb for xen-devel@lists.xenproject.org; Fri, 07 Apr 2017 00:33:56 +0000 Received: from [85.158.137.68] by server-3.bemta-3.messagelabs.com id F9/08-14551-37ED6E85; Fri, 07 Apr 2017 00:33:55 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBIsWRWlGSWpSXmKPExsVyMbThoG7xvWc RBq9XSll83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBnr3xYWrDavuHjgH2sD4wTtLkYuDiGBGYwS K17cYgdxWATWsEp8W/iGFcSRELjEKnGi8zpLFyMnkBMj8X7RUTYIu1ri4OQbTCC2kICKxM3tq 5ggRv1ilLi4YwtYQlhAT+LI0R/sELaPxMQ/t8Ga2QQMJN7s2MsKYosIKEncWzUZrJ5ZIF9i1Y Q+sDiLgKrEjQWHweK8At4SHQ1HwWxOoDlvJ21nhljsLXFm/yewmaICchIrL7ewQtQLSpyc+QT oaA6gmZoS63fpQ4yXl9j+dg7zBEaRWUiqZiFUzUJStYCReRWjRnFqUVlqka6RiV5SUWZ6Rklu YmaOrqGBsV5uanFxYnpqTmJSsV5yfu4mRmD41zMwMO5gfHXc7xCjJAeTkiivgs+TCCG+pPyUy ozE4oz4otKc1OJDjDIcHEoSvNV3n0UICRalpqdWpGXmACMRJi3BwaMkwisOkuYtLkjMLc5Mh0 idYjTmeHH5/Xsmjicrf7xnEmLJy89LlRLnDQEpFQApzSjNgxsESxCXGGWlhHkZGRgYhHgKUot yM0tQ5V8xinMwKgnzzgWZwpOZVwK37xXQKUxAp/jcegpySkkiQkqqgTFK6MkXFkOW1ZZtwsfe /Pty0Sab5Vrwud8Ciue5lhhPbdmTPu1uSeDyHdwSx21Fp9QYv7xTpF1+tln4AS+nt/nCXUkc8 7SDBeWD5huwliVZSeYtOH6Occrf5YXTPRov/jrbUrrlzt3QgugU+RC+7zofG28vPrbwmVnU1g MzeR5pNWnHqS68cFSJpTgj0VCLuag4EQCOZ4sfCwMAAA== X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-5.tower-31.messagelabs.com!1491525235!91420903!1 X-Originating-IP: [209.85.128.193] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 27148 invoked from network); 7 Apr 2017 00:33:55 -0000 Received: from mail-wr0-f193.google.com (HELO mail-wr0-f193.google.com) (209.85.128.193) by server-5.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 7 Apr 2017 00:33:55 -0000 Received: by mail-wr0-f193.google.com with SMTP id u18so7640915wrc.1 for ; Thu, 06 Apr 2017 17:33:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=OH1b/ShRR1H6YnB3/wwjeWPMuwRWr4t2lovsNE2yAQw=; b=eiHZfvHSj9ejQEJP+JKmeb/Ig9zenrq//N82oHHE2OCRDeErBk8UdZZ0FCICqGe9Ty A2D3wc/RuKXoiFjDvGOSXg8FFBwUq1H19I8HtE4G8Hm91v6WZv2x/VStsJMFVxz8nYW+ CB81DSNUePf63KH2FvmhkESMKNXUgdY1j68USRt8DsHmjbr77E0+i1CYq6PfiNewcDwV s3aQyvxyK2kYDtgIATUe8q+RSPmYYGgD3ok0cJQt5lOFG3m0p4Cpsh4C0OXNVMpVqKSM oAT1OI7X9mKWE1L6dd+X7IK+qN8JZgtWpbuMag1bzaqlpOTUBjtdTdIy/omVqlukEOvZ m8Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:from:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=OH1b/ShRR1H6YnB3/wwjeWPMuwRWr4t2lovsNE2yAQw=; b=pGeYXVEDq2EzWwWuOMdo8GJvgPdhNeaexzno99T9S2CXFl+898yThtSNze/ib8lyDt lj1bRfG55rNK6IFua4FhtQkUPtl8nAMzAMIUjSY3ISJYtVUAcwNZWrNB4tRH2BoVJUaS dEAJccYhJwha6iWgyJJjSC1XglHEdIsjvEf099jEOjUotdDTCcs43ose1YxXGx5NIdN2 gV8jwfj7kwbgiG4mdR95p90A/bGFojIPEurTvpnz/jcluWygcEnmXKiM3j2mG/99b0Gh YfimMw3gsxjx05SiKH5+1MSHRFApI4nTJ0g97/9yXGYxWMK/ayyZyNP5vYNKD2NZ5Cfl KbPQ== X-Gm-Message-State: AFeK/H3TeRYUz2vNp91g39ckNUjtmILfBCd8SWGHRRttvVCErqgTKGqAKiJz0CbpcOxOHA== X-Received: by 10.223.139.221 with SMTP id w29mr33326394wra.18.1491525235022; Thu, 06 Apr 2017 17:33:55 -0700 (PDT) Received: from Solace.fritz.box ([80.66.223.217]) by smtp.gmail.com with ESMTPSA id l14sm3963012wre.23.2017.04.06.17.33.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Apr 2017 17:33:54 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Fri, 07 Apr 2017 02:33:52 +0200 Message-ID: <149152523265.31941.6787732353764983034.stgit@Solace.fritz.box> In-Reply-To: <149152426922.31941.6054159629649244529.stgit@Solace.fritz.box> References: <149152426922.31941.6054159629649244529.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: Juergen Gross , George Dunlap , Jan Beulich Subject: [Xen-devel] [PATCH v2 1/5] xen: sched: improve robustness (and rename) DOM2OP() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Clarify and enforce (with ASSERTs) when the function is called on the idle domain, and explain in comments what it means and when it is ok to do so. While there, change the name of the function to a more self-explanatory one, and do the same to VCPU2OP. Signed-off-by: Dario Faggioli Acked-by: George Dunlap --- Cc: George Dunlap Cc: Juergen Gross Cc: Jan Beulich --- Changes from v1: - new patch; - renamed VCPU2OP, as suggested during v1's review of patch 1. Changes from v1 of the null scheduler series: - renamed the helpers to dom_scheduler() and vcpu_scheduler(). --- xen/common/schedule.c | 56 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index d344b7c..d67227f 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -77,8 +77,25 @@ static struct scheduler __read_mostly ops; (( (opsptr)->fn != NULL ) ? (opsptr)->fn(opsptr, ##__VA_ARGS__ ) \ : (typeof((opsptr)->fn(opsptr, ##__VA_ARGS__)))0 ) -#define DOM2OP(_d) (((_d)->cpupool == NULL) ? &ops : ((_d)->cpupool->sched)) -static inline struct scheduler *VCPU2OP(const struct vcpu *v) +static inline struct scheduler *dom_scheduler(const struct domain *d) +{ + if ( likely(d->cpupool != NULL) ) + return d->cpupool->sched; + + /* + * If d->cpupool is NULL, this is the idle domain. This is special + * because the idle domain does not really bolong to any cpupool, and, + * hence, does not really have a scheduler. + * + * This is (should be!) only called like this for allocating the idle + * vCPUs for the first time, during boot, in which case what we want + * is the default scheduler that has been, choosen at boot. + */ + ASSERT(is_idle_domain(d)); + return &ops; +} + +static inline struct scheduler *vcpu_scheduler(const struct vcpu *v) { struct domain *d = v->domain; @@ -260,7 +277,8 @@ int sched_init_vcpu(struct vcpu *v, unsigned int processor) init_timer(&v->poll_timer, poll_timer_fn, v, v->processor); - v->sched_priv = SCHED_OP(DOM2OP(d), alloc_vdata, v, d->sched_priv); + v->sched_priv = SCHED_OP(dom_scheduler(d), alloc_vdata, v, + d->sched_priv); if ( v->sched_priv == NULL ) return 1; @@ -272,7 +290,7 @@ int sched_init_vcpu(struct vcpu *v, unsigned int processor) } else { - SCHED_OP(DOM2OP(d), insert_vcpu, v); + SCHED_OP(dom_scheduler(d), insert_vcpu, v); } return 0; @@ -326,7 +344,7 @@ int sched_move_domain(struct domain *d, struct cpupool *c) domain_pause(d); - old_ops = DOM2OP(d); + old_ops = dom_scheduler(d); old_domdata = d->sched_priv; for_each_vcpu ( d, v ) @@ -389,8 +407,8 @@ void sched_destroy_vcpu(struct vcpu *v) kill_timer(&v->poll_timer); if ( test_and_clear_bool(v->is_urgent) ) atomic_dec(&per_cpu(schedule_data, v->processor).urgent_count); - SCHED_OP(VCPU2OP(v), remove_vcpu, v); - SCHED_OP(VCPU2OP(v), free_vdata, v->sched_priv); + SCHED_OP(vcpu_scheduler(v), remove_vcpu, v); + SCHED_OP(vcpu_scheduler(v), free_vdata, v->sched_priv); } int sched_init_domain(struct domain *d, int poolid) @@ -404,7 +422,7 @@ int sched_init_domain(struct domain *d, int poolid) SCHED_STAT_CRANK(dom_init); TRACE_1D(TRC_SCHED_DOM_ADD, d->domain_id); - return SCHED_OP(DOM2OP(d), init_domain, d); + return SCHED_OP(dom_scheduler(d), init_domain, d); } void sched_destroy_domain(struct domain *d) @@ -413,7 +431,7 @@ void sched_destroy_domain(struct domain *d) SCHED_STAT_CRANK(dom_destroy); TRACE_1D(TRC_SCHED_DOM_REM, d->domain_id); - SCHED_OP(DOM2OP(d), destroy_domain, d); + SCHED_OP(dom_scheduler(d), destroy_domain, d); cpupool_rm_domain(d); } @@ -432,7 +450,7 @@ void vcpu_sleep_nosync(struct vcpu *v) if ( v->runstate.state == RUNSTATE_runnable ) vcpu_runstate_change(v, RUNSTATE_offline, NOW()); - SCHED_OP(VCPU2OP(v), sleep, v); + SCHED_OP(vcpu_scheduler(v), sleep, v); } vcpu_schedule_unlock_irqrestore(lock, flags, v); @@ -461,7 +479,7 @@ void vcpu_wake(struct vcpu *v) { if ( v->runstate.state >= RUNSTATE_blocked ) vcpu_runstate_change(v, RUNSTATE_runnable, NOW()); - SCHED_OP(VCPU2OP(v), wake, v); + SCHED_OP(vcpu_scheduler(v), wake, v); } else if ( !(v->pause_flags & VPF_blocked) ) { @@ -516,8 +534,8 @@ static void vcpu_move_locked(struct vcpu *v, unsigned int new_cpu) * 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); + if ( vcpu_scheduler(v)->migrate ) + SCHED_OP(vcpu_scheduler(v), migrate, v, new_cpu); else v->processor = new_cpu; } @@ -583,7 +601,7 @@ static void vcpu_migrate(struct vcpu *v) break; /* Select a new CPU. */ - new_cpu = SCHED_OP(VCPU2OP(v), pick_cpu, v); + new_cpu = SCHED_OP(vcpu_scheduler(v), pick_cpu, v); if ( (new_lock == per_cpu(schedule_data, new_cpu).schedule_lock) && cpumask_test_cpu(new_cpu, v->domain->cpupool->cpu_valid) ) break; @@ -685,7 +703,7 @@ void restore_vcpu_affinity(struct domain *d) spin_unlock_irq(lock);; lock = vcpu_schedule_lock_irq(v); - v->processor = SCHED_OP(VCPU2OP(v), pick_cpu, v); + v->processor = SCHED_OP(vcpu_scheduler(v), pick_cpu, v); spin_unlock_irq(lock); } @@ -975,7 +993,7 @@ long vcpu_yield(void) struct vcpu * v=current; spinlock_t *lock = vcpu_schedule_lock_irq(v); - SCHED_OP(VCPU2OP(v), yield, v); + SCHED_OP(vcpu_scheduler(v), yield, v); vcpu_schedule_unlock_irq(lock, v); SCHED_STAT_CRANK(vcpu_yield); @@ -1288,7 +1306,7 @@ long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op) if ( ret ) return ret; - if ( op->sched_id != DOM2OP(d)->sched_id ) + if ( op->sched_id != dom_scheduler(d)->sched_id ) return -EINVAL; switch ( op->cmd ) @@ -1304,7 +1322,7 @@ long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op) /* NB: the pluggable scheduler code needs to take care * of locking by itself. */ - if ( (ret = SCHED_OP(DOM2OP(d), adjust, d, op)) == 0 ) + if ( (ret = SCHED_OP(dom_scheduler(d), adjust, d, op)) == 0 ) TRACE_1D(TRC_SCHED_ADJDOM, d->domain_id); return ret; @@ -1482,7 +1500,7 @@ void context_saved(struct vcpu *prev) /* Check for migration request /after/ clearing running flag. */ smp_mb(); - SCHED_OP(VCPU2OP(prev), context_saved, prev); + SCHED_OP(vcpu_scheduler(prev), context_saved, prev); if ( unlikely(prev->pause_flags & VPF_migrating) ) vcpu_migrate(prev);