From patchwork Fri Jun 17 23:12:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9185137 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 D269E601C0 for ; Fri, 17 Jun 2016 23:13:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEF76200E7 for ; Fri, 17 Jun 2016 23:13:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B112C27F07; Fri, 17 Jun 2016 23:13:54 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,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 404D5200E7 for ; Fri, 17 Jun 2016 23:13:54 +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 1bE2vl-0003Ez-Bm; Fri, 17 Jun 2016 23:12:05 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bE2vk-0003ER-EC for xen-devel@lists.xenproject.org; Fri, 17 Jun 2016 23:12:04 +0000 Received: from [85.158.137.68] by server-3.bemta-3.messagelabs.com id B7/85-31810-3C384675; Fri, 17 Jun 2016 23:12:03 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgleJIrShJLcpLzFFi42Lxqg1y1j3cnBJ u8LGd2+L7lslMDowehz9cYQlgjGLNzEvKr0hgzVh8YQN7wQzeikuvXzA2MM7n6mLk4hASmM4o seTuQzYQh0VgDatE56p7rCCOhMAlVolHm/oZuxg5gZwYid33LjNB2JUSN5ZdZAWxhQRUJG5uX 8UEMWoxk8TCdy9ZQBLCAnoSR47+YIew/SXart8FG8QmYCDxZsdesGYRASWJe6smgzUzCzQwSk x4vAtsA4uAqsTnVffBGngFvCSOHb4FFucU8JVYfWUXG8RmH4mL5x6B2aICchIrL7ewQtQLSpy c+QToCA6goZoS63fpg4SZBeQltr+dwzyBUWQWkqpZCFWzkFQtYGRexahRnFpUllqka2iml1SU mZ5RkpuYmaNraGCsl5taXJyYnpqTmFSsl5yfu4kRGAMMQLCDcdV2z0OMkhxMSqK8VypTwoX4k vJTKjMSizPii0pzUosPMWpwcAhMODt3OpMUS15+XqqSBO+GJqA6waLU9NSKtMwcYJTClEpw8C iJ8O4ESfMWFyTmFmemQ6ROMepybJl6by2TENgMKXHezSBFAiBFGaV5cCNgCeMSo6yUMC8j0IF CPAWpRbmZJajyrxjFORiVhHmvgUzhycwrgdv0CugIJqAjNOclgxxRkoiQkmpgtBdY/6vjSfE9 pynC9bdrG29naTBVSW++N6fX1eyBlfzKOdffL3vqrdPCqLXqft2qhJXHljb3l9sWS825WcS76 rXgowNvlseHT/aPYrps5BTxom6pxLOdVj+2ahjt7vHpf/h1uvMcpUknf8nt8/iq9nTP+lse5y yPXNtVKv15rZp18pbY1b0hHEosxRmJhlrMRcWJAD+GNZ0TAwAA X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1466205123!45421505!1 X-Originating-IP: [74.125.82.67] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 22119 invoked from network); 17 Jun 2016 23:12:03 -0000 Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by server-13.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 17 Jun 2016 23:12:03 -0000 Received: by mail-wm0-f67.google.com with SMTP id 187so1090789wmz.1 for ; Fri, 17 Jun 2016 16:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=AvwdRKoL0FIeEEiPWhRO612cXuPlOsMRGRMGQJXGDEQ=; b=PUmD28Cl7YKiCY8H3ELj9pj8Ipi0xHvewOPJ3Yhir6e4MOb0w4hyqOLmrB9wjSCpck esTBWrRiG9WD2mX0q5smEB13hGWQzr81FcLEgNHl9Cmz2dGelUHL7fnteY9+8D7/4R8z h8H2DLL9cd0sjk4uIJO0jd1JKqrV1B1XVlvKElo5nFYnOYElmYI6AwBu+3Ggvz/P30yE llKvvmkUWWet18TUAMZRquqwnLZVO85cSovSbVvi3ConWPtLnLzfFTJrYJ7QVzjAy0H0 1z0SBct9N/H+W3/L98rwICuqntXfOC0HK7VGgcW3SmDPQLGONvBhKYuySbz03l0GJTnM ZhoA== 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 :in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=AvwdRKoL0FIeEEiPWhRO612cXuPlOsMRGRMGQJXGDEQ=; b=jFX1kDpj+2gro9uClXzy5lw1ZsEU5ukLJMyT7+jMpiGlnoiclnrDVmJ7uP5XdgB8uh fKVag6LNFd7sYpO5cFVNht186BSLQtVShpfoEsMACihWy0ojnEl5weTuWvUmO5rKPCJC IjX1AmwV2cnTemMrwlmxICaE176k9tuqvKIauPKxkio2zA0jnf7VMzl4iSRDDIz0vaNl 9q4l+WgZYym2tUDz3Xu5fC8tWfkDBagvAGPch1oHkQMP2AjTToOXlMCjeSvjiFuqPzGE UdImmdhb5thraPT5IKJFh28F1qnKKtMhsTT3g5lN8x78mGlpT5YLLK0wc53vj0hjWXIA 9ieQ== X-Gm-Message-State: ALyK8tIi2gBOivCBcwFuVlLKB1udQXbaVPklrFsjAaMFyzQ2cM26Smhx1qWPNsV2dR5b0g== X-Received: by 10.194.114.72 with SMTP id je8mr4076960wjb.88.1466205122711; Fri, 17 Jun 2016 16:12:02 -0700 (PDT) Received: from Solace.fritz.box (net-93-65-149-191.cust.vodafonedsl.it. [93.65.149.191]) by smtp.gmail.com with ESMTPSA id vu10sm41341732wjb.27.2016.06.17.16.12.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jun 2016 16:12:01 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Sat, 18 Jun 2016 01:12:00 +0200 Message-ID: <146620512051.29766.574756341169521466.stgit@Solace.fritz.box> In-Reply-To: <146620492155.29766.10321123657058307698.stgit@Solace.fritz.box> References: <146620492155.29766.10321123657058307698.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: Anshul Makkar , George Dunlap , David Vrabel Subject: [Xen-devel] [PATCH 06/19] xen: credit2: read NOW() with the proper runq lock held 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 Yet another situation very similar to 779511f4bf5ae ("sched: avoid races on time values read from NOW()"). In fact, when more than one runqueue is involved, we need to make sure that the following does not happen: 1. take the lock of 1st runq 2. now = NOW() 3. take the lock of 2nd runq 4. use now as, if we have to wait at step 3, the value in now may be stale when we get to use it at step 4. While there, fix the style of a label. Signed-off-by: Dario Faggioli --- Cc: George Dunlap Cc: Anshul Makkar Cc: David Vrabel --- xen/common/sched_credit2.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 9e8e561..50f8dfd 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -1361,7 +1361,7 @@ static void balance_load(const struct scheduler *ops, int cpu, s_time_t now) __update_runq_load(ops, st.lrqd, 0, now); -retry: + retry: if ( !spin_trylock(&prv->lock) ) return; @@ -1377,7 +1377,8 @@ retry: || !spin_trylock(&st.orqd->lock) ) continue; - __update_runq_load(ops, st.orqd, 0, now); + /* Use a value of NOW() sampled after taking orqd's lock. */ + __update_runq_load(ops, st.orqd, 0, NOW()); delta = st.lrqd->b_avgload - st.orqd->b_avgload; if ( delta < 0 ) @@ -1435,6 +1436,8 @@ retry: if ( unlikely(st.orqd->id < 0) ) goto out_up; + now = NOW(); + /* Look for "swap" which gives the best load average * FIXME: O(n^2)! */