From patchwork Fri Sep 15 16:32:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1835055 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=BoHXb9ez; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RnKWt5xX5z1yhR for ; Sat, 16 Sep 2023 02:34:02 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qhBkc-0008FO-7J; Fri, 15 Sep 2023 12:33:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qhBka-0008Ee-Sc for qemu-devel@nongnu.org; Fri, 15 Sep 2023 12:33:00 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qhBkZ-00037L-7W for qemu-devel@nongnu.org; Fri, 15 Sep 2023 12:33:00 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-68fb79ef55eso2137444b3a.0 for ; Fri, 15 Sep 2023 09:32:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694795578; x=1695400378; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iJ6Oywpvjr1xG7Guou9tEnbUmyP3OUnn4VhCnCRzKJY=; b=BoHXb9ezG57eYc6uny9thtZ+GyAvtvLAWsvuG7K3IA6JdWWE8iYKOcpa3pwq5uBKKU xTRtw9WvIQlADM1orag8E9Gd18zaPELz5PJ/vm7qYzat/ZqkxV5Wy2dWF7Fkpls/YN69 eQIGbbWTBQCPKOWGB+XNKW4k6XYgMIU+dxIjgOKHrIcYxq2JMy18jbL7xTscPfoOQD0N C5FvXKdkXQZLes3a3hg6C9wHtVHUsc74UGJLatmcToDl1CVCgiV2mWS8M322t/YXK7T8 89Uj22CyPNgETbdrwT3qhn2jYgH32Dx3jId9TSFMlCNOT88Q+MnehVGSTWI5w1qPRKV+ RA6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694795578; x=1695400378; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iJ6Oywpvjr1xG7Guou9tEnbUmyP3OUnn4VhCnCRzKJY=; b=gb4vYcHghb+K3wppA3VaK4RR4241nCam3uJm99q6yV+4aGxqJRjeTz17N05rDQjPcu AH0hJnRd2hHN7zkhCEYyIb+nRyRrpeFIR11VJRhv3SswcIzt2WxwA1fqCQngvl57S1Tm F875PsUObkAxRk3YC6TVAPtG3FqwXInFT3wPn2Df+IUfoPBpqYgt/Wstv8MnXjO4Tb+Z +G1Rjf54x3VDhgUx2pKkB4KbkTOgtN3pTT2VfncQC35EJAU6z2pxUnL6PwKb4vSdN7It RWQBgsY56XZgyZACJxFmPgzly4ox4ZRM0Te5IvyvpCGEPm7+RMYULalZ/XxlwAeMvMma YbVw== X-Gm-Message-State: AOJu0YxX28T++bMEPxNf7t4UEwa2gT9fTqd19dMRo05ARAfO5p94hFjg 0/bCi7pqI+ekJoGw2kjVI+uLnpoA0rBZBi0Cz+E= X-Google-Smtp-Source: AGHT+IHmBWeoqa475C9Bo6s5X6vPH5xf3QnpRGzSFb+/ImQCwZ/mfNMX1sfgbdg61SmgMpulVGHWjA== X-Received: by 2002:a05:6a21:18d:b0:129:d944:2e65 with SMTP id le13-20020a056a21018d00b00129d9442e65mr3105614pzb.13.1694795577935; Fri, 15 Sep 2023 09:32:57 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id z3-20020a637e03000000b0057754ae4eb7sm2958497pgc.39.2023.09.15.09.32.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 09:32:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: philmd@linaro.org Subject: [PATCH v2 2/3] softmmu: Introduce AddressSpaceDispatch generation numbers Date: Fri, 15 Sep 2023 09:32:53 -0700 Message-Id: <20230915163254.123338-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230915163254.123338-1-richard.henderson@linaro.org> References: <20230915163254.123338-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 Allow the cpu to easily check if an address space update is required. The acquire/release semantics will be used by a subsequent patch. Signed-off-by: Richard Henderson --- softmmu/physmem.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 88fafec1da..e1c535380a 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -163,6 +163,8 @@ struct CPUAddressSpace { AddressSpace *as; struct AddressSpaceDispatch *memory_dispatch; MemoryListener tcg_as_listener; + uint32_t commit_gen; + uint32_t layout_gen; }; struct DirtyBitmapSnapshot { @@ -2486,14 +2488,23 @@ static void tcg_log_global_after_sync(MemoryListener *listener) } } -static void tcg_commit_cpu(CPUState *cpu, run_on_cpu_data data) +static void tcg_commit_cpu_0(CPUState *cpu, CPUAddressSpace *cpuas) { - CPUAddressSpace *cpuas = data.host_ptr; - cpuas->memory_dispatch = address_space_to_dispatch(cpuas->as); tlb_flush(cpu); } +static void tcg_commit_cpu_1(CPUState *cpu, run_on_cpu_data data) +{ + CPUAddressSpace *cpuas = data.host_ptr; + uint32_t gen = qatomic_load_acquire(&cpuas->layout_gen); + + if (cpuas->commit_gen != gen) { + cpuas->commit_gen = gen; + tcg_commit_cpu_0(cpu, cpuas); + } +} + static void tcg_commit(MemoryListener *listener) { CPUAddressSpace *cpuas; @@ -2518,9 +2529,10 @@ static void tcg_commit(MemoryListener *listener) * all of the tcg machinery for run-on is initialized: thus created. */ if (cpu->created) { - async_run_on_cpu(cpu, tcg_commit_cpu, RUN_ON_CPU_HOST_PTR(cpuas)); + qatomic_store_release(&cpuas->layout_gen, cpuas->layout_gen + 1); + async_run_on_cpu(cpu, tcg_commit_cpu_1, RUN_ON_CPU_HOST_PTR(cpuas)); } else { - tcg_commit_cpu(cpu, RUN_ON_CPU_HOST_PTR(cpuas)); + tcg_commit_cpu_0(cpu, cpuas); } }