Kill redundant bdc->done_cmds
authorJens Axboe <jaxboe@fusionio.com>
Fri, 8 Oct 2010 18:17:33 +0000 (20:17 +0200)
committerJens Axboe <jaxboe@fusionio.com>
Fri, 8 Oct 2010 18:17:33 +0000 (20:17 +0200)
We only care about whether there are done commands or not,
not how many.

Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
main.c

diff --git a/main.c b/main.c
index 3d9144c6b87d34483c6c33559f01a6d5d9919e88..7261999e44af59b42c6651c3da1e729dc0b549a7 100644 (file)
--- a/main.c
+++ b/main.c
@@ -31,7 +31,6 @@ static int b_major;
 struct b_dev_cpu {
        spinlock_t lock;
        struct list_head done_list;
-       unsigned int done_cmds;
 };
 
 struct b_dev {
@@ -199,7 +198,6 @@ ret_one:
                spin_lock_irq(&bdc->lock);
                if (!list_empty(&bdc->done_list)) {
                        list_splice_init(&bdc->done_list, &bd->reaped_done);
-                       bdc->done_cmds = 0;
                        spliced++;
                }
                spin_unlock_irq(&bdc->lock);
@@ -212,20 +210,18 @@ ret_one:
        return NULL;
 }
 
-static int bd_done_count(struct b_dev *bd)
+static int bd_pending_done(struct b_dev *bd)
 {
-       int cpu, done;
+       int cpu;
 
-       done = 0;
        for_each_possible_cpu(cpu) {
                struct b_dev_cpu *bdc = per_cpu_ptr(bd->cpu_queue, cpu);
 
-               spin_lock_irq(&bdc->lock);
-               done += bdc->done_cmds;
-               spin_unlock_irq(&bdc->lock);
+               if (!list_empty_careful(&bdc->done_list))
+                       return 1;
        }
 
-       return done;
+       return 0;
 }
 
 static struct b_cmd *get_done_command(struct b_dev *bd, int block)
@@ -241,7 +237,7 @@ static struct b_cmd *get_done_command(struct b_dev *bd, int block)
                if (!block)
                        break;
 
-               ret = wait_event_interruptible(bd->wq_done, bd_done_count(bd));
+               ret = wait_event_interruptible(bd->wq_done, bd_pending_done(bd));
                if (ret) {
                        bc = ERR_PTR(-ERESTARTSYS);
                        break;
@@ -326,7 +322,6 @@ static void b_cmd_endio(struct bio *bio, int error)
 
        spin_lock(&bdc->lock);
        list_add_tail(&bc->list, &bdc->done_list);
-       bdc->done_cmds++;
        spin_unlock_irqrestore(&bdc->lock, flags);
 
        atomic_dec(&bd->in_flight);
@@ -474,18 +469,11 @@ static unsigned int b_dev_poll(struct file *file, poll_table *wait)
 {
        struct b_dev *bd = file->private_data;
        unsigned int mask = POLLOUT;
-       int cpu;
 
        poll_wait(file, &bd->wq_done, wait);
 
-       for_each_possible_cpu(cpu) {
-               struct b_dev_cpu *bdc = per_cpu_ptr(bd->cpu_queue, cpu);
-
-               if (!list_empty_careful(&bdc->done_list)) {
-                       mask |= POLLIN | POLLRDNORM;
-                       break;
-               }
-       }
+       if (bd_pending_done(bd))
+               mask |= POLLIN | POLLRDNORM;
 
        return mask;
 }
@@ -690,7 +678,6 @@ static int b_add_dev(struct b_ioctl_cmd *bic)
 
                bdc = per_cpu_ptr(bd->cpu_queue, cpu);
                INIT_LIST_HEAD(&bdc->done_list);
-               bdc->done_cmds = 0;
                spin_lock_init(&bdc->lock);
        }