Skip to content

Commit 3763d63

Browse files
drm/ttm: add debugfs directory v2
As far as I can tell the buffer_count was never used by an 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. v2: add that additionally to sysfs Signed-off-by: Christian König <[email protected]> Acked-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/414954/
1 parent e182780 commit 3763d63

File tree

3 files changed

+11
-47
lines changed

3 files changed

+11
-47
lines changed

drivers/gpu/drm/ttm/ttm_bo.c

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444

4545
#include "ttm_module.h"
4646

47-
static void ttm_bo_global_kobj_release(struct kobject *kobj);
48-
4947
/*
5048
* ttm_global_mutex - protecting the global BO state
5149
*/
@@ -54,11 +52,6 @@ unsigned ttm_bo_glob_use_count;
5452
struct ttm_bo_global ttm_bo_glob;
5553
EXPORT_SYMBOL(ttm_bo_glob);
5654

57-
static struct attribute ttm_bo_count = {
58-
.name = "bo_count",
59-
.mode = S_IRUGO
60-
};
61-
6255
/* default destructor */
6356
static void ttm_bo_default_destroy(struct ttm_buffer_object *bo)
6457
{
@@ -84,32 +77,6 @@ static void ttm_bo_mem_space_debug(struct ttm_buffer_object *bo,
8477
}
8578
}
8679

87-
static ssize_t ttm_bo_global_show(struct kobject *kobj,
88-
struct attribute *attr,
89-
char *buffer)
90-
{
91-
struct ttm_bo_global *glob =
92-
container_of(kobj, struct ttm_bo_global, kobj);
93-
94-
return snprintf(buffer, PAGE_SIZE, "%d\n",
95-
atomic_read(&glob->bo_count));
96-
}
97-
98-
static struct attribute *ttm_bo_global_attrs[] = {
99-
&ttm_bo_count,
100-
NULL
101-
};
102-
103-
static const struct sysfs_ops ttm_bo_global_ops = {
104-
.show = &ttm_bo_global_show
105-
};
106-
107-
static struct kobj_type ttm_bo_glob_kobj_type = {
108-
.release = &ttm_bo_global_kobj_release,
109-
.sysfs_ops = &ttm_bo_global_ops,
110-
.default_attrs = ttm_bo_global_attrs
111-
};
112-
11380
static void ttm_bo_del_from_lru(struct ttm_buffer_object *bo)
11481
{
11582
struct ttm_bo_device *bdev = bo->bdev;
@@ -1228,14 +1195,6 @@ size_t ttm_bo_dma_acc_size(struct ttm_bo_device *bdev,
12281195
}
12291196
EXPORT_SYMBOL(ttm_bo_dma_acc_size);
12301197

1231-
static void ttm_bo_global_kobj_release(struct kobject *kobj)
1232-
{
1233-
struct ttm_bo_global *glob =
1234-
container_of(kobj, struct ttm_bo_global, kobj);
1235-
1236-
__free_page(glob->dummy_read_page);
1237-
}
1238-
12391198
static void ttm_bo_global_release(void)
12401199
{
12411200
struct ttm_bo_global *glob = &ttm_bo_glob;
@@ -1247,6 +1206,7 @@ static void ttm_bo_global_release(void)
12471206
kobject_del(&glob->kobj);
12481207
kobject_put(&glob->kobj);
12491208
ttm_mem_global_release(&ttm_mem_glob);
1209+
__free_page(glob->dummy_read_page);
12501210
memset(glob, 0, sizeof(*glob));
12511211
out:
12521212
mutex_unlock(&ttm_global_mutex);
@@ -1279,10 +1239,8 @@ static int ttm_bo_global_init(void)
12791239
INIT_LIST_HEAD(&glob->device_list);
12801240
atomic_set(&glob->bo_count, 0);
12811241

1282-
ret = kobject_init_and_add(
1283-
&glob->kobj, &ttm_bo_glob_kobj_type, ttm_get_kobj(), "buffer_objects");
1284-
if (unlikely(ret != 0))
1285-
kobject_put(&glob->kobj);
1242+
debugfs_create_atomic_t("buffer_objects", 0444, ttm_debugfs_root,
1243+
&glob->bo_count);
12861244
out:
12871245
mutex_unlock(&ttm_global_mutex);
12881246
return ret;

drivers/gpu/drm/ttm/ttm_module.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@
3232
#include <linux/module.h>
3333
#include <linux/device.h>
3434
#include <linux/sched.h>
35+
#include <linux/debugfs.h>
3536
#include <drm/drm_sysfs.h>
3637

3738
#include "ttm_module.h"
3839

3940
static DECLARE_WAIT_QUEUE_HEAD(exit_q);
4041
static atomic_t device_released;
42+
struct dentry *ttm_debugfs_root;
4143

4244
static struct device_type ttm_drm_class_type = {
4345
.name = "ttm",
@@ -77,6 +79,7 @@ static int __init ttm_init(void)
7779
if (unlikely(ret != 0))
7880
goto out_no_dev_reg;
7981

82+
ttm_debugfs_root = debugfs_create_dir("ttm", NULL);
8083
return 0;
8184
out_no_dev_reg:
8285
atomic_set(&device_released, 1);
@@ -94,6 +97,7 @@ static void __exit ttm_exit(void)
9497
*/
9598

9699
wait_event(exit_q, atomic_read(&device_released) == 1);
100+
debugfs_remove(ttm_debugfs_root);
97101
}
98102

99103
module_init(ttm_init);

drivers/gpu/drm/ttm/ttm_module.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
#ifndef _TTM_MODULE_H_
3232
#define _TTM_MODULE_H_
3333

34-
#include <linux/kernel.h>
34+
#define TTM_PFX "[TTM] "
35+
3536
struct kobject;
37+
struct dentry;
3638

37-
#define TTM_PFX "[TTM] "
3839
extern struct kobject *ttm_get_kobj(void);
40+
extern struct dentry *ttm_debugfs_root;
3941

4042
#endif /* _TTM_MODULE_H_ */

0 commit comments

Comments
 (0)