linux-zen-desktop/drivers/gpu/drm/i915/i915_drm_client.c

112 lines
2.6 KiB
C
Raw Normal View History

2023-08-30 17:31:07 +02:00
// SPDX-License-Identifier: MIT
/*
* Copyright © 2020 Intel Corporation
*/
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <uapi/drm/i915_drm.h>
#include <drm/drm_print.h>
#include "gem/i915_gem_context.h"
#include "i915_drm_client.h"
#include "i915_file_private.h"
#include "i915_gem.h"
#include "i915_utils.h"
2023-10-24 12:59:35 +02:00
struct i915_drm_client *i915_drm_client_alloc(void)
2023-08-30 17:31:07 +02:00
{
struct i915_drm_client *client;
client = kzalloc(sizeof(*client), GFP_KERNEL);
if (!client)
2023-10-24 12:59:35 +02:00
return NULL;
2023-08-30 17:31:07 +02:00
kref_init(&client->kref);
spin_lock_init(&client->ctx_lock);
INIT_LIST_HEAD(&client->ctx_list);
return client;
}
void __i915_drm_client_free(struct kref *kref)
{
struct i915_drm_client *client =
container_of(kref, typeof(*client), kref);
kfree(client);
}
#ifdef CONFIG_PROC_FS
static const char * const uabi_class_names[] = {
[I915_ENGINE_CLASS_RENDER] = "render",
[I915_ENGINE_CLASS_COPY] = "copy",
[I915_ENGINE_CLASS_VIDEO] = "video",
[I915_ENGINE_CLASS_VIDEO_ENHANCE] = "video-enhance",
[I915_ENGINE_CLASS_COMPUTE] = "compute",
};
static u64 busy_add(struct i915_gem_context *ctx, unsigned int class)
{
struct i915_gem_engines_iter it;
struct intel_context *ce;
u64 total = 0;
for_each_gem_engine(ce, rcu_dereference(ctx->engines), it) {
if (ce->engine->uabi_class != class)
continue;
total += intel_context_get_total_runtime_ns(ce);
}
return total;
}
static void
2023-10-24 12:59:35 +02:00
show_client_class(struct drm_printer *p,
struct drm_i915_private *i915,
2023-08-30 17:31:07 +02:00
struct i915_drm_client *client,
unsigned int class)
{
2023-10-24 12:59:35 +02:00
const unsigned int capacity = i915->engine_uabi_class_count[class];
2023-08-30 17:31:07 +02:00
u64 total = atomic64_read(&client->past_runtime[class]);
struct i915_gem_context *ctx;
rcu_read_lock();
2023-10-24 12:59:35 +02:00
list_for_each_entry_rcu(ctx, &client->ctx_list, client_link)
2023-08-30 17:31:07 +02:00
total += busy_add(ctx, class);
rcu_read_unlock();
if (capacity)
2023-10-24 12:59:35 +02:00
drm_printf(p, "drm-engine-%s:\t%llu ns\n",
2023-08-30 17:31:07 +02:00
uabi_class_names[class], total);
if (capacity > 1)
2023-10-24 12:59:35 +02:00
drm_printf(p, "drm-engine-capacity-%s:\t%u\n",
2023-08-30 17:31:07 +02:00
uabi_class_names[class],
capacity);
}
2023-10-24 12:59:35 +02:00
void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file)
2023-08-30 17:31:07 +02:00
{
struct drm_i915_file_private *file_priv = file->driver_priv;
2023-10-24 12:59:35 +02:00
struct drm_i915_private *i915 = file_priv->i915;
2023-08-30 17:31:07 +02:00
unsigned int i;
/*
* ******************************************************************
* For text output format description please see drm-usage-stats.rst!
* ******************************************************************
*/
2023-10-24 12:59:35 +02:00
if (GRAPHICS_VER(i915) < 8)
2023-08-30 17:31:07 +02:00
return;
for (i = 0; i < ARRAY_SIZE(uabi_class_names); i++)
2023-10-24 12:59:35 +02:00
show_client_class(p, i915, file_priv->client, i);
2023-08-30 17:31:07 +02:00
}
#endif