Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] can we go lockless for has_work? Basically the same as in dd_has_work … ? #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 12 additions & 26 deletions k2.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,38 +162,24 @@ static void k2_completed_request(struct request *r)
blk_mq_run_hw_queues(r->q, true);
}

static bool _k2_has_work(struct k2_data *k2d)
static bool k2_has_work(struct blk_mq_hw_ctx *hctx)
{
unsigned int i;

assert_spin_locked(&k2d->lock);

if (k2d->inflight >= k2d->max_inflight)
return(false);
unsigned int i;
struct k2_data *k2d = hctx->queue->elevator->elevator_data;

if (READ_ONCE(&k2d->inflight) >= READ_ONCE(&k2d->max_inflight))
return (false);

if (! list_empty(&k2d->be_reqs))
return(true);
if (!list_empty_careful(&k2d->be_reqs))
return (true);

for (i = 0; i < IOPRIO_BE_NR; i++) {
if (list_empty(&k2d->rt_reqs[i])) {
return(true);
if (list_empty_careful(&k2d->rt_reqs[i])) {
return (true);
}
}

return(false);
}

static bool k2_has_work(struct blk_mq_hw_ctx *hctx)
{
struct k2_data *k2d = hctx->queue->elevator->elevator_data;
bool has_work;
unsigned long flags;

spin_lock_irqsave(&k2d->lock, flags);
has_work = _k2_has_work(k2d);
spin_unlock_irqrestore(&k2d->lock, flags);

return(has_work);
return (false);
}

/* Inserts a request into the scheduler queue. For now, at_head is ignored! */
Expand Down Expand Up @@ -272,8 +258,8 @@ static struct request *k2_dispatch_request(struct blk_mq_hw_ctx *hctx)
return(NULL);

end:
++k2d->inflight;
list_del_init(&r->queuelist);
k2d->inflight++;
r->rq_flags |= RQF_STARTED;
spin_unlock_irqrestore(&k2d->lock, flags);
return(r);
Expand Down