From mboxrd@z Thu Jan 1 00:00:00 1970 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) From: Alvise Rigo Date: Thu, 26 May 2016 18:35:43 +0200 Message-Id: <20160526163549.3276-5-a.rigo@virtualopensystems.com> In-Reply-To: <20160526163549.3276-1-a.rigo@virtualopensystems.com> References: <20160526163549.3276-1-a.rigo@virtualopensystems.com> Subject: [Qemu-devel] [RFC 04/10] cputlb: Introduce tlb_flush_other() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: mttcg@listserver.greensocs.com, alex.bennee@linaro.org Cc: qemu-devel@nongnu.org, jani.kokkonen@huawei.com, claudio.fontana@huawei.com, tech@virtualopensystems.com, fred.konrad@greensocs.com, pbonzini@redhat.com, rth@twiddle.net, serge.fdrv@gmail.com, cota@braap.org, peter.maydell@linaro.org, Alvise Rigo 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); } } } -- 2.8.3