From patchwork Wed Feb 24 17:42:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 8410391 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 76E3FC0553 for ; Wed, 24 Feb 2016 17:45:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 711682025B for ; Wed, 24 Feb 2016 17:45:43 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6690C201EC for ; Wed, 24 Feb 2016 17:45:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aYdSc-00055r-Av; Wed, 24 Feb 2016 17:42:50 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aYdSa-00055l-T7 for xen-devel@lists.xenproject.org; Wed, 24 Feb 2016 17:42:49 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id 6A/6F-03800-89BEDC65; Wed, 24 Feb 2016 17:42:48 +0000 X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-15.tower-206.messagelabs.com!1456335767!16360950!1 X-Originating-IP: [74.125.82.52] X-SpamReason: No, hits=0.7 required=7.0 tests=BODY_RANDOM_LONG, RCVD_ILLEGAL_IP X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 18686 invoked from network); 24 Feb 2016 17:42:47 -0000 Received: from mail-wm0-f52.google.com (HELO mail-wm0-f52.google.com) (74.125.82.52) by server-15.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 24 Feb 2016 17:42:47 -0000 Received: by mail-wm0-f52.google.com with SMTP id a4so40892199wme.1 for ; Wed, 24 Feb 2016 09:42:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:from:to:cc:date:message-id:user-agent:mime-version :content-type:content-transfer-encoding; bh=23yrTN3eap7tLgxvy8DKEk5nEM4ww2FZLbK2a3arNN8=; b=KXryVQX4dEhx268svGP8FceWT3kqZttApN0LiFCQ3o6JpEUNGYH7dGE/jMQkORzGtO tuQkiqGDZHvagKBUII89e42KHnKH6BPdywhUbAxPyqBAORwf7fjOtgDlEERiUd+XyImH OjI1MEH3Ju1K9byjFCDunyvyrOgP3zQNNYBa+6Rm51ad5+JLIo4p/x1BrDxZeyZKAfZq /moFtGC67VsO2VqVm5y6qflj/bGJFysPBrMuQvTx796X9TcfID5XSNT9uXtf4qJcjcr4 Ju2qWdWrmr4rVaV0a1pmFO0vksgYDY04hHdJZn0EqsztdKivnngh6Z5XCIiIN88VP5zl ke0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:from:to:cc:date:message-id :user-agent:mime-version:content-type:content-transfer-encoding; bh=23yrTN3eap7tLgxvy8DKEk5nEM4ww2FZLbK2a3arNN8=; b=MwII8dswL4M8k4FVngAHSGQ0fh/e8VJPU+QCWaRkYjQ5QXthyyj/KfkJyiK0EiS381 jzx4YIyOw4T07+1H8RxC5GiQlnH3/OWWjw9f9grFlDXL41CQDDwfHZyd58nCSZOPknTI iScc242B3vaWi8jtW5jr6lOD0o4KqLpj38lJYvuwtj+eMVnvax2FbO8IoX7L/Sw3ewjj bUZV9+MZWWSoJetKNoO/Kl8KAKO0hPgNeViajeKZD2Teo78A8GbG/Od3kZR8oEHR8YDm YBw+su9VkCrg7tKjZYjkdRZj6yo6eWkUZT1EwEmg1cHKUfLXgGMfZmtPayT/lu0GhWsW 72cw== X-Gm-Message-State: AG10YOSaRENwRGfjIps7D0eoWhK7N8w1e8Hj925TLjYkj+LZ8IFhNaMAHCluXLRC0+9Z7A== X-Received: by 10.28.53.4 with SMTP id c4mr4753989wma.34.1456335767335; Wed, 24 Feb 2016 09:42:47 -0800 (PST) Received: from Solace.station (net-2-35-170-8.cust.vodafonedsl.it. [2.35.170.8]) by smtp.gmail.com with ESMTPSA id 8sm32329738wmk.13.2016.02.24.09.42.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Feb 2016 09:42:46 -0800 (PST) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Wed, 24 Feb 2016 18:42:39 +0100 Message-ID: <20160224174239.13376.58865.stgit@Solace.station> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: George Dunlap , Jan Beulich Subject: [Xen-devel] [PATCH v4] xen: credit1: avoid boosting vCPUs being "just" migrated X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Moving a vCPU to a different pCPU means offlining it and then waking it up, on the new pCPU. Credit1 grants BOOST priority to vCPUs that wakes up, with the aim of improving I/O latency. The net effect of this all is that vCPUs get boosted when migrating, which shouldn't happen. For instance, this causes scheduling anomalies and, potentially, performance problems, as reported here: http://lists.xen.org/archives/html/xen-devel/2015-10/msg02851.html This patch fixes this by noting down (by means of a flag) the fact that the vCPU is about to undergo a migration. This way we can tell, later, during a wakeup, whether the vCPU is migrating or unblocking, and decide whether or not to apply the boosting. Note that it is important that atomic-safe bit operations are used when manipulating vCPUs' flags. Take the chance and add a comment about this. Signed-off-by: Dario Faggioli Reviewed-by: George Dunlap --- Cc: George Dunlap Cc: Jan Beulich --- Changes from v3: * use a local boolean variable to track if the vcpu is migrating, to make the code clearer and easier to read, as suggested during review. Changes from v2: * test_and_clear() is necessary when accessing svc->flags; * added a comment about such need at the top, where the flags are defined. Changes from v1: * rewritten, following suggestion got during review: there are no wakeup flags any longer, and all is done in sched_credit.c by setting a flag in csched_cpu_pick() and testing (and cleating) it in csched_vcpu_wake(). --- xen/common/sched_credit.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 0af5f69..305889a 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -63,9 +63,14 @@ /* * Flags + * + * Note that svc->flags (where these flags live) is protected by an + * inconsistent set of locks. Therefore atomic-safe bit operations must + * be used for accessing it. */ #define CSCHED_FLAG_VCPU_PARKED 0x0 /* VCPU over capped credits */ #define CSCHED_FLAG_VCPU_YIELD 0x1 /* VCPU yielding */ +#define CSCHED_FLAG_VCPU_MIGRATING 0x2 /* VCPU may have moved to a new pcpu */ /* @@ -786,6 +791,16 @@ _csched_cpu_pick(const struct scheduler *ops, struct vcpu *vc, bool_t commit) static int csched_cpu_pick(const struct scheduler *ops, struct vcpu *vc) { + struct csched_vcpu *svc = CSCHED_VCPU(vc); + + /* + * We have been called by vcpu_migrate() (in schedule.c), as part + * of the process of seeing if vc can be migrated to another pcpu. + * We make a note about this in svc->flags so that later, in + * csched_vcpu_wake() (still called from vcpu_migrate()) we won't + * get boosted, which we don't deserve as we are "only" migrating. + */ + set_bit(CSCHED_FLAG_VCPU_MIGRATING, &svc->flags); return _csched_cpu_pick(ops, vc, 1); } @@ -985,6 +1000,7 @@ static void csched_vcpu_wake(const struct scheduler *ops, struct vcpu *vc) { struct csched_vcpu * const svc = CSCHED_VCPU(vc); + bool_t migrating; BUG_ON( is_idle_vcpu(vc) ); @@ -1020,11 +1036,15 @@ csched_vcpu_wake(const struct scheduler *ops, struct vcpu *vc) * more CPU resource intensive VCPUs without impacting overall * system fairness. * - * The one exception is for VCPUs of capped domains unpausing - * after earning credits they had overspent. We don't boost - * those. + * There are two cases, when we don't want to boost: + * - VCPUs that are waking up after a migration, rather than + * after having block; + * - VCPUs of capped domains unpausing after earning credits + * they had overspent. */ - if ( svc->pri == CSCHED_PRI_TS_UNDER && + migrating = test_and_clear_bit(CSCHED_FLAG_VCPU_MIGRATING, &svc->flags); + + if ( !migrating && svc->pri == CSCHED_PRI_TS_UNDER && !test_bit(CSCHED_FLAG_VCPU_PARKED, &svc->flags) ) { TRACE_2D(TRC_CSCHED_BOOST_START, vc->domain->domain_id, vc->vcpu_id);