1 // SPDX-License-Identifier: MIT
3 * Copyright © 2023 Igalia S.L.
6 #include <linux/sched/clock.h>
7 #include <linux/sysfs.h>
12 gpu_stats_show(struct device *dev, struct device_attribute *attr, char *buf)
14 struct drm_device *drm = dev_get_drvdata(dev);
15 struct v3d_dev *v3d = to_v3d_dev(drm);
17 u64 timestamp = local_clock();
21 len += sysfs_emit(buf, "queue\ttimestamp\tjobs\truntime\n");
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;
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:
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
39 len += sysfs_emit_at(buf, len, "%s\t%llu\t%llu\t%llu\n",
40 v3d_queue_to_string(queue),
42 v3d->queue[queue].jobs_sent,
43 v3d->queue[queue].enabled_ns + active_runtime);
48 static DEVICE_ATTR_RO(gpu_stats);
50 static struct attribute *v3d_sysfs_entries[] = {
51 &dev_attr_gpu_stats.attr,
55 static struct attribute_group v3d_sysfs_attr_group = {
56 .attrs = v3d_sysfs_entries,
60 v3d_sysfs_init(struct device *dev)
62 return sysfs_create_group(&dev->kobj, &v3d_sysfs_attr_group);
66 v3d_sysfs_destroy(struct device *dev)
68 return sysfs_remove_group(&dev->kobj, &v3d_sysfs_attr_group);