diff options
author | Arnd Bergmann <arnd@arndb.de> | 2006-10-04 11:26:15 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2006-10-04 19:21:01 -0400 |
commit | 6263203ed6e9ff107129a1ebe613290b342a4465 (patch) | |
tree | dc7d68b783fed2b5ffcb8905c62086ebe078368b /arch/powerpc/platforms/cell/spufs/gang.c | |
parent | 9add11daeee2f6d69f6b86237f197824332a4a3b (diff) |
[POWERPC] spufs: Add infrastructure needed for gang scheduling
Add the concept of a gang to spufs as a new type of object.
So far, this has no impact whatsover on scheduling, but makes
it possible to add that later.
A new type of object in spufs is now a spu_gang. It is created
with the spu_create system call with the flags argument set
to SPU_CREATE_GANG (0x2). Inside of a spu_gang, it
is then possible to create spu_context objects, which until
now was only possible at the root of spufs.
There is a new member in struct spu_context pointing to
the spu_gang it belongs to, if any. The spu_gang maintains
a list of spu_context structures that are its children.
This information can then be used in the scheduler in the
future.
There is still a bug that needs to be resolved in this
basic infrastructure regarding the order in which objects
are removed. When the spu_gang file descriptor is closed
before the spu_context descriptors, we leak the dentry
and inode for the gang. Any ideas how to cleanly solve
this are appreciated.
Signed-off-by: Arnd Bergmann <arnd.bergmann@de.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/platforms/cell/spufs/gang.c')
-rw-r--r-- | arch/powerpc/platforms/cell/spufs/gang.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/arch/powerpc/platforms/cell/spufs/gang.c b/arch/powerpc/platforms/cell/spufs/gang.c new file mode 100644 index 000000000000..212ea78f9051 --- /dev/null +++ b/arch/powerpc/platforms/cell/spufs/gang.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /* | ||
2 | * SPU file system | ||
3 | * | ||
4 | * (C) Copyright IBM Deutschland Entwicklung GmbH 2005 | ||
5 | * | ||
6 | * Author: Arnd Bergmann <arndb@de.ibm.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2, or (at your option) | ||
11 | * any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | */ | ||
22 | |||
23 | #include <linux/list.h> | ||
24 | #include <linux/slab.h> | ||
25 | |||
26 | #include "spufs.h" | ||
27 | |||
28 | struct spu_gang *alloc_spu_gang(void) | ||
29 | { | ||
30 | struct spu_gang *gang; | ||
31 | |||
32 | gang = kzalloc(sizeof *gang, GFP_KERNEL); | ||
33 | if (!gang) | ||
34 | goto out; | ||
35 | |||
36 | kref_init(&gang->kref); | ||
37 | mutex_init(&gang->mutex); | ||
38 | INIT_LIST_HEAD(&gang->list); | ||
39 | |||
40 | out: | ||
41 | return gang; | ||
42 | } | ||
43 | |||
44 | static void destroy_spu_gang(struct kref *kref) | ||
45 | { | ||
46 | struct spu_gang *gang; | ||
47 | gang = container_of(kref, struct spu_gang, kref); | ||
48 | WARN_ON(gang->contexts || !list_empty(&gang->list)); | ||
49 | kfree(gang); | ||
50 | } | ||
51 | |||
52 | struct spu_gang *get_spu_gang(struct spu_gang *gang) | ||
53 | { | ||
54 | kref_get(&gang->kref); | ||
55 | return gang; | ||
56 | } | ||
57 | |||
58 | int put_spu_gang(struct spu_gang *gang) | ||
59 | { | ||
60 | return kref_put(&gang->kref, &destroy_spu_gang); | ||
61 | } | ||
62 | |||
63 | void spu_gang_add_ctx(struct spu_gang *gang, struct spu_context *ctx) | ||
64 | { | ||
65 | mutex_lock(&gang->mutex); | ||
66 | ctx->gang = get_spu_gang(gang); | ||
67 | list_add(&ctx->gang_list, &gang->list); | ||
68 | gang->contexts++; | ||
69 | mutex_unlock(&gang->mutex); | ||
70 | } | ||
71 | |||
72 | void spu_gang_remove_ctx(struct spu_gang *gang, struct spu_context *ctx) | ||
73 | { | ||
74 | mutex_lock(&gang->mutex); | ||
75 | WARN_ON(ctx->gang != gang); | ||
76 | list_del_init(&ctx->gang_list); | ||
77 | gang->contexts--; | ||
78 | mutex_unlock(&gang->mutex); | ||
79 | |||
80 | put_spu_gang(gang); | ||
81 | } | ||