From af4b7f74b2c9aca637f6da33b6594ab2bfc2ded3 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Thu, 3 Mar 2022 15:34:36 -0800 Subject: [PATCH] freedreno/drm: Add SYSPROF param Add new param for putting kernel in system-profiling mode and add corresponding fd_pipe_set_param() mechanism. Signed-off-by: Rob Clark Part-of: --- src/freedreno/drm/freedreno_drmif.h | 3 +++ src/freedreno/drm/freedreno_pipe.c | 6 ++++++ src/freedreno/drm/freedreno_priv.h | 2 ++ src/freedreno/drm/msm_pipe.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/src/freedreno/drm/freedreno_drmif.h b/src/freedreno/drm/freedreno_drmif.h index 5c2b1d9ad18..074f475fe09 100644 --- a/src/freedreno/drm/freedreno_drmif.h +++ b/src/freedreno/drm/freedreno_drmif.h @@ -62,6 +62,7 @@ enum fd_param_id { FD_CTX_FAULTS, /* # of per context faults */ FD_GLOBAL_FAULTS, /* # of global (all context) faults */ FD_SUSPEND_COUNT, /* # of times the GPU has suspended, and potentially lost state */ + FD_SYSPROF, /* Settable (for CAP_SYS_ADMIN) param for system profiling */ }; /** @@ -149,6 +150,8 @@ void fd_pipe_purge(struct fd_pipe *pipe); const struct fd_dev_id * fd_pipe_dev_id(struct fd_pipe *pipe); int fd_pipe_get_param(struct fd_pipe *pipe, enum fd_param_id param, uint64_t *value); +int fd_pipe_set_param(struct fd_pipe *pipe, enum fd_param_id param, + uint64_t value); int fd_pipe_wait(struct fd_pipe *pipe, const struct fd_fence *fence); /* timeout in nanosec */ int fd_pipe_wait_timeout(struct fd_pipe *pipe, const struct fd_fence *fence, diff --git a/src/freedreno/drm/freedreno_pipe.c b/src/freedreno/drm/freedreno_pipe.c index 83052b98d11..579c98c040b 100644 --- a/src/freedreno/drm/freedreno_pipe.c +++ b/src/freedreno/drm/freedreno_pipe.c @@ -164,6 +164,12 @@ fd_pipe_get_param(struct fd_pipe *pipe, enum fd_param_id param, uint64_t *value) return pipe->funcs->get_param(pipe, param, value); } +int +fd_pipe_set_param(struct fd_pipe *pipe, enum fd_param_id param, uint64_t value) +{ + return pipe->funcs->set_param(pipe, param, value); +} + const struct fd_dev_id * fd_pipe_dev_id(struct fd_pipe *pipe) { diff --git a/src/freedreno/drm/freedreno_priv.h b/src/freedreno/drm/freedreno_priv.h index bb165b87285..dbdfd803b33 100644 --- a/src/freedreno/drm/freedreno_priv.h +++ b/src/freedreno/drm/freedreno_priv.h @@ -198,6 +198,8 @@ struct fd_pipe_funcs { int (*get_param)(struct fd_pipe *pipe, enum fd_param_id param, uint64_t *value); + int (*set_param)(struct fd_pipe *pipe, enum fd_param_id param, + uint64_t value); int (*wait)(struct fd_pipe *pipe, const struct fd_fence *fence, uint64_t timeout); void (*destroy)(struct fd_pipe *pipe); diff --git a/src/freedreno/drm/msm_pipe.c b/src/freedreno/drm/msm_pipe.c index 4a71a9f9400..49587fc8915 100644 --- a/src/freedreno/drm/msm_pipe.c +++ b/src/freedreno/drm/msm_pipe.c @@ -107,6 +107,32 @@ msm_pipe_get_param(struct fd_pipe *pipe, enum fd_param_id param, } } +static int +set_param(struct fd_pipe *pipe, uint32_t param, uint64_t value) +{ + struct msm_pipe *msm_pipe = to_msm_pipe(pipe); + struct drm_msm_param req = { + .pipe = msm_pipe->pipe, + .param = param, + .value = value, + }; + + return drmCommandWriteRead(pipe->dev->fd, DRM_MSM_SET_PARAM, + &req, sizeof(req)); +} + +static int +msm_pipe_set_param(struct fd_pipe *pipe, enum fd_param_id param, uint64_t value) +{ + switch (param) { + case FD_SYSPROF: + return set_param(pipe, MSM_PARAM_SYSPROF, value); + default: + ERROR_MSG("invalid param id: %d", param); + return -1; + } +} + static int msm_pipe_wait(struct fd_pipe *pipe, const struct fd_fence *fence, uint64_t timeout) { @@ -182,6 +208,7 @@ static const struct fd_pipe_funcs sp_funcs = { .submit_new = msm_submit_sp_new, .flush = msm_pipe_sp_flush, .get_param = msm_pipe_get_param, + .set_param = msm_pipe_set_param, .wait = msm_pipe_wait, .destroy = msm_pipe_destroy, }; @@ -190,6 +217,7 @@ static const struct fd_pipe_funcs legacy_funcs = { .ringbuffer_new_object = msm_ringbuffer_new_object, .submit_new = msm_submit_new, .get_param = msm_pipe_get_param, + .set_param = msm_pipe_set_param, .wait = msm_pipe_wait, .destroy = msm_pipe_destroy, };