A couple of improvements for sputrace: - If the trace is full, print the warning out of the critical region so that we give higher chances to user space to free space from it. - Instead of clearing the trace completely when it fills, attempt to append stuff to it even if intermediate events are lost. This way, we might lose events from time to time, but not whole chunks of them. Signed-off-by: Julio M. Merino Vidal Index: linux-2.6.25.y/arch/powerpc/platforms/cell/spufs/sputrace.c =================================================================== --- linux-2.6.25.y.orig/arch/powerpc/platforms/cell/spufs/sputrace.c +++ linux-2.6.25.y/arch/powerpc/platforms/cell/spufs/sputrace.c @@ -48,7 +48,7 @@ static int sputrace_used(void) static inline int sputrace_avail(void) { - return bufsize - sputrace_used(); + return bufsize - sputrace_used() - 1; } static int sputrace_sprint(char *tbuf, int n) @@ -126,8 +126,11 @@ static const struct file_operations sput static void sputrace_log_item(const char *name, struct spu_context *ctx, struct spu *spu) { + int full; + spin_lock(&sputrace_lock); - if (sputrace_avail() > 1) { + full = (sputrace_avail() == 0); + if (!full) { struct sputrace *t = sputrace_log + sputrace_head; t->tstamp = ktime_get(); @@ -137,11 +140,13 @@ static void sputrace_log_item(const char t->number = spu ? spu->number : -1; sputrace_head = (sputrace_head + 1) % bufsize; - } else { + } + spin_unlock(&sputrace_lock); + + if (full) { printk(KERN_WARNING "sputrace: lost samples due to full buffer.\n"); } - spin_unlock(&sputrace_lock); wake_up(&sputrace_wait); } @@ -212,6 +217,9 @@ static int __init sputrace_init(void) struct proc_dir_entry *entry; int i, error = -ENOMEM; + if (bufsize == 0) + bufsize = 1; + sputrace_log = kcalloc(sizeof(struct sputrace), bufsize, GFP_KERNEL); if (!sputrace_log) -- Julio M. Merino Vidal