spufs: Add a register file for the debugger
PATCH 7/7 spufs: Add a register file for the debugger
In order to debug spu threads, we need access to the registers of the running SPU. Unfortunately, this is only possible when the SPU context is saved to memory.
This patch adds operations that enable accessing an SPU in either runnable or saved state. We use an RW semaphore to protect the state of the SPU from changing underneath us, while we are holding it readable. In order to change the state, it is acquired writeable and a context save or restore is executed before downgrading the semaphore to read-only.
Future schedulers will likely be built on top of this.
From: Ulrich Weigand <[email protected]>
Signed-off-by Arnd Bergmann <[email protected]>
--
context.c | 48 ++++++++++++ file.c | 239 ++++++++++++++++++++++++++++++++++++++++++++++++------------ spufs.h | 3 4 files changed, 243 insertions(+), 47 deletions(-)
fs/spufs/context.c +48 -0
@@ -53,6 +53,8 @@ struct spu_context *alloc_spu_context(voinit_rwsem (&ctx->backing_sema);spin_lock_init (&ctx->mmio_lock);kref_init (&ctx->kref); +init_rwsem (&ctx->state_sema); + ctx->state =SPU_STATE_SAVED ; goto out; out_free:kfree (ctx);
@@ -82,4 +84,50 @@ void put_spu_context(struct spu_contextkref_put (&ctx->kref, &destroy_spu_context); } +void spu_acquire (struct spu_context *ctx) +{ +down_read (&ctx->state_sema); +} + +void spu_release (struct spu_context *ctx) +{ +up_read (&ctx->state_sema); +} + +void spu_acquire_runnable (struct spu_context *ctx) +{ +down_read (&ctx->state_sema); + +if (ctx->state ==SPU_STATE_RUNNABLE + || ctx->state ==SPU_STATE_LOCKED ) +return ; + +up_read (&ctx->state_sema); +down_write (&ctx->state_sema); +if (ctx->state ==SPU_STATE_SAVED ) { +spu_restore (&ctx->csa, ctx->spu); + ctx->state =SPU_STATE_RUNNABLE ; + } + +downgrade_write (&ctx->state_sema); +} + +void spu_acquire_saved (struct spu_context *ctx) +{ +down_read (&ctx->state_sema); + +if (ctx->state ==SPU_STATE_SAVED + || ctx->state ==SPU_STATE_LOCKED ) +return ; + +up_read (&ctx->state_sema); +down_write (&ctx->state_sema); + +if (ctx->state ==SPU_STATE_RUNNABLE ) { +spu_save (&ctx->csa, ctx->spu); + ctx->state =SPU_STATE_SAVED ; + } + +downgrade_write (&ctx->state_sema); +}
fs/spufs/file.c +192 -47
535 lines not on this page · raw message
fs/spufs/spufs.h +3 -0
@@ -41,6 +41,9 @@ struct spu_context {struct rw_semaphore backing_sema;/* protects the above */ spinlock_t mmio_lock;/* protects mmio access */ +enum {SPU_STATE_RUNNABLE ,SPU_STATE_SAVED ,SPU_STATE_LOCKED } state; +struct rw_semaphore state_sema; +struct kref kref; };