nvme: determine the number of IO queues
PATCH 1/1 nvme: determine the number of IO queues
Some controllers support limited IO queues, when over set the number, it will return invalid field error. Then NVME will be removed by driver.
Find the max number of IO queues that controller supports. When it still got invalid result, set 1 IO queue at least to bring NVME online.
--- drivers/nvme/host/core.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
drivers/nvme/host/core.c +18 -11
@@ -1134,14 +1134,24 @@ static int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dwordint nvme_set_queue_count (struct nvme_ctrl *ctrl,int *count) { -u32 q_count = (*count -1 ) | ((*count -1 ) <<16 ); +u32 q_count;u32 result; -int status, nr_io_queues; - - status =nvme_set_features (ctrl,NVME_FEAT_NUM_QUEUES , q_count,NULL ,0 , - &result); -if (status <0 ) -return status; +int status =-1 ; +int nr_io_queues; +int try_count; + +for (try_count = *count; try_count >0 ; try_count--) { + q_count = (try_count -1 ) | ((try_count -1 ) <<16 ); + status =nvme_set_features (ctrl,NVME_FEAT_NUM_QUEUES , + q_count,NULL ,0 , &result); +if (status <0 ) +return status; +else if (status ==0 ) { + nr_io_queues =min (result &0xffff , result >>16 ) +1 ; + *count =min (try_count, nr_io_queues); +break ; + } + }/* * Degraded controllers might return an error when setting the queue
@@ -1150,10 +1160,7 @@ int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count)*/ if (status >0 ) {dev_err (ctrl->device,"Could not set queue count (%d)\n" , status); - *count =0 ; - }else { - nr_io_queues =min (result &0xffff , result >>16 ) +1 ; - *count =min (*count, nr_io_queues); + *count =1 ; }return 0 ;
Signature · 1 line
2.20.1
Quoted 7 lines · Aaron Ma
Some controllers support limited IO queues, when over set the number, it will return invalid field error. Then NVME will be removed by driver.
Find the max number of IO queues that controller supports. When it still got invalid result, set 1 IO queue at least to bring NVME online.
To be honest a spec compliant device should not need this. The spec states:
"Number of I/O Completion Queues Requested (NCQR): Indicates the number of I/O Completion
Queues requested by software. This number does not include the Admin Completion Queue. A
minimum of one queue shall be requested, reflecting that the minimum support is for one I/O
Completion Queue. This is a 0?s based value. The maximum value that may be specified is 65,534
(i.e., 65,535 I/O Completion Queues). If the value specified is 65,535, the controller should return
an error of Invalid Field in Command."
This implies that you can ask for any value and the controller must not respond with an error, but rather indicate how many queues it supports.
Maybe its better to add a quirk for the broken device, which needs this?
Best regards,
Maxim Levitsky
Quoted 27 lines · Maxim Levitsky
Quoted 7 lines · Aaron Ma
Some controllers support limited IO queues, when over set the number, it will return invalid field error. Then NVME will be removed by driver.
Find the max number of IO queues that controller supports. When it still got invalid result, set 1 IO queue at least to bring NVME online.
To be honest a spec compliant device should not need this. The spec states:
"Number of I/O Completion Queues Requested (NCQR): Indicates the number of I/O Completion
Queues requested by software. This number does not include the Admin Completion
Queue. A
minimum of one queue shall be requested, reflecting that the minimum support is
for one I/O
Completion Queue. This is a 0?s based value. The maximum value that may be specified is 65,534
(i.e., 65,535 I/O Completion Queues). If the value specified is 65,535, the controller should return
an error of Invalid Field in Command."
Quoted 5 lines
This implies that you can ask for any value and the controller must not respond
with an error, but rather indicate how many queues it supports.Maybe its better to add a quirk for the broken device, which needs this?
I forgot to add the relevant paragraph:
"Note: The value allocated may be smaller or larger than the number of queues requested, often in virtualized
implementations. The controller may not have as many queues to allocate as are requested. Alternatively,
the controller may have an allocation unit of queues (e.g. power of two) and may supply more queues to
host software to satisfy its allocation unit."
Best regards,
Maxim Levitsky
Quoted 27 lines · Maxim Levitsky
Quoted 26 lines · Maxim Levitsky
Quoted 7 lines · Aaron Ma
Some controllers support limited IO queues, when over set the number, it will return invalid field error. Then NVME will be removed by driver.
Find the max number of IO queues that controller supports. When it still got invalid result, set 1 IO queue at least to bring NVME online.
To be honest a spec compliant device should not need this. The spec states:
"Number of I/O Completion Queues Requested (NCQR): Indicates the number of I/O Completion
Queues requested by software. This number does not include the Admin Completion
Queue. A
minimum of one queue shall be requested, reflecting that the minimum support is
for one I/O
Completion Queue. This is a 0?s based value. The maximum value that may be specified is 65,534
(i.e., 65,535 I/O Completion Queues). If the value specified is 65,535, the controller should return
an error of Invalid Field in Command."
Quoted 5 lines
Quoted 5 lines
This implies that you can ask for any value and the controller must not respond
with an error, but rather indicate how many queues it supports.Maybe its better to add a quirk for the broken device, which needs this?
Adding quirk only makes the code more complicated. This patch doesn't change the default behavior. Only handle the NVME error code.
Yes the IO queues number is 0's based, but driver would return error and remove the nvme device as dead.
So set it as 1 at least the NVME can be probed properly.
Regards,
Aaron
Quoted 14 lines
I forgot to add the relevant paragraph:
"Note: The value allocated may be smaller or larger than the number of queues requested, often in virtualized
implementations. The controller may not have as many queues to allocate as are requested. Alternatively,
the controller may have an allocation unit of queues (e.g. power of two) and may supply more queues to
host software to satisfy its allocation unit."Best regards,
Maxim Levitsky
Quoted 36 lines · Aaron Ma
Quoted 35 lines · Maxim Levitsky
Quoted 34 lines · Maxim Levitsky
Quoted 7 lines · Aaron Ma
Some controllers support limited IO queues, when over set the number, it will return invalid field error. Then NVME will be removed by driver.
Find the max number of IO queues that controller supports. When it still got invalid result, set 1 IO queue at least to bring NVME online.
To be honest a spec compliant device should not need this. The spec states:
"Number of I/O Completion Queues Requested (NCQR): Indicates the number of I/O
Completion
Queues requested by software. This number does not include the Admin Completion
Queue. A
minimum of one queue shall be requested, reflecting that the minimum support
is
for one I/O
Completion Queue. This is a 0?s based value. The maximum value that may be specified is 65,534
(i.e., 65,535 I/O Completion Queues). If the value specified is 65,535, the
controller should return
an error of Invalid Field in Command."This implies that you can ask for any value and the controller must not respond
with an error, but rather indicate how many queues it supports.
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Maybe its better to add a quirk for the broken device, which needs this?
Adding quirk only makes the code more complicated. This patch doesn't change the default behavior. Only handle the NVME error code.
Yes the IO queues number is 0's based, but driver would return error and remove the nvme device as dead.
No, no, the spec says that no matter what the number queues you ask for, unless it is 65,535, the controller should not fail with an error, but rather indicate in the return value (in the completion entry) the actual number of queues it allocated which can be larger or smaller that what you asked for.
If controller returns an error, that means its firmware has a bug, which is not something unusual but usually those cases are handled with a quirk rather than with general code change.
But anyway that is just my opinion, as someone who studied and implemented (hopefully mostly correctly) the spec very recently (I am the author of nvme- mdev device).
It doesn't really matter to me if this is implemented this or another way as long as it doesn't break things.
Best regards,
Maxim Levitsky
Quoted 27 lines
So set it as 1 at least the NVME can be probed properly.
Regards,
AaronQuoted 21 lines
I forgot to add the relevant paragraph:
"Note: The value allocated may be smaller or larger than the number of queues
requested, often in virtualized
implementations. The controller may not have as many queues to allocate as are
requested. Alternatively,
the controller may have an allocation unit of queues (e.g. power of two) and may
supply more queues to
host software to satisfy its allocation unit."Best regards,
Maxim Levitsky
Quoted 32 lines · Aaron Ma
Quoted 31 lines · Maxim Levitsky
Quoted 30 lines · Maxim Levitsky
Quoted 7 lines · Aaron Ma
Some controllers support limited IO queues, when over set the number, it will return invalid field error. Then NVME will be removed by driver.
Find the max number of IO queues that controller supports. When it still got invalid result, set 1 IO queue at least to bring NVME online.
To be honest a spec compliant device should not need this. The spec states:
"Number of I/O Completion Queues Requested (NCQR): Indicates the number of I/O Completion
Queues requested by software. This number does not include the Admin Completion
Queue. A
minimum of one queue shall be requested, reflecting that the minimum support is
for one I/O
Completion Queue. This is a 0?s based value. The maximum value that may be specified is 65,534
(i.e., 65,535 I/O Completion Queues). If the value specified is 65,535, the controller should return
an error of Invalid Field in Command."This implies that you can ask for any value and the controller must not respond
with an error, but rather indicate how many queues it supports.
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Maybe its better to add a quirk for the broken device, which needs this?
Adding quirk only makes the code more complicated. This patch doesn't change the default behavior. Only handle the NVME error code.
Yes the IO queues number is 0's based, but driver would return error and remove the nvme device as dead.
IMHO, if a controller indicates an error with this set_feature command, then we need to figure out why the controller was returning the error to host.
If you really want to use at least a single queue to see an alive I/O queue, controller should not return the error because as you mentioned above, NCQA, NSQA will be returned as 0-based. If an error is there, that could mean that controller may not able to provide even a single queue for I/O.
Thanks,
Minwoo Im
Quoted 26 lines
So set it as 1 at least the NVME can be probed properly.
Regards,
AaronQuoted 11 lines
I forgot to add the relevant paragraph:
"Note: The value allocated may be smaller or larger than the number of queues requested, often in virtualized
implementations. The controller may not have as many queues to allocate as are requested. Alternatively,
the controller may have an allocation unit of queues (e.g. power of two) and may supply more queues to
host software to satisfy its allocation unit."Quoted 3 lines
Best regards,
Maxim Levitsky_______________________________________________
Linux-nvme mailing list
Linux-nvme at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 7 lines · Minwoo Im
Quoted 2 lines
Yes the IO queues number is 0's based, but driver would return error and remove the nvme device as dead.
IMHO, if a controller indicates an error with this
set_featurecommand, then
we need to figure out why the controller was returning the error to host.
Quoted 5 lines
If you really want to use at least a single queue to see an alive I/O queue,
controller should not return the error because as you mentioned above, NCQA, NSQA will be returned as 0-based.? If an error is there, that could mean that controller may not able to provide even a single queue for I/O.
I was thinking about try to set 1 I/O queue in driver to try to probe NVME device.
If it works, at least system can bootup to debug instead of just remove NVME device and kernel boot hang at loading rootfs.
If you still concern this 1 I/O queue I can still set it as *count = 0;
At least we try all count, NVME device still failed to respond.
Regards,
Aaron
Quoted 3 lines
Thanks,
Minwoo Im
Quoted 16 lines · Aaron Ma
Quoted 7 lines · Minwoo Im
Quoted 2 lines
Yes the IO queues number is 0's based, but driver would return error and remove the nvme device as dead.
IMHO, if a controller indicates an error with this
set_featurecommand, then
we need to figure out why the controller was returning the error to host.Quoted 5 lines
If you really want to use at least a single queue to see an alive I/O queue,
controller should not return the error because as you mentioned above, NCQA, NSQA will be returned as 0-based.? If an error is there, that could mean that controller may not able to provide even a single queue for I/O.
Quoted 4 lines
I was thinking about try to set 1 I/O queue in driver to try to probe NVME device.
If it works, at least system can bootup to debug instead of just remove NVME device and kernel boot hang at loading rootfs.
If the controller returns error for that command, how can we assure that the controller would support a single I/O queue ?
Quoted 12 lines
If you still concern this 1 I/O queue I can still set it as *count = 0;
At least we try all count, NVME device still failed to respond.
Regards,
AaronQuoted 3 lines
Thanks,
Minwoo Im
Quoted 2 lines · Minwoo Im
If the controller returns error for that command, how can we assure that the controller would support a single I/O queue ?
Make sense, I will keep *count = 0 in V2.
Thanks,
Aaron
Quoted 7 lines · Aaron Ma
Quoted 2 lines · Minwoo Im
If the controller returns error for that command, how can we assure that the controller would support a single I/O queue ?
Make sense, I will keep *count = 0 in V2.
IMHO, If you would like to set *count to 0, then what's gonna be V2? I guess if some device is failed, we can make it as a quirk.
Quoted 4 lines
Thanks,
Aaron
Keith Busch
maintainerQuoted 7 lines · Aaron Ma
Quoted 2 lines · Maxim Levitsky
Quoted 2 lines
Maybe its better to add a quirk for the broken device, which needs this?
Adding quirk only makes the code more complicated. This patch doesn't change the default behavior. Only handle the NVME error code.
It does change the default behavior. If I have a degraded controller that can't do IO in a machine with 1000's of CPUs, I have to iterate this non-standard behavior 1000's of times before the drive is servicable again. We currenlty figure that out in just a single try.
At least the quirks document *why* the driver is doing non-standard behavior. We do the IO queue quirks for Macbooks, for example.
But why don't you file a bug report with the device vendor instead? Surely a firmware fix provides the best possible outcome, and would make this device work not only in all versions of Linux, but also every standard compliant driver for any OS.
Quoted 5 lines · Keith Busch
It does change the default behavior. If I have a degraded controller that can't do IO in a machine with 1000's of CPUs, I have to iterate this non-standard behavior 1000's of times before the drive is servicable again. We currenlty figure that out in just a single try.
Quoted 7 lines
At least the quirks document *why* the driver is doing non-standard behavior. We do the IO queue quirks for Macbooks, for example.
But why don't you file a bug report with the device vendor instead? Surely a firmware fix provides the best possible outcome, and would make this device work not only in all versions of Linux, but also every standard compliant driver for any OS.
I will do it, no v2 for now.
Thanks,
Aaron
Quoted 11 lines · Aaron Ma
Quoted 8 lines · Keith Busch
It does change the default behavior. If I have a degraded controller that can't do IO in a machine with 1000's of CPUs, I have to iterate this non-standard behavior 1000's of times before the drive is servicable again. We currenlty figure that out in just a single try.
At least the quirks document *why* the driver is doing non-standard behavior. We do the IO queue quirks for Macbooks, for example.
Quoted 6 lines
Quoted 4 lines
But why don't you file a bug report with the device vendor instead? Surely a firmware fix provides the best possible outcome, and would make this device work not only in all versions of Linux, but also every standard compliant driver for any OS.
I will do it, no v2 for now.
Honestly, unless this is a device shiping in a max market consumer product already I don't think we should work around this crap at all, given that this device has obviously never been tested at all. It really needs a firmware fix instead of a host workaround.
Quoted 4 lines · Christoph Hellwig
Honestly, unless this is a device shiping in a max market consumer product already I don't think we should work around this crap at all, given that this device has obviously never been tested at all. It really needs a firmware fix instead of a host workaround.
Already pushed this issue to firmware eng team. They will try to fix it.
As far as I know we don't need this host workaround.
Thanks,
Aaron
Quoted 26 lines · Aaron Ma
Some controllers support limited IO queues, when over set the number, it will return invalid field error. Then NVME will be removed by driver.
Find the max number of IO queues that controller supports. When it still got invalid result, set 1 IO queue at least to bring NVME online.
Signed-off-by Aaron Ma <aaron.ma at canonical.com>--- drivers/nvme/host/core.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)drivers/nvme/host/core.c +1
-3@@ -1134,14 +1134,24 @@ static int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dwordint nvme_set_queue_count (struct nvme_ctrl *ctrl,int *count) { -u32 q_count = (*count -1 ) | ((*count -1 ) <<16 ); +u32 q_count;u32 result; -int status, nr_io_queues; -
drivers/nvme/host/core.c static int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dword · line 1144
Quoted 10 lines
drivers/nvme/host/core.c +6
-4- status =nvme_set_features (ctrl,NVME_FEAT_NUM_QUEUES , q_count,NULL ,0 , - &result); -if (status <0 ) -return status; +int status =-1 ; +int nr_io_queues; +int try_count; + +for (try_count = *count; try_count >0 ; try_count--) { + q_count = (try_count -1 ) | ((try_count -1 ) <<16 );
A macro here might help readability.
drivers/nvme/host/core.c static int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dword · line 1149
Quoted 5 lines
drivers/nvme/host/core.c +5
-0+ status =nvme_set_features (ctrl,NVME_FEAT_NUM_QUEUES , + q_count,NULL ,0 , &result); +if (status <0 ) +return status; +else if (status ==0 ) {
else following return is not needed.
drivers/nvme/host/core.c static int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dword · line 1150
Quoted 1 line
drivers/nvme/host/core.c +1
-0+ nr_io_queues =min (result &0xffff , result >>16 ) +1 ;
Likewise, a macro as above.
Ed
Quoted 20 lines
drivers/nvme/host/core.c +5
-4+ *count =min (try_count, nr_io_queues); +break ; + } + }/* * Degraded controllers might return an error when setting the queue @@ -1150,10 +1160,7 @@ int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count)*/ if (status >0 ) {dev_err (ctrl->device,"Could not set queue count (%d)\n" , status); - *count =0 ; - }else { - nr_io_queues =min (result &0xffff , result >>16 ) +1 ; - *count =min (*count, nr_io_queues); + *count =1 ; }return 0 ;
Quoted 32 lines · Edmund Nadolski (Microsoft)
Quoted 31 lines · Aaron Ma
Some controllers support limited IO queues, when over set the number, it will return invalid field error. Then NVME will be removed by driver.
Find the max number of IO queues that controller supports. When it still got invalid result, set 1 IO queue at least to bring NVME online.
Signed-off-by Aaron Ma <aaron.ma at canonical.com>---
?drivers/nvme/host/core.c| 29 ++++++++++++++++++----------- ? 1 file changed, 18 insertions(+), 11 deletions(-)drivers/nvme/host/core.c +1
-7@@ -1134,14 +1134,24 @@ static int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dword ? ? int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count) ? { -??? u32 q_count = (*count - 1) | ((*count - 1) << 16); +??? u32 q_count; ????? u32 result; -??? int status, nr_io_queues; - -??? status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES, q_count, NULL, 0, -??????????? &result); -??? if (status < 0) -??????? return status;
Quoted 8 lines
drivers/nvme/host/core.c static int nvme_set_features(struct nvme_ctrl · line 1145
Quoted 6 lines
drivers/nvme/host/core.c +6
-0+??? int status = -1; +??? int nr_io_queues; +??? int try_count; + +??? for (try_count = *count; try_count > 0; try_count--) { +??????? q_count = (try_count - 1) | ((try_count - 1) << 16);A macro here might help readability.
Will add in V2.
Quoted 8 lines
drivers/nvme/host/core.c static int nvme_set_features(struct nvme_ctrl · line 1150
Quoted 6 lines
drivers/nvme/host/core.c +5
-0+??????? status = nvme_set_features(ctrl, NVME_FEAT_NUM_QUEUES, +??????????????? q_count, NULL, 0, &result); +??????? if (status < 0) +??????????? return status; +??????? else if (status == 0) {else following return is not needed.
* 0: successful read * > 0: NVMe error status code * < 0: Linux errno error code
3 conditions should be taken care.
status > 0 will be handled after loop.
else is needed.
Quoted 5 lines
drivers/nvme/host/core.c static int nvme_set_features(struct nvme_ctrl · line 1151
Quoted 3 lines
drivers/nvme/host/core.c +1
-0+??????????? nr_io_queues = min(result & 0xffff, result >> 16) + 1;Likewise, a macro as above.
Will add in V2.
Quoted 26 lines
Ed
Quoted 21 lines
drivers/nvme/host/core.c +4
-0+??????????? *count = min(try_count, nr_io_queues); +??????????? break; +??????? } +??? }? ????? /*
?????? * Degraded controllers might return an error when setting the queuedrivers/nvme/host/core.c +0
-0@@ -1150,10 +1160,7 @@ int nvme_set_queue_count(struct nvme_ctrl *ctrl, int *count)?????? */
????? if (status > 0) {
?????????dev_err(ctrl->device, "Could not set queue count (%d)\n", status);
-??????? *count = 0;
-??? } else {
-???????nr_io_queues=min(result & 0xffff, result >> 16)+ 1; -??????? *count =min(*count, nr_io_queues);
+??????? *count = 1;
????? }
? ????? return 0;