From patchwork Fri Aug 9 18:08:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 818124 Delivered-To: patch@linaro.org Received: by 2002:a5d:5711:0:b0:367:895a:4699 with SMTP id a17csp421212wrv; Fri, 9 Aug 2024 11:10:39 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWaDt8uwsYsOJOt85wmZSYl/al+HHNIGujTmy7zRJrruL3FGFI5ty7d3Dd/C4s354S05/Z0ihYqT1JM9L5vOt9w X-Google-Smtp-Source: AGHT+IEXaITHq8rOKNYbrb/X4Dqs1InZxB0CTj31Cy2p5nUUr7S3OHTGKuOTAIky1DQyIOFrUf+g X-Received: by 2002:a05:622a:5905:b0:447:f41a:aac0 with SMTP id d75a77b69052e-453125c27d0mr27704691cf.35.1723227039242; Fri, 09 Aug 2024 11:10:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723227039; cv=none; d=google.com; s=arc-20160816; b=dfcVG7EvpL7A1qAAQnUbnVYuSAAac9RyVuiUssUa3SGNxAEm3sPcDEsXJ0vWBAlKR+ qTR3JBExCeE8JpFXo95Plyq00cr6KL2aNwvT0W4eyOCrrEPNNNicyYC+eNiRQTehdImk yIEfdlXBLUHoMWxkF4Ft9suTaxlWTa0XY6WOAog2/CFyX9CQ1Cy8e9X3Ps811GWm1lyS xshg72DOiqfhvl5hTtuPRSa14svNvTKKJMBPMIBjVrBJa5pJuurXzgIh/fnkdLdmqMxV /r7Vdxcbg206p633YqMz8eKeYYaEa+ocgay8JKTjvuwuSB83GxE+aT72hZRGyUapDVCg zD7w== 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:to:from :dkim-signature; bh=jquWz0USW85lcynOd+V15nNwRrJbu/joQPKxFZlMmk0=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=Z30efNipkaQ16oUZ7qXXh6GlYx6SJVxRU04+oyFjHAY3ZNUzWl5l2Tl+GW2mOWYIda TzkBhu7kDhFQvo4CAp/nBAGXtrcxUNrwLPlX5iJn2v5rKMx8AMmg/yFEymLp320W/UD9 nFEMPWWBn1nHCtMhf4yltAGnGLBT49bLBR7blIPEQPrBDSZLe0IJ83XZD7ZRBfFgRmki mLlakl4u1oXGJWt6cpzjtcrQJyWAQC1+8FjNArOreCYBBavwoHdUMYRq88h97R5hm4gn QJBzCwiH/mAslJl8ac6zSpWkyJh6lueK+pCTdpiatmxE10hCkZUTvgK2Uww4FJGQz1Jl U56A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WQIwxzah; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4531c2692e8si383441cf.367.2024.08.09.11.10.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 09 Aug 2024 11:10:39 -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=WQIwxzah; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1scU3B-0002eQ-2z; Fri, 09 Aug 2024 14:09:17 -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 1scU38-0002cI-1l for qemu-devel@nongnu.org; Fri, 09 Aug 2024 14:09:14 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1scU35-0007Ew-JF for qemu-devel@nongnu.org; Fri, 09 Aug 2024 14:09:13 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-369c609d0c7so1775434f8f.3 for ; Fri, 09 Aug 2024 11:09:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723226950; x=1723831750; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=jquWz0USW85lcynOd+V15nNwRrJbu/joQPKxFZlMmk0=; b=WQIwxzahEbk5TtQe53/t2dj3VLdxR0tAvSKmHpGENWXu6Zi9vzuJUK19TWaPoHofm+ +rMzQXccEV8GbxabRLcXLT25R1Tk+BDbtDnU4ivxpMIE3SsRlxasWaDRQy1T7cVsmVdv 2TzRIawn5y5/vejNvaiT5d7FZ0Pesw0FyFs8LzcD+pyRflXWITXmKQJaXI8I4AAxdi/W 4FnKXy9K/nAGMx9NKhuintoOTaMxA4SEuns51eHJe+Akr7CR4vzBnvRr6G2311N13Zxu RXbKi7Z3I2n/JjEmbdxMJHy2oZEz5Omyq+5tAGjkbZ0nLaGCmwtsPyRKVvpgm2HGQXfj CE7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723226950; x=1723831750; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jquWz0USW85lcynOd+V15nNwRrJbu/joQPKxFZlMmk0=; b=kzvhkgAR1IErBFTopVqPTV9t9QtfwCULxok4FvxayofYPHJr6rMVFgkOvlSd26cEeq Wf0+QXecC4QueAY49ZGP3QKNmkEockEs6HN1j1oYDBy6BC5wAR2jP1taEffCdDXTa+eh EJtUbAEy3lrB3y4wGhP2jkA9zHBrZgDv0TjS3Z1gh+atF9FLHDc5brJ5SMrsMh/bwUOS o1ilQCFYebGhIgs4rWW7ciNHbattY5knUGKwmOA5xyegRtb1o8UrZ3VcGj0Kdz2ve0Gi +6fHCwz/v+m/cZhls3LgUS3lVlHtDC9bhIt+qWgD8VaeosSHKehd/8neCd/c//7CNx1A stXQ== X-Gm-Message-State: AOJu0YxgGtibGNK3ZXi1V585RjaQJpoGifxEXES0AepsBYHoDGe02GtA G+hQLPERZEBs+UKQuYuUrMOnDWYUzL/cYzBCsU6UzM/ZJU1JMVTOxaq4mIozDgHuSkihqumyl/d i X-Received: by 2002:adf:ee50:0:b0:368:6596:edba with SMTP id ffacd0b85a97d-36d5fd7e9b0mr1986551f8f.39.1723226949954; Fri, 09 Aug 2024 11:09:09 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36e4c937b6esm132262f8f.32.2024.08.09.11.09.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Aug 2024 11:09:00 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 10/11] hw/core/ptimer: fix timer zero period condition for freq > 1GHz Date: Fri, 9 Aug 2024 19:08:34 +0100 Message-Id: <20240809180835.1243269-11-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240809180835.1243269-1-peter.maydell@linaro.org> References: <20240809180835.1243269-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x436.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Jianzhou Yue The real period is zero when both period and period_frac are zero. Check the method ptimer_set_freq, if freq is larger than 1000 MHz, the period is zero, but the period_frac is not, in this case, the ptimer will work but the current code incorrectly recognizes that the ptimer is disabled. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2306 Signed-off-by: JianZhou Yue Message-id: 3DA024AEA8B57545AF1B3CAA37077D0FB75E82C8@SHASXM03.verisilicon.com Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/core/ptimer.c | 4 ++-- tests/unit/ptimer-test.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c index b1517592c6b..1d8964d8044 100644 --- a/hw/core/ptimer.c +++ b/hw/core/ptimer.c @@ -83,7 +83,7 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust) delta = s->delta = s->limit; } - if (s->period == 0) { + if (s->period == 0 && s->period_frac == 0) { if (!qtest_enabled()) { fprintf(stderr, "Timer with period zero, disabling\n"); } @@ -309,7 +309,7 @@ void ptimer_run(ptimer_state *s, int oneshot) assert(s->in_transaction); - if (was_disabled && s->period == 0) { + if (was_disabled && s->period == 0 && s->period_frac == 0) { if (!qtest_enabled()) { fprintf(stderr, "Timer with period zero, disabling\n"); } diff --git a/tests/unit/ptimer-test.c b/tests/unit/ptimer-test.c index 04b5f4e3d03..08240594bbd 100644 --- a/tests/unit/ptimer-test.c +++ b/tests/unit/ptimer-test.c @@ -763,6 +763,33 @@ static void check_oneshot_with_load_0(gconstpointer arg) ptimer_free(ptimer); } +static void check_freq_more_than_1000M(gconstpointer arg) +{ + const uint8_t *policy = arg; + ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy); + bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN); + + triggered = false; + + ptimer_transaction_begin(ptimer); + ptimer_set_freq(ptimer, 2000000000); + ptimer_set_limit(ptimer, 8, 1); + ptimer_run(ptimer, 1); + ptimer_transaction_commit(ptimer); + + qemu_clock_step(3); + + g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 3 : 2); + g_assert_false(triggered); + + qemu_clock_step(1); + + g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0); + g_assert_true(triggered); + + ptimer_free(ptimer); +} + static void add_ptimer_tests(uint8_t policy) { char policy_name[256] = ""; @@ -857,6 +884,12 @@ static void add_ptimer_tests(uint8_t policy) policy_name), g_memdup2(&policy, 1), check_oneshot_with_load_0, g_free); g_free(tmp); + + g_test_add_data_func_full( + tmp = g_strdup_printf("/ptimer/freq_more_than_1000M policy=%s", + policy_name), + g_memdup2(&policy, 1), check_freq_more_than_1000M, g_free); + g_free(tmp); } static void add_all_ptimer_policies_comb_tests(void)