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
gpu_stats_show(struct device * dev,struct device_attribute * attr,char * buf)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 ssize_t len = 0;
19
20 len += sysfs_emit(buf, "queue\ttimestamp\tjobs\truntime\n");
21
22 for (queue = 0; queue < V3D_MAX_QUEUES; queue++) {
23 struct v3d_stats *stats = &v3d->queue[queue].stats;
24 u64 active_runtime, jobs_completed;
25
26 v3d_get_stats(stats, timestamp, &active_runtime, &jobs_completed);
27
28 /* Each line will display the queue name, timestamp, the number
29 * of jobs sent to that queue and the runtime, as can be seem here:
30 *
31 * queue timestamp jobs runtime
32 * bin 239043069420 22620 17438164056
33 * render 239043069420 22619 27284814161
34 * tfu 239043069420 8763 394592566
35 * csd 239043069420 3168 10787905530
36 * cache_clean 239043069420 6127 237375940
37 */
38 len += sysfs_emit_at(buf, len, "%s\t%llu\t%llu\t%llu\n",
39 v3d_queue_to_string(queue),
40 timestamp, jobs_completed, active_runtime);
41 }
42
43 return len;
44 }
45 static DEVICE_ATTR_RO(gpu_stats);
46
47 static struct attribute *v3d_sysfs_entries[] = {
48 &dev_attr_gpu_stats.attr,
49 NULL,
50 };
51
52 static struct attribute_group v3d_sysfs_attr_group = {
53 .attrs = v3d_sysfs_entries,
54 };
55
56 int
v3d_sysfs_init(struct device * dev)57 v3d_sysfs_init(struct device *dev)
58 {
59 return sysfs_create_group(&dev->kobj, &v3d_sysfs_attr_group);
60 }
61
62 void
v3d_sysfs_destroy(struct device * dev)63 v3d_sysfs_destroy(struct device *dev)
64 {
65 return sysfs_remove_group(&dev->kobj, &v3d_sysfs_attr_group);
66 }
67