From patchwork Tue Dec 23 12:35:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paulo Zanoni X-Patchwork-Id: 5533151 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B07069F2F7 for ; Tue, 23 Dec 2014 12:36:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B1BA5201BB for ; Tue, 23 Dec 2014 12:36:51 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id A11C72011D for ; Tue, 23 Dec 2014 12:36:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3136B6E49C; Tue, 23 Dec 2014 04:36:50 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by gabe.freedesktop.org (Postfix) with ESMTP id 2CBC96E49C for ; Tue, 23 Dec 2014 04:36:45 -0800 (PST) Received: by mail-vc0-f177.google.com with SMTP id ij19so2277205vcb.36 for ; Tue, 23 Dec 2014 04:36:44 -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=gckz9up6clnZeyPX2WGd2QUUAroJvTg9Dd8PH+/SqrY=; b=cjGiw4+pdqQm1gdhY4Ghm1TqSRP8EWF6137Qsi3OGoKFuokz/xZaHdsxdPfVZYOVoD eq9XZOgETdpYzIDOzaOp7Gg93hpPmzOAD4WiF9tGmDGMjxlGEXntBzcpEM8Z91UI/3NW MqOa6viZ5iYDUrCPAu7m2/K1EoV4GDj5nvQQh0s/d0H3Blh/8+mVzpzNQE034gQMV2Cv X3uYsxYcKpZPglOyZKLKh1xoGr5lxljk/v0y12AecmFkaBWTqBBTs4nS+BKfd+WhHn82 1A7ymiPwa2I35KQPHBxPvZ1dROO+g7wtXYAMmTFnvq4eAmAps1q5MCHqt1halTYEtNzY 1+1Q== X-Received: by 10.52.75.202 with SMTP id e10mr8391695vdw.73.1419338204862; Tue, 23 Dec 2014 04:36:44 -0800 (PST) Received: from localhost.localdomain ([177.92.19.202]) by mx.google.com with ESMTPSA id at12sm4915045vdc.15.2014.12.23.04.36.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Dec 2014 04:36:44 -0800 (PST) From: Paulo Zanoni To: intel-gfx@lists.freedesktop.org Date: Tue, 23 Dec 2014 10:35:43 -0200 Message-Id: <1419338145-1912-8-git-send-email-przanoni@gmail.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1419338145-1912-1-git-send-email-przanoni@gmail.com> References: <1419338145-1912-1-git-send-email-przanoni@gmail.com> Cc: Paulo Zanoni Subject: [Intel-gfx] [PATCH 7/9] drm/i915: don't alloc/free fbc_work at every update X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 Because there's no need for it. Just use a static structure with a bool field to tell if it's in use or not. The big advantage here is not saving kzalloc/kfree calls, it's cutting the ugly "failed to allocate FBC work structure" code path: in this path we call enable_fbc() directly but we don't update fbc.crtc, fbc.fb_id and fbc.y - they are updated in intel_fbc_work_fn(), which we're not calling. And since testing out-of-memory cases like this is really hard, getting rid of the code path is a major relief. Signed-off-by: Paulo Zanoni --- drivers/gpu/drm/i915/i915_drv.h | 3 ++- drivers/gpu/drm/i915/intel_fbc.c | 41 +++++++++++++++------------------------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 18fcce4..40bc864 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -751,10 +751,11 @@ struct i915_fbc { bool enabled; struct intel_fbc_work { + bool scheduled; struct delayed_work work; struct drm_crtc *crtc; struct drm_framebuffer *fb; - } *fbc_work; + } work; enum no_fbc_reason { FBC_OK, /* FBC is enabled */ diff --git a/drivers/gpu/drm/i915/intel_fbc.c b/drivers/gpu/drm/i915/intel_fbc.c index 6611266..80bdbde 100644 --- a/drivers/gpu/drm/i915/intel_fbc.c +++ b/drivers/gpu/drm/i915/intel_fbc.c @@ -336,7 +336,7 @@ static void intel_fbc_work_fn(struct work_struct *__work) mutex_lock(&dev->struct_mutex); mutex_lock(&dev_priv->fbc.lock); - if (work == dev_priv->fbc.fbc_work) { + if (dev_priv->fbc.work.scheduled) { /* Double check that we haven't switched fb without cancelling * the prior work. */ @@ -348,42 +348,37 @@ static void intel_fbc_work_fn(struct work_struct *__work) dev_priv->fbc.y = work->crtc->y; } - dev_priv->fbc.fbc_work = NULL; + dev_priv->fbc.work.scheduled = false; } mutex_unlock(&dev_priv->fbc.lock); mutex_unlock(&dev->struct_mutex); - - kfree(work); } static void intel_fbc_cancel_work(struct drm_i915_private *dev_priv) { lockdep_assert_held(&dev_priv->fbc.lock); - if (dev_priv->fbc.fbc_work == NULL) + if (!dev_priv->fbc.work.scheduled) return; DRM_DEBUG_KMS("cancelling pending FBC enable\n"); - /* Synchronisation is provided by struct_mutex and checking of - * dev_priv->fbc.fbc_work, so we can perform the cancellation + /* Synchronisation is provided by fbc.lock and checking of + * dev_priv->fbc.work.scheduled, so we can perform the cancellation * entirely asynchronously. */ - if (cancel_delayed_work(&dev_priv->fbc.fbc_work->work)) - /* tasklet was killed before being run, clean up */ - kfree(dev_priv->fbc.fbc_work); + cancel_delayed_work(&dev_priv->fbc.work.work); /* Mark the work as no longer wanted so that if it does * wake-up (because the work was already running and waiting * for our mutex), it will discover that is no longer * necessary to run. */ - dev_priv->fbc.fbc_work = NULL; + dev_priv->fbc.work.scheduled = false; } static void intel_fbc_enable(struct drm_crtc *crtc) { - struct intel_fbc_work *work; struct drm_device *dev = crtc->dev; struct drm_i915_private *dev_priv = dev->dev_private; @@ -394,18 +389,10 @@ static void intel_fbc_enable(struct drm_crtc *crtc) intel_fbc_cancel_work(dev_priv); - work = kzalloc(sizeof(*work), GFP_KERNEL); - if (work == NULL) { - DRM_ERROR("Failed to allocate FBC work structure\n"); - dev_priv->display.enable_fbc(crtc); - return; - } + dev_priv->fbc.work.crtc = crtc; + dev_priv->fbc.work.fb = crtc->primary->fb; - work->crtc = crtc; - work->fb = crtc->primary->fb; - INIT_DELAYED_WORK(&work->work, intel_fbc_work_fn); - - dev_priv->fbc.fbc_work = work; + dev_priv->fbc.work.scheduled = true; /* Delay the actual enabling to let pageflipping cease and the * display to settle before starting the compression. Note that @@ -420,7 +407,7 @@ static void intel_fbc_enable(struct drm_crtc *crtc) * * WaFbcWaitForVBlankBeforeEnable:ilk,snb */ - schedule_delayed_work(&work->work, msecs_to_jiffies(50)); + schedule_delayed_work(&dev_priv->fbc.work.work, msecs_to_jiffies(50)); } static void __intel_fbc_disable(struct drm_device *dev) @@ -702,9 +689,9 @@ void intel_fbc_invalidate(struct drm_i915_private *dev_priv, if (dev_priv->fbc.enabled) fbc_bits = INTEL_FRONTBUFFER_PRIMARY(dev_priv->fbc.crtc->pipe); - else if (dev_priv->fbc.fbc_work) + else if (dev_priv->fbc.work.scheduled) fbc_bits = INTEL_FRONTBUFFER_PRIMARY( - to_intel_crtc(dev_priv->fbc.fbc_work->crtc)->pipe); + to_intel_crtc(dev_priv->fbc.work.crtc)->pipe); else fbc_bits = dev_priv->fbc.possible_framebuffer_bits; @@ -773,6 +760,8 @@ void intel_fbc_init(struct drm_i915_private *dev_priv) return; } + INIT_DELAYED_WORK(&dev_priv->fbc.work.work, intel_fbc_work_fn); + for_each_pipe(dev_priv, pipe) { dev_priv->fbc.possible_framebuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(pipe);