Skip to content

Commit 5b36ad6

Browse files
htejunJens Axboe
authored andcommitted
mg_disk: dequeue and track in-flight request
mg_disk has at most single request in flight per device. Till now, whenever it needs to access the in-flight request it called elv_next_request(). This patch makes mg_disk track the in-flight request directly using mg_host->req and dequeue it when processing starts. q->queuedata is set to mg_host so that mg_host can be determined without fetching request from the queue. [ Impact: dequeue in-flight request, one elv_next_request() per request ] Signed-off-by: Tejun Heo <tj@kernel.org> Cc: unsik Kim <donari75@gmail.com> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
1 parent 9a8d23d commit 5b36ad6

1 file changed

Lines changed: 59 additions & 50 deletions

File tree

‎drivers/block/mg_disk.c‎

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct mg_host {
135135
struct device *dev;
136136

137137
struct request_queue *breq;
138+
struct request *req;
138139
spinlock_t lock;
139140
struct gendisk *gd;
140141

@@ -171,17 +172,27 @@ struct mg_host {
171172

172173
static void mg_request(struct request_queue *);
173174

175+
static bool mg_end_request(struct mg_host *host, int err, unsigned int nr_bytes)
176+
{
177+
if (__blk_end_request(host->req, err, nr_bytes))
178+
return true;
179+
180+
host->req = NULL;
181+
return false;
182+
}
183+
184+
static bool mg_end_request_cur(struct mg_host *host, int err)
185+
{
186+
return mg_end_request(host, err, blk_rq_cur_bytes(host->req));
187+
}
188+
174189
static void mg_dump_status(const char *msg, unsigned int stat,
175190
struct mg_host *host)
176191
{
177192
char *name = MG_DISK_NAME;
178-
struct request *req;
179193

180-
if (host->breq) {
181-
req = elv_next_request(host->breq);
182-
if (req)
183-
name = req->rq_disk->disk_name;
184-
}
194+
if (host->req)
195+
name = host->req->rq_disk->disk_name;
185196

186197
printk(KERN_ERR "%s: %s: status=0x%02x { ", name, msg, stat & 0xff);
187198
if (stat & ATA_BUSY)
@@ -217,13 +228,9 @@ static void mg_dump_status(const char *msg, unsigned int stat,
217228
printk("AddrMarkNotFound ");
218229
printk("}");
219230
if (host->error & (ATA_BBK | ATA_UNC | ATA_IDNF | ATA_AMNF)) {
220-
if (host->breq) {
221-
req = elv_next_request(host->breq);
222-
if (req)
223-
printk(", sector=%u",
224-
(unsigned int)blk_rq_pos(req));
225-
}
226-
231+
if (host->req)
232+
printk(", sector=%u",
233+
(unsigned int)blk_rq_pos(host->req));
227234
}
228235
printk("\n");
229236
}
@@ -453,11 +460,10 @@ static int mg_disk_init(struct mg_host *host)
453460

454461
static void mg_bad_rw_intr(struct mg_host *host)
455462
{
456-
struct request *req = elv_next_request(host->breq);
457-
if (req != NULL)
458-
if (++req->errors >= MG_MAX_ERRORS ||
459-
host->error == MG_ERR_TIMEOUT)
460-
__blk_end_request_cur(req, -EIO);
463+
if (host->req)
464+
if (++host->req->errors >= MG_MAX_ERRORS ||
465+
host->error == MG_ERR_TIMEOUT)
466+
mg_end_request_cur(host, -EIO);
461467
}
462468

463469
static unsigned int mg_out(struct mg_host *host,
@@ -515,7 +521,7 @@ static void mg_read(struct request *req)
515521

516522
outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base +
517523
MG_REG_COMMAND);
518-
} while (__blk_end_request(req, 0, MG_SECTOR_SIZE));
524+
} while (mg_end_request(host, 0, MG_SECTOR_SIZE));
519525
}
520526

521527
static void mg_write(struct request *req)
@@ -545,14 +551,14 @@ static void mg_write(struct request *req)
545551

546552
outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base +
547553
MG_REG_COMMAND);
548-
} while (__blk_end_request(req, 0, MG_SECTOR_SIZE));
554+
} while (mg_end_request(host, 0, MG_SECTOR_SIZE));
549555
}
550556

551557
static void mg_read_intr(struct mg_host *host)
552558
{
559+
struct request *req = host->req;
553560
u32 i;
554561
u16 *buff;
555-
struct request *req;
556562

557563
/* check status */
558564
do {
@@ -571,7 +577,6 @@ static void mg_read_intr(struct mg_host *host)
571577

572578
ok_to_read:
573579
/* get current segment of request */
574-
req = elv_next_request(host->breq);
575580
buff = (u16 *)req->buffer;
576581

577582
/* read 1 sector */
@@ -585,7 +590,7 @@ static void mg_read_intr(struct mg_host *host)
585590
/* send read confirm */
586591
outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND);
587592

588-
if (__blk_end_request(req, 0, MG_SECTOR_SIZE)) {
593+
if (mg_end_request(host, 0, MG_SECTOR_SIZE)) {
589594
/* set handler if read remains */
590595
host->mg_do_intr = mg_read_intr;
591596
mod_timer(&host->timer, jiffies + 3 * HZ);
@@ -595,14 +600,11 @@ static void mg_read_intr(struct mg_host *host)
595600

596601
static void mg_write_intr(struct mg_host *host)
597602
{
603+
struct request *req = host->req;
598604
u32 i, j;
599605
u16 *buff;
600-
struct request *req;
601606
bool rem;
602607

603-
/* get current segment of request */
604-
req = elv_next_request(host->breq);
605-
606608
/* check status */
607609
do {
608610
i = inb((unsigned long)host->dev_base + MG_REG_STATUS);
@@ -619,7 +621,7 @@ static void mg_write_intr(struct mg_host *host)
619621
return;
620622

621623
ok_to_write:
622-
if ((rem = __blk_end_request(req, 0, MG_SECTOR_SIZE))) {
624+
if ((rem = mg_end_request(host, 0, MG_SECTOR_SIZE))) {
623625
/* write 1 sector and set handler if remains */
624626
buff = (u16 *)req->buffer;
625627
for (j = 0; j < MG_STORAGE_BUFFER_SIZE >> 1; j++) {
@@ -644,44 +646,47 @@ void mg_times_out(unsigned long data)
644646
{
645647
struct mg_host *host = (struct mg_host *)data;
646648
char *name;
647-
struct request *req;
648649

649650
spin_lock_irq(&host->lock);
650651

651-
req = elv_next_request(host->breq);
652-
if (!req)
652+
if (!host->req)
653653
goto out_unlock;
654654

655655
host->mg_do_intr = NULL;
656656

657-
name = req->rq_disk->disk_name;
657+
name = host->req->rq_disk->disk_name;
658658
printk(KERN_DEBUG "%s: timeout\n", name);
659659

660660
host->error = MG_ERR_TIMEOUT;
661661
mg_bad_rw_intr(host);
662662

663-
mg_request(host->breq);
664663
out_unlock:
664+
mg_request(host->breq);
665665
spin_unlock_irq(&host->lock);
666666
}
667667

668668
static void mg_request_poll(struct request_queue *q)
669669
{
670-
struct request *req;
671-
struct mg_host *host;
670+
struct mg_host *host = q->queuedata;
672671

673-
while ((req = elv_next_request(q)) != NULL) {
674-
host = req->rq_disk->private_data;
672+
while (1) {
673+
if (!host->req) {
674+
host->req = elv_next_request(q);
675+
if (host->req)
676+
blkdev_dequeue_request(host->req);
677+
else
678+
break;
679+
}
675680

676-
if (unlikely(!blk_fs_request(req))) {
677-
__blk_end_request_cur(req, -EIO);
681+
if (unlikely(!blk_fs_request(host->req))) {
682+
mg_end_request_cur(host, -EIO);
678683
continue;
679684
}
680685

681-
if (rq_data_dir(req) == READ)
682-
mg_read(req);
686+
if (rq_data_dir(host->req) == READ)
687+
mg_read(host->req);
683688
else
684-
mg_write(req);
689+
mg_write(host->req);
685690
}
686691
}
687692

@@ -733,16 +738,19 @@ static unsigned int mg_issue_req(struct request *req,
733738
/* This function also called from IRQ context */
734739
static void mg_request(struct request_queue *q)
735740
{
741+
struct mg_host *host = q->queuedata;
736742
struct request *req;
737-
struct mg_host *host;
738743
u32 sect_num, sect_cnt;
739744

740745
while (1) {
741-
req = elv_next_request(q);
742-
if (!req)
743-
return;
744-
745-
host = req->rq_disk->private_data;
746+
if (!host->req) {
747+
host->req = elv_next_request(q);
748+
if (host->req)
749+
blkdev_dequeue_request(host->req);
750+
else
751+
break;
752+
}
753+
req = host->req;
746754

747755
/* check unwanted request call */
748756
if (host->mg_do_intr)
@@ -762,12 +770,12 @@ static void mg_request(struct request_queue *q)
762770
"%s: bad access: sector=%d, count=%d\n",
763771
req->rq_disk->disk_name,
764772
sect_num, sect_cnt);
765-
__blk_end_request_cur(req, -EIO);
773+
mg_end_request_cur(host, -EIO);
766774
continue;
767775
}
768776

769777
if (unlikely(!blk_fs_request(req))) {
770-
__blk_end_request_cur(req, -EIO);
778+
mg_end_request_cur(host, -EIO);
771779
continue;
772780
}
773781

@@ -981,6 +989,7 @@ static int mg_probe(struct platform_device *plat_dev)
981989
__func__, __LINE__);
982990
goto probe_err_5;
983991
}
992+
host->breq->queuedata = host;
984993

985994
/* mflash is random device, thanx for the noop */
986995
elevator_exit(host->breq->elevator);

0 commit comments

Comments
 (0)