[Cbe-oss-dev] [PATCH] spufs: kill spu_acquire/spu_release
Christoph Hellwig
hch at lst.de
Tue Dec 4 01:56:59 EST 2007
Kill spu_acquire/spu_release and use the plain mutex calls for these
as suggested by Arnd.
Signed-off-by: Christoph Hellwig <hch at lst.de>
Index: linux-2.6/arch/powerpc/platforms/cell/spufs/sched.c
===================================================================
--- linux-2.6.orig/arch/powerpc/platforms/cell/spufs/sched.c 2007-12-03 12:20:50.000000000 +0100
+++ linux-2.6/arch/powerpc/platforms/cell/spufs/sched.c 2007-12-03 13:03:13.000000000 +0100
@@ -717,7 +717,7 @@ static void spu_schedule(struct spu *spu
from the scheduler thread or from spu_deactivate */
mutex_lock(&ctx->state_mutex);
__spu_schedule(spu, ctx);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
}
static void spu_unschedule(struct spu *spu, struct spu_context *ctx)
@@ -831,7 +831,7 @@ static int __spu_deactivate(struct spu_c
if (new->flags & SPU_CREATE_NOSCHED)
wake_up(&new->stop_wq);
else {
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
spu_schedule(spu, new);
/* this one can't easily be made
interruptible */
@@ -881,9 +881,7 @@ static noinline void spusched_tick(struc
struct spu *spu = NULL;
u32 status;
- if (spu_acquire(ctx))
- BUG(); /* a kernel thread never has signals pending */
-
+ mutex_lock(&ctx->state_mutex);
if (ctx->state != SPU_STATE_RUNNABLE)
goto out;
if (spu_stopped(ctx, &status))
@@ -909,7 +907,7 @@ static noinline void spusched_tick(struc
ctx->time_slice++;
}
out:
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
if (new)
spu_schedule(spu, new);
Index: linux-2.6/arch/powerpc/platforms/cell/spufs/context.c
===================================================================
--- linux-2.6.orig/arch/powerpc/platforms/cell/spufs/context.c 2007-12-03 13:03:44.000000000 +0100
+++ linux-2.6/arch/powerpc/platforms/cell/spufs/context.c 2007-12-03 13:03:54.000000000 +0100
@@ -120,7 +120,7 @@ void spu_forget(struct spu_context *ctx)
mm = ctx->owner;
ctx->owner = NULL;
mmput(mm);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
}
void spu_unmap_mappings(struct spu_context *ctx)
@@ -151,7 +151,7 @@ int spu_acquire_saved(struct spu_context
{
int ret;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
@@ -174,7 +174,7 @@ void spu_release_saved(struct spu_contex
if (test_and_clear_bit(SPU_SCHED_WAS_ACTIVE, &ctx->sched_flags))
spu_activate(ctx, 0);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
}
void spu_set_profile_private_kref(struct spu_context *ctx,
Index: linux-2.6/arch/powerpc/platforms/cell/spufs/fault.c
===================================================================
--- linux-2.6.orig/arch/powerpc/platforms/cell/spufs/fault.c 2007-12-03 13:03:29.000000000 +0100
+++ linux-2.6/arch/powerpc/platforms/cell/spufs/fault.c 2007-12-03 13:04:38.000000000 +0100
@@ -134,7 +134,7 @@ int spufs_handle_class1(struct spu_conte
ctx->spu->stats.hash_flt++;
/* we must not hold the lock when entering spu_handle_mm_fault */
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
access = (_PAGE_PRESENT | _PAGE_USER);
access |= (dsisr & MFC_DSISR_ACCESS_PUT) ? _PAGE_RW : 0UL;
@@ -147,11 +147,11 @@ int spufs_handle_class1(struct spu_conte
ret = spu_handle_mm_fault(current->mm, ea, dsisr, &flt);
/*
- * If spu_acquire fails due to a pending signal we just want to return
- * EINTR to userspace even if that means missing the dma restart or
- * updating the page fault statistics.
+ * If we can't acquire the state_mutex due to a pending signal we
+ * just want to return EINTR to userspace even if that means
+ * missing the dma restart or updating the page fault statistics.
*/
- ret2 = spu_acquire(ctx);
+ ret2 = mutex_lock_interruptible(&ctx->state_mutex);
if (ret2)
goto out;
Index: linux-2.6/arch/powerpc/platforms/cell/spufs/file.c
===================================================================
--- linux-2.6.orig/arch/powerpc/platforms/cell/spufs/file.c 2007-12-03 12:22:16.000000000 +0100
+++ linux-2.6/arch/powerpc/platforms/cell/spufs/file.c 2007-12-03 13:01:53.000000000 +0100
@@ -199,11 +199,11 @@ spufs_mem_read(struct file *file, char _
struct spu_context *ctx = file->private_data;
ssize_t ret;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
ret = __spufs_mem_read(ctx, buffer, size, pos);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return ret;
}
@@ -224,13 +224,13 @@ spufs_mem_write(struct file *file, const
if (size > LS_SIZE - pos)
size = LS_SIZE - pos;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
local_store = ctx->ops->get_ls(ctx);
ret = copy_from_user(local_store + pos, buffer, size);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
if (ret)
return -EFAULT;
@@ -267,7 +267,7 @@ static unsigned long spufs_mem_mmap_nopf
pr_debug("spufs_mem_mmap_nopfn address=0x%lx -> 0x%lx, offset=0x%lx\n",
addr0, address, offset);
- if (spu_acquire(ctx))
+ if (mutex_lock_interruptible(&ctx->state_mutex))
return NOPFN_REFAULT;
if (ctx->state == SPU_STATE_SAVED) {
@@ -281,7 +281,7 @@ static unsigned long spufs_mem_mmap_nopf
}
vm_insert_pfn(vma, address, pfn);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return NOPFN_REFAULT;
}
@@ -373,7 +373,7 @@ static unsigned long spufs_ps_nopfn(stru
* to return NOPFN_REFAULT because the mappings may have
* hanged.
*/
- if (spu_acquire(ctx))
+ if (mutex_lock_interruptible(&ctx->state_mutex))
return NOPFN_REFAULT;
if (ctx->state == SPU_STATE_SAVED) {
@@ -388,7 +388,7 @@ static unsigned long spufs_ps_nopfn(stru
spu_context_trace(spufs_ps_nopfn__insert, ctx, ctx->spu);
}
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return NOPFN_REFAULT;
}
@@ -427,11 +427,11 @@ static int spufs_cntl_get(void *data, u6
struct spu_context *ctx = data;
int ret;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
*val = ctx->ops->status_read(ctx);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return 0;
}
@@ -441,11 +441,11 @@ static int spufs_cntl_set(void *data, u6
struct spu_context *ctx = data;
int ret;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
ctx->ops->runcntl_write(ctx, val);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return 0;
}
@@ -637,7 +637,7 @@ static ssize_t spufs_mbox_read(struct fi
udata = (void __user *)buf;
- count = spu_acquire(ctx);
+ count = mutex_lock_interruptible(&ctx->state_mutex);
if (count)
return count;
@@ -659,7 +659,7 @@ static ssize_t spufs_mbox_read(struct fi
break;
}
}
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
if (!count)
count = -EAGAIN;
@@ -682,13 +682,13 @@ static ssize_t spufs_mbox_stat_read(stru
if (len < 4)
return -EINVAL;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
return -EFAULT;
@@ -753,7 +753,7 @@ static ssize_t spufs_ibox_read(struct fi
udata = (void __user *)buf;
- count = spu_acquire(ctx);
+ count = mutex_lock_interruptible(&ctx->state_mutex);
if (count)
return count;
@@ -789,7 +789,7 @@ static ssize_t spufs_ibox_read(struct fi
}
out:
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return count;
}
@@ -807,7 +807,7 @@ static unsigned int spufs_ibox_poll(stru
*/
mutex_lock(&ctx->state_mutex);
mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return mask;
}
@@ -829,11 +829,11 @@ static ssize_t spufs_ibox_stat_read(stru
if (len < 4)
return -EINVAL;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
return -EFAULT;
@@ -903,7 +903,7 @@ static ssize_t spufs_wbox_write(struct f
if (__get_user(wbox_data, udata))
return -EFAULT;
- count = spu_acquire(ctx);
+ count = mutex_lock_interruptible(&ctx->state_mutex);
if (count)
return count;
@@ -935,7 +935,7 @@ static ssize_t spufs_wbox_write(struct f
}
out:
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return count;
}
@@ -952,7 +952,7 @@ static unsigned int spufs_wbox_poll(stru
*/
mutex_lock(&ctx->state_mutex);
mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return mask;
}
@@ -974,11 +974,11 @@ static ssize_t spufs_wbox_stat_read(stru
if (len < 4)
return -EINVAL;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
return -EFAULT;
@@ -1071,11 +1071,11 @@ static ssize_t spufs_signal1_write(struc
if (copy_from_user(&data, buf, 4))
return -EFAULT;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
ctx->ops->signal1_write(ctx, data);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return 4;
}
@@ -1207,11 +1207,11 @@ static ssize_t spufs_signal2_write(struc
if (copy_from_user(&data, buf, 4))
return -EFAULT;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
ctx->ops->signal2_write(ctx, data);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return 4;
}
@@ -1283,11 +1283,11 @@ static int __##__get(void *data, u64 *va
int ret = 0; \
\
if (__acquire == SPU_ATTR_ACQUIRE) { \
- ret = spu_acquire(ctx); \
+ ret = mutex_lock_interruptible(&ctx->state_mutex); \
if (ret) \
return ret; \
*val = __get(ctx); \
- spu_release(ctx); \
+ mutex_unlock(&ctx->state_mutex); \
} else if (__acquire == SPU_ATTR_ACQUIRE_SAVED) { \
ret = spu_acquire_saved(ctx); \
if (ret) \
@@ -1306,11 +1306,11 @@ static int spufs_signal1_type_set(void *
struct spu_context *ctx = data;
int ret;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
ctx->ops->signal1_type_set(ctx, val);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return 0;
}
@@ -1328,11 +1328,11 @@ static int spufs_signal2_type_set(void *
struct spu_context *ctx = data;
int ret;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
ctx->ops->signal2_type_set(ctx, val);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return 0;
}
@@ -1583,7 +1583,7 @@ static ssize_t spufs_mfc_read(struct fil
if (size != 4)
goto out;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
@@ -1599,7 +1599,7 @@ static ssize_t spufs_mfc_read(struct fil
ret = spufs_wait(ctx->mfc_wq,
spufs_read_mfc_tagstatus(ctx, &status));
}
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
if (ret)
goto out;
@@ -1718,7 +1718,7 @@ static ssize_t spufs_mfc_write(struct fi
if (ret)
goto out;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
goto out;
@@ -1743,7 +1743,7 @@ static ssize_t spufs_mfc_write(struct fi
ret = size;
out_unlock:
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
out:
return ret;
}
@@ -1764,7 +1764,7 @@ static unsigned int spufs_mfc_poll(struc
ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
free_elements = ctx->ops->get_mfc_free_elements(ctx);
tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
mask = 0;
if (free_elements & 0xffff)
@@ -1783,7 +1783,7 @@ static int spufs_mfc_flush(struct file *
struct spu_context *ctx = file->private_data;
int ret;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
#if 0
@@ -1798,7 +1798,7 @@ out:
#else
ret = 0;
#endif
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return ret;
}
@@ -1833,11 +1833,11 @@ static int spufs_npc_set(void *data, u64
struct spu_context *ctx = data;
int ret;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
ctx->ops->npc_write(ctx, val);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return 0;
}
@@ -2333,7 +2333,7 @@ static int spufs_show_stat(struct seq_fi
struct spu_context *ctx = s->private;
int ret;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
return ret;
@@ -2352,7 +2352,7 @@ static int spufs_show_stat(struct seq_fi
ctx->stats.maj_flt,
spufs_class2_intrs(ctx),
ctx->stats.libassist);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
return 0;
}
Index: linux-2.6/arch/powerpc/platforms/cell/spufs/run.c
===================================================================
--- linux-2.6.orig/arch/powerpc/platforms/cell/spufs/run.c 2007-12-03 13:03:17.000000000 +0100
+++ linux-2.6/arch/powerpc/platforms/cell/spufs/run.c 2007-12-03 13:03:24.000000000 +0100
@@ -234,7 +234,7 @@ static int spu_run_fini(struct spu_conte
*npc = ctx->ops->npc_read(ctx);
spuctx_switch_state(ctx, SPU_UTIL_IDLE_LOADED);
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
if (signal_pending(current))
ret = -ERESTARTSYS;
@@ -308,13 +308,13 @@ static int spu_process_callback(struct s
npc += 4;
if (s.nr_ret < __NR_syscalls) {
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
/* do actual system call from here */
spu_ret = spu_sys_callback(&s);
if (spu_ret <= -ERESTARTSYS) {
ret = spu_handle_restartsys(ctx, &spu_ret, &npc);
}
- ret2 = spu_acquire(ctx);
+ ret2 = mutex_lock_interruptible(&ctx->state_mutex);
if (ret == -ERESTARTSYS)
return ret;
if (ret2)
@@ -340,7 +340,7 @@ long spufs_run_spu(struct spu_context *c
spu_enable_spu(ctx);
ctx->event_return = 0;
- ret = spu_acquire(ctx);
+ ret = mutex_lock_interruptible(&ctx->state_mutex);
if (ret)
goto out_unlock;
@@ -348,7 +348,7 @@ long spufs_run_spu(struct spu_context *c
ret = spu_run_init(ctx, npc);
if (ret) {
- spu_release(ctx);
+ mutex_unlock(&ctx->state_mutex);
goto out;
}
Index: linux-2.6/arch/powerpc/platforms/cell/spufs/spufs.h
===================================================================
--- linux-2.6.orig/arch/powerpc/platforms/cell/spufs/spufs.h 2007-12-03 13:05:27.000000000 +0100
+++ linux-2.6/arch/powerpc/platforms/cell/spufs/spufs.h 2007-12-03 13:06:40.000000000 +0100
@@ -229,16 +229,6 @@ struct spu *affinity_check(struct spu_co
/* context management */
extern atomic_t nr_spu_contexts;
-static inline int __must_check spu_acquire(struct spu_context *ctx)
-{
- return mutex_lock_interruptible(&ctx->state_mutex);
-}
-
-static inline void spu_release(struct spu_context *ctx)
-{
- mutex_unlock(&ctx->state_mutex);
-}
-
struct spu_context * alloc_spu_context(struct spu_gang *gang);
void destroy_spu_context(struct kref *kref);
struct spu_context * get_spu_context(struct spu_context *ctx);
@@ -266,8 +256,8 @@ extern char *isolated_loader;
/*
* spufs_wait
* Same as wait_event_interruptible(), except that here
- * we need to call spu_release(ctx) before sleeping, and
- * then spu_acquire(ctx) when awoken.
+ * we need to call mutex_unlock(&ctx->state_mutex) before sleeping,
+ * and then mutex_lock_interruptible(&ctx->state_mutex) when awoken.
*/
#define spufs_wait(wq, condition) \
@@ -282,9 +272,9 @@ extern char *isolated_loader;
__ret = -ERESTARTSYS; \
break; \
} \
- spu_release(ctx); \
+ mutex_unlock(&ctx->state_mutex); \
schedule(); \
- __ret = spu_acquire(ctx); \
+ __ret = mutex_lock_interruptible(&ctx->state_mutex); \
if (__ret) \
break; \
} \
More information about the cbe-oss-dev
mailing list