STRUCT MSM_CONTEXT(9)
π struct msm_context(9) β Kernel API Manual, but make it make sense
okay so bestie, listen π this page is literally about struct msm_context β the per-drm_file context β like, one per open file, that's her whole gig. She's the main character of your process's GPU life, no cap. π
β¨ NAME β¨
struct msm_context β per-drm_file context π
πΈ SYNOPSIS πΈ
struct msm_context {
struct rw_semaphore ctxlock;
struct list_head submitqueues;
int queueid;
bool closed;
bool userspace_managed_vm;
struct drm_gpuvm *vm;
struct kref ref;
int seqno;
int sysprof;
char *comm;
char *cmdline;
uint64_t elapsed_ns;
uint64_t cycles;
struct drm_sched_entity *entities[NR_SCHED_PRIORITIES * MSM_GPU_MAX_RINGS];
atomic64_t ctx_mem;
struct msm_perfcntr_context_state *perfctx;
};
π¦ Members π¦
okay this is the part where we go member by member, and honestly? each one ate. π
ctxlockβ she's the bouncer π«Ά she synchronizes access tosubmitqueueslist, etc. Ever heard of it bestie, she's literally the lock.submitqueuesβ the guest list π list ofmsm_gpu_submitqueuecreated by userspace β everything userspace has spun up lives right here.queueidβ Counter incremented each time a submitqueue is created, and it's used to assignmsm_gpu_submitqueue.id. So yes, she's the little ticker handing out the numbers π’closedβ The device file associated with this context has been closed. β οΈ and here's the vibe-killer detail: Once the device is closed, any submits that have not been written to the ring buffer are no-op'd. That's not a drill bestie, they just silently do nothing πuserspace_managed_vmβ the yes/no question: Has userspace opted-in to userspace managed VM (ie. VM_BIND) viaMSM_PARAM_EN_VM_BIND? That's literally the whole field. Vibe check on VM_BIND πvmβ The per-process GPU address-space. Big deal, main character energy π but do not access directly, usemsm_context_vm. Like, respect the accessor, okay?? πrefβ the reference count. She's counting refs, that's it, that's the tweet. π§seqnoβ A unique per-process sequence number. What's it for? Used to detect context switches, without relying on keeping a, potentially dangling, pointer to the previous context. ngl, that's so smart β no dangling pointer drama, we just compare numbers π₯sysprofβ The value ofMSM_PARAM_SYSPROFset by userspace. It's intended to be used by system profiling tools like Mesa'spps-producer(perfetto), and it's restricted toCAP_SYS_ADMIN. so like, privileged girlies only π
π okay breaking out the details because they matter: Setting a value of 1 will preserve performance counters across context switches. Setting a value of 2 will in addition suppress suspend. And why do we care?? (Performance counters lose state across power collapse, which is undesirable for profiling in some cases.) literally the worst π
π also: The value automatically reverts to zero when the drm device file is closed. She resets herself, periodt.
commβ Overridden task comm, seeMSM_PARAM_COMM
Accessed under msm_gpu::lock β οΈ so lock her properly bestie, no shortcuts.
cmdlineβ Overridden task cmdline, seeMSM_PARAM_CMDLINE
Accessed under msm_gpu::lock πΈ same deal, same lock.
elapsed_nsβ The total (cumulative) elapsed time GPU was busy with rendering from this context in ns. Cumulative, bestie β she stacks. β±οΈcyclesβ The total (cumulative) GPU cycles elapsed attributed to this context. Cycle count, also cumulative, also iconic πentitiesβ Table of per-priority-level sched entities used by submitqueues associated with thisdrm_file. And here's the lore π₯ Because some userspace apps make assumptions about rendering from multiple gl contexts (of the same priority) within the process happening in FIFO order without requiring any fencing beyond MakeCurrent, we create at most onedrm_sched_entityper-process per-priority- level. So yes β at most one per process per priority level, because userspace assumptions are load-bearing, iykyk πctx_memβ Total amount of memory of GEM buffers with handles attached for this context. That's the memory total, tracked with anatomic64_t, she's precise πperfctxβ the perf counter context state pointer, typedstruct msm_perfcntr_context_state *π (and yeah, she gets her own SEE ALSO entries down below because she runs with a whole crew)
β SEE ALSO β
- Kernel file
./drivers/gpu/drm/msm/msm_gpu.h struct msm_gpu_devfreq(9)struct msm_perfcntr_group_state(9)struct msm_perfcntr_state(9)msm_context_is_vmbind(9)msm_gpu_convert_priority(9)struct msm_gpu_submitqueue(9)
okay that's the whole page bestie, you're officially a msm_context expert now, I don't make the rules π«Άβ¨ this was struct msm_context(9) from ./drivers/gpu/drm/msm, dated October 2026 β go forth and slay your context switches πππ¦
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms