Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2017 Valve Corporation
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: Andres Rodriguez <andresx7@gmail.com>
0023  */
0024 
0025 #include <linux/fdtable.h>
0026 #include <linux/file.h>
0027 #include <linux/pid.h>
0028 
0029 #include <drm/amdgpu_drm.h>
0030 
0031 #include "amdgpu.h"
0032 #include "amdgpu_sched.h"
0033 #include "amdgpu_vm.h"
0034 
0035 static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
0036                           int fd,
0037                           int32_t priority)
0038 {
0039     struct fd f = fdget(fd);
0040     struct amdgpu_fpriv *fpriv;
0041     struct amdgpu_ctx *ctx;
0042     uint32_t id;
0043     int r;
0044 
0045     if (!f.file)
0046         return -EINVAL;
0047 
0048     r = amdgpu_file_to_fpriv(f.file, &fpriv);
0049     if (r) {
0050         fdput(f);
0051         return r;
0052     }
0053 
0054     idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id)
0055         amdgpu_ctx_priority_override(ctx, priority);
0056 
0057     fdput(f);
0058     return 0;
0059 }
0060 
0061 static int amdgpu_sched_context_priority_override(struct amdgpu_device *adev,
0062                           int fd,
0063                           unsigned ctx_id,
0064                           int32_t priority)
0065 {
0066     struct fd f = fdget(fd);
0067     struct amdgpu_fpriv *fpriv;
0068     struct amdgpu_ctx *ctx;
0069     int r;
0070 
0071     if (!f.file)
0072         return -EINVAL;
0073 
0074     r = amdgpu_file_to_fpriv(f.file, &fpriv);
0075     if (r) {
0076         fdput(f);
0077         return r;
0078     }
0079 
0080     ctx = amdgpu_ctx_get(fpriv, ctx_id);
0081 
0082     if (!ctx) {
0083         fdput(f);
0084         return -EINVAL;
0085     }
0086 
0087     amdgpu_ctx_priority_override(ctx, priority);
0088     amdgpu_ctx_put(ctx);
0089     fdput(f);
0090 
0091     return 0;
0092 }
0093 
0094 int amdgpu_sched_ioctl(struct drm_device *dev, void *data,
0095                struct drm_file *filp)
0096 {
0097     union drm_amdgpu_sched *args = data;
0098     struct amdgpu_device *adev = drm_to_adev(dev);
0099     int r;
0100 
0101     /* First check the op, then the op's argument.
0102      */
0103     switch (args->in.op) {
0104     case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE:
0105     case AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE:
0106         break;
0107     default:
0108         DRM_ERROR("Invalid sched op specified: %d\n", args->in.op);
0109         return -EINVAL;
0110     }
0111 
0112     if (!amdgpu_ctx_priority_is_valid(args->in.priority)) {
0113         WARN(1, "Invalid context priority %d\n", args->in.priority);
0114         return -EINVAL;
0115     }
0116 
0117     switch (args->in.op) {
0118     case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE:
0119         r = amdgpu_sched_process_priority_override(adev,
0120                                args->in.fd,
0121                                args->in.priority);
0122         break;
0123     case AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE:
0124         r = amdgpu_sched_context_priority_override(adev,
0125                                args->in.fd,
0126                                args->in.ctx_id,
0127                                args->in.priority);
0128         break;
0129     default:
0130         /* Impossible.
0131          */
0132         r = -EINVAL;
0133         break;
0134     }
0135 
0136     return r;
0137 }