[Cbe-oss-dev] [RFC/PATCH 2/2] spufs: Add a "capabilities" file to spu contexts

Christoph Hellwig hch at lst.de
Fri Jun 1 05:36:41 EST 2007


On Thu, May 31, 2007 at 09:35:15PM +0200, Christoph Hellwig wrote:
> On Fri, May 25, 2007 at 02:54:05PM +1000, Benjamin Herrenschmidt wrote:
> > This adds a "capabilities" file to spu contexts consisting of a
> > list of space separated capability names. The current exposed
> > capabilities are "sched" (the context is scheduleable) and
> > "step" (the context supports single stepping).
> 
> I don't like the handcrafted buffer printing.  The patch below does
> a seq_file version instead.  This has one notable difference in the
> output because it always prints an whitespace before the newline
> at the end to keep the code simpler.  This should be perfectly fine
> for any reasonable parser.

Attaching the patch might be appreciated, so here it is:


Index: linux-cell/arch/powerpc/platforms/cell/spufs/file.c
===================================================================
--- linux-cell.orig/arch/powerpc/platforms/cell/spufs/file.c	2007-05-31 21:12:29.000000000 +0200
+++ linux-cell/arch/powerpc/platforms/cell/spufs/file.c	2007-05-31 21:17:29.000000000 +0200
@@ -1799,33 +1799,29 @@ static int spufs_info_open(struct inode 
 	return 0;
 }
 
-#define CAPS_BUF_LEN		64
-#define ADD_ONE_CAP(name)	\
-  do { p += snprintf(p, CAPS_BUF_LEN - 3 - (p - buffer), "%s ", #name); \
-     } while(0)
-
-static ssize_t spufs_caps_read(struct file *file, char __user *buf,
-			       size_t len, loff_t *pos)
+static int spufs_caps_show(struct seq_file *s, void *private)
 {
-	struct spu_context *ctx = file->private_data;
-	char buffer[CAPS_BUF_LEN];
-	char *p = buffer;
+	struct spu_context *ctx = s->private;
 
 	if (!(ctx->flags & SPU_CREATE_NOSCHED))
-		ADD_ONE_CAP(sched);
+		seq_puts(s, "sched ");
 	if (!(ctx->flags & SPU_CREATE_ISOLATE))
-		ADD_ONE_CAP(step);
+		seq_puts(s, "step ");
 
-	/* remove last space and add newline */
-	if (p != buffer)
-		p--;
-	*(p++) = '\n';
-	return simple_read_from_buffer(buf, len, pos, buffer, p - buffer);
+	seq_puts(s, "\n");
+	return 0;
+}
+
+static int spufs_caps_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, spufs_caps_show, SPUFS_I(inode)->i_ctx);
 }
 
 static const struct file_operations spufs_caps_fops = {
-	.open = spufs_info_open,
-	.read = spufs_caps_read,
+	.open		= spufs_caps_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= single_release,
 };
 
 static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,



More information about the cbe-oss-dev mailing list