From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7B366CD6E55 for ; Mon, 1 Jun 2026 14:19:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CC7051133EC; Mon, 1 Jun 2026 14:19:46 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id 234701133F0 for ; Mon, 1 Jun 2026 14:19:46 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4339D6784A; Mon, 1 Jun 2026 14:19:30 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E6242779A7; Mon, 1 Jun 2026 14:19:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id KCUDN/GUHWpSdwAAD6G6ig (envelope-from ); Mon, 01 Jun 2026 14:19:29 +0000 From: Thomas Zimmermann To: simona@ffwll.ch, michel.daenzer@mailbox.org, louis.chauvet@bootlin.com, ville.syrjala@linux.intel.com, jani.nikula@intel.com, mhklkml@zohomail.com, maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@gmail.com Cc: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, virtualization@lists.linux.dev, Thomas Zimmermann Subject: [PATCH 7/7] drm/vblank: timer: Avoid reading the vblank time unnecessarily Date: Mon, 1 Jun 2026 16:08:35 +0200 Message-ID: <20260601141922.91498-8-tzimmermann@suse.de> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260601141922.91498-1-tzimmermann@suse.de> References: <20260601141922.91498-1-tzimmermann@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: 4339D6784A X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In drm_crtc_vblank_get_vblank_timeout(), there's a loop to read a consistent vblank count and time. Only read the time once per iteration and avoid costly locking and an atomic read. Return an error after 10 retries. This indicates that the vblank counter is broken or being updated way too often. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/drm_vblank.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index 75e2183be0ab..05f28e27cbff 100644 --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -2316,7 +2316,8 @@ bool drm_crtc_vblank_get_vblank_timeout(struct drm_crtc *crtc, ktime_t *vblank_t if (READ_ONCE(vblank->enabled)) { ktime_t cur_time; - u64 cur_count; + u64 lst_count, cur_count; + unsigned int retries = 10; /* * A concurrent vblank timeout could update the expires field before @@ -2324,10 +2325,15 @@ bool drm_crtc_vblank_get_vblank_timeout(struct drm_crtc *crtc, ktime_t *vblank_t * expiry time to the new vblank time; deducing the timer had already * expired. Reread until we get consistent values from both fields. */ + cur_count = drm_crtc_vblank_count(crtc); do { - cur_count = drm_crtc_vblank_count_and_time(crtc, &cur_time); + lst_count = cur_count; *vblank_time = READ_ONCE(vtimer->timer.node.expires); - } while (cur_count != drm_crtc_vblank_count_and_time(crtc, &cur_time)); + cur_count = drm_crtc_vblank_count_and_time(crtc, &cur_time); + } while (cur_count != lst_count && retries--); + + if (drm_WARN_ON(dev, cur_count != lst_count)) + return false; /* broken vblank counter */ if (drm_WARN_ON(dev, !ktime_after(*vblank_time, cur_time))) return false; /* already expired */ -- 2.54.0