spufs fixes and cleanups
Subsystems (3)
cover spufs fixes and cleanups
In a review almost a month ago, Al Viro found numerous problems in the current spufs code. I now finally found some time to go through those and attempt to fix them.
There are also a few other changes in this series that should also help, in particular improved interrupt sending and an abstraction for priviledged register access (as suggested by Masato Noguchi and Geoff Levand).
Please apply to powerpc.git before sending spufs upstream.
Al, could you have a look over this to see if it addresses all the concerns you had and if I broke it in new ways?
Arnd <><
arch/powerpc/platforms/cell/Makefile | 5 arch/powerpc/platforms/cell/interrupt.c | 42 ++-- arch/powerpc/platforms/cell/interrupt.h | 1 arch/powerpc/platforms/cell/spu_base.c | 67 +++---- arch/powerpc/platforms/cell/spu_priv1.c | 133 ++++++++++++++ arch/powerpc/platforms/cell/spufs/Makefile | 2 arch/powerpc/platforms/cell/spufs/file.c | 167 +---------------- arch/powerpc/platforms/cell/spufs/hw_ops.c | 19 -- arch/powerpc/platforms/cell/spufs/inode.c | 156 ++++++++------- arch/powerpc/platforms/cell/spufs/run.c | 131 ++++++++++++++ arch/powerpc/platforms/cell/spufs/sched.c | 13 + arch/powerpc/platforms/cell/spufs/spufs.h | 35 +++ arch/powerpc/platforms/cell/spufs/switch.c | 139 +++++---------- arch/powerpc/platforms/cell/spufs/syscalls.c | 5 arch/powerpc/platforms/cell/spufs/context.c | 11 - include/asm-powerpc/spu.h | 42 +++- 20 files changed, 565 insertions(+), 407 deletions(-)
PATCH 1/13 spufs: fix locking in spu_acquire_runnable
We need to check for validity of owner under down_write, down_read is not enough.
Noticed by Al Viro.
arch/powerpc/platforms/cell/spufs/context.c +6 -4
@@ -120,27 +120,29 @@ ctx->spu->prio = current->prio;return 0 ; } +up_read (&ctx->state_sema); + +down_write (&ctx->state_sema);/* ctx is about to be freed, can't acquire any more */ if (!ctx->owner) { ret = -EINVAL ; goto out; } -up_read (&ctx->state_sema); -down_write (&ctx->state_sema);if (ctx->state ==SPU_STATE_SAVED ) { ret =spu_activate (ctx,0 ); ctx->state =SPU_STATE_RUNNABLE ; } -downgrade_write (&ctx->state_sema);if (ret) goto out; +downgrade_write (&ctx->state_sema);/* On success, we return holding the lock */ +return ret; out:/* Release here, to simplify calling code. */ -up_read (&ctx->state_sema); +up_write (&ctx->state_sema);return ret; }
--
PATCH 2/13 spufs: dont hold root->isem in spu_forget
In reply to Arnd Bergmannspu_forget will do mmput on the DMA address space, which can lead to lots of other stuff getting triggered. We better not hold a semaphore here that we might need in the process.
Noticed by Al Viro.
arch/powerpc/platforms/cell/spufs/inode.c +10 -10
@@ -162,10 +162,10 @@ {struct dentry *dentry, *tmp;struct spu_context *ctx; -int err;/* remove all entries */ - err =0 ; +down (&root->i_sem); +down (&dir_dentry->d_inode->i_sem);list_for_each_entry_safe (dentry, tmp, &dir_dentry->d_subdirs, d_child) {spin_lock (&dcache_lock);spin_lock (&dentry->d_lock);
@@ -181,16 +181,16 @@spin_unlock (&dcache_lock); } } +shrink_dcache_parent (dir_dentry); +up (&dir_dentry->d_inode->i_sem); +up (&root->i_sem);/* We have to give up the mm_struct */ ctx =SPUFS_I (dir_dentry->d_inode)->i_ctx;spu_forget (ctx); -if (!err) { -shrink_dcache_parent (dir_dentry); - err =simple_rmdir (root, dir_dentry); - } -return err; +/* XXX Do we need to hold i_sem here ? */ +return simple_rmdir (root, dir_dentry); }static int spufs_dir_close (struct inode *inode,struct file *file)
@@ -201,10 +201,10 @@ dentry = file->f_dentry; dir = dentry->d_parent->d_inode; -down (&dir->i_sem); - ret =spufs_rmdir (dir, file->f_dentry); + + ret =spufs_rmdir (dir, dentry);WARN_ON (ret); -up (&dir->i_sem); +return dcache_dir_close (inode, file); }
--
PATCH 3/13 spufs: check for proper file pointer in sys_spu_run
In reply to Arnd BergmannOnly checking for SPUFS_MAGIC is not reliable, because it might not be unique in theory. Worse than that, we accidentally allow spu_run to be performed on any file in spufs, not just those returned from spu_create as intended.
Noticed by Al Viro.
arch/powerpc/platforms/cell/spufs/inode.c +2 -2
@@ -212,7 +212,7 @@ struct inode_operations spufs_dir_inode_ .lookup = simple_lookup, }; -struct file_operations spufs_autodelete_dir_operations = { +struct file_operations spufs_context_fops = { .open = dcache_dir_open, .release = spufs_dir_close, .llseek = dcache_dir_lseek,
@@ -301,7 +301,7 @@ spufs_create_thread(struct nameidata *ndput_unused_fd (ret); ret =PTR_ERR (filp); }else { - filp->f_op = &spufs_autodelete_dir_operations; + filp->f_op = &spufs_context_fops;fd_install (ret, filp); }
arch/powerpc/platforms/cell/spufs/spufs.h +1 -0
@@ -103,6 +103,7 @@ long spufs_run_spu(struct file *file, struct spu_context *ctx, u32 *npc, u32 *status);long spufs_create_thread (struct nameidata *nd,const char *name,unsigned int flags,mode_t mode); +extern struct file_operations spufs_context_fops;/* context management */ struct spu_context *alloc_spu_context (struct address_space *local_store);
arch/powerpc/platforms/cell/spufs/syscalls.c +2 -1
@@ -39,8 +39,9 @@ long do_spu_run(struct file *filp, __u32if (get_user (npc, unpc) ||get_user (status, ustatus)) goto out; +/* check if this file was created by spu_create */ ret = -EINVAL ; -if (filp->f_vfsmnt->mnt_sb->s_magic !=SPUFS_MAGIC ) +if (filp->f_op != &spufs_context_fops) goto out; i =SPUFS_I (filp->f_dentry->d_inode);
--
PATCH 4/13 spufs: serialize sys_spu_run per spu
In reply to Arnd BergmannDuring an earlier cleanup, we lost the serialization of multiple spu_run calls performed on the same spu_context. In order to get this back, introduce a mutex in the spu_context that is held inside of spu_run.
Noticed by Al Viro.
arch/powerpc/platforms/cell/spufs/context.c +1 -0
@@ -43,6 +43,7 @@spin_lock_init (&ctx->mmio_lock);kref_init (&ctx->kref);init_rwsem (&ctx->state_sema); +init_MUTEX (&ctx->run_sema);init_waitqueue_head (&ctx->ibox_wq);init_waitqueue_head (&ctx->wbox_wq);init_waitqueue_head (&ctx->stop_wq);
arch/powerpc/platforms/cell/spufs/file.c +10 -5
@@ -620,8 +620,12 @@ {int ret; -if ((ret =spu_run_init (ctx, npc, status)) !=0 ) -return ret; +if (down_interruptible (&ctx->run_sema)) +return -ERESTARTSYS ; + + ret =spu_run_init (ctx, npc, status); +if (ret) + goto out; do { ret = spufs_wait(ctx->stop_wq, spu_stopped(ctx, status));
@@ -629,9 +633,8 @@break ;if (unlikely (ctx->state !=SPU_STATE_RUNNABLE )) { ret =spu_reacquire_runnable (ctx, npc, status); -if (ret) { -return ret; - } +if (ret) + goto out;continue ; } ret =spu_process_events (ctx);
@@ -645,6 +648,8 @@ ret = *status;spu_yield (ctx); +out: +up (&ctx->run_sema);return ret; }
arch/powerpc/platforms/cell/spufs/spufs.h +1 -0
@@ -48,6 +48,7 @@enum {SPU_STATE_RUNNABLE ,SPU_STATE_SAVED } state;struct rw_semaphore state_sema; +struct semaphore run_sema;struct mm_struct *owner;
--
PATCH 5/13 spufs fix spu_acquire_runnable error path
In reply to Arnd BergmannWhen spu_activate fails in spu_acquire_runnable, the state must still be SPU_STATE_SAVED, we were incorrectly setting it to SPU_STATE_RUNNABLE.
arch/powerpc/platforms/cell/spufs/context.c +2 -2
@@ -132,10 +132,10 @@ int spu_acquire_runnable(struct spu_contif (ctx->state ==SPU_STATE_SAVED ) { ret =spu_activate (ctx,0 ); +if (ret) + goto out; ctx->state =SPU_STATE_RUNNABLE ; } -if (ret) - goto out;downgrade_write (&ctx->state_sema);/* On success, we return holding the lock */
--
PATCH 6/13 spufs: dont leak directories in failed spu_create
In reply to Arnd BergmannIf get_unused_fd failed in sys_spu_create, we never cleaned up the created directory. Fix that by restructuring the error path.
Noticed by Al Viro.
arch/powerpc/platforms/cell/spufs/inode.c +37 -17
@@ -26,6 +26,7 @@#include <linux/init.h> #include <linux/ioctl.h> #include <linux/module.h> +#include <linux/mount.h> #include <linux/namei.h> #include <linux/pagemap.h> #include <linux/poll.h>
@@ -251,6 +252,7 @@ spufs_mkdir(struct inode *dir, struct ded_instantiate (dentry, inode);dget (dentry); dir->i_nlink++; + dentry->d_inode->i_nlink++; goto out; out_free_ctx:
@@ -261,18 +263,44 @@ out:return ret; } +static int spufs_context_open (struct dentry *dentry,struct vfsmount *mnt) +{ +int ret; +struct file *filp; + + ret =get_unused_fd (); +if (ret <0 ) { +dput (dentry); +mntput (mnt); + goto out; + } + + filp =dentry_open (dentry, mnt,O_RDONLY ); +if (IS_ERR (filp)) { +put_unused_fd (ret); + ret =PTR_ERR (filp); + goto out; + } + + filp->f_op = &spufs_context_fops; +fd_install (ret, filp); +out: +return ret; +} + +static struct file_system_type spufs_type; +long spufs_create_thread (struct nameidata *nd,const char *name,unsigned int flags,mode_t mode) {struct dentry *dentry; -struct file *filp;int ret;/* need to be at the root of spufs */ ret = -EINVAL ; -if (nd->dentry->d_sb->s_magic !=SPUFS_MAGIC || - nd->dentry != nd->dentry->d_sb->s_root) +if (nd->dentry->d_sb->s_type != &spufs_type || + nd->dentry != nd->dentry->d_sb->s_root) goto out; dentry =lookup_create (nd,1 );
@@ -289,21 +317,13 @@ spufs_create_thread(struct nameidata *ndif (ret) goto out_dput; - ret =get_unused_fd (); +/* +* get references for dget and mntget, will be released +* in error path of *_open(). +*/ + ret =spufs_context_open (dget (dentry),mntget (nd->mnt));if (ret <0 ) - goto out_dput; - - dentry->d_inode->i_nlink++; - - filp =filp_open (name,O_RDONLY , mode); -if (IS_ERR (filp)) { -// FIXME: remove directory again -put_unused_fd (ret); - ret =PTR_ERR (filp); - }else { - filp->f_op = &spufs_context_fops; -fd_install (ret, filp); - } +spufs_rmdir (nd->dentry->d_inode, dentry); out_dput:dput (dentry);
--
PATCH 7/13 spufs: fix spufs_fill_dir error path
In reply to Arnd BergmannIf creating one entry failed in spufs_fill_dir, we never cleaned up the freshly created entries. Fix this by calling the cleanup function on error.
Noticed by Al Viro.
arch/powerpc/platforms/cell/spufs/inode.c +38 -35
@@ -134,47 +134,18 @@ spufs_delete_inode(struct inode *inode)clear_inode (inode); } -static int -spufs_fill_dir (struct dentry *dir,struct tree_descr *files, -int mode,struct spu_context *ctx) -{ -struct dentry *dentry; -int ret; - -while (files->name && files->name[0 ]) { - ret = -ENOMEM ; - dentry =d_alloc_name (dir, files->name); -if (!dentry) - goto out; - ret =spufs_new_file (dir->d_sb, dentry, files->ops, - files->mode & mode, ctx); -if (ret) - goto out; - files++; - } -return 0 ; -out: -// FIXME: remove all files that are left - -return ret; -} - -static int spufs_rmdir (struct inode *root,struct dentry *dir_dentry) +static void spufs_prune_dir (struct dentry *dir) {struct dentry *dentry, *tmp; -struct spu_context *ctx; - -/* remove all entries */ -down (&root->i_sem); -down (&dir_dentry->d_inode->i_sem); -list_for_each_entry_safe (dentry, tmp, &dir_dentry->d_subdirs, d_child) { +down (&dir->d_inode->i_sem); +list_for_each_entry_safe (dentry, tmp, &dir->d_subdirs, d_child) {spin_lock (&dcache_lock);spin_lock (&dentry->d_lock);if (!(d_unhashed (dentry)) && dentry->d_inode) {dget_locked (dentry);__d_drop (dentry);spin_unlock (&dentry->d_lock); -simple_unlink (dir_dentry->d_inode, dentry); +simple_unlink (dir->d_inode, dentry);spin_unlock (&dcache_lock);dput (dentry); }else {
@@ -182,8 +153,17 @@ static int spufs_rmdir(struct inode *roospin_unlock (&dcache_lock); } } -shrink_dcache_parent (dir_dentry); -up (&dir_dentry->d_inode->i_sem); +shrink_dcache_parent (dir); +up (&dir->d_inode->i_sem); +} + +static int spufs_rmdir (struct inode *root,struct dentry *dir_dentry) +{ +struct spu_context *ctx; + +/* remove all entries */ +down (&root->i_sem); +spufs_prune_dir (dir_dentry);up (&root->i_sem);/* We have to give up the mm_struct */
@@ -194,6 +174,29 @@ static int spufs_rmdir(struct inode *rooreturn simple_rmdir (root, dir_dentry); } +static int spufs_fill_dir (struct dentry *dir,struct tree_descr *files, +int mode,struct spu_context *ctx) +{ +struct dentry *dentry; +int ret; + +while (files->name && files->name[0 ]) { + ret = -ENOMEM ; + dentry =d_alloc_name (dir, files->name); +if (!dentry) + goto out; + ret =spufs_new_file (dir->d_sb, dentry, files->ops, + files->mode & mode, ctx); +if (ret) + goto out; + files++; + } +return 0 ; +out: +spufs_prune_dir (dir); +return ret; +} +static int spufs_dir_close (struct inode *inode,struct file *file) {struct inode *dir;
--
PATCH 8/13 spufs: clean up use of bitops
In reply to Arnd Bergmannchecking bits manually might not be synchonized with the use of set_bit/clear_bit. Make sure we always use the correct bitops by removing the unnecessary identifiers.
arch/powerpc/platforms/cell/spufs/sched.c +4 -4
@@ -214,14 +214,14 @@ static void spu_reaper(void *data)down_write (&ctx->state_sema); spu = ctx->spu; -if (spu && (ctx->flags &SPU_CONTEXT_PREEMPT )) { +if (spu &&test_bit (SPU_CONTEXT_PREEMPT , &ctx->flags)) {if (atomic_read (&spu->rq->prio.nr_blocked)) {pr_debug ("%s: spu=%d\n" , __func__, spu->number); ctx->ops->runcntl_stop (ctx);spu_deactivate (ctx);wake_up_all (&ctx->stop_wq); }else { -clear_bit (SPU_CONTEXT_PREEMPT_nr, &ctx->flags); +clear_bit (SPU_CONTEXT_PREEMPT , &ctx->flags); } }up_write (&ctx->state_sema);
@@ -234,7 +234,7 @@ static void schedule_spu_reaper(struct sunsigned long now = jiffies;unsigned long expire = spu->timestamp +SPU_MIN_TIMESLICE ; -set_bit (SPU_CONTEXT_PREEMPT_nr, &ctx->flags); +set_bit (SPU_CONTEXT_PREEMPT , &ctx->flags);INIT_WORK (&ctx->reap_work, spu_reaper, ctx);if (time_after (now, expire))schedule_work (&ctx->reap_work);
@@ -250,7 +250,7 @@ static void check_preempt_active(structlist_for_each (p, &rq->active_list) { struct spu *spu = list_entry(p, struct spu, sched_list);struct spu_context *ctx = spu->ctx; -if (!(ctx->flags &SPU_CONTEXT_PREEMPT )) { +if (!test_bit (SPU_CONTEXT_PREEMPT , &ctx->flags)) {if (!worst || (spu->prio > worst->prio)) { worst = spu; }
arch/powerpc/platforms/cell/spufs/spufs.h +1 -2
@@ -37,8 +37,7 @@ enum {struct spu_context_ops ; -#define SPU_CONTEXT_PREEMPT_nr 0UL -#define SPU_CONTEXT_PREEMPT (1UL << SPU_CONTEXT_PREEMPT_nr) +#define SPU_CONTEXT_PREEMPT 0ULstruct spu_context {struct spu *spu;/* pointer to a physical SPU */
include/asm-powerpc/spu.h +2 -4
@@ -102,10 +102,8 @@#define MFC_MULTI_SRC_EVENT 0x00001000/* Flags indicating progress during context switch. */ -#define SPU_CONTEXT_SWITCH_PENDING_nr 0UL -#define SPU_CONTEXT_SWITCH_ACTIVE_nr 1UL -#define SPU_CONTEXT_SWITCH_PENDING (1UL << SPU_CONTEXT_SWITCH_PENDING_nr) -#define SPU_CONTEXT_SWITCH_ACTIVE (1UL << SPU_CONTEXT_SWITCH_ACTIVE_nr) +#define SPU_CONTEXT_SWITCH_PENDING 0UL +#define SPU_CONTEXT_SWITCH_ACTIVE 1ULstruct spu_context ;struct spu_runqueue ;
arch/powerpc/platforms/cell/spu_base.c +3 -3
@@ -63,7 +63,7 @@ static void spu_restart_dma(struct spu * {struct spu_priv2 __iomem *priv2 = spu->priv2; -if (!test_bit (SPU_CONTEXT_SWITCH_PENDING_nr, &spu->flags)) +if (!test_bit (SPU_CONTEXT_SWITCH_PENDING , &spu->flags))out_be64 (&priv2->mfc_control_RW,MFC_CNTL_RESTART_DMA_COMMAND ); }
@@ -75,7 +75,7 @@ static int __spu_trap_data_seg(struct sppr_debug ("%s\n" , __FUNCTION__); -if (test_bit (SPU_CONTEXT_SWITCH_ACTIVE_nr, &spu->flags)) { +if (test_bit (SPU_CONTEXT_SWITCH_ACTIVE , &spu->flags)) {/* SLBs are pre-loaded for context switch, so * we should never get here! */
@@ -122,7 +122,7 @@ static int __spu_trap_data_map(struct spreturn 0 ; } -if (test_bit (SPU_CONTEXT_SWITCH_ACTIVE_nr, &spu->flags)) { +if (test_bit (SPU_CONTEXT_SWITCH_ACTIVE , &spu->flags)) {printk ("%s: invalid access during switch!\n" , __func__);return 1 ; }
arch/powerpc/platforms/cell/spufs/switch.c +4 -4
@@ -165,7 +165,7 @@ static inline void set_switch_pending(st* Restore, Step 5: * Set a software context switch pending flag. */ -set_bit (SPU_CONTEXT_SWITCH_PENDING_nr, &spu->flags); +set_bit (SPU_CONTEXT_SWITCH_PENDING , &spu->flags);mb (); }
@@ -767,8 +767,8 @@ static inline void set_switch_active(str* Change the software context switch pending flag * to context switch active. */ -set_bit (SPU_CONTEXT_SWITCH_ACTIVE_nr, &spu->flags); -clear_bit (SPU_CONTEXT_SWITCH_PENDING_nr, &spu->flags); +set_bit (SPU_CONTEXT_SWITCH_ACTIVE , &spu->flags); +clear_bit (SPU_CONTEXT_SWITCH_PENDING , &spu->flags);mb (); }
@@ -1786,7 +1786,7 @@ static inline void reset_switch_active(s/* Restore, Step 74: * Reset the "context switch active" flag. */ -clear_bit (SPU_CONTEXT_SWITCH_ACTIVE_nr, &spu->flags); +clear_bit (SPU_CONTEXT_SWITCH_ACTIVE , &spu->flags);mb (); }
--
PATCH 9/13 spufs: move spu_run call to its own file
In reply to Arnd BergmannThe logic for sys_spu_run keeps growing and it does not really belong into file.c any more since we moved away from using regular file operations to our own syscall.
No functional change in here.
arch/powerpc/platforms/cell/spufs/Makefile +1 -1
@@ -1,6 +1,6 @@ obj-$(CONFIG_SPU_FS) += spufs.o spufs-y += inode.o file.o context.o switch.o syscalls.o -spufs-y += sched.o backing_ops.o hw_ops.o +spufs-y += sched.o backing_ops.o hw_ops.o run.o # Rules to build switch.o with the help of SPU tool chain SPU_CROSS := spu-
arch/powerpc/platforms/cell/spufs/file.c +0 -152
164 lines not on this page · raw message
arch/powerpc/platforms/cell/spufs/run.c new file +131 -0
131 lines not on this page · raw message
arch/powerpc/platforms/cell/spufs/spufs.h +28 -0
@@ -124,6 +124,34 @@ void spu_yield(struct spu_context *ctx);int __init spu_sched_init (void ); void __exit spu_sched_exit(void); +/* +* 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. +*/ + +#define spufs_wait (wq, condition) \ +({ \ + int __ret = 0; \ + DEFINE_WAIT(__wait); \ + for (;;) { \ + prepare_to_wait(&(wq), &__wait, TASK_INTERRUPTIBLE); \ + if (condition) \ + break; \ + if (!signal_pending(current)) { \ + spu_release(ctx); \ + schedule(); \ + spu_acquire(ctx); \ + continue; \ + } \ + __ret = -ERESTARTSYS; \ + break; \ + } \ + finish_wait(&(wq), &__wait); \ + __ret; \ +}) +size_t spu_wbox_write (struct spu_context *ctx,u32 data);size_t spu_ibox_read (struct spu_context *ctx,u32 *data);
--
PATCH 10/13 spufs: abstract priv1 register access.
In reply to Arnd BergmannIn a hypervisor based setup, direct access to the first priviledged register space can typically not be allowed to the kernel and has to be implemented through hypervisor calls.
As suggested by Masato Noguchi, let's abstract the register access trough a number of function calls. Since there is currently no public specification of actual hypervisor calls to implement this, I only provide a place that makes it easier to hook into.
arch/powerpc/platforms/cell/spu_base.c +18 -33
@@ -142,8 +142,7 @@ static int __spu_trap_mailbox(struct spu/* atomically disable SPU mailbox interrupts */ spin_lock (&spu->register_lock); -out_be64 (&spu->priv1->int_mask_class2_RW, -in_be64 (&spu->priv1->int_mask_class2_RW) & ~0x1 ); +spu_int_mask_and (spu,2 , ~0x1 );spin_unlock (&spu->register_lock);return 0 ; }
@@ -180,8 +179,7 @@ static int __spu_trap_spubox(struct spu/* atomically disable SPU mailbox interrupts */ spin_lock (&spu->register_lock); -out_be64 (&spu->priv1->int_mask_class2_RW, -in_be64 (&spu->priv1->int_mask_class2_RW) & ~0x10 ); +spu_int_mask_and (spu,2 , ~0x10 );spin_unlock (&spu->register_lock);return 0 ; }
@@ -206,8 +204,8 @@ spu_irq_class_0_bottom(struct spu *spu) spu->class_0_pending =0 ; - mask =in_be64 (&spu->priv1->int_mask_class0_RW); - stat =in_be64 (&spu->priv1->int_stat_class0_RW); + mask =spu_int_mask_get (spu,0 ); + stat =spu_int_stat_get (spu,0 ); stat &= mask;
@@ -220,7 +218,7 @@ spu_irq_class_0_bottom(struct spu *spu)if (stat &4 )/* error on SPU */ __spu_trap_error (spu); -out_be64 (&spu->priv1->int_stat_class0_RW, stat); +spu_int_stat_clear (spu,0 , stat);return (stat &0x7 ) ? -EIO :0 ; }
@@ -236,13 +234,13 @@ spu_irq_class_1(int irq, void *data, str/* atomically read & clear class1 status. */ spin_lock (&spu->register_lock); - mask =in_be64 (&spu->priv1->int_mask_class1_RW); - stat =in_be64 (&spu->priv1->int_stat_class1_RW) & mask; - dar =in_be64 (&spu->priv1->mfc_dar_RW); - dsisr =in_be64 (&spu->priv1->mfc_dsisr_RW); + mask =spu_int_mask_get (spu,1 ); + stat =spu_int_stat_get (spu,1 ) & mask; + dar =spu_mfc_dar_get (spu); + dsisr =spu_mfc_dsisr_get (spu);if (stat &2 )/* mapping fault */ -out_be64 (&spu->priv1->mfc_dsisr_RW,0UL ); -out_be64 (&spu->priv1->int_stat_class1_RW, stat); +spu_mfc_dsisr_set (spu,0ul ); +spu_int_stat_clear (spu,1 , stat);spin_unlock (&spu->register_lock);if (stat &1 )/* segment fault */
@@ -270,8 +268,8 @@ spu_irq_class_2(int irq, void *data, strunsigned long mask; spu = data; - stat =in_be64 (&spu->priv1->int_stat_class2_RW); - mask =in_be64 (&spu->priv1->int_mask_class2_RW); + stat =spu_int_stat_get (spu,2 ); + mask =spu_int_mask_get (spu,2 );pr_debug ("class 2 interrupt %d, %lx, %lx\n" , irq, stat, mask);
@@ -292,7 +290,7 @@ spu_irq_class_2(int irq, void *data, strif (stat &0x10 )/* SPU mailbox threshold */ __spu_trap_spubox (spu); -out_be64 (&spu->priv1->int_stat_class2_RW, stat); +spu_int_stat_clear (spu,2 , stat);return stat ?IRQ_HANDLED :IRQ_NONE ; }
@@ -309,21 +307,18 @@ spu_request_irqs(struct spu *spu) spu_irq_class_0, 0, spu->irq_c0, spu);if (ret) goto out; -out_be64 (&spu->priv1->int_mask_class0_RW,0x7 );snprintf (spu->irq_c1,sizeof (spu->irq_c1),"spe%02d.1" , spu->number); ret =request_irq (irq_base +IIC_CLASS_STRIDE + spu->isrc, spu_irq_class_1,0 , spu->irq_c1, spu);if (ret) goto out1; -out_be64 (&spu->priv1->int_mask_class1_RW,0x3 );snprintf (spu->irq_c2,sizeof (spu->irq_c2),"spe%02d.2" , spu->number); ret =request_irq (irq_base +2 *IIC_CLASS_STRIDE + spu->isrc, spu_irq_class_2,0 , spu->irq_c2, spu);if (ret) goto out2; -out_be64 (&spu->priv1->int_mask_class2_RW,0xe ); goto out; out2:
@@ -383,13 +378,6 @@ static void spu_init_channels(struct spu } } -static void spu_init_regs (struct spu *spu) -{ -out_be64 (&spu->priv1->int_mask_class0_RW,0x7 ); -out_be64 (&spu->priv1->int_mask_class1_RW,0x3 ); -out_be64 (&spu->priv1->int_mask_class2_RW,0xe ); -} -struct spu *spu_alloc (void ) {struct spu *spu;
@@ -405,10 +393,8 @@ struct spu *spu_alloc(void) }up (&spu_mutex); -if (spu) { +if (spu)spu_init_channels (spu); -spu_init_regs (spu); - }return spu; }
@@ -579,8 +565,7 @@ static int __init spu_map_device(struct goto out_unmap; spu->priv1=map_spe_prop (spe,"priv1" ); -if (!spu->priv1) - goto out_unmap; +/* priv1 is not available on a hypervisor */ spu->priv2=map_spe_prop (spe,"priv2" );if (!spu->priv2)
@@ -633,8 +618,8 @@ static int __init create_spu(struct devi spu->dsisr =0UL ;spin_lock_init (&spu->register_lock); -out_be64 (&spu->priv1->mfc_sdr_RW,mfspr (SPRN_SDR1 )); -out_be64 (&spu->priv1->mfc_sr1_RW,0x33 ); +spu_mfc_sdr_set (spu,mfspr (SPRN_SDR1 )); +spu_mfc_sr1_set (spu,0x33 ); spu->ibox_callback =NULL ; spu->wbox_callback =NULL ;
arch/powerpc/platforms/cell/spu_priv1.c new file +133 -0
133 lines not on this page · raw message
arch/powerpc/platforms/cell/spufs/hw_ops.c +6 -13
@@ -62,7 +62,6 @@ static unsigned int spu_hw_mbox_stat_pol unsigned int events) {struct spu *spu = ctx->spu; -struct spu_priv1 __iomem *priv1 = spu->priv1;int ret =0 ;u32 stat;
@@ -78,18 +77,16 @@ static unsigned int spu_hw_mbox_stat_polif (stat &0xff0000 ) ret |=POLLIN |POLLRDNORM ;else { -out_be64 (&priv1->int_stat_class2_RW,0x1 ); -out_be64 (&priv1->int_mask_class2_RW, -in_be64 (&priv1->int_mask_class2_RW) |0x1 ); +spu_int_stat_clear (spu,2 ,0x1 ); +spu_int_mask_or (spu,2 ,0x1 ); } }if (events & (POLLOUT |POLLWRNORM )) {if (stat &0x00ff00 ) ret =POLLOUT |POLLWRNORM ;else { -out_be64 (&priv1->int_stat_class2_RW,0x10 ); -out_be64 (&priv1->int_mask_class2_RW, -in_be64 (&priv1->int_mask_class2_RW) |0x10 ); +spu_int_stat_clear (spu,2 ,0x10 ); +spu_int_mask_or (spu,2 ,0x10 ); } }spin_unlock_irq (&spu->register_lock);
@@ -100,7 +97,6 @@ static int spu_hw_ibox_read(struct spu_c {struct spu *spu = ctx->spu;struct spu_problem __iomem *prob = spu->problem; -struct spu_priv1 __iomem *priv1 = spu->priv1;struct spu_priv2 __iomem *priv2 = spu->priv2;int ret;
@@ -111,8 +107,7 @@ static int spu_hw_ibox_read(struct spu_c ret =4 ; }else {/* make sure we get woken up by the interrupt */ -out_be64 (&priv1->int_mask_class2_RW, -in_be64 (&priv1->int_mask_class2_RW) |0x1 ); +spu_int_mask_or (spu,2 ,0x1 ); ret =0 ; }spin_unlock_irq (&spu->register_lock);
@@ -123,7 +118,6 @@ static int spu_hw_wbox_write(struct spu_ {struct spu *spu = ctx->spu;struct spu_problem __iomem *prob = spu->problem; -struct spu_priv1 __iomem *priv1 = spu->priv1;int ret;spin_lock_irq (&spu->register_lock);
@@ -134,8 +128,7 @@ static int spu_hw_wbox_write(struct spu_ }else {/* make sure we get woken up by the interrupt when space becomes available */ -out_be64 (&priv1->int_mask_class2_RW, -in_be64 (&priv1->int_mask_class2_RW) |0x10 ); +spu_int_mask_or (spu,2 ,0x10 ); ret =0 ; }spin_unlock_irq (&spu->register_lock);
arch/powerpc/platforms/cell/spufs/switch.c +48 -83
346 lines not on this page · raw message
include/asm-powerpc/spu.h +25 -6
@@ -172,6 +172,29 @@ static inline void unregister_spu_syscal#endif /* MODULE */ +/* access to priv1 registers */ +void spu_int_mask_and (struct spu *spu,int class,u64 mask); +void spu_int_mask_or (struct spu *spu,int class,u64 mask); +void spu_int_mask_set (struct spu *spu,int class,u64 mask); +u64 spu_int_mask_get (struct spu *spu,int class); +void spu_int_stat_clear (struct spu *spu,int class,u64 stat); +u64 spu_int_stat_get (struct spu *spu,int class); +void spu_int_route_set (struct spu *spu,u64 route); +u64 spu_mfc_dar_get (struct spu *spu); +u64 spu_mfc_dsisr_get (struct spu *spu); +void spu_mfc_dsisr_set (struct spu *spu,u64 dsisr); +void spu_mfc_sdr_set (struct spu *spu,u64 sdr); +void spu_mfc_sr1_set (struct spu *spu,u64 sr1); +u64 spu_mfc_sr1_get (struct spu *spu); +void spu_mfc_tclass_id_set (struct spu *spu,u64 tclass_id); +u64 spu_mfc_tclass_id_get (struct spu *spu); +void spu_tlb_invalidate (struct spu *spu); +void spu_resource_allocation_groupID_set (struct spu *spu,u64 id); +u64 spu_resource_allocation_groupID_get (struct spu *spu); +void spu_resource_allocation_enable_set (struct spu *spu,u64 enable); +u64 spu_resource_allocation_enable_get (struct spu *spu); + +/* * This defines the Local Store, Problem Area and Privlege Area of an SPU. */
@@ -379,25 +402,21 @@ struct spu_priv1 {/* Interrupt Area */ -u64 int_mask_class0_RW;/* 0x100 */ +u64 int_mask_RW[3 ];/* 0x100 */ #define CLASS0_ENABLE_DMA_ALIGNMENT_INTR 0x1L#define CLASS0_ENABLE_INVALID_DMA_COMMAND_INTR 0x2L#define CLASS0_ENABLE_SPU_ERROR_INTR 0x4L#define CLASS0_ENABLE_MFC_FIR_INTR 0x8L -u64 int_mask_class1_RW;/* 0x108 */ #define CLASS1_ENABLE_SEGMENT_FAULT_INTR 0x1L#define CLASS1_ENABLE_STORAGE_FAULT_INTR 0x2L#define CLASS1_ENABLE_LS_COMPARE_SUSPEND_ON_GET_INTR 0x4L#define CLASS1_ENABLE_LS_COMPARE_SUSPEND_ON_PUT_INTR 0x8L -u64 int_mask_class2_RW;/* 0x110 */ #define CLASS2_ENABLE_MAILBOX_INTR 0x1L#define CLASS2_ENABLE_SPU_STOP_INTR 0x2L#define CLASS2_ENABLE_SPU_HALT_INTR 0x4L#define CLASS2_ENABLE_SPU_DMA_TAG_GROUP_COMPLETE_INTR 0x8Lu8 pad_0x118_0x140[0x28 ];/* 0x118 */ -u64 int_stat_class0_RW;/* 0x140 */ -u64 int_stat_class1_RW;/* 0x148 */ -u64 int_stat_class2_RW;/* 0x150 */ +u64 int_stat_RW[3 ];/* 0x140 */ u8 pad_0x158_0x180[0x28 ];/* 0x158 */ u64 int_route_RW;/* 0x180 */
arch/powerpc/platforms/cell/Makefile +4 -1
@@ -2,6 +2,9 @@ obj-y += interrupt.o iommu.o setup.o s obj-y += pervasive.o obj-$(CONFIG_SMP) += smp.o -obj-$(CONFIG_SPU_FS) += spufs/ spu_base.o +obj-$(CONFIG_SPU_FS) += spufs/ spu-base.o + +spu-base-y += spu_base.o spu_priv1.o + builtin-spufs-$(CONFIG_SPU_FS) += spu_syscalls.o obj-y += $(builtin-spufs-m)
--
PATCH 11/13 spufs: fix sparse warnings
In reply to Arnd BergmannOne local variable is missing an __iomem modifier, in another place, we pass a completely unused argument with a missing __user modifier.
arch/powerpc/platforms/cell/spu_base.c +1 -1
@@ -357,7 +357,7 @@ static void spu_init_channels(struct spu { 0x17, 1, }, { 0x18, 0, }, { 0x19, 0, }, { 0x1b, 0, }, { 0x1c, 1, }, { 0x1d, 0, }, { 0x1e, 1, }, }; -struct spu_priv2 *priv2; +struct spu_priv2 __iomem *priv2;int i; priv2 = spu->priv2;
arch/powerpc/platforms/cell/spufs/spufs.h +1 -1
@@ -101,7 +101,7 @@ extern struct tree_descr spufs_dir_conte/* system call implementation */ long spufs_run_spu (struct file *file,struct spu_context *ctx,u32 *npc,u32 *status); -long spufs_create_thread (struct nameidata *nd,const char *name, +long spufs_create_thread (struct nameidata *nd,unsigned int flags,mode_t mode);extern struct file_operations spufs_context_fops;
arch/powerpc/platforms/cell/spufs/inode.c +2 -3
@@ -293,9 +293,8 @@ out:static struct file_system_type spufs_type; -long -spufs_create_thread (struct nameidata *nd,const char *name, -unsigned int flags,mode_t mode) +long spufs_create_thread (struct nameidata *nd, +unsigned int flags,mode_t mode) {struct dentry *dentry;int ret;
arch/powerpc/platforms/cell/spufs/syscalls.c +1 -1
@@ -85,7 +85,7 @@ asmlinkage long sys_spu_create(const cha ret =path_lookup (tmp,LOOKUP_PARENT |LOOKUP_OPEN |LOOKUP_CREATE , &nd);if (!ret) { - ret =spufs_create_thread (&nd, pathname, flags, mode); + ret =spufs_create_thread (&nd, flags, mode);path_release (&nd); }putname (tmp);
--
PATCH 12/13 spufs: fix allocation on 64k pages
In reply to Arnd BergmannThe size of the local store is architecture defined and independent from the page size, so it should not be defined in terms of pages in the first place.
This mistake broke a few places when building for
64kb pages.
include/asm-powerpc/spu.h +1 -3
@@ -28,9 +28,7 @@#include <linux/kref.h> #include <linux/workqueue.h> -#define LS_ORDER (6)/* 256 kb */ - -#define LS_SIZE (PAGE_SIZE << LS_ORDER) +#define LS_SIZE (256 * 1024)#define LS_ADDR_MASK (LS_SIZE - 1)#define MFC_PUT_CMD 0x20
--
PATCH 13/13 spufs: set irq affinity for running threads
In reply to Arnd BergmannFor far, all SPU triggered interrupts always end up on the first SMT thread, which is a bad solution.
This patch implements setting the affinity to the CPU that was running last when entering execution on an SPU. This should result in a significant reduction in IPI calls and better cache locality for SPE thread specific data.
include/asm-powerpc/spu.h +1 -0
@@ -147,6 +147,7 @@ struct spu *spu_alloc(void);void spu_free (struct spu *spu);int spu_irq_class_0_bottom (struct spu *spu);int spu_irq_class_1_bottom (struct spu *spu); +void spu_irq_setaffinity (struct spu *spu,int cpu); extern struct spufs_calls { asmlinkage long (*create_thread)(const char __user *name,
arch/powerpc/platforms/cell/interrupt.c +26 -16
83 lines not on this page · raw message
arch/powerpc/platforms/cell/interrupt.h +1 -0
@@ -54,6 +54,7 @@ extern void iic_setup_cpu(void);extern void iic_local_enable (void );extern void iic_local_disable (void ); +extern u8 iic_get_target_id (int cpu);extern void spider_init_IRQ (void );extern int spider_get_irq (unsigned long int_pending);
arch/powerpc/platforms/cell/spu_base.c +8 -0
@@ -507,6 +507,14 @@ int spu_irq_class_1_bottom(struct spu *sreturn ret; } +void spu_irq_setaffinity (struct spu *spu,int cpu) +{ +u64 target =iic_get_target_id (cpu); +u64 route = target <<48 | target <<32 | target <<16 ; +spu_int_route_set (spu, route); +} +EXPORT_SYMBOL_GPL (spu_irq_setaffinity); +static void __iomem *__init map_spe_prop (struct device_node *n,const char *name) {
arch/powerpc/platforms/cell/spufs/sched.c +5 -0
@@ -357,6 +357,11 @@ int spu_activate(struct spu_context *ctxif (!spu)return (signal_pending (current)) ? -ERESTARTSYS : -EAGAIN ;bind_context (spu, ctx); +/* +* We're likely to wait for interrupts on the same +* CPU that we are now on, so send them here. +*/ +spu_irq_setaffinity (spu,smp_processor_id ());put_active_spu (spu);return 0 ; }
--
Re: [PATCH 13/13] spufs: set irq affinity for running threads
Quoted 8 lines · Arnd Bergmann
For far, all SPU triggered interrupts always end up on the first SMT thread, which is a bad solution.
This patch implements setting the affinity to the CPU that was running last when entering execution on an SPU. This should result in a significant reduction in IPI calls and better cache locality for SPE thread specific data.
...
arch/powerpc/platforms/cell/spufs/sched.c int spu_activate(struct spu_context *ctx · line 364
Quoted 11 lines
arch/powerpc/platforms/cell/spufs/sched.c +5
-0@@ -357,6 +357,11 @@ int spu_activate(struct spu_context *ctxif (!spu)return (signal_pending (current)) ? -ERESTARTSYS : -EAGAIN ;bind_context (spu, ctx); +/* +* We're likely to wait for interrupts on the same +* CPU that we are now on, so send them here. +*/ +spu_irq_setaffinity (spu,smp_processor_id ());
With CONFIG_DEBUG_PREEMPT this will give a warning about using smp_processor_id in pre-emptible context if I'm reading the code correctly.
Maybe use raw_smp_processor_id, since setting the affinity to this cpu isn't a hard requirement?
Re: [PATCH 13/13] spufs: set irq affinity for running threads
For far, all SPU triggered interrupts always end up on the first SMT thread, which is a bad solution.
This patch implements setting the affinity to the CPU that was running last when entering execution on an SPU. This should result in a significant reduction in IPI calls and better cache locality for SPE thread specific data.
---
Quoted 8 lines · Nathan Lynch
Review
Quoted 1 line
(quoted diff) +1
-0+ spu_irq_setaffinity(spu, smp_processor_id());With
CONFIG_DEBUG_PREEMPTthis will give a warning about usingsmp_processor_idin pre-emptible context if I'm reading the code correctly.Maybe use
raw_smp_processor_id, since setting the affinity to this cpu isn't a hard requirement?
Good point. Please use this version instead.
Arnd <><
include/asm-powerpc/spu.h +1 -0
@@ -147,6 +147,7 @@ struct spu *spu_alloc(void);void spu_free (struct spu *spu);int spu_irq_class_0_bottom (struct spu *spu);int spu_irq_class_1_bottom (struct spu *spu); +void spu_irq_setaffinity (struct spu *spu,int cpu); extern struct spufs_calls { asmlinkage long (*create_thread)(const char __user *name,
arch/powerpc/platforms/cell/interrupt.c +26 -16
83 lines not on this page · raw message
arch/powerpc/platforms/cell/interrupt.h +1 -0
@@ -54,6 +54,7 @@ extern void iic_setup_cpu(void);extern void iic_local_enable (void );extern void iic_local_disable (void ); +extern u8 iic_get_target_id (int cpu);extern void spider_init_IRQ (void );extern int spider_get_irq (unsigned long int_pending);
arch/powerpc/platforms/cell/spu_base.c +8 -0
@@ -507,6 +507,14 @@ int spu_irq_class_1_bottom(struct spu *sreturn ret; } +void spu_irq_setaffinity (struct spu *spu,int cpu) +{ +u64 target =iic_get_target_id (cpu); +u64 route = target <<48 | target <<32 | target <<16 ; +spu_int_route_set (spu, route); +} +EXPORT_SYMBOL_GPL (spu_irq_setaffinity); +static void __iomem *__init map_spe_prop (struct device_node *n,const char *name) {
arch/powerpc/platforms/cell/spufs/sched.c +5 -0
@@ -357,6 +357,11 @@ int spu_activate(struct spu_context *ctxif (!spu)return (signal_pending (current)) ? -ERESTARTSYS : -EAGAIN ;bind_context (spu, ctx); +/* +* We're likely to wait for interrupts on the same +* CPU that we are now on, so send them here. +*/ +spu_irq_setaffinity (spu,raw_smp_processor_id ());put_active_spu (spu);return 0 ; }