Skip to contentSkip to conversation

blk-mq-sched: allow to use hw tag for sched

PATCH In review Ming Lei 5 participants 25 messages Apr 15, 2017 – Apr 27, 2017 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

cover blk-mq-sched: allow to use hw tag for sched

The 1st patch enhances BLK_MQ_F_NO_SCHED so that we can't change/ show available io schedulers on devices which don't support io scheduler.

The 2nd patch passes BLK_MQ_F_NO_SCHED for avoiding one regression on mtip32xx, which is introduced by blk-mq io scheduler.

The last two patches introduce BLK_MQ_F_SCHED_USE_HW_TAG so that we can allow to use hardware tag for scheduler, then mq-deadline can work well on mtip32xx. Even though other devices with enough hardware tag space can benefit from this feature too.

The 1st two patches aims on v4.11, and the last two are for v4.12.

Thanks,
Ming

Ming Lei (4):
block: respect BLK_MQ_F_NO_SCHED
mtip32xx: pass BLK_MQ_F_NO_SCHED
blk-mq: introduce BLK_MQ_F_SCHED_USE_HW_TAG
mtip32xx: use BLK_MQ_F_USE_SCHED_TAG

 block/blk-mq-sched.c              | 10 +++++++++-
 block/blk-mq.c                    | 35 +++++++++++++++++++++++++++++------
 block/elevator.c                  | 12 ++++++++++--
 drivers/block/mtip32xx/mtip32xx.c |  2 +-
 include/linux/blk-mq.h            |  1 +
 5 files changed, 50 insertions(+), 10 deletions(-)
Signature · 1 line
2.9.3
author
#1 lore raw

PATCH 1/4 block: respect BLK_MQ_F_NO_SCHED

If one driver claims that it doesn't support io scheduler via BLK_MQ_F_NO_SCHED, we should not allow to change and show the availabe io schedulers.

This patch adds check to enhance this behaviour.

---
 block/elevator.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
block/elevator.c +10 -2
index dbeecf7be719..4d9084a14c10 100644
@@ -1098,12 +1098,20 @@ int elevator_change(struct request_queue *q, const char *name)
 }
 EXPORT_SYMBOL(elevator_change);
 
+static inline bool elv_support_iosched(struct request_queue *q)
+{
+	if (q->mq_ops && q->tag_set && (q->tag_set->flags &
+				BLK_MQ_F_NO_SCHED))
+		return false;
+	return true;
+}
+
 ssize_t elv_iosched_store(struct request_queue *q, const char *name,
 			  size_t count)
 {
 	int ret;
 
-	if (!(q->mq_ops || q->request_fn))
+	if (!(q->mq_ops || q->request_fn) || !elv_support_iosched(q))
 		return count;
 
 	ret = __elevator_change(q, name);
@@ -1135,7 +1143,7 @@ ssize_t elv_iosched_show(struct request_queue *q, char *name)
 			len += sprintf(name+len, "[%s] ", elv->elevator_name);
 			continue;
 		}
-		if (__e->uses_mq && q->mq_ops)
+		if (__e->uses_mq && q->mq_ops && elv_support_iosched(q))
 			len += sprintf(name+len, "%s ", __e->elevator_name);
 		else if (!__e->uses_mq && !q->mq_ops)
 			len += sprintf(name+len, "%s ", __e->elevator_name);
Signature · 1 line
2.9.3
author
#2 lore raw

PATCH 2/4 mtip32xx: pass BLK_MQ_F_NO_SCHED

In reply to Ming Lei

The recent introduced MQ IO scheduler breaks mtip32xx in the following way.

mtip32xx use the 'request_index' passed to .init_request() as hardware tag index for initializing hardware queue, and it actually require that rq->tag is always same with 'request_index' passed to .init_request(). Current blk-mq IO scheduler can't guarantee this point, so this patch passes BLK_MQ_F_NO_SCHED and at least make mtip32xx working.

This patch fixes the following strange hardware failure. The issue can be triggered easily when doing I/O with mq-deadline enabled.

[  186.972578] {1}[Hardware Error]: Hardware error from APEI Generic Hardware Error Source: 32993
[  186.972578] {1}[Hardware Error]: event severity: fatal
[  186.972579] {1}[Hardware Error]:  Error 0, type: fatal
[  186.972580] {1}[Hardware Error]:   section_type: PCIe error
[  186.972580] {1}[Hardware Error]:   port_type: 0, PCIe end point
[  186.972581] {1}[Hardware Error]:   version: 1.0
[  186.972581] {1}[Hardware Error]:   command: 0x0407, status: 0x0010
[  186.972582] {1}[Hardware Error]:   device_id: 0000:07:00.0
[  186.972582] {1}[Hardware Error]:   slot: 4
[  186.972583] {1}[Hardware Error]:   secondary_bus: 0x00
[  186.972583] {1}[Hardware Error]:   vendor_id: 0x1344, device_id: 0x5150
[  186.972584] {1}[Hardware Error]:   class_code: 008001
[  186.972585] Kernel panic - not syncing: Fatal hardware error!
---
 drivers/block/mtip32xx/mtip32xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/mtip32xx/mtip32xx.c +1 -1
index 05e3e664ea1b..4e344246c8dd 100644
@@ -3969,7 +3969,7 @@ static int mtip_block_initialize(struct driver_data *dd)
 	dd->tags.reserved_tags = 1;
 	dd->tags.cmd_size = sizeof(struct mtip_cmd);
 	dd->tags.numa_node = dd->numa_node;
-	dd->tags.flags = BLK_MQ_F_SHOULD_MERGE;
+	dd->tags.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_NO_SCHED;
 	dd->tags.driver_data = dd;
 	dd->tags.timeout = MTIP_NCQ_CMD_TIMEOUT_MS;
 
Signature · 1 line
2.9.3
author
#3 lore raw

PATCH 3/4 blk-mq: introduce BLK_MQ_F_SCHED_USE_HW_TAG

In reply to Ming Lei

Some drivers, for example of mtip32xx, use the 'request_index' passed to .init_request() as hardware tag index for initializing hardware queue, and these drivers actually require that rq->tag is always same with 'request_index' passed to .init_request().

After blk-mq I/O scheduler is in, the driver tag is allocated during dispatching, and the allocated driver tag can't be same with I/O scheduler's tag, so blk-mq I/O scheduler breaks these devices, like mtip32xx.

This patch introduces BLK_MQ_F_SCHED_USE_HW_TAG flag, and just allocate hardware tag for scheduler directly, then we can address mtip32xx's issue.

On the other hand, this feature should make blk-mq io scheduler more efficient than current way if the hardware tag space is big enough, because we can save one tag allocation/release.

---
 block/blk-mq-sched.c   | 10 +++++++++-
 block/blk-mq.c         | 35 +++++++++++++++++++++++++++++------
 include/linux/blk-mq.h |  1 +
 3 files changed, 39 insertions(+), 7 deletions(-)
block/blk-mq-sched.c +9 -1
index 9e3c0f92851b..1ff4b61135bc 100644
@@ -83,7 +83,12 @@ struct request *blk_mq_sched_get_request(struct request_queue *q,
 		data->hctx = blk_mq_map_queue(q, data->ctx->cpu);
 
 	if (e) {
-		data->flags |= BLK_MQ_REQ_INTERNAL;
+		/*
+		 * If BLK_MQ_F_SCHED_USE_HW_TAG is set, we use hardware
+		 * tag as scheduler tag.
+		 */
+		if (!(data->hctx->flags & BLK_MQ_F_SCHED_USE_HW_TAG))
+			data->flags |= BLK_MQ_REQ_INTERNAL;
 
 		/*
 		 * Flush requests are special and go directly to the
@@ -445,6 +450,9 @@ static int blk_mq_sched_alloc_tags(struct request_queue *q,
 	struct blk_mq_tag_set *set = q->tag_set;
 	int ret;
 
+	if (hctx->flags & BLK_MQ_F_SCHED_USE_HW_TAG)
+		return 0;
+
 	hctx->sched_tags = blk_mq_alloc_rq_map(set, hctx_idx, q->nr_requests,
 					       set->reserved_tags);
 	if (!hctx->sched_tags)
block/blk-mq.c +29 -6
index e536dacfae4c..ac6245bdbc8c 100644
@@ -247,9 +247,19 @@ struct request *__blk_mq_alloc_request(struct blk_mq_alloc_data *data,
 				rq->rq_flags = RQF_MQ_INFLIGHT;
 				atomic_inc(&data->hctx->nr_active);
 			}
-			rq->tag = tag;
-			rq->internal_tag = -1;
-			data->hctx->tags->rqs[rq->tag] = rq;
+			data->hctx->tags->rqs[tag] = rq;
+
+			/*
+			 * If we use hw tag for scheduling, postpone setting
+			 * rq->tag in blk_mq_get_driver_tag().
+			 */
+			if (data->hctx->flags & BLK_MQ_F_SCHED_USE_HW_TAG) {
+				rq->tag = -1;
+				rq->internal_tag = tag;
+			} else {
+				rq->tag = tag;
+				rq->internal_tag = -1;
+			}
 		}
 
 		blk_mq_rq_ctx_init(data->q, data->ctx, rq, op);
@@ -349,7 +359,7 @@ void __blk_mq_finish_request(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx,
 	clear_bit(REQ_ATOM_POLL_SLEPT, &rq->atomic_flags);
 	if (rq->tag != -1)
 		blk_mq_put_tag(hctx, hctx->tags, ctx, rq->tag);
-	if (sched_tag != -1)
+	if (sched_tag != -1 && !(hctx->flags & BLK_MQ_F_SCHED_USE_HW_TAG))
 		blk_mq_sched_completed_request(hctx, rq);
 	blk_mq_sched_restart(hctx);
 	blk_queue_exit(q);
@@ -866,6 +876,12 @@ bool blk_mq_get_driver_tag(struct request *rq, struct blk_mq_hw_ctx **hctx,
 	if (rq->tag != -1)
 		goto done;
 
+	/* we buffered driver tag in rq->internal_tag */
+	if (data.hctx->flags & BLK_MQ_F_SCHED_USE_HW_TAG) {
+		rq->tag = rq->internal_tag;
+		goto done;
+	}
+
 	if (blk_mq_tag_is_reserved(data.hctx->sched_tags, rq->internal_tag))
 		data.flags |= BLK_MQ_REQ_RESERVED;
 
@@ -887,9 +903,15 @@ bool blk_mq_get_driver_tag(struct request *rq, struct blk_mq_hw_ctx **hctx,
 static void __blk_mq_put_driver_tag(struct blk_mq_hw_ctx *hctx,
 				    struct request *rq)
 {
-	blk_mq_put_tag(hctx, hctx->tags, rq->mq_ctx, rq->tag);
+	unsigned tag = rq->tag;
+
 	rq->tag = -1;
 
+	if (hctx->flags & BLK_MQ_F_SCHED_USE_HW_TAG)
+		return;
+
+	blk_mq_put_tag(hctx, hctx->tags, rq->mq_ctx, tag);
+
 	if (rq->rq_flags & RQF_MQ_INFLIGHT) {
 		rq->rq_flags &= ~RQF_MQ_INFLIGHT;
 		atomic_dec(&hctx->nr_active);
@@ -2852,7 +2874,8 @@ bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie)
 		blk_flush_plug_list(plug, false);
 
 	hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num(cookie)];
-	if (!blk_qc_t_is_internal(cookie))
+	if (!blk_qc_t_is_internal(cookie) || (hctx->flags &
+			BLK_MQ_F_SCHED_USE_HW_TAG))
 		rq = blk_mq_tag_to_rq(hctx->tags, blk_qc_t_to_tag(cookie));
 	else
 		rq = blk_mq_tag_to_rq(hctx->sched_tags, blk_qc_t_to_tag(cookie));
include/linux/blk-mq.h +1 -0
index b90c3d5766cd..be605a05f340 100644
@@ -154,6 +154,7 @@ enum {
 	BLK_MQ_F_SG_MERGE	= 1 << 2,
 	BLK_MQ_F_BLOCKING	= 1 << 5,
 	BLK_MQ_F_NO_SCHED	= 1 << 6,
+	BLK_MQ_F_SCHED_USE_HW_TAG	= 1 << 7,
 	BLK_MQ_F_ALLOC_POLICY_START_BIT = 8,
 	BLK_MQ_F_ALLOC_POLICY_BITS = 1,
 
Signature · 1 line
2.9.3
author
#4 lore raw

PATCH 4/4 mtip32xx: use BLK_MQ_F_USE_SCHED_TAG

In reply to Ming Lei

This patch applys the new introduced flag of BLK_MQ_F_USE_SCHED_TAG to make mq-deadline working on mtip32xx. With this flag, we can allocate hardware tag for scheduler, then mtip32xx can work well.

Also mtip32xx has 256 queue depth, which is same with the default value of q->nr_requests, so in theory performance loss won't happen.

Finally BLK_MQ_F_NO_SCHED isn't necessary any more.

---
 drivers/block/mtip32xx/mtip32xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/mtip32xx/mtip32xx.c +1 -1
index 4e344246c8dd..203b18a9eff0 100644
@@ -3969,7 +3969,7 @@ static int mtip_block_initialize(struct driver_data *dd)
 	dd->tags.reserved_tags = 1;
 	dd->tags.cmd_size = sizeof(struct mtip_cmd);
 	dd->tags.numa_node = dd->numa_node;
-	dd->tags.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_NO_SCHED;
+	dd->tags.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SCHED_USE_HW_TAG;
 	dd->tags.driver_data = dd;
 	dd->tags.timeout = MTIP_NCQ_CMD_TIMEOUT_MS;
 
Signature · 1 line
2.9.3
author
#5 lore raw
In reply to Ming Lei
Quoted 7 lines · Ming Lei

The 1st patch enhances BLK_MQ_F_NO_SCHED so that we can't change/ show available io schedulers on devices which don't support io scheduler.

The 2nd patch passes BLK_MQ_F_NO_SCHED for avoiding one regression on mtip32xx, which is introduced by blk-mq io scheduler.

Quoted 7 lines

The last two patches introduce BLK_MQ_F_SCHED_USE_HW_TAG so that we can allow to use hardware tag for scheduler, then mq-deadline can work well on mtip32xx. Even though other devices with enough hardware tag space can benefit from this feature too.

The 1st two patches aims on v4.11, and the last two are for v4.12.

Please ignore this patchset, and I will post another serial for mtip32xx fix.

thanks,
Ming

#6 lore raw
Quoted 13 lines · Ming Lei
Quoted 12 lines · Ming Lei

The 1st patch enhances BLK_MQ_F_NO_SCHED so that we can't change/ show available io schedulers on devices which don't support io scheduler.

The 2nd patch passes BLK_MQ_F_NO_SCHED for avoiding one regression on mtip32xx, which is introduced by blk-mq io scheduler.

The last two patches introduce BLK_MQ_F_SCHED_USE_HW_TAG so that we can allow to use hardware tag for scheduler, then mq-deadline can work well on mtip32xx. Even though other devices with enough hardware tag space can benefit from this feature too.

Quoted 8 lines
Quoted 2 lines

The 1st two patches aims on v4.11, and the last two are for v4.12.

Please ignore this patchset, and I will post another serial for mtip32xx fix.

thanks,
Ming

Regardless of the mtip32xx fix, I actually wanted to skip the scheduler tags when possible just for performance reasons. I don't think that should be a device-specific setting. We can let the I/O scheduler decide how many tags it wants, and if the device has at least that many tags, just use the hardware tags directly. I'll probably look at doing that for 4.13, we'll see if it actually makes a performance difference.

author
#7 lore raw
Quoted 23 lines · Omar Sandoval
Quoted 13 lines · Ming Lei
Quoted 12 lines · Ming Lei

The 1st patch enhances BLK_MQ_F_NO_SCHED so that we can't change/ show available io schedulers on devices which don't support io scheduler.

The 2nd patch passes BLK_MQ_F_NO_SCHED for avoiding one regression on mtip32xx, which is introduced by blk-mq io scheduler.

The last two patches introduce BLK_MQ_F_SCHED_USE_HW_TAG so that we can allow to use hardware tag for scheduler, then mq-deadline can work well on mtip32xx. Even though other devices with enough hardware tag space can benefit from this feature too.

Quoted 8 lines
Quoted 2 lines

The 1st two patches aims on v4.11, and the last two are for v4.12.

Please ignore this patchset, and I will post another serial for mtip32xx fix.

thanks,
Ming

Quoted 6 lines

Regardless of the mtip32xx fix, I actually wanted to skip the scheduler tags when possible just for performance reasons. I don't think that should be a device-specific setting. We can let the I/O scheduler decide how many tags it wants, and if the device has at least that many tags, just use the hardware tags directly. I'll probably look at doing that for 4.13, we'll see if it actually makes a performance difference.

Yes, I thought about that too, the following policy may be applied at default:

- if queue depth is not less than q->nr_requests and
- the tag space isn't shared

We still can keep the flag of BLK_MQ_F_SCHED_USE_HW_TAG so that drivers can decide if they want to do that, since I guess it may help some shared tag cases too.

Now the mtip32xx fix has been sent out already, I will post this patchset of using hw tag for scheduler out soon for review.

Thanks,
Ming

#8 lore raw
In reply to Ming Lei
Quoted 6 lines · Ming Lei

The 1st patch enhances BLK_MQ_F_NO_SCHED so that we can't change/ show available io schedulers on devices which don't support io scheduler.

The 2nd patch passes BLK_MQ_F_NO_SCHED for avoiding one regression on mtip32xx, which is introduced by blk-mq io scheduler.

I've added 1-2 for 4.11 for now, and then let's plan on getting a real fix done for 4.12.

Signature · 1 line
Jens Axboe
author
#9 lore raw
Quoted 10 lines · Jens Axboe
Quoted 6 lines · Ming Lei

The 1st patch enhances BLK_MQ_F_NO_SCHED so that we can't change/ show available io schedulers on devices which don't support io scheduler.

The 2nd patch passes BLK_MQ_F_NO_SCHED for avoiding one regression on mtip32xx, which is introduced by blk-mq io scheduler.

I've added 1-2 for 4.11 for now, and then let's plan on getting a real fix done for 4.12.

The real fix has been posted out already:

	http://marc.info/?t=149256196700001&r=1&w=2

Could you consider that for 4.12?

Thanks,
Ming

#10 lore raw
Quoted 9 lines · Ming Lei
Quoted 8 lines · Jens Axboe
Quoted 6 lines · Ming Lei

The 1st patch enhances BLK_MQ_F_NO_SCHED so that we can't change/ show available io schedulers on devices which don't support io scheduler.

The 2nd patch passes BLK_MQ_F_NO_SCHED for avoiding one regression on mtip32xx, which is introduced by blk-mq io scheduler.

Quoted 8 lines
Quoted 2 lines

I've added 1-2 for 4.11 for now, and then let's plan on getting a real fix done for 4.12.

The real fix has been posted out already:

	http://marc.info/?t=149256196700001&r=1&w=2

Could you consider that for 4.12?

I didn't particularly like that approach. And we are really late in the 4.11 cycle, and your first two patches fit the bill for how we should fix it in the interim.

I'll take a closer look for 4.12, I want to get this fixed for real, obviously.

Signature · 1 line
Jens Axboe
author
#11 lore raw
Quoted 15 lines · Jens Axboe
Quoted 14 lines · Ming Lei
Quoted 10 lines · Jens Axboe
Quoted 6 lines · Ming Lei

The 1st patch enhances BLK_MQ_F_NO_SCHED so that we can't change/ show available io schedulers on devices which don't support io scheduler.

The 2nd patch passes BLK_MQ_F_NO_SCHED for avoiding one regression on mtip32xx, which is introduced by blk-mq io scheduler.

I've added 1-2 for 4.11 for now, and then let's plan on getting a real fix done for 4.12.

The real fix has been posted out already:

Quoted 7 lines
Quoted 3 lines
	http://marc.info/?t=149256196700001&r=1&w=2

Could you consider that for 4.12?

I didn't particularly like that approach. And we are really late in the 4.11 cycle, and your first two patches fit the bill for how we should fix it in the interim.

If we don't need to reserve tag for internal command, I am happy to fix it in the interim. However, the mtip32xx driver has to ask blk-mq to reserve the tag zero for internal command. Then if we can't allow the driver to use that reserved tag, it looks quite awkward, doesn't it?

Quoted 2 lines

I'll take a closer look for 4.12, I want to get this fixed for real, obviously.

OK, thanks, let's discuss on solutions.

Thanks,
Ming

#12 lore raw
Quoted 5 lines · Ming Lei

If we don't need to reserve tag for internal command, I am happy to fix it in the interim. However, the mtip32xx driver has to ask blk-mq to reserve the tag zero for internal command. Then if we can't allow the driver to use that reserved tag, it looks quite awkward, doesn't it?

It doesn't. Just offset the hardware tags by 1 from the blk-mq tags.

But I'm pretty sure the hardware wouldn't require a specific tag for the internal ops.

author
#13 lore raw

Hi Christoph,

Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · Ming Lei

If we don't need to reserve tag for internal command, I am happy to fix it in the interim. However, the mtip32xx driver has to ask blk-mq to reserve the tag zero for internal command. Then if we can't allow the driver to use that reserved tag, it looks quite awkward, doesn't it?

Quoted 6 lines

It doesn't. Just offset the hardware tags by 1 from the blk-mq tags.

But I'm pretty sure the hardware wouldn't require a specific tag for the internal ops.

From mtip32xx code, the tag 0 is used to send internal command only, and

not used for submitting normal request.

Quoted 1 line

From code of mtip_issue_non_ncq_command() and mtip_issue_ncq_command(),

even same hardware address is writen to when issuing non-ncq and ncq commands. So I think the internal ops and normal requests share one same tag space on mtip32xx.

Could you explain it a bit why you think the hw doesn't need the tag for internal ops in this case?

Thanks,
Ming

#23 lore raw
In reply to Christoph Hellwig
Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · Ming Lei

If we don't need to reserve tag for internal command, I am happy to fix it in the interim. However, the mtip32xx driver has to ask blk-mq to reserve the tag zero for internal command. Then if we can't allow the driver to use that reserved tag, it looks quite awkward, doesn't it?

It doesn't. Just offset the hardware tags by 1 from the blk-mq tags.

But I'm pretty sure the hardware wouldn't require a specific tag for the internal ops.

Right, the hardware doesn't require it at all, it's just an oddity of the driver that it hardwares tag 0 as an internal tag. That could definitely get cleaned up.

Signature · 1 line
Jens Axboe
#24 lore raw
Quoted 3 lines · Jens Axboe

Right, the hardware doesn't require it at all, it's just an oddity of the driver that it hardwares tag 0 as an internal tag. That could definitely get cleaned up.

That's exactly what I suspect, especially as the hardware is AHCI on stereoids. But I'd need a data sheet to confirm my suspicion.

author
#14 lore raw
In reply to Ming Lei

Hi Christoph,

Quoted 18 lines · Ming Lei

Hi Christoph,

Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · Ming Lei

If we don't need to reserve tag for internal command, I am happy to fix it in the interim. However, the mtip32xx driver has to ask blk-mq to reserve the tag zero for internal command. Then if we can't allow the driver to use that reserved tag, it looks quite awkward, doesn't it?

It doesn't. Just offset the hardware tags by 1 from the blk-mq tags.

But I'm pretty sure the hardware wouldn't require a specific tag for the internal ops.

From mtip32xx code, the tag 0 is used to send internal command only, and not used for submitting normal request.

Quoted 7 lines

From code of mtip_issue_non_ncq_command() and mtip_issue_ncq_command(), even same hardware address is writen to when issuing non-ncq and ncq commands. So I think the internal ops and normal requests share one same tag space on mtip32xx.

Could you explain it a bit why you think the hw doesn't need the tag for internal ops in this case?

Gentle ping...

Looks there are some choices for this issue:

1) if internal ops uses independent tag space
- we need to clean up the mtip32xx driver

2) if internal ops shares tag space with normal request
- export blk_mq_get_driver_tag() for mtip32xx

or

- use private way to send internal ops, and the drawback is that we still need to reserve tag and the reserved tag can't be used at all.

Quoted 1 line

From mtip32xx source code, I can see both share same tag space.

When I try to search hw manual via google, not succeed yet.

Christoph, could you share us your findings about if internal ops uses independent tag space or not?

Thanks,
Ming

maintainer
#15 lore raw
Quoted 45 lines · Ming Lei

Hi Christoph,

Quoted 18 lines · Ming Lei

Hi Christoph,

Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · Ming Lei

If we don't need to reserve tag for internal command, I am happy to fix it in the interim. However, the mtip32xx driver has to ask blk-mq to reserve the tag zero for internal command. Then if we can't allow the driver to use that reserved tag, it looks quite awkward, doesn't it?

It doesn't. Just offset the hardware tags by 1 from the blk-mq tags.

But I'm pretty sure the hardware wouldn't require a specific tag for the internal ops.

From mtip32xx code, the tag 0 is used to send internal command only, and not used for submitting normal request.

Quoted 7 lines

From code of mtip_issue_non_ncq_command() and mtip_issue_ncq_command(), even same hardware address is writen to when issuing non-ncq and ncq commands. So I think the internal ops and normal requests share one same tag space on mtip32xx.

Could you explain it a bit why you think the hw doesn't need the tag for internal ops in this case?

Gentle ping...

Looks there are some choices for this issue:

1) if internal ops uses independent tag space
- we need to clean up the mtip32xx driver

2) if internal ops shares tag space with normal request
- export blk_mq_get_driver_tag() for mtip32xx

or

- use private way to send internal ops, and the drawback is that we still need to reserve tag and the reserved tag can't be used at all.

Quoted 5 lines

From mtip32xx source code, I can see both share same tag space. When I try to search hw manual via google, not succeed yet.

Christoph, could you share us your findings about if internal ops uses independent tag space or not?

Why aren't we just bypassing for RESERVED? If someone is asking for an reserved tag, ensure that we use the right tag pool (sched vs normal) and sub pool (reserved vs normal). Then insert just bypasses the scheduler, like it already does if we have a driver tag assigned already.

I've got a few of these cards, but traveling. I'll wire up something and test it end this week.

Signature · 1 line
Jens Axboe
maintainer
#16 lore raw
Quoted 52 lines · Jens Axboe
Quoted 45 lines · Ming Lei

Hi Christoph,

Quoted 18 lines · Ming Lei

Hi Christoph,

Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · Ming Lei

If we don't need to reserve tag for internal command, I am happy to fix it in the interim. However, the mtip32xx driver has to ask blk-mq to reserve the tag zero for internal command. Then if we can't allow the driver to use that reserved tag, it looks quite awkward, doesn't it?

It doesn't. Just offset the hardware tags by 1 from the blk-mq tags.

But I'm pretty sure the hardware wouldn't require a specific tag for the internal ops.

From mtip32xx code, the tag 0 is used to send internal command only, and not used for submitting normal request.

Quoted 7 lines

From code of mtip_issue_non_ncq_command() and mtip_issue_ncq_command(), even same hardware address is writen to when issuing non-ncq and ncq commands. So I think the internal ops and normal requests share one same tag space on mtip32xx.

Could you explain it a bit why you think the hw doesn't need the tag for internal ops in this case?

Gentle ping...

Looks there are some choices for this issue:

1) if internal ops uses independent tag space
- we need to clean up the mtip32xx driver

2) if internal ops shares tag space with normal request
- export blk_mq_get_driver_tag() for mtip32xx

or

- use private way to send internal ops, and the drawback is that we still need to reserve tag and the reserved tag can't be used at all.

Quoted 5 lines

From mtip32xx source code, I can see both share same tag space. When I try to search hw manual via google, not succeed yet.

Christoph, could you share us your findings about if internal ops uses independent tag space or not?

Quoted 8 lines

Why aren't we just bypassing for RESERVED? If someone is asking for an reserved tag, ensure that we use the right tag pool (sched vs normal) and sub pool (reserved vs normal). Then insert just bypasses the scheduler, like it already does if we have a driver tag assigned already.

I've got a few of these cards, but traveling. I'll wire up something and test it end this week.

Something like this. Totally untested.

block/blk-mq-sched.c +5 -1
index c974a1bbf4cb..11109b5b64b6 100644
@@ -119,7 +119,11 @@ struct request *blk_mq_sched_get_request(struct request_queue *q,
 	if (likely(!data->hctx))
 		data->hctx = blk_mq_map_queue(q, data->ctx->cpu);
 
-	if (e) {
+	/*
+	 * For a reserved tag, allocate a normal request since we might
+	 * have driver dependencies on the value of the internal tag.
+	 */
+	if (e && !(data->flags & BLK_MQ_REQ_RESERVED)) {
 		data->flags |= BLK_MQ_REQ_INTERNAL;
 
 		/*
Signature · 1 line
Jens Axboe
author Tested-by
#17 lore raw
Quoted 71 lines · Jens Axboe
Quoted 52 lines · Jens Axboe
Quoted 45 lines · Ming Lei

Hi Christoph,

Quoted 18 lines · Ming Lei

Hi Christoph,

Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · Ming Lei

If we don't need to reserve tag for internal command, I am happy to fix it in the interim. However, the mtip32xx driver has to ask blk-mq to reserve the tag zero for internal command. Then if we can't allow the driver to use that reserved tag, it looks quite awkward, doesn't it?

It doesn't. Just offset the hardware tags by 1 from the blk-mq tags.

But I'm pretty sure the hardware wouldn't require a specific tag for the internal ops.

From mtip32xx code, the tag 0 is used to send internal command only, and not used for submitting normal request.

Quoted 7 lines

From code of mtip_issue_non_ncq_command() and mtip_issue_ncq_command(), even same hardware address is writen to when issuing non-ncq and ncq commands. So I think the internal ops and normal requests share one same tag space on mtip32xx.

Could you explain it a bit why you think the hw doesn't need the tag for internal ops in this case?

Gentle ping...

Looks there are some choices for this issue:

1) if internal ops uses independent tag space
- we need to clean up the mtip32xx driver

2) if internal ops shares tag space with normal request
- export blk_mq_get_driver_tag() for mtip32xx

or

- use private way to send internal ops, and the drawback is that we still need to reserve tag and the reserved tag can't be used at all.

Quoted 5 lines

From mtip32xx source code, I can see both share same tag space. When I try to search hw manual via google, not succeed yet.

Christoph, could you share us your findings about if internal ops uses independent tag space or not?

Quoted 8 lines

Why aren't we just bypassing for RESERVED? If someone is asking for an reserved tag, ensure that we use the right tag pool (sched vs normal) and sub pool (reserved vs normal). Then insert just bypasses the scheduler, like it already does if we have a driver tag assigned already.

I've got a few of these cards, but traveling. I'll wire up something and test it end this week.

Something like this. Totally untested.

block/blk-mq-sched.c +0 -0
index c974a1bbf4cb..11109b5b64b6 100644
@@ -119,7 +119,11 @@ struct request *blk_mq_sched_get_request(struct request_queue *q,
 	if (likely(!data->hctx))
 		data->hctx = blk_mq_map_queue(q, data->ctx->cpu);

block/blk-mq-sched.c struct request *blk_mq_sched_get_request(struct request_queue *q, · line 129

Quoted 10 lines
block/blk-mq-sched.c +5 -1
 
-	if (e) {
+	/*
+	 * For a reserved tag, allocate a normal request since we might
+	 * have driver dependencies on the value of the internal tag.
+	 */
+	if (e && !(data->flags & BLK_MQ_REQ_RESERVED)) {
 		data->flags |= BLK_MQ_REQ_INTERNAL;
 
 		/*

This one looks reasonable, since reserved rqs often needn't scheduling, also works well on mtip32xx with another patch[1] together.

[1] http://marc.info/?l=linux-block&m=149256194703481&w=2

Thanks,
Ming

#22 lore raw
In reply to Ming Lei
Quoted 5 lines · Ming Lei

Looks there are some choices for this issue:

1) if internal ops uses independent tag space
- we need to clean up the mtip32xx driver

Quoted 8 lines

2) if internal ops shares tag space with normal request
- export blk_mq_get_driver_tag() for mtip32xx

or

- use private way to send internal ops, and the drawback is that we still need to reserve tag and the reserved tag can't be used at all.

The fundamental problem in mtip is that it uses the block layer to allocate requests, but not to issue them. Either it needs to switch to use blk_execute_rq(_nowait) to issue the command, or it needs to stop using blk_mq_alloc_request to allocatate the internal commands. Everything else is a layering violation just asking for more problems down the road.

Quoted 6 lines
Quoted 2 lines

From mtip32xx source code, I can see both share same tag space.

When I try to search hw manual via google, not succeed yet.

Christoph, could you share us your findings about if internal ops uses independent tag space or not?

As said earlier in the thread - mtip32xx is a beefed up AHCI design, and the internal commands issued are bog standard ATA commands. So I would be very surprised if the hardware requires a specific tag. The way the driver is written it might very well expect a tag to be set aside, though.

maintainer
#18 lore raw
In reply to Ming Lei
Quoted 81 lines · Ming Lei
Quoted 80 lines · Jens Axboe
Quoted 52 lines · Jens Axboe
Quoted 45 lines · Ming Lei

Hi Christoph,

Quoted 18 lines · Ming Lei

Hi Christoph,

Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · Ming Lei

If we don't need to reserve tag for internal command, I am happy to fix it in the interim. However, the mtip32xx driver has to ask blk-mq to reserve the tag zero for internal command. Then if we can't allow the driver to use that reserved tag, it looks quite awkward, doesn't it?

It doesn't. Just offset the hardware tags by 1 from the blk-mq tags.

But I'm pretty sure the hardware wouldn't require a specific tag for the internal ops.

From mtip32xx code, the tag 0 is used to send internal command only, and not used for submitting normal request.

Quoted 7 lines

From code of mtip_issue_non_ncq_command() and mtip_issue_ncq_command(), even same hardware address is writen to when issuing non-ncq and ncq commands. So I think the internal ops and normal requests share one same tag space on mtip32xx.

Could you explain it a bit why you think the hw doesn't need the tag for internal ops in this case?

Gentle ping...

Looks there are some choices for this issue:

1) if internal ops uses independent tag space
- we need to clean up the mtip32xx driver

2) if internal ops shares tag space with normal request
- export blk_mq_get_driver_tag() for mtip32xx

or

- use private way to send internal ops, and the drawback is that we still need to reserve tag and the reserved tag can't be used at all.

Quoted 5 lines

From mtip32xx source code, I can see both share same tag space. When I try to search hw manual via google, not succeed yet.

Christoph, could you share us your findings about if internal ops uses independent tag space or not?

Quoted 8 lines

Why aren't we just bypassing for RESERVED? If someone is asking for an reserved tag, ensure that we use the right tag pool (sched vs normal) and sub pool (reserved vs normal). Then insert just bypasses the scheduler, like it already does if we have a driver tag assigned already.

I've got a few of these cards, but traveling. I'll wire up something and test it end this week.

Something like this. Totally untested.

block/blk-mq-sched.c +5 -1
index c974a1bbf4cb..11109b5b64b6 100644
@@ -119,7 +119,11 @@ struct request *blk_mq_sched_get_request(struct request_queue *q,
 	if (likely(!data->hctx))
 		data->hctx = blk_mq_map_queue(q, data->ctx->cpu);
 
-	if (e) {
+	/*
+	 * For a reserved tag, allocate a normal request since we might
+	 * have driver dependencies on the value of the internal tag.
+	 */
+	if (e && !(data->flags & BLK_MQ_REQ_RESERVED)) {
 		data->flags |= BLK_MQ_REQ_INTERNAL;
 
Quoted 6 lines

block/blk-mq-sched.c struct request *blk_mq_sched_get_request(struct request_queue *q, · line 129

Quoted 1 line
block/blk-mq-sched.c +0 -0
 		/*

This one looks reasonable, since reserved rqs often needn't scheduling, also works well on mtip32xx with another patch[1] together.

Thanks Ming, I've added that patch and your patch to initialize the cmd at runtime. Queued up for 4.12. Once 4.12 opens and it gets merged with master, I'll queue up a revert of:

commit 4981d04dd8f1ab19e2cce008da556d7f099b6e68

Author: Ming Lei <[email protected]>
Date:   Sat Apr 15 20:38:23 2017 +0800

mtip32xx: pass BLK_MQ_F_NO_SCHED

Signature · 1 line
Jens Axboe
#19 lore raw
Quoted 2 lines · Jens Axboe

Thanks Ming, I've added that patch and your patch to initialize the cmd at runtime.

I really think this is the wrong fix, and doing these sort of band-aids just will lead to further problems done the road.

maintainer
#20 lore raw
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Jens Axboe

Thanks Ming, I've added that patch and your patch to initialize the cmd at runtime.

I really think this is the wrong fix, and doing these sort of band-aids just will lead to further problems done the road.

Ming's patch is just fine, mine is a bit more of a hack. I'll throw some cycles at fixing up mtip32xx to not have a hard wired internal tag since it doesn't need to, and then we can drop my one-liner again.

Signature · 1 line
Jens Axboe
maintainer
#21 lore raw
Quoted 11 lines · Jens Axboe
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Jens Axboe

Thanks Ming, I've added that patch and your patch to initialize the cmd at runtime.

I really think this is the wrong fix, and doing these sort of band-aids just will lead to further problems done the road.

Ming's patch is just fine, mine is a bit more of a hack. I'll throw some cycles at fixing up mtip32xx to not have a hard wired internal tag since it doesn't need to, and then we can drop my one-liner again.

Something like this, to keep it simple. This allows us to drop the requirement that RESERVED requests bypass the normal insertion logic, and converts mtip32xx to go through queue_rq for internal commands. Quiesce of NCQ tags is done with busy backoff from queue_rq.

We don't really care about the value of the tag at this point, but since we KNOW it's a reserved request, I did not rewrite the fact that we hard code 0 as the internal tag. I think it's safer this way.

Compiles...

block/blk-mq-sched.c +3 -5
index 8b361e1..27c6746 100644
@@ -82,11 +82,7 @@ struct request *blk_mq_sched_get_request(struct request_queue *q,
 	if (likely(!data->hctx))
 		data->hctx = blk_mq_map_queue(q, data->ctx->cpu);
 
-	/*
-	 * For a reserved tag, allocate a normal request since we might
-	 * have driver dependencies on the value of the internal tag.
-	 */
-	if (e && !(data->flags & BLK_MQ_REQ_RESERVED)) {
+	if (e) {
 		data->flags |= BLK_MQ_REQ_INTERNAL;
 
 		/*
@@ -104,6 +100,8 @@ struct request *blk_mq_sched_get_request(struct request_queue *q,
 	}
 
 	if (rq) {
+		if (data->flags & BLK_MQ_REQ_RESERVED)
+			rq->rq_flags |= RQF_RESERVED;
 		if (!op_is_flush(op)) {
 			rq->elv.icq = NULL;
 			if (e && e->type->icq_cache)
block/blk-mq.c +3 -0
index b75ef23..0168b27 100644
@@ -268,6 +268,9 @@ struct request *__blk_mq_alloc_request(struct blk_mq_alloc_data *data,
 			data->hctx->tags->rqs[rq->tag] = rq;
 		}
 
+		if (data->flags & BLK_MQ_REQ_RESERVED)
+			rq->rq_flags |= RQF_RESERVED;
+
 		blk_mq_rq_ctx_init(data->q, data->ctx, rq, op);
 		return rq;
 	}
drivers/block/mtip32xx/mtip32xx.c +119 -162

447 lines not on this page · raw message

include/linux/blkdev.h +2 -0
index ba3884f..c246de5 100644
@@ -120,6 +120,8 @@ typedef __u32 __bitwise req_flags_t;
 /* Look at ->special_vec for the actual data payload instead of the
    bio chain. */
 #define RQF_SPECIAL_PAYLOAD	((__force req_flags_t)(1 << 18))
+/* Request came from the reserved tags/pool */
+#define RQF_RESERVED		((__force req_flags_t)(1 << 19))
 
 /* flags that prevent us from merging requests: */
 #define RQF_NOMERGE_FLAGS \
Signature · 1 line
Jens Axboe