diff options
Diffstat (limited to 'include/os/linux/sched.c')
| -rw-r--r-- | include/os/linux/sched.c | 666 |
1 files changed, 0 insertions, 666 deletions
diff --git a/include/os/linux/sched.c b/include/os/linux/sched.c deleted file mode 100644 index 30c58a1..0000000 --- a/include/os/linux/sched.c +++ /dev/null | |||
| @@ -1,666 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2016-2020, NVIDIA CORPORATION. All rights reserved. | ||
| 3 | * | ||
| 4 | * This program is free software; you can redistribute it and/or modify it | ||
| 5 | * under the terms and conditions of the GNU General Public License, | ||
| 6 | * version 2, as published by the Free Software Foundation. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 11 | * more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #include <asm/barrier.h> | ||
| 17 | #include <linux/wait.h> | ||
| 18 | #include <linux/uaccess.h> | ||
| 19 | #include <linux/poll.h> | ||
| 20 | #include <uapi/linux/nvgpu.h> | ||
| 21 | |||
| 22 | #include <nvgpu/kmem.h> | ||
| 23 | #include <nvgpu/log.h> | ||
| 24 | #include <nvgpu/bug.h> | ||
| 25 | #include <nvgpu/barrier.h> | ||
| 26 | #include <nvgpu/gk20a.h> | ||
| 27 | |||
| 28 | #include "gk20a/gr_gk20a.h" | ||
| 29 | #include "sched.h" | ||
| 30 | #include "os_linux.h" | ||
| 31 | #include "ioctl_tsg.h" | ||
| 32 | |||
| 33 | #include <nvgpu/hw/gk20a/hw_ctxsw_prog_gk20a.h> | ||
| 34 | #include <nvgpu/hw/gk20a/hw_gr_gk20a.h> | ||
| 35 | |||
| 36 | ssize_t gk20a_sched_dev_read(struct file *filp, char __user *buf, | ||
| 37 | size_t size, loff_t *off) | ||
| 38 | { | ||
| 39 | struct gk20a *g = filp->private_data; | ||
| 40 | struct nvgpu_sched_ctrl *sched = &g->sched_ctrl; | ||
| 41 | struct nvgpu_sched_event_arg event = { 0 }; | ||
| 42 | int err; | ||
| 43 | |||
| 44 | nvgpu_log(g, gpu_dbg_fn | gpu_dbg_sched, | ||
| 45 | "filp=%p buf=%p size=%zu", filp, buf, size); | ||
| 46 | |||
| 47 | if (size < sizeof(event)) | ||
| 48 | return -EINVAL; | ||
| 49 | size = sizeof(event); | ||
| 50 | |||
| 51 | nvgpu_mutex_acquire(&sched->status_lock); | ||
| 52 | while (!sched->status) { | ||
| 53 | nvgpu_mutex_release(&sched->status_lock); | ||
| 54 | if (filp->f_flags & O_NONBLOCK) | ||
| 55 | return -EAGAIN; | ||
| 56 | err = NVGPU_COND_WAIT_INTERRUPTIBLE(&sched->readout_wq, | ||
| 57 | sched->status, 0); | ||
| 58 | if (err) | ||
| 59 | return err; | ||
| 60 | nvgpu_mutex_acquire(&sched->status_lock); | ||
| 61 | } | ||
| 62 | |||
| 63 | event.reserved = 0; | ||
| 64 | event.status = sched->status; | ||
| 65 | |||
| 66 | if (copy_to_user(buf, &event, size)) { | ||
| 67 | nvgpu_mutex_release(&sched->status_lock); | ||
| 68 | return -EFAULT; | ||
| 69 | } | ||
| 70 | |||
| 71 | sched->status = 0; | ||
| 72 | |||
| 73 | nvgpu_mutex_release(&sched->status_lock); | ||
| 74 | |||
| 75 | return size; | ||
| 76 | } | ||
| 77 | |||
| 78 | unsigned int gk20a_sched_dev_poll(struct file *filp, poll_table *wait) | ||
| 79 | { | ||
| 80 | struct gk20a *g = filp->private_data; | ||
| 81 | struct nvgpu_sched_ctrl *sched = &g->sched_ctrl; | ||
| 82 | unsigned int mask = 0; | ||
| 83 | |||
| 84 | nvgpu_log(g, gpu_dbg_fn | gpu_dbg_sched, " "); | ||
| 85 | |||
| 86 | nvgpu_mutex_acquire(&sched->status_lock); | ||
| 87 | poll_wait(filp, &sched->readout_wq.wq, wait); | ||
| 88 | if (sched->status) | ||
| 89 | mask |= POLLIN | POLLRDNORM; | ||
| 90 | nvgpu_mutex_release(&sched->status_lock); | ||
| 91 | |||
| 92 | return mask; | ||
| 93 | } | ||
| 94 | |||
| 95 | static int gk20a_sched_dev_ioctl_get_tsgs(struct gk20a *g, | ||
| 96 | struct nvgpu_sched_get_tsgs_args *arg) | ||
| 97 | { | ||
| 98 | struct nvgpu_sched_ctrl *sched = &g->sched_ctrl; | ||
| 99 | |||
| 100 | nvgpu_log(g, gpu_dbg_fn | gpu_dbg_sched, "size=%u buffer=%llx", | ||
| 101 | arg->size, arg->buffer); | ||
| 102 | |||
| 103 | if ((arg->size < sched->bitmap_size) || (!arg->buffer)) { | ||
| 104 | arg->size = sched->bitmap_size; | ||
| 105 | return -ENOSPC; | ||
| 106 | } | ||
| 107 | |||
| 108 | nvgpu_mutex_acquire(&sched->status_lock); | ||
| 109 | if (copy_to_user((void __user *)(uintptr_t)arg->buffer, | ||
| 110 | sched->active_tsg_bitmap, sched->bitmap_size)) { | ||
| 111 | nvgpu_mutex_release(&sched->status_lock); | ||
| 112 | return -EFAULT; | ||
| 113 | } | ||
| 114 | nvgpu_mutex_release(&sched->status_lock); | ||
| 115 | |||
| 116 | return 0; | ||
| 117 | } | ||
| 118 | |||
| 119 | static int gk20a_sched_dev_ioctl_get_recent_tsgs(struct gk20a *g, | ||
| 120 | struct nvgpu_sched_get_tsgs_args *arg) | ||
| 121 | { | ||
| 122 | struct nvgpu_sched_ctrl *sched = &g->sched_ctrl; | ||
| 123 | |||
| 124 | nvgpu_log(g, gpu_dbg_fn | gpu_dbg_sched, "size=%u buffer=%llx", | ||
| 125 | arg->size, arg->buffer); | ||
| 126 | |||
| 127 | if ((arg->size < sched->bitmap_size) || (!arg->buffer)) { | ||
| 128 | arg->size = sched->bitmap_size; | ||
| 129 | return -ENOSPC; | ||
| 130 | } | ||
| 131 | |||
| 132 | nvgpu_mutex_acquire(&sched->status_lock); | ||
| 133 | if (copy_to_user((void __user *)(uintptr_t)arg->buffer, | ||
| 134 | sched->recent_tsg_bitmap, sched->bitmap_size)) { | ||
| 135 | nvgpu_mutex_release(&sched->status_lock); | ||
| 136 | return -EFAULT; | ||
| 137 | } | ||
| 138 | |||
| 139 | memset(sched->recent_tsg_bitmap, 0, sched->bitmap_size); | ||
| 140 | nvgpu_mutex_release(&sched->status_lock); | ||
| 141 | |||
| 142 | return 0; | ||
| 143 | } | ||
| 144 | |||
| 145 | static int gk20a_sched_dev_ioctl_get_tsgs_by_pid(struct gk20a *g, | ||
| 146 | struct nvgpu_sched_get_tsgs_by_pid_args *arg) | ||
| 147 | { | ||
| 148 | struct nvgpu_sched_ctrl *sched = &g->sched_ctrl; | ||
| 149 | struct fifo_gk20a *f = &g->fifo; | ||
| 150 | struct tsg_gk20a *tsg; | ||
| 151 | u64 *bitmap; | ||
| 152 | unsigned int tsgid; | ||
| 153 | /* pid at user level corresponds to kernel tgid */ | ||
| 154 | pid_t tgid = (pid_t)arg->pid; | ||
| 155 | int err = 0; | ||
| 156 | |||
| 157 | nvgpu_log(g, gpu_dbg_fn | gpu_dbg_sched, "pid=%d size=%u buffer=%llx", | ||
| 158 | (pid_t)arg->pid, arg->size, arg->buffer); | ||
| 159 | |||
| 160 | if ((arg->size < sched->bitmap_size) || (!arg->buffer)) { | ||
| 161 | arg->size = sched->bitmap_size; | ||
| 162 | return -ENOSPC; | ||
| 163 | } | ||
| 164 | |||
| 165 | bitmap = nvgpu_kzalloc(g, sched->bitmap_size); | ||
| 166 | if (!bitmap) | ||
| 167 | return -ENOMEM; | ||
| 168 | |||
| 169 | nvgpu_mutex_acquire(&sched->status_lock); | ||
| 170 | for (tsgid = 0; tsgid < f->num_channels; tsgid++) { | ||
| 171 | if (NVGPU_SCHED_ISSET(tsgid, sched->active_tsg_bitmap)) { | ||
| 172 | tsg = &f->tsg[tsgid]; | ||
| 173 | if (tsg->tgid == tgid) | ||
| 174 | NVGPU_SCHED_SET(tsgid, bitmap); | ||
| 175 | } | ||
| 176 | } | ||
| 177 | nvgpu_mutex_release(&sched->status_lock); | ||
| 178 | |||
| 179 | if (copy_to_user((void __user *)(uintptr_t)arg->buffer, | ||
| 180 | bitmap, sched->bitmap_size)) | ||
| 181 | err = -EFAULT; | ||
| 182 | |||
| 183 | nvgpu_kfree(g, bitmap); | ||
| 184 | |||
| 185 | return err; | ||
| 186 | } | ||
| 187 | |||
| 188 | static int gk20a_sched_dev_ioctl_get_params(struct gk20a *g, | ||
| 189 | struct nvgpu_sched_tsg_get_params_args *arg) | ||
| 190 | { | ||
| 191 | struct fifo_gk20a *f = &g->fifo; | ||
| 192 | struct tsg_gk20a *tsg; | ||
| 193 | u32 tsgid = arg->tsgid; | ||
| 194 | |||
| 195 | nvgpu_log(g, gpu_dbg_fn | gpu_dbg_sched, "tsgid=%u", tsgid); | ||
| 196 | |||
| 197 | if (tsgid >= f->num_channels) | ||
| 198 | return -EINVAL; | ||
| 199 | |||
| 200 | nvgpu_speculation_barrier(); | ||
| 201 | |||
| 202 | tsg = &f->tsg[tsgid]; | ||
| 203 | if (!nvgpu_ref_get_unless_zero(&tsg->refcount)) | ||
| 204 | return -ENXIO; | ||
| 205 | |||
| 206 | arg->pid = tsg->tgid; /* kernel tgid corresponds to user pid */ | ||
| 207 | arg->runlist_interleave = tsg->interleave_level; | ||
| 208 | arg->timeslice = gk20a_tsg_get_timeslice(tsg); | ||
| 209 | |||
| 210 | arg->graphics_preempt_mode = | ||
| 211 | tsg->gr_ctx.graphics_preempt_mode; | ||
| 212 | arg->compute_preempt_mode = | ||
| 213 | tsg->gr_ctx.compute_preempt_mode; | ||
| 214 | |||
| 215 | nvgpu_ref_put(&tsg->refcount, nvgpu_ioctl_tsg_release); | ||
| 216 | |||
| 217 | return 0; | ||
| 218 | } | ||
| 219 | |||
| 220 | static int gk20a_sched_dev_ioctl_tsg_set_timeslice( | ||
| 221 | struct gk20a *g, | ||
| 222 | struct nvgpu_sched_tsg_timeslice_args *arg) | ||
| 223 | { | ||
| 224 | struct fifo_gk20a *f = &g->fifo; | ||
| 225 | struct tsg_gk20a *tsg; | ||
