Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1 | /* sched.c - SPU scheduler. |
| 2 | * |
| 3 | * Copyright (C) IBM 2005 |
| 4 | * Author: Mark Nutter <mnutter@us.ibm.com> |
| 5 | * |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 6 | * 2006-03-31 NUMA domains added. |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2, or (at your option) |
| 11 | * any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
Arnd Bergmann | 3b3d22c | 2005-12-05 22:52:24 -0500 | [diff] [blame] | 23 | #undef DEBUG |
| 24 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 25 | #include <linux/errno.h> |
| 26 | #include <linux/sched.h> |
Ingo Molnar | badaff8 | 2017-02-08 08:45:17 +0100 | [diff] [blame] | 27 | #include <linux/sched/loadavg.h> |
Ingo Molnar | 993db4b | 2013-02-11 10:45:33 +0100 | [diff] [blame] | 28 | #include <linux/sched/rt.h> |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 29 | #include <linux/kernel.h> |
| 30 | #include <linux/mm.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 32 | #include <linux/completion.h> |
| 33 | #include <linux/vmalloc.h> |
| 34 | #include <linux/smp.h> |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 35 | #include <linux/stddef.h> |
| 36 | #include <linux/unistd.h> |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 37 | #include <linux/numa.h> |
| 38 | #include <linux/mutex.h> |
Arnd Bergmann | 8676727 | 2006-10-04 17:26:21 +0200 | [diff] [blame] | 39 | #include <linux/notifier.h> |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 40 | #include <linux/kthread.h> |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 41 | #include <linux/pid_namespace.h> |
| 42 | #include <linux/proc_fs.h> |
| 43 | #include <linux/seq_file.h> |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 44 | |
| 45 | #include <asm/io.h> |
| 46 | #include <asm/mmu_context.h> |
| 47 | #include <asm/spu.h> |
| 48 | #include <asm/spu_csa.h> |
Geoff Levand | a91942a | 2006-06-19 20:33:30 +0200 | [diff] [blame] | 49 | #include <asm/spu_priv1.h> |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 50 | #include "spufs.h" |
Christoph Hellwig | ae142e0 | 2009-06-12 04:31:52 +0000 | [diff] [blame] | 51 | #define CREATE_TRACE_POINTS |
| 52 | #include "sputrace.h" |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 53 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 54 | struct spu_prio_array { |
Christoph Hellwig | 72cb360 | 2007-02-13 21:54:28 +0100 | [diff] [blame] | 55 | DECLARE_BITMAP(bitmap, MAX_PRIO); |
Christoph Hellwig | 079cdb6 | 2007-02-13 21:54:23 +0100 | [diff] [blame] | 56 | struct list_head runq[MAX_PRIO]; |
| 57 | spinlock_t runq_lock; |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 58 | int nr_waiting; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 59 | }; |
| 60 | |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 61 | static unsigned long spu_avenrun[3]; |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 62 | static struct spu_prio_array *spu_prio; |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 63 | static struct task_struct *spusched_task; |
| 64 | static struct timer_list spusched_timer; |
Aegis Lin | 90608a2 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 65 | static struct timer_list spuloadavg_timer; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 66 | |
Christoph Hellwig | fe443ef | 2007-06-29 10:57:52 +1000 | [diff] [blame] | 67 | /* |
| 68 | * Priority of a normal, non-rt, non-niced'd process (aka nice level 0). |
| 69 | */ |
| 70 | #define NORMAL_PRIO 120 |
| 71 | |
| 72 | /* |
| 73 | * Frequency of the spu scheduler tick. By default we do one SPU scheduler |
| 74 | * tick for every 10 CPU scheduler ticks. |
| 75 | */ |
| 76 | #define SPUSCHED_TICK (10) |
| 77 | |
| 78 | /* |
| 79 | * These are the 'tuning knobs' of the scheduler: |
| 80 | * |
Jeremy Kerr | 60e2423 | 2007-06-29 10:57:53 +1000 | [diff] [blame] | 81 | * Minimum timeslice is 5 msecs (or 1 spu scheduler tick, whichever is |
| 82 | * larger), default timeslice is 100 msecs, maximum timeslice is 800 msecs. |
Christoph Hellwig | fe443ef | 2007-06-29 10:57:52 +1000 | [diff] [blame] | 83 | */ |
Jeremy Kerr | 60e2423 | 2007-06-29 10:57:53 +1000 | [diff] [blame] | 84 | #define MIN_SPU_TIMESLICE max(5 * HZ / (1000 * SPUSCHED_TICK), 1) |
| 85 | #define DEF_SPU_TIMESLICE (100 * HZ / (1000 * SPUSCHED_TICK)) |
Christoph Hellwig | fe443ef | 2007-06-29 10:57:52 +1000 | [diff] [blame] | 86 | |
Christoph Hellwig | fe443ef | 2007-06-29 10:57:52 +1000 | [diff] [blame] | 87 | #define SCALE_PRIO(x, prio) \ |
| 88 | max(x * (MAX_PRIO - prio) / (MAX_USER_PRIO / 2), MIN_SPU_TIMESLICE) |
| 89 | |
| 90 | /* |
| 91 | * scale user-nice values [ -20 ... 0 ... 19 ] to time slice values: |
| 92 | * [800ms ... 100ms ... 5ms] |
| 93 | * |
| 94 | * The higher a thread's priority, the bigger timeslices |
| 95 | * it gets during one round of execution. But even the lowest |
| 96 | * priority thread gets MIN_TIMESLICE worth of execution time. |
| 97 | */ |
| 98 | void spu_set_timeslice(struct spu_context *ctx) |
| 99 | { |
| 100 | if (ctx->prio < NORMAL_PRIO) |
| 101 | ctx->time_slice = SCALE_PRIO(DEF_SPU_TIMESLICE * 4, ctx->prio); |
| 102 | else |
| 103 | ctx->time_slice = SCALE_PRIO(DEF_SPU_TIMESLICE, ctx->prio); |
| 104 | } |
| 105 | |
Christoph Hellwig | 2cf2b3b | 2007-06-29 10:57:55 +1000 | [diff] [blame] | 106 | /* |
| 107 | * Update scheduling information from the owning thread. |
| 108 | */ |
| 109 | void __spu_update_sched_info(struct spu_context *ctx) |
| 110 | { |
| 111 | /* |
Luke Browning | 9156953 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 112 | * assert that the context is not on the runqueue, so it is safe |
| 113 | * to change its scheduling parameters. |
| 114 | */ |
| 115 | BUG_ON(!list_empty(&ctx->rq)); |
| 116 | |
| 117 | /* |
Julio M. Merino Vidal | 9b1d21f | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 118 | * 32-Bit assignments are atomic on powerpc, and we don't care about |
| 119 | * memory ordering here because retrieving the controlling thread is |
| 120 | * per definition racy. |
Christoph Hellwig | 476273a | 2007-06-29 10:58:01 +1000 | [diff] [blame] | 121 | */ |
| 122 | ctx->tid = current->pid; |
| 123 | |
| 124 | /* |
Christoph Hellwig | 2cf2b3b | 2007-06-29 10:57:55 +1000 | [diff] [blame] | 125 | * We do our own priority calculations, so we normally want |
Julio M. Merino Vidal | 9b1d21f | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 126 | * ->static_prio to start with. Unfortunately this field |
Christoph Hellwig | 2cf2b3b | 2007-06-29 10:57:55 +1000 | [diff] [blame] | 127 | * contains junk for threads with a realtime scheduling |
| 128 | * policy so we have to look at ->prio in this case. |
| 129 | */ |
| 130 | if (rt_prio(current->prio)) |
| 131 | ctx->prio = current->prio; |
| 132 | else |
| 133 | ctx->prio = current->static_prio; |
| 134 | ctx->policy = current->policy; |
Christoph Hellwig | ea1ae59 | 2007-06-29 10:57:56 +1000 | [diff] [blame] | 135 | |
| 136 | /* |
Luke Browning | 9156953 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 137 | * TO DO: the context may be loaded, so we may need to activate |
| 138 | * it again on a different node. But it shouldn't hurt anything |
| 139 | * to update its parameters, because we know that the scheduler |
| 140 | * is not actively looking at this field, since it is not on the |
| 141 | * runqueue. The context will be rescheduled on the proper node |
| 142 | * if it is timesliced or preempted. |
Christoph Hellwig | ea1ae59 | 2007-06-29 10:57:56 +1000 | [diff] [blame] | 143 | */ |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 144 | cpumask_copy(&ctx->cpus_allowed, tsk_cpus_allowed(current)); |
Luke Browning | 7a21420 | 2008-04-28 14:32:34 +1000 | [diff] [blame] | 145 | |
| 146 | /* Save the current cpu id for spu interrupt routing. */ |
| 147 | ctx->last_ran = raw_smp_processor_id(); |
Christoph Hellwig | 2cf2b3b | 2007-06-29 10:57:55 +1000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | void spu_update_sched_info(struct spu_context *ctx) |
| 151 | { |
Luke Browning | 9156953 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 152 | int node; |
Christoph Hellwig | 2cf2b3b | 2007-06-29 10:57:55 +1000 | [diff] [blame] | 153 | |
Luke Browning | 9156953 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 154 | if (ctx->state == SPU_STATE_RUNNABLE) { |
| 155 | node = ctx->spu->node; |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 156 | |
| 157 | /* |
| 158 | * Take list_mutex to sync with find_victim(). |
| 159 | */ |
Luke Browning | 9156953 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 160 | mutex_lock(&cbe_spu_info[node].list_mutex); |
| 161 | __spu_update_sched_info(ctx); |
| 162 | mutex_unlock(&cbe_spu_info[node].list_mutex); |
| 163 | } else { |
| 164 | __spu_update_sched_info(ctx); |
| 165 | } |
Christoph Hellwig | 2cf2b3b | 2007-06-29 10:57:55 +1000 | [diff] [blame] | 166 | } |
| 167 | |
Christoph Hellwig | ea1ae59 | 2007-06-29 10:57:56 +1000 | [diff] [blame] | 168 | static int __node_allowed(struct spu_context *ctx, int node) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 169 | { |
Christoph Hellwig | ea1ae59 | 2007-06-29 10:57:56 +1000 | [diff] [blame] | 170 | if (nr_cpus_node(node)) { |
Rusty Russell | 86c6f27 | 2008-12-26 22:23:39 +1030 | [diff] [blame] | 171 | const struct cpumask *mask = cpumask_of_node(node); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 172 | |
Rusty Russell | 86c6f27 | 2008-12-26 22:23:39 +1030 | [diff] [blame] | 173 | if (cpumask_intersects(mask, &ctx->cpus_allowed)) |
Christoph Hellwig | ea1ae59 | 2007-06-29 10:57:56 +1000 | [diff] [blame] | 174 | return 1; |
| 175 | } |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static int node_allowed(struct spu_context *ctx, int node) |
| 181 | { |
| 182 | int rval; |
| 183 | |
| 184 | spin_lock(&spu_prio->runq_lock); |
| 185 | rval = __node_allowed(ctx, node); |
| 186 | spin_unlock(&spu_prio->runq_lock); |
| 187 | |
| 188 | return rval; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 189 | } |
| 190 | |
Bob Nelson | aed3a8c | 2007-12-15 01:27:30 +1100 | [diff] [blame] | 191 | void do_notify_spus_active(void) |
Bob Nelson | 36aaccc | 2007-07-20 21:39:52 +0200 | [diff] [blame] | 192 | { |
| 193 | int node; |
| 194 | |
| 195 | /* |
| 196 | * Wake up the active spu_contexts. |
| 197 | * |
| 198 | * When the awakened processes see their "notify_active" flag is set, |
Julio M. Merino Vidal | 9b1d21f | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 199 | * they will call spu_switch_notify(). |
Bob Nelson | 36aaccc | 2007-07-20 21:39:52 +0200 | [diff] [blame] | 200 | */ |
| 201 | for_each_online_node(node) { |
| 202 | struct spu *spu; |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 203 | |
| 204 | mutex_lock(&cbe_spu_info[node].list_mutex); |
| 205 | list_for_each_entry(spu, &cbe_spu_info[node].spus, cbe_list) { |
| 206 | if (spu->alloc_state != SPU_FREE) { |
| 207 | struct spu_context *ctx = spu->ctx; |
| 208 | set_bit(SPU_SCHED_NOTIFY_ACTIVE, |
| 209 | &ctx->sched_flags); |
| 210 | mb(); |
| 211 | wake_up_all(&ctx->stop_wq); |
| 212 | } |
Bob Nelson | 36aaccc | 2007-07-20 21:39:52 +0200 | [diff] [blame] | 213 | } |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 214 | mutex_unlock(&cbe_spu_info[node].list_mutex); |
Bob Nelson | 36aaccc | 2007-07-20 21:39:52 +0200 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
Christoph Hellwig | 202557d | 2007-02-13 21:36:49 +0100 | [diff] [blame] | 218 | /** |
| 219 | * spu_bind_context - bind spu context to physical spu |
| 220 | * @spu: physical spu to bind to |
| 221 | * @ctx: context to bind |
| 222 | */ |
| 223 | static void spu_bind_context(struct spu *spu, struct spu_context *ctx) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 224 | { |
Christoph Hellwig | 038200c | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 225 | spu_context_trace(spu_bind_context__enter, ctx, spu); |
| 226 | |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 227 | spuctx_switch_state(ctx, SPU_UTIL_SYSTEM); |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 228 | |
Arnd Bergmann | aa6d5b2 | 2007-07-20 21:39:44 +0200 | [diff] [blame] | 229 | if (ctx->flags & SPU_CREATE_NOSCHED) |
| 230 | atomic_inc(&cbe_spu_info[spu->node].reserved_spus); |
| 231 | |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 232 | ctx->stats.slb_flt_base = spu->stats.slb_flt; |
| 233 | ctx->stats.class2_intr_base = spu->stats.class2_intr; |
| 234 | |
Luke Browning | 2c911a1 | 2008-06-13 14:17:35 +1000 | [diff] [blame] | 235 | spu_associate_mm(spu, ctx->owner); |
| 236 | |
| 237 | spin_lock_irq(&spu->register_lock); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 238 | spu->ctx = ctx; |
| 239 | spu->flags = 0; |
| 240 | ctx->spu = spu; |
| 241 | ctx->ops = &spu_hw_ops; |
| 242 | spu->pid = current->pid; |
Bob Nelson | 1474855 | 2007-07-20 21:39:53 +0200 | [diff] [blame] | 243 | spu->tgid = current->tgid; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 244 | spu->ibox_callback = spufs_ibox_callback; |
| 245 | spu->wbox_callback = spufs_wbox_callback; |
Arnd Bergmann | 5110459 | 2005-12-05 22:52:25 -0500 | [diff] [blame] | 246 | spu->stop_callback = spufs_stop_callback; |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 247 | spu->mfc_callback = spufs_mfc_callback; |
Luke Browning | 2c911a1 | 2008-06-13 14:17:35 +1000 | [diff] [blame] | 248 | spin_unlock_irq(&spu->register_lock); |
| 249 | |
Arnd Bergmann | 5110459 | 2005-12-05 22:52:25 -0500 | [diff] [blame] | 250 | spu_unmap_mappings(ctx); |
Luke Browning | 2c911a1 | 2008-06-13 14:17:35 +1000 | [diff] [blame] | 251 | |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 252 | spu_switch_log_notify(spu, ctx, SWITCH_LOG_START, 0); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 253 | spu_restore(&ctx->csa, spu); |
Arnd Bergmann | 2a911f0 | 2005-12-05 22:52:26 -0500 | [diff] [blame] | 254 | spu->timestamp = jiffies; |
Arnd Bergmann | 8676727 | 2006-10-04 17:26:21 +0200 | [diff] [blame] | 255 | spu_switch_notify(spu, ctx); |
Christoph Hellwig | 81998ba | 2007-02-13 21:36:48 +0100 | [diff] [blame] | 256 | ctx->state = SPU_STATE_RUNNABLE; |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 257 | |
Andre Detsch | 2a58aa3 | 2008-02-25 15:07:42 -0300 | [diff] [blame] | 258 | spuctx_switch_state(ctx, SPU_UTIL_USER); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 259 | } |
| 260 | |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 261 | /* |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 262 | * Must be used with the list_mutex held. |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 263 | */ |
| 264 | static inline int sched_spu(struct spu *spu) |
| 265 | { |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 266 | BUG_ON(!mutex_is_locked(&cbe_spu_info[spu->node].list_mutex)); |
| 267 | |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 268 | return (!spu->ctx || !(spu->ctx->flags & SPU_CREATE_NOSCHED)); |
| 269 | } |
| 270 | |
| 271 | static void aff_merge_remaining_ctxs(struct spu_gang *gang) |
| 272 | { |
| 273 | struct spu_context *ctx; |
| 274 | |
| 275 | list_for_each_entry(ctx, &gang->aff_list_head, aff_list) { |
| 276 | if (list_empty(&ctx->aff_list)) |
| 277 | list_add(&ctx->aff_list, &gang->aff_list_head); |
| 278 | } |
| 279 | gang->aff_flags |= AFF_MERGED; |
| 280 | } |
| 281 | |
| 282 | static void aff_set_offsets(struct spu_gang *gang) |
| 283 | { |
| 284 | struct spu_context *ctx; |
| 285 | int offset; |
| 286 | |
| 287 | offset = -1; |
| 288 | list_for_each_entry_reverse(ctx, &gang->aff_ref_ctx->aff_list, |
| 289 | aff_list) { |
| 290 | if (&ctx->aff_list == &gang->aff_list_head) |
| 291 | break; |
| 292 | ctx->aff_offset = offset--; |
| 293 | } |
| 294 | |
| 295 | offset = 0; |
| 296 | list_for_each_entry(ctx, gang->aff_ref_ctx->aff_list.prev, aff_list) { |
| 297 | if (&ctx->aff_list == &gang->aff_list_head) |
| 298 | break; |
| 299 | ctx->aff_offset = offset++; |
| 300 | } |
| 301 | |
| 302 | gang->aff_flags |= AFF_OFFSETS_SET; |
| 303 | } |
| 304 | |
| 305 | static struct spu *aff_ref_location(struct spu_context *ctx, int mem_aff, |
| 306 | int group_size, int lowest_offset) |
| 307 | { |
| 308 | struct spu *spu; |
| 309 | int node, n; |
| 310 | |
| 311 | /* |
| 312 | * TODO: A better algorithm could be used to find a good spu to be |
| 313 | * used as reference location for the ctxs chain. |
| 314 | */ |
| 315 | node = cpu_to_node(raw_smp_processor_id()); |
| 316 | for (n = 0; n < MAX_NUMNODES; n++, node++) { |
Andre Detsch | 10baa26 | 2008-10-21 11:15:23 +1100 | [diff] [blame] | 317 | /* |
| 318 | * "available_spus" counts how many spus are not potentially |
| 319 | * going to be used by other affinity gangs whose reference |
| 320 | * context is already in place. Although this code seeks to |
| 321 | * avoid having affinity gangs with a summed amount of |
| 322 | * contexts bigger than the amount of spus in the node, |
| 323 | * this may happen sporadically. In this case, available_spus |
| 324 | * becomes negative, which is harmless. |
| 325 | */ |
Andre Detsch | ad1ede1 | 2008-07-24 11:01:54 +1000 | [diff] [blame] | 326 | int available_spus; |
| 327 | |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 328 | node = (node < MAX_NUMNODES) ? node : 0; |
| 329 | if (!node_allowed(ctx, node)) |
| 330 | continue; |
Andre Detsch | ad1ede1 | 2008-07-24 11:01:54 +1000 | [diff] [blame] | 331 | |
| 332 | available_spus = 0; |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 333 | mutex_lock(&cbe_spu_info[node].list_mutex); |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 334 | list_for_each_entry(spu, &cbe_spu_info[node].spus, cbe_list) { |
Andre Detsch | 10baa26 | 2008-10-21 11:15:23 +1100 | [diff] [blame] | 335 | if (spu->ctx && spu->ctx->gang && !spu->ctx->aff_offset |
| 336 | && spu->ctx->gang->aff_ref_spu) |
| 337 | available_spus -= spu->ctx->gang->contexts; |
| 338 | available_spus++; |
Andre Detsch | ad1ede1 | 2008-07-24 11:01:54 +1000 | [diff] [blame] | 339 | } |
| 340 | if (available_spus < ctx->gang->contexts) { |
| 341 | mutex_unlock(&cbe_spu_info[node].list_mutex); |
| 342 | continue; |
| 343 | } |
| 344 | |
| 345 | list_for_each_entry(spu, &cbe_spu_info[node].spus, cbe_list) { |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 346 | if ((!mem_aff || spu->has_mem_affinity) && |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 347 | sched_spu(spu)) { |
| 348 | mutex_unlock(&cbe_spu_info[node].list_mutex); |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 349 | return spu; |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 350 | } |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 351 | } |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 352 | mutex_unlock(&cbe_spu_info[node].list_mutex); |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 353 | } |
| 354 | return NULL; |
| 355 | } |
| 356 | |
| 357 | static void aff_set_ref_point_location(struct spu_gang *gang) |
| 358 | { |
| 359 | int mem_aff, gs, lowest_offset; |
| 360 | struct spu_context *ctx; |
| 361 | struct spu *tmp; |
| 362 | |
| 363 | mem_aff = gang->aff_ref_ctx->flags & SPU_CREATE_AFFINITY_MEM; |
| 364 | lowest_offset = 0; |
| 365 | gs = 0; |
| 366 | |
| 367 | list_for_each_entry(tmp, &gang->aff_list_head, aff_list) |
| 368 | gs++; |
| 369 | |
| 370 | list_for_each_entry_reverse(ctx, &gang->aff_ref_ctx->aff_list, |
| 371 | aff_list) { |
| 372 | if (&ctx->aff_list == &gang->aff_list_head) |
| 373 | break; |
| 374 | lowest_offset = ctx->aff_offset; |
| 375 | } |
| 376 | |
Andre Detsch | 683e3ab | 2007-07-31 09:48:11 +1000 | [diff] [blame] | 377 | gang->aff_ref_spu = aff_ref_location(gang->aff_ref_ctx, mem_aff, gs, |
| 378 | lowest_offset); |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 379 | } |
| 380 | |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 381 | static struct spu *ctx_location(struct spu *ref, int offset, int node) |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 382 | { |
| 383 | struct spu *spu; |
| 384 | |
| 385 | spu = NULL; |
| 386 | if (offset >= 0) { |
| 387 | list_for_each_entry(spu, ref->aff_list.prev, aff_list) { |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 388 | BUG_ON(spu->node != node); |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 389 | if (offset == 0) |
| 390 | break; |
| 391 | if (sched_spu(spu)) |
| 392 | offset--; |
| 393 | } |
| 394 | } else { |
| 395 | list_for_each_entry_reverse(spu, ref->aff_list.next, aff_list) { |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 396 | BUG_ON(spu->node != node); |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 397 | if (offset == 0) |
| 398 | break; |
| 399 | if (sched_spu(spu)) |
| 400 | offset++; |
| 401 | } |
| 402 | } |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 403 | |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 404 | return spu; |
| 405 | } |
| 406 | |
| 407 | /* |
| 408 | * affinity_check is called each time a context is going to be scheduled. |
| 409 | * It returns the spu ptr on which the context must run. |
| 410 | */ |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 411 | static int has_affinity(struct spu_context *ctx) |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 412 | { |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 413 | struct spu_gang *gang = ctx->gang; |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 414 | |
| 415 | if (list_empty(&ctx->aff_list)) |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 416 | return 0; |
| 417 | |
Andre Detsch | 0855b54 | 2008-07-24 10:57:26 +1000 | [diff] [blame] | 418 | if (atomic_read(&ctx->gang->aff_sched_count) == 0) |
| 419 | ctx->gang->aff_ref_spu = NULL; |
| 420 | |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 421 | if (!gang->aff_ref_spu) { |
| 422 | if (!(gang->aff_flags & AFF_MERGED)) |
| 423 | aff_merge_remaining_ctxs(gang); |
| 424 | if (!(gang->aff_flags & AFF_OFFSETS_SET)) |
| 425 | aff_set_offsets(gang); |
| 426 | aff_set_ref_point_location(gang); |
| 427 | } |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 428 | |
| 429 | return gang->aff_ref_spu != NULL; |
Arnd Bergmann | c5fc8d2 | 2007-07-20 21:39:48 +0200 | [diff] [blame] | 430 | } |
| 431 | |
Christoph Hellwig | 202557d | 2007-02-13 21:36:49 +0100 | [diff] [blame] | 432 | /** |
| 433 | * spu_unbind_context - unbind spu context from physical spu |
| 434 | * @spu: physical spu to unbind from |
| 435 | * @ctx: context to unbind |
Christoph Hellwig | 202557d | 2007-02-13 21:36:49 +0100 | [diff] [blame] | 436 | */ |
Christoph Hellwig | 678b2ff | 2007-02-13 21:54:25 +0100 | [diff] [blame] | 437 | static void spu_unbind_context(struct spu *spu, struct spu_context *ctx) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 438 | { |
Luke Browning | 028fda0 | 2008-06-16 10:42:38 +1000 | [diff] [blame] | 439 | u32 status; |
| 440 | |
Christoph Hellwig | 038200c | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 441 | spu_context_trace(spu_unbind_context__enter, ctx, spu); |
| 442 | |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 443 | spuctx_switch_state(ctx, SPU_UTIL_SYSTEM); |
Christoph Hellwig | fe2f896 | 2007-06-29 10:58:07 +1000 | [diff] [blame] | 444 | |
Arnd Bergmann | aa6d5b2 | 2007-07-20 21:39:44 +0200 | [diff] [blame] | 445 | if (spu->ctx->flags & SPU_CREATE_NOSCHED) |
| 446 | atomic_dec(&cbe_spu_info[spu->node].reserved_spus); |
Andre Detsch | 36ddbb1 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 447 | |
Andre Detsch | 0855b54 | 2008-07-24 10:57:26 +1000 | [diff] [blame] | 448 | if (ctx->gang) |
Andre Detsch | 34318c2 | 2008-10-21 11:16:09 +1100 | [diff] [blame] | 449 | /* |
| 450 | * If ctx->gang->aff_sched_count is positive, SPU affinity is |
| 451 | * being considered in this gang. Using atomic_dec_if_positive |
| 452 | * allow us to skip an explicit check for affinity in this gang |
| 453 | */ |
Andre Detsch | 0855b54 | 2008-07-24 10:57:26 +1000 | [diff] [blame] | 454 | atomic_dec_if_positive(&ctx->gang->aff_sched_count); |
Andre Detsch | 36ddbb1 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 455 | |
Arnd Bergmann | 8676727 | 2006-10-04 17:26:21 +0200 | [diff] [blame] | 456 | spu_switch_notify(spu, NULL); |
Arnd Bergmann | 5110459 | 2005-12-05 22:52:25 -0500 | [diff] [blame] | 457 | spu_unmap_mappings(ctx); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 458 | spu_save(&ctx->csa, spu); |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 459 | spu_switch_log_notify(spu, ctx, SWITCH_LOG_STOP, 0); |
Luke Browning | 2c911a1 | 2008-06-13 14:17:35 +1000 | [diff] [blame] | 460 | |
| 461 | spin_lock_irq(&spu->register_lock); |
Arnd Bergmann | 2a911f0 | 2005-12-05 22:52:26 -0500 | [diff] [blame] | 462 | spu->timestamp = jiffies; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 463 | ctx->state = SPU_STATE_SAVED; |
| 464 | spu->ibox_callback = NULL; |
| 465 | spu->wbox_callback = NULL; |
Arnd Bergmann | 5110459 | 2005-12-05 22:52:25 -0500 | [diff] [blame] | 466 | spu->stop_callback = NULL; |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 467 | spu->mfc_callback = NULL; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 468 | spu->pid = 0; |
Bob Nelson | 1474855 | 2007-07-20 21:39:53 +0200 | [diff] [blame] | 469 | spu->tgid = 0; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 470 | ctx->ops = &spu_backing_ops; |
Arnd Bergmann | 2a911f0 | 2005-12-05 22:52:26 -0500 | [diff] [blame] | 471 | spu->flags = 0; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 472 | spu->ctx = NULL; |
Luke Browning | 2c911a1 | 2008-06-13 14:17:35 +1000 | [diff] [blame] | 473 | spin_unlock_irq(&spu->register_lock); |
| 474 | |
| 475 | spu_associate_mm(spu, NULL); |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 476 | |
| 477 | ctx->stats.slb_flt += |
| 478 | (spu->stats.slb_flt - ctx->stats.slb_flt_base); |
| 479 | ctx->stats.class2_intr += |
| 480 | (spu->stats.class2_intr - ctx->stats.class2_intr_base); |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 481 | |
| 482 | /* This maps the underlying spu state to idle */ |
| 483 | spuctx_switch_state(ctx, SPU_UTIL_IDLE_LOADED); |
| 484 | ctx->spu = NULL; |
Luke Browning | 028fda0 | 2008-06-16 10:42:38 +1000 | [diff] [blame] | 485 | |
| 486 | if (spu_stopped(ctx, &status)) |
| 487 | wake_up_all(&ctx->stop_wq); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 488 | } |
| 489 | |
Christoph Hellwig | 079cdb6 | 2007-02-13 21:54:23 +0100 | [diff] [blame] | 490 | /** |
| 491 | * spu_add_to_rq - add a context to the runqueue |
| 492 | * @ctx: context to add |
| 493 | */ |
Luke Browning | 4e0f4ed | 2007-04-23 21:08:13 +0200 | [diff] [blame] | 494 | static void __spu_add_to_rq(struct spu_context *ctx) |
Arnd Bergmann | 2a911f0 | 2005-12-05 22:52:26 -0500 | [diff] [blame] | 495 | { |
Christoph Hellwig | 2744997 | 2007-06-29 10:58:06 +1000 | [diff] [blame] | 496 | /* |
| 497 | * Unfortunately this code path can be called from multiple threads |
| 498 | * on behalf of a single context due to the way the problem state |
| 499 | * mmap support works. |
| 500 | * |
| 501 | * Fortunately we need to wake up all these threads at the same time |
| 502 | * and can simply skip the runqueue addition for every but the first |
| 503 | * thread getting into this codepath. |
| 504 | * |
| 505 | * It's still quite hacky, and long-term we should proxy all other |
| 506 | * threads through the owner thread so that spu_run is in control |
| 507 | * of all the scheduling activity for a given context. |
| 508 | */ |
| 509 | if (list_empty(&ctx->rq)) { |
| 510 | list_add_tail(&ctx->rq, &spu_prio->runq[ctx->prio]); |
| 511 | set_bit(ctx->prio, spu_prio->bitmap); |
| 512 | if (!spu_prio->nr_waiting++) |
Ingo Molnar | 7401922 | 2009-02-18 12:23:29 +0100 | [diff] [blame] | 513 | mod_timer(&spusched_timer, jiffies + SPUSCHED_TICK); |
Christoph Hellwig | 2744997 | 2007-06-29 10:58:06 +1000 | [diff] [blame] | 514 | } |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 515 | } |
Arnd Bergmann | 2a911f0 | 2005-12-05 22:52:26 -0500 | [diff] [blame] | 516 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 517 | static void spu_add_to_rq(struct spu_context *ctx) |
| 518 | { |
| 519 | spin_lock(&spu_prio->runq_lock); |
| 520 | __spu_add_to_rq(ctx); |
| 521 | spin_unlock(&spu_prio->runq_lock); |
| 522 | } |
| 523 | |
Luke Browning | 4e0f4ed | 2007-04-23 21:08:13 +0200 | [diff] [blame] | 524 | static void __spu_del_from_rq(struct spu_context *ctx) |
Christoph Hellwig | a475c2f | 2007-04-23 21:08:11 +0200 | [diff] [blame] | 525 | { |
Luke Browning | 4e0f4ed | 2007-04-23 21:08:13 +0200 | [diff] [blame] | 526 | int prio = ctx->prio; |
| 527 | |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 528 | if (!list_empty(&ctx->rq)) { |
Christoph Hellwig | c77239b | 2007-06-29 10:58:05 +1000 | [diff] [blame] | 529 | if (!--spu_prio->nr_waiting) |
| 530 | del_timer(&spusched_timer); |
Christoph Hellwig | a475c2f | 2007-04-23 21:08:11 +0200 | [diff] [blame] | 531 | list_del_init(&ctx->rq); |
Christoph Hellwig | c77239b | 2007-06-29 10:58:05 +1000 | [diff] [blame] | 532 | |
| 533 | if (list_empty(&spu_prio->runq[prio])) |
| 534 | clear_bit(prio, spu_prio->bitmap); |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 535 | } |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 536 | } |
| 537 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 538 | void spu_del_from_rq(struct spu_context *ctx) |
| 539 | { |
| 540 | spin_lock(&spu_prio->runq_lock); |
| 541 | __spu_del_from_rq(ctx); |
| 542 | spin_unlock(&spu_prio->runq_lock); |
| 543 | } |
| 544 | |
Christoph Hellwig | 079cdb6 | 2007-02-13 21:54:23 +0100 | [diff] [blame] | 545 | static void spu_prio_wait(struct spu_context *ctx) |
| 546 | { |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 547 | DEFINE_WAIT(wait); |
| 548 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 549 | /* |
| 550 | * The caller must explicitly wait for a context to be loaded |
| 551 | * if the nosched flag is set. If NOSCHED is not set, the caller |
| 552 | * queues the context and waits for an spu event or error. |
| 553 | */ |
| 554 | BUG_ON(!(ctx->flags & SPU_CREATE_NOSCHED)); |
| 555 | |
Luke Browning | 4e0f4ed | 2007-04-23 21:08:13 +0200 | [diff] [blame] | 556 | spin_lock(&spu_prio->runq_lock); |
Christoph Hellwig | 079cdb6 | 2007-02-13 21:54:23 +0100 | [diff] [blame] | 557 | prepare_to_wait_exclusive(&ctx->stop_wq, &wait, TASK_INTERRUPTIBLE); |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 558 | if (!signal_pending(current)) { |
Luke Browning | 4e0f4ed | 2007-04-23 21:08:13 +0200 | [diff] [blame] | 559 | __spu_add_to_rq(ctx); |
| 560 | spin_unlock(&spu_prio->runq_lock); |
Christoph Hellwig | 650f8b0 | 2007-02-13 21:36:50 +0100 | [diff] [blame] | 561 | mutex_unlock(&ctx->state_mutex); |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 562 | schedule(); |
Christoph Hellwig | 650f8b0 | 2007-02-13 21:36:50 +0100 | [diff] [blame] | 563 | mutex_lock(&ctx->state_mutex); |
Luke Browning | 4e0f4ed | 2007-04-23 21:08:13 +0200 | [diff] [blame] | 564 | spin_lock(&spu_prio->runq_lock); |
| 565 | __spu_del_from_rq(ctx); |
Arnd Bergmann | 2a911f0 | 2005-12-05 22:52:26 -0500 | [diff] [blame] | 566 | } |
Luke Browning | 4e0f4ed | 2007-04-23 21:08:13 +0200 | [diff] [blame] | 567 | spin_unlock(&spu_prio->runq_lock); |
Christoph Hellwig | 079cdb6 | 2007-02-13 21:54:23 +0100 | [diff] [blame] | 568 | __set_current_state(TASK_RUNNING); |
| 569 | remove_wait_queue(&ctx->stop_wq, &wait); |
Arnd Bergmann | 2a911f0 | 2005-12-05 22:52:26 -0500 | [diff] [blame] | 570 | } |
| 571 | |
Christoph Hellwig | 079cdb6 | 2007-02-13 21:54:23 +0100 | [diff] [blame] | 572 | static struct spu *spu_get_idle(struct spu_context *ctx) |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 573 | { |
Andre Detsch | 36ddbb1 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 574 | struct spu *spu, *aff_ref_spu; |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 575 | int node, n; |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 576 | |
Christoph Hellwig | 038200c | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 577 | spu_context_nospu_trace(spu_get_idle__enter, ctx); |
| 578 | |
Andre Detsch | 36ddbb1 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 579 | if (ctx->gang) { |
| 580 | mutex_lock(&ctx->gang->aff_mutex); |
| 581 | if (has_affinity(ctx)) { |
| 582 | aff_ref_spu = ctx->gang->aff_ref_spu; |
| 583 | atomic_inc(&ctx->gang->aff_sched_count); |
| 584 | mutex_unlock(&ctx->gang->aff_mutex); |
| 585 | node = aff_ref_spu->node; |
Arnd Bergmann | cbc23d3 | 2007-07-20 21:39:49 +0200 | [diff] [blame] | 586 | |
Andre Detsch | 36ddbb1 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 587 | mutex_lock(&cbe_spu_info[node].list_mutex); |
| 588 | spu = ctx_location(aff_ref_spu, ctx->aff_offset, node); |
| 589 | if (spu && spu->alloc_state == SPU_FREE) |
| 590 | goto found; |
| 591 | mutex_unlock(&cbe_spu_info[node].list_mutex); |
| 592 | |
Andre Detsch | 0855b54 | 2008-07-24 10:57:26 +1000 | [diff] [blame] | 593 | atomic_dec(&ctx->gang->aff_sched_count); |
Christoph Hellwig | 038200c | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 594 | goto not_found; |
Andre Detsch | 36ddbb1 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 595 | } |
| 596 | mutex_unlock(&ctx->gang->aff_mutex); |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 597 | } |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 598 | node = cpu_to_node(raw_smp_processor_id()); |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 599 | for (n = 0; n < MAX_NUMNODES; n++, node++) { |
| 600 | node = (node < MAX_NUMNODES) ? node : 0; |
Christoph Hellwig | ea1ae59 | 2007-06-29 10:57:56 +1000 | [diff] [blame] | 601 | if (!node_allowed(ctx, node)) |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 602 | continue; |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 603 | |
| 604 | mutex_lock(&cbe_spu_info[node].list_mutex); |
| 605 | list_for_each_entry(spu, &cbe_spu_info[node].spus, cbe_list) { |
| 606 | if (spu->alloc_state == SPU_FREE) |
| 607 | goto found; |
| 608 | } |
| 609 | mutex_unlock(&cbe_spu_info[node].list_mutex); |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 610 | } |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 611 | |
Christoph Hellwig | 038200c | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 612 | not_found: |
| 613 | spu_context_nospu_trace(spu_get_idle__not_found, ctx); |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 614 | return NULL; |
| 615 | |
| 616 | found: |
| 617 | spu->alloc_state = SPU_USED; |
| 618 | mutex_unlock(&cbe_spu_info[node].list_mutex); |
Christoph Hellwig | 038200c | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 619 | spu_context_trace(spu_get_idle__found, ctx, spu); |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 620 | spu_init_channels(spu); |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 621 | return spu; |
| 622 | } |
| 623 | |
Christoph Hellwig | 079cdb6 | 2007-02-13 21:54:23 +0100 | [diff] [blame] | 624 | /** |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 625 | * find_victim - find a lower priority context to preempt |
Michael Ellerman | 027dfac | 2016-06-01 16:34:37 +1000 | [diff] [blame] | 626 | * @ctx: candidate context for running |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 627 | * |
| 628 | * Returns the freed physical spu to run the new context on. |
| 629 | */ |
| 630 | static struct spu *find_victim(struct spu_context *ctx) |
| 631 | { |
| 632 | struct spu_context *victim = NULL; |
| 633 | struct spu *spu; |
| 634 | int node, n; |
| 635 | |
Julio M. Merino Vidal | 8a476d4 | 2008-04-30 15:16:14 +1000 | [diff] [blame] | 636 | spu_context_nospu_trace(spu_find_victim__enter, ctx); |
Christoph Hellwig | 038200c | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 637 | |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 638 | /* |
| 639 | * Look for a possible preemption candidate on the local node first. |
| 640 | * If there is no candidate look at the other nodes. This isn't |
Julio M. Merino Vidal | 9b1d21f | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 641 | * exactly fair, but so far the whole spu scheduler tries to keep |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 642 | * a strong node affinity. We might want to fine-tune this in |
| 643 | * the future. |
| 644 | */ |
| 645 | restart: |
| 646 | node = cpu_to_node(raw_smp_processor_id()); |
| 647 | for (n = 0; n < MAX_NUMNODES; n++, node++) { |
| 648 | node = (node < MAX_NUMNODES) ? node : 0; |
Christoph Hellwig | ea1ae59 | 2007-06-29 10:57:56 +1000 | [diff] [blame] | 649 | if (!node_allowed(ctx, node)) |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 650 | continue; |
| 651 | |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 652 | mutex_lock(&cbe_spu_info[node].list_mutex); |
| 653 | list_for_each_entry(spu, &cbe_spu_info[node].spus, cbe_list) { |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 654 | struct spu_context *tmp = spu->ctx; |
| 655 | |
Christoph Hellwig | c0e7b4a | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 656 | if (tmp && tmp->prio > ctx->prio && |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 657 | !(tmp->flags & SPU_CREATE_NOSCHED) && |
Jeremy Kerr | 8d5636f | 2008-08-14 14:59:12 +1000 | [diff] [blame] | 658 | (!victim || tmp->prio > victim->prio)) { |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 659 | victim = spu->ctx; |
Jeremy Kerr | 8d5636f | 2008-08-14 14:59:12 +1000 | [diff] [blame] | 660 | } |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 661 | } |
Jeremy Kerr | 9f43e39 | 2008-09-02 11:57:09 +1000 | [diff] [blame] | 662 | if (victim) |
| 663 | get_spu_context(victim); |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 664 | mutex_unlock(&cbe_spu_info[node].list_mutex); |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 665 | |
| 666 | if (victim) { |
| 667 | /* |
| 668 | * This nests ctx->state_mutex, but we always lock |
| 669 | * higher priority contexts before lower priority |
| 670 | * ones, so this is safe until we introduce |
| 671 | * priority inheritance schemes. |
Luke Browning | 9156953 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 672 | * |
| 673 | * XXX if the highest priority context is locked, |
| 674 | * this can loop a long time. Might be better to |
| 675 | * look at another context or give up after X retries. |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 676 | */ |
| 677 | if (!mutex_trylock(&victim->state_mutex)) { |
Jeremy Kerr | 8d5636f | 2008-08-14 14:59:12 +1000 | [diff] [blame] | 678 | put_spu_context(victim); |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 679 | victim = NULL; |
| 680 | goto restart; |
| 681 | } |
| 682 | |
| 683 | spu = victim->spu; |
Luke Browning | b192541 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 684 | if (!spu || victim->prio <= ctx->prio) { |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 685 | /* |
| 686 | * This race can happen because we've dropped |
Luke Browning | b192541 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 687 | * the active list mutex. Not a problem, just |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 688 | * restart the search. |
| 689 | */ |
| 690 | mutex_unlock(&victim->state_mutex); |
Jeremy Kerr | 8d5636f | 2008-08-14 14:59:12 +1000 | [diff] [blame] | 691 | put_spu_context(victim); |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 692 | victim = NULL; |
| 693 | goto restart; |
| 694 | } |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 695 | |
Christoph Hellwig | 038200c | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 696 | spu_context_trace(__spu_deactivate__unload, ctx, spu); |
| 697 | |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 698 | mutex_lock(&cbe_spu_info[node].list_mutex); |
| 699 | cbe_spu_info[node].nr_active--; |
Christoph Hellwig | c0e7b4a | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 700 | spu_unbind_context(spu, victim); |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 701 | mutex_unlock(&cbe_spu_info[node].list_mutex); |
| 702 | |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 703 | victim->stats.invol_ctx_switch++; |
Christoph Hellwig | fe2f896 | 2007-06-29 10:58:07 +1000 | [diff] [blame] | 704 | spu->stats.invol_ctx_switch++; |
Luke Browning | 08fcf1d | 2008-05-12 14:36:59 +0000 | [diff] [blame] | 705 | if (test_bit(SPU_SCHED_SPU_RUN, &victim->sched_flags)) |
Christoph Hellwig | 7a28a15 | 2008-05-08 15:26:32 +1000 | [diff] [blame] | 706 | spu_add_to_rq(victim); |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 707 | |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 708 | mutex_unlock(&victim->state_mutex); |
Jeremy Kerr | 8d5636f | 2008-08-14 14:59:12 +1000 | [diff] [blame] | 709 | put_spu_context(victim); |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 710 | |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 711 | return spu; |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | return NULL; |
| 716 | } |
| 717 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 718 | static void __spu_schedule(struct spu *spu, struct spu_context *ctx) |
| 719 | { |
| 720 | int node = spu->node; |
| 721 | int success = 0; |
| 722 | |
| 723 | spu_set_timeslice(ctx); |
| 724 | |
| 725 | mutex_lock(&cbe_spu_info[node].list_mutex); |
| 726 | if (spu->ctx == NULL) { |
| 727 | spu_bind_context(spu, ctx); |
| 728 | cbe_spu_info[node].nr_active++; |
| 729 | spu->alloc_state = SPU_USED; |
| 730 | success = 1; |
| 731 | } |
| 732 | mutex_unlock(&cbe_spu_info[node].list_mutex); |
| 733 | |
| 734 | if (success) |
| 735 | wake_up_all(&ctx->run_wq); |
| 736 | else |
| 737 | spu_add_to_rq(ctx); |
| 738 | } |
| 739 | |
| 740 | static void spu_schedule(struct spu *spu, struct spu_context *ctx) |
| 741 | { |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 742 | /* not a candidate for interruptible because it's called either |
| 743 | from the scheduler thread or from spu_deactivate */ |
| 744 | mutex_lock(&ctx->state_mutex); |
Andre Detsch | b2e601d | 2008-09-04 21:16:27 +0000 | [diff] [blame] | 745 | if (ctx->state == SPU_STATE_SAVED) |
| 746 | __spu_schedule(spu, ctx); |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 747 | spu_release(ctx); |
| 748 | } |
| 749 | |
Jeremy Kerr | b65fe03 | 2008-09-04 15:02:47 +1000 | [diff] [blame] | 750 | /** |
| 751 | * spu_unschedule - remove a context from a spu, and possibly release it. |
| 752 | * @spu: The SPU to unschedule from |
| 753 | * @ctx: The context currently scheduled on the SPU |
| 754 | * @free_spu Whether to free the SPU for other contexts |
| 755 | * |
| 756 | * Unbinds the context @ctx from the SPU @spu. If @free_spu is non-zero, the |
| 757 | * SPU is made available for other contexts (ie, may be returned by |
| 758 | * spu_get_idle). If this is zero, the caller is expected to schedule another |
| 759 | * context to this spu. |
| 760 | * |
| 761 | * Should be called with ctx->state_mutex held. |
| 762 | */ |
| 763 | static void spu_unschedule(struct spu *spu, struct spu_context *ctx, |
| 764 | int free_spu) |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 765 | { |
| 766 | int node = spu->node; |
| 767 | |
| 768 | mutex_lock(&cbe_spu_info[node].list_mutex); |
| 769 | cbe_spu_info[node].nr_active--; |
Jeremy Kerr | b65fe03 | 2008-09-04 15:02:47 +1000 | [diff] [blame] | 770 | if (free_spu) |
| 771 | spu->alloc_state = SPU_FREE; |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 772 | spu_unbind_context(spu, ctx); |
| 773 | ctx->stats.invol_ctx_switch++; |
| 774 | spu->stats.invol_ctx_switch++; |
| 775 | mutex_unlock(&cbe_spu_info[node].list_mutex); |
| 776 | } |
| 777 | |
Christoph Hellwig | 52f04fc | 2007-02-13 21:54:27 +0100 | [diff] [blame] | 778 | /** |
Christoph Hellwig | 079cdb6 | 2007-02-13 21:54:23 +0100 | [diff] [blame] | 779 | * spu_activate - find a free spu for a context and execute it |
| 780 | * @ctx: spu context to schedule |
| 781 | * @flags: flags (currently ignored) |
| 782 | * |
Christoph Hellwig | 0887309 | 2007-04-23 21:08:06 +0200 | [diff] [blame] | 783 | * Tries to find a free spu to run @ctx. If no free spu is available |
Christoph Hellwig | 079cdb6 | 2007-02-13 21:54:23 +0100 | [diff] [blame] | 784 | * add the context to the runqueue so it gets woken up once an spu |
| 785 | * is available. |
| 786 | */ |
Christoph Hellwig | 26bec67 | 2007-02-13 21:54:24 +0100 | [diff] [blame] | 787 | int spu_activate(struct spu_context *ctx, unsigned long flags) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 788 | { |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 789 | struct spu *spu; |
Christoph Hellwig | 079cdb6 | 2007-02-13 21:54:23 +0100 | [diff] [blame] | 790 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 791 | /* |
| 792 | * If there are multiple threads waiting for a single context |
| 793 | * only one actually binds the context while the others will |
| 794 | * only be able to acquire the state_mutex once the context |
| 795 | * already is in runnable state. |
| 796 | */ |
| 797 | if (ctx->spu) |
| 798 | return 0; |
Christoph Hellwig | 2744997 | 2007-06-29 10:58:06 +1000 | [diff] [blame] | 799 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 800 | spu_activate_top: |
| 801 | if (signal_pending(current)) |
| 802 | return -ERESTARTSYS; |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 803 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 804 | spu = spu_get_idle(ctx); |
| 805 | /* |
| 806 | * If this is a realtime thread we try to get it running by |
| 807 | * preempting a lower priority thread. |
| 808 | */ |
| 809 | if (!spu && rt_prio(ctx->prio)) |
| 810 | spu = find_victim(ctx); |
| 811 | if (spu) { |
| 812 | unsigned long runcntl; |
Christoph Hellwig | 079cdb6 | 2007-02-13 21:54:23 +0100 | [diff] [blame] | 813 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 814 | runcntl = ctx->ops->runcntl_read(ctx); |
| 815 | __spu_schedule(spu, ctx); |
| 816 | if (runcntl & SPU_RUNCNTL_RUNNABLE) |
| 817 | spuctx_switch_state(ctx, SPU_UTIL_USER); |
| 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | if (ctx->flags & SPU_CREATE_NOSCHED) { |
Christoph Hellwig | 50b520d | 2007-03-10 00:05:36 +0100 | [diff] [blame] | 823 | spu_prio_wait(ctx); |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 824 | goto spu_activate_top; |
| 825 | } |
Christoph Hellwig | 079cdb6 | 2007-02-13 21:54:23 +0100 | [diff] [blame] | 826 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 827 | spu_add_to_rq(ctx); |
| 828 | |
| 829 | return 0; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 830 | } |
| 831 | |
Christoph Hellwig | 678b2ff | 2007-02-13 21:54:25 +0100 | [diff] [blame] | 832 | /** |
Christoph Hellwig | bb5db29 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 833 | * grab_runnable_context - try to find a runnable context |
| 834 | * |
| 835 | * Remove the highest priority context on the runqueue and return it |
| 836 | * to the caller. Returns %NULL if no runnable context was found. |
| 837 | */ |
Christoph Hellwig | ea1ae59 | 2007-06-29 10:57:56 +1000 | [diff] [blame] | 838 | static struct spu_context *grab_runnable_context(int prio, int node) |
Christoph Hellwig | bb5db29 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 839 | { |
Christoph Hellwig | ea1ae59 | 2007-06-29 10:57:56 +1000 | [diff] [blame] | 840 | struct spu_context *ctx; |
Christoph Hellwig | bb5db29 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 841 | int best; |
| 842 | |
| 843 | spin_lock(&spu_prio->runq_lock); |
Masato Noguchi | 7e90b74 | 2007-07-20 21:39:43 +0200 | [diff] [blame] | 844 | best = find_first_bit(spu_prio->bitmap, prio); |
Christoph Hellwig | ea1ae59 | 2007-06-29 10:57:56 +1000 | [diff] [blame] | 845 | while (best < prio) { |
Christoph Hellwig | bb5db29 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 846 | struct list_head *rq = &spu_prio->runq[best]; |
| 847 | |
Christoph Hellwig | ea1ae59 | 2007-06-29 10:57:56 +1000 | [diff] [blame] | 848 | list_for_each_entry(ctx, rq, rq) { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 849 | /* XXX(hch): check for affinity here as well */ |
Christoph Hellwig | ea1ae59 | 2007-06-29 10:57:56 +1000 | [diff] [blame] | 850 | if (__node_allowed(ctx, node)) { |
| 851 | __spu_del_from_rq(ctx); |
| 852 | goto found; |
| 853 | } |
| 854 | } |
| 855 | best++; |
Christoph Hellwig | bb5db29 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 856 | } |
Christoph Hellwig | ea1ae59 | 2007-06-29 10:57:56 +1000 | [diff] [blame] | 857 | ctx = NULL; |
| 858 | found: |
Christoph Hellwig | bb5db29 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 859 | spin_unlock(&spu_prio->runq_lock); |
Christoph Hellwig | bb5db29 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 860 | return ctx; |
| 861 | } |
| 862 | |
| 863 | static int __spu_deactivate(struct spu_context *ctx, int force, int max_prio) |
| 864 | { |
| 865 | struct spu *spu = ctx->spu; |
| 866 | struct spu_context *new = NULL; |
| 867 | |
| 868 | if (spu) { |
Christoph Hellwig | ea1ae59 | 2007-06-29 10:57:56 +1000 | [diff] [blame] | 869 | new = grab_runnable_context(max_prio, spu->node); |
Christoph Hellwig | bb5db29 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 870 | if (new || force) { |
Jeremy Kerr | b65fe03 | 2008-09-04 15:02:47 +1000 | [diff] [blame] | 871 | spu_unschedule(spu, ctx, new == NULL); |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 872 | if (new) { |
| 873 | if (new->flags & SPU_CREATE_NOSCHED) |
| 874 | wake_up(&new->stop_wq); |
| 875 | else { |
| 876 | spu_release(ctx); |
| 877 | spu_schedule(spu, new); |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 878 | /* this one can't easily be made |
| 879 | interruptible */ |
| 880 | mutex_lock(&ctx->state_mutex); |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 881 | } |
| 882 | } |
Christoph Hellwig | bb5db29 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 883 | } |
Christoph Hellwig | bb5db29 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | return new != NULL; |
| 887 | } |
| 888 | |
| 889 | /** |
Christoph Hellwig | 678b2ff | 2007-02-13 21:54:25 +0100 | [diff] [blame] | 890 | * spu_deactivate - unbind a context from it's physical spu |
| 891 | * @ctx: spu context to unbind |
| 892 | * |
| 893 | * Unbind @ctx from the physical spu it is running on and schedule |
| 894 | * the highest priority context to run on the freed physical spu. |
| 895 | */ |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 896 | void spu_deactivate(struct spu_context *ctx) |
| 897 | { |
Christoph Hellwig | 038200c | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 898 | spu_context_nospu_trace(spu_deactivate__enter, ctx); |
Christoph Hellwig | bb5db29 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 899 | __spu_deactivate(ctx, 1, MAX_PRIO); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 900 | } |
| 901 | |
Christoph Hellwig | ae7b4c5 | 2007-02-13 21:54:26 +0100 | [diff] [blame] | 902 | /** |
Bob Nelson | 1474855 | 2007-07-20 21:39:53 +0200 | [diff] [blame] | 903 | * spu_yield - yield a physical spu if others are waiting |
Christoph Hellwig | ae7b4c5 | 2007-02-13 21:54:26 +0100 | [diff] [blame] | 904 | * @ctx: spu context to yield |
| 905 | * |
| 906 | * Check if there is a higher priority context waiting and if yes |
| 907 | * unbind @ctx from the physical spu and schedule the highest |
| 908 | * priority context to run on the freed physical spu instead. |
| 909 | */ |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 910 | void spu_yield(struct spu_context *ctx) |
| 911 | { |
Christoph Hellwig | 038200c | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 912 | spu_context_nospu_trace(spu_yield__enter, ctx); |
Christoph Hellwig | e5c0b9e | 2007-06-05 11:25:59 +1000 | [diff] [blame] | 913 | if (!(ctx->flags & SPU_CREATE_NOSCHED)) { |
| 914 | mutex_lock(&ctx->state_mutex); |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 915 | __spu_deactivate(ctx, 0, MAX_PRIO); |
Christoph Hellwig | e5c0b9e | 2007-06-05 11:25:59 +1000 | [diff] [blame] | 916 | mutex_unlock(&ctx->state_mutex); |
| 917 | } |
Christoph Hellwig | bb5db29 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 918 | } |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 919 | |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 920 | static noinline void spusched_tick(struct spu_context *ctx) |
Christoph Hellwig | bb5db29 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 921 | { |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 922 | struct spu_context *new = NULL; |
| 923 | struct spu *spu = NULL; |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 924 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 925 | if (spu_acquire(ctx)) |
| 926 | BUG(); /* a kernel thread never has signals pending */ |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 927 | |
| 928 | if (ctx->state != SPU_STATE_RUNNABLE) |
| 929 | goto out; |
Christoph Hellwig | df09cf3 | 2007-06-29 10:57:58 +1000 | [diff] [blame] | 930 | if (ctx->flags & SPU_CREATE_NOSCHED) |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 931 | goto out; |
Christoph Hellwig | df09cf3 | 2007-06-29 10:57:58 +1000 | [diff] [blame] | 932 | if (ctx->policy == SCHED_FIFO) |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 933 | goto out; |
Christoph Hellwig | df09cf3 | 2007-06-29 10:57:58 +1000 | [diff] [blame] | 934 | |
Jeremy Kerr | ce7c191 | 2008-03-04 20:17:02 +1100 | [diff] [blame] | 935 | if (--ctx->time_slice && test_bit(SPU_SCHED_SPU_RUN, &ctx->sched_flags)) |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 936 | goto out; |
Christoph Hellwig | bb5db29 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 937 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 938 | spu = ctx->spu; |
Christoph Hellwig | 038200c | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 939 | |
| 940 | spu_context_trace(spusched_tick__preempt, ctx, spu); |
| 941 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 942 | new = grab_runnable_context(ctx->prio + 1, spu->node); |
| 943 | if (new) { |
Jeremy Kerr | b65fe03 | 2008-09-04 15:02:47 +1000 | [diff] [blame] | 944 | spu_unschedule(spu, ctx, 0); |
Jeremy Kerr | ce7c191 | 2008-03-04 20:17:02 +1100 | [diff] [blame] | 945 | if (test_bit(SPU_SCHED_SPU_RUN, &ctx->sched_flags)) |
Jeremy Kerr | 4ef1101 | 2008-02-19 10:05:35 +1100 | [diff] [blame] | 946 | spu_add_to_rq(ctx); |
Christoph Hellwig | bb5db29 | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 947 | } else { |
Christoph Hellwig | 038200c | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 948 | spu_context_nospu_trace(spusched_tick__newslice, ctx); |
Luke Browning | 2442a8b | 2008-06-06 11:26:54 +0800 | [diff] [blame] | 949 | if (!ctx->time_slice) |
| 950 | ctx->time_slice++; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 951 | } |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 952 | out: |
| 953 | spu_release(ctx); |
| 954 | |
| 955 | if (new) |
| 956 | spu_schedule(spu, new); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 957 | } |
| 958 | |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 959 | /** |
| 960 | * count_active_contexts - count nr of active tasks |
| 961 | * |
| 962 | * Return the number of tasks currently running or waiting to run. |
| 963 | * |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 964 | * Note that we don't take runq_lock / list_mutex here. Reading |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 965 | * a single 32bit value is atomic on powerpc, and we don't care |
| 966 | * about memory ordering issues here. |
| 967 | */ |
| 968 | static unsigned long count_active_contexts(void) |
| 969 | { |
| 970 | int nr_active = 0, node; |
| 971 | |
| 972 | for (node = 0; node < MAX_NUMNODES; node++) |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 973 | nr_active += cbe_spu_info[node].nr_active; |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 974 | nr_active += spu_prio->nr_waiting; |
| 975 | |
| 976 | return nr_active; |
| 977 | } |
| 978 | |
| 979 | /** |
Aegis Lin | 90608a2 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 980 | * spu_calc_load - update the avenrun load estimates. |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 981 | * |
| 982 | * No locking against reading these values from userspace, as for |
| 983 | * the CPU loadavg code. |
| 984 | */ |
Aegis Lin | 90608a2 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 985 | static void spu_calc_load(void) |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 986 | { |
| 987 | unsigned long active_tasks; /* fixed-point */ |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 988 | |
Aegis Lin | 90608a2 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 989 | active_tasks = count_active_contexts() * FIXED_1; |
Johannes Weiner | f1675aa | 2018-10-26 15:06:11 -0700 | [diff] [blame] | 990 | spu_avenrun[0] = calc_load(spu_avenrun[0], EXP_1, active_tasks); |
| 991 | spu_avenrun[1] = calc_load(spu_avenrun[1], EXP_5, active_tasks); |
| 992 | spu_avenrun[2] = calc_load(spu_avenrun[2], EXP_15, active_tasks); |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 993 | } |
| 994 | |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 995 | static void spusched_wake(unsigned long data) |
| 996 | { |
| 997 | mod_timer(&spusched_timer, jiffies + SPUSCHED_TICK); |
| 998 | wake_up_process(spusched_task); |
Aegis Lin | 90608a2 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | static void spuloadavg_wake(unsigned long data) |
| 1002 | { |
| 1003 | mod_timer(&spuloadavg_timer, jiffies + LOAD_FREQ); |
| 1004 | spu_calc_load(); |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | static int spusched_thread(void *unused) |
| 1008 | { |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 1009 | struct spu *spu; |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 1010 | int node; |
| 1011 | |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 1012 | while (!kthread_should_stop()) { |
| 1013 | set_current_state(TASK_INTERRUPTIBLE); |
| 1014 | schedule(); |
| 1015 | for (node = 0; node < MAX_NUMNODES; node++) { |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1016 | struct mutex *mtx = &cbe_spu_info[node].list_mutex; |
| 1017 | |
| 1018 | mutex_lock(mtx); |
| 1019 | list_for_each_entry(spu, &cbe_spu_info[node].spus, |
| 1020 | cbe_list) { |
| 1021 | struct spu_context *ctx = spu->ctx; |
| 1022 | |
| 1023 | if (ctx) { |
Jeremy Kerr | 8d5636f | 2008-08-14 14:59:12 +1000 | [diff] [blame] | 1024 | get_spu_context(ctx); |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1025 | mutex_unlock(mtx); |
| 1026 | spusched_tick(ctx); |
| 1027 | mutex_lock(mtx); |
Jeremy Kerr | 8d5636f | 2008-08-14 14:59:12 +1000 | [diff] [blame] | 1028 | put_spu_context(ctx); |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1029 | } |
| 1030 | } |
| 1031 | mutex_unlock(mtx); |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 1032 | } |
| 1033 | } |
| 1034 | |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 1035 | return 0; |
| 1036 | } |
| 1037 | |
Jeremy Kerr | 7cd58e4 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1038 | void spuctx_switch_state(struct spu_context *ctx, |
| 1039 | enum spu_utilization_state new_state) |
| 1040 | { |
| 1041 | unsigned long long curtime; |
| 1042 | signed long long delta; |
Jeremy Kerr | 7cd58e4 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1043 | struct spu *spu; |
| 1044 | enum spu_utilization_state old_state; |
Maxim Shchetynin | fabb657 | 2008-07-05 05:05:39 +1000 | [diff] [blame] | 1045 | int node; |
Jeremy Kerr | 7cd58e4 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1046 | |
Thomas Gleixner | f2dec1e | 2014-07-16 21:04:38 +0000 | [diff] [blame] | 1047 | curtime = ktime_get_ns(); |
Jeremy Kerr | 7cd58e4 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1048 | delta = curtime - ctx->stats.tstamp; |
| 1049 | |
| 1050 | WARN_ON(!mutex_is_locked(&ctx->state_mutex)); |
| 1051 | WARN_ON(delta < 0); |
| 1052 | |
| 1053 | spu = ctx->spu; |
| 1054 | old_state = ctx->stats.util_state; |
| 1055 | ctx->stats.util_state = new_state; |
| 1056 | ctx->stats.tstamp = curtime; |
| 1057 | |
| 1058 | /* |
| 1059 | * Update the physical SPU utilization statistics. |
| 1060 | */ |
| 1061 | if (spu) { |
| 1062 | ctx->stats.times[old_state] += delta; |
| 1063 | spu->stats.times[old_state] += delta; |
| 1064 | spu->stats.util_state = new_state; |
| 1065 | spu->stats.tstamp = curtime; |
Maxim Shchetynin | fabb657 | 2008-07-05 05:05:39 +1000 | [diff] [blame] | 1066 | node = spu->node; |
| 1067 | if (old_state == SPU_UTIL_USER) |
| 1068 | atomic_dec(&cbe_spu_info[node].busy_spus); |
Ilpo Järvinen | cb9808d | 2008-08-19 08:48:57 +0300 | [diff] [blame] | 1069 | if (new_state == SPU_UTIL_USER) |
Maxim Shchetynin | fabb657 | 2008-07-05 05:05:39 +1000 | [diff] [blame] | 1070 | atomic_inc(&cbe_spu_info[node].busy_spus); |
Jeremy Kerr | 7cd58e4 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1071 | } |
| 1072 | } |
| 1073 | |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 1074 | static int show_spu_loadavg(struct seq_file *s, void *private) |
| 1075 | { |
| 1076 | int a, b, c; |
| 1077 | |
| 1078 | a = spu_avenrun[0] + (FIXED_1/200); |
| 1079 | b = spu_avenrun[1] + (FIXED_1/200); |
| 1080 | c = spu_avenrun[2] + (FIXED_1/200); |
| 1081 | |
| 1082 | /* |
| 1083 | * Note that last_pid doesn't really make much sense for the |
Julio M. Merino Vidal | 9b1d21f | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1084 | * SPU loadavg (it even seems very odd on the CPU side...), |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 1085 | * but we include it here to have a 100% compatible interface. |
| 1086 | */ |
| 1087 | seq_printf(s, "%d.%02d %d.%02d %d.%02d %ld/%d %d\n", |
| 1088 | LOAD_INT(a), LOAD_FRAC(a), |
| 1089 | LOAD_INT(b), LOAD_FRAC(b), |
| 1090 | LOAD_INT(c), LOAD_FRAC(c), |
| 1091 | count_active_contexts(), |
| 1092 | atomic_read(&nr_spu_contexts), |
Eric W. Biederman | 17cf22c | 2010-03-02 14:51:53 -0800 | [diff] [blame] | 1093 | task_active_pid_ns(current)->last_pid); |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 1094 | return 0; |
| 1095 | } |
| 1096 | |
| 1097 | static int spu_loadavg_open(struct inode *inode, struct file *file) |
| 1098 | { |
| 1099 | return single_open(file, show_spu_loadavg, NULL); |
| 1100 | } |
| 1101 | |
| 1102 | static const struct file_operations spu_loadavg_fops = { |
| 1103 | .open = spu_loadavg_open, |
| 1104 | .read = seq_read, |
| 1105 | .llseek = seq_lseek, |
| 1106 | .release = single_release, |
| 1107 | }; |
| 1108 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1109 | int __init spu_sched_init(void) |
| 1110 | { |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 1111 | struct proc_dir_entry *entry; |
| 1112 | int err = -ENOMEM, i; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1113 | |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 1114 | spu_prio = kzalloc(sizeof(struct spu_prio_array), GFP_KERNEL); |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 1115 | if (!spu_prio) |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 1116 | goto out; |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 1117 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1118 | for (i = 0; i < MAX_PRIO; i++) { |
Christoph Hellwig | 079cdb6 | 2007-02-13 21:54:23 +0100 | [diff] [blame] | 1119 | INIT_LIST_HEAD(&spu_prio->runq[i]); |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 1120 | __clear_bit(i, spu_prio->bitmap); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1121 | } |
Christoph Hellwig | 079cdb6 | 2007-02-13 21:54:23 +0100 | [diff] [blame] | 1122 | spin_lock_init(&spu_prio->runq_lock); |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 1123 | |
Christoph Hellwig | c77239b | 2007-06-29 10:58:05 +1000 | [diff] [blame] | 1124 | setup_timer(&spusched_timer, spusched_wake, 0); |
Aegis Lin | 90608a2 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1125 | setup_timer(&spuloadavg_timer, spuloadavg_wake, 0); |
Christoph Hellwig | c77239b | 2007-06-29 10:58:05 +1000 | [diff] [blame] | 1126 | |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 1127 | spusched_task = kthread_run(spusched_thread, NULL, "spusched"); |
| 1128 | if (IS_ERR(spusched_task)) { |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 1129 | err = PTR_ERR(spusched_task); |
| 1130 | goto out_free_spu_prio; |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 1131 | } |
Jeremy Kerr | f3f59be | 2007-06-29 10:57:54 +1000 | [diff] [blame] | 1132 | |
Aegis Lin | 90608a2 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1133 | mod_timer(&spuloadavg_timer, 0); |
| 1134 | |
Denis V. Lunev | 6674713 | 2008-04-29 01:02:26 -0700 | [diff] [blame] | 1135 | entry = proc_create("spu_loadavg", 0, NULL, &spu_loadavg_fops); |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 1136 | if (!entry) |
| 1137 | goto out_stop_kthread; |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 1138 | |
Jeremy Kerr | f3f59be | 2007-06-29 10:57:54 +1000 | [diff] [blame] | 1139 | pr_debug("spusched: tick: %d, min ticks: %d, default ticks: %d\n", |
| 1140 | SPUSCHED_TICK, MIN_SPU_TIMESLICE, DEF_SPU_TIMESLICE); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1141 | return 0; |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 1142 | |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 1143 | out_stop_kthread: |
| 1144 | kthread_stop(spusched_task); |
| 1145 | out_free_spu_prio: |
| 1146 | kfree(spu_prio); |
| 1147 | out: |
| 1148 | return err; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1149 | } |
| 1150 | |
Sebastian Siewior | d145031 | 2007-07-20 21:39:29 +0200 | [diff] [blame] | 1151 | void spu_sched_exit(void) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1152 | { |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 1153 | struct spu *spu; |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 1154 | int node; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1155 | |
Christoph Hellwig | 65de66f | 2007-06-29 10:58:02 +1000 | [diff] [blame] | 1156 | remove_proc_entry("spu_loadavg", NULL); |
| 1157 | |
Christoph Hellwig | c77239b | 2007-06-29 10:58:05 +1000 | [diff] [blame] | 1158 | del_timer_sync(&spusched_timer); |
Aegis Lin | 90608a2 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1159 | del_timer_sync(&spuloadavg_timer); |
Christoph Hellwig | 3790180 | 2007-06-29 10:57:51 +1000 | [diff] [blame] | 1160 | kthread_stop(spusched_task); |
| 1161 | |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 1162 | for (node = 0; node < MAX_NUMNODES; node++) { |
Christoph Hellwig | 486acd4 | 2007-07-20 21:39:54 +0200 | [diff] [blame] | 1163 | mutex_lock(&cbe_spu_info[node].list_mutex); |
| 1164 | list_for_each_entry(spu, &cbe_spu_info[node].spus, cbe_list) |
| 1165 | if (spu->alloc_state != SPU_FREE) |
| 1166 | spu->alloc_state = SPU_FREE; |
| 1167 | mutex_unlock(&cbe_spu_info[node].list_mutex); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1168 | } |
Mark Nutter | a68cf98 | 2006-10-04 17:26:12 +0200 | [diff] [blame] | 1169 | kfree(spu_prio); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1170 | } |