Skip to content

Commit

Permalink
drm/msm: Add SYSPROF param (v2)
Browse files Browse the repository at this point in the history
Add a SYSPROF param for system profiling tools like Mesa's pps-producer
(perfetto) to control behavior related to system-wide performance
counter collection.  In particular, for profiling, one wants to ensure
that GPU context switches do not effect perfcounter state, and might
want to suppress suspend (which would cause counters to lose state).

v2: Swap the order in msm_file_private_set_sysprof() [sboyd] and
    initialize the sysprof_active refcount to one (because the under/
    overflow checking in refcount_t doesn't expect a 0->1 transition)
    meaning that values greater than 1 means sysprof is active.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Link: https://lore.kernel.org/r/20220304005317.776110-4-robdclark@gmail.com
  • Loading branch information
Rob Clark committed Mar 4, 2022
1 parent f7ddbf5 commit 90f45c4
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/gpu/drm/msm/adreno/adreno_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ int adreno_set_param(struct msm_gpu *gpu, struct msm_file_private *ctx,
uint32_t param, uint64_t value)
{
switch (param) {
case MSM_PARAM_SYSPROF:
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
return msm_file_private_set_sysprof(ctx, gpu, value);
default:
DBG("%s: invalid param: %u", gpu->name, param);
return -EINVAL;
Expand Down
8 changes: 8 additions & 0 deletions drivers/gpu/drm/msm/msm_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,16 @@ static void context_close(struct msm_file_private *ctx)

static void msm_postclose(struct drm_device *dev, struct drm_file *file)
{
struct msm_drm_private *priv = dev->dev_private;
struct msm_file_private *ctx = file->driver_priv;

/*
* It is not possible to set sysprof param to non-zero if gpu
* is not initialized:
*/
if (priv->gpu)
msm_file_private_set_sysprof(ctx, priv->gpu, 0);

context_close(ctx);
}

Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/msm/msm_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,8 @@ int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,

gpu->nr_rings = nr_rings;

refcount_set(&gpu->sysprof_active, 1);

return 0;

fail:
Expand Down
27 changes: 27 additions & 0 deletions drivers/gpu/drm/msm/msm_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ struct msm_gpu {
struct msm_ringbuffer *rb[MSM_GPU_MAX_RINGS];
int nr_rings;

/**
* sysprof_active:
*
* The count of contexts that have enabled system profiling.
*/
refcount_t sysprof_active;

/**
* cur_ctx_seqno:
*
Expand Down Expand Up @@ -329,6 +336,24 @@ struct msm_file_private {
struct kref ref;
int seqno;

/**
* sysprof:
*
* The value of MSM_PARAM_SYSPROF set by userspace. This is
* intended to be used by system profiling tools like Mesa's
* pps-producer (perfetto), and restricted to CAP_SYS_ADMIN.
*
* Setting a value of 1 will preserve performance counters across
* context switches. Setting a value of 2 will in addition
* suppress suspend. (Performance counters lose state across
* power collapse, which is undesirable for profiling in some
* cases.)
*
* The value automatically reverts to zero when the drm device
* file is closed.
*/
int sysprof;

/**
* entities:
*
Expand Down Expand Up @@ -525,6 +550,8 @@ void msm_submitqueue_close(struct msm_file_private *ctx);

void msm_submitqueue_destroy(struct kref *kref);

int msm_file_private_set_sysprof(struct msm_file_private *ctx,
struct msm_gpu *gpu, int sysprof);
void __msm_file_private_destroy(struct kref *kref);

static inline void msm_file_private_put(struct msm_file_private *ctx)
Expand Down
39 changes: 39 additions & 0 deletions drivers/gpu/drm/msm/msm_submitqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,45 @@

#include "msm_gpu.h"

int msm_file_private_set_sysprof(struct msm_file_private *ctx,
struct msm_gpu *gpu, int sysprof)
{
/*
* Since pm_runtime and sysprof_active are both refcounts, we
* call apply the new value first, and then unwind the previous
* value
*/

switch (sysprof) {
default:
return -EINVAL;
case 2:
pm_runtime_get_sync(&gpu->pdev->dev);
fallthrough;
case 1:
refcount_inc(&gpu->sysprof_active);
fallthrough;
case 0:
break;
}

/* unwind old value: */
switch (ctx->sysprof) {
case 2:
pm_runtime_put_autosuspend(&gpu->pdev->dev);
fallthrough;
case 1:
refcount_dec(&gpu->sysprof_active);
fallthrough;
case 0:
break;
}

ctx->sysprof = sysprof;

return 0;
}

void __msm_file_private_destroy(struct kref *kref)
{
struct msm_file_private *ctx = container_of(kref,
Expand Down
1 change: 1 addition & 0 deletions include/uapi/drm/msm_drm.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct drm_msm_timespec {
#define MSM_PARAM_PP_PGTABLE 0x08 /* RO: Deprecated, always returns zero */
#define MSM_PARAM_FAULTS 0x09 /* RO */
#define MSM_PARAM_SUSPENDS 0x0a /* RO */
#define MSM_PARAM_SYSPROF 0x0b /* WO: 1 preserves perfcntrs, 2 also disables suspend */

/* For backwards compat. The original support for preemption was based on
* a single ring per priority level so # of priority levels equals the #
Expand Down

0 comments on commit 90f45c4

Please sign in to comment.