blk-rq-qos.h 3.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#ifndef RQ_QOS_H
#define RQ_QOS_H

#include <linux/kernel.h>
#include <linux/blkdev.h>
#include <linux/blk_types.h>
#include <linux/atomic.h>
#include <linux/wait.h>

enum rq_qos_id {
	RQ_QOS_WBT,
	RQ_QOS_CGROUP,
};

struct rq_wait {
	wait_queue_head_t wait;
	atomic_t inflight;
};

struct rq_qos {
	struct rq_qos_ops *ops;
	struct request_queue *q;
	enum rq_qos_id id;
	struct rq_qos *next;
};

struct rq_qos_ops {
28 29
	void (*throttle)(struct rq_qos *, struct bio *, spinlock_t *);
	void (*track)(struct rq_qos *, struct request *, struct bio *);
T
Tejun Heo 已提交
30
	void (*merge)(struct rq_qos *, struct request *, struct bio *);
31 32 33
	void (*issue)(struct rq_qos *, struct request *);
	void (*requeue)(struct rq_qos *, struct request *);
	void (*done)(struct rq_qos *, struct request *);
J
Josef Bacik 已提交
34
	void (*done_bio)(struct rq_qos *, struct bio *);
35
	void (*cleanup)(struct rq_qos *, struct bio *);
36
	void (*queue_depth_changed)(struct rq_qos *);
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
	void (*exit)(struct rq_qos *);
};

struct rq_depth {
	unsigned int max_depth;

	int scale_step;
	bool scaled_max;

	unsigned int queue_depth;
	unsigned int default_depth;
};

static inline struct rq_qos *rq_qos_id(struct request_queue *q,
				       enum rq_qos_id id)
{
	struct rq_qos *rqos;
	for (rqos = q->rq_qos; rqos; rqos = rqos->next) {
		if (rqos->id == id)
			break;
	}
	return rqos;
}

static inline struct rq_qos *wbt_rq_qos(struct request_queue *q)
{
	return rq_qos_id(q, RQ_QOS_WBT);
}

static inline struct rq_qos *blkcg_rq_qos(struct request_queue *q)
{
	return rq_qos_id(q, RQ_QOS_CGROUP);
}

static inline void rq_wait_init(struct rq_wait *rq_wait)
{
	atomic_set(&rq_wait->inflight, 0);
	init_waitqueue_head(&rq_wait->wait);
}

static inline void rq_qos_add(struct request_queue *q, struct rq_qos *rqos)
{
	rqos->next = q->rq_qos;
	q->rq_qos = rqos;
}

static inline void rq_qos_del(struct request_queue *q, struct rq_qos *rqos)
{
85 86 87 88 89
	struct rq_qos **cur;

	for (cur = &q->rq_qos; *cur; cur = &(*cur)->next) {
		if (*cur == rqos) {
			*cur = rqos->next;
90 91 92 93 94
			break;
		}
	}
}

95
bool rq_wait_inc_below(struct rq_wait *rq_wait, unsigned int limit);
96 97
bool rq_depth_scale_up(struct rq_depth *rqd);
bool rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle);
98 99
bool rq_depth_calc_max_depth(struct rq_depth *rqd);

100
void rq_qos_cleanup(struct request_queue *, struct bio *);
101 102 103
void rq_qos_done(struct request_queue *, struct request *);
void rq_qos_issue(struct request_queue *, struct request *);
void rq_qos_requeue(struct request_queue *, struct request *);
J
Josef Bacik 已提交
104
void rq_qos_done_bio(struct request_queue *q, struct bio *bio);
105 106
void rq_qos_throttle(struct request_queue *, struct bio *, spinlock_t *);
void rq_qos_track(struct request_queue *q, struct request *, struct bio *);
T
Tejun Heo 已提交
107
void __rq_qos_merge(struct rq_qos *rqos, struct request *rq, struct bio *bio);
108
void __rq_qos_queue_depth_changed(struct rq_qos *rqos);
109
void rq_qos_exit(struct request_queue *);
T
Tejun Heo 已提交
110 111 112 113 114 115 116 117

static inline void rq_qos_merge(struct request_queue *q, struct request *rq,
				struct bio *bio)
{
	if (q->rq_qos)
		__rq_qos_merge(q->rq_qos, rq, bio);
}

118 119 120 121 122 123
static inline void rq_qos_queue_depth_changed(struct request_queue *q)
{
	if (q->rq_qos)
		__rq_qos_queue_depth_changed(q->rq_qos);
}

124
#endif