Linux-HyperV List
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: mhklinux@outlook.com, maarten.lankhorst@linux.intel.com,
	mripard@kernel.org, airlied@gmail.com, simona@ffwll.ch,
	drawat.floss@gmail.com, javierm@redhat.com, kraxel@redhat.com,
	louis.chauvet@bootlin.com, hamohammed.sa@gmail.com,
	melissa.srw@gmail.com, fvogt@suse.com
Cc: dri-devel@lists.freedesktop.org, linux-hyperv@vger.kernel.org,
	virtualization@lists.linux.dev,
	Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 5/6] drm/hypervdrm: Use vblank timer
Date: Thu,  5 Jun 2025 17:24:43 +0200	[thread overview]
Message-ID: <20250605152637.98493-6-tzimmermann@suse.de> (raw)
In-Reply-To: <20250605152637.98493-1-tzimmermann@suse.de>

HyperV's virtual hardware does not provide vblank interrupts. Use a
vblank timer to simulate the interrupt in software. Rate-limits the
display's update frequency to the display-mode settings. Avoids
excessive CPU overhead with compositors that do not rate-limit their
output.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/hyperv/hyperv_drm.h         |  4 ++
 drivers/gpu/drm/hyperv/hyperv_drm_modeset.c | 70 +++++++++++++++++++++
 2 files changed, 74 insertions(+)

diff --git a/drivers/gpu/drm/hyperv/hyperv_drm.h b/drivers/gpu/drm/hyperv/hyperv_drm.h
index 9e776112c03e..730e4a37545d 100644
--- a/drivers/gpu/drm/hyperv/hyperv_drm.h
+++ b/drivers/gpu/drm/hyperv/hyperv_drm.h
@@ -6,12 +6,16 @@
 #ifndef _HYPERV_DRM_H_
 #define _HYPERV_DRM_H_
 
+#include <drm/drm_vblank.h>
+#include <drm/drm_vblank_timer.h>
+
 #define VMBUS_MAX_PACKET_SIZE 0x4000
 
 struct hyperv_drm_device {
 	/* drm */
 	struct drm_device dev;
 	struct drm_plane plane;
+	struct drm_vblank_timer vtimer;
 	struct drm_crtc crtc;
 	struct drm_encoder encoder;
 	struct drm_connector connector;
diff --git a/drivers/gpu/drm/hyperv/hyperv_drm_modeset.c b/drivers/gpu/drm/hyperv/hyperv_drm_modeset.c
index f7d2e973f79e..ed19e471b96f 100644
--- a/drivers/gpu/drm/hyperv/hyperv_drm_modeset.c
+++ b/drivers/gpu/drm/hyperv/hyperv_drm_modeset.c
@@ -97,6 +97,28 @@ static const uint64_t hyperv_modifiers[] = {
 	DRM_FORMAT_MOD_INVALID
 };
 
+static void hyperv_crtc_helper_atomic_flush(struct drm_crtc *crtc,
+					    struct drm_atomic_state *state)
+{
+	struct drm_device *dev = crtc->dev;
+	struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
+	struct drm_pending_vblank_event *event;
+
+	spin_lock_irq(&dev->event_lock);
+
+	event = crtc_state->event;
+	crtc_state->event = NULL;
+
+	if (event) {
+		if (drm_crtc_vblank_get(crtc) == 0)
+			drm_crtc_arm_vblank_event(crtc, event);
+		else
+			drm_crtc_send_vblank_event(crtc, event);
+	}
+
+	spin_unlock_irq(&dev->event_lock);
+}
+
 static void hyperv_crtc_helper_atomic_enable(struct drm_crtc *crtc,
 					     struct drm_atomic_state *state)
 {
@@ -110,13 +132,49 @@ static void hyperv_crtc_helper_atomic_enable(struct drm_crtc *crtc,
 				crtc_state->mode.hdisplay,
 				crtc_state->mode.vdisplay,
 				plane_state->fb->pitches[0]);
+
+	drm_crtc_vblank_on(crtc);
+}
+
+static void hyperv_crtc_helper_atomic_disable(struct drm_crtc *crtc,
+					      struct drm_atomic_state *crtc_state)
+{
+	drm_crtc_vblank_off(crtc);
 }
 
 static const struct drm_crtc_helper_funcs hyperv_crtc_helper_funcs = {
 	.atomic_check = drm_crtc_helper_atomic_check,
+	.atomic_flush = hyperv_crtc_helper_atomic_flush,
 	.atomic_enable = hyperv_crtc_helper_atomic_enable,
+	.atomic_disable = hyperv_crtc_helper_atomic_disable,
 };
 
+static int hyperv_crtc_enable_vblank(struct drm_crtc *crtc)
+{
+	struct hyperv_drm_device *hv = to_hv(crtc->dev);
+
+	drm_vblank_timer_start(&hv->vtimer);
+
+	return 0;
+}
+
+static void hyperv_crtc_disable_vblank(struct drm_crtc *crtc)
+{
+	struct hyperv_drm_device *hv = to_hv(crtc->dev);
+
+	drm_vblank_timer_cancel(&hv->vtimer);
+}
+
+static bool hyperv_crtc_get_vblank_timestamp(struct drm_crtc *crtc,
+					     int *max_error, ktime_t *vblank_time,
+					     bool in_vblank_irq)
+{
+	struct hyperv_drm_device *hv = to_hv(crtc->dev);
+
+	return drm_vblank_timer_get_vblank_timestamp(&hv->vtimer, max_error,
+						     vblank_time, in_vblank_irq);
+}
+
 static const struct drm_crtc_funcs hyperv_crtc_funcs = {
 	.reset = drm_atomic_helper_crtc_reset,
 	.destroy = drm_crtc_cleanup,
@@ -124,6 +182,9 @@ static const struct drm_crtc_funcs hyperv_crtc_funcs = {
 	.page_flip = drm_atomic_helper_page_flip,
 	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
 	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
+	.enable_vblank = hyperv_crtc_enable_vblank,
+	.disable_vblank = hyperv_crtc_disable_vblank,
+	.get_vblank_timestamp = hyperv_crtc_get_vblank_timestamp,
 };
 
 static int hyperv_plane_atomic_check(struct drm_plane *plane,
@@ -285,6 +346,15 @@ int hyperv_mode_config_init(struct hyperv_drm_device *hv)
 		return ret;
 	}
 
+	/* Vertical blanking */
+
+	ret = drm_vblank_init(dev, 1);
+	if (ret)
+		return ret;
+	ret = drmm_vblank_timer_init(&hv->vtimer, &hv->crtc, NULL);
+	if (ret)
+		return ret;
+
 	drm_mode_config_reset(dev);
 
 	return 0;
-- 
2.49.0


  parent reply	other threads:[~2025-06-05 15:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-05 15:24 [RFC PATCH 0/6] drm: Add vblank timers for devices without interrupts Thomas Zimmermann
2025-06-05 15:24 ` [PATCH 1/6] drm/vblank: Add vblank timer Thomas Zimmermann
2025-06-06  8:43   ` Louis Chauvet
2025-06-10 15:36     ` Thomas Zimmermann
2025-06-05 15:24 ` [PATCH 2/6] drm/vkms: Use " Thomas Zimmermann
2025-06-06  9:14   ` Louis Chauvet
2025-06-05 15:24 ` [PATCH 3/6] drm/simpledrm: " Thomas Zimmermann
2025-06-05 15:24 ` [PATCH 4/6] drm/bochs: " Thomas Zimmermann
2025-06-05 15:24 ` Thomas Zimmermann [this message]
2025-06-05 15:24 ` [PATCH 6/6] drm/fb-helper: Synchronize dirty worker with vblank Thomas Zimmermann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250605152637.98493-6-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@gmail.com \
    --cc=drawat.floss@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=fvogt@suse.com \
    --cc=hamohammed.sa@gmail.com \
    --cc=javierm@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=louis.chauvet@bootlin.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=melissa.srw@gmail.com \
    --cc=mhklinux@outlook.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=virtualization@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox