6 #include <linux/module.h>
7 #include <linux/types.h>
8 #include <linux/ctype.h>
9 #include <linux/kernel.h>
13 #define POSDIFF(A, B) ((int)((A) - (B)) > 0 ? (A) - (B) : 0)
14 #define AFTER_EQ(A, B) ((int)((A) - (B)) >= 0)
19 unsigned int inprogress, prev_inprogress,
limit;
20 unsigned int ovlimit,
completed, num_queued;
21 bool all_prev_completed;
26 BUG_ON(count > num_queued - dql->num_completed);
28 completed = dql->num_completed +
count;
30 ovlimit =
POSDIFF(num_queued - dql->num_completed, limit);
32 prev_inprogress = dql->prev_num_queued - dql->num_completed;
33 all_prev_completed =
AFTER_EQ(completed, dql->prev_num_queued);
35 if ((ovlimit && !inprogress) ||
36 (dql->prev_ovlimit && all_prev_completed)) {
52 limit +=
POSDIFF(completed, dql->prev_num_queued) +
54 dql->slack_start_time =
jiffies;
56 }
else if (inprogress && prev_inprogress && !all_prev_completed) {
68 unsigned int slack, slack_last_objs;
81 slack =
POSDIFF(limit + dql->prev_ovlimit,
82 2 * (completed - dql->num_completed));
83 slack_last_objs = dql->prev_ovlimit ?
84 POSDIFF(dql->prev_last_obj_cnt, dql->prev_ovlimit) : 0;
86 slack =
max(slack, slack_last_objs);
88 if (slack < dql->lowest_slack)
89 dql->lowest_slack = slack;
92 dql->slack_start_time + dql->slack_hold_time)) {
93 limit =
POSDIFF(limit, dql->lowest_slack);
94 dql->slack_start_time =
jiffies;
100 limit =
clamp(limit, dql->min_limit, dql->max_limit);
102 if (limit != dql->limit) {
108 dql->prev_ovlimit = ovlimit;
109 dql->prev_last_obj_cnt = dql->last_obj_cnt;
111 dql->prev_num_queued = num_queued;
120 dql->num_completed = 0;
121 dql->last_obj_cnt = 0;
122 dql->prev_num_queued = 0;
123 dql->prev_last_obj_cnt = 0;
124 dql->prev_ovlimit = 0;
126 dql->slack_start_time =
jiffies;
132 dql->max_limit = DQL_MAX_LIMIT;
134 dql->slack_hold_time = hold_time;