percpu_ida: add an API to return free tags
authorShaohua Li <shli@kernel.org>
Tue, 15 Oct 2013 01:05:03 +0000 (09:05 +0800)
committerJens Axboe <axboe@kernel.dk>
Fri, 25 Oct 2013 10:56:00 +0000 (11:56 +0100)
Add an API to return free tags, blk-mq-tag will use it.

Note, this just returns a snapshot of free tags number. blk-mq-tag has
two usages of it. One is for info output for diagnosis. The other is to
quickly check if there are free tags for request dispatch checking.
Neither requires very precise.

Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Shaohua Li <shli@fusionio.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/linux/percpu_ida.h
lib/percpu_ida.c

index 63510ae6f93388b024b9991bf7a63fcf8d087313..1900bd0fa639ae7a3c72d1c97a4f0758337c1560 100644 (file)
@@ -77,4 +77,5 @@ typedef int (*percpu_ida_cb)(unsigned, void *);
 int percpu_ida_for_each_free(struct percpu_ida *pool, percpu_ida_cb fn,
        void *data);
 
+unsigned percpu_ida_free_tags(struct percpu_ida *pool, int cpu);
 #endif /* __PERCPU_IDA_H__ */
index 0f51c1b556cf2fbd9758fd0e0a28ac9ccfee6a40..b0698ea972c65025976e87d6e1a5bb5beac92747 100644 (file)
@@ -371,3 +371,20 @@ out:
        return err;
 }
 EXPORT_SYMBOL_GPL(percpu_ida_for_each_free);
+
+/**
+ * percpu_ida_free_tags - return free tags number of a specific cpu or global pool
+ * @pool: pool related
+ * @cpu: specific cpu or global pool if @cpu == nr_cpu_ids
+ *
+ * Note: this just returns a snapshot of free tags number.
+ */
+unsigned percpu_ida_free_tags(struct percpu_ida *pool, int cpu)
+{
+       struct percpu_ida_cpu *remote;
+       if (cpu == nr_cpu_ids)
+               return pool->nr_free;
+       remote = per_cpu_ptr(pool->tag_cpu, cpu);
+       return remote->nr_free;
+}
+EXPORT_SYMBOL_GPL(percpu_ida_free_tags);
This page took 0.026271 seconds and 5 git commands to generate.