* [Intel-gfx] [PATCH v4 0/5] fdinfo memory stats
@ 2023-06-12 10:46 Tvrtko Ursulin
2023-06-12 10:46 ` [Intel-gfx] [PATCH 1/5] drm/i915: Add ability for tracking buffer objects per client Tvrtko Ursulin
` (7 more replies)
0 siblings, 8 replies; 23+ messages in thread
From: Tvrtko Ursulin @ 2023-06-12 10:46 UTC (permalink / raw)
To: Intel-gfx, dri-devel
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
I added tracking of most classes of objects which contribute to client's memory
footprint and accouting along the similar lines as in Rob's msm code. Then
printing it out to fdinfo using the drm helper Rob added.
Accounting by keeping per client lists may not be the most effient method,
perhaps we should simply add and subtract stats directly at convenient sites,
but that too is not straightforward due no existing connection between buffer
objects and clients. Possibly some other tricky bits in the buffer sharing
deparment. So lets see if this works for now. Infrequent reader penalty should
not be too bad (may be even useful to dump the lists in debugfs?) and additional
list_head per object pretty much drowns in the noise.
Example fdinfo with the series applied:
# cat /proc/1383/fdinfo/8
pos: 0
flags: 02100002
mnt_id: 21
ino: 397
drm-driver: i915
drm-client-id: 18
drm-pdev: 0000:00:02.0
drm-total-system: 125 MiB
drm-shared-system: 16 MiB
drm-active-system: 110 MiB
drm-resident-system: 125 MiB
drm-purgeable-system: 2 MiB
drm-total-stolen-system: 0
drm-shared-stolen-system: 0
drm-active-stolen-system: 0
drm-resident-stolen-system: 0
drm-purgeable-stolen-system: 0
drm-engine-render: 25662044495 ns
drm-engine-copy: 0 ns
drm-engine-video: 0 ns
drm-engine-video-enhance: 0 ns
Example gputop output (local patches currently):
DRM minor 0
PID SMEM SMEMRSS render copy video NAME
1233 124M 124M |████████|| || || | neverball
1130 59M 59M |█▌ || || || | Xorg
1207 12M 12M | || || || | xfwm4
v2:
* Now actually per client.
v3:
* Track imported dma-buf objects.
v4:
* Rely on DRM GEM handles for tracking user objects.
* Fix internal object accounting (no placements).
Tvrtko Ursulin (5):
drm/i915: Add ability for tracking buffer objects per client
drm/i915: Record which client owns a VM
drm/i915: Track page table backing store usage
drm/i915: Account ring buffer and context state storage
drm/i915: Implement fdinfo memory stats printing
drivers/gpu/drm/i915/gem/i915_gem_context.c | 11 +-
.../gpu/drm/i915/gem/i915_gem_context_types.h | 3 +
drivers/gpu/drm/i915/gem/i915_gem_object.c | 5 +
.../gpu/drm/i915/gem/i915_gem_object_types.h | 12 ++
.../gpu/drm/i915/gem/selftests/mock_context.c | 4 +-
drivers/gpu/drm/i915/gt/intel_context.c | 8 ++
drivers/gpu/drm/i915/gt/intel_gtt.c | 6 +
drivers/gpu/drm/i915/gt/intel_gtt.h | 1 +
drivers/gpu/drm/i915/i915_drm_client.c | 124 +++++++++++++++++-
drivers/gpu/drm/i915/i915_drm_client.h | 42 +++++-
drivers/gpu/drm/i915/i915_gem.c | 2 +-
11 files changed, 210 insertions(+), 8 deletions(-)
--
2.39.2
^ permalink raw reply [flat|nested] 23+ messages in thread* [Intel-gfx] [PATCH 1/5] drm/i915: Add ability for tracking buffer objects per client 2023-06-12 10:46 [Intel-gfx] [PATCH v4 0/5] fdinfo memory stats Tvrtko Ursulin @ 2023-06-12 10:46 ` Tvrtko Ursulin 2023-06-12 10:46 ` [Intel-gfx] [PATCH 2/5] drm/i915: Record which client owns a VM Tvrtko Ursulin ` (6 subsequent siblings) 7 siblings, 0 replies; 23+ messages in thread From: Tvrtko Ursulin @ 2023-06-12 10:46 UTC (permalink / raw) To: Intel-gfx, dri-devel From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> In order to show per client memory usage lets add some infrastructure which enables tracking buffer objects owned by clients. We add a per client list protected by a new per client lock and to support delayed destruction (post client exit) we make tracked objects hold references to the owning client. Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> --- drivers/gpu/drm/i915/gem/i915_gem_object.c | 5 +++ .../gpu/drm/i915/gem/i915_gem_object_types.h | 12 +++++++ drivers/gpu/drm/i915/i915_drm_client.c | 36 ++++++++++++++++++- drivers/gpu/drm/i915/i915_drm_client.h | 34 +++++++++++++++++- drivers/gpu/drm/i915/i915_gem.c | 2 +- 5 files changed, 86 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.c b/drivers/gpu/drm/i915/gem/i915_gem_object.c index 97ac6fb37958..d6961f6818f1 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_object.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c @@ -105,6 +105,10 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj, INIT_LIST_HEAD(&obj->mm.link); +#ifdef CONFIG_PROC_FS + INIT_LIST_HEAD(&obj->client_link); +#endif + INIT_LIST_HEAD(&obj->lut_list); spin_lock_init(&obj->lut_lock); @@ -410,6 +414,7 @@ static void __i915_gem_free_objects(struct drm_i915_private *i915, } __i915_gem_object_pages_fini(obj); + i915_drm_client_remove_object(obj); __i915_gem_free_object(obj); /* But keep the pointer alive for RCU-protected lookups */ diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h index e72c57716bee..8de2b91b3edf 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h +++ b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h @@ -300,6 +300,18 @@ struct drm_i915_gem_object { */ struct i915_address_space *shares_resv_from; +#ifdef CONFIG_PROC_FS + /** + * @client: @i915_drm_client which created the object + */ + struct i915_drm_client *client; + + /** + * @client_link: Link into @i915_drm_client.objects_list + */ + struct list_head client_link; +#endif + union { struct rcu_head rcu; struct llist_node freed; diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index 2a44b3876cb5..3c8d6a46a801 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -17,7 +17,8 @@ #include "i915_gem.h" #include "i915_utils.h" -struct i915_drm_client *i915_drm_client_alloc(void) +struct i915_drm_client * +i915_drm_client_alloc(struct drm_i915_file_private *fpriv) { struct i915_drm_client *client; @@ -28,6 +29,12 @@ struct i915_drm_client *i915_drm_client_alloc(void) kref_init(&client->kref); spin_lock_init(&client->ctx_lock); INIT_LIST_HEAD(&client->ctx_list); +#ifdef CONFIG_PROC_FS + spin_lock_init(&client->objects_lock); + INIT_LIST_HEAD(&client->objects_list); + + client->fpriv = fpriv; +#endif return client; } @@ -108,4 +115,31 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) for (i = 0; i < ARRAY_SIZE(uabi_class_names); i++) show_client_class(p, i915, file_priv->client, i); } + +void i915_drm_client_add_object(struct i915_drm_client *client, + struct drm_i915_gem_object *obj) +{ + GEM_WARN_ON(obj->client); + GEM_WARN_ON(!list_empty(&obj->client_link)); + + spin_lock(&client->objects_lock); + obj->client = i915_drm_client_get(client); + list_add_tail(&obj->client_link, &client->objects_list); + spin_unlock(&client->objects_lock); +} + +void i915_drm_client_remove_object(struct drm_i915_gem_object *obj) +{ + struct i915_drm_client *client = fetch_and_zero(&obj->client); + + /* Object may not be associated with a client. */ + if (!client || list_empty(&obj->client_link)) + return; + + spin_lock(&client->objects_lock); + list_del(&obj->client_link); + spin_unlock(&client->objects_lock); + + i915_drm_client_put(client); +} #endif diff --git a/drivers/gpu/drm/i915/i915_drm_client.h b/drivers/gpu/drm/i915/i915_drm_client.h index 4c18b99e10a4..5fc897ab1a6b 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.h +++ b/drivers/gpu/drm/i915/i915_drm_client.h @@ -12,6 +12,9 @@ #include <uapi/drm/i915_drm.h> +#include "i915_file_private.h" +#include "gem/i915_gem_object_types.h" + #define I915_LAST_UABI_ENGINE_CLASS I915_ENGINE_CLASS_COMPUTE struct drm_file; @@ -25,6 +28,22 @@ struct i915_drm_client { spinlock_t ctx_lock; /* For add/remove from ctx_list. */ struct list_head ctx_list; /* List of contexts belonging to client. */ +#ifdef CONFIG_PROC_FS + struct drm_i915_file_private *fpriv; + + /** + * @objects_lock: lock protecting @objects_list + */ + spinlock_t objects_lock; + + /** + * @objects_list: list of objects created by this client + * + * Protected by @objects_lock. + */ + struct list_head objects_list; +#endif + /** * @past_runtime: Accumulation of pphwsp runtimes from closed contexts. */ @@ -45,10 +64,23 @@ static inline void i915_drm_client_put(struct i915_drm_client *client) kref_put(&client->kref, __i915_drm_client_free); } -struct i915_drm_client *i915_drm_client_alloc(void); +struct i915_drm_client *i915_drm_client_alloc(struct drm_i915_file_private *fpriv); #ifdef CONFIG_PROC_FS void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file); + +void i915_drm_client_add_object(struct i915_drm_client *client, + struct drm_i915_gem_object *obj); +void i915_drm_client_remove_object(struct drm_i915_gem_object *obj); +#else +static inline void i915_drm_client_add_object(struct i915_drm_client *client, + struct drm_i915_gem_object *obj) +{ +} + +static inline void i915_drm_client_remove_object(struct drm_i915_gem_object *obj) +{ +} #endif #endif /* !__I915_DRM_CLIENT_H__ */ diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 1f65bb33dd21..7ae42f746cc2 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -1325,7 +1325,7 @@ int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file) if (!file_priv) goto err_alloc; - client = i915_drm_client_alloc(); + client = i915_drm_client_alloc(file_priv); if (!client) goto err_client; -- 2.39.2 ^ permalink raw reply related [flat|nested] 23+ messages in thread
* [Intel-gfx] [PATCH 2/5] drm/i915: Record which client owns a VM 2023-06-12 10:46 [Intel-gfx] [PATCH v4 0/5] fdinfo memory stats Tvrtko Ursulin 2023-06-12 10:46 ` [Intel-gfx] [PATCH 1/5] drm/i915: Add ability for tracking buffer objects per client Tvrtko Ursulin @ 2023-06-12 10:46 ` Tvrtko Ursulin 2023-06-12 10:46 ` [Intel-gfx] [PATCH 3/5] drm/i915: Track page table backing store usage Tvrtko Ursulin ` (5 subsequent siblings) 7 siblings, 0 replies; 23+ messages in thread From: Tvrtko Ursulin @ 2023-06-12 10:46 UTC (permalink / raw) To: Intel-gfx, dri-devel From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> To enable accounting of indirect client memory usage (such as page tables) in the following patch, lets start recording the creator of each PPGTT. Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> --- drivers/gpu/drm/i915/gem/i915_gem_context.c | 11 ++++++++--- drivers/gpu/drm/i915/gem/i915_gem_context_types.h | 3 +++ drivers/gpu/drm/i915/gem/selftests/mock_context.c | 4 ++-- drivers/gpu/drm/i915/gt/intel_gtt.h | 1 + 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c index 9a9ff84c90d7..35cf6608180e 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -279,7 +279,8 @@ static int proto_context_set_protected(struct drm_i915_private *i915, } static struct i915_gem_proto_context * -proto_context_create(struct drm_i915_private *i915, unsigned int flags) +proto_context_create(struct drm_i915_file_private *fpriv, + struct drm_i915_private *i915, unsigned int flags) { struct i915_gem_proto_context *pc, *err; @@ -287,6 +288,7 @@ proto_context_create(struct drm_i915_private *i915, unsigned int flags) if (!pc) return ERR_PTR(-ENOMEM); + pc->fpriv = fpriv; pc->num_user_engines = -1; pc->user_engines = NULL; pc->user_flags = BIT(UCONTEXT_BANNABLE) | @@ -1621,6 +1623,7 @@ i915_gem_create_context(struct drm_i915_private *i915, err = PTR_ERR(ppgtt); goto err_ctx; } + ppgtt->vm.fpriv = pc->fpriv; vm = &ppgtt->vm; } if (vm) @@ -1740,7 +1743,7 @@ int i915_gem_context_open(struct drm_i915_private *i915, /* 0 reserved for invalid/unassigned ppgtt */ xa_init_flags(&file_priv->vm_xa, XA_FLAGS_ALLOC1); - pc = proto_context_create(i915, 0); + pc = proto_context_create(file_priv, i915, 0); if (IS_ERR(pc)) { err = PTR_ERR(pc); goto err; @@ -1822,6 +1825,7 @@ int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data, GEM_BUG_ON(id == 0); /* reserved for invalid/unassigned ppgtt */ args->vm_id = id; + ppgtt->vm.fpriv = file_priv; return 0; err_put: @@ -2284,7 +2288,8 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data, return -EIO; } - ext_data.pc = proto_context_create(i915, args->flags); + ext_data.pc = proto_context_create(file->driver_priv, i915, + args->flags); if (IS_ERR(ext_data.pc)) return PTR_ERR(ext_data.pc); diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context_types.h b/drivers/gpu/drm/i915/gem/i915_gem_context_types.h index cb78214a7dcd..c573c067779f 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context_types.h +++ b/drivers/gpu/drm/i915/gem/i915_gem_context_types.h @@ -188,6 +188,9 @@ struct i915_gem_proto_engine { * CONTEXT_CREATE_SET_PARAM during GEM_CONTEXT_CREATE. */ struct i915_gem_proto_context { + /** @fpriv: Client which creates the context */ + struct drm_i915_file_private *fpriv; + /** @vm: See &i915_gem_context.vm */ struct i915_address_space *vm; diff --git a/drivers/gpu/drm/i915/gem/selftests/mock_context.c b/drivers/gpu/drm/i915/gem/selftests/mock_context.c index 8ac6726ec16b..125584ada282 100644 --- a/drivers/gpu/drm/i915/gem/selftests/mock_context.c +++ b/drivers/gpu/drm/i915/gem/selftests/mock_context.c @@ -83,7 +83,7 @@ live_context(struct drm_i915_private *i915, struct file *file) int err; u32 id; - pc = proto_context_create(i915, 0); + pc = proto_context_create(fpriv, i915, 0); if (IS_ERR(pc)) return ERR_CAST(pc); @@ -152,7 +152,7 @@ kernel_context(struct drm_i915_private *i915, struct i915_gem_context *ctx; struct i915_gem_proto_context *pc; - pc = proto_context_create(i915, 0); + pc = proto_context_create(NULL, i915, 0); if (IS_ERR(pc)) return ERR_CAST(pc); diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.h b/drivers/gpu/drm/i915/gt/intel_gtt.h index 4d6296cdbcfd..7192a534a654 100644 --- a/drivers/gpu/drm/i915/gt/intel_gtt.h +++ b/drivers/gpu/drm/i915/gt/intel_gtt.h @@ -248,6 +248,7 @@ struct i915_address_space { struct drm_mm mm; struct intel_gt *gt; struct drm_i915_private *i915; + struct drm_i915_file_private *fpriv; struct device *dma; u64 total; /* size addr space maps (ex. 2GB for ggtt) */ u64 reserved; /* size addr space reserved */ -- 2.39.2 ^ permalink raw reply related [flat|nested] 23+ messages in thread
* [Intel-gfx] [PATCH 3/5] drm/i915: Track page table backing store usage 2023-06-12 10:46 [Intel-gfx] [PATCH v4 0/5] fdinfo memory stats Tvrtko Ursulin 2023-06-12 10:46 ` [Intel-gfx] [PATCH 1/5] drm/i915: Add ability for tracking buffer objects per client Tvrtko Ursulin 2023-06-12 10:46 ` [Intel-gfx] [PATCH 2/5] drm/i915: Record which client owns a VM Tvrtko Ursulin @ 2023-06-12 10:46 ` Tvrtko Ursulin 2023-06-12 10:46 ` [Intel-gfx] [PATCH 4/5] drm/i915: Account ring buffer and context state storage Tvrtko Ursulin ` (4 subsequent siblings) 7 siblings, 0 replies; 23+ messages in thread From: Tvrtko Ursulin @ 2023-06-12 10:46 UTC (permalink / raw) To: Intel-gfx, dri-devel From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Account page table backing store against the owning client memory usage stats. Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> --- drivers/gpu/drm/i915/gt/intel_gtt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.c b/drivers/gpu/drm/i915/gt/intel_gtt.c index 2f6a9be0ffe6..126269a0d728 100644 --- a/drivers/gpu/drm/i915/gt/intel_gtt.c +++ b/drivers/gpu/drm/i915/gt/intel_gtt.c @@ -58,6 +58,9 @@ struct drm_i915_gem_object *alloc_pt_lmem(struct i915_address_space *vm, int sz) if (!IS_ERR(obj)) { obj->base.resv = i915_vm_resv_get(vm); obj->shares_resv_from = vm; + + if (vm->fpriv) + i915_drm_client_add_object(vm->fpriv->client, obj); } return obj; @@ -79,6 +82,9 @@ struct drm_i915_gem_object *alloc_pt_dma(struct i915_address_space *vm, int sz) if (!IS_ERR(obj)) { obj->base.resv = i915_vm_resv_get(vm); obj->shares_resv_from = vm; + + if (vm->fpriv) + i915_drm_client_add_object(vm->fpriv->client, obj); } return obj; -- 2.39.2 ^ permalink raw reply related [flat|nested] 23+ messages in thread
* [Intel-gfx] [PATCH 4/5] drm/i915: Account ring buffer and context state storage 2023-06-12 10:46 [Intel-gfx] [PATCH v4 0/5] fdinfo memory stats Tvrtko Ursulin ` (2 preceding siblings ...) 2023-06-12 10:46 ` [Intel-gfx] [PATCH 3/5] drm/i915: Track page table backing store usage Tvrtko Ursulin @ 2023-06-12 10:46 ` Tvrtko Ursulin 2023-06-12 10:46 ` [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin ` (3 subsequent siblings) 7 siblings, 0 replies; 23+ messages in thread From: Tvrtko Ursulin @ 2023-06-12 10:46 UTC (permalink / raw) To: Intel-gfx, dri-devel From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Account ring buffers and logical context space against the owning client memory usage stats. Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> --- drivers/gpu/drm/i915/gt/intel_context.c | 8 ++++++++ drivers/gpu/drm/i915/i915_drm_client.c | 10 ++++++++++ drivers/gpu/drm/i915/i915_drm_client.h | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/drivers/gpu/drm/i915/gt/intel_context.c b/drivers/gpu/drm/i915/gt/intel_context.c index a53b26178f0a..cb6d8e7cdd9d 100644 --- a/drivers/gpu/drm/i915/gt/intel_context.c +++ b/drivers/gpu/drm/i915/gt/intel_context.c @@ -6,6 +6,7 @@ #include "gem/i915_gem_context.h" #include "gem/i915_gem_pm.h" +#include "i915_drm_client.h" #include "i915_drv.h" #include "i915_trace.h" @@ -50,6 +51,7 @@ intel_context_create(struct intel_engine_cs *engine) int intel_context_alloc_state(struct intel_context *ce) { + struct i915_gem_context *ctx; int err = 0; if (mutex_lock_interruptible(&ce->pin_mutex)) @@ -66,6 +68,12 @@ int intel_context_alloc_state(struct intel_context *ce) goto unlock; set_bit(CONTEXT_ALLOC_BIT, &ce->flags); + + rcu_read_lock(); + ctx = rcu_dereference(ce->gem_context); + if (ctx && ctx->file_priv) + i915_drm_client_add_context(ctx->file_priv->client, ce); + rcu_read_unlock(); } unlock: diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index 3c8d6a46a801..da29d01d1c3d 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -142,4 +142,14 @@ void i915_drm_client_remove_object(struct drm_i915_gem_object *obj) i915_drm_client_put(client); } + +void i915_drm_client_add_context(struct i915_drm_client *client, + struct intel_context *ce) +{ + if (ce->state) + i915_drm_client_add_object(client, ce->state->obj); + + if (ce->ring != ce->engine->legacy.ring && ce->ring->vma) + i915_drm_client_add_object(client, ce->ring->vma->obj); +} #endif diff --git a/drivers/gpu/drm/i915/i915_drm_client.h b/drivers/gpu/drm/i915/i915_drm_client.h index 5fc897ab1a6b..744e48ed133c 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.h +++ b/drivers/gpu/drm/i915/i915_drm_client.h @@ -14,6 +14,7 @@ #include "i915_file_private.h" #include "gem/i915_gem_object_types.h" +#include "gt/intel_context_types.h" #define I915_LAST_UABI_ENGINE_CLASS I915_ENGINE_CLASS_COMPUTE @@ -72,6 +73,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file); void i915_drm_client_add_object(struct i915_drm_client *client, struct drm_i915_gem_object *obj); void i915_drm_client_remove_object(struct drm_i915_gem_object *obj); +void i915_drm_client_add_context(struct i915_drm_client *client, + struct intel_context *ce); #else static inline void i915_drm_client_add_object(struct i915_drm_client *client, struct drm_i915_gem_object *obj) @@ -81,6 +84,11 @@ static inline void i915_drm_client_add_object(struct i915_drm_client *client, static inline void i915_drm_client_remove_object(struct drm_i915_gem_object *obj) { } + +static inline void i915_drm_client_add_context(struct i915_drm_client *client, + struct intel_context *ce) +{ +} #endif #endif /* !__I915_DRM_CLIENT_H__ */ -- 2.39.2 ^ permalink raw reply related [flat|nested] 23+ messages in thread
* [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-06-12 10:46 [Intel-gfx] [PATCH v4 0/5] fdinfo memory stats Tvrtko Ursulin ` (3 preceding siblings ...) 2023-06-12 10:46 ` [Intel-gfx] [PATCH 4/5] drm/i915: Account ring buffer and context state storage Tvrtko Ursulin @ 2023-06-12 10:46 ` Tvrtko Ursulin 2023-06-12 12:45 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for fdinfo memory stats (rev3) Patchwork ` (2 subsequent siblings) 7 siblings, 0 replies; 23+ messages in thread From: Tvrtko Ursulin @ 2023-06-12 10:46 UTC (permalink / raw) To: Intel-gfx, dri-devel From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Use the newly added drm_print_memory_stats helper to show memory utilisation of our objects in drm/driver specific fdinfo output. To collect the stats we walk the per memory regions object lists and accumulate object size into the respective drm_memory_stats categories. Objects with multiple possible placements are reported in multiple regions for total and shared sizes, while other categories are counted only for the currently active region. Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> Cc: Rob Clark <robdclark@gmail.com> --- drivers/gpu/drm/i915/i915_drm_client.c | 78 ++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index da29d01d1c3d..406e5a5c2961 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -48,6 +48,82 @@ void __i915_drm_client_free(struct kref *kref) } #ifdef CONFIG_PROC_FS +static void +obj_meminfo(struct drm_i915_gem_object *obj, + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) +{ + struct intel_memory_region *mr; + u64 sz = obj->base.size; + enum intel_region_id id; + unsigned int i; + + /* Attribute size and shared to all possible memory regions. */ + for (i = 0; i < obj->mm.n_placements; i++) { + mr = obj->mm.placements[i]; + id = mr->id; + + if (obj->base.handle_count > 1) + stats[id].shared += sz; + else + stats[id].private += sz; + } + + /* Attribute other categories to only the current region. */ + mr = obj->mm.region; + if (mr) + id = mr->id; + else + id = INTEL_REGION_SMEM; + + if (!obj->mm.n_placements) { + if (obj->base.handle_count > 1) + stats[id].shared += sz; + else + stats[id].private += sz; + } + + if (i915_gem_object_has_pages(obj)) { + stats[id].resident += sz; + + if (!dma_resv_test_signaled(obj->base.resv, + dma_resv_usage_rw(true))) + stats[id].active += sz; + else if (i915_gem_object_is_shrinkable(obj) && + obj->mm.madv == I915_MADV_DONTNEED) + stats[id].purgeable += sz; + } +} + +static void show_meminfo(struct drm_printer *p, struct drm_file *file) +{ + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; + struct drm_i915_file_private *fpriv = file->driver_priv; + struct i915_drm_client *client = fpriv->client; + struct drm_i915_private *i915 = fpriv->i915; + struct drm_i915_gem_object *obj; + struct intel_memory_region *mr; + unsigned int id; + + /* Public objects. */ + spin_lock(&file->table_lock); + idr_for_each_entry (&file->object_idr, obj, id) + obj_meminfo(obj, stats); + spin_unlock(&file->table_lock); + + /* Internal objects. */ + spin_lock(&client->objects_lock); + list_for_each_entry(obj, &client->objects_list, client_link) + obj_meminfo(obj, stats); + spin_unlock(&client->objects_lock); + + for_each_memory_region(mr, i915, id) + drm_print_memory_stats(p, + &stats[id], + DRM_GEM_OBJECT_RESIDENT | + DRM_GEM_OBJECT_PURGEABLE, + mr->name); +} + static const char * const uabi_class_names[] = { [I915_ENGINE_CLASS_RENDER] = "render", [I915_ENGINE_CLASS_COPY] = "copy", @@ -109,6 +185,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) * ****************************************************************** */ + show_meminfo(p, file); + if (GRAPHICS_VER(i915) < 8) return; -- 2.39.2 ^ permalink raw reply related [flat|nested] 23+ messages in thread
* [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for fdinfo memory stats (rev3) 2023-06-12 10:46 [Intel-gfx] [PATCH v4 0/5] fdinfo memory stats Tvrtko Ursulin ` (4 preceding siblings ...) 2023-06-12 10:46 ` [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin @ 2023-06-12 12:45 ` Patchwork 2023-06-12 12:45 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork 2023-06-12 13:02 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork 7 siblings, 0 replies; 23+ messages in thread From: Patchwork @ 2023-06-12 12:45 UTC (permalink / raw) To: Tvrtko Ursulin; +Cc: intel-gfx == Series Details == Series: fdinfo memory stats (rev3) URL : https://patchwork.freedesktop.org/series/119082/ State : warning == Summary == Error: dim checkpatch failed 0e7a9361b003 drm/i915: Add ability for tracking buffer objects per client e0e7d111353c drm/i915: Record which client owns a VM 8645bd51fede drm/i915: Track page table backing store usage eb2fd9e3fbbe drm/i915: Account ring buffer and context state storage 02d2f2e3e48f drm/i915: Implement fdinfo memory stats printing -:87: WARNING:SPACING: space prohibited between function name and open parenthesis '(' #87: FILE: drivers/gpu/drm/i915/i915_drm_client.c:109: + idr_for_each_entry (&file->object_idr, obj, id) total: 0 errors, 1 warnings, 0 checks, 90 lines checked ^ permalink raw reply [flat|nested] 23+ messages in thread
* [Intel-gfx] ✗ Fi.CI.SPARSE: warning for fdinfo memory stats (rev3) 2023-06-12 10:46 [Intel-gfx] [PATCH v4 0/5] fdinfo memory stats Tvrtko Ursulin ` (5 preceding siblings ...) 2023-06-12 12:45 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for fdinfo memory stats (rev3) Patchwork @ 2023-06-12 12:45 ` Patchwork 2023-06-12 13:02 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork 7 siblings, 0 replies; 23+ messages in thread From: Patchwork @ 2023-06-12 12:45 UTC (permalink / raw) To: Tvrtko Ursulin; +Cc: intel-gfx == Series Details == Series: fdinfo memory stats (rev3) URL : https://patchwork.freedesktop.org/series/119082/ State : warning == Summary == Error: dim sparse failed Sparse version: v0.6.2 Fast mode used, each commit won't be checked separately. ^ permalink raw reply [flat|nested] 23+ messages in thread
* [Intel-gfx] ✗ Fi.CI.BAT: failure for fdinfo memory stats (rev3) 2023-06-12 10:46 [Intel-gfx] [PATCH v4 0/5] fdinfo memory stats Tvrtko Ursulin ` (6 preceding siblings ...) 2023-06-12 12:45 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork @ 2023-06-12 13:02 ` Patchwork 7 siblings, 0 replies; 23+ messages in thread From: Patchwork @ 2023-06-12 13:02 UTC (permalink / raw) To: Tvrtko Ursulin; +Cc: intel-gfx [-- Attachment #1: Type: text/plain, Size: 7425 bytes --] == Series Details == Series: fdinfo memory stats (rev3) URL : https://patchwork.freedesktop.org/series/119082/ State : failure == Summary == CI Bug Log - changes from CI_DRM_13262 -> Patchwork_119082v3 ==================================================== Summary ------- **FAILURE** Serious unknown changes coming with Patchwork_119082v3 absolutely need to be verified manually. If you think the reported changes have nothing to do with the changes introduced in Patchwork_119082v3, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI. External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119082v3/index.html Participating hosts (42 -> 41) ------------------------------ Missing (1): fi-snb-2520m Possible new issues ------------------- Here are the unknown changes that may have been introduced in Patchwork_119082v3: ### IGT changes ### #### Possible regressions #### * igt@gem_busy@busy@all-engines: - bat-dg1-5: [PASS][1] -> [ABORT][2] [1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13262/bat-dg1-5/igt@gem_busy@busy@all-engines.html [2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119082v3/bat-dg1-5/igt@gem_busy@busy@all-engines.html - bat-dg1-7: [PASS][3] -> [ABORT][4] [3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13262/bat-dg1-7/igt@gem_busy@busy@all-engines.html [4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119082v3/bat-dg1-7/igt@gem_busy@busy@all-engines.html - bat-dg2-9: [PASS][5] -> [ABORT][6] [5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13262/bat-dg2-9/igt@gem_busy@busy@all-engines.html [6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119082v3/bat-dg2-9/igt@gem_busy@busy@all-engines.html - bat-atsm-1: [PASS][7] -> [ABORT][8] [7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13262/bat-atsm-1/igt@gem_busy@busy@all-engines.html [8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119082v3/bat-atsm-1/igt@gem_busy@busy@all-engines.html - bat-dg2-11: [PASS][9] -> [ABORT][10] [9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13262/bat-dg2-11/igt@gem_busy@busy@all-engines.html [10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119082v3/bat-dg2-11/igt@gem_busy@busy@all-engines.html - bat-dg2-8: [PASS][11] -> [ABORT][12] [11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13262/bat-dg2-8/igt@gem_busy@busy@all-engines.html [12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119082v3/bat-dg2-8/igt@gem_busy@busy@all-engines.html Known issues ------------ Here are the changes found in Patchwork_119082v3 that come from known issues: ### IGT changes ### #### Issues hit #### * igt@i915_selftest@live@gt_heartbeat: - fi-kbl-soraka: [PASS][13] -> [DMESG-FAIL][14] ([i915#5334] / [i915#7872]) [13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13262/fi-kbl-soraka/igt@i915_selftest@live@gt_heartbeat.html [14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119082v3/fi-kbl-soraka/igt@i915_selftest@live@gt_heartbeat.html * igt@i915_selftest@live@reset: - bat-rpls-2: [PASS][15] -> [ABORT][16] ([i915#4983] / [i915#7461] / [i915#7913] / [i915#7981] / [i915#8347]) [15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13262/bat-rpls-2/igt@i915_selftest@live@reset.html [16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119082v3/bat-rpls-2/igt@i915_selftest@live@reset.html * igt@i915_suspend@basic-s3-without-i915: - bat-rpls-1: NOTRUN -> [ABORT][17] ([i915#6687] / [i915#7978]) [17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119082v3/bat-rpls-1/igt@i915_suspend@basic-s3-without-i915.html #### Possible fixes #### * igt@i915_selftest@live@reset: - bat-rpls-1: [ABORT][18] ([i915#4983] / [i915#7461] / [i915#8347] / [i915#8384]) -> [PASS][19] [18]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13262/bat-rpls-1/igt@i915_selftest@live@reset.html [19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119082v3/bat-rpls-1/igt@i915_selftest@live@reset.html * igt@i915_selftest@live@slpc: - {bat-mtlp-6}: [DMESG-WARN][20] ([i915#6367]) -> [PASS][21] [20]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13262/bat-mtlp-6/igt@i915_selftest@live@slpc.html [21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119082v3/bat-mtlp-6/igt@i915_selftest@live@slpc.html * igt@kms_psr@cursor_plane_move: - fi-kbl-soraka: [INCOMPLETE][22] -> [PASS][23] [22]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13262/fi-kbl-soraka/igt@kms_psr@cursor_plane_move.html [23]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119082v3/fi-kbl-soraka/igt@kms_psr@cursor_plane_move.html {name}: This element is suppressed. This means it is ignored when computing the status of the difference (SUCCESS, WARNING, or FAILURE). [fdo#109285]: https://bugs.freedesktop.org/show_bug.cgi?id=109285 [i915#3708]: https://gitlab.freedesktop.org/drm/intel/issues/3708 [i915#4077]: https://gitlab.freedesktop.org/drm/intel/issues/4077 [i915#4213]: https://gitlab.freedesktop.org/drm/intel/issues/4213 [i915#4423]: https://gitlab.freedesktop.org/drm/intel/issues/4423 [i915#4579]: https://gitlab.freedesktop.org/drm/intel/issues/4579 [i915#4613]: https://gitlab.freedesktop.org/drm/intel/issues/4613 [i915#4983]: https://gitlab.freedesktop.org/drm/intel/issues/4983 [i915#5274]: https://gitlab.freedesktop.org/drm/intel/issues/5274 [i915#5334]: https://gitlab.freedesktop.org/drm/intel/issues/5334 [i915#6367]: https://gitlab.freedesktop.org/drm/intel/issues/6367 [i915#6621]: https://gitlab.freedesktop.org/drm/intel/issues/6621 [i915#6645]: https://gitlab.freedesktop.org/drm/intel/issues/6645 [i915#6687]: https://gitlab.freedesktop.org/drm/intel/issues/6687 [i915#7059]: https://gitlab.freedesktop.org/drm/intel/issues/7059 [i915#7461]: https://gitlab.freedesktop.org/drm/intel/issues/7461 [i915#7828]: https://gitlab.freedesktop.org/drm/intel/issues/7828 [i915#7872]: https://gitlab.freedesktop.org/drm/intel/issues/7872 [i915#7913]: https://gitlab.freedesktop.org/drm/intel/issues/7913 [i915#7978]: https://gitlab.freedesktop.org/drm/intel/issues/7978 [i915#7981]: https://gitlab.freedesktop.org/drm/intel/issues/7981 [i915#8347]: https://gitlab.freedesktop.org/drm/intel/issues/8347 [i915#8384]: https://gitlab.freedesktop.org/drm/intel/issues/8384 Build changes ------------- * Linux: CI_DRM_13262 -> Patchwork_119082v3 CI-20190529: 20190529 CI_DRM_13262: 26f62dc5b6119b2fcc3380b76e25dbe3903060a0 @ git://anongit.freedesktop.org/gfx-ci/linux IGT_7326: 02c2cf17628b6203d6105d4a91dfe8a101d482ce @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git Patchwork_119082v3: 26f62dc5b6119b2fcc3380b76e25dbe3903060a0 @ git://anongit.freedesktop.org/gfx-ci/linux ### Linux commits 0497e4b1f7c2 drm/i915: Implement fdinfo memory stats printing 942364187b4f drm/i915: Account ring buffer and context state storage a6a8bce070ce drm/i915: Track page table backing store usage 6eaa9cbe37cb drm/i915: Record which client owns a VM 15570a43e2fe drm/i915: Add ability for tracking buffer objects per client == Logs == For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_119082v3/index.html [-- Attachment #2: Type: text/html, Size: 7693 bytes --] ^ permalink raw reply [flat|nested] 23+ messages in thread
* [Intel-gfx] [PATCH v7 0/5] fdinfo memory stats @ 2023-09-21 11:48 Tvrtko Ursulin 2023-09-21 11:48 ` [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 0 siblings, 1 reply; 23+ messages in thread From: Tvrtko Ursulin @ 2023-09-21 11:48 UTC (permalink / raw) To: Intel-gfx, dri-devel From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> A short series to enable fdinfo memory stats for i915. I added tracking of most classes of objects (user objects, page tables, context state, ring buffers) which contribute to client's memory footprint and am accouting their memory use along the similar lines as in Rob's msm code, just that with i915 specific code we can show a memory region breakdown and so support discrete and multi-tile GPUs properly. And also reflect that our objects can have multiple allowed backing stores. The existing helper Rob added is then used to dump the per memory region stats to fdinfo. The basic objects-per-client infrastructure can later be extended to cover all objects and so avoid needing to walk the IDR under the client's file table lock, which would further avoid distburbing the running clients by parallel fdinfo readers. Example fdinfo format: # cat /proc/1383/fdinfo/8 pos: 0 flags: 02100002 mnt_id: 21 ino: 397 drm-driver: i915 drm-client-id: 18 drm-pdev: 0000:00:02.0 drm-total-system: 125 MiB drm-shared-system: 16 MiB drm-active-system: 110 MiB drm-resident-system: 125 MiB drm-purgeable-system: 2 MiB drm-total-stolen-system: 0 drm-shared-stolen-system: 0 drm-active-stolen-system: 0 drm-resident-stolen-system: 0 drm-purgeable-stolen-system: 0 drm-engine-render: 25662044495 ns drm-engine-copy: 0 ns drm-engine-video: 0 ns drm-engine-video-enhance: 0 ns Example gputop output: DRM minor 0 PID SMEM SMEMRSS render copy video NAME 1233 124M 124M |████████|| || || | neverball 1130 59M 59M |█▌ || || || | Xorg 1207 12M 12M | || || || | xfwm4 Or with Wayland: DRM minor 0 PID MEM RSS render copy video video-enhance NAME 2093 191M 191M |▊ || || || | gnome-shell DRM minor 128 PID MEM RSS render copy video video-enhance NAME 2551 71M 71M |██▉ || || || | neverball 2553 50M 50M | || || || | Xwayland v2: * Now actually per client. v3: * Track imported dma-buf objects. v4: * Rely on DRM GEM handles for tracking user objects. * Fix internal object accounting (no placements). v5: * Fixed brain fart of overwriting the loop cursor. * Fixed object destruction racing with fdinfo reads. * Take reference to GEM context while using it. v6: * Rebase, cover letter update. v7: * Account against active region only. * Cover all dma_resv usage when testing for activity. Test-with: 20230921114557.192629-1-tvrtko.ursulin@linux.intel.com Tvrtko Ursulin (5): drm/i915: Add ability for tracking buffer objects per client drm/i915: Record which client owns a VM drm/i915: Track page table backing store usage drm/i915: Account ring buffer and context state storage drm/i915: Implement fdinfo memory stats printing drivers/gpu/drm/i915/gem/i915_gem_context.c | 11 +- .../gpu/drm/i915/gem/i915_gem_context_types.h | 3 + drivers/gpu/drm/i915/gem/i915_gem_object.c | 13 ++- .../gpu/drm/i915/gem/i915_gem_object_types.h | 12 ++ .../gpu/drm/i915/gem/selftests/mock_context.c | 4 +- drivers/gpu/drm/i915/gt/intel_context.c | 14 +++ drivers/gpu/drm/i915/gt/intel_gtt.c | 6 + drivers/gpu/drm/i915/gt/intel_gtt.h | 1 + drivers/gpu/drm/i915/i915_drm_client.c | 110 ++++++++++++++++++ drivers/gpu/drm/i915/i915_drm_client.h | 41 +++++++ 10 files changed, 207 insertions(+), 8 deletions(-) -- 2.39.2 ^ permalink raw reply [flat|nested] 23+ messages in thread
* [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-09-21 11:48 [Intel-gfx] [PATCH v7 0/5] fdinfo memory stats Tvrtko Ursulin @ 2023-09-21 11:48 ` Tvrtko Ursulin 2023-09-22 8:48 ` Iddamsetty, Aravind 2023-09-22 11:01 ` Andi Shyti 0 siblings, 2 replies; 23+ messages in thread From: Tvrtko Ursulin @ 2023-09-21 11:48 UTC (permalink / raw) To: Intel-gfx, dri-devel From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Use the newly added drm_print_memory_stats helper to show memory utilisation of our objects in drm/driver specific fdinfo output. To collect the stats we walk the per memory regions object lists and accumulate object size into the respective drm_memory_stats categories. Objects with multiple possible placements are reported in multiple regions for total and shared sizes, while other categories are counted only for the currently active region. v2: * Only account against the active region. * Use DMA_RESV_USAGE_BOOKKEEP when testing for active. (Tejas) Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> Cc: Rob Clark <robdclark@gmail.com> Cc: Andi Shyti <andi.shyti@linux.intel.com> Cc: Tejas Upadhyay <tejas.upadhyay@intel.com> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> # v1 --- drivers/gpu/drm/i915/i915_drm_client.c | 64 ++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index a61356012df8..94abc2fb2ea6 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -45,6 +45,68 @@ void __i915_drm_client_free(struct kref *kref) } #ifdef CONFIG_PROC_FS +static void +obj_meminfo(struct drm_i915_gem_object *obj, + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) +{ + const enum intel_region_id id = obj->mm.region ? + obj->mm.region->id : INTEL_REGION_SMEM; + const u64 sz = obj->base.size; + + if (obj->base.handle_count > 1) + stats[id].shared += sz; + else + stats[id].private += sz; + + if (i915_gem_object_has_pages(obj)) { + stats[id].resident += sz; + + if (!dma_resv_test_signaled(obj->base.resv, + DMA_RESV_USAGE_BOOKKEEP)) + stats[id].active += sz; + else if (i915_gem_object_is_shrinkable(obj) && + obj->mm.madv == I915_MADV_DONTNEED) + stats[id].purgeable += sz; + } +} + +static void show_meminfo(struct drm_printer *p, struct drm_file *file) +{ + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; + struct drm_i915_file_private *fpriv = file->driver_priv; + struct i915_drm_client *client = fpriv->client; + struct drm_i915_private *i915 = fpriv->i915; + struct drm_i915_gem_object *obj; + struct intel_memory_region *mr; + struct list_head *pos; + unsigned int id; + + /* Public objects. */ + spin_lock(&file->table_lock); + idr_for_each_entry(&file->object_idr, obj, id) + obj_meminfo(obj, stats); + spin_unlock(&file->table_lock); + + /* Internal objects. */ + rcu_read_lock(); + list_for_each_rcu(pos, &client->objects_list) { + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), + client_link)); + if (!obj) + continue; + obj_meminfo(obj, stats); + i915_gem_object_put(obj); + } + rcu_read_unlock(); + + for_each_memory_region(mr, i915, id) + drm_print_memory_stats(p, + &stats[id], + DRM_GEM_OBJECT_RESIDENT | + DRM_GEM_OBJECT_PURGEABLE, + mr->name); +} + static const char * const uabi_class_names[] = { [I915_ENGINE_CLASS_RENDER] = "render", [I915_ENGINE_CLASS_COPY] = "copy", @@ -106,6 +168,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) * ****************************************************************** */ + show_meminfo(p, file); + if (GRAPHICS_VER(i915) < 8) return; -- 2.39.2 ^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-09-21 11:48 ` [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin @ 2023-09-22 8:48 ` Iddamsetty, Aravind 2023-09-22 10:57 ` Tvrtko Ursulin 2023-09-22 11:01 ` Andi Shyti 1 sibling, 1 reply; 23+ messages in thread From: Iddamsetty, Aravind @ 2023-09-22 8:48 UTC (permalink / raw) To: Tvrtko Ursulin, Intel-gfx, dri-devel On 21-09-2023 17:18, Tvrtko Ursulin wrote: > From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > > Use the newly added drm_print_memory_stats helper to show memory > utilisation of our objects in drm/driver specific fdinfo output. > > To collect the stats we walk the per memory regions object lists > and accumulate object size into the respective drm_memory_stats > categories. > > Objects with multiple possible placements are reported in multiple > regions for total and shared sizes, while other categories are I guess you forgot to correct this. > counted only for the currently active region. > > v2: > * Only account against the active region. > * Use DMA_RESV_USAGE_BOOKKEEP when testing for active. (Tejas) > > Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> > Cc: Rob Clark <robdclark@gmail.com> > Cc: Andi Shyti <andi.shyti@linux.intel.com> > Cc: Tejas Upadhyay <tejas.upadhyay@intel.com> > Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> # v1 > --- > drivers/gpu/drm/i915/i915_drm_client.c | 64 ++++++++++++++++++++++++++ > 1 file changed, 64 insertions(+) > > diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c > index a61356012df8..94abc2fb2ea6 100644 > --- a/drivers/gpu/drm/i915/i915_drm_client.c > +++ b/drivers/gpu/drm/i915/i915_drm_client.c > @@ -45,6 +45,68 @@ void __i915_drm_client_free(struct kref *kref) > } > > #ifdef CONFIG_PROC_FS > +static void > +obj_meminfo(struct drm_i915_gem_object *obj, > + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) > +{ > + const enum intel_region_id id = obj->mm.region ? > + obj->mm.region->id : INTEL_REGION_SMEM; > + const u64 sz = obj->base.size; > + > + if (obj->base.handle_count > 1) > + stats[id].shared += sz; > + else > + stats[id].private += sz; > + > + if (i915_gem_object_has_pages(obj)) { > + stats[id].resident += sz; > + > + if (!dma_resv_test_signaled(obj->base.resv, > + DMA_RESV_USAGE_BOOKKEEP)) > + stats[id].active += sz; > + else if (i915_gem_object_is_shrinkable(obj) && > + obj->mm.madv == I915_MADV_DONTNEED) > + stats[id].purgeable += sz; > + } > +} > + > +static void show_meminfo(struct drm_printer *p, struct drm_file *file) > +{ > + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; > + struct drm_i915_file_private *fpriv = file->driver_priv; > + struct i915_drm_client *client = fpriv->client; > + struct drm_i915_private *i915 = fpriv->i915; > + struct drm_i915_gem_object *obj; > + struct intel_memory_region *mr; > + struct list_head *pos; > + unsigned int id; > + > + /* Public objects. */ > + spin_lock(&file->table_lock); > + idr_for_each_entry(&file->object_idr, obj, id) > + obj_meminfo(obj, stats); > + spin_unlock(&file->table_lock); > + > + /* Internal objects. */ > + rcu_read_lock(); > + list_for_each_rcu(pos, &client->objects_list) { > + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), > + client_link)); > + if (!obj) > + continue; > + obj_meminfo(obj, stats); > + i915_gem_object_put(obj); > + } > + rcu_read_unlock(); > + > + for_each_memory_region(mr, i915, id) > + drm_print_memory_stats(p, > + &stats[id], > + DRM_GEM_OBJECT_RESIDENT | > + DRM_GEM_OBJECT_PURGEABLE, > + mr->name); > +} > + > static const char * const uabi_class_names[] = { > [I915_ENGINE_CLASS_RENDER] = "render", > [I915_ENGINE_CLASS_COPY] = "copy", > @@ -106,6 +168,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) > * ****************************************************************** > */ > > + show_meminfo(p, file); > + > if (GRAPHICS_VER(i915) < 8) > return; > Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@intel.com> Thanks, Aravind. ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-09-22 8:48 ` Iddamsetty, Aravind @ 2023-09-22 10:57 ` Tvrtko Ursulin 2023-09-22 12:33 ` Iddamsetty, Aravind 0 siblings, 1 reply; 23+ messages in thread From: Tvrtko Ursulin @ 2023-09-22 10:57 UTC (permalink / raw) To: Iddamsetty, Aravind, Intel-gfx, dri-devel On 22/09/2023 09:48, Iddamsetty, Aravind wrote: > > > On 21-09-2023 17:18, Tvrtko Ursulin wrote: >> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >> >> Use the newly added drm_print_memory_stats helper to show memory >> utilisation of our objects in drm/driver specific fdinfo output. >> >> To collect the stats we walk the per memory regions object lists >> and accumulate object size into the respective drm_memory_stats >> categories. >> >> Objects with multiple possible placements are reported in multiple >> regions for total and shared sizes, while other categories are > > I guess you forgot to correct this. Ah yes, will fix. > >> counted only for the currently active region. >> >> v2: >> * Only account against the active region. >> * Use DMA_RESV_USAGE_BOOKKEEP when testing for active. (Tejas) >> >> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >> Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> >> Cc: Rob Clark <robdclark@gmail.com> >> Cc: Andi Shyti <andi.shyti@linux.intel.com> >> Cc: Tejas Upadhyay <tejas.upadhyay@intel.com> >> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> # v1 >> --- >> drivers/gpu/drm/i915/i915_drm_client.c | 64 ++++++++++++++++++++++++++ >> 1 file changed, 64 insertions(+) >> >> diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c >> index a61356012df8..94abc2fb2ea6 100644 >> --- a/drivers/gpu/drm/i915/i915_drm_client.c >> +++ b/drivers/gpu/drm/i915/i915_drm_client.c >> @@ -45,6 +45,68 @@ void __i915_drm_client_free(struct kref *kref) >> } >> >> #ifdef CONFIG_PROC_FS >> +static void >> +obj_meminfo(struct drm_i915_gem_object *obj, >> + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) >> +{ >> + const enum intel_region_id id = obj->mm.region ? >> + obj->mm.region->id : INTEL_REGION_SMEM; >> + const u64 sz = obj->base.size; >> + >> + if (obj->base.handle_count > 1) >> + stats[id].shared += sz; >> + else >> + stats[id].private += sz; >> + >> + if (i915_gem_object_has_pages(obj)) { >> + stats[id].resident += sz; >> + >> + if (!dma_resv_test_signaled(obj->base.resv, >> + DMA_RESV_USAGE_BOOKKEEP)) >> + stats[id].active += sz; >> + else if (i915_gem_object_is_shrinkable(obj) && >> + obj->mm.madv == I915_MADV_DONTNEED) >> + stats[id].purgeable += sz; >> + } >> +} >> + >> +static void show_meminfo(struct drm_printer *p, struct drm_file *file) >> +{ >> + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; >> + struct drm_i915_file_private *fpriv = file->driver_priv; >> + struct i915_drm_client *client = fpriv->client; >> + struct drm_i915_private *i915 = fpriv->i915; >> + struct drm_i915_gem_object *obj; >> + struct intel_memory_region *mr; >> + struct list_head *pos; >> + unsigned int id; >> + >> + /* Public objects. */ >> + spin_lock(&file->table_lock); >> + idr_for_each_entry(&file->object_idr, obj, id) >> + obj_meminfo(obj, stats); >> + spin_unlock(&file->table_lock); >> + >> + /* Internal objects. */ >> + rcu_read_lock(); >> + list_for_each_rcu(pos, &client->objects_list) { >> + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), >> + client_link)); >> + if (!obj) >> + continue; >> + obj_meminfo(obj, stats); >> + i915_gem_object_put(obj); >> + } >> + rcu_read_unlock(); >> + >> + for_each_memory_region(mr, i915, id) >> + drm_print_memory_stats(p, >> + &stats[id], >> + DRM_GEM_OBJECT_RESIDENT | >> + DRM_GEM_OBJECT_PURGEABLE, >> + mr->name); >> +} >> + >> static const char * const uabi_class_names[] = { >> [I915_ENGINE_CLASS_RENDER] = "render", >> [I915_ENGINE_CLASS_COPY] = "copy", >> @@ -106,6 +168,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) >> * ****************************************************************** >> */ >> >> + show_meminfo(p, file); >> + >> if (GRAPHICS_VER(i915) < 8) >> return; >> > > Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@intel.com> Thank you! Would you be able to also look at the IGTs I posted yesterday? Regards, Tvrtko ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-09-22 10:57 ` Tvrtko Ursulin @ 2023-09-22 12:33 ` Iddamsetty, Aravind 0 siblings, 0 replies; 23+ messages in thread From: Iddamsetty, Aravind @ 2023-09-22 12:33 UTC (permalink / raw) To: Tvrtko Ursulin, Intel-gfx, dri-devel On 22-09-2023 16:27, Tvrtko Ursulin wrote: > > On 22/09/2023 09:48, Iddamsetty, Aravind wrote: >> >> >> On 21-09-2023 17:18, Tvrtko Ursulin wrote: >>> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >>> >>> Use the newly added drm_print_memory_stats helper to show memory >>> utilisation of our objects in drm/driver specific fdinfo output. >>> >>> To collect the stats we walk the per memory regions object lists >>> and accumulate object size into the respective drm_memory_stats >>> categories. >>> >>> Objects with multiple possible placements are reported in multiple >>> regions for total and shared sizes, while other categories are >> >> I guess you forgot to correct this. > > Ah yes, will fix. > >> >>> counted only for the currently active region. >>> >>> v2: >>> * Only account against the active region. >>> * Use DMA_RESV_USAGE_BOOKKEEP when testing for active. (Tejas) >>> >>> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >>> Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> >>> Cc: Rob Clark <robdclark@gmail.com> >>> Cc: Andi Shyti <andi.shyti@linux.intel.com> >>> Cc: Tejas Upadhyay <tejas.upadhyay@intel.com> >>> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> # v1 >>> --- >>> drivers/gpu/drm/i915/i915_drm_client.c | 64 ++++++++++++++++++++++++++ >>> 1 file changed, 64 insertions(+) >>> >>> diff --git a/drivers/gpu/drm/i915/i915_drm_client.c >>> b/drivers/gpu/drm/i915/i915_drm_client.c >>> index a61356012df8..94abc2fb2ea6 100644 >>> --- a/drivers/gpu/drm/i915/i915_drm_client.c >>> +++ b/drivers/gpu/drm/i915/i915_drm_client.c >>> @@ -45,6 +45,68 @@ void __i915_drm_client_free(struct kref *kref) >>> } >>> #ifdef CONFIG_PROC_FS >>> +static void >>> +obj_meminfo(struct drm_i915_gem_object *obj, >>> + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) >>> +{ >>> + const enum intel_region_id id = obj->mm.region ? >>> + obj->mm.region->id : INTEL_REGION_SMEM; >>> + const u64 sz = obj->base.size; >>> + >>> + if (obj->base.handle_count > 1) >>> + stats[id].shared += sz; >>> + else >>> + stats[id].private += sz; >>> + >>> + if (i915_gem_object_has_pages(obj)) { >>> + stats[id].resident += sz; >>> + >>> + if (!dma_resv_test_signaled(obj->base.resv, >>> + DMA_RESV_USAGE_BOOKKEEP)) >>> + stats[id].active += sz; >>> + else if (i915_gem_object_is_shrinkable(obj) && >>> + obj->mm.madv == I915_MADV_DONTNEED) >>> + stats[id].purgeable += sz; >>> + } >>> +} >>> + >>> +static void show_meminfo(struct drm_printer *p, struct drm_file *file) >>> +{ >>> + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; >>> + struct drm_i915_file_private *fpriv = file->driver_priv; >>> + struct i915_drm_client *client = fpriv->client; >>> + struct drm_i915_private *i915 = fpriv->i915; >>> + struct drm_i915_gem_object *obj; >>> + struct intel_memory_region *mr; >>> + struct list_head *pos; >>> + unsigned int id; >>> + >>> + /* Public objects. */ >>> + spin_lock(&file->table_lock); >>> + idr_for_each_entry(&file->object_idr, obj, id) >>> + obj_meminfo(obj, stats); >>> + spin_unlock(&file->table_lock); >>> + >>> + /* Internal objects. */ >>> + rcu_read_lock(); >>> + list_for_each_rcu(pos, &client->objects_list) { >>> + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), >>> + client_link)); >>> + if (!obj) >>> + continue; >>> + obj_meminfo(obj, stats); >>> + i915_gem_object_put(obj); >>> + } >>> + rcu_read_unlock(); >>> + >>> + for_each_memory_region(mr, i915, id) >>> + drm_print_memory_stats(p, >>> + &stats[id], >>> + DRM_GEM_OBJECT_RESIDENT | >>> + DRM_GEM_OBJECT_PURGEABLE, >>> + mr->name); >>> +} >>> + >>> static const char * const uabi_class_names[] = { >>> [I915_ENGINE_CLASS_RENDER] = "render", >>> [I915_ENGINE_CLASS_COPY] = "copy", >>> @@ -106,6 +168,8 @@ void i915_drm_client_fdinfo(struct drm_printer >>> *p, struct drm_file *file) >>> * >>> ****************************************************************** >>> */ >>> + show_meminfo(p, file); >>> + >>> if (GRAPHICS_VER(i915) < 8) >>> return; >>> >> >> Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@intel.com> > > Thank you! Would you be able to also look at the IGTs I posted yesterday? Ya sure will take a look. Thanks, Aravind. > > Regards, > > Tvrtko ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-09-21 11:48 ` [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 2023-09-22 8:48 ` Iddamsetty, Aravind @ 2023-09-22 11:01 ` Andi Shyti 1 sibling, 0 replies; 23+ messages in thread From: Andi Shyti @ 2023-09-22 11:01 UTC (permalink / raw) To: Tvrtko Ursulin; +Cc: Intel-gfx, dri-devel Hi Tvrtko, On Thu, Sep 21, 2023 at 12:48:52PM +0100, Tvrtko Ursulin wrote: > From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > > Use the newly added drm_print_memory_stats helper to show memory > utilisation of our objects in drm/driver specific fdinfo output. > > To collect the stats we walk the per memory regions object lists > and accumulate object size into the respective drm_memory_stats > categories. > > Objects with multiple possible placements are reported in multiple > regions for total and shared sizes, while other categories are > counted only for the currently active region. > > v2: > * Only account against the active region. > * Use DMA_RESV_USAGE_BOOKKEEP when testing for active. (Tejas) > > Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> > Cc: Rob Clark <robdclark@gmail.com> > Cc: Andi Shyti <andi.shyti@linux.intel.com> > Cc: Tejas Upadhyay <tejas.upadhyay@intel.com> > Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> # v1 Reiewed also this version :) Thanks, Andi > --- > drivers/gpu/drm/i915/i915_drm_client.c | 64 ++++++++++++++++++++++++++ > 1 file changed, 64 insertions(+) > > diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c > index a61356012df8..94abc2fb2ea6 100644 > --- a/drivers/gpu/drm/i915/i915_drm_client.c > +++ b/drivers/gpu/drm/i915/i915_drm_client.c > @@ -45,6 +45,68 @@ void __i915_drm_client_free(struct kref *kref) > } > > #ifdef CONFIG_PROC_FS > +static void > +obj_meminfo(struct drm_i915_gem_object *obj, > + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) > +{ > + const enum intel_region_id id = obj->mm.region ? > + obj->mm.region->id : INTEL_REGION_SMEM; > + const u64 sz = obj->base.size; > + > + if (obj->base.handle_count > 1) > + stats[id].shared += sz; > + else > + stats[id].private += sz; > + > + if (i915_gem_object_has_pages(obj)) { > + stats[id].resident += sz; > + > + if (!dma_resv_test_signaled(obj->base.resv, > + DMA_RESV_USAGE_BOOKKEEP)) > + stats[id].active += sz; > + else if (i915_gem_object_is_shrinkable(obj) && > + obj->mm.madv == I915_MADV_DONTNEED) > + stats[id].purgeable += sz; > + } > +} > + > +static void show_meminfo(struct drm_printer *p, struct drm_file *file) > +{ > + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; > + struct drm_i915_file_private *fpriv = file->driver_priv; > + struct i915_drm_client *client = fpriv->client; > + struct drm_i915_private *i915 = fpriv->i915; > + struct drm_i915_gem_object *obj; > + struct intel_memory_region *mr; > + struct list_head *pos; > + unsigned int id; > + > + /* Public objects. */ > + spin_lock(&file->table_lock); > + idr_for_each_entry(&file->object_idr, obj, id) > + obj_meminfo(obj, stats); > + spin_unlock(&file->table_lock); > + > + /* Internal objects. */ > + rcu_read_lock(); > + list_for_each_rcu(pos, &client->objects_list) { > + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), > + client_link)); > + if (!obj) > + continue; > + obj_meminfo(obj, stats); > + i915_gem_object_put(obj); > + } > + rcu_read_unlock(); > + > + for_each_memory_region(mr, i915, id) > + drm_print_memory_stats(p, > + &stats[id], > + DRM_GEM_OBJECT_RESIDENT | > + DRM_GEM_OBJECT_PURGEABLE, > + mr->name); > +} > + > static const char * const uabi_class_names[] = { > [I915_ENGINE_CLASS_RENDER] = "render", > [I915_ENGINE_CLASS_COPY] = "copy", > @@ -106,6 +168,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) > * ****************************************************************** > */ > > + show_meminfo(p, file); > + > if (GRAPHICS_VER(i915) < 8) > return; > > -- > 2.39.2 ^ permalink raw reply [flat|nested] 23+ messages in thread
* [Intel-gfx] [PATCH v6 0/5] fdinfo memory stats @ 2023-07-27 10:13 Tvrtko Ursulin 2023-07-27 10:13 ` [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 0 siblings, 1 reply; 23+ messages in thread From: Tvrtko Ursulin @ 2023-07-27 10:13 UTC (permalink / raw) To: Intel-gfx, dri-devel From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> A short series to enable fdinfo memory stats for i915. I added tracking of most classes of objects (user objects, page tables, context state, ring buffers) which contribute to client's memory footprint and am accouting their memory use along the similar lines as in Rob's msm code, just that with i915 specific code we can show a memory region breakdown and so support discrete and multi-tile GPUs properly. And also reflect that our objects can have multiple allowed backing stores. The existing helper Rob added is then used to dump the per memory region stats to fdinfo. The basic objects-per-client infrastructure can later be extended to cover all objects and so avoid needing to walk the IDR under the client's file table lock, which would further avoid distburbing the running clients by parallel fdinfo readers. Example fdinfo format: # cat /proc/1383/fdinfo/8 pos: 0 flags: 02100002 mnt_id: 21 ino: 397 drm-driver: i915 drm-client-id: 18 drm-pdev: 0000:00:02.0 drm-total-system: 125 MiB drm-shared-system: 16 MiB drm-active-system: 110 MiB drm-resident-system: 125 MiB drm-purgeable-system: 2 MiB drm-total-stolen-system: 0 drm-shared-stolen-system: 0 drm-active-stolen-system: 0 drm-resident-stolen-system: 0 drm-purgeable-stolen-system: 0 drm-engine-render: 25662044495 ns drm-engine-copy: 0 ns drm-engine-video: 0 ns drm-engine-video-enhance: 0 ns Example gputop output: DRM minor 0 PID SMEM SMEMRSS render copy video NAME 1233 124M 124M |████████|| || || | neverball 1130 59M 59M |█▌ || || || | Xorg 1207 12M 12M | || || || | xfwm4 Or with Wayland: DRM minor 0 PID MEM RSS render copy video video-enhance NAME 2093 191M 191M |▊ || || || | gnome-shell DRM minor 128 PID MEM RSS render copy video video-enhance NAME 2551 71M 71M |██▉ || || || | neverball 2553 50M 50M | || || || | Xwayland v2: * Now actually per client. v3: * Track imported dma-buf objects. v4: * Rely on DRM GEM handles for tracking user objects. * Fix internal object accounting (no placements). v5: * Fixed brain fart of overwriting the loop cursor. * Fixed object destruction racing with fdinfo reads. * Take reference to GEM context while using it. v6: * Rebase, cover letter update. Tvrtko Ursulin (5): drm/i915: Add ability for tracking buffer objects per client drm/i915: Record which client owns a VM drm/i915: Track page table backing store usage drm/i915: Account ring buffer and context state storage drm/i915: Implement fdinfo memory stats printing drivers/gpu/drm/i915/gem/i915_gem_context.c | 11 +- .../gpu/drm/i915/gem/i915_gem_context_types.h | 3 + drivers/gpu/drm/i915/gem/i915_gem_object.c | 13 +- .../gpu/drm/i915/gem/i915_gem_object_types.h | 12 ++ .../gpu/drm/i915/gem/selftests/mock_context.c | 4 +- drivers/gpu/drm/i915/gt/intel_context.c | 14 ++ drivers/gpu/drm/i915/gt/intel_gtt.c | 6 + drivers/gpu/drm/i915/gt/intel_gtt.h | 1 + drivers/gpu/drm/i915/i915_drm_client.c | 131 ++++++++++++++++++ drivers/gpu/drm/i915/i915_drm_client.h | 41 ++++++ 10 files changed, 228 insertions(+), 8 deletions(-) -- 2.39.2 ^ permalink raw reply [flat|nested] 23+ messages in thread
* [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-07-27 10:13 [Intel-gfx] [PATCH v6 0/5] fdinfo memory stats Tvrtko Ursulin @ 2023-07-27 10:13 ` Tvrtko Ursulin 2023-08-03 5:15 ` Iddamsetty, Aravind 0 siblings, 1 reply; 23+ messages in thread From: Tvrtko Ursulin @ 2023-07-27 10:13 UTC (permalink / raw) To: Intel-gfx, dri-devel From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Use the newly added drm_print_memory_stats helper to show memory utilisation of our objects in drm/driver specific fdinfo output. To collect the stats we walk the per memory regions object lists and accumulate object size into the respective drm_memory_stats categories. Objects with multiple possible placements are reported in multiple regions for total and shared sizes, while other categories are counted only for the currently active region. Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> Cc: Rob Clark <robdclark@gmail.com> --- drivers/gpu/drm/i915/i915_drm_client.c | 85 ++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index a61356012df8..9e7a6075ee25 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -45,6 +45,89 @@ void __i915_drm_client_free(struct kref *kref) } #ifdef CONFIG_PROC_FS +static void +obj_meminfo(struct drm_i915_gem_object *obj, + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) +{ + struct intel_memory_region *mr; + u64 sz = obj->base.size; + enum intel_region_id id; + unsigned int i; + + /* Attribute size and shared to all possible memory regions. */ + for (i = 0; i < obj->mm.n_placements; i++) { + mr = obj->mm.placements[i]; + id = mr->id; + + if (obj->base.handle_count > 1) + stats[id].shared += sz; + else + stats[id].private += sz; + } + + /* Attribute other categories to only the current region. */ + mr = obj->mm.region; + if (mr) + id = mr->id; + else + id = INTEL_REGION_SMEM; + + if (!obj->mm.n_placements) { + if (obj->base.handle_count > 1) + stats[id].shared += sz; + else + stats[id].private += sz; + } + + if (i915_gem_object_has_pages(obj)) { + stats[id].resident += sz; + + if (!dma_resv_test_signaled(obj->base.resv, + dma_resv_usage_rw(true))) + stats[id].active += sz; + else if (i915_gem_object_is_shrinkable(obj) && + obj->mm.madv == I915_MADV_DONTNEED) + stats[id].purgeable += sz; + } +} + +static void show_meminfo(struct drm_printer *p, struct drm_file *file) +{ + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; + struct drm_i915_file_private *fpriv = file->driver_priv; + struct i915_drm_client *client = fpriv->client; + struct drm_i915_private *i915 = fpriv->i915; + struct drm_i915_gem_object *obj; + struct intel_memory_region *mr; + struct list_head *pos; + unsigned int id; + + /* Public objects. */ + spin_lock(&file->table_lock); + idr_for_each_entry(&file->object_idr, obj, id) + obj_meminfo(obj, stats); + spin_unlock(&file->table_lock); + + /* Internal objects. */ + rcu_read_lock(); + list_for_each_rcu(pos, &client->objects_list) { + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), + client_link)); + if (!obj) + continue; + obj_meminfo(obj, stats); + i915_gem_object_put(obj); + } + rcu_read_unlock(); + + for_each_memory_region(mr, i915, id) + drm_print_memory_stats(p, + &stats[id], + DRM_GEM_OBJECT_RESIDENT | + DRM_GEM_OBJECT_PURGEABLE, + mr->name); +} + static const char * const uabi_class_names[] = { [I915_ENGINE_CLASS_RENDER] = "render", [I915_ENGINE_CLASS_COPY] = "copy", @@ -106,6 +189,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) * ****************************************************************** */ + show_meminfo(p, file); + if (GRAPHICS_VER(i915) < 8) return; -- 2.39.2 ^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-07-27 10:13 ` [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin @ 2023-08-03 5:15 ` Iddamsetty, Aravind 2023-08-03 8:49 ` Tvrtko Ursulin 0 siblings, 1 reply; 23+ messages in thread From: Iddamsetty, Aravind @ 2023-08-03 5:15 UTC (permalink / raw) To: Tvrtko Ursulin, Intel-gfx, dri-devel On 27-07-2023 15:43, Tvrtko Ursulin wrote: > From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > > Use the newly added drm_print_memory_stats helper to show memory > utilisation of our objects in drm/driver specific fdinfo output. > > To collect the stats we walk the per memory regions object lists > and accumulate object size into the respective drm_memory_stats > categories. > > Objects with multiple possible placements are reported in multiple > regions for total and shared sizes, while other categories are > counted only for the currently active region. > > Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> > Cc: Rob Clark <robdclark@gmail.com>> --- > drivers/gpu/drm/i915/i915_drm_client.c | 85 ++++++++++++++++++++++++++ > 1 file changed, 85 insertions(+) > > diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c > index a61356012df8..9e7a6075ee25 100644 > --- a/drivers/gpu/drm/i915/i915_drm_client.c > +++ b/drivers/gpu/drm/i915/i915_drm_client.c > @@ -45,6 +45,89 @@ void __i915_drm_client_free(struct kref *kref) > } > > #ifdef CONFIG_PROC_FS > +static void > +obj_meminfo(struct drm_i915_gem_object *obj, > + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) > +{ > + struct intel_memory_region *mr; > + u64 sz = obj->base.size; > + enum intel_region_id id; > + unsigned int i; > + > + /* Attribute size and shared to all possible memory regions. */ > + for (i = 0; i < obj->mm.n_placements; i++) { > + mr = obj->mm.placements[i]; > + id = mr->id; > + > + if (obj->base.handle_count > 1) > + stats[id].shared += sz; > + else > + stats[id].private += sz; > + } > + > + /* Attribute other categories to only the current region. */ > + mr = obj->mm.region; > + if (mr) > + id = mr->id; > + else > + id = INTEL_REGION_SMEM; > + > + if (!obj->mm.n_placements) { I guess we do not expect to have n_placements set to public objects, is that right? Thanks, Aravind. > + if (obj->base.handle_count > 1) > + stats[id].shared += sz; > + else > + stats[id].private += sz; > + } > + > + if (i915_gem_object_has_pages(obj)) { > + stats[id].resident += sz; > + > + if (!dma_resv_test_signaled(obj->base.resv, > + dma_resv_usage_rw(true))) > + stats[id].active += sz; > + else if (i915_gem_object_is_shrinkable(obj) && > + obj->mm.madv == I915_MADV_DONTNEED) > + stats[id].purgeable += sz; > + } > +} > + > +static void show_meminfo(struct drm_printer *p, struct drm_file *file) > +{ > + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; > + struct drm_i915_file_private *fpriv = file->driver_priv; > + struct i915_drm_client *client = fpriv->client; > + struct drm_i915_private *i915 = fpriv->i915; > + struct drm_i915_gem_object *obj; > + struct intel_memory_region *mr; > + struct list_head *pos; > + unsigned int id; > + > + /* Public objects. */ > + spin_lock(&file->table_lock); > + idr_for_each_entry(&file->object_idr, obj, id) > + obj_meminfo(obj, stats); > + spin_unlock(&file->table_lock); > + > + /* Internal objects. */ > + rcu_read_lock(); > + list_for_each_rcu(pos, &client->objects_list) { > + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), > + client_link)); > + if (!obj) > + continue; > + obj_meminfo(obj, stats); > + i915_gem_object_put(obj); > + } > + rcu_read_unlock(); > + > + for_each_memory_region(mr, i915, id) > + drm_print_memory_stats(p, > + &stats[id], > + DRM_GEM_OBJECT_RESIDENT | > + DRM_GEM_OBJECT_PURGEABLE, > + mr->name); > +} > + > static const char * const uabi_class_names[] = { > [I915_ENGINE_CLASS_RENDER] = "render", > [I915_ENGINE_CLASS_COPY] = "copy", > @@ -106,6 +189,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) > * ****************************************************************** > */ > > + show_meminfo(p, file); > + > if (GRAPHICS_VER(i915) < 8) > return; > ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-08-03 5:15 ` Iddamsetty, Aravind @ 2023-08-03 8:49 ` Tvrtko Ursulin 2023-08-09 4:33 ` Iddamsetty, Aravind 0 siblings, 1 reply; 23+ messages in thread From: Tvrtko Ursulin @ 2023-08-03 8:49 UTC (permalink / raw) To: Iddamsetty, Aravind, Intel-gfx, dri-devel On 03/08/2023 06:15, Iddamsetty, Aravind wrote: > On 27-07-2023 15:43, Tvrtko Ursulin wrote: >> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >> >> Use the newly added drm_print_memory_stats helper to show memory >> utilisation of our objects in drm/driver specific fdinfo output. >> >> To collect the stats we walk the per memory regions object lists >> and accumulate object size into the respective drm_memory_stats >> categories. >> >> Objects with multiple possible placements are reported in multiple >> regions for total and shared sizes, while other categories are >> counted only for the currently active region. >> >> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >> Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> >> Cc: Rob Clark <robdclark@gmail.com>> --- >> drivers/gpu/drm/i915/i915_drm_client.c | 85 ++++++++++++++++++++++++++ >> 1 file changed, 85 insertions(+) >> >> diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c >> index a61356012df8..9e7a6075ee25 100644 >> --- a/drivers/gpu/drm/i915/i915_drm_client.c >> +++ b/drivers/gpu/drm/i915/i915_drm_client.c >> @@ -45,6 +45,89 @@ void __i915_drm_client_free(struct kref *kref) >> } >> >> #ifdef CONFIG_PROC_FS >> +static void >> +obj_meminfo(struct drm_i915_gem_object *obj, >> + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) >> +{ >> + struct intel_memory_region *mr; >> + u64 sz = obj->base.size; >> + enum intel_region_id id; >> + unsigned int i; >> + >> + /* Attribute size and shared to all possible memory regions. */ >> + for (i = 0; i < obj->mm.n_placements; i++) { >> + mr = obj->mm.placements[i]; >> + id = mr->id; >> + >> + if (obj->base.handle_count > 1) >> + stats[id].shared += sz; >> + else >> + stats[id].private += sz; >> + } >> + >> + /* Attribute other categories to only the current region. */ >> + mr = obj->mm.region; >> + if (mr) >> + id = mr->id; >> + else >> + id = INTEL_REGION_SMEM; >> + >> + if (!obj->mm.n_placements) { > > I guess we do not expect to have n_placements set to public objects, is > that right? I think they are the only ones which can have placements. It is via I915_GEM_CREATE_EXT_MEMORY_REGIONS userspace is able to create them. My main conundrum in this patch is a few lines above, the loop which adds shared and private. Question is, if an object can be either smem or lmem, how do we want to report it? This patch adds the size for all possible regions and resident and active only to the currently active. But perhaps that is wrong. Maybe I should change it is only against the active region and multiple regions are just ignored. Then if object is migrated do access patterns or memory pressure, the total size would migrate too. I think I was trying to achieve something here (have more visibility on what kind of backing store clients are allocating) which maybe does not work to well with the current categories. Namely if userspace allocates say one 1MiB object with placement in either smem or lmem, and it is currently resident in lmem, I wanted it to show as: total-smem: 1 MiB resident-smem: 0 total-lmem: 1 MiB resident-lmem: 1 MiB To constantly show how in theory client could be using memory from either region. Maybe that is misleading and should instead be: total-smem: 0 resident-smem: 0 total-lmem: 1 MiB resident-lmem: 1 MiB ? And then if/when the same object gets migrated to smem it changes to (lets assume it is also not resident any more but got swapped out): total-smem: 1 MiB resident-smem: 0 total-lmem: 0 resident-lmem: 0 Regards, Tvrtko >> + if (obj->base.handle_count > 1) >> + stats[id].shared += sz; >> + else >> + stats[id].private += sz; >> + } >> + >> + if (i915_gem_object_has_pages(obj)) { >> + stats[id].resident += sz; >> + >> + if (!dma_resv_test_signaled(obj->base.resv, >> + dma_resv_usage_rw(true))) >> + stats[id].active += sz; >> + else if (i915_gem_object_is_shrinkable(obj) && >> + obj->mm.madv == I915_MADV_DONTNEED) >> + stats[id].purgeable += sz; >> + } >> +} >> + >> +static void show_meminfo(struct drm_printer *p, struct drm_file *file) >> +{ >> + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; >> + struct drm_i915_file_private *fpriv = file->driver_priv; >> + struct i915_drm_client *client = fpriv->client; >> + struct drm_i915_private *i915 = fpriv->i915; >> + struct drm_i915_gem_object *obj; >> + struct intel_memory_region *mr; >> + struct list_head *pos; >> + unsigned int id; >> + >> + /* Public objects. */ >> + spin_lock(&file->table_lock); >> + idr_for_each_entry(&file->object_idr, obj, id) >> + obj_meminfo(obj, stats); >> + spin_unlock(&file->table_lock); >> + >> + /* Internal objects. */ >> + rcu_read_lock(); >> + list_for_each_rcu(pos, &client->objects_list) { >> + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), >> + client_link)); >> + if (!obj) >> + continue; >> + obj_meminfo(obj, stats); >> + i915_gem_object_put(obj); >> + } >> + rcu_read_unlock(); >> + >> + for_each_memory_region(mr, i915, id) >> + drm_print_memory_stats(p, >> + &stats[id], >> + DRM_GEM_OBJECT_RESIDENT | >> + DRM_GEM_OBJECT_PURGEABLE, >> + mr->name); >> +} >> + >> static const char * const uabi_class_names[] = { >> [I915_ENGINE_CLASS_RENDER] = "render", >> [I915_ENGINE_CLASS_COPY] = "copy", >> @@ -106,6 +189,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) >> * ****************************************************************** >> */ >> >> + show_meminfo(p, file); >> + >> if (GRAPHICS_VER(i915) < 8) >> return; >> > > > ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-08-03 8:49 ` Tvrtko Ursulin @ 2023-08-09 4:33 ` Iddamsetty, Aravind 0 siblings, 0 replies; 23+ messages in thread From: Iddamsetty, Aravind @ 2023-08-09 4:33 UTC (permalink / raw) To: Tvrtko Ursulin, Intel-gfx, dri-devel On 03-08-2023 14:19, Tvrtko Ursulin wrote: > > On 03/08/2023 06:15, Iddamsetty, Aravind wrote: >> On 27-07-2023 15:43, Tvrtko Ursulin wrote: >>> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >>> >>> Use the newly added drm_print_memory_stats helper to show memory >>> utilisation of our objects in drm/driver specific fdinfo output. >>> >>> To collect the stats we walk the per memory regions object lists >>> and accumulate object size into the respective drm_memory_stats >>> categories. >>> >>> Objects with multiple possible placements are reported in multiple >>> regions for total and shared sizes, while other categories are >>> counted only for the currently active region. >>> >>> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >>> Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> >>> Cc: Rob Clark <robdclark@gmail.com>> --- >>> drivers/gpu/drm/i915/i915_drm_client.c | 85 ++++++++++++++++++++++++++ >>> 1 file changed, 85 insertions(+) >>> >>> diff --git a/drivers/gpu/drm/i915/i915_drm_client.c >>> b/drivers/gpu/drm/i915/i915_drm_client.c >>> index a61356012df8..9e7a6075ee25 100644 >>> --- a/drivers/gpu/drm/i915/i915_drm_client.c >>> +++ b/drivers/gpu/drm/i915/i915_drm_client.c >>> @@ -45,6 +45,89 @@ void __i915_drm_client_free(struct kref *kref) >>> } >>> #ifdef CONFIG_PROC_FS >>> +static void >>> +obj_meminfo(struct drm_i915_gem_object *obj, >>> + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) >>> +{ >>> + struct intel_memory_region *mr; >>> + u64 sz = obj->base.size; >>> + enum intel_region_id id; >>> + unsigned int i; >>> + >>> + /* Attribute size and shared to all possible memory regions. */ >>> + for (i = 0; i < obj->mm.n_placements; i++) { >>> + mr = obj->mm.placements[i]; >>> + id = mr->id; >>> + >>> + if (obj->base.handle_count > 1) >>> + stats[id].shared += sz; >>> + else >>> + stats[id].private += sz; >>> + } >>> + >>> + /* Attribute other categories to only the current region. */ >>> + mr = obj->mm.region; >>> + if (mr) >>> + id = mr->id; >>> + else >>> + id = INTEL_REGION_SMEM; >>> + >>> + if (!obj->mm.n_placements) { >> >> I guess we do not expect to have n_placements set to public objects, is >> that right? > > I think they are the only ones which can have placements. It is via > I915_GEM_CREATE_EXT_MEMORY_REGIONS userspace is able to create them. > > My main conundrum in this patch is a few lines above, the loop which > adds shared and private. > > Question is, if an object can be either smem or lmem, how do we want to > report it? This patch adds the size for all possible regions and > resident and active only to the currently active. But perhaps that is > wrong. Maybe I should change it is only against the active region and > multiple regions are just ignored. Then if object is migrated do access > patterns or memory pressure, the total size would migrate too. > > I think I was trying to achieve something here (have more visibility on > what kind of backing store clients are allocating) which maybe does not > work to well with the current categories. > > Namely if userspace allocates say one 1MiB object with placement in > either smem or lmem, and it is currently resident in lmem, I wanted it > to show as: > > total-smem: 1 MiB > resident-smem: 0 > total-lmem: 1 MiB > resident-lmem: 1 MiB > > To constantly show how in theory client could be using memory from > either region. Maybe that is misleading and should instead be: > > total-smem: 0 > resident-smem: 0 > total-lmem: 1 MiB > resident-lmem: 1 MiB > > ? I think the current implementation will not match with the memregion info in query ioctl as well. While what you say is true I'm not sure if there can be a client who is tracking the allocation say for an obj who has 2 placements LMEM and SMEM, and might assume since I had made a reservation in SMEM it shall not fail when i try to migrate there later. Thanks, Aravind. > > And then if/when the same object gets migrated to smem it changes to > (lets assume it is also not resident any more but got swapped out): > > total-smem: 1 MiB > resident-smem: 0 > total-lmem: 0 > resident-lmem: 0 > > Regards, > > Tvrtko > >>> + if (obj->base.handle_count > 1) >>> + stats[id].shared += sz; >>> + else >>> + stats[id].private += sz; >>> + } >>> + >>> + if (i915_gem_object_has_pages(obj)) { >>> + stats[id].resident += sz; >>> + >>> + if (!dma_resv_test_signaled(obj->base.resv, >>> + dma_resv_usage_rw(true))) >>> + stats[id].active += sz; >>> + else if (i915_gem_object_is_shrinkable(obj) && >>> + obj->mm.madv == I915_MADV_DONTNEED) >>> + stats[id].purgeable += sz; >>> + } >>> +} >>> + >>> +static void show_meminfo(struct drm_printer *p, struct drm_file *file) >>> +{ >>> + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; >>> + struct drm_i915_file_private *fpriv = file->driver_priv; >>> + struct i915_drm_client *client = fpriv->client; >>> + struct drm_i915_private *i915 = fpriv->i915; >>> + struct drm_i915_gem_object *obj; >>> + struct intel_memory_region *mr; >>> + struct list_head *pos; >>> + unsigned int id; >>> + >>> + /* Public objects. */ >>> + spin_lock(&file->table_lock); >>> + idr_for_each_entry(&file->object_idr, obj, id) >>> + obj_meminfo(obj, stats); >>> + spin_unlock(&file->table_lock); >>> + >>> + /* Internal objects. */ >>> + rcu_read_lock(); >>> + list_for_each_rcu(pos, &client->objects_list) { >>> + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), >>> + client_link)); >>> + if (!obj) >>> + continue; >>> + obj_meminfo(obj, stats); >>> + i915_gem_object_put(obj); >>> + } >>> + rcu_read_unlock(); >>> + >>> + for_each_memory_region(mr, i915, id) >>> + drm_print_memory_stats(p, >>> + &stats[id], >>> + DRM_GEM_OBJECT_RESIDENT | >>> + DRM_GEM_OBJECT_PURGEABLE, >>> + mr->name); >>> +} >>> + >>> static const char * const uabi_class_names[] = { >>> [I915_ENGINE_CLASS_RENDER] = "render", >>> [I915_ENGINE_CLASS_COPY] = "copy", >>> @@ -106,6 +189,8 @@ void i915_drm_client_fdinfo(struct drm_printer >>> *p, struct drm_file *file) >>> * >>> ****************************************************************** >>> */ >>> + show_meminfo(p, file); >>> + >>> if (GRAPHICS_VER(i915) < 8) >>> return; >>> >> >> >> ^ permalink raw reply [flat|nested] 23+ messages in thread
* [Intel-gfx] [PATCH v5 0/5] fdinfo memory stats @ 2023-07-07 13:02 Tvrtko Ursulin 2023-07-07 13:02 ` [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 0 siblings, 1 reply; 23+ messages in thread From: Tvrtko Ursulin @ 2023-07-07 13:02 UTC (permalink / raw) To: Intel-gfx, dri-devel From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> I added tracking of most classes of objects which contribute to client's memory footprint and accouting along the similar lines as in Rob's msm code. Then printing it out to fdinfo using the drm helper Rob added. Accounting by keeping per client lists may not be the most effient method, perhaps we should simply add and subtract stats directly at convenient sites, but that too is not straightforward due no existing connection between buffer objects and clients. Possibly some other tricky bits in the buffer sharing deparment. So lets see if this works for now. Infrequent reader penalty should not be too bad (may be even useful to dump the lists in debugfs?) and additional list_head per object pretty much drowns in the noise. Example fdinfo with the series applied: # cat /proc/1383/fdinfo/8 pos: 0 flags: 02100002 mnt_id: 21 ino: 397 drm-driver: i915 drm-client-id: 18 drm-pdev: 0000:00:02.0 drm-total-system: 125 MiB drm-shared-system: 16 MiB drm-active-system: 110 MiB drm-resident-system: 125 MiB drm-purgeable-system: 2 MiB drm-total-stolen-system: 0 drm-shared-stolen-system: 0 drm-active-stolen-system: 0 drm-resident-stolen-system: 0 drm-purgeable-stolen-system: 0 drm-engine-render: 25662044495 ns drm-engine-copy: 0 ns drm-engine-video: 0 ns drm-engine-video-enhance: 0 ns Example gputop output (local patches currently): DRM minor 0 PID SMEM SMEMRSS render copy video NAME 1233 124M 124M |████████|| || || | neverball 1130 59M 59M |█▌ || || || | Xorg 1207 12M 12M | || || || | xfwm4 v2: * Now actually per client. v3: * Track imported dma-buf objects. v4: * Rely on DRM GEM handles for tracking user objects. * Fix internal object accounting (no placements). v5: * Fixed brain fart of overwriting the loop cursor. * Fixed object destruction racing with fdinfo reads. * Take reference to GEM context while using it. Tvrtko Ursulin (5): drm/i915: Add ability for tracking buffer objects per client drm/i915: Record which client owns a VM drm/i915: Track page table backing store usage drm/i915: Account ring buffer and context state storage drm/i915: Implement fdinfo memory stats printing drivers/gpu/drm/i915/gem/i915_gem_context.c | 11 +- .../gpu/drm/i915/gem/i915_gem_context_types.h | 3 + drivers/gpu/drm/i915/gem/i915_gem_object.c | 13 +- .../gpu/drm/i915/gem/i915_gem_object_types.h | 12 ++ .../gpu/drm/i915/gem/selftests/mock_context.c | 4 +- drivers/gpu/drm/i915/gt/intel_context.c | 13 ++ drivers/gpu/drm/i915/gt/intel_gtt.c | 6 + drivers/gpu/drm/i915/gt/intel_gtt.h | 1 + drivers/gpu/drm/i915/i915_drm_client.c | 131 ++++++++++++++++++ drivers/gpu/drm/i915/i915_drm_client.h | 40 ++++++ 10 files changed, 226 insertions(+), 8 deletions(-) -- 2.39.2 ^ permalink raw reply [flat|nested] 23+ messages in thread
* [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-07-07 13:02 [Intel-gfx] [PATCH v5 0/5] fdinfo memory stats Tvrtko Ursulin @ 2023-07-07 13:02 ` Tvrtko Ursulin 2023-08-24 11:35 ` Upadhyay, Tejas 0 siblings, 1 reply; 23+ messages in thread From: Tvrtko Ursulin @ 2023-07-07 13:02 UTC (permalink / raw) To: Intel-gfx, dri-devel From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Use the newly added drm_print_memory_stats helper to show memory utilisation of our objects in drm/driver specific fdinfo output. To collect the stats we walk the per memory regions object lists and accumulate object size into the respective drm_memory_stats categories. Objects with multiple possible placements are reported in multiple regions for total and shared sizes, while other categories are counted only for the currently active region. Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> Cc: Rob Clark <robdclark@gmail.com> --- drivers/gpu/drm/i915/i915_drm_client.c | 85 ++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index ffccb6239789..5c77d6987d90 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -45,6 +45,89 @@ void __i915_drm_client_free(struct kref *kref) } #ifdef CONFIG_PROC_FS +static void +obj_meminfo(struct drm_i915_gem_object *obj, + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) +{ + struct intel_memory_region *mr; + u64 sz = obj->base.size; + enum intel_region_id id; + unsigned int i; + + /* Attribute size and shared to all possible memory regions. */ + for (i = 0; i < obj->mm.n_placements; i++) { + mr = obj->mm.placements[i]; + id = mr->id; + + if (obj->base.handle_count > 1) + stats[id].shared += sz; + else + stats[id].private += sz; + } + + /* Attribute other categories to only the current region. */ + mr = obj->mm.region; + if (mr) + id = mr->id; + else + id = INTEL_REGION_SMEM; + + if (!obj->mm.n_placements) { + if (obj->base.handle_count > 1) + stats[id].shared += sz; + else + stats[id].private += sz; + } + + if (i915_gem_object_has_pages(obj)) { + stats[id].resident += sz; + + if (!dma_resv_test_signaled(obj->base.resv, + dma_resv_usage_rw(true))) + stats[id].active += sz; + else if (i915_gem_object_is_shrinkable(obj) && + obj->mm.madv == I915_MADV_DONTNEED) + stats[id].purgeable += sz; + } +} + +static void show_meminfo(struct drm_printer *p, struct drm_file *file) +{ + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; + struct drm_i915_file_private *fpriv = file->driver_priv; + struct i915_drm_client *client = fpriv->client; + struct drm_i915_private *i915 = fpriv->i915; + struct drm_i915_gem_object *obj; + struct intel_memory_region *mr; + struct list_head *pos; + unsigned int id; + + /* Public objects. */ + spin_lock(&file->table_lock); + idr_for_each_entry (&file->object_idr, obj, id) + obj_meminfo(obj, stats); + spin_unlock(&file->table_lock); + + /* Internal objects. */ + rcu_read_lock(); + list_for_each_rcu(pos, &client->objects_list) { + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), + client_link)); + if (!obj) + continue; + obj_meminfo(obj, stats); + i915_gem_object_put(obj); + } + rcu_read_unlock(); + + for_each_memory_region(mr, i915, id) + drm_print_memory_stats(p, + &stats[id], + DRM_GEM_OBJECT_RESIDENT | + DRM_GEM_OBJECT_PURGEABLE, + mr->name); +} + static const char * const uabi_class_names[] = { [I915_ENGINE_CLASS_RENDER] = "render", [I915_ENGINE_CLASS_COPY] = "copy", @@ -106,6 +189,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) * ****************************************************************** */ + show_meminfo(p, file); + if (GRAPHICS_VER(i915) < 8) return; -- 2.39.2 ^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-07-07 13:02 ` [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin @ 2023-08-24 11:35 ` Upadhyay, Tejas 2023-09-20 14:22 ` Tvrtko Ursulin 0 siblings, 1 reply; 23+ messages in thread From: Upadhyay, Tejas @ 2023-08-24 11:35 UTC (permalink / raw) To: Tvrtko Ursulin, Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org > -----Original Message----- > From: Intel-gfx <intel-gfx-bounces@lists.freedesktop.org> On Behalf Of Tvrtko > Ursulin > Sent: Friday, July 7, 2023 6:32 PM > To: Intel-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org > Subject: [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats > printing > > From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > > Use the newly added drm_print_memory_stats helper to show memory > utilisation of our objects in drm/driver specific fdinfo output. > > To collect the stats we walk the per memory regions object lists and > accumulate object size into the respective drm_memory_stats categories. > > Objects with multiple possible placements are reported in multiple regions for > total and shared sizes, while other categories are counted only for the > currently active region. > > Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> > Cc: Rob Clark <robdclark@gmail.com> > --- > drivers/gpu/drm/i915/i915_drm_client.c | 85 ++++++++++++++++++++++++++ > 1 file changed, 85 insertions(+) > > diff --git a/drivers/gpu/drm/i915/i915_drm_client.c > b/drivers/gpu/drm/i915/i915_drm_client.c > index ffccb6239789..5c77d6987d90 100644 > --- a/drivers/gpu/drm/i915/i915_drm_client.c > +++ b/drivers/gpu/drm/i915/i915_drm_client.c > @@ -45,6 +45,89 @@ void __i915_drm_client_free(struct kref *kref) } > > #ifdef CONFIG_PROC_FS > +static void > +obj_meminfo(struct drm_i915_gem_object *obj, > + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) { > + struct intel_memory_region *mr; > + u64 sz = obj->base.size; > + enum intel_region_id id; > + unsigned int i; > + > + /* Attribute size and shared to all possible memory regions. */ > + for (i = 0; i < obj->mm.n_placements; i++) { > + mr = obj->mm.placements[i]; > + id = mr->id; > + > + if (obj->base.handle_count > 1) > + stats[id].shared += sz; > + else > + stats[id].private += sz; > + } > + > + /* Attribute other categories to only the current region. */ > + mr = obj->mm.region; > + if (mr) > + id = mr->id; > + else > + id = INTEL_REGION_SMEM; > + > + if (!obj->mm.n_placements) { > + if (obj->base.handle_count > 1) > + stats[id].shared += sz; > + else > + stats[id].private += sz; > + } > + > + if (i915_gem_object_has_pages(obj)) { > + stats[id].resident += sz; > + > + if (!dma_resv_test_signaled(obj->base.resv, > + dma_resv_usage_rw(true))) Should not DMA_RESV_USAGE_BOOKKEEP also considered active (why only "rw")? Some app is syncing with syncjobs and has added dma_fence with DMA_RESV_USAGE_BOOKKEEP during execbuf while that BO is busy on waiting on work! Thanks, Tejas > + stats[id].active += sz; > + else if (i915_gem_object_is_shrinkable(obj) && > + obj->mm.madv == I915_MADV_DONTNEED) > + stats[id].purgeable += sz; > + } > +} > + > +static void show_meminfo(struct drm_printer *p, struct drm_file *file) > +{ > + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; > + struct drm_i915_file_private *fpriv = file->driver_priv; > + struct i915_drm_client *client = fpriv->client; > + struct drm_i915_private *i915 = fpriv->i915; > + struct drm_i915_gem_object *obj; > + struct intel_memory_region *mr; > + struct list_head *pos; > + unsigned int id; > + > + /* Public objects. */ > + spin_lock(&file->table_lock); > + idr_for_each_entry (&file->object_idr, obj, id) > + obj_meminfo(obj, stats); > + spin_unlock(&file->table_lock); > + > + /* Internal objects. */ > + rcu_read_lock(); > + list_for_each_rcu(pos, &client->objects_list) { > + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), > + client_link)); > + if (!obj) > + continue; > + obj_meminfo(obj, stats); > + i915_gem_object_put(obj); > + } > + rcu_read_unlock(); > + > + for_each_memory_region(mr, i915, id) > + drm_print_memory_stats(p, > + &stats[id], > + DRM_GEM_OBJECT_RESIDENT | > + DRM_GEM_OBJECT_PURGEABLE, > + mr->name); > +} > + > static const char * const uabi_class_names[] = { > [I915_ENGINE_CLASS_RENDER] = "render", > [I915_ENGINE_CLASS_COPY] = "copy", > @@ -106,6 +189,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, > struct drm_file *file) > * > **************************************************************** > ** > */ > > + show_meminfo(p, file); > + > if (GRAPHICS_VER(i915) < 8) > return; > > -- > 2.39.2 ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-08-24 11:35 ` Upadhyay, Tejas @ 2023-09-20 14:22 ` Tvrtko Ursulin 2023-09-20 14:39 ` Rob Clark 0 siblings, 1 reply; 23+ messages in thread From: Tvrtko Ursulin @ 2023-09-20 14:22 UTC (permalink / raw) To: Upadhyay, Tejas, Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Rob Clark On 24/08/2023 12:35, Upadhyay, Tejas wrote: >> -----Original Message----- >> From: Intel-gfx <intel-gfx-bounces@lists.freedesktop.org> On Behalf Of Tvrtko >> Ursulin >> Sent: Friday, July 7, 2023 6:32 PM >> To: Intel-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org >> Subject: [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats >> printing >> >> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >> >> Use the newly added drm_print_memory_stats helper to show memory >> utilisation of our objects in drm/driver specific fdinfo output. >> >> To collect the stats we walk the per memory regions object lists and >> accumulate object size into the respective drm_memory_stats categories. >> >> Objects with multiple possible placements are reported in multiple regions for >> total and shared sizes, while other categories are counted only for the >> currently active region. >> >> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> >> Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> >> Cc: Rob Clark <robdclark@gmail.com> >> --- >> drivers/gpu/drm/i915/i915_drm_client.c | 85 ++++++++++++++++++++++++++ >> 1 file changed, 85 insertions(+) >> >> diff --git a/drivers/gpu/drm/i915/i915_drm_client.c >> b/drivers/gpu/drm/i915/i915_drm_client.c >> index ffccb6239789..5c77d6987d90 100644 >> --- a/drivers/gpu/drm/i915/i915_drm_client.c >> +++ b/drivers/gpu/drm/i915/i915_drm_client.c >> @@ -45,6 +45,89 @@ void __i915_drm_client_free(struct kref *kref) } >> >> #ifdef CONFIG_PROC_FS >> +static void >> +obj_meminfo(struct drm_i915_gem_object *obj, >> + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) { >> + struct intel_memory_region *mr; >> + u64 sz = obj->base.size; >> + enum intel_region_id id; >> + unsigned int i; >> + >> + /* Attribute size and shared to all possible memory regions. */ >> + for (i = 0; i < obj->mm.n_placements; i++) { >> + mr = obj->mm.placements[i]; >> + id = mr->id; >> + >> + if (obj->base.handle_count > 1) >> + stats[id].shared += sz; >> + else >> + stats[id].private += sz; >> + } >> + >> + /* Attribute other categories to only the current region. */ >> + mr = obj->mm.region; >> + if (mr) >> + id = mr->id; >> + else >> + id = INTEL_REGION_SMEM; >> + >> + if (!obj->mm.n_placements) { >> + if (obj->base.handle_count > 1) >> + stats[id].shared += sz; >> + else >> + stats[id].private += sz; >> + } >> + >> + if (i915_gem_object_has_pages(obj)) { >> + stats[id].resident += sz; >> + >> + if (!dma_resv_test_signaled(obj->base.resv, >> + dma_resv_usage_rw(true))) > > Should not DMA_RESV_USAGE_BOOKKEEP also considered active (why only "rw")? Some app is syncing with syncjobs and has added dma_fence with DMA_RESV_USAGE_BOOKKEEP during execbuf while that BO is busy on waiting on work! Hmm do we have a path which adds DMA_RESV_USAGE_BOOKKEEP usage in execbuf? Rob, any comments here? Given how I basically lifted the logic from 686b21b5f6ca ("drm: Add fdinfo memory stats"), does it sound plausible to upgrade the test against all fences? Regards, Tvrtko >> + stats[id].active += sz; >> + else if (i915_gem_object_is_shrinkable(obj) && >> + obj->mm.madv == I915_MADV_DONTNEED) >> + stats[id].purgeable += sz; >> + } >> +} >> + >> +static void show_meminfo(struct drm_printer *p, struct drm_file *file) >> +{ >> + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; >> + struct drm_i915_file_private *fpriv = file->driver_priv; >> + struct i915_drm_client *client = fpriv->client; >> + struct drm_i915_private *i915 = fpriv->i915; >> + struct drm_i915_gem_object *obj; >> + struct intel_memory_region *mr; >> + struct list_head *pos; >> + unsigned int id; >> + >> + /* Public objects. */ >> + spin_lock(&file->table_lock); >> + idr_for_each_entry (&file->object_idr, obj, id) >> + obj_meminfo(obj, stats); >> + spin_unlock(&file->table_lock); >> + >> + /* Internal objects. */ >> + rcu_read_lock(); >> + list_for_each_rcu(pos, &client->objects_list) { >> + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), >> + client_link)); >> + if (!obj) >> + continue; >> + obj_meminfo(obj, stats); >> + i915_gem_object_put(obj); >> + } >> + rcu_read_unlock(); >> + >> + for_each_memory_region(mr, i915, id) >> + drm_print_memory_stats(p, >> + &stats[id], >> + DRM_GEM_OBJECT_RESIDENT | >> + DRM_GEM_OBJECT_PURGEABLE, >> + mr->name); >> +} >> + >> static const char * const uabi_class_names[] = { >> [I915_ENGINE_CLASS_RENDER] = "render", >> [I915_ENGINE_CLASS_COPY] = "copy", >> @@ -106,6 +189,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, >> struct drm_file *file) >> * >> **************************************************************** >> ** >> */ >> >> + show_meminfo(p, file); >> + >> if (GRAPHICS_VER(i915) < 8) >> return; >> >> -- >> 2.39.2 > ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-09-20 14:22 ` Tvrtko Ursulin @ 2023-09-20 14:39 ` Rob Clark 0 siblings, 0 replies; 23+ messages in thread From: Rob Clark @ 2023-09-20 14:39 UTC (permalink / raw) To: Tvrtko Ursulin Cc: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org On Wed, Sep 20, 2023 at 7:35 AM Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com> wrote: > > > On 24/08/2023 12:35, Upadhyay, Tejas wrote: > >> -----Original Message----- > >> From: Intel-gfx <intel-gfx-bounces@lists.freedesktop.org> On Behalf Of Tvrtko > >> Ursulin > >> Sent: Friday, July 7, 2023 6:32 PM > >> To: Intel-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org > >> Subject: [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats > >> printing > >> > >> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > >> > >> Use the newly added drm_print_memory_stats helper to show memory > >> utilisation of our objects in drm/driver specific fdinfo output. > >> > >> To collect the stats we walk the per memory regions object lists and > >> accumulate object size into the respective drm_memory_stats categories. > >> > >> Objects with multiple possible placements are reported in multiple regions for > >> total and shared sizes, while other categories are counted only for the > >> currently active region. > >> > >> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> > >> Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> > >> Cc: Rob Clark <robdclark@gmail.com> > >> --- > >> drivers/gpu/drm/i915/i915_drm_client.c | 85 ++++++++++++++++++++++++++ > >> 1 file changed, 85 insertions(+) > >> > >> diff --git a/drivers/gpu/drm/i915/i915_drm_client.c > >> b/drivers/gpu/drm/i915/i915_drm_client.c > >> index ffccb6239789..5c77d6987d90 100644 > >> --- a/drivers/gpu/drm/i915/i915_drm_client.c > >> +++ b/drivers/gpu/drm/i915/i915_drm_client.c > >> @@ -45,6 +45,89 @@ void __i915_drm_client_free(struct kref *kref) } > >> > >> #ifdef CONFIG_PROC_FS > >> +static void > >> +obj_meminfo(struct drm_i915_gem_object *obj, > >> + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) { > >> + struct intel_memory_region *mr; > >> + u64 sz = obj->base.size; > >> + enum intel_region_id id; > >> + unsigned int i; > >> + > >> + /* Attribute size and shared to all possible memory regions. */ > >> + for (i = 0; i < obj->mm.n_placements; i++) { > >> + mr = obj->mm.placements[i]; > >> + id = mr->id; > >> + > >> + if (obj->base.handle_count > 1) > >> + stats[id].shared += sz; > >> + else > >> + stats[id].private += sz; > >> + } > >> + > >> + /* Attribute other categories to only the current region. */ > >> + mr = obj->mm.region; > >> + if (mr) > >> + id = mr->id; > >> + else > >> + id = INTEL_REGION_SMEM; > >> + > >> + if (!obj->mm.n_placements) { > >> + if (obj->base.handle_count > 1) > >> + stats[id].shared += sz; > >> + else > >> + stats[id].private += sz; > >> + } > >> + > >> + if (i915_gem_object_has_pages(obj)) { > >> + stats[id].resident += sz; > >> + > >> + if (!dma_resv_test_signaled(obj->base.resv, > >> + dma_resv_usage_rw(true))) > > > > Should not DMA_RESV_USAGE_BOOKKEEP also considered active (why only "rw")? Some app is syncing with syncjobs and has added dma_fence with DMA_RESV_USAGE_BOOKKEEP during execbuf while that BO is busy on waiting on work! > > Hmm do we have a path which adds DMA_RESV_USAGE_BOOKKEEP usage in execbuf? > > Rob, any comments here? Given how I basically lifted the logic from > 686b21b5f6ca ("drm: Add fdinfo memory stats"), does it sound plausible > to upgrade the test against all fences? Yes, I think so.. I don't have any use for BOOKKEEP so I hadn't considered it BR, -R > > Regards, > > Tvrtko > > >> + stats[id].active += sz; > >> + else if (i915_gem_object_is_shrinkable(obj) && > >> + obj->mm.madv == I915_MADV_DONTNEED) > >> + stats[id].purgeable += sz; > >> + } > >> +} > >> + > >> +static void show_meminfo(struct drm_printer *p, struct drm_file *file) > >> +{ > >> + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; > >> + struct drm_i915_file_private *fpriv = file->driver_priv; > >> + struct i915_drm_client *client = fpriv->client; > >> + struct drm_i915_private *i915 = fpriv->i915; > >> + struct drm_i915_gem_object *obj; > >> + struct intel_memory_region *mr; > >> + struct list_head *pos; > >> + unsigned int id; > >> + > >> + /* Public objects. */ > >> + spin_lock(&file->table_lock); > >> + idr_for_each_entry (&file->object_idr, obj, id) > >> + obj_meminfo(obj, stats); > >> + spin_unlock(&file->table_lock); > >> + > >> + /* Internal objects. */ > >> + rcu_read_lock(); > >> + list_for_each_rcu(pos, &client->objects_list) { > >> + obj = i915_gem_object_get_rcu(list_entry(pos, typeof(*obj), > >> + client_link)); > >> + if (!obj) > >> + continue; > >> + obj_meminfo(obj, stats); > >> + i915_gem_object_put(obj); > >> + } > >> + rcu_read_unlock(); > >> + > >> + for_each_memory_region(mr, i915, id) > >> + drm_print_memory_stats(p, > >> + &stats[id], > >> + DRM_GEM_OBJECT_RESIDENT | > >> + DRM_GEM_OBJECT_PURGEABLE, > >> + mr->name); > >> +} > >> + > >> static const char * const uabi_class_names[] = { > >> [I915_ENGINE_CLASS_RENDER] = "render", > >> [I915_ENGINE_CLASS_COPY] = "copy", > >> @@ -106,6 +189,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, > >> struct drm_file *file) > >> * > >> **************************************************************** > >> ** > >> */ > >> > >> + show_meminfo(p, file); > >> + > >> if (GRAPHICS_VER(i915) < 8) > >> return; > >> > >> -- > >> 2.39.2 > > ^ permalink raw reply [flat|nested] 23+ messages in thread
* [Intel-gfx] [PATCH v2 0/5] fdinfo memory stats @ 2023-06-08 14:51 Tvrtko Ursulin 2023-06-08 14:51 ` [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 0 siblings, 1 reply; 23+ messages in thread From: Tvrtko Ursulin @ 2023-06-08 14:51 UTC (permalink / raw) To: Intel-gfx, dri-devel From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Second try, this time actually per client! :) I added tracking of most classes of objects which contribute to clients memory footprint and accouting along the similar lines as in Rob's msm code. Then printing it out to fdinfo using the drm helper Rob added. Example fdinfo with the series applied: # cat /proc/1383/fdinfo/8 pos: 0 flags: 02100002 mnt_id: 21 ino: 397 drm-driver: i915 drm-client-id: 18 drm-pdev: 0000:00:02.0 drm-total-system: 125 MiB drm-shared-system: 16 MiB drm-active-system: 110 MiB drm-resident-system: 125 MiB drm-purgeable-system: 2 MiB drm-total-stolen-system: 0 drm-shared-stolen-system: 0 drm-active-stolen-system: 0 drm-resident-stolen-system: 0 drm-purgeable-stolen-system: 0 drm-engine-render: 25662044495 ns drm-engine-copy: 0 ns drm-engine-video: 0 ns drm-engine-video-enhance: 0 ns Tvrtko Ursulin (5): drm/i915: Track buffer objects belonging to clients drm/i915: Record which clients own a VM drm/i915: Track page table backing store usage drm/i915: Account ring buffer and context state storage drm/i915: Implement fdinfo memory stats printing drivers/gpu/drm/i915/gem/i915_gem_context.c | 17 ++- .../gpu/drm/i915/gem/i915_gem_context_types.h | 3 + drivers/gpu/drm/i915/gem/i915_gem_create.c | 32 ++++- drivers/gpu/drm/i915/gem/i915_gem_object.c | 6 + .../gpu/drm/i915/gem/i915_gem_object_types.h | 12 ++ drivers/gpu/drm/i915/gt/intel_gtt.c | 6 + drivers/gpu/drm/i915/gt/intel_gtt.h | 1 + drivers/gpu/drm/i915/i915_drm_client.c | 110 +++++++++++++++++- drivers/gpu/drm/i915/i915_drm_client.h | 46 +++++++- drivers/gpu/drm/i915/i915_gem.c | 2 +- 10 files changed, 226 insertions(+), 9 deletions(-) -- 2.39.2 ^ permalink raw reply [flat|nested] 23+ messages in thread
* [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-06-08 14:51 [Intel-gfx] [PATCH v2 0/5] fdinfo memory stats Tvrtko Ursulin @ 2023-06-08 14:51 ` Tvrtko Ursulin 0 siblings, 0 replies; 23+ messages in thread From: Tvrtko Ursulin @ 2023-06-08 14:51 UTC (permalink / raw) To: Intel-gfx, dri-devel From: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Use the newly added drm_print_memory_stats helper to show memory utilisation of our objects in drm/driver specific fdinfo output. To collect the stats we walk the per memory regions object lists and accumulate object size into the respective drm_memory_stats categories. Objects with multiple possible placements are reported in multiple regions for total and shared sizes, while other categories are counted only for the currently active region. Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com> Cc: Rob Clark <robdclark@gmail.com> --- drivers/gpu/drm/i915/i915_drm_client.c | 64 ++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index 777930f4995f..686db139b241 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -48,6 +48,68 @@ void __i915_drm_client_free(struct kref *kref) } #ifdef CONFIG_PROC_FS +static void +obj_meminfo(struct drm_i915_gem_object *obj, + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN]) +{ + struct intel_memory_region *mr; + u64 sz = obj->base.size; + enum intel_region_id id; + unsigned int i; + + /* Attribute size and shared to all possible memory regions. */ + for (i = 0; i < obj->mm.n_placements; i++) { + mr = obj->mm.placements[i]; + id = mr->id; + + if (obj->base.handle_count > 1) + stats[id].shared += sz; + else + stats[id].private += sz; + } + + /* Attribute other categories to only the current region. */ + mr = obj->mm.region; + if (mr) + id = mr->id; + else + id = INTEL_REGION_SMEM; + + if (i915_gem_object_has_pages(obj)) { + stats[id].resident += sz; + + if (!dma_resv_test_signaled(obj->base.resv, + dma_resv_usage_rw(true))) + stats[id].active += sz; + else if (i915_gem_object_is_shrinkable(obj) && + obj->mm.madv == I915_MADV_DONTNEED) + stats[id].purgeable += sz; + } +} + +static void show_meminfo(struct drm_printer *p, struct drm_file *file) +{ + struct drm_memory_stats stats[INTEL_REGION_UNKNOWN] = {}; + struct drm_i915_file_private *fpriv = file->driver_priv; + struct i915_drm_client *client = fpriv->client; + struct drm_i915_private *i915 = fpriv->i915; + struct drm_i915_gem_object *obj; + struct intel_memory_region *mr; + unsigned int id; + + mutex_lock(&client->objects_lock); + list_for_each_entry(obj, &client->objects_list, client_link) + obj_meminfo(obj, stats); + mutex_unlock(&client->objects_lock); + + for_each_memory_region(mr, i915, id) + drm_print_memory_stats(p, + &stats[id], + DRM_GEM_OBJECT_RESIDENT | + DRM_GEM_OBJECT_PURGEABLE, + mr->name); +} + static const char * const uabi_class_names[] = { [I915_ENGINE_CLASS_RENDER] = "render", [I915_ENGINE_CLASS_COPY] = "copy", @@ -109,6 +171,8 @@ void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file) * ****************************************************************** */ + show_meminfo(p, file); + if (GRAPHICS_VER(i915) < 8) return; -- 2.39.2 ^ permalink raw reply related [flat|nested] 23+ messages in thread
end of thread, other threads:[~2023-09-22 12:33 UTC | newest] Thread overview: 23+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-06-12 10:46 [Intel-gfx] [PATCH v4 0/5] fdinfo memory stats Tvrtko Ursulin 2023-06-12 10:46 ` [Intel-gfx] [PATCH 1/5] drm/i915: Add ability for tracking buffer objects per client Tvrtko Ursulin 2023-06-12 10:46 ` [Intel-gfx] [PATCH 2/5] drm/i915: Record which client owns a VM Tvrtko Ursulin 2023-06-12 10:46 ` [Intel-gfx] [PATCH 3/5] drm/i915: Track page table backing store usage Tvrtko Ursulin 2023-06-12 10:46 ` [Intel-gfx] [PATCH 4/5] drm/i915: Account ring buffer and context state storage Tvrtko Ursulin 2023-06-12 10:46 ` [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 2023-06-12 12:45 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for fdinfo memory stats (rev3) Patchwork 2023-06-12 12:45 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork 2023-06-12 13:02 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork -- strict thread matches above, loose matches on Subject: below -- 2023-09-21 11:48 [Intel-gfx] [PATCH v7 0/5] fdinfo memory stats Tvrtko Ursulin 2023-09-21 11:48 ` [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 2023-09-22 8:48 ` Iddamsetty, Aravind 2023-09-22 10:57 ` Tvrtko Ursulin 2023-09-22 12:33 ` Iddamsetty, Aravind 2023-09-22 11:01 ` Andi Shyti 2023-07-27 10:13 [Intel-gfx] [PATCH v6 0/5] fdinfo memory stats Tvrtko Ursulin 2023-07-27 10:13 ` [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 2023-08-03 5:15 ` Iddamsetty, Aravind 2023-08-03 8:49 ` Tvrtko Ursulin 2023-08-09 4:33 ` Iddamsetty, Aravind 2023-07-07 13:02 [Intel-gfx] [PATCH v5 0/5] fdinfo memory stats Tvrtko Ursulin 2023-07-07 13:02 ` [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 2023-08-24 11:35 ` Upadhyay, Tejas 2023-09-20 14:22 ` Tvrtko Ursulin 2023-09-20 14:39 ` Rob Clark 2023-06-08 14:51 [Intel-gfx] [PATCH v2 0/5] fdinfo memory stats Tvrtko Ursulin 2023-06-08 14:51 ` [Intel-gfx] [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox