From patchwork Tue Nov 17 16:33:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 11912853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADEA4C2D0E4 for ; Tue, 17 Nov 2020 16:33:50 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 33EBA216C4 for ; Tue, 17 Nov 2020 16:33:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bzlsn5f6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 33EBA216C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9DCE46E03F; Tue, 17 Nov 2020 16:33:45 +0000 (UTC) Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by gabe.freedesktop.org (Postfix) with ESMTPS id A7BAB6E03C for ; Tue, 17 Nov 2020 16:33:43 +0000 (UTC) Received: by mail-ej1-x642.google.com with SMTP id k27so2914326ejs.10 for ; Tue, 17 Nov 2020 08:33:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=PchTq9pBWco3KprvJ1j/lo5yNyEtD7jqJKvWp8PECG8=; b=Bzlsn5f6ETrDyYsPXDqR1OY5Ewpi+dhGnm6cV4CFjb1R5i4212N7EzEXUrXpYx2Iyy VTJxzbin9aqsrcVI2ObHdjfZcdYIz0SBe5Uj3W7u04W9cW+ozn4RxvUALO0HAAfFcuyL Kh0oSn04aKSk5OdXME6EUo6zm+wdfJcguBAPKik40FT+xkTh2dXJZNl8NWgv8igZdTG1 siZxzG3blI0kY+CN9E5PLfrPbzeKiFxg8+Gpt4sIfbUxRuyhksCZhoaKW/6N2CwphUvW W5PYPZRBOF3D+WhYR/j3oizhLU1aWXPxM8GYJpmtqRQT8UCCeR9Jmky32I607cDoGBnI Y3kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PchTq9pBWco3KprvJ1j/lo5yNyEtD7jqJKvWp8PECG8=; b=Mm1yr1G1sH5vWBMihT2Lvmmokn4oveNPuvaroX0K3BvGwkOOfu/QBWu/WhZxmLAWSy ZFvz7ItDKAxWu1fyw2fi7H9ipxQQmhsCo3sCIyolmBJCootxst1Pcw6YqZ0puzJ0962T TmwiTgSV5PbEyAK1k686rGjA60B69ewwDqtNaj9dIWN29LmTRUjusF3LHMxGY0OsBSeJ oHGdSJPwAwZaDL1GGK+TJICKJ7KZpWGNwiY4f5jbhHZH+8fVbTQk/E+4CHyMXppAIFiE kYKySmiFwaSHplB0j2fVEyS7tUF0FjbpPiKwiuPEPDn3zhLhV/mvAMiFWLOWq+lYqJS1 LHwA== X-Gm-Message-State: AOAM531d/1BPTqZJmD5xzLnLXi6joPoR2l7gKJpAZAGnaccvTzX/INnk UqfWsB+evNomBqmt5sMDL7CsNQZ5pLE= X-Google-Smtp-Source: ABdhPJzyCCAalP7dwqMyWZeHpCIIouYf7tt0VvrR6uLlYXosrnpzFg0o7fW8F4aE4NmfvdQnACkNLA== X-Received: by 2002:a17:906:c18c:: with SMTP id g12mr19755982ejz.334.1605630820776; Tue, 17 Nov 2020 08:33:40 -0800 (PST) Received: from abel.fritz.box ([2a02:908:1252:fb60:dd48:f15c:7bed:4c52]) by smtp.gmail.com with ESMTPSA id dn16sm12225351edb.19.2020.11.17.08.33.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Nov 2020 08:33:40 -0800 (PST) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/4] drm/ttm: replace sysfs with debugfs Date: Tue, 17 Nov 2020 17:33:36 +0100 Message-Id: <20201117163338.1784-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201117163338.1784-1-christian.koenig@amd.com> References: <20201117163338.1784-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" As far as I can tell this has never been used by any userspace application. The number of BOs in the system is far better suited in debugfs than sysfs and we now should be able to add other information here as well. Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo.c | 51 ++-------------- drivers/gpu/drm/ttm/ttm_module.c | 58 ++----------------- {include => drivers/gpu}/drm/ttm/ttm_module.h | 8 +-- include/drm/ttm/ttm_bo_driver.h | 1 - 4 files changed, 13 insertions(+), 105 deletions(-) rename {include => drivers/gpu}/drm/ttm/ttm_module.h (94%) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 0a93df93dba4..cd1273c76c51 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -31,7 +31,6 @@ #define pr_fmt(fmt) "[TTM] " fmt -#include #include #include #include @@ -43,7 +42,7 @@ #include #include -static void ttm_bo_global_kobj_release(struct kobject *kobj); +#include "ttm_module.h" /** * ttm_global_mutex - protecting the global BO state @@ -53,11 +52,6 @@ unsigned ttm_bo_glob_use_count; struct ttm_bo_global ttm_bo_glob; EXPORT_SYMBOL(ttm_bo_glob); -static struct attribute ttm_bo_count = { - .name = "bo_count", - .mode = S_IRUGO -}; - /* default destructor */ static void ttm_bo_default_destroy(struct ttm_buffer_object *bo) { @@ -83,32 +77,6 @@ static void ttm_bo_mem_space_debug(struct ttm_buffer_object *bo, } } -static ssize_t ttm_bo_global_show(struct kobject *kobj, - struct attribute *attr, - char *buffer) -{ - struct ttm_bo_global *glob = - container_of(kobj, struct ttm_bo_global, kobj); - - return snprintf(buffer, PAGE_SIZE, "%d\n", - atomic_read(&glob->bo_count)); -} - -static struct attribute *ttm_bo_global_attrs[] = { - &ttm_bo_count, - NULL -}; - -static const struct sysfs_ops ttm_bo_global_ops = { - .show = &ttm_bo_global_show -}; - -static struct kobj_type ttm_bo_glob_kobj_type = { - .release = &ttm_bo_global_kobj_release, - .sysfs_ops = &ttm_bo_global_ops, - .default_attrs = ttm_bo_global_attrs -}; - static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo, struct ttm_resource *mem) { @@ -1216,14 +1184,6 @@ int ttm_bo_init(struct ttm_bo_device *bdev, } EXPORT_SYMBOL(ttm_bo_init); -static void ttm_bo_global_kobj_release(struct kobject *kobj) -{ - struct ttm_bo_global *glob = - container_of(kobj, struct ttm_bo_global, kobj); - - __free_page(glob->dummy_read_page); -} - static void ttm_bo_global_release(void) { struct ttm_bo_global *glob = &ttm_bo_glob; @@ -1233,9 +1193,8 @@ static void ttm_bo_global_release(void) goto out; ttm_pool_mgr_fini(); + __free_page(glob->dummy_read_page); - kobject_del(&glob->kobj); - kobject_put(&glob->kobj); memset(glob, 0, sizeof(*glob)); out: mutex_unlock(&ttm_global_mutex); @@ -1288,10 +1247,8 @@ static int ttm_bo_global_init(void) INIT_LIST_HEAD(&glob->device_list); atomic_set(&glob->bo_count, 0); - ret = kobject_init_and_add( - &glob->kobj, &ttm_bo_glob_kobj_type, ttm_get_kobj(), "buffer_objects"); - if (unlikely(ret != 0)) - kobject_put(&glob->kobj); + debugfs_create_atomic_t("buffer_objects", 0444, ttm_debugfs_root, + &glob->bo_count); out: mutex_unlock(&ttm_global_mutex); return ret; diff --git a/drivers/gpu/drm/ttm/ttm_module.c b/drivers/gpu/drm/ttm/ttm_module.c index 6ff40c041d79..ac295861a688 100644 --- a/drivers/gpu/drm/ttm/ttm_module.c +++ b/drivers/gpu/drm/ttm/ttm_module.c @@ -30,69 +30,21 @@ * Jerome Glisse */ #include -#include -#include -#include -#include +#include -static DECLARE_WAIT_QUEUE_HEAD(exit_q); -static atomic_t device_released; +#include "ttm_module.h" -static struct device_type ttm_drm_class_type = { - .name = "ttm", - /** - * Add pm ops here. - */ -}; - -static void ttm_drm_class_device_release(struct device *dev) -{ - atomic_set(&device_released, 1); - wake_up_all(&exit_q); -} - -static struct device ttm_drm_class_device = { - .type = &ttm_drm_class_type, - .release = &ttm_drm_class_device_release -}; - -struct kobject *ttm_get_kobj(void) -{ - struct kobject *kobj = &ttm_drm_class_device.kobj; - BUG_ON(kobj == NULL); - return kobj; -} +struct dentry *ttm_debugfs_root; static int __init ttm_init(void) { - int ret; - - ret = dev_set_name(&ttm_drm_class_device, "ttm"); - if (unlikely(ret != 0)) - return ret; - - atomic_set(&device_released, 0); - ret = drm_class_device_register(&ttm_drm_class_device); - if (unlikely(ret != 0)) - goto out_no_dev_reg; - + ttm_debugfs_root = debugfs_create_dir("ttm", NULL); return 0; -out_no_dev_reg: - atomic_set(&device_released, 1); - wake_up_all(&exit_q); - return ret; } static void __exit ttm_exit(void) { - drm_class_device_unregister(&ttm_drm_class_device); - - /** - * Refuse to unload until the TTM device is released. - * Not sure this is 100% needed. - */ - - wait_event(exit_q, atomic_read(&device_released) == 1); + debugfs_remove(ttm_debugfs_root); } module_init(ttm_init); diff --git a/include/drm/ttm/ttm_module.h b/drivers/gpu/drm/ttm/ttm_module.h similarity index 94% rename from include/drm/ttm/ttm_module.h rename to drivers/gpu/drm/ttm/ttm_module.h index 45fa318c1585..d7cac5d4b835 100644 --- a/include/drm/ttm/ttm_module.h +++ b/drivers/gpu/drm/ttm/ttm_module.h @@ -31,10 +31,10 @@ #ifndef _TTM_MODULE_H_ #define _TTM_MODULE_H_ -#include -struct kobject; - #define TTM_PFX "[TTM] " -extern struct kobject *ttm_get_kobj(void); + +struct dentry; + +extern struct dentry *ttm_debugfs_root; #endif /* _TTM_MODULE_H_ */ diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index fdf01c7f1f99..9b2d34303734 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h @@ -245,7 +245,6 @@ extern struct ttm_bo_global { * Constant after init. */ - struct kobject kobj; struct page *dummy_read_page; spinlock_t lru_lock;