From patchwork Thu May 26 09:34:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9136857 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 693DD6075C for ; Thu, 26 May 2016 09:35:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58C8120499 for ; Thu, 26 May 2016 09:35:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D860280B2; Thu, 26 May 2016 09:35:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D5DD282E8 for ; Thu, 26 May 2016 09:35:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 75B5E6EA6B; Thu, 26 May 2016 09:35:07 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id AB7E36EA6C; Thu, 26 May 2016 09:35:05 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id q62so3502919wmg.3; Thu, 26 May 2016 02:35:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=uceY5iI4QTwqG26kcjLLhyrAGnYYg+VTh6IKMSkTwNQ=; b=k1K0f3MyYmqVHK7X2mBnQl6haNru6vTdm6WTeBS4hAMhj9pvy2K3DNwgxzbALZdWGv pPgfGTeLqk3Jdcm0zwDVhajJ6OmMmy7KdxRtZQiagp+Su/Q/mBxQ87wGgcRRYptFlP/v 4J0lAmZPIXzJsT+sPW6b7Pddout7ghAR8CwsBrpoDI44A0NRElAMnmfLVcnk5QkREUj9 n4Wg5ZyGI41qFUCt3pt6PthQPBB/u3pO3i/KSY3ZNblY7jLq7nNihoqFf0EBwW+RZDnM OCK0wbdcxqNncp0FnlfT+lPHpcm4LgNn2K87nZinfeZnIKje6hmX3cLxaIPUBytPTrFp MvFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=uceY5iI4QTwqG26kcjLLhyrAGnYYg+VTh6IKMSkTwNQ=; b=dOsj4Ja4+GpNPMlZFt0c+Q0GLyQHdtO+fjxmjcHm/TXOtS/3TckI7bURjAKfW942Cx h2wvEwksj+Wvgy+1WVeZce8xB3b3lF96ODFjLz6cjuFKv8LXfSielgBxdCfUHYsfrQmJ pUtKa1PlY/hOVZGX9MwSvHgL6of5nX40O4Xh3Jg7efvU9xfQMD0QSFNC9veHVlOzhydF +Po2GP4AEoeOqsamJCeQG86tWW/Vq+N/TjjV1qj6JuQIy4jX7szTyGMvWd7dbEMCUKAt Kvf8Kszs061/+FyL3KoFxbvDCZSximb1xoru/ZBKQJzx1qBzzCidJiR/iI50Gat6Jmit V/VQ== X-Gm-Message-State: ALyK8tLGFqkCBsKJuado7UeQ3yDDjke1xU+dR/VbCqpSGNOpY/PgYtcTSlvY4X+Rnm08eg== X-Received: by 10.194.104.138 with SMTP id ge10mr7957837wjb.85.1464255303366; Thu, 26 May 2016 02:35:03 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id r123sm2556134wmg.20.2016.05.26.02.35.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 May 2016 02:35:01 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm: Store the plane's index Date: Thu, 26 May 2016 10:34:57 +0100 Message-Id: <1464255297-13015-1-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.8.1 Cc: Daniel Vetter , intel-gfx@lists.freedesktop.org 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-Virus-Scanned: ClamAV using ClamSMTP Currently the plane's index is determined by walking the list of all planes in the mode and finding the position of that plane in the list. A linear walk, especially a linear walk within a linear walk as frequently conceived by i915.ko [O(N^2)] quickly comes to dominate profiles. The plane's index is constant for as long as no earlier planes are removed from the list. For most drivers, planes are static, determined at boot and then untouched until shutdown. Storing the index upon construction and then only walking the tail upon removal should be a major improvement for all. Signed-off-by: Chris Wilson Cc: Daniel Vetter Cc: Matt Roper Reviewed-by: Ville Syrjälä --- drivers/gpu/drm/drm_crtc.c | 38 +++++++++----------------------------- include/drm/drm_crtc.h | 6 +++++- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 3a0384cce4a2..00ee01126b6f 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -1302,7 +1302,7 @@ int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, plane->type = type; list_add_tail(&plane->head, &config->plane_list); - config->num_total_plane++; + plane->index = config->num_total_plane++; if (plane->type == DRM_PLANE_TYPE_OVERLAY) config->num_overlay_plane++; @@ -1369,6 +1369,7 @@ EXPORT_SYMBOL(drm_plane_init); void drm_plane_cleanup(struct drm_plane *plane) { struct drm_device *dev = plane->dev; + struct drm_plane *other; drm_modeset_lock_all(dev); kfree(plane->format_types); @@ -1376,6 +1377,10 @@ void drm_plane_cleanup(struct drm_plane *plane) BUG_ON(list_empty(&plane->head)); + other = list_next_entry(plane, head); + list_for_each_entry_from(other, &dev->mode_config.plane_list, head) + other->index--; + list_del(&plane->head); dev->mode_config.num_total_plane--; if (plane->type == DRM_PLANE_TYPE_OVERLAY) @@ -1393,29 +1398,6 @@ void drm_plane_cleanup(struct drm_plane *plane) EXPORT_SYMBOL(drm_plane_cleanup); /** - * drm_plane_index - find the index of a registered plane - * @plane: plane to find index for - * - * Given a registered plane, return the index of that CRTC within a DRM - * device's list of planes. - */ -unsigned int drm_plane_index(struct drm_plane *plane) -{ - unsigned int index = 0; - struct drm_plane *tmp; - - drm_for_each_plane(tmp, plane->dev) { - if (tmp == plane) - return index; - - index++; - } - - BUG(); -} -EXPORT_SYMBOL(drm_plane_index); - -/** * drm_plane_from_index - find the registered plane at an index * @dev: DRM device * @idx: index of registered plane to find for @@ -1427,13 +1409,11 @@ struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx) { struct drm_plane *plane; - unsigned int i = 0; - drm_for_each_plane(plane, dev) { - if (i == idx) + drm_for_each_plane(plane, dev) + if (idx == plane->index) return plane; - i++; - } + return NULL; } EXPORT_SYMBOL(drm_plane_from_index); diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 9771428e1ba8..eda3b1b3d3b4 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -1543,6 +1543,7 @@ struct drm_plane { struct drm_object_properties properties; enum drm_plane_type type; + unsigned index; const struct drm_plane_helper_funcs *helper_private; @@ -2316,7 +2317,10 @@ extern int drm_plane_init(struct drm_device *dev, const uint32_t *formats, unsigned int format_count, bool is_primary); extern void drm_plane_cleanup(struct drm_plane *plane); -extern unsigned int drm_plane_index(struct drm_plane *plane); +static inline unsigned int drm_plane_index(struct drm_plane *plane) +{ + return plane->index; +} extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx); extern void drm_plane_force_disable(struct drm_plane *plane); extern int drm_plane_check_pixel_format(const struct drm_plane *plane,