]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
powerpc/spufs: Don't require full buffer in switch_log read
authorJeremy Kerr <jk@ozlabs.org>
Wed, 15 Oct 2008 23:51:46 +0000 (10:51 +1100)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 21 Oct 2008 00:13:30 +0000 (11:13 +1100)
Currently, read() on the sputrace log will block until the read buffer
is full. This makes it difficult to retrieve the end of the buffer, as
the user will need to read with the right-sized buffer.

In a similar method as 91553a1b5e0df006a3573a88d98ee7cd48a3818a, this
change makes the switch_log return if there has already been data
read.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
arch/powerpc/platforms/cell/spufs/file.c

index adb5abb9af5d71f0cb7cc6eeb319f400ec9a0eb4..f139cd8b594db6accac1757788feb5c9892d65d6 100644 (file)
@@ -2503,30 +2503,38 @@ static ssize_t spufs_switch_log_read(struct file *file, char __user *buf,
                char tbuf[128];
                int width;
 
-               if (file->f_flags & O_NONBLOCK) {
-                       if (spufs_switch_log_used(ctx) == 0) {
+               if (spufs_switch_log_used(ctx) == 0) {
+                       if (cnt > 0) {
+                               /* If there's data ready to go, we can
+                                * just return straight away */
+                               break;
+
+                       } else if (file->f_flags & O_NONBLOCK) {
                                error = -EAGAIN;
                                break;
+
+                       } else {
+                               /* spufs_wait will drop the mutex and
+                                * re-acquire, but since we're in read(), the
+                                * file cannot be _released (and so
+                                * ctx->switch_log is stable).
+                                */
+                               error = spufs_wait(ctx->switch_log->wait,
+                                               spufs_switch_log_used(ctx) > 0);
+
+                               /* On error, spufs_wait returns without the
+                                * state mutex held */
+                               if (error)
+                                       return error;
+
+                               /* We may have had entries read from underneath
+                                * us while we dropped the mutex in spufs_wait,
+                                * so re-check */
+                               if (spufs_switch_log_used(ctx) == 0)
+                                       continue;
                        }
-               } else {
-                       /* spufs_wait will drop the mutex and re-acquire,
-                        * but since we're in read(), the file cannot be
-                        * _released (and so ctx->switch_log is stable).
-                        */
-                       error = spufs_wait(ctx->switch_log->wait,
-                                       spufs_switch_log_used(ctx) > 0);
-
-                       /* On error, spufs_wait returns without the
-                        * state mutex held */
-                       if (error)
-                               return error;
                }
 
-               /* We may have had entries read from underneath us while we
-                * dropped the mutex in spufs_wait, so re-check */
-               if (ctx->switch_log->head == ctx->switch_log->tail)
-                       continue;
-
                width = switch_log_sprint(ctx, tbuf, sizeof(tbuf));
                if (width < len)
                        ctx->switch_log->tail =