From patchwork Wed Sep 14 11:52:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 605727 Delivered-To: patch@linaro.org Received: by 2002:ab3:1c02:0:b0:1e7:4ce8:c350 with SMTP id u2csp728335lth; Wed, 14 Sep 2022 06:09:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR5V9DvN4Nq4l0MXkUmZ7s+vbmrrSebNU0r9CDC3Dw+wLrz1lhVgNy9QNxhrQ2cfoxe9PAV8 X-Received: by 2002:a0c:a901:0:b0:4aa:a283:ef4a with SMTP id y1-20020a0ca901000000b004aaa283ef4amr31186885qva.53.1663160954033; Wed, 14 Sep 2022 06:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663160954; cv=none; d=google.com; s=arc-20160816; b=CPMgruZCS7GJsQvsKAZpIPcndfBcDf59u0J6GUIUooZ8DhHpBQvyLsWsKU2YdQQ93y kMue+g5nEyRuBPgD3uacpWQqZLJXoZeHoQNVDv3GjvnC6WCUoT0h1K8tcSLqiDuhrPN2 IiNG8RjF56DRtYT6FwszzXre2vONevRpDJt0ql+RGg9U49ydp3amKuqaYN9jmElzSA7D D7uVnLZpzZMMYJpTlaA3YwPRMQlfC8yPJLrkibEUzqp12r6Bo20B84BFw6ysi9jxUcU6 iK/OrrFiD2/fJ5RVVztEkEaOqlSpwIlvu5z9EfVNShi3CkbQrUS9qDSQZrO2a0q3MSHk 3t6A== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=08B8gQb2lmpmsncem0SFN7qjCMuyv6NQI4M/MAS7Oc4=; b=O8rBRWmTt6N+1+rMtKz1YluBUbOHEpOyEwZqaq6tId5V/WnjrhIEzOYkpWbJvV2PrF 0+IZEsZqWB5sV7cafIo3s1/TUsYEZ9F8/iUksBfbd6T1+rgSa76JUJL/6RMlN4pJNOEr uYCDeSnl4VpaXfOtBTRG39DR2TXihpMICsWYje13x3eaKLq0itQSS066sk7O1azeNzm9 eIVU3OmvSZNzaJ0qmucCeN9wihzdA5eBDlj3jddQv5Evoo782ozkfQZNDNq5GhvSgHMY l25RWre0YEtzezLs4W3JozlELMeSZIxh88Bg+4LATIrpkqeRC/HpKKLwk/eGMwZMSNDd iN8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=w+X8lKz4; 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 g7-20020ac85807000000b0031eee68f7f6si1394355qtg.462.2022.09.14.06.09.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Sep 2022 06:09:14 -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=w+X8lKz4; 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]:54918 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYS8f-0003Vc-CK for patch@linaro.org; Wed, 14 Sep 2022 09:09:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYQwb-0000Vb-EB for qemu-devel@nongnu.org; Wed, 14 Sep 2022 07:52:41 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:51717) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYQwS-00005h-6C for qemu-devel@nongnu.org; Wed, 14 Sep 2022 07:52:41 -0400 Received: by mail-wm1-x330.google.com with SMTP id o5so7351257wms.1 for ; Wed, 14 Sep 2022 04:52:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=08B8gQb2lmpmsncem0SFN7qjCMuyv6NQI4M/MAS7Oc4=; b=w+X8lKz4CgWH26KyKERUhL2HiTwlZQYH9eiTMJlNGmRcnkN5cA84RnB0fhX1RZmdKs 3DYoBTFKtxxFkzxxab0AymTjbfuYoZIdOookm/Kvw7SQfXR/Khye66k6vGSqnXqdKLSP uNzOMOZ0iXBrDxPTEHiyUarFsk9Rkj+whNC2C5sMKiZFbT0fkDcrUiLvMAOQiJ9tGa7S N4iD+UPwchzkE60uNSTwAu5aECRIf1UEx2T5Ocn8bdFoLjfifXAW+IN0cYM16AhehthY LJwKWV5XIQ+DsCfOrUNy9QJEJVy5HXBY+I95rrxxfxSs8GXg8ZzlVsHn7lgJXJOC1cp3 OU/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=08B8gQb2lmpmsncem0SFN7qjCMuyv6NQI4M/MAS7Oc4=; b=LfOfcYtyAYtJ9tri6n3yv2PqehXL3nkAXhbNX0xBtbXuAv7TkJ4wQDiGLuygRjmtbA KfFbY30pRwwOmBjtOpw/HPtMUDiSBFUZUi4cp9h1zTcSojZanSH7aoHyeTHC++xl5OrP CG1VGNPPZV1tEAsquTIXIAMdXIkLmEexY998MgRjeOIJktuY0RPrcgOUw52vedtHILpY d8YKRkli5N/SKbXEGS82BJ+NaHiXeGXN1s0PM07TQO4FKodoSyZ2uCac96IHCN9HMlYx 50kRdK/Fy96T+C0RbJGCLiOqMIR1sxT2IyNOlJkzCFGNBk3XQ3TuxH7r55S0VO2ZCKQ1 VUlA== X-Gm-Message-State: ACgBeo1lySHwW5OUhtFzUKEe2QAhg5dsflOVPNkZ9LYUutLDoPT34wiG XUjhYMVUwNOOQjPIWt7ZX9WuS8hUb0zQxrNU X-Received: by 2002:a05:600c:3844:b0:3a6:123:5ac5 with SMTP id s4-20020a05600c384400b003a601235ac5mr2793863wmr.102.1663156350871; Wed, 14 Sep 2022 04:52:30 -0700 (PDT) Received: from stoup.. ([89.101.193.70]) by smtp.gmail.com with ESMTPSA id t9-20020a5d6909000000b0022a3a887ceasm13712970wru.49.2022.09.14.04.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 04:52:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Peter Maydell Subject: [PULL 12/20] target/arm: Ignore PMCR.D when PMCR.LC is set Date: Wed, 14 Sep 2022 12:52:09 +0100 Message-Id: <20220914115217.117532-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220914115217.117532-1-richard.henderson@linaro.org> References: <20220914115217.117532-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x330.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" From: Peter Maydell The architecture requires that if PMCR.LC is set (for a 64-bit cycle counter) then PMCR.D (which enables the clock divider so the counter ticks every 64 cycles rather than every cycle) should be ignored. We were always honouring PMCR.D; fix the bug so we correctly ignore it in this situation. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-Id: <20220822132358.3524971-5-peter.maydell@linaro.org> Signed-off-by: Richard Henderson --- target/arm/helper.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index a348c7407d..f1b20de16d 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -1172,6 +1172,17 @@ static void pmu_update_irq(CPUARMState *env) (env->cp15.c9_pminten & env->cp15.c9_pmovsr)); } +static bool pmccntr_clockdiv_enabled(CPUARMState *env) +{ + /* + * Return true if the clock divider is enabled and the cycle counter + * is supposed to tick only once every 64 clock cycles. This is + * controlled by PMCR.D, but if PMCR.LC is set to enable the long + * (64-bit) cycle counter PMCR.D has no effect. + */ + return (env->cp15.c9_pmcr & (PMCRD | PMCRLC)) == PMCRD; +} + /* * Ensure c15_ccnt is the guest-visible count so that operations such as * enabling/disabling the counter or filtering, modifying the count itself, @@ -1184,8 +1195,7 @@ static void pmccntr_op_start(CPUARMState *env) if (pmu_counter_enabled(env, 31)) { uint64_t eff_cycles = cycles; - if (env->cp15.c9_pmcr & PMCRD) { - /* Increment once every 64 processor clock cycles */ + if (pmccntr_clockdiv_enabled(env)) { eff_cycles /= 64; } @@ -1228,8 +1238,7 @@ static void pmccntr_op_finish(CPUARMState *env) #endif uint64_t prev_cycles = env->cp15.c15_ccnt_delta; - if (env->cp15.c9_pmcr & PMCRD) { - /* Increment once every 64 processor clock cycles */ + if (pmccntr_clockdiv_enabled(env)) { prev_cycles /= 64; } env->cp15.c15_ccnt_delta = prev_cycles - env->cp15.c15_ccnt;