]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/powerpc/platforms/cell/spufs/context.c
[POWERPC] spusched: Update scheduling paramters on every spu_run
[linux-2.6-omap-h63xx.git] / arch / powerpc / platforms / cell / spufs / context.c
index 88a8871863039a42f64c7f00abe1dc89b511e1ee..c778d9178e0f1fce1c7af60f9257d5034c31266a 100644 (file)
@@ -36,14 +36,13 @@ struct spu_context *alloc_spu_context(struct spu_gang *gang)
        /* Binding to physical processor deferred
         * until spu_activate().
         */
-       spu_init_csa(&ctx->csa);
-       if (!ctx->csa.lscsa) {
+       if (spu_init_csa(&ctx->csa))
                goto out_free;
-       }
        spin_lock_init(&ctx->mmio_lock);
+       mutex_init(&ctx->mapping_lock);
        kref_init(&ctx->kref);
        mutex_init(&ctx->state_mutex);
-       init_MUTEX(&ctx->run_sema);
+       mutex_init(&ctx->run_mutex);
        init_waitqueue_head(&ctx->ibox_wq);
        init_waitqueue_head(&ctx->wbox_wq);
        init_waitqueue_head(&ctx->stop_wq);
@@ -51,9 +50,11 @@ struct spu_context *alloc_spu_context(struct spu_gang *gang)
        ctx->state = SPU_STATE_SAVED;
        ctx->ops = &spu_backing_ops;
        ctx->owner = get_task_mm(current);
+       INIT_LIST_HEAD(&ctx->rq);
        if (gang)
                spu_gang_add_ctx(gang, ctx);
-       ctx->prio = current->prio;
+
+       spu_set_timeslice(ctx);
        goto out;
 out_free:
        kfree(ctx);
@@ -72,6 +73,7 @@ void destroy_spu_context(struct kref *kref)
        spu_fini_csa(&ctx->csa);
        if (ctx->gang)
                spu_gang_remove_ctx(ctx->gang, ctx);
+       BUG_ON(!list_empty(&ctx->rq));
        kfree(ctx);
 }
 
@@ -99,6 +101,7 @@ void spu_forget(struct spu_context *ctx)
 
 void spu_unmap_mappings(struct spu_context *ctx)
 {
+       mutex_lock(&ctx->mapping_lock);
        if (ctx->local_store)
                unmap_mapping_range(ctx->local_store, 0, LS_SIZE, 1);
        if (ctx->mfc)
@@ -113,46 +116,7 @@ void spu_unmap_mappings(struct spu_context *ctx)
                unmap_mapping_range(ctx->mss, 0, 0x1000, 1);
        if (ctx->psmap)
                unmap_mapping_range(ctx->psmap, 0, 0x20000, 1);
-}
-
-/**
- * spu_acquire_exclusive - lock spu contex and protect against userspace access
- * @ctx:       spu contex to lock
- *
- * Note:
- *     Returns 0 and with the context locked on success
- *     Returns negative error and with the context _unlocked_ on failure.
- */
-int spu_acquire_exclusive(struct spu_context *ctx)
-{
-       int ret = -EINVAL;
-
-       spu_acquire(ctx);
-       /*
-        * Context is about to be freed, so we can't acquire it anymore.
-        */
-       if (!ctx->owner)
-               goto out_unlock;
-
-       if (ctx->state == SPU_STATE_SAVED) {
-               ret = spu_activate(ctx, 0);
-               if (ret)
-                       goto out_unlock;
-       } else {
-               /*
-                * We need to exclude userspace access to the context.
-                *
-                * To protect against memory access we invalidate all ptes
-                * and make sure the pagefault handlers block on the mutex.
-                */
-               spu_unmap_mappings(ctx);
-       }
-
-       return 0;
-
- out_unlock:
-       spu_release(ctx);
-       return ret;
+       mutex_unlock(&ctx->mapping_lock);
 }
 
 /**
@@ -163,7 +127,7 @@ int spu_acquire_exclusive(struct spu_context *ctx)
  *     Returns 0 and with the context locked on success
  *     Returns negative error and with the context _unlocked_ on failure.
  */
-int spu_acquire_runnable(struct spu_context *ctx)
+int spu_acquire_runnable(struct spu_context *ctx, unsigned long flags)
 {
        int ret = -EINVAL;
 
@@ -174,7 +138,7 @@ int spu_acquire_runnable(struct spu_context *ctx)
                 */
                if (!ctx->owner)
                        goto out_unlock;
-               ret = spu_activate(ctx, 0);
+               ret = spu_activate(ctx, flags);
                if (ret)
                        goto out_unlock;
        }