From patchwork Thu Feb 23 16:18:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9588515 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 4A97E60578 for ; Thu, 23 Feb 2017 16:19:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B405283CA for ; Thu, 23 Feb 2017 16:19:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 302A22844A; Thu, 23 Feb 2017 16:19:14 +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]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 87A51283CA for ; Thu, 23 Feb 2017 16:19:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8A4C26EA8C; Thu, 23 Feb 2017 16:19:07 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr0-x244.google.com (mail-wr0-x244.google.com [IPv6:2a00:1450:400c:c0c::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 76B456EA64 for ; Thu, 23 Feb 2017 16:18:42 +0000 (UTC) Received: by mail-wr0-x244.google.com with SMTP id 89so4445902wrr.1 for ; Thu, 23 Feb 2017 08:18:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=SCHGlOE2/UUTrFmIhd1XvzNcVNTHP/WbC75eDmrDvDA=; b=X+GfyG0SeFabuXy9xkTIBiHatzhm1WUtYpHoU3SBOGeaeBFT7rDtaTfaiGsclBaIMe NGIJ41jzlkjVrjxpVGai6CqfbocgvugpAr/C/axnAKsViXtJsW/ZjOn79xjqeAfdR3mc riMBzK0e8WQA+ylm4U+TSgS5Wrg4xZxf/jDLb82X9OqNfcnj9QVV6OkB78dbZs3ijxmN 6FbGau1vGtNbrMDN+ZzzoyW2On6OWtvWqJKKsZHHwOL3lV/U73G2V8BbEA+APQxI2EQj IU24oQuTVo/uPcVsJc0zcywGEkqk14weC/jezaWJqXoFWVajPPBpN1tiKbA6fSzM/yUn ez+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=SCHGlOE2/UUTrFmIhd1XvzNcVNTHP/WbC75eDmrDvDA=; b=SQpF4uXbMMMO9he2NAOcZa8oPuAHcRyqR1T6akBW8j7B5KJBI4airvycKMvVncxv49 i2QsUTyHK1ZkKi+nxfJAKkXq1dEN/XOo7qhfGzNuVXjF7wi4IWLAWfmsLStedZhi7I0M Pv0PdgZ+T8TVYc1/ic1+E6o6/etkIXCxQ/2OEG+hprJWoCdJVueAes2RfpYl6/s7uEyd 4n7ZkXIdPDb8aN5PGHJSHuqhbHCxM/3zlnAKqeu4RD+ZhAyYwRwh0XcksPckop79pZY/ KlO8K1m/GOAwIVko0G5r68gfFE7fkS8nuq3YkOKPKz6qGeYOmIWcXKRLAE3e+jGdP7/u 4Yew== X-Gm-Message-State: AMke39kz5UHyPx3bfdXc0pkfIlIB1fb2huTVctzgneHuh+eeFYY58y/eBgPk1ykKjkyocA== X-Received: by 10.223.146.34 with SMTP id 31mr4865731wrj.44.1487866720868; Thu, 23 Feb 2017 08:18:40 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id 65sm6587444wri.53.2017.02.23.08.18.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Feb 2017 08:18:40 -0800 (PST) From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Thu, 23 Feb 2017 16:18:22 +0000 Message-Id: <20170223161830.26965-8-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170223161830.26965-1-chris@chris-wilson.co.uk> References: <20170223161830.26965-1-chris@chris-wilson.co.uk> Subject: [Intel-gfx] [PATCH 07/15] drm/i915: Stop using obj->obj_exec_link outside of execbuf 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-Virus-Scanned: ClamAV using ClamSMTP i915_gem_stolen_list_info() sneakily takes advantage of the obj->obj_exec_link to save itself from having to allocate. Enough of the subterfuge, just allocate an array of pointers and sort them instead of the list. Signed-off-by: Chris Wilson Reviewed-by: Mika Kuoppala --- drivers/gpu/drm/i915/i915_debugfs.c | 52 ++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c index ddae8e442176..75efa1ae234e 100644 --- a/drivers/gpu/drm/i915/i915_debugfs.c +++ b/drivers/gpu/drm/i915/i915_debugfs.c @@ -27,7 +27,7 @@ */ #include -#include +#include #include "intel_drv.h" static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node) @@ -230,13 +230,12 @@ describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj) seq_printf(m, " (frontbuffer: 0x%03x)", frontbuffer_bits); } -static int obj_rank_by_stolen(void *priv, - struct list_head *A, struct list_head *B) +static int obj_rank_by_stolen(const void *A, const void *B) { - struct drm_i915_gem_object *a = - container_of(A, struct drm_i915_gem_object, obj_exec_link); - struct drm_i915_gem_object *b = - container_of(B, struct drm_i915_gem_object, obj_exec_link); + const struct drm_i915_gem_object *a = + *(const struct drm_i915_gem_object **)A; + const struct drm_i915_gem_object *b = + *(const struct drm_i915_gem_object **)B; if (a->stolen->start < b->stolen->start) return -1; @@ -249,49 +248,54 @@ static int i915_gem_stolen_list_info(struct seq_file *m, void *data) { struct drm_i915_private *dev_priv = node_to_i915(m->private); struct drm_device *dev = &dev_priv->drm; + struct drm_i915_gem_object **objects; struct drm_i915_gem_object *obj; u64 total_obj_size, total_gtt_size; - LIST_HEAD(stolen); - int count, ret; + unsigned long count, n; + int ret; ret = mutex_lock_interruptible(&dev->struct_mutex); if (ret) return ret; + objects = drm_malloc_ab(dev_priv->mm.object_count, sizeof(*objects)); + if (!objects) { + ret = -ENOMEM; + goto out_unlock; + } + total_obj_size = total_gtt_size = count = 0; list_for_each_entry(obj, &dev_priv->mm.bound_list, global_link) { if (obj->stolen == NULL) continue; - list_add(&obj->obj_exec_link, &stolen); - + objects[count++] = obj; total_obj_size += obj->base.size; total_gtt_size += i915_gem_obj_total_ggtt_size(obj); - count++; } list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_link) { if (obj->stolen == NULL) continue; - list_add(&obj->obj_exec_link, &stolen); - + objects[count++] = obj; total_obj_size += obj->base.size; - count++; } - list_sort(NULL, &stolen, obj_rank_by_stolen); + + sort(objects, count, sizeof(*objects), obj_rank_by_stolen, NULL); + seq_puts(m, "Stolen:\n"); - while (!list_empty(&stolen)) { - obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link); + for (n = 0; n < count; n++) { seq_puts(m, " "); - describe_obj(m, obj); + describe_obj(m, objects[n]); seq_putc(m, '\n'); - list_del_init(&obj->obj_exec_link); } - mutex_unlock(&dev->struct_mutex); - - seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n", + seq_printf(m, "Total %lu objects, %llu bytes, %llu GTT size\n", count, total_obj_size, total_gtt_size); - return 0; + + drm_free_large(objects); +out_unlock: + mutex_unlock(&dev->struct_mutex); + return ret; } struct file_stats {