Commit 4a893e83 authored by Jens Axboe's avatar Jens Axboe Committed by Jens Axboe

[PATCH] elevator: define ioc counting mechanism

None of the in-kernel primitives for handling "atomic" counting seem
to be a good fit. We need something that is essentially free for
incrementing/decrementing, while the read side may be more expensive
as we only ever need to do that when a device is removed from the
kernel.

Use a per-cpu variable for maintaining a per-cpu ioc count and define
a reading mechanism that just sums up the values.
Signed-off-by: default avatarJens Axboe <axboe@suse.de>
parent fc46379d
#ifndef _LINUX_ELEVATOR_H #ifndef _LINUX_ELEVATOR_H
#define _LINUX_ELEVATOR_H #define _LINUX_ELEVATOR_H
#include <linux/percpu.h>
typedef int (elevator_merge_fn) (request_queue_t *, struct request **, typedef int (elevator_merge_fn) (request_queue_t *, struct request **,
struct bio *); struct bio *);
...@@ -178,4 +180,27 @@ enum { ...@@ -178,4 +180,27 @@ enum {
INIT_LIST_HEAD(&(rq)->donelist); \ INIT_LIST_HEAD(&(rq)->donelist); \
} while (0) } while (0)
/*
* io context count accounting
*/
#define elv_ioc_count_mod(name, __val) \
do { \
preempt_disable(); \
__get_cpu_var(name) += (__val); \
preempt_enable(); \
} while (0)
#define elv_ioc_count_inc(name) elv_ioc_count_mod(name, 1)
#define elv_ioc_count_dec(name) elv_ioc_count_mod(name, -1)
#define elv_ioc_count_read(name) \
({ \
unsigned long __val = 0; \
int __cpu; \
smp_wmb(); \
for_each_possible_cpu(__cpu) \
__val += per_cpu(name, __cpu); \
__val; \
})
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment