1 // SPDX-License-Identifier: MIT
3 * Copyright © 2020 Intel Corporation
6 #include <linux/kernel.h>
7 #include <linux/slab.h>
8 #include <linux/types.h>
10 #include <uapi/drm/i915_drm.h>
12 #include <drm/drm_print.h>
14 #include "gem/i915_gem_context.h"
15 #include "i915_drm_client.h"
16 #include "i915_file_private.h"
18 #include "i915_utils.h"
20 struct i915_drm_client *i915_drm_client_alloc(void)
22 struct i915_drm_client *client;
24 client = kzalloc(sizeof(*client), GFP_KERNEL);
28 kref_init(&client->kref);
29 spin_lock_init(&client->ctx_lock);
30 INIT_LIST_HEAD(&client->ctx_list);
35 void __i915_drm_client_free(struct kref *kref)
37 struct i915_drm_client *client =
38 container_of(kref, typeof(*client), kref);
44 static const char * const uabi_class_names[] = {
45 [I915_ENGINE_CLASS_RENDER] = "render",
46 [I915_ENGINE_CLASS_COPY] = "copy",
47 [I915_ENGINE_CLASS_VIDEO] = "video",
48 [I915_ENGINE_CLASS_VIDEO_ENHANCE] = "video-enhance",
49 [I915_ENGINE_CLASS_COMPUTE] = "compute",
52 static u64 busy_add(struct i915_gem_context *ctx, unsigned int class)
54 struct i915_gem_engines_iter it;
55 struct intel_context *ce;
58 for_each_gem_engine(ce, rcu_dereference(ctx->engines), it) {
59 if (ce->engine->uabi_class != class)
62 total += intel_context_get_total_runtime_ns(ce);
69 show_client_class(struct drm_printer *p,
70 struct drm_i915_private *i915,
71 struct i915_drm_client *client,
74 const unsigned int capacity = i915->engine_uabi_class_count[class];
75 u64 total = atomic64_read(&client->past_runtime[class]);
76 struct i915_gem_context *ctx;
79 list_for_each_entry_rcu(ctx, &client->ctx_list, client_link)
80 total += busy_add(ctx, class);
84 drm_printf(p, "drm-engine-%s:\t%llu ns\n",
85 uabi_class_names[class], total);
88 drm_printf(p, "drm-engine-capacity-%s:\t%u\n",
89 uabi_class_names[class],
93 void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file)
95 struct drm_i915_file_private *file_priv = file->driver_priv;
96 struct drm_i915_private *i915 = file_priv->i915;
100 * ******************************************************************
101 * For text output format description please see drm-usage-stats.rst!
102 * ******************************************************************
105 if (GRAPHICS_VER(i915) < 8)
108 for (i = 0; i < ARRAY_SIZE(uabi_class_names); i++)
109 show_client_class(p, i915, file_priv->client, i);