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 4/6] drm/bochs: Use vblank timer
Date: Thu,  5 Jun 2025 17:24:42 +0200	[thread overview]
Message-ID: <20250605152637.98493-5-tzimmermann@suse.de> (raw)
In-Reply-To: <20250605152637.98493-1-tzimmermann@suse.de>

Bochs' 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/tiny/bochs.c | 68 ++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/drivers/gpu/drm/tiny/bochs.c b/drivers/gpu/drm/tiny/bochs.c
index 8706763af8fb..dbc6a15c1a58 100644
--- a/drivers/gpu/drm/tiny/bochs.c
+++ b/drivers/gpu/drm/tiny/bochs.c
@@ -21,6 +21,8 @@
 #include <drm/drm_module.h>
 #include <drm/drm_plane_helper.h>
 #include <drm/drm_probe_helper.h>
+#include <drm/drm_vblank.h>
+#include <drm/drm_vblank_timer.h>
 
 #include <video/vga.h>
 
@@ -95,6 +97,7 @@ struct bochs_device {
 
 	/* drm */
 	struct drm_plane primary_plane;
+	struct drm_vblank_timer vtimer;
 	struct drm_crtc crtc;
 	struct drm_encoder encoder;
 	struct drm_connector connector;
@@ -501,12 +504,35 @@ static int bochs_crtc_helper_atomic_check(struct drm_crtc *crtc,
 	return drm_atomic_helper_check_crtc_primary_plane(crtc_state);
 }
 
+static void bochs_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 bochs_crtc_helper_atomic_enable(struct drm_crtc *crtc,
 					    struct drm_atomic_state *state)
 {
 	struct bochs_device *bochs = to_bochs_device(crtc->dev);
 
 	bochs_hw_blank(bochs, false);
+	drm_crtc_vblank_on(crtc);
 }
 
 static void bochs_crtc_helper_atomic_disable(struct drm_crtc *crtc,
@@ -514,16 +540,44 @@ static void bochs_crtc_helper_atomic_disable(struct drm_crtc *crtc,
 {
 	struct bochs_device *bochs = to_bochs_device(crtc->dev);
 
+	drm_crtc_vblank_off(crtc);
 	bochs_hw_blank(bochs, true);
 }
 
 static const struct drm_crtc_helper_funcs bochs_crtc_helper_funcs = {
 	.mode_set_nofb = bochs_crtc_helper_mode_set_nofb,
 	.atomic_check = bochs_crtc_helper_atomic_check,
+	.atomic_flush = bochs_crtc_helper_atomic_flush,
 	.atomic_enable = bochs_crtc_helper_atomic_enable,
 	.atomic_disable = bochs_crtc_helper_atomic_disable,
 };
 
+static int bochs_crtc_enable_vblank(struct drm_crtc *crtc)
+{
+	struct bochs_device *bochs = to_bochs_device(crtc->dev);
+
+	drm_vblank_timer_start(&bochs->vtimer);
+
+	return 0;
+}
+
+static void bochs_crtc_disable_vblank(struct drm_crtc *crtc)
+{
+	struct bochs_device *bochs = to_bochs_device(crtc->dev);
+
+	drm_vblank_timer_cancel(&bochs->vtimer);
+}
+
+static bool bochs_crtc_get_vblank_timestamp(struct drm_crtc *crtc,
+					    int *max_error, ktime_t *vblank_time,
+					    bool in_vblank_irq)
+{
+	struct bochs_device *bochs = to_bochs_device(crtc->dev);
+
+	return drm_vblank_timer_get_vblank_timestamp(&bochs->vtimer, max_error,
+						     vblank_time, in_vblank_irq);
+}
+
 static const struct drm_crtc_funcs bochs_crtc_funcs = {
 	.reset = drm_atomic_helper_crtc_reset,
 	.destroy = drm_crtc_cleanup,
@@ -531,6 +585,9 @@ static const struct drm_crtc_funcs bochs_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 = bochs_crtc_enable_vblank,
+	.disable_vblank = bochs_crtc_disable_vblank,
+	.get_vblank_timestamp = bochs_crtc_get_vblank_timestamp,
 };
 
 static const struct drm_encoder_funcs bochs_encoder_funcs = {
@@ -602,6 +659,7 @@ static int bochs_kms_init(struct bochs_device *bochs)
 	struct drm_crtc *crtc;
 	struct drm_connector *connector;
 	struct drm_encoder *encoder;
+	struct drm_vblank_timer *vtimer;
 	int ret;
 
 	ret = drmm_mode_config_init(dev);
@@ -651,6 +709,16 @@ static int bochs_kms_init(struct bochs_device *bochs)
 	drm_connector_attach_edid_property(connector);
 	drm_connector_attach_encoder(connector, encoder);
 
+	/* Vertical blanking */
+
+	ret = drm_vblank_init(dev, 1);
+	if (ret)
+		return ret;
+	vtimer = &bochs->vtimer;
+	ret = drmm_vblank_timer_init(vtimer, 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 ` Thomas Zimmermann [this message]
2025-06-05 15:24 ` [PATCH 5/6] drm/hypervdrm: " Thomas Zimmermann
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-5-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