From patchwork Mon Jun 5 19:59:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 689222 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d8a:0:0:0:0:0 with SMTP id b10csp2278661wru; Mon, 5 Jun 2023 13:00:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ePzGimB+GHT5sWo00afnvkdjUUtuDE5UiZZO80UvETCn/1KkfK4unQJeDZKg529ExIHha X-Received: by 2002:a05:6214:f0a:b0:626:94f:6044 with SMTP id gw10-20020a0562140f0a00b00626094f6044mr9493213qvb.2.1685995200653; Mon, 05 Jun 2023 13:00:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685995200; cv=none; d=google.com; s=arc-20160816; b=lTA0/D0uPhikWxSM8RCg/ztyJLMKLjM6ZiHWpdlfalj9O1/vOWopkKibuTPrFsvnHU Jb/hQdJOUjXCQuXv/FUjdXrgb4joQloPSjtQJbV45kGBZ/0ojVJq9mr6LadaGc9LjDOI yRYTxz17sddCkY0ixohRPeEgc+0z+1QTGXwgEMavidiQvBNPCnwkuug0v3lOSAoCOdQH gDlVcMmLEweJe9pXvftlWfWv2gdRKkIRMASDwTqUkOUHDEpcG2PaNA03MaI1opVEWODF qbtkKMnciSAippTFrVxe+iCwwFsGh6Z6IS+jZm9FzBEnehlxeZDXEm/Iwm++yPRjqq2z tgvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=HzdINXCsYw0zym0hC+hQh9rtw8qpwjppdu7/nsvwA5s=; b=xUiHUvU/NS2udrK9wlAy+Yw+MGMd68NOinjJa9Lafe6Nf8TZcnpu3nStQELEAPbuhW q5Lz0tqSZDN/yj4yZjroE7lGgNMEPRCUWPCBi1ipO4EZGyTKSCqVF5RjYE4yntKveqVr zQLGl1eTG+R6Tpp/uSOMm1iOJkRX5ANM7g5eh607YilXFI60Ewn5t4ZlBBBFz0sWz5e0 JV07EZM1fRE/h6mKUC9SfsVxibPR5ilW97kigxgztxVfTYKFh2huDtIhk5olhXmrsRiE nv5cWZs/xE0HNBd6jAX3Y30cJShAj/roisnkxshv/NO1/QpeIttIW3OkYiPJ7CEfOBVm Dj6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P9ALl6VD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id kk25-20020a056214509900b006261fd81906si5040610qvb.248.2023.06.05.13.00.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Jun 2023 13:00:00 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P9ALl6VD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q6GMJ-0006px-2T; Mon, 05 Jun 2023 15:59:19 -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 1q6GMH-0006pl-Qm for qemu-devel@nongnu.org; Mon, 05 Jun 2023 15:59:17 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q6GMG-0002tL-8Y for qemu-devel@nongnu.org; Mon, 05 Jun 2023 15:59:17 -0400 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3090d3e9c92so5286328f8f.2 for ; Mon, 05 Jun 2023 12:59:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685995154; x=1688587154; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=HzdINXCsYw0zym0hC+hQh9rtw8qpwjppdu7/nsvwA5s=; b=P9ALl6VDl6wa6kzj/rBJZrZFX8ud8gPURpHrNhCQC15hWFdeCELL095pcIttnS59O5 0IC/Blk/tFdtHm842hLWiWvU3q8LRKtL4ex5Lxyby9vc+WQUGaO5BVBOSVI6VI2930Z8 lSSBevfAatXyVmA76Prcf59Y8iocLRga5enPNjkbfZ6fOsNcAh+gYy61/CNQ81eXwaXR Zbj/+/vDAZ1wulY0y3SfyLT0w8J4dDDoci2KS3+WK9qe7MPpCQ3EbsUObxrwbPN19O6M XY/BLxe/2nCpPEOnGRe6GuVRRo8erwGXHbs7/6faf57ydAsHE/JUmq9msATpziIt+2I5 PiBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685995154; x=1688587154; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HzdINXCsYw0zym0hC+hQh9rtw8qpwjppdu7/nsvwA5s=; b=UacJNYwtz64PtFCQIw4/DlbUWhz7aEkZ/cQTrhmakpLTtyXYj1637kynHVMvLP5Gn2 XWQD3L5erstoLGsVBAVH8t7Q1MIj7jXfPT+2uqVBi2p2f3VeUsUVTJ/bH2neMB3mRZ+j ya/hMvPh73wmhikFMzhScCKEE+CZv9CE2dBqJKGOR6tg81OTYHeUDbM+FAfhOVQCjARF Y584Lgu8RdNFWYiRPUMAYHlwrHvs1E4ljOIcnrYmDpujM0Z9UgsH2h1fbWtN0JktUhey ScspQEsW3aFCVkqbHI7BgAP3yetds26DqXGC1PZx8wPdK3n+V2FnKywlhH75X2f5Fn+n R+9w== X-Gm-Message-State: AC+VfDw+MApG1ZMYghkWBpBtLunYRAA1Ww+qjTsjjbH1zC6XkAX5iGvB kqd8FBpTq0eOsVwyirCj8Rq3SgXuD2s9t5jP80M= X-Received: by 2002:a5d:4492:0:b0:2f4:170:3807 with SMTP id j18-20020a5d4492000000b002f401703807mr7915714wrq.44.1685995154262; Mon, 05 Jun 2023 12:59:14 -0700 (PDT) Received: from localhost.localdomain ([176.187.217.157]) by smtp.gmail.com with ESMTPSA id z10-20020a056000110a00b003063a92bbf5sm10629676wrw.70.2023.06.05.12.59.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 05 Jun 2023 12:59:13 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Richard Henderson , Akihiko Odaki , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH] util/cacheflush: Avoid flushing dcache twice when not necessary Date: Mon, 5 Jun 2023 21:59:11 +0200 Message-Id: <20230605195911.96033-1-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=philmd@linaro.org; helo=mail-wr1-x431.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, T_SCC_BODY_TEXT_LINE=-0.01 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org describes sys_icache_invalidate() as "equivalent to sys_cache_control(kCacheFunctionPrepareForExecution)", having kCacheFunctionPrepareForExecution defined as: /* Prepare memory for execution. This should be called * after writing machine instructions to memory, before * executing them. It syncs the dcache and icache. [...] */ Since the dcache is also sync'd, we can avoid the sys_dcache_flush() call when both rx/rw pointers are equal. Suggested-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- Based-on: <20230605175647.88395-2-philmd@linaro.org> --- util/cacheflush.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/util/cacheflush.c b/util/cacheflush.c index de35616718..a08906155a 100644 --- a/util/cacheflush.c +++ b/util/cacheflush.c @@ -241,7 +241,14 @@ static void __attribute__((constructor)) init_cache_info(void) void flush_idcache_range(uintptr_t rx, uintptr_t rw, size_t len) { - sys_dcache_flush((void *)rw, len); + if (rx == rw) { + /* + * sys_icache_invalidate() syncs the dcache and icache, + * so no need to call sys_dcache_flush(). + */ + } else { + sys_dcache_flush((void *)rw, len); + } sys_icache_invalidate((void *)rx, len); } #else