~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/platforms/cell/spufs/context.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * SPU file system -- SPU context management
  4  *
  5  * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
  6  *
  7  * Author: Arnd Bergmann <arndb@de.ibm.com>
  8  */
  9 
 10 #include <linux/fs.h>
 11 #include <linux/mm.h>
 12 #include <linux/slab.h>
 13 #include <linux/atomic.h>
 14 #include <linux/sched.h>
 15 #include <linux/sched/mm.h>
 16 
 17 #include <asm/spu.h>
 18 #include <asm/spu_csa.h>
 19 #include "spufs.h"
 20 #include "sputrace.h"
 21 
 22 
 23 atomic_t nr_spu_contexts = ATOMIC_INIT(0);
 24 
 25 struct spu_context *alloc_spu_context(struct spu_gang *gang)
 26 {
 27         struct spu_context *ctx;
 28 
 29         ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
 30         if (!ctx)
 31                 goto out;
 32         /* Binding to physical processor deferred
 33          * until spu_activate().
 34          */
 35         if (spu_init_csa(&ctx->csa))
 36                 goto out_free;
 37         spin_lock_init(&ctx->mmio_lock);
 38         mutex_init(&ctx->mapping_lock);
 39         kref_init(&ctx->kref);
 40         mutex_init(&ctx->state_mutex);
 41         mutex_init(&ctx->run_mutex);
 42         init_waitqueue_head(&ctx->ibox_wq);
 43         init_waitqueue_head(&ctx->wbox_wq);
 44         init_waitqueue_head(&ctx->stop_wq);
 45         init_waitqueue_head(&ctx->mfc_wq);
 46         init_waitqueue_head(&ctx->run_wq);
 47         ctx->state = SPU_STATE_SAVED;
 48         ctx->ops = &spu_backing_ops;
 49         ctx->owner = get_task_mm(current);
 50         INIT_LIST_HEAD(&ctx->rq);
 51         INIT_LIST_HEAD(&ctx->aff_list);
 52         if (gang)
 53                 spu_gang_add_ctx(gang, ctx);
 54 
 55         __spu_update_sched_info(ctx);
 56         spu_set_timeslice(ctx);
 57         ctx->stats.util_state = SPU_UTIL_IDLE_LOADED;
 58         ctx->stats.tstamp = ktime_get_ns();
 59 
 60         atomic_inc(&nr_spu_contexts);
 61         goto out;
 62 out_free:
 63         kfree(ctx);
 64         ctx = NULL;
 65 out:
 66         return ctx;
 67 }
 68 
 69 void destroy_spu_context(struct kref *kref)
 70 {
 71         struct spu_context *ctx;
 72         ctx = container_of(kref, struct spu_context, kref);
 73         spu_context_nospu_trace(destroy_spu_context__enter, ctx);
 74         mutex_lock(&ctx->state_mutex);
 75         spu_deactivate(ctx);
 76         mutex_unlock(&ctx->state_mutex);
 77         spu_fini_csa(&ctx->csa);
 78         if (ctx->gang)
 79                 spu_gang_remove_ctx(ctx->gang, ctx);
 80         if (ctx->prof_priv_kref)
 81                 kref_put(ctx->prof_priv_kref, ctx->prof_priv_release);
 82         BUG_ON(!list_empty(&ctx->rq));
 83         atomic_dec(&nr_spu_contexts);
 84         kfree(ctx->switch_log);
 85         kfree(ctx);
 86 }
 87 
 88 struct spu_context * get_spu_context(struct spu_context *ctx)
 89 {
 90         kref_get(&ctx->kref);
 91         return ctx;
 92 }
 93 
 94 int put_spu_context(struct spu_context *ctx)
 95 {
 96         return kref_put(&ctx->kref, &destroy_spu_context);
 97 }
 98 
 99 /* give up the mm reference when the context is about to be destroyed */
100 void spu_forget(struct spu_context *ctx)
101 {
102         struct mm_struct *mm;
103 
104         /*
105          * This is basically an open-coded spu_acquire_saved, except that
106          * we don't acquire the state mutex interruptible, and we don't
107          * want this context to be rescheduled on release.
108          */
109         mutex_lock(&ctx->state_mutex);
110         if (ctx->state != SPU_STATE_SAVED)
111                 spu_deactivate(ctx);
112 
113         mm = ctx->owner;
114         ctx->owner = NULL;
115         mmput(mm);
116         spu_release(ctx);
117 }
118 
119 void spu_unmap_mappings(struct spu_context *ctx)
120 {
121         mutex_lock(&ctx->mapping_lock);
122         if (ctx->local_store)
123                 unmap_mapping_range(ctx->local_store, 0, LS_SIZE, 1);
124         if (ctx->mfc)
125                 unmap_mapping_range(ctx->mfc, 0, SPUFS_MFC_MAP_SIZE, 1);
126         if (ctx->cntl)
127                 unmap_mapping_range(ctx->cntl, 0, SPUFS_CNTL_MAP_SIZE, 1);
128         if (ctx->signal1)
129                 unmap_mapping_range(ctx->signal1, 0, SPUFS_SIGNAL_MAP_SIZE, 1);
130         if (ctx->signal2)
131                 unmap_mapping_range(ctx->signal2, 0, SPUFS_SIGNAL_MAP_SIZE, 1);
132         if (ctx->mss)
133                 unmap_mapping_range(ctx->mss, 0, SPUFS_MSS_MAP_SIZE, 1);
134         if (ctx->psmap)
135                 unmap_mapping_range(ctx->psmap, 0, SPUFS_PS_MAP_SIZE, 1);
136         mutex_unlock(&ctx->mapping_lock);
137 }
138 
139 /**
140  * spu_acquire_saved - lock spu contex and make sure it is in saved state
141  * @ctx:        spu contex to lock
142  */
143 int spu_acquire_saved(struct spu_context *ctx)
144 {
145         int ret;
146 
147         spu_context_nospu_trace(spu_acquire_saved__enter, ctx);
148 
149         ret = spu_acquire(ctx);
150         if (ret)
151                 return ret;
152 
153         if (ctx->state != SPU_STATE_SAVED) {
154                 set_bit(SPU_SCHED_WAS_ACTIVE, &ctx->sched_flags);
155                 spu_deactivate(ctx);
156         }
157 
158         return 0;
159 }
160 
161 /**
162  * spu_release_saved - unlock spu context and return it to the runqueue
163  * @ctx:        context to unlock
164  */
165 void spu_release_saved(struct spu_context *ctx)
166 {
167         BUG_ON(ctx->state != SPU_STATE_SAVED);
168 
169         if (test_and_clear_bit(SPU_SCHED_WAS_ACTIVE, &ctx->sched_flags) &&
170                         test_bit(SPU_SCHED_SPU_RUN, &ctx->sched_flags))
171                 spu_activate(ctx, 0);
172 
173         spu_release(ctx);
174 }
175 
176 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php