From patchwork Wed Nov 19 19:47:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paulo Zanoni X-Patchwork-Id: 5340711 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C3703C11AC for ; Wed, 19 Nov 2014 19:48:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ABB7C201FB for ; Wed, 19 Nov 2014 19:48:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id E48F52021B for ; Wed, 19 Nov 2014 19:48:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CA34E6F162; Wed, 19 Nov 2014 11:48:27 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qc0-f177.google.com (mail-qc0-f177.google.com [209.85.216.177]) by gabe.freedesktop.org (Postfix) with ESMTP id 91A6D6F161; Wed, 19 Nov 2014 11:48:26 -0800 (PST) Received: by mail-qc0-f177.google.com with SMTP id x3so1000488qcv.8 for ; Wed, 19 Nov 2014 11:48:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/5mDMmvaj1NMS0YKNcpVIWCAJmjzgDmRzK1KIGGmL6c=; b=VqLM0qm2czq37jmAwrwSYqgVtgFvhr5KWDm6a82zqn2O89pQQp7AQ028cE5ZmYt9zE QJ85KxVBW/Vx038w9Sj4uXHnxJ+BOWDCFeSCTiBpP0gEonJEzoAuPDU6/HPh08UHE4El wAP6DTtWexgnY+GIXxs0/xTxuWhlTPy4zLc+xdQyAfpYIxVaxdEQxLD/W8WBQr3iT55d TIPOZ2kUf90xMoOoNzIPQg+G8/nsFuWFh8Lyn0DNhxbR83phazxSfoDe2UbTYk2KJSL0 LfTwSN38bB5NIr+H/ky/KIVyKAIEmGYNDHtnECHoAu5q7Tf2LDksYL+MCfmKWUbJdkWa jacQ== X-Received: by 10.140.51.99 with SMTP id t90mr53947305qga.72.1416426506078; Wed, 19 Nov 2014 11:48:26 -0800 (PST) Received: from localhost.localdomain ([177.96.119.122]) by mx.google.com with ESMTPSA id b60sm168806qge.22.2014.11.19.11.48.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Nov 2014 11:48:25 -0800 (PST) From: Paulo Zanoni To: dri-devel@lists.freedesktop.org Subject: [RFC 2/7] drm: allow drm_wait_vblank_kernel() callback from workqueues Date: Wed, 19 Nov 2014 17:47:10 -0200 Message-Id: <1416426435-2237-4-git-send-email-przanoni@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1416426435-2237-1-git-send-email-przanoni@gmail.com> References: <1416426435-2237-1-git-send-email-przanoni@gmail.com> Cc: intel-gfx@lists.freedesktop.org, Paulo Zanoni X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Paulo Zanoni This is going to be needed by i915.ko, and I guess other drivers could use it too. Signed-off-by: Paulo Zanoni --- drivers/gpu/drm/drm_irq.c | 46 ++++++++++++++++++++++++++++++++----- drivers/gpu/drm/i915/i915_debugfs.c | 45 ++++++++++++++++++++++++++++-------- include/drm/drmP.h | 11 ++++++++- 3 files changed, 86 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c index f031f77..099aef1 100644 --- a/drivers/gpu/drm/drm_irq.c +++ b/drivers/gpu/drm/drm_irq.c @@ -1108,6 +1108,22 @@ void drm_crtc_wait_one_vblank(struct drm_crtc *crtc) } EXPORT_SYMBOL(drm_crtc_wait_one_vblank); +static void drm_wait_vblank_callback(struct drm_device *dev, + struct drm_pending_vblank_event *e, + unsigned long seq, struct timeval *now, + bool premature) +{ + if (e->callback_from_work) { + e->callback_args.dev = dev; + e->callback_args.seq = seq; + e->callback_args.now = now; + e->callback_args.premature = premature; + schedule_work(&e->callback_work); + } else { + e->callback(dev, e, seq, now, premature); + } +} + /** * drm_vblank_off - disable vblank events on a CRTC * @dev: DRM device @@ -1160,7 +1176,7 @@ void drm_vblank_off(struct drm_device *dev, int crtc) e->event.sequence, seq); list_del(&e->base.link); drm_vblank_put(dev, e->pipe); - e->callback(dev, e, seq, &now, true); + drm_wait_vblank_callback(dev, e, seq, &now, true); } spin_unlock_irqrestore(&dev->event_lock, irqflags); } @@ -1372,9 +1388,20 @@ int drm_modeset_ctl(struct drm_device *dev, void *data, return 0; } +static void drm_vblank_event_work_func(struct work_struct *work) +{ + struct drm_pending_vblank_event *e = + container_of(work, struct drm_pending_vblank_event, + callback_work); + + e->callback(e->callback_args.dev, e, e->callback_args.seq, + e->callback_args.now, e->callback_args.premature); +} + static int drm_queue_vblank_event(struct drm_device *dev, int pipe, union drm_wait_vblank *vblwait, struct drm_file *file_priv, + bool callback_from_work, drm_vblank_callback_t callback) { struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; @@ -1399,6 +1426,9 @@ static int drm_queue_vblank_event(struct drm_device *dev, int pipe, e->base.file_priv = file_priv; e->base.destroy = (void (*) (struct drm_pending_event *)) kfree; e->callback = callback; + e->callback_from_work = callback_from_work; + if (callback_from_work) + INIT_WORK(&e->callback_work, drm_vblank_event_work_func); spin_lock_irqsave(&dev->event_lock, flags); @@ -1440,7 +1470,7 @@ static int drm_queue_vblank_event(struct drm_device *dev, int pipe, e->event.sequence = vblwait->request.sequence; if ((seq - vblwait->request.sequence) <= (1 << 23)) { drm_vblank_put(dev, pipe); - e->callback(dev, e, seq, &now, false); + drm_wait_vblank_callback(dev, e, seq, &now, false); vblwait->reply.sequence = seq; } else { /* drm_handle_vblank_events will call drm_vblank_put */ @@ -1477,6 +1507,7 @@ err_put: static int __drm_wait_vblank(struct drm_device *dev, union drm_wait_vblank *vblwait, struct drm_file *file_priv, + bool callback_from_work, drm_vblank_callback_t callback) { struct drm_vblank_crtc *vblank; @@ -1533,7 +1564,7 @@ static int __drm_wait_vblank(struct drm_device *dev, * drm_vblank_put will be called asynchronously */ return drm_queue_vblank_event(dev, crtc, vblwait, file_priv, - callback); + callback_from_work, callback); } if ((flags & _DRM_VBLANK_NEXTONMISS) && @@ -1573,10 +1604,12 @@ int drm_wait_vblank_ioctl(struct drm_device *dev, void *data, { union drm_wait_vblank *vblwait = data; - return __drm_wait_vblank(dev, vblwait, file_priv, send_vblank_event); + return __drm_wait_vblank(dev, vblwait, file_priv, false, + send_vblank_event); } int drm_wait_vblank_kernel(struct drm_crtc *crtc, int count, bool absolute, + bool callback_from_work, drm_vblank_callback_t callback, unsigned long user_data) { @@ -1593,7 +1626,8 @@ int drm_wait_vblank_kernel(struct drm_crtc *crtc, int count, bool absolute, vblwait.request.sequence = count; vblwait.request.signal = user_data; - return __drm_wait_vblank(dev, &vblwait, NULL, callback); + return __drm_wait_vblank(dev, &vblwait, NULL, callback_from_work, + callback); } EXPORT_SYMBOL(drm_wait_vblank_kernel); @@ -1618,7 +1652,7 @@ static void drm_handle_vblank_events(struct drm_device *dev, int crtc) list_del(&e->base.link); drm_vblank_put(dev, e->pipe); - e->callback(dev, e, seq, &now, false); + drm_wait_vblank_callback(dev, e, seq, &now, false); } trace_drm_vblank_event(crtc, seq); diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c index f989587..95cf6d3 100644 --- a/drivers/gpu/drm/i915/i915_debugfs.c +++ b/drivers/gpu/drm/i915/i915_debugfs.c @@ -2718,6 +2718,7 @@ static int i915_ddb_info(struct seq_file *m, void *unused) struct vblank_data { int eight; const char *message; + bool can_sleep; }; static void vblank_callback(struct drm_device *dev, @@ -2727,6 +2728,7 @@ static void vblank_callback(struct drm_device *dev, { struct vblank_data *data = (struct vblank_data *)e->event.user_data; + WARN_ON(data->can_sleep != drm_can_sleep()); WARN_ON(data->eight != 8); DRM_DEBUG_KMS("vblank callback, seq: %lu, premature: %s message:%s\n", seq, yesno(premature), data->message); @@ -2741,7 +2743,7 @@ static int i915_vblank_queue_test_new(struct seq_file *m, void *unused) struct drm_device *dev = node->minor->dev; struct intel_crtc *crtc = NULL; int ret = 0; - struct vblank_data *data; + struct vblank_data *data1, *data2; for_each_intel_crtc(dev, crtc) if (crtc->pipe == PIPE_A) @@ -2749,26 +2751,51 @@ static int i915_vblank_queue_test_new(struct seq_file *m, void *unused) if (WARN_ON(!crtc)) return -EINVAL; - data = kzalloc(sizeof *data, GFP_KERNEL); - if (!data) + data1 = kzalloc(sizeof *data1, GFP_KERNEL); + if (!data1) return -ENOMEM; - data->message = "hello world"; - data->eight = 8; + data1->message = "hello world (atomic)"; + data1->eight = 8; + data1->can_sleep = false; + + data2 = kzalloc(sizeof *data2, GFP_KERNEL); + if (!data2) { + kfree(data1); + return -ENOMEM; + } + + data2->message = "hello world (from work)"; + data2->eight = 8; + data2->can_sleep = true; DRM_DEBUG_KMS("waiting 60 vblanks (no callback)\n"); - ret = drm_wait_vblank_kernel(&crtc->base, 60, false, NULL, 0); + ret = drm_wait_vblank_kernel(&crtc->base, 60, false, false, NULL, 0); if (ret) { DRM_DEBUG_KMS("vblank wait error: %d\n", ret); + kfree(data1); + kfree(data2); return ret; } DRM_DEBUG_KMS("vblank wait done\n"); - DRM_DEBUG_KMS("scheduling 60 vblanks (with callback)\n"); - ret = drm_wait_vblank_kernel(&crtc->base, 60, false, vblank_callback, - (unsigned long) data); + DRM_DEBUG_KMS("scheduling 60 vblanks (with callback, can't sleep)\n"); + ret = drm_wait_vblank_kernel(&crtc->base, 60, false, false, + vblank_callback, (unsigned long) data1); + if (ret) { + DRM_DEBUG_KMS("vblank schedule error: %d\n", ret); + kfree(data1); + kfree(data2); + return ret; + } + DRM_DEBUG_KMS("vblanks scheduled\n"); + + DRM_DEBUG_KMS("scheduling 60 vblanks (with callback, can sleep)\n"); + ret = drm_wait_vblank_kernel(&crtc->base, 60, false, true, + vblank_callback, (unsigned long) data2); if (ret) { DRM_DEBUG_KMS("vblank schedule error: %d\n", ret); + kfree(data2); return ret; } DRM_DEBUG_KMS("vblanks scheduled\n"); diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 39d0d87..bc114f0 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -669,7 +669,16 @@ struct drm_pending_vblank_event { struct drm_pending_event base; int pipe; struct drm_event_vblank event; + drm_vblank_callback_t callback; + bool callback_from_work; + struct work_struct callback_work; + struct { + struct drm_device *dev; + unsigned long seq; + struct timeval *now; + bool premature; + } callback_args; }; struct drm_vblank_crtc { @@ -906,7 +915,7 @@ extern int drm_vblank_init(struct drm_device *dev, int num_crtcs); extern int drm_wait_vblank_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); extern int drm_wait_vblank_kernel(struct drm_crtc *crtc, int count, - bool absolute, + bool absolute, bool callback_from_work, drm_vblank_callback_t callback, unsigned long user_data); extern u32 drm_vblank_count(struct drm_device *dev, int crtc);