Commit dd67d051 authored by Jens Axboe's avatar Jens Axboe Committed by Jens Axboe

[PATCH] rbtree: support functions used by the io schedulers

They all duplicate macros to check for empty root and/or node, and
clearing a node. So put those in rbtree.h.
Signed-off-by: default avatarJens Axboe <axboe@suse.de>
parent 9e94cd4f
...@@ -347,9 +347,6 @@ static struct request *as_find_arq_hash(struct as_data *ad, sector_t offset) ...@@ -347,9 +347,6 @@ static struct request *as_find_arq_hash(struct as_data *ad, sector_t offset)
/* /*
* rb tree support functions * rb tree support functions
*/ */
#define RB_EMPTY(root) ((root)->rb_node == NULL)
#define ON_RB(node) (rb_parent(node) != node)
#define RB_CLEAR(node) (rb_set_parent(node, node))
#define rb_entry_arq(node) rb_entry((node), struct as_rq, rb_node) #define rb_entry_arq(node) rb_entry((node), struct as_rq, rb_node)
#define ARQ_RB_ROOT(ad, arq) (&(ad)->sort_list[(arq)->is_sync]) #define ARQ_RB_ROOT(ad, arq) (&(ad)->sort_list[(arq)->is_sync])
#define rq_rb_key(rq) (rq)->sector #define rq_rb_key(rq) (rq)->sector
...@@ -418,13 +415,13 @@ static void as_add_arq_rb(struct as_data *ad, struct as_rq *arq) ...@@ -418,13 +415,13 @@ static void as_add_arq_rb(struct as_data *ad, struct as_rq *arq)
static inline void as_del_arq_rb(struct as_data *ad, struct as_rq *arq) static inline void as_del_arq_rb(struct as_data *ad, struct as_rq *arq)
{ {
if (!ON_RB(&arq->rb_node)) { if (!RB_EMPTY_NODE(&arq->rb_node)) {
WARN_ON(1); WARN_ON(1);
return; return;
} }
rb_erase(&arq->rb_node, ARQ_RB_ROOT(ad, arq)); rb_erase(&arq->rb_node, ARQ_RB_ROOT(ad, arq));
RB_CLEAR(&arq->rb_node); RB_CLEAR_NODE(&arq->rb_node);
} }
static struct request * static struct request *
...@@ -545,7 +542,7 @@ static struct as_rq *as_find_next_arq(struct as_data *ad, struct as_rq *last) ...@@ -545,7 +542,7 @@ static struct as_rq *as_find_next_arq(struct as_data *ad, struct as_rq *last)
struct rb_node *rbprev = rb_prev(&last->rb_node); struct rb_node *rbprev = rb_prev(&last->rb_node);
struct as_rq *arq_next, *arq_prev; struct as_rq *arq_next, *arq_prev;
BUG_ON(!ON_RB(&last->rb_node)); BUG_ON(!RB_EMPTY_NODE(&last->rb_node));
if (rbprev) if (rbprev)
arq_prev = rb_entry_arq(rbprev); arq_prev = rb_entry_arq(rbprev);
...@@ -1122,7 +1119,7 @@ static void as_move_to_dispatch(struct as_data *ad, struct as_rq *arq) ...@@ -1122,7 +1119,7 @@ static void as_move_to_dispatch(struct as_data *ad, struct as_rq *arq)
struct request *rq = arq->request; struct request *rq = arq->request;
const int data_dir = arq->is_sync; const int data_dir = arq->is_sync;
BUG_ON(!ON_RB(&arq->rb_node)); BUG_ON(!RB_EMPTY_NODE(&arq->rb_node));
as_antic_stop(ad); as_antic_stop(ad);
ad->antic_status = ANTIC_OFF; ad->antic_status = ANTIC_OFF;
...@@ -1247,7 +1244,7 @@ static int as_dispatch_request(request_queue_t *q, int force) ...@@ -1247,7 +1244,7 @@ static int as_dispatch_request(request_queue_t *q, int force)
*/ */
if (reads) { if (reads) {
BUG_ON(RB_EMPTY(&ad->sort_list[REQ_SYNC])); BUG_ON(RB_EMPTY_ROOT(&ad->sort_list[REQ_SYNC]));
if (writes && ad->batch_data_dir == REQ_SYNC) if (writes && ad->batch_data_dir == REQ_SYNC)
/* /*
...@@ -1271,7 +1268,7 @@ static int as_dispatch_request(request_queue_t *q, int force) ...@@ -1271,7 +1268,7 @@ static int as_dispatch_request(request_queue_t *q, int force)
if (writes) { if (writes) {
dispatch_writes: dispatch_writes:
BUG_ON(RB_EMPTY(&ad->sort_list[REQ_ASYNC])); BUG_ON(RB_EMPTY_ROOT(&ad->sort_list[REQ_ASYNC]));
if (ad->batch_data_dir == REQ_SYNC) { if (ad->batch_data_dir == REQ_SYNC) {
ad->changed_batch = 1; ad->changed_batch = 1;
...@@ -1591,7 +1588,7 @@ static int as_set_request(request_queue_t *q, struct request *rq, ...@@ -1591,7 +1588,7 @@ static int as_set_request(request_queue_t *q, struct request *rq,
if (arq) { if (arq) {
memset(arq, 0, sizeof(*arq)); memset(arq, 0, sizeof(*arq));
RB_CLEAR(&arq->rb_node); RB_CLEAR_NODE(&arq->rb_node);
arq->request = rq; arq->request = rq;
arq->state = AS_RQ_PRESCHED; arq->state = AS_RQ_PRESCHED;
arq->io_context = NULL; arq->io_context = NULL;
......
...@@ -60,11 +60,6 @@ static DEFINE_SPINLOCK(cfq_exit_lock); ...@@ -60,11 +60,6 @@ static DEFINE_SPINLOCK(cfq_exit_lock);
/* /*
* rb-tree defines * rb-tree defines
*/ */
#define RB_EMPTY(node) ((node)->rb_node == NULL)
#define RB_CLEAR(node) do { \
memset(node, 0, sizeof(*node)); \
} while (0)
#define RB_CLEAR_ROOT(root) ((root)->rb_node = NULL)
#define rb_entry_crq(node) rb_entry((node), struct cfq_rq, rb_node) #define rb_entry_crq(node) rb_entry((node), struct cfq_rq, rb_node)
#define rq_rb_key(rq) (rq)->sector #define rq_rb_key(rq) (rq)->sector
...@@ -559,7 +554,7 @@ static inline void cfq_del_crq_rb(struct cfq_rq *crq) ...@@ -559,7 +554,7 @@ static inline void cfq_del_crq_rb(struct cfq_rq *crq)
rb_erase(&crq->rb_node, &cfqq->sort_list); rb_erase(&crq->rb_node, &cfqq->sort_list);
if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY(&cfqq->sort_list)) if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY_ROOT(&cfqq->sort_list))
cfq_del_cfqq_rr(cfqd, cfqq); cfq_del_cfqq_rr(cfqd, cfqq);
} }
...@@ -914,7 +909,7 @@ static int cfq_arm_slice_timer(struct cfq_data *cfqd, struct cfq_queue *cfqq) ...@@ -914,7 +909,7 @@ static int cfq_arm_slice_timer(struct cfq_data *cfqd, struct cfq_queue *cfqq)
struct cfq_io_context *cic; struct cfq_io_context *cic;
unsigned long sl; unsigned long sl;
WARN_ON(!RB_EMPTY(&cfqq->sort_list)); WARN_ON(!RB_EMPTY_ROOT(&cfqq->sort_list));
WARN_ON(cfqq != cfqd->active_queue); WARN_ON(cfqq != cfqd->active_queue);
/* /*
...@@ -1042,7 +1037,7 @@ static struct cfq_queue *cfq_select_queue(struct cfq_data *cfqd) ...@@ -1042,7 +1037,7 @@ static struct cfq_queue *cfq_select_queue(struct cfq_data *cfqd)
* if queue has requests, dispatch one. if not, check if * if queue has requests, dispatch one. if not, check if
* enough slice is left to wait for one * enough slice is left to wait for one
*/ */
if (!RB_EMPTY(&cfqq->sort_list)) if (!RB_EMPTY_ROOT(&cfqq->sort_list))
goto keep_queue; goto keep_queue;
else if (cfq_cfqq_dispatched(cfqq)) { else if (cfq_cfqq_dispatched(cfqq)) {
cfqq = NULL; cfqq = NULL;
...@@ -1066,7 +1061,7 @@ __cfq_dispatch_requests(struct cfq_data *cfqd, struct cfq_queue *cfqq, ...@@ -1066,7 +1061,7 @@ __cfq_dispatch_requests(struct cfq_data *cfqd, struct cfq_queue *cfqq,
{ {
int dispatched = 0; int dispatched = 0;
BUG_ON(RB_EMPTY(&cfqq->sort_list)); BUG_ON(RB_EMPTY_ROOT(&cfqq->sort_list));
do { do {
struct cfq_rq *crq; struct cfq_rq *crq;
...@@ -1090,7 +1085,7 @@ __cfq_dispatch_requests(struct cfq_data *cfqd, struct cfq_queue *cfqq, ...@@ -1090,7 +1085,7 @@ __cfq_dispatch_requests(struct cfq_data *cfqd, struct cfq_queue *cfqq,
cfqd->active_cic = crq->io_context; cfqd->active_cic = crq->io_context;
} }
if (RB_EMPTY(&cfqq->sort_list)) if (RB_EMPTY_ROOT(&cfqq->sort_list))
break; break;
} while (dispatched < max_dispatch); } while (dispatched < max_dispatch);
...@@ -1480,7 +1475,6 @@ cfq_get_queue(struct cfq_data *cfqd, unsigned int key, struct task_struct *tsk, ...@@ -1480,7 +1475,6 @@ cfq_get_queue(struct cfq_data *cfqd, unsigned int key, struct task_struct *tsk,
INIT_HLIST_NODE(&cfqq->cfq_hash); INIT_HLIST_NODE(&cfqq->cfq_hash);
INIT_LIST_HEAD(&cfqq->cfq_list); INIT_LIST_HEAD(&cfqq->cfq_list);
RB_CLEAR_ROOT(&cfqq->sort_list);
INIT_LIST_HEAD(&cfqq->fifo); INIT_LIST_HEAD(&cfqq->fifo);
cfqq->key = key; cfqq->key = key;
...@@ -1873,7 +1867,7 @@ static void cfq_completed_request(request_queue_t *q, struct request *rq) ...@@ -1873,7 +1867,7 @@ static void cfq_completed_request(request_queue_t *q, struct request *rq)
if (cfqd->active_queue == cfqq) { if (cfqd->active_queue == cfqq) {
if (time_after(now, cfqq->slice_end)) if (time_after(now, cfqq->slice_end))
cfq_slice_expired(cfqd, 0); cfq_slice_expired(cfqd, 0);
else if (sync && RB_EMPTY(&cfqq->sort_list)) { else if (sync && RB_EMPTY_ROOT(&cfqq->sort_list)) {
if (!cfq_arm_slice_timer(cfqd, cfqq)) if (!cfq_arm_slice_timer(cfqd, cfqq))
cfq_schedule_dispatch(cfqd); cfq_schedule_dispatch(cfqd);
} }
...@@ -2059,7 +2053,7 @@ cfq_set_request(request_queue_t *q, struct request *rq, struct bio *bio, ...@@ -2059,7 +2053,7 @@ cfq_set_request(request_queue_t *q, struct request *rq, struct bio *bio,
crq = mempool_alloc(cfqd->crq_pool, gfp_mask); crq = mempool_alloc(cfqd->crq_pool, gfp_mask);
if (crq) { if (crq) {
RB_CLEAR(&crq->rb_node); RB_CLEAR_NODE(&crq->rb_node);
crq->rb_key = 0; crq->rb_key = 0;
crq->request = rq; crq->request = rq;
INIT_HLIST_NODE(&crq->hash); INIT_HLIST_NODE(&crq->hash);
...@@ -2151,7 +2145,7 @@ static void cfq_idle_slice_timer(unsigned long data) ...@@ -2151,7 +2145,7 @@ static void cfq_idle_slice_timer(unsigned long data)
/* /*
* not expired and it has a request pending, let it dispatch * not expired and it has a request pending, let it dispatch
*/ */
if (!RB_EMPTY(&cfqq->sort_list)) { if (!RB_EMPTY_ROOT(&cfqq->sort_list)) {
cfq_mark_cfqq_must_dispatch(cfqq); cfq_mark_cfqq_must_dispatch(cfqq);
goto out_kick; goto out_kick;
} }
......
...@@ -159,9 +159,6 @@ deadline_find_drq_hash(struct deadline_data *dd, sector_t offset) ...@@ -159,9 +159,6 @@ deadline_find_drq_hash(struct deadline_data *dd, sector_t offset)
/* /*
* rb tree support functions * rb tree support functions
*/ */
#define RB_EMPTY(root) ((root)->rb_node == NULL)
#define ON_RB(node) (rb_parent(node) != node)
#define RB_CLEAR(node) (rb_set_parent(node, node))
#define rb_entry_drq(node) rb_entry((node), struct deadline_rq, rb_node) #define rb_entry_drq(node) rb_entry((node), struct deadline_rq, rb_node)
#define DRQ_RB_ROOT(dd, drq) (&(dd)->sort_list[rq_data_dir((drq)->request)]) #define DRQ_RB_ROOT(dd, drq) (&(dd)->sort_list[rq_data_dir((drq)->request)])
#define rq_rb_key(rq) (rq)->sector #define rq_rb_key(rq) (rq)->sector
...@@ -220,9 +217,9 @@ deadline_del_drq_rb(struct deadline_data *dd, struct deadline_rq *drq) ...@@ -220,9 +217,9 @@ deadline_del_drq_rb(struct deadline_data *dd, struct deadline_rq *drq)
dd->next_drq[data_dir] = rb_entry_drq(rbnext); dd->next_drq[data_dir] = rb_entry_drq(rbnext);
} }
BUG_ON(!ON_RB(&drq->rb_node)); BUG_ON(!RB_EMPTY_NODE(&drq->rb_node));
rb_erase(&drq->rb_node, DRQ_RB_ROOT(dd, drq)); rb_erase(&drq->rb_node, DRQ_RB_ROOT(dd, drq));
RB_CLEAR(&drq->rb_node); RB_CLEAR_NODE(&drq->rb_node);
} }
static struct request * static struct request *
...@@ -496,7 +493,7 @@ static int deadline_dispatch_requests(request_queue_t *q, int force) ...@@ -496,7 +493,7 @@ static int deadline_dispatch_requests(request_queue_t *q, int force)
*/ */
if (reads) { if (reads) {
BUG_ON(RB_EMPTY(&dd->sort_list[READ])); BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[READ]));
if (writes && (dd->starved++ >= dd->writes_starved)) if (writes && (dd->starved++ >= dd->writes_starved))
goto dispatch_writes; goto dispatch_writes;
...@@ -512,7 +509,7 @@ static int deadline_dispatch_requests(request_queue_t *q, int force) ...@@ -512,7 +509,7 @@ static int deadline_dispatch_requests(request_queue_t *q, int force)
if (writes) { if (writes) {
dispatch_writes: dispatch_writes:
BUG_ON(RB_EMPTY(&dd->sort_list[WRITE])); BUG_ON(RB_EMPTY_ROOT(&dd->sort_list[WRITE]));
dd->starved = 0; dd->starved = 0;
...@@ -668,7 +665,7 @@ deadline_set_request(request_queue_t *q, struct request *rq, struct bio *bio, ...@@ -668,7 +665,7 @@ deadline_set_request(request_queue_t *q, struct request *rq, struct bio *bio,
drq = mempool_alloc(dd->drq_pool, gfp_mask); drq = mempool_alloc(dd->drq_pool, gfp_mask);
if (drq) { if (drq) {
memset(drq, 0, sizeof(*drq)); memset(drq, 0, sizeof(*drq));
RB_CLEAR(&drq->rb_node); RB_CLEAR_NODE(&drq->rb_node);
drq->request = rq; drq->request = rq;
INIT_HLIST_NODE(&drq->hash); INIT_HLIST_NODE(&drq->hash);
......
...@@ -132,6 +132,10 @@ static inline void rb_set_color(struct rb_node *rb, int color) ...@@ -132,6 +132,10 @@ static inline void rb_set_color(struct rb_node *rb, int color)
#define RB_ROOT (struct rb_root) { NULL, } #define RB_ROOT (struct rb_root) { NULL, }
#define rb_entry(ptr, type, member) container_of(ptr, type, member) #define rb_entry(ptr, type, member) container_of(ptr, type, member)
#define RB_EMPTY_ROOT(root) ((root)->rb_node == NULL)
#define RB_EMPTY_NODE(node) (rb_parent(node) != node)
#define RB_CLEAR_NODE(node) (rb_set_parent(node, node))
extern void rb_insert_color(struct rb_node *, struct rb_root *); extern void rb_insert_color(struct rb_node *, struct rb_root *);
extern void rb_erase(struct rb_node *, struct rb_root *); extern void rb_erase(struct rb_node *, struct rb_root *);
......
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