From patchwork Wed Jul 6 21:14:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: sergey.fedorov@linaro.org X-Patchwork-Id: 9217057 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 7B8E060752 for ; Wed, 6 Jul 2016 21:20:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 663DC2846A for ; Wed, 6 Jul 2016 21:20:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5636428486; Wed, 6 Jul 2016 21:20:15 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B007C2846A for ; Wed, 6 Jul 2016 21:20:14 +0000 (UTC) Received: from localhost ([::1]:35876 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKuEv-00012I-Es for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Jul 2016 17:20:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48396) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKuA8-0003g3-4Q for qemu-devel@nongnu.org; Wed, 06 Jul 2016 17:15:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKuA6-0007Gn-0F for qemu-devel@nongnu.org; Wed, 06 Jul 2016 17:15:15 -0400 Received: from mail-lf0-x235.google.com ([2a00:1450:4010:c07::235]:35771) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKuA5-0007GS-PU for qemu-devel@nongnu.org; Wed, 06 Jul 2016 17:15:13 -0400 Received: by mail-lf0-x235.google.com with SMTP id l188so162672764lfe.2 for ; Wed, 06 Jul 2016 14:15:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pq9CNYUnU+xAH3qLEFxM8bEY7UMNZB3Yb8LXpqTRUUo=; b=XxoUUPSsWh0QKajXHxZOyb8SAV9HW5CSWJwUtpFkeJ12Zla0MmQcrDFYVNmUeBMau4 U9HOWVGslL5Otv1KWkRpbZGx9HILB9m/jYPriks+VZPzbWV84AbvUYQNf0aSLrcHvNBp yEhaASA9Yq+4bMSSCpXD72F5Izzf1wVahHn8M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Pq9CNYUnU+xAH3qLEFxM8bEY7UMNZB3Yb8LXpqTRUUo=; b=gHKGyVA/hWnfLVn99GKiqDDYWDqX84j6k73pN3in4COEFT4wKOIQh4BseQuQhQEEy0 uAQJvplgGlPXTtG/7ujsjGBkXVd21JasqRIUCXChcNWPtU5kMlyft1JI70O4NEWAl0Sf EmY2irlAIgfEqef37nPolIl2XFQGlx+2HqscudS7VjrAzlHoQcUvfa7keGA7pEsYnPFR T0Lbqzqxr/24jnTIS9MHsH+Nq1omzwbivft8Jk4gORbdXoykZDTX9WgXKYI/V5rkrAlo J1s4R+dvpEWCgsMBZhx0CgMGgFuPUfPawS3zCWXskNZkDkTXMSxnTOuw+3qpXZBTu5M+ wImw== X-Gm-Message-State: ALyK8tIUFDluCUh+JyynCX3yNMv7kRYTzpBF48vGtmZuct6snHFXZqzJuQfMZ6YKxgoeCsES X-Received: by 10.25.149.6 with SMTP id x6mr5355107lfd.106.1467839713147; Wed, 06 Jul 2016 14:15:13 -0700 (PDT) Received: from sergey-laptop.Dlink (broadband-46-188-120-37.2com.net. [46.188.120.37]) by smtp.gmail.com with ESMTPSA id l79sm4420028lfi.40.2016.07.06.14.15.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Jul 2016 14:15:12 -0700 (PDT) From: Sergey Fedorov To: qemu-devel@nongnu.org Date: Thu, 7 Jul 2016 00:14:55 +0300 Message-Id: <1467839703-11733-4-git-send-email-sergey.fedorov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467839703-11733-1-git-send-email-sergey.fedorov@linaro.org> References: <1467839703-11733-1-git-send-email-sergey.fedorov@linaro.org> 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:4010:c07::235 Subject: [Qemu-devel] [RFC v2 03/11] cpus: Move common code out of {async_, }run_on_cpu() 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: MTTCG Devel , Peter Maydell , Sergey Fedorov , Peter Crosthwaite , Alvise Rigo , "Emilio G. Cota" , Sergey Fedorov , Paolo Bonzini , Richard Henderson , =?UTF-8?Q?Alex_Benn=c3=a9e?= , =?UTF-8?B?S09OUkFEIEZyw6lkw6lyaWM=?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Sergey Fedorov Move the code common between run_on_cpu() and async_run_on_cpu() into a new function queue_work_on_cpu(). Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Reviewed-by: Alex Bennée --- cpus.c | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/cpus.c b/cpus.c index 049c2d04e150..04687c85bcd4 100644 --- a/cpus.c +++ b/cpus.c @@ -910,6 +910,22 @@ void qemu_init_cpu_loop(void) qemu_thread_get_self(&io_thread); } +static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi) +{ + qemu_mutex_lock(&cpu->work_mutex); + if (cpu->queued_work_first == NULL) { + cpu->queued_work_first = wi; + } else { + cpu->queued_work_last->next = wi; + } + cpu->queued_work_last = wi; + wi->next = NULL; + wi->done = false; + qemu_mutex_unlock(&cpu->work_mutex); + + qemu_cpu_kick(cpu); +} + void run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data) { struct qemu_work_item wi; @@ -923,18 +939,7 @@ void run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data) wi.data = data; wi.free = false; - qemu_mutex_lock(&cpu->work_mutex); - if (cpu->queued_work_first == NULL) { - cpu->queued_work_first = &wi; - } else { - cpu->queued_work_last->next = &wi; - } - cpu->queued_work_last = &wi; - wi.next = NULL; - wi.done = false; - qemu_mutex_unlock(&cpu->work_mutex); - - qemu_cpu_kick(cpu); + queue_work_on_cpu(cpu, &wi); while (!atomic_mb_read(&wi.done)) { CPUState *self_cpu = current_cpu; @@ -957,18 +962,7 @@ void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, void *data) wi->data = data; wi->free = true; - qemu_mutex_lock(&cpu->work_mutex); - if (cpu->queued_work_first == NULL) { - cpu->queued_work_first = wi; - } else { - cpu->queued_work_last->next = wi; - } - cpu->queued_work_last = wi; - wi->next = NULL; - wi->done = false; - qemu_mutex_unlock(&cpu->work_mutex); - - qemu_cpu_kick(cpu); + queue_work_on_cpu(cpu, wi); } static void qemu_kvm_destroy_vcpu(CPUState *cpu)