mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-02 00:24:12 +08:00
84f603246d
Originally when I split out the common code from blk-wbt into rq_qos I left the wbt_wait() where it was and simply copied and modified it slightly to work for io-latency. However they are both basically the same thing, and as time has gone on wbt_wait() has ended up much smarter and kinder than it was when I copied it into io-latency, which means io-latency has lost out on these improvements. Since they are the same thing essentially except for a few minor things, create rq_qos_wait() that replicates what wbt_wait() currently does with callbacks that can be passed in for the snowflakes to do their own thing as appropriate. Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
161 lines
3.8 KiB
C
161 lines
3.8 KiB
C
#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 {
|
|
void (*throttle)(struct rq_qos *, struct bio *);
|
|
void (*track)(struct rq_qos *, struct request *, struct bio *);
|
|
void (*issue)(struct rq_qos *, struct request *);
|
|
void (*requeue)(struct rq_qos *, struct request *);
|
|
void (*done)(struct rq_qos *, struct request *);
|
|
void (*done_bio)(struct rq_qos *, struct bio *);
|
|
void (*cleanup)(struct rq_qos *, struct bio *);
|
|
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)
|
|
{
|
|
struct rq_qos *cur, *prev = NULL;
|
|
for (cur = q->rq_qos; cur; cur = cur->next) {
|
|
if (cur == rqos) {
|
|
if (prev)
|
|
prev->next = rqos->next;
|
|
else
|
|
q->rq_qos = cur;
|
|
break;
|
|
}
|
|
prev = cur;
|
|
}
|
|
}
|
|
|
|
typedef bool (acquire_inflight_cb_t)(struct rq_wait *rqw, void *private_data);
|
|
typedef void (cleanup_cb_t)(struct rq_wait *rqw, void *private_data);
|
|
|
|
void rq_qos_wait(struct rq_wait *rqw, void *private_data,
|
|
acquire_inflight_cb_t *acquire_inflight_cb,
|
|
cleanup_cb_t *cleanup_cb);
|
|
bool rq_wait_inc_below(struct rq_wait *rq_wait, unsigned int limit);
|
|
void rq_depth_scale_up(struct rq_depth *rqd);
|
|
void rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle);
|
|
bool rq_depth_calc_max_depth(struct rq_depth *rqd);
|
|
|
|
void __rq_qos_cleanup(struct rq_qos *rqos, struct bio *bio);
|
|
void __rq_qos_done(struct rq_qos *rqos, struct request *rq);
|
|
void __rq_qos_issue(struct rq_qos *rqos, struct request *rq);
|
|
void __rq_qos_requeue(struct rq_qos *rqos, struct request *rq);
|
|
void __rq_qos_throttle(struct rq_qos *rqos, struct bio *bio);
|
|
void __rq_qos_track(struct rq_qos *rqos, struct request *rq, struct bio *bio);
|
|
void __rq_qos_done_bio(struct rq_qos *rqos, struct bio *bio);
|
|
|
|
static inline void rq_qos_cleanup(struct request_queue *q, struct bio *bio)
|
|
{
|
|
if (q->rq_qos)
|
|
__rq_qos_cleanup(q->rq_qos, bio);
|
|
}
|
|
|
|
static inline void rq_qos_done(struct request_queue *q, struct request *rq)
|
|
{
|
|
if (q->rq_qos)
|
|
__rq_qos_done(q->rq_qos, rq);
|
|
}
|
|
|
|
static inline void rq_qos_issue(struct request_queue *q, struct request *rq)
|
|
{
|
|
if (q->rq_qos)
|
|
__rq_qos_issue(q->rq_qos, rq);
|
|
}
|
|
|
|
static inline void rq_qos_requeue(struct request_queue *q, struct request *rq)
|
|
{
|
|
if (q->rq_qos)
|
|
__rq_qos_requeue(q->rq_qos, rq);
|
|
}
|
|
|
|
static inline void rq_qos_done_bio(struct request_queue *q, struct bio *bio)
|
|
{
|
|
if (q->rq_qos)
|
|
__rq_qos_done_bio(q->rq_qos, bio);
|
|
}
|
|
|
|
static inline void rq_qos_throttle(struct request_queue *q, struct bio *bio)
|
|
{
|
|
if (q->rq_qos)
|
|
__rq_qos_throttle(q->rq_qos, bio);
|
|
}
|
|
|
|
static inline void rq_qos_track(struct request_queue *q, struct request *rq,
|
|
struct bio *bio)
|
|
{
|
|
if (q->rq_qos)
|
|
__rq_qos_track(q->rq_qos, rq, bio);
|
|
}
|
|
|
|
void rq_qos_exit(struct request_queue *);
|
|
|
|
#endif
|