* [PATCH v7 0/5] fdinfo memory stats
@ 2023-09-21 11:48 Tvrtko Ursulin
2023-09-21 11:48 ` [PATCH 1/5] drm/i915: Add ability for tracking buffer objects per client Tvrtko Ursulin
` (4 more replies)
0 siblings, 5 replies; 17+ messages in thread
From: Tvrtko Ursulin @ 2023-09-21 11:48 UTC (permalink / raw)
To: Intel-gfx, dri-devel; +Cc: Tvrtko Ursulin
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] 17+ messages in thread* [PATCH 1/5] drm/i915: Add ability for tracking buffer objects per client 2023-09-21 11:48 [PATCH v7 0/5] fdinfo memory stats Tvrtko Ursulin @ 2023-09-21 11:48 ` Tvrtko Ursulin 2023-09-21 11:48 ` [PATCH 2/5] drm/i915: Record which client owns a VM Tvrtko Ursulin ` (3 subsequent siblings) 4 siblings, 0 replies; 17+ messages in thread From: Tvrtko Ursulin @ 2023-09-21 11:48 UTC (permalink / raw) To: Intel-gfx, dri-devel; +Cc: Aravind Iddamsetty, Tvrtko Ursulin 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. Also, object memory region teardown is moved to the existing RCU free callback to allow safe dereference from the fdinfo RCU read section. Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@intel.com> --- drivers/gpu/drm/i915/gem/i915_gem_object.c | 13 +++++-- .../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 | 32 +++++++++++++++++ 4 files changed, 90 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 c26d87555825..25eeeb863209 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_object.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c @@ -106,6 +106,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); @@ -293,6 +297,10 @@ void __i915_gem_free_object_rcu(struct rcu_head *head) container_of(head, typeof(*obj), rcu); struct drm_i915_private *i915 = to_i915(obj->base.dev); + /* We need to keep this alive for RCU read access from fdinfo. */ + if (obj->mm.n_placements > 1) + kfree(obj->mm.placements); + i915_gem_object_free(obj); GEM_BUG_ON(!atomic_read(&i915->mm.free_count)); @@ -389,9 +397,6 @@ void __i915_gem_free_object(struct drm_i915_gem_object *obj) if (obj->ops->release) obj->ops->release(obj); - if (obj->mm.n_placements > 1) - kfree(obj->mm.placements); - if (obj->shares_resv_from) i915_vm_resv_put(obj->shares_resv_from); @@ -442,6 +447,8 @@ static void i915_gem_free_object(struct drm_gem_object *gem_obj) GEM_BUG_ON(i915_gem_object_is_framebuffer(obj)); + i915_drm_client_remove_object(obj); + /* * Before we free the object, make sure any pure RCU-only * read-side critical sections are complete, e.g. 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 2292404007c8..0c5cdab278b6 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h +++ b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h @@ -302,6 +302,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..2e5e69edc0f9 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -28,6 +28,10 @@ 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); +#endif return client; } @@ -108,4 +112,36 @@ 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) +{ + unsigned long flags; + + GEM_WARN_ON(obj->client); + GEM_WARN_ON(!list_empty(&obj->client_link)); + + spin_lock_irqsave(&client->objects_lock, flags); + obj->client = i915_drm_client_get(client); + list_add_tail_rcu(&obj->client_link, &client->objects_list); + spin_unlock_irqrestore(&client->objects_lock, flags); +} + +bool i915_drm_client_remove_object(struct drm_i915_gem_object *obj) +{ + struct i915_drm_client *client = fetch_and_zero(&obj->client); + unsigned long flags; + + /* Object may not be associated with a client. */ + if (!client) + return false; + + spin_lock_irqsave(&client->objects_lock, flags); + list_del_rcu(&obj->client_link); + spin_unlock_irqrestore(&client->objects_lock, flags); + + i915_drm_client_put(client); + + return true; +} #endif diff --git a/drivers/gpu/drm/i915/i915_drm_client.h b/drivers/gpu/drm/i915/i915_drm_client.h index 67816c912bca..5f58fdf7dcb8 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,20 @@ 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 + /** + * @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. */ @@ -49,4 +66,19 @@ struct i915_drm_client *i915_drm_client_alloc(void); void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file); +#ifdef CONFIG_PROC_FS +void i915_drm_client_add_object(struct i915_drm_client *client, + struct drm_i915_gem_object *obj); +bool 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 bool i915_drm_client_remove_object(struct drm_i915_gem_object *obj) +{ +} +#endif + #endif /* !__I915_DRM_CLIENT_H__ */ -- 2.39.2 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 2/5] drm/i915: Record which client owns a VM 2023-09-21 11:48 [PATCH v7 0/5] fdinfo memory stats Tvrtko Ursulin 2023-09-21 11:48 ` [PATCH 1/5] drm/i915: Add ability for tracking buffer objects per client Tvrtko Ursulin @ 2023-09-21 11:48 ` Tvrtko Ursulin 2023-09-21 11:48 ` [PATCH 3/5] drm/i915: Track page table backing store usage Tvrtko Ursulin ` (2 subsequent siblings) 4 siblings, 0 replies; 17+ messages in thread From: Tvrtko Ursulin @ 2023-09-21 11:48 UTC (permalink / raw) To: Intel-gfx, dri-devel; +Cc: Aravind Iddamsetty, Tvrtko Ursulin 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> Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@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 346ec8ec2edd..8cf62f5134a9 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] 17+ messages in thread
* [PATCH 3/5] drm/i915: Track page table backing store usage 2023-09-21 11:48 [PATCH v7 0/5] fdinfo memory stats Tvrtko Ursulin 2023-09-21 11:48 ` [PATCH 1/5] drm/i915: Add ability for tracking buffer objects per client Tvrtko Ursulin 2023-09-21 11:48 ` [PATCH 2/5] drm/i915: Record which client owns a VM Tvrtko Ursulin @ 2023-09-21 11:48 ` Tvrtko Ursulin 2023-09-21 11:48 ` [PATCH 4/5] drm/i915: Account ring buffer and context state storage Tvrtko Ursulin 2023-09-21 11:48 ` [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 4 siblings, 0 replies; 17+ messages in thread From: Tvrtko Ursulin @ 2023-09-21 11:48 UTC (permalink / raw) To: Intel-gfx, dri-devel; +Cc: Aravind Iddamsetty, Tvrtko Ursulin 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> Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@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 13944a14ea2d..c3f29999b379 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] 17+ messages in thread
* [PATCH 4/5] drm/i915: Account ring buffer and context state storage 2023-09-21 11:48 [PATCH v7 0/5] fdinfo memory stats Tvrtko Ursulin ` (2 preceding siblings ...) 2023-09-21 11:48 ` [PATCH 3/5] drm/i915: Track page table backing store usage Tvrtko Ursulin @ 2023-09-21 11:48 ` Tvrtko Ursulin 2023-09-21 11:48 ` [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 4 siblings, 0 replies; 17+ messages in thread From: Tvrtko Ursulin @ 2023-09-21 11:48 UTC (permalink / raw) To: Intel-gfx, dri-devel; +Cc: Aravind Iddamsetty, Tvrtko Ursulin 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> Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@intel.com> --- drivers/gpu/drm/i915/gt/intel_context.c | 14 ++++++++++++++ drivers/gpu/drm/i915/i915_drm_client.c | 10 ++++++++++ drivers/gpu/drm/i915/i915_drm_client.h | 9 +++++++++ 3 files changed, 33 insertions(+) diff --git a/drivers/gpu/drm/i915/gt/intel_context.c b/drivers/gpu/drm/i915/gt/intel_context.c index a53b26178f0a..a2f1245741bb 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,18 @@ 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 && !kref_get_unless_zero(&ctx->ref)) + ctx = NULL; + rcu_read_unlock(); + if (ctx) { + if (ctx->client) + i915_drm_client_add_context_objects(ctx->client, + ce); + i915_gem_context_put(ctx); + } } unlock: diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index 2e5e69edc0f9..a61356012df8 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -144,4 +144,14 @@ bool i915_drm_client_remove_object(struct drm_i915_gem_object *obj) return true; } + +void i915_drm_client_add_context_objects(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 5f58fdf7dcb8..69cedfcd3d69 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 @@ -70,6 +71,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); bool i915_drm_client_remove_object(struct drm_i915_gem_object *obj); +void i915_drm_client_add_context_objects(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) @@ -79,6 +82,12 @@ static inline void i915_drm_client_add_object(struct i915_drm_client *client, static inline bool i915_drm_client_remove_object(struct drm_i915_gem_object *obj) { } + +static inline void +i915_drm_client_add_context_objects(struct i915_drm_client *client, + struct intel_context *ce) +{ +} #endif #endif /* !__I915_DRM_CLIENT_H__ */ -- 2.39.2 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-09-21 11:48 [PATCH v7 0/5] fdinfo memory stats Tvrtko Ursulin ` (3 preceding siblings ...) 2023-09-21 11:48 ` [PATCH 4/5] drm/i915: Account ring buffer and context state storage Tvrtko Ursulin @ 2023-09-21 11:48 ` Tvrtko Ursulin 2023-09-22 8:48 ` Iddamsetty, Aravind 2023-09-22 11:01 ` Andi Shyti 4 siblings, 2 replies; 17+ messages in thread From: Tvrtko Ursulin @ 2023-09-21 11:48 UTC (permalink / raw) To: Intel-gfx, dri-devel Cc: Tejas Upadhyay, Andi Shyti, Aravind Iddamsetty, Tvrtko Ursulin 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] 17+ messages in thread
* Re: [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-09-21 11:48 ` [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; 17+ messages in thread From: Iddamsetty, Aravind @ 2023-09-22 8:48 UTC (permalink / raw) To: Tvrtko Ursulin, Intel-gfx, dri-devel Cc: Tejas Upadhyay, Andi Shyti, Tvrtko Ursulin 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] 17+ messages in thread
* Re: [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; 17+ messages in thread From: Tvrtko Ursulin @ 2023-09-22 10:57 UTC (permalink / raw) To: Iddamsetty, Aravind, Intel-gfx, dri-devel Cc: Tejas Upadhyay, Andi Shyti, Tvrtko Ursulin 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] 17+ messages in thread
* Re: [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; 17+ messages in thread From: Iddamsetty, Aravind @ 2023-09-22 12:33 UTC (permalink / raw) To: Tvrtko Ursulin, Intel-gfx, dri-devel Cc: Tejas Upadhyay, Andi Shyti, Tvrtko Ursulin 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] 17+ messages in thread
* Re: [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-09-21 11:48 ` [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; 17+ messages in thread From: Andi Shyti @ 2023-09-22 11:01 UTC (permalink / raw) To: Tvrtko Ursulin Cc: Aravind Iddamsetty, Tvrtko Ursulin, Intel-gfx, Tejas Upadhyay, dri-devel, Andi Shyti 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] 17+ messages in thread
* [PATCH v6 0/5] fdinfo memory stats @ 2023-07-27 10:13 Tvrtko Ursulin 2023-07-27 10:13 ` [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 0 siblings, 1 reply; 17+ messages in thread From: Tvrtko Ursulin @ 2023-07-27 10:13 UTC (permalink / raw) To: Intel-gfx, dri-devel; +Cc: Tvrtko Ursulin 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] 17+ messages in thread
* [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-07-27 10:13 [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; 17+ messages in thread From: Tvrtko Ursulin @ 2023-07-27 10:13 UTC (permalink / raw) To: Intel-gfx, dri-devel; +Cc: Aravind Iddamsetty, Tvrtko Ursulin 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] 17+ messages in thread
* Re: [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-07-27 10:13 ` [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; 17+ messages in thread From: Iddamsetty, Aravind @ 2023-08-03 5:15 UTC (permalink / raw) To: Tvrtko Ursulin, Intel-gfx, dri-devel; +Cc: Tvrtko Ursulin 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] 17+ messages in thread
* Re: [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; 17+ messages in thread From: Tvrtko Ursulin @ 2023-08-03 8:49 UTC (permalink / raw) To: Iddamsetty, Aravind, Intel-gfx, dri-devel; +Cc: Tvrtko Ursulin 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] 17+ messages in thread
* Re: [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; 17+ messages in thread From: Iddamsetty, Aravind @ 2023-08-09 4:33 UTC (permalink / raw) To: Tvrtko Ursulin, Intel-gfx, dri-devel; +Cc: Tvrtko Ursulin 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] 17+ messages in thread
* [PATCH v5 0/5] fdinfo memory stats @ 2023-07-07 13:02 Tvrtko Ursulin 2023-07-07 13:02 ` [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 0 siblings, 1 reply; 17+ messages in thread From: Tvrtko Ursulin @ 2023-07-07 13:02 UTC (permalink / raw) To: Intel-gfx, dri-devel; +Cc: Tvrtko Ursulin 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] 17+ messages in thread
* [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-07-07 13:02 [PATCH v5 0/5] fdinfo memory stats Tvrtko Ursulin @ 2023-07-07 13:02 ` Tvrtko Ursulin 0 siblings, 0 replies; 17+ messages in thread From: Tvrtko Ursulin @ 2023-07-07 13:02 UTC (permalink / raw) To: Intel-gfx, dri-devel; +Cc: Aravind Iddamsetty, Tvrtko Ursulin 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] 17+ messages in thread
* [PATCH v4 0/5] fdinfo memory stats @ 2023-06-12 10:46 Tvrtko Ursulin 2023-06-12 10:46 ` [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 0 siblings, 1 reply; 17+ messages in thread From: Tvrtko Ursulin @ 2023-06-12 10:46 UTC (permalink / raw) To: Intel-gfx, dri-devel; +Cc: Tvrtko Ursulin 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] 17+ messages in thread
* [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-06-12 10:46 [PATCH v4 0/5] fdinfo memory stats Tvrtko Ursulin @ 2023-06-12 10:46 ` Tvrtko Ursulin 0 siblings, 0 replies; 17+ messages in thread From: Tvrtko Ursulin @ 2023-06-12 10:46 UTC (permalink / raw) To: Intel-gfx, dri-devel; +Cc: Aravind Iddamsetty, Tvrtko Ursulin 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] 17+ messages in thread
* [PATCH v2 0/5] fdinfo memory stats @ 2023-06-08 14:51 Tvrtko Ursulin 2023-06-08 14:51 ` [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 0 siblings, 1 reply; 17+ messages in thread From: Tvrtko Ursulin @ 2023-06-08 14:51 UTC (permalink / raw) To: Intel-gfx, dri-devel; +Cc: Tvrtko Ursulin 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] 17+ messages in thread
* [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing 2023-06-08 14:51 [PATCH v2 0/5] fdinfo memory stats Tvrtko Ursulin @ 2023-06-08 14:51 ` Tvrtko Ursulin 0 siblings, 0 replies; 17+ messages in thread From: Tvrtko Ursulin @ 2023-06-08 14:51 UTC (permalink / raw) To: Intel-gfx, dri-devel; +Cc: Aravind Iddamsetty, Tvrtko Ursulin 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] 17+ messages in thread
end of thread, other threads:[~2023-09-22 12:33 UTC | newest] Thread overview: 17+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-09-21 11:48 [PATCH v7 0/5] fdinfo memory stats Tvrtko Ursulin 2023-09-21 11:48 ` [PATCH 1/5] drm/i915: Add ability for tracking buffer objects per client Tvrtko Ursulin 2023-09-21 11:48 ` [PATCH 2/5] drm/i915: Record which client owns a VM Tvrtko Ursulin 2023-09-21 11:48 ` [PATCH 3/5] drm/i915: Track page table backing store usage Tvrtko Ursulin 2023-09-21 11:48 ` [PATCH 4/5] drm/i915: Account ring buffer and context state storage Tvrtko Ursulin 2023-09-21 11:48 ` [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 -- strict thread matches above, loose matches on Subject: below -- 2023-07-27 10:13 [PATCH v6 0/5] fdinfo memory stats Tvrtko Ursulin 2023-07-27 10:13 ` [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 [PATCH v5 0/5] fdinfo memory stats Tvrtko Ursulin 2023-07-07 13:02 ` [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 2023-06-12 10:46 [PATCH v4 0/5] fdinfo memory stats Tvrtko Ursulin 2023-06-12 10:46 ` [PATCH 5/5] drm/i915: Implement fdinfo memory stats printing Tvrtko Ursulin 2023-06-08 14:51 [PATCH v2 0/5] fdinfo memory stats Tvrtko Ursulin 2023-06-08 14:51 ` [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