From patchwork Fri Aug 14 15:55:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alvise Rigo X-Patchwork-Id: 507492 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 51184140293 for ; Sat, 15 Aug 2015 02:02:07 +1000 (AEST) Received: from localhost ([::1]:47073 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZQHQj-0000VL-9U for incoming@patchwork.ozlabs.org; Fri, 14 Aug 2015 12:02:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZQHHi-0003wV-Lq for qemu-devel@nongnu.org; Fri, 14 Aug 2015 11:52:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZQHHf-0003Va-EB for qemu-devel@nongnu.org; Fri, 14 Aug 2015 11:52:46 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:38087) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZQHHf-0003VL-8v for qemu-devel@nongnu.org; Fri, 14 Aug 2015 11:52:43 -0400 Received: by wicja10 with SMTP id ja10so25237884wic.1 for ; Fri, 14 Aug 2015 08:52:42 -0700 (PDT) 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=AxHgShzkV1R2YkGPwHLc54jY6BJ7VJE+uIiM3onHgak=; b=WQs+8usaAqzWZ5lr4PXL2EEWQTsZ4YlrM1R0wr4K5UJ1TpPW5zTywiCl/RLhQgdZgS cRHwgyCzGK0b4TiWB0Cynzc8IDDZjQbmI6ESy4kc67dSI7QubOuvDXXIajpdOgKIOgXs yqbvCQ32wNuP3/pBTtE3sTOuhiqR1KAK3aReixHpLQSy2Pc/X3oWua/t04+Z4i+ppYSa hkwQiiKMfMSYkpmOqXNqBQYYx2M9legX7yMBqBfKVq5lD9QmbE3yZB6nPcI4K1Xxp7o7 7YyAceT23kfcMBCeW7y0wqwjwMJkjrwwnoVNaBbEmXLBDoNjLNHS/pkzVkVRjs2vPQri RhRw== X-Gm-Message-State: ALoCoQkzGn68eRTwsQznmmYtMOv1kKiYJapWt88P8i+Uvmi/XxQ0ySN9VcA9lkG79WsWzioxs7rj X-Received: by 10.180.188.201 with SMTP id gc9mr8324614wic.39.1439567562705; Fri, 14 Aug 2015 08:52:42 -0700 (PDT) Received: from linarch.home (LPuteaux-656-1-278-113.w80-15.abo.wanadoo.fr. [80.15.154.113]) by smtp.googlemail.com with ESMTPSA id fs8sm3694285wib.0.2015.08.14.08.52.41 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Aug 2015 08:52:42 -0700 (PDT) From: Alvise Rigo To: qemu-devel@nongnu.org, mttcg@listserver.greensocs.com Date: Fri, 14 Aug 2015 17:55:28 +0200 Message-Id: <1439567732-14118-3-git-send-email-a.rigo@virtualopensystems.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1439567732-14118-1-git-send-email-a.rigo@virtualopensystems.com> References: <1439567732-14118-1-git-send-email-a.rigo@virtualopensystems.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.212.169 Cc: claudio.fontana@huawei.com, pbonzini@redhat.com, jani.kokkonen@huawei.com, tech@virtualopensystems.com, alex.bennee@linaro.org, aurelien@aurel32.net Subject: [Qemu-devel] [mttcg RFC v4 2/6] cputlb: wrap tlb_flush with the a new function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Introduce the new tlb_query_flush_cpu function to query a TLB flush to a given vCPU. The function takes care to check and set a new flag (pending_tlb_flush) to avoid unnecessary flushes. Signed-off-by: Alvise Rigo --- cputlb.c | 21 ++++++++++++++++----- include/exec/exec-all.h | 1 + include/qom/cpu.h | 4 ++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/cputlb.c b/cputlb.c index 538c92d..7cbaaca 100644 --- a/cputlb.c +++ b/cputlb.c @@ -79,13 +79,27 @@ static void tlb_flush_async_work(void *opaque) struct TLBFlushParams *params = opaque; tlb_flush(params->cpu, params->flush_global); + atomic_set(¶ms->cpu->pending_tlb_flush, 0); + g_free(params); } +void tlb_query_flush_cpu(CPUState *cpu, int flush_global) { + struct TLBFlushParams *params; + + if (!atomic_read(&cpu->pending_tlb_flush)) { + params = g_malloc(sizeof(struct TLBFlushParams)); + params->cpu = cpu; + params->flush_global = flush_global; + + atomic_set(&cpu->pending_tlb_flush, 1); + async_run_on_cpu(cpu, tlb_flush_async_work, params); + } +} + void tlb_flush_all(int flush_global) { CPUState *cpu; - struct TLBFlushParams *params; #if 0 /* MTTCG */ CPU_FOREACH(cpu) { @@ -99,10 +113,7 @@ void tlb_flush_all(int flush_global) */ tlb_flush(cpu, flush_global); } else { - params = g_malloc(sizeof(struct TLBFlushParams)); - params->cpu = cpu; - params->flush_global = flush_global; - async_run_on_cpu(cpu, tlb_flush_async_work, params); + tlb_query_flush_cpu(cpu, flush_global); } } #endif /* MTTCG */ diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 246df68..3c36724 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -99,6 +99,7 @@ void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as); /* cputlb.c */ void tlb_flush_page_all(target_ulong addr); void tlb_flush_page(CPUState *cpu, target_ulong addr); +void tlb_query_flush_cpu(CPUState *cpu, int flush_global); void tlb_flush_all(int flush_global); void tlb_flush(CPUState *cpu, int flush_global); void tlb_set_page(CPUState *cpu, target_ulong vaddr, diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 23418c0..62abf6e 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -299,6 +299,10 @@ struct CPUState { void *opaque; + /* True if the CPU has a pending request for a TLB flush. While this value + * is true, any flush request will be ignored. */ + int pending_tlb_flush; + /* In order to avoid passing too many arguments to the MMIO helpers, * we store some rarely used information in the CPU context. */