From patchwork Wed Jul 27 03:09:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9249203 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 BEB60607D8 for ; Wed, 27 Jul 2016 03:12:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFF2C276AE for ; Wed, 27 Jul 2016 03:12:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A321327BE5; Wed, 27 Jul 2016 03:12:26 +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 965E4276AE for ; Wed, 27 Jul 2016 03:12:25 +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 1bSFET-0000QT-FK; Wed, 27 Jul 2016 03:10: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 1bSFER-0000QK-SC for xen-devel@lists.xenproject.org; Wed, 27 Jul 2016 03:10:04 +0000 Received: from [85.158.137.68] by server-1.bemta-3.messagelabs.com id 15/95-17152-10628975; Wed, 27 Jul 2016 03:09:53 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrOIsWRWlGSWpSXmKPExsXiVRvkrMugNiP cYFGrpMX3LZOZHBg9Dn+4whLAGMWamZeUX5HAmvHw/DvmggNSFQ8e97E0MD4R7mLk4hASmM4o 8f/BKmYQh0VgKqvEobkH2EAcCYGNrBJfm3azdDFyAjkxEiuPdTJ2MXIA2dUSHffEQcJCAioSN 7evYoKYtIhJYnr7NTaQhLCAnsSRoz/YIexIiXdXpjGB2GwCBhJvduxlBbFFBJQk7q2aDNbMLN DMKLH85lxmkASLgKrE148zwGxeAW+Jv+d3gNmiAnISKy+3sELEBSVOznzCAnIQs4CmxPpd+iB hZgF5ie1v5zBPYBSahaRqFkLVLCRVCxiZVzFqFKcWlaUW6Rpa6iUVZaZnlOQmZuboGhoY6+Wm FhcnpqfmJCYV6yXn525iBAZ0PQMD4w7G38f9DjFKcjApifKqLZ4eLsSXlJ9SmZFYnBFfVJqTW nyIUYODQ2DC2bnTmaRY8vLzUpUkeG+ozAgXEixKTU+tSMvMAcYcTKkEB4+SCC8XSJq3uCAxtz gzHSJ1ilGXY8vUe2uZhMBmSInzngIpEgApyijNgxsBi/9LjLJSwryMDAwMQjwFqUW5mSWo8q8 YxTkYlYR5I1SBpvBk5pXAbXoFdAQT0BELeCaDHFGSiJCSamBcy/H5yApJZ37/RIneTSYa1+uv C3M1ilVkzzZa2in5UX226oKC19IiLI495yfob+fT97kootDiNmmfmN+yhjJ7pdfPvob3vjV21 fdgX3THq6H1/FK1VR/SNjLNUqk6pKC6a5mjS5LElhcfVqQHtXiE7qz8vEk2dVLEVuPgeTPTq+ ZXpGi5fFdiKc5INNRiLipOBAA+GHXj+gIAAA== X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1469588992!52621890!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.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 18964 invoked from network); 27 Jul 2016 03:09:52 -0000 Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by server-8.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 27 Jul 2016 03:09:52 -0000 Received: by mail-wm0-f67.google.com with SMTP id x83so4403362wma.3 for ; Tue, 26 Jul 2016 20:09:52 -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:user-agent:mime-version :content-transfer-encoding; bh=4acwCq0eFGNghEOUAlDG/bxAvmBbn9uUJvo+JjScFYI=; b=U9vc5KFX3gCuYPoEXyH82kDlaH7+qjg3rQJ0ZzQXmS2CxVcY4niz1WkDDlr7BVPDGO 4lgJoTMElv7fI5gtr9REY8Ar+U3aCdV0WaeQDylnBgtAs15pTXeg0a7+hhho31MxgQSd z9SMW70QOLTacsEjozvH60rasw51vstzOlbDaS7rHUkqq8YaeOmrMV+L9Jn3lvMMM8YI 1Uqa6bZIQ5DHGAO4PsmDXwIvpAO0Yk/AW/nJCkjz4GGZ9mW68gOwS7Ysa8GQqmzdxlUh w0rYLrT5SWhEHAQY/rtGpG4wL9FkZBeVXzkf4hMcD+D6T4yPJ7lRajHBzmHtuUvvkic0 hw5w== 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-transfer-encoding; bh=4acwCq0eFGNghEOUAlDG/bxAvmBbn9uUJvo+JjScFYI=; b=Zrvt2hVoZqLF7jusslOuZuRiEqYYavxZJV8bBeXEIVLgycb9mHi1mXQ0OkE3lIT8t4 WeUkjZA8EhIZSRJEqHn91+eujIpUvPgQ6pPNeM7BNG/EFt/Ser0Kn2ZT1Flo3GCzz+SM In5U6JzzMHD0eMURK+jifKwWh4XS93beE45FjGJesOT++V3JkxuXa+YzTiOaziAeqrIO dOxPxHlrbBphhBItKXxrYeF0ccF4JuBUH3TjQdWOPupsZ6I7GXlwRmm4U2d4pijkP6Xf g+dHzKi4kw3RNm2N9yj+ESlUxPlxulf6J4zNXmroMbaZU57U0FvQPtKgcpaUIL/V7jPW gwaA== X-Gm-Message-State: AEkooutHEG75bIc+LxyQShmudyi5w70MkZdLfaqzG8JszSyX0Ul91imj+HfLFyGkEAj6DQ== X-Received: by 10.194.127.37 with SMTP id nd5mr24589884wjb.156.1469588991746; Tue, 26 Jul 2016 20:09:51 -0700 (PDT) Received: from Solace.fritz.box (net-188-217-84-158.cust.vodafonedsl.it. [188.217.84.158]) by smtp.gmail.com with ESMTPSA id c8sm3912435wjm.19.2016.07.26.20.09.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jul 2016 20:09:50 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Wed, 27 Jul 2016 05:09:49 +0200 Message-ID: <146958898908.1696.15298736648669297817.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: Andrew Cooper , Anshul Makkar , George Dunlap Subject: [Xen-devel] [PATCH v3] xen: credit2: issues in csched2_cpu_pick(), when tracing is enabled. 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 In fact, when not finding a suitable runqueue where to place a vCPU, and hence using a fallback, we either: - don't issue any trace record (while we should, at least, output the chosen pcpu), - risk underruning when accessing the runqueues array, while preparing the trace record. Fix both issues and, while there, also a couple of style problems found nearby. Spotted by Coverity. Signed-off-by: Dario Faggioli Reported-by: Andrew Cooper Reviewed-by: George Dunlap --- Cc: George Dunlap Cc: Anshul Makkar --- Changes from v2: * use local variables to prevent unlocked access to prv, as suggested during review. Changes from v1: * cite Coverity in the changelog. --- xen/common/sched_credit2.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index 7ec7f62..00d3300 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -1464,7 +1464,7 @@ csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) struct csched2_private *prv = CSCHED2_PRIV(ops); int i, min_rqi = -1, new_cpu; struct csched2_vcpu *svc = CSCHED2_VCPU(vc); - s_time_t min_avgload; + s_time_t min_avgload = MAX_LOAD; ASSERT(!cpumask_empty(&prv->active_queues)); @@ -1488,7 +1488,12 @@ csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) { /* We may be here because someone requested us to migrate. */ __clear_bit(__CSFLAG_runq_migrate_request, &svc->flags); - return get_fallback_cpu(svc); + new_cpu = get_fallback_cpu(svc); + /* + * Tracing of runq and its load won't be accurate, since we could + * not get the lock, but at least we will output the chosen pcpu. + */ + goto out; } /* @@ -1513,8 +1518,6 @@ csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) /* Fall-through to normal cpu pick */ } - min_avgload = MAX_LOAD; - /* Find the runqueue with the lowest average load. */ for_each_cpu(i, &prv->active_queues) { @@ -1552,7 +1555,7 @@ csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) if ( rqd_avgload < min_avgload ) { min_avgload = rqd_avgload; - min_rqi=i; + min_rqi = i; } } @@ -1560,6 +1563,8 @@ csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) if ( min_rqi == -1 ) { new_cpu = get_fallback_cpu(svc); + min_rqi = c2r(ops, new_cpu); + min_avgload = prv->rqd[min_rqi].b_avgload; goto out_up; } @@ -1570,18 +1575,18 @@ csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) out_up: read_unlock(&prv->lock); - + out: if ( unlikely(tb_init_done) ) { struct { uint64_t b_avgload; unsigned vcpu:16, dom:16; unsigned rq_id:16, new_cpu:16; - } d; - d.b_avgload = prv->rqd[min_rqi].b_avgload; + } d; d.dom = vc->domain->domain_id; d.vcpu = vc->vcpu_id; - d.rq_id = c2r(ops, new_cpu); + d.rq_id = min_rqi; + d.b_avgload = min_avgload; d.new_cpu = new_cpu; __trace_var(TRC_CSCHED2_PICKED_CPU, 1, sizeof(d),