Skip to content

Commit 3cca6dc

Browse files
author
Jens Axboe
committed
block: add API for delaying work/request_fn a little bit
Currently we use plugging for that, but as plugging is going away, we need an alternative mechanism. Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
1 parent 53f2295 commit 3cca6dc

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

‎block/blk-core.c‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,32 @@ void blk_dump_rq_flags(struct request *rq, char *msg)
197197
}
198198
EXPORT_SYMBOL(blk_dump_rq_flags);
199199

200+
static void blk_delay_work(struct work_struct *work)
201+
{
202+
struct request_queue *q;
203+
204+
q = container_of(work, struct request_queue, delay_work.work);
205+
spin_lock_irq(q->queue_lock);
206+
q->request_fn(q);
207+
spin_unlock_irq(q->queue_lock);
208+
}
209+
210+
/**
211+
* blk_delay_queue - restart queueing after defined interval
212+
* @q: The &struct request_queue in question
213+
* @msecs: Delay in msecs
214+
*
215+
* Description:
216+
* Sometimes queueing needs to be postponed for a little while, to allow
217+
* resources to come back. This function will make sure that queueing is
218+
* restarted around the specified time.
219+
*/
220+
void blk_delay_queue(struct request_queue *q, unsigned long msecs)
221+
{
222+
schedule_delayed_work(&q->delay_work, msecs_to_jiffies(msecs));
223+
}
224+
EXPORT_SYMBOL(blk_delay_queue);
225+
200226
/*
201227
* "plug" the device if there are no outstanding requests: this will
202228
* force the transfer to start only after we have put all the requests
@@ -363,6 +389,7 @@ EXPORT_SYMBOL(blk_start_queue);
363389
void blk_stop_queue(struct request_queue *q)
364390
{
365391
blk_remove_plug(q);
392+
cancel_delayed_work(&q->delay_work);
366393
queue_flag_set(QUEUE_FLAG_STOPPED, q);
367394
}
368395
EXPORT_SYMBOL(blk_stop_queue);
@@ -387,6 +414,7 @@ void blk_sync_queue(struct request_queue *q)
387414
del_timer_sync(&q->timeout);
388415
cancel_work_sync(&q->unplug_work);
389416
throtl_shutdown_timer_wq(q);
417+
cancel_delayed_work_sync(&q->delay_work);
390418
}
391419
EXPORT_SYMBOL(blk_sync_queue);
392420

@@ -534,6 +562,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
534562
INIT_LIST_HEAD(&q->flush_queue[1]);
535563
INIT_LIST_HEAD(&q->flush_data_in_flight);
536564
INIT_WORK(&q->unplug_work, blk_unplug_work);
565+
INIT_DELAYED_WORK(&q->delay_work, blk_delay_work);
537566

538567
kobject_init(&q->kobj, &blk_queue_ktype);
539568

‎include/linux/blkdev.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ struct request_queue
300300
unsigned long unplug_delay; /* After this many jiffies */
301301
struct work_struct unplug_work;
302302

303+
/*
304+
* Delayed queue handling
305+
*/
306+
struct delayed_work delay_work;
307+
303308
struct backing_dev_info backing_dev_info;
304309

305310
/*
@@ -677,6 +682,7 @@ extern int blk_insert_cloned_request(struct request_queue *q,
677682
extern void blk_plug_device(struct request_queue *);
678683
extern void blk_plug_device_unlocked(struct request_queue *);
679684
extern int blk_remove_plug(struct request_queue *);
685+
extern void blk_delay_queue(struct request_queue *, unsigned long);
680686
extern void blk_recount_segments(struct request_queue *, struct bio *);
681687
extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t,
682688
unsigned int, void __user *);

0 commit comments

Comments
 (0)