1 #include "blk-rq-qos.h"
4 * Increment 'v', if 'v' is below 'below'. Returns true if we succeeded,
5 * false if 'v' + 1 would be bigger than 'below'.
7 static bool atomic_inc_below(atomic_t
*v
, unsigned int below
)
9 unsigned int cur
= atomic_read(v
);
16 old
= atomic_cmpxchg(v
, cur
, cur
+ 1);
25 bool rq_wait_inc_below(struct rq_wait
*rq_wait
, unsigned int limit
)
27 return atomic_inc_below(&rq_wait
->inflight
, limit
);
30 void rq_qos_cleanup(struct request_queue
*q
, struct bio
*bio
)
34 for (rqos
= q
->rq_qos
; rqos
; rqos
= rqos
->next
) {
35 if (rqos
->ops
->cleanup
)
36 rqos
->ops
->cleanup(rqos
, bio
);
40 void rq_qos_done(struct request_queue
*q
, struct request
*rq
)
44 for (rqos
= q
->rq_qos
; rqos
; rqos
= rqos
->next
) {
46 rqos
->ops
->done(rqos
, rq
);
50 void rq_qos_issue(struct request_queue
*q
, struct request
*rq
)
54 for(rqos
= q
->rq_qos
; rqos
; rqos
= rqos
->next
) {
56 rqos
->ops
->issue(rqos
, rq
);
60 void rq_qos_requeue(struct request_queue
*q
, struct request
*rq
)
64 for(rqos
= q
->rq_qos
; rqos
; rqos
= rqos
->next
) {
65 if (rqos
->ops
->requeue
)
66 rqos
->ops
->requeue(rqos
, rq
);
70 void rq_qos_throttle(struct request_queue
*q
, struct bio
*bio
,
75 for(rqos
= q
->rq_qos
; rqos
; rqos
= rqos
->next
) {
76 if (rqos
->ops
->throttle
)
77 rqos
->ops
->throttle(rqos
, bio
, lock
);
81 void rq_qos_track(struct request_queue
*q
, struct request
*rq
, struct bio
*bio
)
85 for(rqos
= q
->rq_qos
; rqos
; rqos
= rqos
->next
) {
87 rqos
->ops
->track(rqos
, rq
, bio
);
91 void rq_qos_done_bio(struct request_queue
*q
, struct bio
*bio
)
95 for(rqos
= q
->rq_qos
; rqos
; rqos
= rqos
->next
) {
96 if (rqos
->ops
->done_bio
)
97 rqos
->ops
->done_bio(rqos
, bio
);
102 * Return true, if we can't increase the depth further by scaling
104 bool rq_depth_calc_max_depth(struct rq_depth
*rqd
)
110 * For QD=1 devices, this is a special case. It's important for those
111 * to have one request ready when one completes, so force a depth of
112 * 2 for those devices. On the backend, it'll be a depth of 1 anyway,
113 * since the device can't have more than that in flight. If we're
114 * scaling down, then keep a setting of 1/1/1.
116 if (rqd
->queue_depth
== 1) {
117 if (rqd
->scale_step
> 0)
125 * scale_step == 0 is our default state. If we have suffered
126 * latency spikes, step will be > 0, and we shrink the
127 * allowed write depths. If step is < 0, we're only doing
128 * writes, and we allow a temporarily higher depth to
129 * increase performance.
131 depth
= min_t(unsigned int, rqd
->default_depth
,
133 if (rqd
->scale_step
> 0)
134 depth
= 1 + ((depth
- 1) >> min(31, rqd
->scale_step
));
135 else if (rqd
->scale_step
< 0) {
136 unsigned int maxd
= 3 * rqd
->queue_depth
/ 4;
138 depth
= 1 + ((depth
- 1) << -rqd
->scale_step
);
145 rqd
->max_depth
= depth
;
151 /* Returns true on success and false if scaling up wasn't possible */
152 bool rq_depth_scale_up(struct rq_depth
*rqd
)
155 * Hit max in previous round, stop here
162 rqd
->scaled_max
= rq_depth_calc_max_depth(rqd
);
167 * Scale rwb down. If 'hard_throttle' is set, do it quicker, since we
168 * had a latency violation. Returns true on success and returns false if
169 * scaling down wasn't possible.
171 bool rq_depth_scale_down(struct rq_depth
*rqd
, bool hard_throttle
)
174 * Stop scaling down when we've hit the limit. This also prevents
175 * ->scale_step from going to crazy values, if the device can't
178 if (rqd
->max_depth
== 1)
181 if (rqd
->scale_step
< 0 && hard_throttle
)
186 rqd
->scaled_max
= false;
187 rq_depth_calc_max_depth(rqd
);
191 void rq_qos_exit(struct request_queue
*q
)
194 struct rq_qos
*rqos
= q
->rq_qos
;
195 q
->rq_qos
= rqos
->next
;
196 rqos
->ops
->exit(rqos
);