Skip to content

Commit c9d88d4

Browse files
committed
drm/amdgpu: add flag for high priority contexts
Add a new context creation flag, AMDGPU_CTX_FLAG_HIGHPRIORITY. This flag results in the allocated context receiving a higher scheduler priority that other contexts system-wide.
1 parent 4f9d4bb commit c9d88d4

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,19 @@
2525
#include <drm/drmP.h>
2626
#include "amdgpu.h"
2727

28-
static int amdgpu_ctx_init(struct amdgpu_device *adev, struct amdgpu_ctx *ctx)
28+
static int amdgpu_ctx_init(struct amdgpu_device *adev, int priority, struct amdgpu_ctx *ctx)
2929
{
3030
unsigned i, j;
3131
int r;
3232

33+
int pid = task_pid_nr(current);
34+
35+
if (priority < 0 || priority >= AMD_SCHED_MAX_PRIORITY)
36+
return -EINVAL;
37+
38+
if (priority == AMD_SCHED_PRIORITY_HIGH && !capable(CAP_SYS_ADMIN))
39+
return -EACCES;
40+
3341
memset(ctx, 0, sizeof(*ctx));
3442
ctx->adev = adev;
3543
kref_init(&ctx->refcount);
@@ -51,7 +59,7 @@ static int amdgpu_ctx_init(struct amdgpu_device *adev, struct amdgpu_ctx *ctx)
5159
struct amdgpu_ring *ring = adev->rings[i];
5260
struct amd_sched_rq *rq;
5361

54-
rq = &ring->sched.sched_rq[AMD_SCHED_PRIORITY_NORMAL];
62+
rq = &ring->sched.sched_rq[priority];
5563
r = amd_sched_entity_init(&ring->sched, &ctx->rings[i].entity,
5664
rq, amdgpu_sched_jobs);
5765
if (r)
@@ -90,11 +98,15 @@ static void amdgpu_ctx_fini(struct amdgpu_ctx *ctx)
9098

9199
static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
92100
struct amdgpu_fpriv *fpriv,
101+
int flags,
93102
uint32_t *id)
94103
{
95104
struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr;
96105
struct amdgpu_ctx *ctx;
97-
int r;
106+
int r, priority;
107+
108+
priority = flags & AMDGPU_CTX_FLAG_HIGHPRIORITY ?
109+
AMD_SCHED_PRIORITY_HIGH : AMD_SCHED_PRIORITY_NORMAL;
98110

99111
ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
100112
if (!ctx)
@@ -107,8 +119,9 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
107119
kfree(ctx);
108120
return r;
109121
}
122+
110123
*id = (uint32_t)r;
111-
r = amdgpu_ctx_init(adev, ctx);
124+
r = amdgpu_ctx_init(adev, priority, ctx);
112125
if (r) {
113126
idr_remove(&mgr->ctx_handles, *id);
114127
*id = 0;
@@ -186,18 +199,19 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
186199
struct drm_file *filp)
187200
{
188201
int r;
189-
uint32_t id;
202+
uint32_t id, flags;
190203

191204
union drm_amdgpu_ctx *args = data;
192205
struct amdgpu_device *adev = dev->dev_private;
193206
struct amdgpu_fpriv *fpriv = filp->driver_priv;
194207

195208
r = 0;
196209
id = args->in.ctx_id;
210+
flags = args->in.flags;
197211

198212
switch (args->in.op) {
199213
case AMDGPU_CTX_OP_ALLOC_CTX:
200-
r = amdgpu_ctx_alloc(adev, fpriv, &id);
214+
r = amdgpu_ctx_alloc(adev, fpriv, flags, &id);
201215
args->out.alloc.ctx_id = id;
202216
break;
203217
case AMDGPU_CTX_OP_FREE_CTX:

drivers/gpu/drm/amd/scheduler/gpu_scheduler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct amd_sched_backend_ops {
108108

109109
enum amd_sched_priority {
110110
AMD_SCHED_PRIORITY_KERNEL = 0,
111+
AMD_SCHED_PRIORITY_HIGH,
111112
AMD_SCHED_PRIORITY_NORMAL,
112113
AMD_SCHED_MAX_PRIORITY
113114
};

include/uapi/drm/amdgpu_drm.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,11 @@ union drm_amdgpu_bo_list {
160160
/* unknown cause */
161161
#define AMDGPU_CTX_UNKNOWN_RESET 3
162162

163+
#define AMDGPU_CTX_FLAG_HIGHPRIORITY (1 << 0)
163164
struct drm_amdgpu_ctx_in {
164165
/** AMDGPU_CTX_OP_* */
165166
__u32 op;
166-
/** For future use, no flags defined so far */
167+
/** AMDGPU_CTX_FLAG_* */
167168
__u32 flags;
168169
__u32 ctx_id;
169170
__u32 _pad;

0 commit comments

Comments
 (0)