Skip to contentSkip to conversation

null_blk: prevent timer handler running on a different CPU where started

PATCH Applied Akinobu Mita 2 participants 4 messages Jun 1, 2015 – Jun 2, 2015 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 null_blk: prevent timer handler running on a different CPU where started

When irqmode=2 (IRQ completion handler is timer), timer handler should be called on the same CPU where the timer has been started.

Since completion_queues are per-cpu and the completion handler only touches completion_queue for local CPU, we need to prevent the handler from running on a different CPU where the timer has been started. Otherwise, the IO cannot be completed until another completion handler is executed on that CPU.

---
 drivers/block/null_blk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/null_blk.c +1 -1
index 65cd61a..6f0a58e 100644
@@ -257,7 +257,7 @@ static void null_cmd_end_timer(struct nullb_cmd *cmd)
 	if (llist_add(&cmd->ll_list, &cq->list)) {
 		ktime_t kt = ktime_set(0, completion_nsec);
 
-		hrtimer_start(&cq->timer, kt, HRTIMER_MODE_REL);
+		hrtimer_start(&cq->timer, kt, HRTIMER_MODE_REL_PINNED);
 	}
 
 	put_cpu();
Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/2 null_blk: restart request processing on completion handler

When irqmode=2 (IRQ completion handler is timer) and queue_mode=1 (Block interface to use is rq), the completion handler should restart request handling for any pending requests on a queue because request processing stops when the number of commands are queued more than hw_queue_depth (null_rq_prep_fn returns BLKPREP_DEFER).

Without this change, the following command cannot finish.

	# modprobe null_blk irqmode=2 queue_mode=1 hw_queue_depth=1
	# fio --name=t --rw=read --size=1g --direct=1 \
	  --ioengine=libaio --iodepth=64 --filename=/dev/nullb0
---
 drivers/block/null_blk.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/block/null_blk.c +12 -0
index 6f0a58e..6f9b753 100644
@@ -243,6 +243,17 @@ static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer)
 			cmd = container_of(entry, struct nullb_cmd, ll_list);
 			entry = entry->next;
 			end_cmd(cmd);
+
+			if (cmd->rq) {
+				struct request_queue *q = cmd->rq->q;
+
+				if (!q->mq_ops && blk_queue_stopped(q)) {
+					spin_lock(q->queue_lock);
+					if (blk_queue_stopped(q))
+						blk_start_queue(q);
+					spin_unlock(q->queue_lock);
+				}
+			}
 		} while (entry);
 	}
 
@@ -334,6 +345,7 @@ static int null_rq_prep_fn(struct request_queue *q, struct request *req)
 		req->special = cmd;
 		return BLKPREP_OK;
 	}
+	blk_stop_queue(q);
 
 	return BLKPREP_DEFER;
 }
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH 2/2] null_blk: restart request processing on completion handler

2015-06-02 8:35 GMT+09:00 Akinobu Mita <[email protected]>:

Quoted 24 lines

When irqmode=2 (IRQ completion handler is timer) and queue_mode=1 (Block interface to use is rq), the completion handler should restart request handling for any pending requests on a queue because request processing stops when the number of commands are queued more than hw_queue_depth (null_rq_prep_fn returns BLKPREP_DEFER).

Without this change, the following command cannot finish.

        # modprobe null_blk irqmode=2 queue_mode=1 hw_queue_depth=1
        # fio --name=t --rw=read --size=1g --direct=1 \
          --ioengine=libaio --iodepth=64 --filename=/dev/nullb0
---
 drivers/block/null_blk.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/block/null_blk.c +0 -0
index 6f0a58e..6f9b753 100644
@@ -243,6 +243,17 @@ static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer)
                        cmd = container_of(entry, struct nullb_cmd, ll_list);

drivers/block/null_blk.c static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer) · line 253

Quoted 10 lines
drivers/block/null_blk.c +8 -0
                        entry = entry->next;
                        end_cmd(cmd);
+
+                       if (cmd->rq) {
+                               struct request_queue *q = cmd->rq->q;
+
+                               if (!q->mq_ops && blk_queue_stopped(q)) {
+                                       spin_lock(q->queue_lock);
+                                       if (blk_queue_stopped(q))
+                                               blk_start_queue(q);

Should 'blk_start_queue(q)' be:

                queue_flag_clear(QUEUE_FLAG_STOPPED, q);
                blk_run_queue_async(q);

?

Otherwise, all pending requests on a queue are completed by this timer handler execution without needing next timer expiry.

Quoted 17 lines
drivers/block/null_blk.c +4 -1
+                                       spin_unlock(q->queue_lock);
+                               }
+                       }
                } while (entry);
        }
 
@@ -334,6 +345,7 @@ static int null_rq_prep_fn(struct request_queue *q, struct request *req)
                req->special = cmd;
                return BLKPREP_OK;
        }
+       blk_stop_queue(q);
 
        return BLKPREP_DEFER;
 }
--

1.9.1

Applied
#3 lore raw
In reply to Akinobu Mita
Quoted 8 lines · Akinobu Mita

When irqmode=2 (IRQ completion handler is timer), timer handler should be called on the same CPU where the timer has been started.

Since completion_queues are per-cpu and the completion handler only touches completion_queue for local CPU, we need to prevent the handler from running on a different CPU where the timer has been started. Otherwise, the IO cannot be completed until another completion handler is executed on that CPU.

Thanks, applied this and 2/2, the latter seems to have been forgotten after our initial discussion about it.

Signature · 1 line
Jens Axboe