0001
0002
0003
0004
0005
0006 #include <linux/kernel.h>
0007 #include <linux/slab.h>
0008 #include <linux/types.h>
0009
0010 #include <uapi/drm/i915_drm.h>
0011
0012 #include <drm/drm_print.h>
0013
0014 #include "gem/i915_gem_context.h"
0015 #include "i915_drm_client.h"
0016 #include "i915_file_private.h"
0017 #include "i915_gem.h"
0018 #include "i915_utils.h"
0019
0020 void i915_drm_clients_init(struct i915_drm_clients *clients,
0021 struct drm_i915_private *i915)
0022 {
0023 clients->i915 = i915;
0024 clients->next_id = 0;
0025
0026 xa_init_flags(&clients->xarray, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ);
0027 }
0028
0029 struct i915_drm_client *i915_drm_client_add(struct i915_drm_clients *clients)
0030 {
0031 struct i915_drm_client *client;
0032 struct xarray *xa = &clients->xarray;
0033 int ret;
0034
0035 client = kzalloc(sizeof(*client), GFP_KERNEL);
0036 if (!client)
0037 return ERR_PTR(-ENOMEM);
0038
0039 xa_lock_irq(xa);
0040 ret = __xa_alloc_cyclic(xa, &client->id, client, xa_limit_32b,
0041 &clients->next_id, GFP_KERNEL);
0042 xa_unlock_irq(xa);
0043 if (ret < 0)
0044 goto err;
0045
0046 kref_init(&client->kref);
0047 spin_lock_init(&client->ctx_lock);
0048 INIT_LIST_HEAD(&client->ctx_list);
0049 client->clients = clients;
0050
0051 return client;
0052
0053 err:
0054 kfree(client);
0055
0056 return ERR_PTR(ret);
0057 }
0058
0059 void __i915_drm_client_free(struct kref *kref)
0060 {
0061 struct i915_drm_client *client =
0062 container_of(kref, typeof(*client), kref);
0063 struct xarray *xa = &client->clients->xarray;
0064 unsigned long flags;
0065
0066 xa_lock_irqsave(xa, flags);
0067 __xa_erase(xa, client->id);
0068 xa_unlock_irqrestore(xa, flags);
0069 kfree(client);
0070 }
0071
0072 void i915_drm_clients_fini(struct i915_drm_clients *clients)
0073 {
0074 GEM_BUG_ON(!xa_empty(&clients->xarray));
0075 xa_destroy(&clients->xarray);
0076 }
0077
0078 #ifdef CONFIG_PROC_FS
0079 static const char * const uabi_class_names[] = {
0080 [I915_ENGINE_CLASS_RENDER] = "render",
0081 [I915_ENGINE_CLASS_COPY] = "copy",
0082 [I915_ENGINE_CLASS_VIDEO] = "video",
0083 [I915_ENGINE_CLASS_VIDEO_ENHANCE] = "video-enhance",
0084 [I915_ENGINE_CLASS_COMPUTE] = "compute",
0085 };
0086
0087 static u64 busy_add(struct i915_gem_context *ctx, unsigned int class)
0088 {
0089 struct i915_gem_engines_iter it;
0090 struct intel_context *ce;
0091 u64 total = 0;
0092
0093 for_each_gem_engine(ce, rcu_dereference(ctx->engines), it) {
0094 if (ce->engine->uabi_class != class)
0095 continue;
0096
0097 total += intel_context_get_total_runtime_ns(ce);
0098 }
0099
0100 return total;
0101 }
0102
0103 static void
0104 show_client_class(struct seq_file *m,
0105 struct i915_drm_client *client,
0106 unsigned int class)
0107 {
0108 const struct list_head *list = &client->ctx_list;
0109 u64 total = atomic64_read(&client->past_runtime[class]);
0110 const unsigned int capacity =
0111 client->clients->i915->engine_uabi_class_count[class];
0112 struct i915_gem_context *ctx;
0113
0114 rcu_read_lock();
0115 list_for_each_entry_rcu(ctx, list, client_link)
0116 total += busy_add(ctx, class);
0117 rcu_read_unlock();
0118
0119 if (capacity)
0120 seq_printf(m, "drm-engine-%s:\t%llu ns\n",
0121 uabi_class_names[class], total);
0122
0123 if (capacity > 1)
0124 seq_printf(m, "drm-engine-capacity-%s:\t%u\n",
0125 uabi_class_names[class],
0126 capacity);
0127 }
0128
0129 void i915_drm_client_fdinfo(struct seq_file *m, struct file *f)
0130 {
0131 struct drm_file *file = f->private_data;
0132 struct drm_i915_file_private *file_priv = file->driver_priv;
0133 struct drm_i915_private *i915 = file_priv->dev_priv;
0134 struct i915_drm_client *client = file_priv->client;
0135 struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
0136 unsigned int i;
0137
0138
0139
0140
0141
0142
0143
0144 seq_printf(m, "drm-driver:\t%s\n", i915->drm.driver->name);
0145 seq_printf(m, "drm-pdev:\t%04x:%02x:%02x.%d\n",
0146 pci_domain_nr(pdev->bus), pdev->bus->number,
0147 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
0148 seq_printf(m, "drm-client-id:\t%u\n", client->id);
0149
0150
0151
0152
0153
0154 if (GRAPHICS_VER(i915) < 8 || intel_uc_uses_guc_submission(&i915->gt0.uc))
0155 return;
0156
0157 for (i = 0; i < ARRAY_SIZE(uabi_class_names); i++)
0158 show_client_class(m, client, i);
0159 }
0160 #endif