Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8e68e2f2 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Arnd Bergmann
Browse files

[CELL] spufs: extension of spu_create to support affinity definition



This patch adds support for additional flags at spu_create, which relate
to the establishment of affinity between contexts and contexts to memory.
A fourth, optional, parameter is supported. This parameter represent
a affinity neighbor of the context being created, and is used when defining
SPU-SPU affinity.
Affinity is represented as a doubly linked list of spu_contexts.

Signed-off-by: default avatarAndre Detsch <adetsch@br.ibm.com>
Signed-off-by: default avatarArnd Bergmann <arnd.bergmann@de.ibm.com>
parent 3ad216ca
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -34,14 +34,27 @@ struct spufs_calls spufs_calls = {
 * this file is not used and the syscalls directly enter the fs code */

asmlinkage long sys_spu_create(const char __user *name,
		unsigned int flags, mode_t mode)
		unsigned int flags, mode_t mode, int neighbor_fd)
{
	long ret;
	struct module *owner = spufs_calls.owner;
	struct file *neighbor;
	int fput_needed;

	ret = -ENOSYS;
	if (owner && try_module_get(owner)) {
		ret = spufs_calls.create_thread(name, flags, mode);
		if (flags & SPU_CREATE_AFFINITY_SPU) {
			neighbor = fget_light(neighbor_fd, &fput_needed);
			if (neighbor) {
				ret = spufs_calls.create_thread(name, flags,
								mode, neighbor);
				fput_light(neighbor, fput_needed);
			}
		}
		else {
			ret = spufs_calls.create_thread(name, flags,
							mode, NULL);
		}
		module_put(owner);
	}
	return ret;
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ struct spu_context *alloc_spu_context(struct spu_gang *gang)
	ctx->ops = &spu_backing_ops;
	ctx->owner = get_task_mm(current);
	INIT_LIST_HEAD(&ctx->rq);
	INIT_LIST_HEAD(&ctx->aff_list);
	if (gang)
		spu_gang_add_ctx(gang, ctx);
	ctx->cpus_allowed = current->cpus_allowed;
+4 −0
Original line number Diff line number Diff line
@@ -35,7 +35,9 @@ struct spu_gang *alloc_spu_gang(void)

	kref_init(&gang->kref);
	mutex_init(&gang->mutex);
	mutex_init(&gang->aff_mutex);
	INIT_LIST_HEAD(&gang->list);
	INIT_LIST_HEAD(&gang->aff_list_head);

out:
	return gang;
@@ -73,6 +75,8 @@ void spu_gang_remove_ctx(struct spu_gang *gang, struct spu_context *ctx)
{
	mutex_lock(&gang->mutex);
	WARN_ON(ctx->gang != gang);
	if (!list_empty(&ctx->aff_list))
		list_del_init(&ctx->aff_list);
	list_del_init(&ctx->gang_list);
	gang->contexts--;
	mutex_unlock(&gang->mutex);
+126 −6
Original line number Diff line number Diff line
@@ -316,11 +316,107 @@ static int spufs_context_open(struct dentry *dentry, struct vfsmount *mnt)
	return ret;
}

static int spufs_create_context(struct inode *inode,
			struct dentry *dentry,
			struct vfsmount *mnt, int flags, int mode)
static struct spu_context *
spufs_assert_affinity(unsigned int flags, struct spu_gang *gang,
						struct file *filp)
{
	struct spu_context *tmp, *neighbor;
	int count, node;
	int aff_supp;

	aff_supp = !list_empty(&(list_entry(cbe_spu_info[0].spus.next,
					struct spu, cbe_list))->aff_list);

	if (!aff_supp)
		return ERR_PTR(-EINVAL);

	if (flags & SPU_CREATE_GANG)
		return ERR_PTR(-EINVAL);

	if (flags & SPU_CREATE_AFFINITY_MEM &&
	    gang->aff_ref_ctx &&
	    gang->aff_ref_ctx->flags & SPU_CREATE_AFFINITY_MEM)
		return ERR_PTR(-EEXIST);

	if (gang->aff_flags & AFF_MERGED)
		return ERR_PTR(-EBUSY);

	neighbor = NULL;
	if (flags & SPU_CREATE_AFFINITY_SPU) {
		if (!filp || filp->f_op != &spufs_context_fops)
			return ERR_PTR(-EINVAL);

		neighbor = get_spu_context(
				SPUFS_I(filp->f_dentry->d_inode)->i_ctx);

		if (!list_empty(&neighbor->aff_list) && !(neighbor->aff_head) &&
		    !list_is_last(&neighbor->aff_list, &gang->aff_list_head) &&
		    !list_entry(neighbor->aff_list.next, struct spu_context,
		    aff_list)->aff_head)
			return ERR_PTR(-EEXIST);

		if (gang != neighbor->gang)
			return ERR_PTR(-EINVAL);

		count = 1;
		list_for_each_entry(tmp, &gang->aff_list_head, aff_list)
			count++;
		if (list_empty(&neighbor->aff_list))
			count++;

		for (node = 0; node < MAX_NUMNODES; node++) {
			if ((cbe_spu_info[node].n_spus - atomic_read(
				&cbe_spu_info[node].reserved_spus)) >= count)
				break;
		}

		if (node == MAX_NUMNODES)
			return ERR_PTR(-EEXIST);
	}

	return neighbor;
}

static void
spufs_set_affinity(unsigned int flags, struct spu_context *ctx,
					struct spu_context *neighbor)
{
	if (flags & SPU_CREATE_AFFINITY_MEM)
		ctx->gang->aff_ref_ctx = ctx;

	if (flags & SPU_CREATE_AFFINITY_SPU) {
		if (list_empty(&neighbor->aff_list)) {
			list_add_tail(&neighbor->aff_list,
				&ctx->gang->aff_list_head);
			neighbor->aff_head = 1;
		}

		if (list_is_last(&neighbor->aff_list, &ctx->gang->aff_list_head)
		    || list_entry(neighbor->aff_list.next, struct spu_context,
							aff_list)->aff_head) {
			list_add(&ctx->aff_list, &neighbor->aff_list);
		} else  {
			list_add_tail(&ctx->aff_list, &neighbor->aff_list);
			if (neighbor->aff_head) {
				neighbor->aff_head = 0;
				ctx->aff_head = 1;
			}
		}

		if (!ctx->gang->aff_ref_ctx)
			ctx->gang->aff_ref_ctx = ctx;
	}
}

static int
spufs_create_context(struct inode *inode, struct dentry *dentry,
			struct vfsmount *mnt, int flags, int mode,
			struct file *aff_filp)
{
	int ret;
	int affinity;
	struct spu_gang *gang;
	struct spu_context *neighbor;

	ret = -EPERM;
	if ((flags & SPU_CREATE_NOSCHED) &&
@@ -336,9 +432,29 @@ static int spufs_create_context(struct inode *inode,
	if ((flags & SPU_CREATE_ISOLATE) && !isolated_loader)
		goto out_unlock;

	gang = NULL;
	neighbor = NULL;
	affinity = flags & (SPU_CREATE_AFFINITY_MEM | SPU_CREATE_AFFINITY_SPU);
	if (affinity) {
		gang = SPUFS_I(inode)->i_gang;
		ret = -EINVAL;
		if (!gang)
			goto out_unlock;
		mutex_lock(&gang->aff_mutex);
		neighbor = spufs_assert_affinity(flags, gang, aff_filp);
		if (IS_ERR(neighbor)) {
			ret = PTR_ERR(neighbor);
			goto out_aff_unlock;
		}
	}

	ret = spufs_mkdir(inode, dentry, flags, mode & S_IRWXUGO);
	if (ret)
		goto out_unlock;
		goto out_aff_unlock;

	if (affinity)
		spufs_set_affinity(flags, SPUFS_I(dentry->d_inode)->i_ctx,
								neighbor);

	/*
	 * get references for dget and mntget, will be released
@@ -352,6 +468,9 @@ static int spufs_create_context(struct inode *inode,
		goto out;
	}

out_aff_unlock:
	if (affinity)
		mutex_unlock(&gang->aff_mutex);
out_unlock:
	mutex_unlock(&inode->i_mutex);
out:
@@ -450,7 +569,8 @@ static int spufs_create_gang(struct inode *inode,

static struct file_system_type spufs_type;

long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode)
long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode,
							struct file *filp)
{
	struct dentry *dentry;
	int ret;
@@ -487,7 +607,7 @@ long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode)
					dentry, nd->mnt, mode);
	else
		return spufs_create_context(nd->dentry->d_inode,
					dentry, nd->mnt, flags, mode);
					dentry, nd->mnt, flags, mode, filp);

out_dput:
	dput(dentry);
+14 −2
Original line number Diff line number Diff line
@@ -109,6 +109,9 @@ struct spu_context {
		unsigned long long class2_intr_base; /* # at last ctx switch */
		unsigned long long libassist;
	} stats;

	struct list_head aff_list;
	int aff_head;
};

struct spu_gang {
@@ -116,8 +119,17 @@ struct spu_gang {
	struct mutex mutex;
	struct kref kref;
	int contexts;

	struct spu_context *aff_ref_ctx;
	struct list_head aff_list_head;
	struct mutex aff_mutex;
	int aff_flags;
};

/* Flag bits for spu_gang aff_flags */
#define AFF_OFFSETS_SET		1
#define AFF_MERGED		2

struct mfc_dma_command {
	int32_t pad;	/* reserved */
	uint32_t lsa;	/* local storage address */
@@ -182,8 +194,8 @@ extern struct tree_descr spufs_dir_nosched_contents[];

/* system call implementation */
long spufs_run_spu(struct spu_context *ctx, u32 *npc, u32 *status);
long spufs_create(struct nameidata *nd,
			 unsigned int flags, mode_t mode);
long spufs_create(struct nameidata *nd, unsigned int flags,
			mode_t mode, struct file *filp);
extern const struct file_operations spufs_context_fops;

/* gang management */
Loading