]> err.no Git - linux-2.6/blobdiff - arch/powerpc/platforms/cell/spufs/sched.c
[POWERPC] Fix build failure on Cell when CONFIG_SPU_FS=y
[linux-2.6] / arch / powerpc / platforms / cell / spufs / sched.c
index 227968b4779d3adc531fac2a71ef68dd1f18c386..9ad53e637aee4c111b747acae0f58d1fa89131fe 100644 (file)
@@ -166,15 +166,7 @@ static int node_allowed(struct spu_context *ctx, int node)
        return rval;
 }
 
-static BLOCKING_NOTIFIER_HEAD(spu_switch_notifier);
-
-void spu_switch_notify(struct spu *spu, struct spu_context *ctx)
-{
-       blocking_notifier_call_chain(&spu_switch_notifier,
-                           ctx ? ctx->object_id : 0, spu);
-}
-
-static void notify_spus_active(void)
+void do_notify_spus_active(void)
 {
        int node;
 
@@ -201,22 +193,6 @@ static void notify_spus_active(void)
        }
 }
 
-int spu_switch_event_register(struct notifier_block * n)
-{
-       int ret;
-       ret = blocking_notifier_chain_register(&spu_switch_notifier, n);
-       if (!ret)
-               notify_spus_active();
-       return ret;
-}
-EXPORT_SYMBOL_GPL(spu_switch_event_register);
-
-int spu_switch_event_unregister(struct notifier_block * n)
-{
-       return blocking_notifier_chain_unregister(&spu_switch_notifier, n);
-}
-EXPORT_SYMBOL_GPL(spu_switch_event_unregister);
-
 /**
  * spu_bind_context - bind spu context to physical spu
  * @spu:       physical spu to bind to
@@ -230,8 +206,6 @@ static void spu_bind_context(struct spu *spu, struct spu_context *ctx)
 
        if (ctx->flags & SPU_CREATE_NOSCHED)
                atomic_inc(&cbe_spu_info[spu->node].reserved_spus);
-       if (!list_empty(&ctx->aff_list))
-               atomic_inc(&ctx->gang->aff_sched_count);
 
        ctx->stats.slb_flt_base = spu->stats.slb_flt;
        ctx->stats.class2_intr_base = spu->stats.class2_intr;
@@ -351,7 +325,8 @@ static void aff_set_ref_point_location(struct spu_gang *gang)
                lowest_offset = ctx->aff_offset;
        }
 
-       gang->aff_ref_spu = aff_ref_location(ctx, mem_aff, gs, lowest_offset);
+       gang->aff_ref_spu = aff_ref_location(gang->aff_ref_ctx, mem_aff, gs,
+                                                       lowest_offset);
 }
 
 static struct spu *ctx_location(struct spu *ref, int offset, int node)
@@ -391,7 +366,6 @@ static int has_affinity(struct spu_context *ctx)
        if (list_empty(&ctx->aff_list))
                return 0;
 
-       mutex_lock(&gang->aff_mutex);
        if (!gang->aff_ref_spu) {
                if (!(gang->aff_flags & AFF_MERGED))
                        aff_merge_remaining_ctxs(gang);
@@ -399,7 +373,6 @@ static int has_affinity(struct spu_context *ctx)
                        aff_set_offsets(gang);
                aff_set_ref_point_location(gang);
        }
-       mutex_unlock(&gang->aff_mutex);
 
        return gang->aff_ref_spu != NULL;
 }
@@ -417,9 +390,16 @@ static void spu_unbind_context(struct spu *spu, struct spu_context *ctx)
 
        if (spu->ctx->flags & SPU_CREATE_NOSCHED)
                atomic_dec(&cbe_spu_info[spu->node].reserved_spus);
-       if (!list_empty(&ctx->aff_list))
-               if (atomic_dec_and_test(&ctx->gang->aff_sched_count))
-                       ctx->gang->aff_ref_spu = NULL;
+
+       if (ctx->gang){
+               mutex_lock(&ctx->gang->aff_mutex);
+               if (has_affinity(ctx)) {
+                       if (atomic_dec_and_test(&ctx->gang->aff_sched_count))
+                               ctx->gang->aff_ref_spu = NULL;
+               }
+               mutex_unlock(&ctx->gang->aff_mutex);
+       }
+
        spu_switch_notify(spu, NULL);
        spu_unmap_mappings(ctx);
        spu_save(&ctx->csa, spu);
@@ -510,20 +490,32 @@ static void spu_prio_wait(struct spu_context *ctx)
 
 static struct spu *spu_get_idle(struct spu_context *ctx)
 {
-       struct spu *spu;
+       struct spu *spu, *aff_ref_spu;
        int node, n;
 
-       if (has_affinity(ctx)) {
-               node = ctx->gang->aff_ref_spu->node;
+       if (ctx->gang) {
+               mutex_lock(&ctx->gang->aff_mutex);
+               if (has_affinity(ctx)) {
+                       aff_ref_spu = ctx->gang->aff_ref_spu;
+                       atomic_inc(&ctx->gang->aff_sched_count);
+                       mutex_unlock(&ctx->gang->aff_mutex);
+                       node = aff_ref_spu->node;
 
-               mutex_lock(&cbe_spu_info[node].list_mutex);
-               spu = ctx_location(ctx->gang->aff_ref_spu, ctx->aff_offset, node);
-               if (spu && spu->alloc_state == SPU_FREE)
-                       goto found;
-               mutex_unlock(&cbe_spu_info[node].list_mutex);
-               return NULL;
-       }
+                       mutex_lock(&cbe_spu_info[node].list_mutex);
+                       spu = ctx_location(aff_ref_spu, ctx->aff_offset, node);
+                       if (spu && spu->alloc_state == SPU_FREE)
+                               goto found;
+                       mutex_unlock(&cbe_spu_info[node].list_mutex);
 
+                       mutex_lock(&ctx->gang->aff_mutex);
+                       if (atomic_dec_and_test(&ctx->gang->aff_sched_count))
+                               ctx->gang->aff_ref_spu = NULL;
+                       mutex_unlock(&ctx->gang->aff_mutex);
+
+                       return NULL;
+               }
+               mutex_unlock(&ctx->gang->aff_mutex);
+       }
        node = cpu_to_node(raw_smp_processor_id());
        for (n = 0; n < MAX_NUMNODES; n++, node++) {
                node = (node < MAX_NUMNODES) ? node : 0;
@@ -578,7 +570,7 @@ static struct spu *find_victim(struct spu_context *ctx)
                list_for_each_entry(spu, &cbe_spu_info[node].spus, cbe_list) {
                        struct spu_context *tmp = spu->ctx;
 
-                       if (tmp->prio > ctx->prio &&
+                       if (tmp && tmp->prio > ctx->prio &&
                            (!victim || tmp->prio > victim->prio))
                                victim = spu->ctx;
                }
@@ -610,9 +602,9 @@ static struct spu *find_victim(struct spu_context *ctx)
 
                        mutex_lock(&cbe_spu_info[node].list_mutex);
                        cbe_spu_info[node].nr_active--;
+                       spu_unbind_context(spu, victim);
                        mutex_unlock(&cbe_spu_info[node].list_mutex);
 
-                       spu_unbind_context(spu, victim);
                        victim->stats.invol_ctx_switch++;
                        spu->stats.invol_ctx_switch++;
                        mutex_unlock(&victim->state_mutex);
@@ -927,10 +919,6 @@ int __init spu_sched_init(void)
                INIT_LIST_HEAD(&spu_prio->runq[i]);
                __clear_bit(i, spu_prio->bitmap);
        }
-       for (i = 0; i < MAX_NUMNODES; i++) {
-               mutex_init(&cbe_spu_info[i].list_mutex);
-               INIT_LIST_HEAD(&cbe_spu_info[i].spus);
-       }
        spin_lock_init(&spu_prio->runq_lock);
 
        setup_timer(&spusched_timer, spusched_wake, 0);