From patchwork Thu May 26 16:35:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alvise rigo X-Patchwork-Id: 9137245 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 0531D607D3 for ; Thu, 26 May 2016 16:36:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDB8927D11 for ; Thu, 26 May 2016 16:36:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2690282E2; Thu, 26 May 2016 16:36:52 +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 8841227D11 for ; Thu, 26 May 2016 16:36:52 +0000 (UTC) Received: from localhost ([::1]:39480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5yHD-0006XE-I6 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 26 May 2016 12:36:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58492) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5yGe-0006S2-FE for qemu-devel@nongnu.org; Thu, 26 May 2016 12:36:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5yGc-0003kO-Cp for qemu-devel@nongnu.org; Thu, 26 May 2016 12:36:15 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:34772) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5yGc-0003kD-5m for qemu-devel@nongnu.org; Thu, 26 May 2016 12:36:14 -0400 Received: by mail-wm0-x242.google.com with SMTP id n129so6554179wmn.1 for ; Thu, 26 May 2016 09:36:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtualopensystems-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oT7O+DGQQFOORiKslg8b7UECPiulrCkyOAnhsOBqfn8=; b=gks3Zwx69BJjmoe8S3qcKLSxrsQUsHvE/swLWf+0RkjhfQqbYWoygm7RZ9HTC5iPB+ iDZ3c2nN+JR9W/8Mc6bTgg2CSmMXlbOxDu/qatpQpjr5CjWWmB2Aps2FMD+bcXNPTcdj BKlLEK85t9cNtpGXrxr42GVuQ2x6HSrV123tooROnReZSsa2HrG5ocZJ+Fu+qkOL0otJ E/5jP1YELIBaQzDQLx7evyx6W6mPwI2beKqyzWFMIMebVo8b0jrmPqX4ygZSk550Vqz8 5Iduu1tQbiJ9cAAJjZLXKYm11g8rK370raPuZQn3KvDFv4o8G/02ECd+AXM3nFt6xH1z 0Q2w== 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; bh=oT7O+DGQQFOORiKslg8b7UECPiulrCkyOAnhsOBqfn8=; b=XkpJeOj3iz0sXOUziFiNTdKsnMoxMnTulqzeX4DymMJ7ICKuL6dD3aKiPyyP20Q66V m4poQD5t7fQI91Bhu8I9A6s0K4e/TlaQ6Wok0uty1MyAGaXG92eTZfAGSONF5LcVYooH DlQyp4KI7kx/4GYs0SngQ2A22vXkNzooL2H6er7t8MGxMJUbmLo8pDMwCPHSysYIdSmo hIWO1pbx2QkF6c+2KFvtBJLCpsyrA9KEiAd/dOD15PlmBcQdErU2Vp3PBY+OhFhZzEBk ADN7KRSPLfMiLuJPPhhJREVt1g5i/z9ukAAzoZ23oqInIZfhpVC7bZFD1mERJJjUGSIj KPNA== X-Gm-Message-State: ALyK8tJtH7RIUqEPxQ7eJrERpr3RRMdN282xE/gAswzKLecjIwN67jRZNCjifJoWcAgRWA== X-Received: by 10.194.89.33 with SMTP id bl1mr10378177wjb.43.1464280573422; Thu, 26 May 2016 09:36:13 -0700 (PDT) Received: from linarch.localdomain (LPuteaux-656-1-278-113.w80-15.abo.wanadoo.fr. [80.15.154.113]) by smtp.googlemail.com with ESMTPSA id lf9sm15133703wjc.44.2016.05.26.09.36.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 May 2016 09:36:12 -0700 (PDT) From: Alvise Rigo To: mttcg@listserver.greensocs.com, alex.bennee@linaro.org Date: Thu, 26 May 2016 18:35:43 +0200 Message-Id: <20160526163549.3276-5-a.rigo@virtualopensystems.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160526163549.3276-1-a.rigo@virtualopensystems.com> References: <20160526163549.3276-1-a.rigo@virtualopensystems.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [RFC 04/10] cputlb: Introduce tlb_flush_other() 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: peter.maydell@linaro.org, rth@twiddle.net, claudio.fontana@huawei.com, qemu-devel@nongnu.org, Alvise Rigo , cota@braap.org, serge.fdrv@gmail.com, pbonzini@redhat.com, jani.kokkonen@huawei.com, tech@virtualopensystems.com, fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In some cases (like in softmmu_llsc_template.h) we know for certain that we need to flush other VCPUs' TLB. tlb_flush_other() serves this purpose, allowing the VCPU @cpu to query a global flush to @other. In addition, use it also in softmmu_llsc_template.h and tlb_flush() if possible. Signed-off-by: Alvise Rigo --- cputlb.c | 28 +++++++++++++++++++++++----- softmmu_llsc_template.h | 2 +- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/cputlb.c b/cputlb.c index 1586b64..55f7447 100644 --- a/cputlb.c +++ b/cputlb.c @@ -81,12 +81,24 @@ static void tlb_flush_nocheck(CPUState *cpu, int flush_global) env->tlb_flush_addr = -1; env->tlb_flush_mask = 0; tlb_flush_count++; - /* atomic_mb_set(&cpu->pending_tlb_flush, 0); */ } static void tlb_flush_global_async_work(CPUState *cpu, void *opaque) { tlb_flush_nocheck(cpu, GPOINTER_TO_INT(opaque)); + atomic_mb_set(&cpu->pending_tlb_flush, false); +} + +static void tlb_flush_other(CPUState *cpu, CPUState *other, int flush_global) +{ + if (other->created) { + if (!atomic_xchg(&other->pending_tlb_flush, true)) { + async_wait_run_on_cpu(other, cpu, tlb_flush_global_async_work, + GINT_TO_POINTER(flush_global)); + } + } else { + tlb_flush_nocheck(other, flush_global); + } } /* NOTE: @@ -103,11 +115,17 @@ static void tlb_flush_global_async_work(CPUState *cpu, void *opaque) */ void tlb_flush(CPUState *cpu, int flush_global) { - if (cpu->created) { - async_run_on_cpu(cpu, tlb_flush_global_async_work, - GINT_TO_POINTER(flush_global)); - } else { + /* if @cpu has not been created yet or it is the current_cpu, we do not + * need to query the flush. */ + if (current_cpu == cpu || !cpu->created) { tlb_flush_nocheck(cpu, flush_global); + } else { + if (current_cpu) { + tlb_flush_other(current_cpu, cpu, flush_global); + } else { + async_run_on_cpu(cpu, tlb_flush_global_async_work, + GINT_TO_POINTER(flush_global)); + } } } diff --git a/softmmu_llsc_template.h b/softmmu_llsc_template.h index d3810c0..51ce58f 100644 --- a/softmmu_llsc_template.h +++ b/softmmu_llsc_template.h @@ -81,7 +81,7 @@ WORD_TYPE helper_ldlink_name(CPUArchState *env, target_ulong addr, excl_history_put_addr(hw_addr); CPU_FOREACH(cpu) { if (this_cpu != cpu) { - tlb_flush(cpu, 1); + tlb_flush_other(this_cpu, cpu, 1); } } }