Lines Matching refs:task
36 static bool __reserve_if_idle(struct rxe_task *task) in __reserve_if_idle() argument
38 WARN_ON(rxe_read(task->qp) <= 0); in __reserve_if_idle()
40 if (task->state == TASK_STATE_IDLE) { in __reserve_if_idle()
41 rxe_get(task->qp); in __reserve_if_idle()
42 task->state = TASK_STATE_BUSY; in __reserve_if_idle()
43 task->num_sched++; in __reserve_if_idle()
47 if (task->state == TASK_STATE_BUSY) in __reserve_if_idle()
48 task->state = TASK_STATE_ARMED; in __reserve_if_idle()
60 static bool __is_done(struct rxe_task *task) in __is_done() argument
62 if (work_pending(&task->work)) in __is_done()
65 if (task->state == TASK_STATE_IDLE || in __is_done()
66 task->state == TASK_STATE_DRAINED) { in __is_done()
74 static bool is_done(struct rxe_task *task) in is_done() argument
79 spin_lock_irqsave(&task->lock, flags); in is_done()
80 done = __is_done(task); in is_done()
81 spin_unlock_irqrestore(&task->lock, flags); in is_done()
103 static void do_task(struct rxe_task *task) in do_task() argument
111 WARN_ON(rxe_read(task->qp) <= 0); in do_task()
113 spin_lock_irqsave(&task->lock, flags); in do_task()
114 if (task->state >= TASK_STATE_DRAINED) { in do_task()
115 rxe_put(task->qp); in do_task()
116 task->num_done++; in do_task()
117 spin_unlock_irqrestore(&task->lock, flags); in do_task()
120 spin_unlock_irqrestore(&task->lock, flags); in do_task()
127 ret = task->func(task->qp); in do_task()
130 spin_lock_irqsave(&task->lock, flags); in do_task()
135 task->state = TASK_STATE_IDLE; in do_task()
140 switch (task->state) { in do_task()
142 task->state = TASK_STATE_IDLE; in do_task()
149 task->state = TASK_STATE_BUSY; in do_task()
154 task->state = TASK_STATE_DRAINED; in do_task()
159 rxe_dbg_qp(task->qp, "unexpected task state = %d", in do_task()
160 task->state); in do_task()
161 task->state = TASK_STATE_IDLE; in do_task()
166 task->num_done++; in do_task()
167 if (WARN_ON(task->num_done != task->num_sched)) in do_task()
169 task->qp, in do_task()
171 task->num_sched, task->num_done); in do_task()
173 spin_unlock_irqrestore(&task->lock, flags); in do_task()
176 task->ret = ret; in do_task()
179 rxe_sched_task(task); in do_task()
181 rxe_put(task->qp); in do_task()
190 int rxe_init_task(struct rxe_task *task, struct rxe_qp *qp, in rxe_init_task() argument
195 task->qp = qp; in rxe_init_task()
196 task->func = func; in rxe_init_task()
197 task->state = TASK_STATE_IDLE; in rxe_init_task()
198 spin_lock_init(&task->lock); in rxe_init_task()
199 INIT_WORK(&task->work, do_work); in rxe_init_task()
212 void rxe_cleanup_task(struct rxe_task *task) in rxe_cleanup_task() argument
216 spin_lock_irqsave(&task->lock, flags); in rxe_cleanup_task()
217 if (!__is_done(task) && task->state < TASK_STATE_DRAINED) { in rxe_cleanup_task()
218 task->state = TASK_STATE_DRAINING; in rxe_cleanup_task()
220 task->state = TASK_STATE_INVALID; in rxe_cleanup_task()
221 spin_unlock_irqrestore(&task->lock, flags); in rxe_cleanup_task()
224 spin_unlock_irqrestore(&task->lock, flags); in rxe_cleanup_task()
229 while (!is_done(task)) in rxe_cleanup_task()
232 spin_lock_irqsave(&task->lock, flags); in rxe_cleanup_task()
233 task->state = TASK_STATE_INVALID; in rxe_cleanup_task()
234 spin_unlock_irqrestore(&task->lock, flags); in rxe_cleanup_task()
240 void rxe_run_task(struct rxe_task *task) in rxe_run_task() argument
245 WARN_ON(rxe_read(task->qp) <= 0); in rxe_run_task()
247 spin_lock_irqsave(&task->lock, flags); in rxe_run_task()
248 run = __reserve_if_idle(task); in rxe_run_task()
249 spin_unlock_irqrestore(&task->lock, flags); in rxe_run_task()
252 do_task(task); in rxe_run_task()
259 void rxe_sched_task(struct rxe_task *task) in rxe_sched_task() argument
263 WARN_ON(rxe_read(task->qp) <= 0); in rxe_sched_task()
265 spin_lock_irqsave(&task->lock, flags); in rxe_sched_task()
266 if (__reserve_if_idle(task)) in rxe_sched_task()
267 queue_work(rxe_wq, &task->work); in rxe_sched_task()
268 spin_unlock_irqrestore(&task->lock, flags); in rxe_sched_task()
275 void rxe_disable_task(struct rxe_task *task) in rxe_disable_task() argument
279 WARN_ON(rxe_read(task->qp) <= 0); in rxe_disable_task()
281 spin_lock_irqsave(&task->lock, flags); in rxe_disable_task()
282 if (!__is_done(task) && task->state < TASK_STATE_DRAINED) { in rxe_disable_task()
283 task->state = TASK_STATE_DRAINING; in rxe_disable_task()
285 task->state = TASK_STATE_DRAINED; in rxe_disable_task()
286 spin_unlock_irqrestore(&task->lock, flags); in rxe_disable_task()
289 spin_unlock_irqrestore(&task->lock, flags); in rxe_disable_task()
291 while (!is_done(task)) in rxe_disable_task()
294 spin_lock_irqsave(&task->lock, flags); in rxe_disable_task()
295 task->state = TASK_STATE_DRAINED; in rxe_disable_task()
296 spin_unlock_irqrestore(&task->lock, flags); in rxe_disable_task()
299 void rxe_enable_task(struct rxe_task *task) in rxe_enable_task() argument
303 WARN_ON(rxe_read(task->qp) <= 0); in rxe_enable_task()
305 spin_lock_irqsave(&task->lock, flags); in rxe_enable_task()
306 if (task->state == TASK_STATE_INVALID) { in rxe_enable_task()
307 spin_unlock_irqrestore(&task->lock, flags); in rxe_enable_task()
311 task->state = TASK_STATE_IDLE; in rxe_enable_task()
312 spin_unlock_irqrestore(&task->lock, flags); in rxe_enable_task()