Skip to content

Commit c815881

Browse files
Lin Mingaxboe
authored andcommitted
block: implement runtime pm strategy
When a request is added: If device is suspended or is suspending and the request is not a PM request, resume the device. When the last request finishes: Call pm_runtime_mark_last_busy(). When pick a request: If device is resuming/suspending, then only PM request is allowed to go. The idea and API is designed by Alan Stern and described here: http://marc.info/?l=linux-scsi&m=133727953625963&w=2 Signed-off-by: Lin Ming <ming.m.lin@intel.com> Signed-off-by: Aaron Lu <aaron.lu@intel.com> Acked-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 6c95466 commit c815881

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

‎block/blk-core.c‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,16 @@ void part_round_stats(int cpu, struct hd_struct *part)
12641264
}
12651265
EXPORT_SYMBOL_GPL(part_round_stats);
12661266

1267+
#ifdef CONFIG_PM_RUNTIME
1268+
static void blk_pm_put_request(struct request *rq)
1269+
{
1270+
if (rq->q->dev && !(rq->cmd_flags & REQ_PM) && !--rq->q->nr_pending)
1271+
pm_runtime_mark_last_busy(rq->q->dev);
1272+
}
1273+
#else
1274+
static inline void blk_pm_put_request(struct request *rq) {}
1275+
#endif
1276+
12671277
/*
12681278
* queue lock must be held
12691279
*/
@@ -1274,6 +1284,8 @@ void __blk_put_request(struct request_queue *q, struct request *req)
12741284
if (unlikely(--req->ref_count))
12751285
return;
12761286

1287+
blk_pm_put_request(req);
1288+
12771289
elv_completed_request(q, req);
12781290

12791291
/* this is a bio leak */
@@ -2053,6 +2065,28 @@ static void blk_account_io_done(struct request *req)
20532065
}
20542066
}
20552067

2068+
#ifdef CONFIG_PM_RUNTIME
2069+
/*
2070+
* Don't process normal requests when queue is suspended
2071+
* or in the process of suspending/resuming
2072+
*/
2073+
static struct request *blk_pm_peek_request(struct request_queue *q,
2074+
struct request *rq)
2075+
{
2076+
if (q->dev && (q->rpm_status == RPM_SUSPENDED ||
2077+
(q->rpm_status != RPM_ACTIVE && !(rq->cmd_flags & REQ_PM))))
2078+
return NULL;
2079+
else
2080+
return rq;
2081+
}
2082+
#else
2083+
static inline struct request *blk_pm_peek_request(struct request_queue *q,
2084+
struct request *rq)
2085+
{
2086+
return rq;
2087+
}
2088+
#endif
2089+
20562090
/**
20572091
* blk_peek_request - peek at the top of a request queue
20582092
* @q: request queue to peek at
@@ -2075,6 +2109,11 @@ struct request *blk_peek_request(struct request_queue *q)
20752109
int ret;
20762110

20772111
while ((rq = __elv_next_request(q)) != NULL) {
2112+
2113+
rq = blk_pm_peek_request(q, rq);
2114+
if (!rq)
2115+
break;
2116+
20782117
if (!(rq->cmd_flags & REQ_STARTED)) {
20792118
/*
20802119
* This is the first time the device driver

‎block/elevator.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/blktrace_api.h>
3535
#include <linux/hash.h>
3636
#include <linux/uaccess.h>
37+
#include <linux/pm_runtime.h>
3738

3839
#include <trace/events/block.h>
3940

@@ -536,6 +537,27 @@ void elv_bio_merged(struct request_queue *q, struct request *rq,
536537
e->type->ops.elevator_bio_merged_fn(q, rq, bio);
537538
}
538539

540+
#ifdef CONFIG_PM_RUNTIME
541+
static void blk_pm_requeue_request(struct request *rq)
542+
{
543+
if (rq->q->dev && !(rq->cmd_flags & REQ_PM))
544+
rq->q->nr_pending--;
545+
}
546+
547+
static void blk_pm_add_request(struct request_queue *q, struct request *rq)
548+
{
549+
if (q->dev && !(rq->cmd_flags & REQ_PM) && q->nr_pending++ == 0 &&
550+
(q->rpm_status == RPM_SUSPENDED || q->rpm_status == RPM_SUSPENDING))
551+
pm_request_resume(q->dev);
552+
}
553+
#else
554+
static inline void blk_pm_requeue_request(struct request *rq) {}
555+
static inline void blk_pm_add_request(struct request_queue *q,
556+
struct request *rq)
557+
{
558+
}
559+
#endif
560+
539561
void elv_requeue_request(struct request_queue *q, struct request *rq)
540562
{
541563
/*
@@ -550,6 +572,8 @@ void elv_requeue_request(struct request_queue *q, struct request *rq)
550572

551573
rq->cmd_flags &= ~REQ_STARTED;
552574

575+
blk_pm_requeue_request(rq);
576+
553577
__elv_add_request(q, rq, ELEVATOR_INSERT_REQUEUE);
554578
}
555579

@@ -572,6 +596,8 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where)
572596
{
573597
trace_block_rq_insert(q, rq);
574598

599+
blk_pm_add_request(q, rq);
600+
575601
rq->q = q;
576602

577603
if (rq->cmd_flags & REQ_SOFTBARRIER) {

0 commit comments

Comments
 (0)