elevator.h 6.4 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
#ifndef _LINUX_ELEVATOR_H
#define _LINUX_ELEVATOR_H

4 5
#include <linux/percpu.h>

L
Linus Torvalds 已提交
6 7 8 9 10
typedef int (elevator_merge_fn) (request_queue_t *, struct request **,
				 struct bio *);

typedef void (elevator_merge_req_fn) (request_queue_t *, struct request *, struct request *);

11
typedef void (elevator_merged_fn) (request_queue_t *, struct request *, int);
L
Linus Torvalds 已提交
12

13
typedef int (elevator_dispatch_fn) (request_queue_t *, int);
L
Linus Torvalds 已提交
14

15
typedef void (elevator_add_req_fn) (request_queue_t *, struct request *);
L
Linus Torvalds 已提交
16 17 18
typedef int (elevator_queue_empty_fn) (request_queue_t *);
typedef struct request *(elevator_request_list_fn) (request_queue_t *, struct request *);
typedef void (elevator_completed_req_fn) (request_queue_t *, struct request *);
19
typedef int (elevator_may_queue_fn) (request_queue_t *, int);
L
Linus Torvalds 已提交
20

21
typedef int (elevator_set_req_fn) (request_queue_t *, struct request *, gfp_t);
L
Linus Torvalds 已提交
22
typedef void (elevator_put_req_fn) (request_queue_t *, struct request *);
23
typedef void (elevator_activate_req_fn) (request_queue_t *, struct request *);
L
Linus Torvalds 已提交
24 25
typedef void (elevator_deactivate_req_fn) (request_queue_t *, struct request *);

J
Jens Axboe 已提交
26
typedef void *(elevator_init_fn) (request_queue_t *, elevator_t *);
L
Linus Torvalds 已提交
27 28 29 30 31 32 33 34
typedef void (elevator_exit_fn) (elevator_t *);

struct elevator_ops
{
	elevator_merge_fn *elevator_merge_fn;
	elevator_merged_fn *elevator_merged_fn;
	elevator_merge_req_fn *elevator_merge_req_fn;

35
	elevator_dispatch_fn *elevator_dispatch_fn;
L
Linus Torvalds 已提交
36
	elevator_add_req_fn *elevator_add_req_fn;
37
	elevator_activate_req_fn *elevator_activate_req_fn;
L
Linus Torvalds 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
	elevator_deactivate_req_fn *elevator_deactivate_req_fn;

	elevator_queue_empty_fn *elevator_queue_empty_fn;
	elevator_completed_req_fn *elevator_completed_req_fn;

	elevator_request_list_fn *elevator_former_req_fn;
	elevator_request_list_fn *elevator_latter_req_fn;

	elevator_set_req_fn *elevator_set_req_fn;
	elevator_put_req_fn *elevator_put_req_fn;

	elevator_may_queue_fn *elevator_may_queue_fn;

	elevator_init_fn *elevator_init_fn;
	elevator_exit_fn *elevator_exit_fn;
53
	void (*trim)(struct io_context *);
L
Linus Torvalds 已提交
54 55 56 57
};

#define ELV_NAME_MAX	(16)

58 59 60 61 62 63
struct elv_fs_entry {
	struct attribute attr;
	ssize_t (*show)(elevator_t *, char *);
	ssize_t (*store)(elevator_t *, const char *, size_t);
};

L
Linus Torvalds 已提交
64 65 66 67 68 69 70 71
/*
 * identifies an elevator type, such as AS or deadline
 */
struct elevator_type
{
	struct list_head list;
	struct elevator_ops ops;
	struct elevator_type *elevator_type;
72
	struct elv_fs_entry *elevator_attrs;
L
Linus Torvalds 已提交
73 74 75 76 77
	char elevator_name[ELV_NAME_MAX];
	struct module *elevator_owner;
};

/*
A
Adrian Bunk 已提交
78
 * each queue has an elevator_queue associated with it
L
Linus Torvalds 已提交
79 80 81 82 83 84 85
 */
struct elevator_queue
{
	struct elevator_ops *ops;
	void *elevator_data;
	struct kobject kobj;
	struct elevator_type *elevator_type;
86
	struct mutex sysfs_lock;
87
	struct hlist_head *hash;
L
Linus Torvalds 已提交
88 89 90 91 92
};

/*
 * block elevator interface
 */
J
Jens Axboe 已提交
93
extern void elv_dispatch_sort(request_queue_t *, struct request *);
94
extern void elv_dispatch_add_tail(request_queue_t *, struct request *);
L
Linus Torvalds 已提交
95 96
extern void elv_add_request(request_queue_t *, struct request *, int, int);
extern void __elv_add_request(request_queue_t *, struct request *, int, int);
97
extern void elv_insert(request_queue_t *, struct request *, int);
L
Linus Torvalds 已提交
98 99 100
extern int elv_merge(request_queue_t *, struct request **, struct bio *);
extern void elv_merge_requests(request_queue_t *, struct request *,
			       struct request *);
101
extern void elv_merged_request(request_queue_t *, struct request *, int);
102
extern void elv_dequeue_request(request_queue_t *, struct request *);
L
Linus Torvalds 已提交
103 104 105 106 107 108 109
extern void elv_requeue_request(request_queue_t *, struct request *);
extern int elv_queue_empty(request_queue_t *);
extern struct request *elv_next_request(struct request_queue *q);
extern struct request *elv_former_request(request_queue_t *, struct request *);
extern struct request *elv_latter_request(request_queue_t *, struct request *);
extern int elv_register_queue(request_queue_t *q);
extern void elv_unregister_queue(request_queue_t *q);
110
extern int elv_may_queue(request_queue_t *, int);
L
Linus Torvalds 已提交
111
extern void elv_completed_request(request_queue_t *, struct request *);
112
extern int elv_set_request(request_queue_t *, struct request *, gfp_t);
L
Linus Torvalds 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
extern void elv_put_request(request_queue_t *, struct request *);

/*
 * io scheduler registration
 */
extern int elv_register(struct elevator_type *);
extern void elv_unregister(struct elevator_type *);

/*
 * io scheduler sysfs switching
 */
extern ssize_t elv_iosched_show(request_queue_t *, char *);
extern ssize_t elv_iosched_store(request_queue_t *, const char *, size_t);

extern int elevator_init(request_queue_t *, char *);
extern void elevator_exit(elevator_t *);
extern int elv_rq_merge_ok(struct request *, struct bio *);

131 132 133 134 135 136 137 138 139 140 141 142 143
/*
 * Helper functions.
 */
extern struct request *elv_rb_former_request(request_queue_t *, struct request *);
extern struct request *elv_rb_latter_request(request_queue_t *, struct request *);

/*
 * rb support functions.
 */
extern struct request *elv_rb_add(struct rb_root *, struct request *);
extern void elv_rb_del(struct rb_root *, struct request *);
extern struct request *elv_rb_find(struct rb_root *, sector_t);

L
Linus Torvalds 已提交
144 145 146 147 148 149 150 151 152 153 154 155 156
/*
 * Return values from elevator merger
 */
#define ELEVATOR_NO_MERGE	0
#define ELEVATOR_FRONT_MERGE	1
#define ELEVATOR_BACK_MERGE	2

/*
 * Insertion selection
 */
#define ELEVATOR_INSERT_FRONT	1
#define ELEVATOR_INSERT_BACK	2
#define ELEVATOR_INSERT_SORT	3
157
#define ELEVATOR_INSERT_REQUEUE	4
L
Linus Torvalds 已提交
158 159 160 161 162 163 164 165 166 167

/*
 * return values from elevator_may_queue_fn
 */
enum {
	ELV_MQUEUE_MAY,
	ELV_MQUEUE_NO,
	ELV_MQUEUE_MUST,
};

J
Jens Axboe 已提交
168
#define rq_end_sector(rq)	((rq)->sector + (rq)->nr_sectors)
169
#define rb_entry_rq(node)	rb_entry((node), struct request, rb_node)
J
Jens Axboe 已提交
170

171 172 173 174 175 176 177 178 179 180 181 182
/*
 * Hack to reuse the donelist list_head as the fifo time holder while
 * the request is in the io scheduler. Saves an unsigned long in rq.
 */
#define rq_fifo_time(rq)	((unsigned long) (rq)->donelist.next)
#define rq_set_fifo_time(rq,exp)	((rq)->donelist.next = (void *) (exp))
#define rq_entry_fifo(ptr)	list_entry((ptr), struct request, queuelist)
#define rq_fifo_clear(rq)	do {		\
	list_del_init(&(rq)->queuelist);	\
	INIT_LIST_HEAD(&(rq)->donelist);	\
	} while (0)

183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
/*
 * 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;							\
})

L
Linus Torvalds 已提交
206
#endif