Function gpa::metrics::GpuMetricsUsedMutexTryLock

Function Documentation

bool gpa::metrics::GpuMetricsUsedMutexTryLock(gpa::metrics::GpuId const *pGpuId, uint32_t *pLockingProcess = nullptr)

Verify no other processes are using Intel MD API's GPU HW metrics counters for the specified GPU, by attempting to lock its named/cross-process GPU metrics used mutex.

Will attempt to lock a named/cross-process mutex associated with the GPU that is used to serialize usage of its HW metrics counters (via the Intel MD API, or others such as the MTL Statistics API). This avoids the limitation that two processes cannot be using different metric sets in the same concurrent group.

Note

Can be locked recursively by the same thread. Must be unlocked an equivalent number of times before it can be locked by another thread/process.

Note

Detects if a process crashed after locking the mutex, and in such a scenario breaks the orphaned lock so it can be locked again.

Note

The verification performed by the function depends upon all processes that directly or indirectly use the GPU HW metrics counters to use these functions.

Parameters
  • pGpuId -- Pointer to the id of the GPU whose metrics used mutex will be used.

  • pLockingProcess -- If the mutex cannot be locked due to another process having the lock, then the uint32_t pointed to by lockingProcess is set to the locking process' id (same as pid_t).

Returns

Upon success, the GPU's metrics used mutex is locked and true is returned. Otherwise, a failure occurred (such as the provided GpuId is invalid, or another process has already locked the mutex) and false is returned.