Subject: cell: add per BE structure with info about its SPUs From: Andre Detsch Addition of a spufs-global "be_info" array. Each entry contains information about one BE node, namelly: * list of spus (both free and busy spus are in this list); * list of free spus (replacing the static spu_list from spu_base.c) * number of spus; * number of reserved (non scheduleable) spus. SPE affinity implementation actually requires only access to one spu per BE node (since it implements its own pointer to walk through the other spus of the ring) and the number of scheduleable spus (n_spus - non_sched_spus) However having this more general structure can be useful for other functionalities, concentrating per-be statistics / data. Signed-off-by: Andre Detsch Signed-off-by: Arnd Bergmann --- Index: linux-2.6/arch/powerpc/platforms/cell/spu_base.c =================================================================== --- linux-2.6.orig/arch/powerpc/platforms/cell/spu_base.c +++ linux-2.6/arch/powerpc/platforms/cell/spu_base.c @@ -327,7 +327,6 @@ static void spu_free_irqs(struct spu *sp free_irq(spu->irqs[2], spu); } -static struct list_head spu_list[MAX_NUMNODES]; static LIST_HEAD(spu_full_list); static DEFINE_MUTEX(spu_mutex); @@ -370,8 +369,9 @@ struct spu *spu_alloc_node(int node) struct spu *spu = NULL; mutex_lock(&spu_mutex); - if (!list_empty(&spu_list[node])) { - spu = list_entry(spu_list[node].next, struct spu, list); + if (!list_empty(&be_spu_info[node].free_spus)) { + spu = list_entry(be_spu_info[node].free_spus.next, struct spu, + list); list_del_init(&spu->list); pr_debug("Got SPU %d %d\n", spu->number, spu->node); spu_init_channels(spu); @@ -399,7 +399,7 @@ struct spu *spu_alloc(void) void spu_free(struct spu *spu) { mutex_lock(&spu_mutex); - list_add_tail(&spu->list, &spu_list[spu->node]); + list_add_tail(&spu->list, &be_spu_info[spu->node].free_spus); mutex_unlock(&spu_mutex); } EXPORT_SYMBOL_GPL(spu_free); @@ -617,7 +617,9 @@ static int __init create_spu(void *data) goto out_free_irqs; mutex_lock(&spu_mutex); - list_add(&spu->list, &spu_list[spu->node]); + list_add(&spu->list, &be_spu_info[spu->node].free_spus); + list_add(&spu->be_list, &be_spu_info[spu->node].spus); + be_spu_info[spu->node].n_spus++; list_add(&spu->full_list, &spu_full_list); mutex_unlock(&spu_mutex); @@ -636,6 +638,7 @@ out: static void destroy_spu(struct spu *spu) { list_del_init(&spu->list); + list_del_init(&spu->be_list); list_del_init(&spu->full_list); spu_destroy_sysdev(spu); @@ -651,7 +654,8 @@ static void cleanup_spu_base(void) mutex_lock(&spu_mutex); for (node = 0; node < MAX_NUMNODES; node++) { - list_for_each_entry_safe(spu, tmp, &spu_list[node], list) + list_for_each_entry_safe(spu, tmp, &be_spu_info[node].free_spus, + list) destroy_spu(spu); } mutex_unlock(&spu_mutex); @@ -659,6 +663,9 @@ static void cleanup_spu_base(void) } module_exit(cleanup_spu_base); +struct be_spu_info be_spu_info[MAX_NUMNODES]; +EXPORT_SYMBOL_GPL(be_spu_info); + static int __init init_spu_base(void) { int i, ret; @@ -671,11 +678,12 @@ static int __init init_spu_base(void) if (ret) return ret; - for (i = 0; i < MAX_NUMNODES; i++) - INIT_LIST_HEAD(&spu_list[i]); + for (i = 0; i < MAX_NUMNODES; i++) { + INIT_LIST_HEAD(&be_spu_info[i].spus); + INIT_LIST_HEAD(&be_spu_info[i].free_spus); + } ret = spu_enumerate_spus(create_spu); - if (ret) { printk(KERN_WARNING "%s: Error initializing spus\n", __FUNCTION__); Index: linux-2.6/include/asm-powerpc/spu.h =================================================================== --- linux-2.6.orig/include/asm-powerpc/spu.h +++ linux-2.6/include/asm-powerpc/spu.h @@ -113,6 +113,7 @@ struct spu { struct spu_problem __iomem *problem; struct spu_priv2 __iomem *priv2; struct list_head list; + struct list_head be_list; struct list_head sched_list; struct list_head full_list; int number; @@ -145,6 +146,15 @@ struct spu { struct sys_device sysdev; }; +struct be_spu_info { + struct list_head spus; + struct list_head free_spus; + int n_spus; + atomic_t reserved_spus; +}; + +extern struct be_spu_info be_spu_info[]; + struct spu *spu_alloc(void); struct spu *spu_alloc_node(int node); void spu_free(struct spu *spu); Index: linux-2.6/arch/powerpc/platforms/cell/spufs/sched.c =================================================================== --- linux-2.6.orig/arch/powerpc/platforms/cell/spufs/sched.c +++ linux-2.6/arch/powerpc/platforms/cell/spufs/sched.c @@ -162,6 +162,8 @@ static void spu_bind_context(struct spu { pr_debug("%s: pid=%d SPU=%d NODE=%d\n", __FUNCTION__, current->pid, spu->number, spu->node); + if (ctx->flags & SPU_CREATE_NOSCHED) + atomic_inc(&be_spu_info[spu->node].reserved_spus); spu->ctx = ctx; spu->flags = 0; ctx->spu = spu; @@ -194,6 +196,8 @@ static void spu_unbind_context(struct sp pr_debug("%s: unbind pid=%d SPU=%d NODE=%d\n", __FUNCTION__, spu->pid, spu->number, spu->node); + if (spu->ctx->flags & SPU_CREATE_NOSCHED) + atomic_dec(&be_spu_info[spu->node].reserved_spus); spu_remove_from_active_list(spu); spu_switch_notify(spu, NULL); spu_unmap_mappings(ctx);