]> Git Repo - linux.git/blob - drivers/gpu/drm/v3d/v3d_sysfs.c
Merge tag 'phy-for-6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/phy/linux-phy
[linux.git] / drivers / gpu / drm / v3d / v3d_sysfs.c
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2023 Igalia S.L.
4  */
5
6 #include <linux/sched/clock.h>
7 #include <linux/sysfs.h>
8
9 #include "v3d_drv.h"
10
11 static ssize_t
12 gpu_stats_show(struct device *dev, struct device_attribute *attr, char *buf)
13 {
14         struct drm_device *drm = dev_get_drvdata(dev);
15         struct v3d_dev *v3d = to_v3d_dev(drm);
16         enum v3d_queue queue;
17         u64 timestamp = local_clock();
18         u64 active_runtime;
19         ssize_t len = 0;
20
21         len += sysfs_emit(buf, "queue\ttimestamp\tjobs\truntime\n");
22
23         for (queue = 0; queue < V3D_MAX_QUEUES; queue++) {
24                 if (v3d->queue[queue].start_ns)
25                         active_runtime = timestamp - v3d->queue[queue].start_ns;
26                 else
27                         active_runtime = 0;
28
29                 /* Each line will display the queue name, timestamp, the number
30                  * of jobs sent to that queue and the runtime, as can be seem here:
31                  *
32                  * queue        timestamp       jobs    runtime
33                  * bin          239043069420    22620   17438164056
34                  * render       239043069420    22619   27284814161
35                  * tfu          239043069420    8763    394592566
36                  * csd          239043069420    3168    10787905530
37                  * cache_clean  239043069420    6127    237375940
38                  */
39                 len += sysfs_emit_at(buf, len, "%s\t%llu\t%llu\t%llu\n",
40                                      v3d_queue_to_string(queue),
41                                      timestamp,
42                                      v3d->queue[queue].jobs_sent,
43                                      v3d->queue[queue].enabled_ns + active_runtime);
44         }
45
46         return len;
47 }
48 static DEVICE_ATTR_RO(gpu_stats);
49
50 static struct attribute *v3d_sysfs_entries[] = {
51         &dev_attr_gpu_stats.attr,
52         NULL,
53 };
54
55 static struct attribute_group v3d_sysfs_attr_group = {
56         .attrs = v3d_sysfs_entries,
57 };
58
59 int
60 v3d_sysfs_init(struct device *dev)
61 {
62         return sysfs_create_group(&dev->kobj, &v3d_sysfs_attr_group);
63 }
64
65 void
66 v3d_sysfs_destroy(struct device *dev)
67 {
68         return sysfs_remove_group(&dev->kobj, &v3d_sysfs_attr_group);
69 }
This page took 0.033847 seconds and 4 git commands to generate.