From patchwork Mon Oct 31 14:13:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 80187 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp147780qge; Mon, 31 Oct 2016 07:32:40 -0700 (PDT) X-Received: by 10.200.39.125 with SMTP id h58mr25379709qth.142.1477924360870; Mon, 31 Oct 2016 07:32:40 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d200si2145505qke.121.2016.10.31.07.32.40 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 31 Oct 2016 07:32:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:36005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1Ddg-0000zh-34 for patch@linaro.org; Mon, 31 Oct 2016 10:32:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1DLc-0000K6-4S for qemu-devel@nongnu.org; Mon, 31 Oct 2016 10:14:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1DLb-0002yK-2E for qemu-devel@nongnu.org; Mon, 31 Oct 2016 10:14:00 -0400 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:38121) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c1DLa-0002xs-Qs for qemu-devel@nongnu.org; Mon, 31 Oct 2016 10:13:58 -0400 Received: by mail-wm0-x22f.google.com with SMTP id n67so231336130wme.1 for ; Mon, 31 Oct 2016 07:13:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eutBw6JYhLQbrJ0Zn8AS6U7S7zyqH1na2jBgHRGYXNk=; b=QUoQNe5zqpgsVZnzG2E0j7b4U1WVqFNa71ThoPmBh9N5PHAyDnd4uU3Bf57gVpuN4o ajhVfmnAHyuwAh3pkbh+VKvJQXVW594hko8zj5CMqtIirQml4IHHT4NdY3MRm1CDGT8N pNtxylSWrLSMpbqu9MzUCH3IdAj8bgd8J+pY54fOIhMN8uM/FVbqyFqLveByxrYEDB6w qhqk4Br0DGL3iarWw0rXsR5pvbps/dPdnPty+21k0fnLmbo1dzGa9gTNy3UwA4sDPyhf Xr1BR0r9Pr6m63lbn3kfbu/VE2Pf8Cl9yWSPGCI3KUN1msOJyOcujrfYtvF3wJyGxImO dFEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=eutBw6JYhLQbrJ0Zn8AS6U7S7zyqH1na2jBgHRGYXNk=; b=GUQ5/PCiNfFVl2/pGhF3SuLFghYItEn1OZTmviRKgO8hilWFoaNEP1n0w4I80d/36s w4B4zQ6ZiedJb1wdvvXnyMouIC+E8t98WjzwaoW75rdGVt9//pMNSmzGyqh0PLO7xTIV VvBX4YeLCZIimu4SJE87n+v1yzQWF+aYGxTSmhuRhVVq0wErj71LlBUW9f0lV2FLt3Y0 8U1x1Rc5gmG/i+WLV/x3ijZWAsxvYY32a2WZylCSp6vRiG2aD1rt88sFuDt1tI1Ck5i1 GcU/zTtV/TCw/Uylq2xa1mzFiEago3JoTXvV8SfkC6up3M/NX/KquI13U8X2DI//Kw8i gbfw== X-Gm-Message-State: ABUngvfcptB2HoRxrrC6MuRaunNiGysgB4mtqTIFoUyiyzu58OGmWmpql74qMVDlbGMRTA== X-Received: by 10.28.126.193 with SMTP id z184mr10380131wmc.87.1477923237549; Mon, 31 Oct 2016 07:13:57 -0700 (PDT) Received: from donizetti.lan (dynamic-adsl-78-12-246-178.clienti.tiscali.it. [78.12.246.178]) by smtp.gmail.com with ESMTPSA id p13sm25052133wmd.20.2016.10.31.07.13.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Oct 2016 07:13:56 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 31 Oct 2016 15:13:32 +0100 Message-Id: <1477923215-30323-12-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477923215-30323-1-git-send-email-pbonzini@redhat.com> References: <1477923215-30323-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22f Subject: [Qemu-devel] [PULL 11/14] tcg: cpus rm tcg_exec_all() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée In preparation for multi-threaded TCG we remove tcg_exec_all and move all the CPU cycling into the main thread function. When MTTCG is enabled we shall use a separate thread function which only handles one vCPU. Signed-off-by: Alex Bennée Reviewed-by: Sergey Fedorov Reviewed-by: Richard Henderson Message-Id: <20161027151030.20863-13-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini --- cpus.c | 87 +++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 43 insertions(+), 44 deletions(-) -- 2.7.4 diff --git a/cpus.c b/cpus.c index 77cc24b..cc49902 100644 --- a/cpus.c +++ b/cpus.c @@ -69,7 +69,6 @@ #endif /* CONFIG_LINUX */ -static CPUState *next_cpu; int64_t max_delay; int64_t max_advance; @@ -1119,46 +1118,26 @@ static int tcg_cpu_exec(CPUState *cpu) return ret; } -static void tcg_exec_all(void) +/* Destroy any remaining vCPUs which have been unplugged and have + * finished running + */ +static void deal_with_unplugged_cpus(void) { - int r; - - /* Account partial waits to QEMU_CLOCK_VIRTUAL. */ - qemu_account_warp_timer(); - - if (next_cpu == NULL) { - next_cpu = first_cpu; - } - for (; next_cpu != NULL && !exit_request; next_cpu = CPU_NEXT(next_cpu)) { - CPUState *cpu = next_cpu; - - qemu_clock_enable(QEMU_CLOCK_VIRTUAL, - (cpu->singlestep_enabled & SSTEP_NOTIMER) == 0); + CPUState *cpu; - if (cpu_can_run(cpu)) { - r = tcg_cpu_exec(cpu); - if (r == EXCP_DEBUG) { - cpu_handle_guest_debug(cpu); - break; - } else if (r == EXCP_ATOMIC) { - cpu_exec_step_atomic(cpu); - } - } else if (cpu->stop || cpu->stopped) { - if (cpu->unplug) { - next_cpu = CPU_NEXT(cpu); - } + CPU_FOREACH(cpu) { + if (cpu->unplug && !cpu_can_run(cpu)) { + qemu_tcg_destroy_vcpu(cpu); + cpu->created = false; + qemu_cond_signal(&qemu_cpu_cond); break; } } - - /* Pairs with smp_wmb in qemu_cpu_kick. */ - atomic_mb_set(&exit_request, 0); } static void *qemu_tcg_cpu_thread_fn(void *arg) { CPUState *cpu = arg; - CPUState *remove_cpu = NULL; rcu_register_thread(); @@ -1185,8 +1164,39 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) /* process any pending work */ atomic_mb_set(&exit_request, 1); + cpu = first_cpu; + while (1) { - tcg_exec_all(); + /* Account partial waits to QEMU_CLOCK_VIRTUAL. */ + qemu_account_warp_timer(); + + if (!cpu) { + cpu = first_cpu; + } + + for (; cpu != NULL && !exit_request; cpu = CPU_NEXT(cpu)) { + + qemu_clock_enable(QEMU_CLOCK_VIRTUAL, + (cpu->singlestep_enabled & SSTEP_NOTIMER) == 0); + + if (cpu_can_run(cpu)) { + int r; + r = tcg_cpu_exec(cpu); + if (r == EXCP_DEBUG) { + cpu_handle_guest_debug(cpu); + break; + } + } else if (cpu->stop || cpu->stopped) { + if (cpu->unplug) { + cpu = CPU_NEXT(cpu); + } + break; + } + + } /* for cpu.. */ + + /* Pairs with smp_wmb in qemu_cpu_kick. */ + atomic_mb_set(&exit_request, 0); if (use_icount) { int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL); @@ -1196,18 +1206,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) } } qemu_tcg_wait_io_event(QTAILQ_FIRST(&cpus)); - CPU_FOREACH(cpu) { - if (cpu->unplug && !cpu_can_run(cpu)) { - remove_cpu = cpu; - break; - } - } - if (remove_cpu) { - qemu_tcg_destroy_vcpu(remove_cpu); - cpu->created = false; - qemu_cond_signal(&qemu_cpu_cond); - remove_cpu = NULL; - } + deal_with_unplugged_cpus(); } return NULL;