[POWERPC] spufs: Add stat file to spufs
[sfrench/cifs-2.6.git] / arch / powerpc / platforms / cell / spufs / run.c
index 57626600b1a4b5c7cb3d46d17ef214e5b5807d1d..c69f63dd5f0a1d25dd1a12d964041dad790e42d9 100644 (file)
@@ -29,7 +29,8 @@ static inline int spu_stopped(struct spu_context *ctx, u32 * stat)
        spu = ctx->spu;
        pte_fault = spu->dsisr &
            (MFC_DSISR_PTE_NOT_FOUND | MFC_DSISR_ACCESS_DENIED);
-       return (!(*stat & 0x1) || pte_fault || spu->class_0_pending) ? 1 : 0;
+       return (!(*stat & SPU_STATUS_RUNNING) || pte_fault || spu->class_0_pending) ?
+               1 : 0;
 }
 
 static int spu_setup_isolated(struct spu_context *ctx)
@@ -142,8 +143,11 @@ static int spu_run_init(struct spu_context *ctx, u32 * npc)
                        runcntl = SPU_RUNCNTL_RUNNABLE;
                ctx->ops->runcntl_write(ctx, runcntl);
        } else {
-               spu_start_tick(ctx);
+               unsigned long mode = SPU_PRIVCNTL_MODE_NORMAL;
                ctx->ops->npc_write(ctx, *npc);
+               if (test_thread_flag(TIF_SINGLESTEP))
+                       mode = SPU_PRIVCNTL_MODE_SINGLE_STEP;
+               out_be64(&ctx->spu->priv2->spu_privcntl_RW, mode);
                ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_RUNNABLE);
        }
 
@@ -155,7 +159,6 @@ static int spu_run_fini(struct spu_context *ctx, u32 * npc,
 {
        int ret = 0;
 
-       spu_stop_tick(ctx);
        *status = ctx->ops->status_read(ctx);
        *npc = ctx->ops->npc_read(ctx);
        spu_release(ctx);
@@ -298,9 +301,22 @@ long spufs_run_spu(struct file *file, struct spu_context *ctx,
        ctx->ops->master_start(ctx);
        ctx->event_return = 0;
 
-       ret = spu_acquire_runnable(ctx, 0);
-       if (ret)
-               return ret;
+       spu_acquire(ctx);
+       if (ctx->state == SPU_STATE_SAVED) {
+               __spu_update_sched_info(ctx);
+
+               ret = spu_activate(ctx, 0);
+               if (ret) {
+                       spu_release(ctx);
+                       goto out;
+               }
+       } else {
+               /*
+                * We have to update the scheduling priority under active_mutex
+                * to protect against find_victim().
+                */
+               spu_update_sched_info(ctx);
+       }
 
        ret = spu_run_init(ctx, npc);
        if (ret) {
@@ -325,16 +341,19 @@ long spufs_run_spu(struct file *file, struct spu_context *ctx,
 
                if (unlikely(ctx->state != SPU_STATE_RUNNABLE)) {
                        ret = spu_reacquire_runnable(ctx, npc, &status);
-                       if (ret) {
-                               spu_stop_tick(ctx);
+                       if (ret)
                                goto out2;
-                       }
                        continue;
                }
                ret = spu_process_events(ctx);
 
        } while (!ret && !(status & (SPU_STATUS_STOPPED_BY_STOP |
-                                     SPU_STATUS_STOPPED_BY_HALT)));
+                                     SPU_STATUS_STOPPED_BY_HALT |
+                                      SPU_STATUS_SINGLE_STEP)));
+
+       if ((status & SPU_STATUS_STOPPED_BY_STOP) &&
+           ((status >> SPU_STOP_STATUS_SHIFT) & 0x2100))
+               ctx->stats.libassist++;
 
        ctx->ops->master_stop(ctx);
        ret = spu_run_fini(ctx, npc, &status);
@@ -344,10 +363,15 @@ out2:
        if ((ret == 0) ||
            ((ret == -ERESTARTSYS) &&
             ((status & SPU_STATUS_STOPPED_BY_HALT) ||
+             (status & SPU_STATUS_SINGLE_STEP) ||
              ((status & SPU_STATUS_STOPPED_BY_STOP) &&
               (status >> SPU_STOP_STATUS_SHIFT != 0x2104)))))
                ret = status;
 
+       /* Note: we don't need to force_sig SIGTRAP on single-step
+        * since we have TIF_SINGLESTEP set, thus the kernel will do
+        * it upon return from the syscall anyawy
+        */
        if ((status & SPU_STATUS_STOPPED_BY_STOP)
            && (status >> SPU_STOP_STATUS_SHIFT) == 0x3fff) {
                force_sig(SIGTRAP, current);