Skip to contentSkip to conversation

mmc: fix async request mechanism for sequential read scenarios

PATCH Konstantin Dorfman 5 participants 23 messages Oct 24, 2012 – Nov 26, 2012 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

Hello Per,

Quoted 21 lines · Per Forlin
Quoted 8 lines

When mmcqt reports on completion of a request there should be a context switch to allow the insertion of the next read ahead BIOs to the block layer. Since the mmcqd tries to fetch another request immediately after the completion of the previous request it gets NULL and starts waiting for the completion of the previous request. This wait on completion gives the FS the opportunity to insert the next request but the MMC layer is already blocked on the previous request completion and is not aware of the new request waiting to be fetched.

I thought that I could trigger a context switch in order to give execution time for FS to add the new request to the MMC queue. I made a simple hack to call yield() in case the request gets NULL. I thought it may give the FS layer enough time to add a new request to the MMC queue. This would not delay the MMC transfer since the yield() is done in parallel with an ongoing transfer. Anyway it was just meant to be a simple test.

One yield was not enough. Just for sanity check I added a msleep as well and that was enough to let FS add a new request, Would it be possible to gain throughput by delaying the fetch of new request? Too avoid unnecessary NULL requests

Quoted 5 lines

If (ongoing request is read AND size is max read ahead AND new request is NULL) yield();

BR
Per

We did the same experiment and it will not give maximum possible performance. There is no guarantee that the context switch which was manually caused by the MMC layer comes just in time: when it was early then next fetch still results in NULL, when it was later, then we miss possibility to fetch/prepare new request.

Any delay in fetch of the new request that comes after the new request has arrived hits throughput and latency.

The solution we are talking about here will fix not only situation with FS read ahead mechanism, but also it will remove penalty of the MMC context waiting on completion while any new request arrives.

Thanks,

Signature · 3 lines
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw
Quoted 35 lines · Konstantin Dorfman

Hello Per,

Quoted 21 lines · Per Forlin
Quoted 8 lines

When mmcqt reports on completion of a request there should be a context switch to allow the insertion of the next read ahead BIOs to the block layer. Since the mmcqd tries to fetch another request immediately after the completion of the previous request it gets NULL and starts waiting for the completion of the previous request. This wait on completion gives the FS the opportunity to insert the next request but the MMC layer is already blocked on the previous request completion and is not aware of the new request waiting to be fetched.

I thought that I could trigger a context switch in order to give execution time for FS to add the new request to the MMC queue. I made a simple hack to call yield() in case the request gets NULL. I thought it may give the FS layer enough time to add a new request to the MMC queue. This would not delay the MMC transfer since the yield() is done in parallel with an ongoing transfer. Anyway it was just meant to be a simple test.

One yield was not enough. Just for sanity check I added a msleep as well and that was enough to let FS add a new request, Would it be possible to gain throughput by delaying the fetch of new request? Too avoid unnecessary NULL requests

Quoted 5 lines

If (ongoing request is read AND size is max read ahead AND new request is NULL) yield();

BR
Per

We did the same experiment and it will not give maximum possible performance. There is no guarantee that the context switch which was manually caused by the MMC layer comes just in time: when it was early then next fetch still results in NULL, when it was later, then we miss possibility to fetch/prepare new request.

Quoted 9 lines

Any delay in fetch of the new request that comes after the new request has arrived hits throughput and latency.

The solution we are talking about here will fix not only situation with FS read ahead mechanism, but also it will remove penalty of the MMC context waiting on completion while any new request arrives.

Thanks,

It seems strange that the block layer cannot keep up with relatively slow flash media devices. There must be a limitation on number of outstanding request towards MMC.
I need to make up my mind if it's the best way to address this issue in the MMC framework or block layer. I have started to look into the block layer code but it will take some time to dig out the relevant parts.

BR
Per

#2 lore raw
Quoted 43 lines · Per Förlin
Quoted 42 lines · Konstantin Dorfman

Hello Per,

Quoted 21 lines · Per Forlin
Quoted 8 lines

When mmcqt reports on completion of a request there should be a context switch to allow the insertion of the next read ahead BIOs to the block layer. Since the mmcqd tries to fetch another request immediately after the completion of the previous request it gets NULL and starts waiting for the completion of the previous request. This wait on completion gives the FS the opportunity to insert the next request but the MMC layer is already blocked on the previous request completion and is not aware of the new request waiting to be fetched.

I thought that I could trigger a context switch in order to give execution time for FS to add the new request to the MMC queue. I made a simple hack to call yield() in case the request gets NULL. I thought it may give the FS layer enough time to add a new request to the MMC queue. This would not delay the MMC transfer since the yield() is done in parallel with an ongoing transfer. Anyway it was just meant to be a simple test.

One yield was not enough. Just for sanity check I added a msleep as well and that was enough to let FS add a new request, Would it be possible to gain throughput by delaying the fetch of new request? Too avoid unnecessary NULL requests

Quoted 5 lines

If (ongoing request is read AND size is max read ahead AND new request is NULL) yield();

BR
Per

We did the same experiment and it will not give maximum possible performance. There is no guarantee that the context switch which was manually caused by the MMC layer comes just in time: when it was early then next fetch still results in NULL, when it was later, then we miss possibility to fetch/prepare new request.

Any delay in fetch of the new request that comes after the new request has arrived hits throughput and latency.

The solution we are talking about here will fix not only situation with FS read ahead mechanism, but also it will remove penalty of the MMC context waiting on completion while any new request arrives.

Quoted 8 lines
Quoted 2 lines

Thanks,

It seems strange that the block layer cannot keep up with relatively slow flash media devices. There must be a limitation on number of outstanding request towards MMC.
I need to make up my mind if it's the best way to address this issue in the MMC framework or block layer. I have started to look into the block layer code but it will take some time to dig out the relevant parts.

BR
Per

The root cause of the issue in incompletion of the current design with well known producer-consumer problem solution (producer is block layer, consumer is mmc layer).
Classic definitions states that the buffer is fix size, in our case we have queue, so Producer always capable to put new request into the queue. Consumer context blocked when both buffers (curr and prev) are busy (first started its execution on the bus, second is fetched and waiting for the first).
Producer context considered to be blocked when FS (or others bio sources) has no requests to put into queue.
To maximize performance there are 2 notifications should be used:
1. Producer notifies Consumer about new item to proceed.
2. Consumer notifies Producer about free place.

In our case 2nd notification not need since as I said before - it is always free space in the queue.
There is no such notification as 1st, i.e. block layer has no way to notify mmc layer about new request arrived.

What you suggesting is to resolve specific case, when FS READ_AHEAD mechanism behavior causes delays in producing new requests. Probably you can resolve this specific case, but do you have guarantee that this is only case that causes delays between new requests events? Flash memory devices these days constantly improved on all levels: NAND, firmware, bus speed and host controller capabilities, this makes any yield/sleep/timeouts solution only temporary hacks.

Thanks

Signature · 4 lines
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center,
Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#3 lore raw
Quoted 52 lines · Konstantin Dorfman
Quoted 43 lines · Per Förlin
Quoted 42 lines · Konstantin Dorfman

Hello Per,

Quoted 21 lines · Per Forlin
Quoted 8 lines

When mmcqt reports on completion of a request there should be a context switch to allow the insertion of the next read ahead BIOs to the block layer. Since the mmcqd tries to fetch another request immediately after the completion of the previous request it gets NULL and starts waiting for the completion of the previous request. This wait on completion gives the FS the opportunity to insert the next request but the MMC layer is already blocked on the previous request completion and is not aware of the new request waiting to be fetched.

I thought that I could trigger a context switch in order to give execution time for FS to add the new request to the MMC queue. I made a simple hack to call yield() in case the request gets NULL. I thought it may give the FS layer enough time to add a new request to the MMC queue. This would not delay the MMC transfer since the yield() is done in parallel with an ongoing transfer. Anyway it was just meant to be a simple test.

One yield was not enough. Just for sanity check I added a msleep as well and that was enough to let FS add a new request, Would it be possible to gain throughput by delaying the fetch of new request? Too avoid unnecessary NULL requests

Quoted 5 lines

If (ongoing request is read AND size is max read ahead AND new request is NULL) yield();

BR
Per

We did the same experiment and it will not give maximum possible performance. There is no guarantee that the context switch which was manually caused by the MMC layer comes just in time: when it was early then next fetch still results in NULL, when it was later, then we miss possibility to fetch/prepare new request.

Any delay in fetch of the new request that comes after the new request has arrived hits throughput and latency.

The solution we are talking about here will fix not only situation with FS read ahead mechanism, but also it will remove penalty of the MMC context waiting on completion while any new request arrives.

Quoted 8 lines
Quoted 2 lines

Thanks,

It seems strange that the block layer cannot keep up with relatively slow flash media devices. There must be a limitation on number of outstanding request towards MMC.
I need to make up my mind if it's the best way to address this issue in the MMC framework or block layer. I have started to look into the block layer code but it will take some time to dig out the relevant parts.

BR
Per

Quoted 8 lines

The root cause of the issue in incompletion of the current design with well known producer-consumer problem solution (producer is block layer, consumer is mmc layer).
Classic definitions states that the buffer is fix size, in our case we have queue, so Producer always capable to put new request into the queue. Consumer context blocked when both buffers (curr and prev) are busy (first started its execution on the bus, second is fetched and waiting for the first).

This happens but I thought that the block layer would continue to add request to the MMC queue while the consumer is busy. When consumer fetches request from the queue again there should be several requests available in the queue, but there is only one.

Quoted 2 lines

Producer context considered to be blocked when FS (or others bio sources) has no requests to put into queue.

Does the block layer ever wait for outstanding request to finish? Could this be another reason why the producer doesn't add new requests on the MMC queue?

Quoted 9 lines

To maximize performance there are 2 notifications should be used:
1. Producer notifies Consumer about new item to proceed.
2. Consumer notifies Producer about free place.

In our case 2nd notification not need since as I said before - it is always free space in the queue.
There is no such notification as 1st, i.e. block layer has no way to notify mmc layer about new request arrived.

Quoted 7 lines

What you suggesting is to resolve specific case, when FS READ_AHEAD mechanism behavior causes delays in producing new requests. Probably you can resolve this specific case, but do you have guarantee that this is only case that causes delays between new requests events? Flash memory devices these days constantly improved on all levels: NAND, firmware, bus speed and host controller capabilities, this makes any yield/sleep/timeouts solution only temporary hacks.

I never meant yield or sleep to be a permanent fix. I was only curious of how if would affect the performance in order to gain a better knowledge of the root cause. My impression is that even if the SD card is very slow you will see the same affect. The behavior of the block layer in this case is not related to the speed for the flash memory. On a slow card the MMC-queue runs empty just like it does for a fast eMMC.
According to you the block layer should have a better chance to feed the MMC queue if the card is slow (more time for the block layer to prepare next requests).

BR
Per

#21 lore raw
In reply to Konstantin Dorfman
Quoted 66 lines · Konstantin Dorfman
Quoted 43 lines · Per Förlin
Quoted 42 lines · Konstantin Dorfman

Hello Per,

Quoted 21 lines · Per Forlin
Quoted 8 lines

When mmcqt reports on completion of a request there should be a context switch to allow the insertion of the next read ahead BIOs to the block layer. Since the mmcqd tries to fetch another request immediately after the completion of the previous request it gets NULL and starts waiting for the completion of the previous request. This wait on completion gives the FS the opportunity to insert the next request but the MMC layer is already blocked on the previous request completion and is not aware of the new request waiting to be fetched.

I thought that I could trigger a context switch in order to give execution time for FS to add the new request to the MMC queue. I made a simple hack to call yield() in case the request gets NULL. I thought it may give the FS layer enough time to add a new request to the MMC queue. This would not delay the MMC transfer since the yield() is done in parallel with an ongoing transfer. Anyway it was just meant to be a simple test.

One yield was not enough. Just for sanity check I added a msleep as well and that was enough to let FS add a new request, Would it be possible to gain throughput by delaying the fetch of new request? Too avoid unnecessary NULL requests

Quoted 5 lines

If (ongoing request is read AND size is max read ahead AND new request is NULL) yield();

BR
Per

We did the same experiment and it will not give maximum possible performance. There is no guarantee that the context switch which was manually caused by the MMC layer comes just in time: when it was early then next fetch still results in NULL, when it was later, then we miss possibility to fetch/prepare new request.

Any delay in fetch of the new request that comes after the new request has arrived hits throughput and latency.

The solution we are talking about here will fix not only situation with FS read ahead mechanism, but also it will remove penalty of the MMC context waiting on completion while any new request arrives.

Quoted 8 lines
Quoted 2 lines

Thanks,

It seems strange that the block layer cannot keep up with relatively slow flash media devices. There must be a limitation on number of outstanding request towards MMC.
I need to make up my mind if it's the best way to address this issue in the MMC framework or block layer. I have started to look into the block layer code but it will take some time to dig out the relevant parts.

BR
Per

The root cause of the issue in incompletion of the current design with well known producer-consumer problem solution (producer is block layer, consumer is mmc layer).
Classic definitions states that the buffer is fix size, in our case we have queue, so Producer always capable to put new request into the queue. Consumer context blocked when both buffers (curr and prev) are busy (first started its execution on the bus, second is fetched and waiting for the first).
Producer context considered to be blocked when FS (or others bio sources) has no requests to put into queue.
To maximize performance there are 2 notifications should be used:
1. Producer notifies Consumer about new item to proceed.
2. Consumer notifies Producer about free place.

Quoted 4 lines

In our case 2nd notification not need since as I said before - it is always free space in the queue.
There is no such notification as 1st, i.e. block layer has no way to notify mmc layer about new request arrived.

Being nitpicky, I think it contradicts with the commit log that you have for the patch..
<Quote>
When the block layer notifies the MMC layer on a new request, we check for the above case where MMC layer is waiting on a previous request completion and the current request is NULL.
</Quote>

Quoted 9 lines

What you suggesting is to resolve specific case, when FS READ_AHEAD mechanism behavior causes delays in producing new requests. Probably you can resolve this specific case, but do you have guarantee that this is only case that causes delays between new requests events? Flash memory devices these days constantly improved on all levels: NAND, firmware, bus speed and host controller capabilities, this makes any yield/sleep/timeouts solution only temporary hacks.

#4 lore raw
In reply to Per Förlin
Quoted 61 lines · Per Förlin
Quoted 52 lines · Konstantin Dorfman
Quoted 43 lines · Per Förlin
Quoted 42 lines · Konstantin Dorfman

Hello Per,

Quoted 21 lines · Per Forlin
Quoted 8 lines

When mmcqt reports on completion of a request there should be a context switch to allow the insertion of the next read ahead BIOs to the block layer. Since the mmcqd tries to fetch another request immediately after the completion of the previous request it gets NULL and starts waiting for the completion of the previous request. This wait on completion gives the FS the opportunity to insert the next request but the MMC layer is already blocked on the previous request completion and is not aware of the new request waiting to be fetched.

I thought that I could trigger a context switch in order to give execution time for FS to add the new request to the MMC queue. I made a simple hack to call yield() in case the request gets NULL. I thought it may give the FS layer enough time to add a new request to the MMC queue. This would not delay the MMC transfer since the yield() is done in parallel with an ongoing transfer. Anyway it was just meant to be a simple test.

One yield was not enough. Just for sanity check I added a msleep as well and that was enough to let FS add a new request, Would it be possible to gain throughput by delaying the fetch of new request? Too avoid unnecessary NULL requests

Quoted 5 lines

If (ongoing request is read AND size is max read ahead AND new request is NULL) yield();

BR
Per

We did the same experiment and it will not give maximum possible performance. There is no guarantee that the context switch which was manually caused by the MMC layer comes just in time: when it was early then next fetch still results in NULL, when it was later, then we miss possibility to fetch/prepare new request.

Any delay in fetch of the new request that comes after the new request has arrived hits throughput and latency.

The solution we are talking about here will fix not only situation with FS read ahead mechanism, but also it will remove penalty of the MMC context waiting on completion while any new request arrives.

Quoted 8 lines
Quoted 2 lines

Thanks,

It seems strange that the block layer cannot keep up with relatively slow flash media devices. There must be a limitation on number of outstanding request towards MMC.
I need to make up my mind if it's the best way to address this issue in the MMC framework or block layer. I have started to look into the block layer code but it will take some time to dig out the relevant parts.

BR
Per

Quoted 8 lines

The root cause of the issue in incompletion of the current design with well known producer-consumer problem solution (producer is block layer, consumer is mmc layer).
Classic definitions states that the buffer is fix size, in our case we have queue, so Producer always capable to put new request into the queue. Consumer context blocked when both buffers (curr and prev) are busy (first started its execution on the bus, second is fetched and waiting for the first).

Quoted 7 lines

This happens but I thought that the block layer would continue to add request to the MMC queue while the consumer is busy. When consumer fetches request from the queue again there should be several requests available in the queue, but there is only one.

Quoted 2 lines

Producer context considered to be blocked when FS (or others bio sources) has no requests to put into queue.

Does the block layer ever wait for outstanding request to finish? Could this be another reason why the producer doesn't add new requests on the MMC queue?

Actually there could a lot of reasons why block layer or CFQ would not have inserted the request into the queue. i.e. you can see a lot of exit paths where blk_peek_request returns NULL, even though there could be any request pending in one of the CFQ requests queues.

Essentially you need to check what makes blk_fetch_request (cfq_dispatch_requests() ) return NULL when there is an element in queue, if at all.

Quoted 23 lines
Quoted 9 lines

To maximize performance there are 2 notifications should be used:
1. Producer notifies Consumer about new item to proceed.
2. Consumer notifies Producer about free place.

In our case 2nd notification not need since as I said before - it is always free space in the queue.
There is no such notification as 1st, i.e. block layer has no way to notify mmc layer about new request arrived.

Quoted 7 lines

What you suggesting is to resolve specific case, when FS READ_AHEAD mechanism behavior causes delays in producing new requests. Probably you can resolve this specific case, but do you have guarantee that this is only case that causes delays between new requests events? Flash memory devices these days constantly improved on all levels: NAND, firmware, bus speed and host controller capabilities, this makes any yield/sleep/timeouts solution only temporary hacks.

I never meant yield or sleep to be a permanent fix. I was only curious of how if would affect the performance in order to gain a better knowledge of the root cause. My impression is that even if the SD card is very slow you will see the same affect. The behavior of the block layer in this case is not related to the speed for the flash memory. On a slow card the MMC-queue runs empty just like it does for a fast eMMC.
According to you the block layer should have a better chance to feed the MMC queue if the card is slow (more time for the block layer to prepare next requests).

BR
Per

#20 lore raw
In reply to Per Förlin
Quoted 61 lines · Per Förlin
Quoted 52 lines · Konstantin Dorfman
Quoted 43 lines · Per Förlin
Quoted 42 lines · Konstantin Dorfman

Hello Per,

Quoted 21 lines · Per Forlin
Quoted 8 lines

When mmcqt reports on completion of a request there should be a context switch to allow the insertion of the next read ahead BIOs to the block layer. Since the mmcqd tries to fetch another request immediately after the completion of the previous request it gets NULL and starts waiting for the completion of the previous request. This wait on completion gives the FS the opportunity to insert the next request but the MMC layer is already blocked on the previous request completion and is not aware of the new request waiting to be fetched.

I thought that I could trigger a context switch in order to give execution time for FS to add the new request to the MMC queue. I made a simple hack to call yield() in case the request gets NULL. I thought it may give the FS layer enough time to add a new request to the MMC queue. This would not delay the MMC transfer since the yield() is done in parallel with an ongoing transfer. Anyway it was just meant to be a simple test.

One yield was not enough. Just for sanity check I added a msleep as well and that was enough to let FS add a new request, Would it be possible to gain throughput by delaying the fetch of new request? Too avoid unnecessary NULL requests

Quoted 5 lines

If (ongoing request is read AND size is max read ahead AND new request is NULL) yield();

BR
Per

We did the same experiment and it will not give maximum possible performance. There is no guarantee that the context switch which was manually caused by the MMC layer comes just in time: when it was early then next fetch still results in NULL, when it was later, then we miss possibility to fetch/prepare new request.

Any delay in fetch of the new request that comes after the new request has arrived hits throughput and latency.

The solution we are talking about here will fix not only situation with FS read ahead mechanism, but also it will remove penalty of the MMC context waiting on completion while any new request arrives.

Quoted 8 lines
Quoted 2 lines

Thanks,

It seems strange that the block layer cannot keep up with relatively slow flash media devices. There must be a limitation on number of outstanding request towards MMC.
I need to make up my mind if it's the best way to address this issue in the MMC framework or block layer. I have started to look into the block layer code but it will take some time to dig out the relevant parts.

BR
Per

Quoted 8 lines

The root cause of the issue in incompletion of the current design with well known producer-consumer problem solution (producer is block layer, consumer is mmc layer).
Classic definitions states that the buffer is fix size, in our case we have queue, so Producer always capable to put new request into the queue. Consumer context blocked when both buffers (curr and prev) are busy (first started its execution on the bus, second is fetched and waiting for the first).

Quoted 2 lines

This happens but I thought that the block layer would continue to add request to the MMC queue while the consumer is busy. When consumer fetches request from the queue again there should be several requests available in the queue, but there is only one.

MMC layer tries to fetch next request immediately after starting prev request, but block layer has no context to submit new request, after fetching NULL request MMC layer goes to be blocked and has no chance to repeat the fetch until current request not completed.

Quoted 5 lines
Quoted 3 lines

Producer context considered to be blocked when FS (or others bio sources) has no requests to put into queue.

Does the block layer ever wait for outstanding request to finish? Could this be another reason why the producer doesn't add new requests on the MMC queue?

In the case with sequence read request, only after request complete returned to the FS/read ahead layer, it will generate next read request. It may depend on READ_AHEAD : mmc_req_size ratio, also it may depend on other layers (above FS) and user space access patterns. You can't expect always "good" access patterns coming to the MMC layer

Quoted 5 lines

I never meant yield or sleep to be a permanent fix. I was only curious of how if would affect the performance in order to gain a better knowledge of the root cause. My impression is that even if the SD card is very slow you will see the same affect. The behavior of the block layer in this case is not related to the speed for the flash memory. On a slow card the MMC-queue runs empty just like it does for a fast eMMC.
According to you the block layer should have a better chance to feed the MMC queue if the card is slow (more time for the block layer to prepare next requests).

I understand that yield/sleep is not a solution, this is not important what are reasons for block layer behaviour, but what is really important
- MMC layer should always be able to fetch the new arrived request ASAP after block layer notification (mmc_request() ) and this is what my fix goes to implement. And the fix is not changing block layer behavior.

Thanks,

Signature · 4 lines
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center,
Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#22 lore raw
In reply to Venkatraman S

Hello Venkatraman,
You are very welcome with any ideas,

Quoted 9 lines · Venkatraman S

Being nitpicky, I think it contradicts with the commit log that you have for the patch..
<Quote>
When the block layer notifies the MMC layer on a new request, we check for the above case where MMC layer is waiting on a previous request completion and the current request is NULL.
</Quote>

Can you be more specific? What is contradiction? Can you suggest better patch description?

What I'm trying to say here:

the patch will modify block layer notification (mmc_request() callback) on new incoming request in such way, that when MMC layer is blocked by waiting for completion of previous request (in core/core.c) - it will unblock MMC layer, rollback in mmc_queue_thread code up to blk_fetch() point. This will permit to the MMC layer start processing of newly notified request immediately (and not after completion of currently running request).

Does it make sense?

Signature · 4 lines
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center,
Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#5 lore raw
In reply to Venkatraman S

Hello,

Quoted 10 lines · Venkatraman S

Actually there could a lot of reasons why block layer or CFQ would not have inserted the request into the queue. i.e. you can see a lot of exit paths where blk_peek_request returns NULL, even though there could be any request pending in one of the CFQ requests queues.

Essentially you need to check what makes blk_fetch_request (cfq_dispatch_requests() ) return NULL when there is an element in queue, if at all.

This is not important why block layer causes to blk_fetch_request() (or blk_peek_request()) to return NULL to the MMC layer, but what is really important - MMC layer should always be able to fetch the new arrived request ASAP, after block layer notification (mmc_request() ) and this is what my fix goes to implement.

And the fix is not changing block layer behavior.

Thanks

Signature · 4 lines
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center,
Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#6 lore raw

Hi,

I would like to move the focus of my concerns from root cause analysis to the actual patch,
My first reflection is that the patch is relatively complex and some of the code looks duplicated.
Would it be possible to simplify it and re-use the current execution flow.

Is the following flow feasible?

in mmc_start_req():
--------------
if (rqc == NULL && not_resend)
wait_for_both_mmc_and_arrival_of_new_req
else
wait_only_for_mmc

if (arrival_of_new_req) {
set flag to indicate fetch-new_req
return NULL;
}
-----------------

in queue.c:
if (fetch-new_req)
don't overwrite previous req.

BR
Per

Quoted 30 lines · Konstantin Dorfman

Hello,

Quoted 10 lines · Venkatraman S

Actually there could a lot of reasons why block layer or CFQ would not have inserted the request into the queue. i.e. you can see a lot of exit paths where blk_peek_request returns NULL, even though there could be any request pending in one of the CFQ requests queues.

Essentially you need to check what makes blk_fetch_request (cfq_dispatch_requests() ) return NULL when there is an element in queue, if at all.

This is not important why block layer causes to blk_fetch_request() (or blk_peek_request()) to return NULL to the MMC layer, but what is really important - MMC layer should always be able to fetch the new arrived request ASAP, after block layer notification (mmc_request() ) and this is what my fix goes to implement.

And the fix is not changing block layer behavior.

Thanks

--
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

#7 lore raw

minor clarification,

Quoted 8 lines · Per Forlin

Hi,

I would like to move the focus of my concerns from root cause analysis to the actual patch,
My first reflection is that the patch is relatively complex and some of the code looks duplicated.
Would it be possible to simplify it and re-use the current execution flow.

Quoted 5 lines

Is the following flow feasible?

in mmc_start_req():
--------------
if (rqc == NULL && not_resend)

&& request_is_ongoing (in case of resend request is never ongoing

Quoted 1 line

wait_for_both_mmc_and_arrival_of_new_req

We should wake up if any of the two events occur.

Quoted 9 lines

else
wait_only_for_mmc

if (arrival_of_new_req) {
set flag to indicate fetch-new_req
return NULL;
}
-----------------

Quoted 4 lines

in queue.c:
if (fetch-new_req)
don't overwrite previous req.

This is somewhat a subset of the your patch. Maybe I'm missing parts of the complexity.
I haven't figured out why a new mmc_start_data_req() is needed. A new mechanism for waiting is required.

BR
Per

Quoted 37 lines

BR
Per

Quoted 30 lines · Konstantin Dorfman

Hello,

Quoted 10 lines · Venkatraman S

Actually there could a lot of reasons why block layer or CFQ would not have inserted the request into the queue. i.e. you can see a lot of exit paths where blk_peek_request returns NULL, even though there could be any request pending in one of the CFQ requests queues.

Essentially you need to check what makes blk_fetch_request (cfq_dispatch_requests() ) return NULL when there is an element in queue, if at all.

This is not important why block layer causes to blk_fetch_request() (or blk_peek_request()) to return NULL to the MMC layer, but what is really important - MMC layer should always be able to fetch the new arrived request ASAP, after block layer notification (mmc_request() ) and this is what my fix goes to implement.

And the fix is not changing block layer behavior.

Thanks

--
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

#9 lore raw
In reply to Per Forlin

Hello,

Quoted 23 lines · Per Forlin

Hi,

I would like to move the focus of my concerns from root cause analysis to the actual patch,
My first reflection is that the patch is relatively complex and some of the code looks duplicated.
Would it be possible to simplify it and re-use the current execution flow.

Is the following flow feasible?

in mmc_start_req():
--------------
if (rqc == NULL && not_resend)
wait_for_both_mmc_and_arrival_of_new_req
else
wait_only_for_mmc

if (arrival_of_new_req) {
set flag to indicate fetch-new_req
return NULL;
}
-----------------

Quoted 6 lines

in queue.c:
if (fetch-new_req)
don't overwrite previous req.

BR
Per

You are talking about using both waiting mechanisms, old (wait on completion) and new - wait_event_interruptible()? But how done() callback, called on host controller irq context, will differentiate which one is relevant for the request?

I think it is better to use single wait point for mmc thread.

Also in future plans to add second reason to wake up mmc thread from
waiting: this is urgent_request - this notification about next-to-fetch read request, that should be executed out-of-order, using new eMMC HPI feature (to stop currently running request).

I will publish this patch soon.

Your idea with fetch_new_req flag is good, I'll try to simplify current patch and lets talk again.

Thanks,

Signature · 4 lines
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center,
Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#8 lore raw
In reply to Per Forlin
Quoted 29 lines · Per Forlin

minor clarification,

Quoted 6 lines · Per Forlin

Is the following flow feasible?

in mmc_start_req():
--------------
if (rqc == NULL && not_resend)

&& request_is_ongoing (in case of resend request is never ongoing

Quoted 1 line

wait_for_both_mmc_and_arrival_of_new_req

We should wake up if any of the two events occur.

Quoted 9 lines

else
wait_only_for_mmc

if (arrival_of_new_req) {
set flag to indicate fetch-new_req
return NULL;
}
-----------------

Quoted 4 lines

in queue.c:
if (fetch-new_req)
don't overwrite previous req.

Quoted 4 lines

This is somewhat a subset of the your patch. Maybe I'm missing parts of the complexity.
I haven't figured out why a new mmc_start_data_req() is needed. A new mechanism for waiting is required.

You're right, it was no reason to add new function, we can use mmc_start_req() and just change mechanism for waiting, I will fix this to minimize changes.

Signature · 4 lines
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center,
Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#10 lore raw
In reply to Konstantin Dorfman

Hi,

Quoted 45 lines · Konstantin Dorfman

Hello,

Quoted 23 lines · Per Forlin

Hi,

I would like to move the focus of my concerns from root cause analysis to the actual patch,
My first reflection is that the patch is relatively complex and some of the code looks duplicated.
Would it be possible to simplify it and re-use the current execution flow.

Is the following flow feasible?

in mmc_start_req():
--------------
if (rqc == NULL && not_resend)
wait_for_both_mmc_and_arrival_of_new_req
else
wait_only_for_mmc

if (arrival_of_new_req) {
set flag to indicate fetch-new_req
return NULL;
}
-----------------

Quoted 6 lines

in queue.c:
if (fetch-new_req)
don't overwrite previous req.

BR
Per

You are talking about using both waiting mechanisms, old (wait on completion) and new - wait_event_interruptible()? But how done() callback, called on host controller irq context, will differentiate which one is relevant for the request?

I think it is better to use single wait point for mmc thread.

Also in future plans to add second reason to wake up mmc thread from
waiting: this is urgent_request - this notification about next-to-fetch read request, that should be executed out-of-order, using new eMMC HPI feature (to stop currently running request).

Quoted 5 lines

I will publish this patch soon.

Your idea with fetch_new_req flag is good, I'll try to simplify current patch and lets talk again.

I have not thought this through entirely. But it would be nice to add a new func() in areq to add support for this a new mechanism. If the func() is NULL the normal flow will be executed. This could be used in the SDIO case too. At least it should be possible to use only the core API and it still make sense without a mmc block driver on top.

How to implement this wait function?
There should be one single wait point, I agree.
One could share the mmc completion perhaps through the new func(). This mean both mmc-queue and mmc-host and completes the same completion.
When waking up from the completion one needs to stop the new func-wait-point and check if a new request is available. If yes, fetch a new request and next time don't re-init the completion (this would overwrite the mmc-host complete value).

Let's talk again when you have a new patch set.

BR
Per

Quoted 6 lines

Thanks,
--
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

#11 lore raw
In reply to Konstantin Dorfman
Quoted 33 lines · Konstantin Dorfman

Hello,

Quoted 23 lines · Per Forlin

Hi,

I would like to move the focus of my concerns from root cause analysis to the actual patch,
My first reflection is that the patch is relatively complex and some of the code looks duplicated.
Would it be possible to simplify it and re-use the current execution flow.

Is the following flow feasible?

in mmc_start_req():
--------------
if (rqc == NULL && not_resend)
wait_for_both_mmc_and_arrival_of_new_req
else
wait_only_for_mmc

if (arrival_of_new_req) {
set flag to indicate fetch-new_req
return NULL;
}
-----------------

Quoted 6 lines

in queue.c:
if (fetch-new_req)
don't overwrite previous req.

BR
Per

Quoted 6 lines

You are talking about using both waiting mechanisms, old (wait on completion) and new - wait_event_interruptible()? But how done() callback, called on host controller irq context, will differentiate which one is relevant for the request?

I think it is better to use single wait point for mmc thread.

I have sketch a patch to better explain my point. It's not tested it barely compiles :)
The patch tries to introduce your feature and still keep the same code path. And it exposes an API that could be used by SDIO as well. The intention of my sketch patch is only to explain what I tried to visualize in the pseudo code previously in this thread.
The out come of your final patch should be documented here I think:
Documentation/mmc/mmc-async-req.txt

Here follows my patch sketch:
........................................................

drivers/mmc/card/queue.c +43 -5
index e360a97..08036a1 100644
@@ -66,6 +66,8 @@ static int mmc_queue_thread(void *d)
 		spin_unlock_irq(q->queue_lock);
 
 		if (req || mq->mqrq_prev->req) {
+			if (!req)
+				mmc_prefetch_start(&mq->mqrq_prev->mmc_active, true);
 			set_current_state(TASK_RUNNING);
 			mq->issue_fn(mq, req);
 		} else {
@@ -79,11 +81,13 @@ static int mmc_queue_thread(void *d)
 		}
 
 		/* Current request becomes previous request and vice versa. */
-		mq->mqrq_prev->brq.mrq.data = NULL;
-		mq->mqrq_prev->req = NULL;
-		tmp = mq->mqrq_prev;
-		mq->mqrq_prev = mq->mqrq_cur;
-		mq->mqrq_cur = tmp;
+		if (!mmc_prefetch_pending(&mq->mqrq_prev->mmc_active)) {
+			mq->mqrq_prev->brq.mrq.data = NULL;
+			mq->mqrq_prev->req = NULL;
+			tmp = mq->mqrq_prev;
+			mq->mqrq_prev = mq->mqrq_cur;
+			mq->mqrq_cur = tmp;
+		}
 	} while (1);
 	up(&mq->thread_sem);
 
@@ -109,10 +113,44 @@ static void mmc_request_fn(struct request_queue *q)
 		return;
 	}
 
+	if (mq->prefetch_enable) {
+		spin_lock(&mq->prefetch_lock);
+		if (mq->prefetch_completion)
+			complete(mq->prefetch_completion);
+		mq->prefetch_pending = true;
+		spin_unlock(&mq->prefetch_lock);
+	}
+
 	if (!mq->mqrq_cur->req && !mq->mqrq_prev->req)
 		wake_up_process(mq->thread);
 }
 
+static void mmc_req_init(struct mmc_async_req *areq, struct completion *compl)
+{
+	struct mmc_queue *mq =
+		container_of(areq->prefetch, struct mmc_queue, prefetch);
+
+	spin_lock(&mq->prefetch_lock);
+	mq->prefetch_completion = compl;
+	if (mq->prefetch_pending)
+		complete(mq->prefetch_completion);
+	spin_unlock(&mq->prefetch_lock);
+}
+
+static void mmc_req_start(struct mmc_async_req *areq, bool enable)
+{
+	struct mmc_queue *mq =
+		container_of(areq->prefetch, struct mmc_queue, prefetch);
+	mq->prefetch_enable = enable;
+}
+
+static bool mmc_req_pending(struct mmc_async_req *areq)
+{
+	struct mmc_queue *mq =
+		container_of(areq->prefetch, struct mmc_queue, prefetch);
+	return mq->prefetch_pending;
+}
+
 static struct scatterlist *mmc_alloc_sg(int sg_len, int *err)
 {
 	struct scatterlist *sg;
@@ -166,6 +204,12 @@ int mmc_init_queue(struct mmc_queue *mq, struct

mmc_card *card,
int ret;
struct mmc_queue_req *mqrq_cur = &mq->mqrq[0]; struct mmc_queue_req *mqrq_prev = &mq->mqrq[1];
+ spin_lock_init(&mq->prefetch_lock);
+ mq->prefetch.wait_req_init = mmc_req_init;
+ mq->prefetch.wait_req_start = mmc_req_start;
+ mq->prefetch.wait_req_pending = mmc_req_pending;
+ mqrq_cur->mmc_active.prefetch = &mq->prefetch;
+ mqrq_prev->mmc_active.prefetch = &mq->prefetch;

if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
limit = *mmc_dev(host)->dma_mask;

drivers/mmc/card/queue.h +6 -0
index d2a1eb4..5afd467 100644
@@ -33,6 +33,12 @@ struct mmc_queue {
 	struct mmc_queue_req	mqrq[2];
 	struct mmc_queue_req	*mqrq_cur;
 	struct mmc_queue_req	*mqrq_prev;
+
+	struct mmc_async_prefetch prefetch;
+	spinlock_t		prefetch_lock;
+	struct completion	*prefetch_completion;
+	bool			prefetch_enable;
+	bool			prefetch_pending;
 };
 
 extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *,
drivers/mmc/core/core.c +8 -0
index 9503cab..06fc036 100644
@@ -352,7 +352,15 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host,
 		mmc_pre_req(host, areq->mrq, !host->areq);
 
 	if (host->areq) {
+		if (!areq)
+			mmc_prefetch_init(host->areq,
+					  &host->areq->mrq->completion);
 		mmc_wait_for_req_done(host, host->areq->mrq);
+		if (!areq) {
+			mmc_prefetch_start(host->areq, false);
+			if (mmc_prefetch_pending(host->areq))
+				return NULL;
+		}
 		err = host->areq->err_check(host->card, host->areq);
 	}
 
include/linux/mmc/host.h +33 -0
index 65c64ee..ce5d03f 100644
@@ -15,6 +15,7 @@
 #include <linux/sched.h>
 #include <linux/device.h>
 #include <linux/fault-inject.h>
+#include <linux/completion.h>
 
 #include <linux/mmc/core.h>
 #include <linux/mmc/pm.h>
@@ -140,6 +141,13 @@ struct mmc_host_ops {
 
 struct mmc_card;
 struct device;
+struct mmc_async_req;
+
+struct mmc_async_prefetch {
+	void (*wait_req_init)(struct mmc_async_req *, struct completion *);
+	void (*wait_req_start)(struct mmc_async_req *, bool);
+	bool (*wait_req_pending)(struct mmc_async_req *);
+};
 
 struct mmc_async_req {
 	/* active mmc request */
@@ -149,8 +157,33 @@ struct mmc_async_req {
 	 * Returns 0 if success otherwise non zero.
 	 */
 	int (*err_check) (struct mmc_card *, struct mmc_async_req *);
+	struct mmc_async_prefetch *prefetch;
 };
 
+/* set completion variable, complete == NULL to reset completion */
+static inline void mmc_prefetch_init(struct mmc_async_req *areq,
+				     struct completion *complete)
+{
+	if (areq->prefetch && areq->prefetch->wait_req_init)
+		areq->prefetch->wait_req_init(areq, complete);
+}
+
+/* enable or disable prefetch feature */
+static inline void mmc_prefetch_start(struct mmc_async_req *areq, bool enable)
+{
+	if (areq->prefetch && areq->prefetch->wait_req_start)
+		areq->prefetch->wait_req_start(areq, enable);
+}
+
+/* return true if new request is pending otherwise false */
+static inline bool mmc_prefetch_pending(struct mmc_async_req *areq)
+{
+	if (areq->prefetch && areq->prefetch->wait_req_pending)
+		return areq->prefetch->wait_req_pending(areq);
+	else
+		return false;
+}
+
 /**
  * struct mmc_slot - MMC slot functions
  *

....................................................................

BR
Per

#12 lore raw

Hello Per,

Quoted 42 lines · Per Forlin
Quoted 33 lines · Konstantin Dorfman

Hello,

Quoted 23 lines · Per Forlin

Hi,

I would like to move the focus of my concerns from root cause analysis to the actual patch,
My first reflection is that the patch is relatively complex and some of the code looks duplicated.
Would it be possible to simplify it and re-use the current execution flow.

Is the following flow feasible?

in mmc_start_req():
--------------
if (rqc == NULL && not_resend)
wait_for_both_mmc_and_arrival_of_new_req
else
wait_only_for_mmc

if (arrival_of_new_req) {
set flag to indicate fetch-new_req
return NULL;
}
-----------------

Quoted 6 lines

in queue.c:
if (fetch-new_req)
don't overwrite previous req.

BR
Per

Quoted 6 lines

You are talking about using both waiting mechanisms, old (wait on completion) and new - wait_event_interruptible()? But how done() callback, called on host controller irq context, will differentiate which one is relevant for the request?

I think it is better to use single wait point for mmc thread.

Quoted 8 lines

I have sketch a patch to better explain my point. It's not tested it barely compiles :)
The patch tries to introduce your feature and still keep the same code path. And it exposes an API that could be used by SDIO as well. The intention of my sketch patch is only to explain what I tried to visualize in the pseudo code previously in this thread.
The out come of your final patch should be documented here I think:
Documentation/mmc/mmc-async-req.txt

This document is ready, attaching it to this mail and will be included in next version of the patch (or RESEND).

Quoted 194 lines

Here follows my patch sketch:
........................................................

drivers/mmc/card/queue.c +49 -5
index e360a97..08036a1 100644
@@ -66,6 +66,8 @@ static int mmc_queue_thread(void *d)
 		spin_unlock_irq(q->queue_lock);
 
 		if (req || mq->mqrq_prev->req) {
+			if (!req)
+				mmc_prefetch_start(&mq->mqrq_prev->mmc_active, true);
 			set_current_state(TASK_RUNNING);
 			mq->issue_fn(mq, req);
 		} else {
@@ -79,11 +81,13 @@ static int mmc_queue_thread(void *d)
 		}
 
 		/* Current request becomes previous request and vice versa. */
-		mq->mqrq_prev->brq.mrq.data = NULL;
-		mq->mqrq_prev->req = NULL;
-		tmp = mq->mqrq_prev;
-		mq->mqrq_prev = mq->mqrq_cur;
-		mq->mqrq_cur = tmp;
+		if (!mmc_prefetch_pending(&mq->mqrq_prev->mmc_active)) {
+			mq->mqrq_prev->brq.mrq.data = NULL;
+			mq->mqrq_prev->req = NULL;
+			tmp = mq->mqrq_prev;
+			mq->mqrq_prev = mq->mqrq_cur;
+			mq->mqrq_cur = tmp;
+		}
 	} while (1);
 	up(&mq->thread_sem);
 
@@ -109,10 +113,44 @@ static void mmc_request_fn(struct request_queue *q)
 		return;
 	}
 
+	if (mq->prefetch_enable) {
+		spin_lock(&mq->prefetch_lock);
+		if (mq->prefetch_completion)
+			complete(mq->prefetch_completion);
+		mq->prefetch_pending = true;
+		spin_unlock(&mq->prefetch_lock);
+	}
+
 	if (!mq->mqrq_cur->req && !mq->mqrq_prev->req)
 		wake_up_process(mq->thread);
 }
 
+static void mmc_req_init(struct mmc_async_req *areq, struct completion *compl)
+{
+	struct mmc_queue *mq =
+		container_of(areq->prefetch, struct mmc_queue, prefetch);
+
+	spin_lock(&mq->prefetch_lock);
+	mq->prefetch_completion = compl;
+	if (mq->prefetch_pending)
+		complete(mq->prefetch_completion);
+	spin_unlock(&mq->prefetch_lock);
+}
+
+static void mmc_req_start(struct mmc_async_req *areq, bool enable)
+{
+	struct mmc_queue *mq =
+		container_of(areq->prefetch, struct mmc_queue, prefetch);
+	mq->prefetch_enable = enable;
+}
+
+static bool mmc_req_pending(struct mmc_async_req *areq)
+{
+	struct mmc_queue *mq =
+		container_of(areq->prefetch, struct mmc_queue, prefetch);
+	return mq->prefetch_pending;
+}
+
 static struct scatterlist *mmc_alloc_sg(int sg_len, int *err)
 {
 	struct scatterlist *sg;
@@ -166,6 +204,12 @@ int mmc_init_queue(struct mmc_queue *mq, struct
 mmc_card *card,
 	int ret;
 	struct mmc_queue_req *mqrq_cur = &mq->mqrq[0];
 	struct mmc_queue_req *mqrq_prev = &mq->mqrq[1];
+	spin_lock_init(&mq->prefetch_lock);
+	mq->prefetch.wait_req_init = mmc_req_init;
+	mq->prefetch.wait_req_start = mmc_req_start;
+	mq->prefetch.wait_req_pending = mmc_req_pending;
+	mqrq_cur->mmc_active.prefetch = &mq->prefetch;
+	mqrq_prev->mmc_active.prefetch = &mq->prefetch;
 
 	if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
drivers/mmc/card/queue.c +0 -0
 		limit = *mmc_dev(host)->dma_mask;
drivers/mmc/card/queue.h +6 -0
index d2a1eb4..5afd467 100644
@@ -33,6 +33,12 @@ struct mmc_queue {
 	struct mmc_queue_req	mqrq[2];
 	struct mmc_queue_req	*mqrq_cur;
 	struct mmc_queue_req	*mqrq_prev;
+
+	struct mmc_async_prefetch prefetch;
+	spinlock_t		prefetch_lock;
+	struct completion	*prefetch_completion;
+	bool			prefetch_enable;
+	bool			prefetch_pending;
 };
 
 extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *,
drivers/mmc/core/core.c +8 -0
index 9503cab..06fc036 100644
@@ -352,7 +352,15 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host,
 		mmc_pre_req(host, areq->mrq, !host->areq);
 
 	if (host->areq) {
+		if (!areq)
+			mmc_prefetch_init(host->areq,
+					  &host->areq->mrq->completion);
 		mmc_wait_for_req_done(host, host->areq->mrq);
+		if (!areq) {
+			mmc_prefetch_start(host->areq, false);
+			if (mmc_prefetch_pending(host->areq))
+				return NULL;
+		}
 		err = host->areq->err_check(host->card, host->areq);
 	}
 
include/linux/mmc/host.h +33 -0
index 65c64ee..ce5d03f 100644
@@ -15,6 +15,7 @@
 #include <linux/sched.h>
 #include <linux/device.h>
 #include <linux/fault-inject.h>
+#include <linux/completion.h>
 
 #include <linux/mmc/core.h>
 #include <linux/mmc/pm.h>
@@ -140,6 +141,13 @@ struct mmc_host_ops {
 
 struct mmc_card;
 struct device;
+struct mmc_async_req;
+
+struct mmc_async_prefetch {
+	void (*wait_req_init)(struct mmc_async_req *, struct completion *);
+	void (*wait_req_start)(struct mmc_async_req *, bool);
+	bool (*wait_req_pending)(struct mmc_async_req *);
+};
 
 struct mmc_async_req {
 	/* active mmc request */
@@ -149,8 +157,33 @@ struct mmc_async_req {
 	 * Returns 0 if success otherwise non zero.
 	 */
 	int (*err_check) (struct mmc_card *, struct mmc_async_req *);
+	struct mmc_async_prefetch *prefetch;
 };
 
+/* set completion variable, complete == NULL to reset completion */
+static inline void mmc_prefetch_init(struct mmc_async_req *areq,
+				     struct completion *complete)
+{
+	if (areq->prefetch && areq->prefetch->wait_req_init)
+		areq->prefetch->wait_req_init(areq, complete);
+}
+
+/* enable or disable prefetch feature */
+static inline void mmc_prefetch_start(struct mmc_async_req *areq, bool enable)
+{
+	if (areq->prefetch && areq->prefetch->wait_req_start)
+		areq->prefetch->wait_req_start(areq, enable);
+}
+
+/* return true if new request is pending otherwise false */
+static inline bool mmc_prefetch_pending(struct mmc_async_req *areq)
+{
+	if (areq->prefetch && areq->prefetch->wait_req_pending)
+		return areq->prefetch->wait_req_pending(areq);
+	else
+		return false;
+}
+
 /**
  * struct mmc_slot - MMC slot functions
  *
....................................................................
Quoted 2 lines

BR
Per

I understand your motivation and idea for re-structure the patch. It is still not clear for me how exactly mmc thread will be awaken on new request notification in your version, but I have another problem:

We want to expand this event based mechanism (unblock mmc thread from waiting for the running request) by adding another reason/event. This is URGENT_REQUEST event. When block layer has Urgent request to execute, it notifies mmc layer (similar to mmc_request() notification) and mmc layer handles this urgent request notification by correctly stopping running request, re-inserting back to I/O scheduler all not yet performed parts and fetching & starting the urgent request.
The reasoning and general idea are documented together with "New event" and will be submitted soon. The patch itself will be submitted in a week or so.

As for our discussion - to handle both events mmc layer should be capable to be awaken not only in case of no mmc_prefetch_pending() (in your patch terms), but also when we have perfect case of async requests:
one running on the bus and second prepared and waiting for the first.

I think, that in case SDIO protocol driver need such functionality as NEW_REQUEST, one need to implement notification to the mmc layer similar to mmc_request() code in my patch.

Does this make sense?

Signature · 4 lines
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center,
Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

Introduction
============
The file system adds block requests to the block device queue asynchronously without waiting for completion. The MMC framework takes these block request synchronously one by one and pushes them to the host driver. When the host driver has completed the request, the framework will pull out a new block request from the block request queue. For each block request the MMC framework converts the generic request to a mmc request. The host driver takes the mmc request and does necessary preparations to process the request. For non-DMA host driver the necessary pre and post preparations are insignificant, but for DMA the cache maintenance is significant. Adding non-blocking request to the MMC framework (between block layer and host driver) will make it possible to prepare caches for one request while another request is being processed by the MMC controller.

[Referenced from the Rational section of
https://wiki.linaro.org/WorkingGroups/Kernel/Specs/
StoragePerfMMC-async-req]

Software description
====================
In case of sequential read operations async request mechanism isn't functional, due to the read ahead mechanism: When "mmcqd" (MMC thread) reports on completion of a request, there should be a context switch to allow the insertion of the next read ahead BIOs to the block layer. Since the "mmcqd" tries to fetch another request immediately after the completion of the previous request - it gets NULL and begins waiting for the completion of the previous request. This wait on completion gives the FS (File System) the opportunity to insert the next request but the MMC layer is already blocked on the previous request completion and is not aware of the new request waiting to be fetched. As a result of this missed oportunity to start cashe prepeare for the new request, while previous request is being serviced. Also it can't look to see if the new request is urgent and the the previous request is not interrupted immediately.

A solution of the above would be to add a mechanism that allows to wake up the MMC layer immediately with new block request when it is available for fetch.

Design
======

The main idea is to replace the blocking wait for a completion with an event driven mechanism and add a set of events that will unblock the MMC layer context from waiting on host driver complete.
The new events to be added are:
1. NEW_REQUEST:
When the block layer notifies the MMC layer on a new request (mmc_request() callback), and the MMC layer is waiting on a previous request completion and the current request is NULL. In such a case the NEW_REQUEST event will be triggered to wakeup the waiting thread. MMC layer will then fetch the new request and after its preparation will go back to waiting on the completion of previous request.

2. URGENT_REQUEST:
In order to decrease a latency of a prioritized requests (such as READ requests) we might want to stop the transmission of a "low priority" request (such as WRITE) in order to handle the "high priority one". The urgency of the request is decided by the block layer I/O scheduler. When the block layer notifies the MMC layer of an urgent request and the MMC layer is blocked it will be woken up. The decision on whether to stop an ongoing transfer is taken according to several parameters, one of them being the number of bytes transferred though host controller so far. The stopped request (and next prepared request in case it is exists) re-inserted back to the I/O scheduler to be handled after the completion of the urgent request.
When the decision taken was not to stop the ongoing transfer, MMC context will wait for normal completion of the ongoing transfer, then already prepared next request (if it exists) will be re-inserted back into block layer and the urgent request fetched.
URGENT_REQUEST handling is possible only when host controller driver supports stop_request() API, otherwise mmc_urgent_request() notification callback will not be registered into block layer.

Performance
===========
With the new event mechanism the READ throughput is improved by 16%.
With the Urgent-Request Event (and ROW scheduler) the READ latency is
decreased by 41%.

Known issues
============
As an performance metric of NEW_REQUEST and URGENT_REQUEST flows we are using average and worst case latency between:
1) block layer dispatches the request
2) MMC layer fetches the request
This latency should be minimized to achieve best overall performance. Right now the latency changes due to bus speed, CPU cores and other changes depending on specific hardware and software configuration.

To do
=====
For URGENT_REQUEST implementation in MMC layer, decision heuristic to stop ongoing transaction may be more accurate and based not on byte count transferred by host controller to the card, but on time needed by MMC card to perform the request.

#13 lore raw
Quoted 249 lines · Konstantin Dorfman

Hello Per,

Quoted 42 lines · Per Forlin
Quoted 33 lines · Konstantin Dorfman

Hello,

Quoted 23 lines · Per Forlin

Hi,

I would like to move the focus of my concerns from root cause analysis to the actual patch,
My first reflection is that the patch is relatively complex and some of the code looks duplicated.
Would it be possible to simplify it and re-use the current execution flow.

Is the following flow feasible?

in mmc_start_req():
--------------
if (rqc == NULL && not_resend)
wait_for_both_mmc_and_arrival_of_new_req
else
wait_only_for_mmc

if (arrival_of_new_req) {
set flag to indicate fetch-new_req
return NULL;
}
-----------------

Quoted 6 lines

in queue.c:
if (fetch-new_req)
don't overwrite previous req.

BR
Per

Quoted 6 lines

You are talking about using both waiting mechanisms, old (wait on completion) and new - wait_event_interruptible()? But how done() callback, called on host controller irq context, will differentiate which one is relevant for the request?

I think it is better to use single wait point for mmc thread.

Quoted 8 lines

I have sketch a patch to better explain my point. It's not tested it barely compiles :)
The patch tries to introduce your feature and still keep the same code path. And it exposes an API that could be used by SDIO as well. The intention of my sketch patch is only to explain what I tried to visualize in the pseudo code previously in this thread.
The out come of your final patch should be documented here I think:
Documentation/mmc/mmc-async-req.txt

This document is ready, attaching it to this mail and will be included in next version of the patch (or RESEND).

Quoted 194 lines

Here follows my patch sketch:
........................................................

drivers/mmc/card/queue.c +49 -5
index e360a97..08036a1 100644
@@ -66,6 +66,8 @@ static int mmc_queue_thread(void *d)
              spin_unlock_irq(q->queue_lock);
 
              if (req || mq->mqrq_prev->req) {
+                     if (!req)
+                             mmc_prefetch_start(&mq->mqrq_prev->mmc_active, true);
                      set_current_state(TASK_RUNNING);
                      mq->issue_fn(mq, req);
              } else {
@@ -79,11 +81,13 @@ static int mmc_queue_thread(void *d)
              }
 
              /* Current request becomes previous request and vice versa. */
-             mq->mqrq_prev->brq.mrq.data = NULL;
-             mq->mqrq_prev->req = NULL;
-             tmp = mq->mqrq_prev;
-             mq->mqrq_prev = mq->mqrq_cur;
-             mq->mqrq_cur = tmp;
+             if (!mmc_prefetch_pending(&mq->mqrq_prev->mmc_active)) {
+                     mq->mqrq_prev->brq.mrq.data = NULL;
+                     mq->mqrq_prev->req = NULL;
+                     tmp = mq->mqrq_prev;
+                     mq->mqrq_prev = mq->mqrq_cur;
+                     mq->mqrq_cur = tmp;
+             }
      } while (1);
      up(&mq->thread_sem);
 
@@ -109,10 +113,44 @@ static void mmc_request_fn(struct request_queue *q)
              return;
      }
 
+     if (mq->prefetch_enable) {
+             spin_lock(&mq->prefetch_lock);
+             if (mq->prefetch_completion)
+                     complete(mq->prefetch_completion);
+             mq->prefetch_pending = true;
+             spin_unlock(&mq->prefetch_lock);
+     }
+
      if (!mq->mqrq_cur->req && !mq->mqrq_prev->req)
              wake_up_process(mq->thread);
 }
 
+static void mmc_req_init(struct mmc_async_req *areq, struct completion *compl)
+{
+     struct mmc_queue *mq =
+             container_of(areq->prefetch, struct mmc_queue, prefetch);
+
+     spin_lock(&mq->prefetch_lock);
+     mq->prefetch_completion = compl;
+     if (mq->prefetch_pending)
+             complete(mq->prefetch_completion);
+     spin_unlock(&mq->prefetch_lock);
+}
+
+static void mmc_req_start(struct mmc_async_req *areq, bool enable)
+{
+     struct mmc_queue *mq =
+             container_of(areq->prefetch, struct mmc_queue, prefetch);
+     mq->prefetch_enable = enable;
+}
+
+static bool mmc_req_pending(struct mmc_async_req *areq)
+{
+     struct mmc_queue *mq =
+             container_of(areq->prefetch, struct mmc_queue, prefetch);
+     return mq->prefetch_pending;
+}
+
 static struct scatterlist *mmc_alloc_sg(int sg_len, int *err)
 {
      struct scatterlist *sg;
@@ -166,6 +204,12 @@ int mmc_init_queue(struct mmc_queue *mq, struct
 mmc_card *card,
      int ret;
      struct mmc_queue_req *mqrq_cur = &mq->mqrq[0];
      struct mmc_queue_req *mqrq_prev = &mq->mqrq[1];
+     spin_lock_init(&mq->prefetch_lock);
+     mq->prefetch.wait_req_init = mmc_req_init;
+     mq->prefetch.wait_req_start = mmc_req_start;
+     mq->prefetch.wait_req_pending = mmc_req_pending;
+     mqrq_cur->mmc_active.prefetch = &mq->prefetch;
+     mqrq_prev->mmc_active.prefetch = &mq->prefetch;
 
      if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
              limit = *mmc_dev(host)->dma_mask;
drivers/mmc/card/queue.h +6 -0
index d2a1eb4..5afd467 100644
@@ -33,6 +33,12 @@ struct mmc_queue {
      struct mmc_queue_req    mqrq[2];
      struct mmc_queue_req    *mqrq_cur;
      struct mmc_queue_req    *mqrq_prev;
+
+     struct mmc_async_prefetch prefetch;
+     spinlock_t              prefetch_lock;
+     struct completion       *prefetch_completion;
+     bool                    prefetch_enable;
+     bool                    prefetch_pending;
 };
 
 extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *,
drivers/mmc/core/core.c +8 -0
index 9503cab..06fc036 100644
@@ -352,7 +352,15 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host,
              mmc_pre_req(host, areq->mrq, !host->areq);
 
      if (host->areq) {
+             if (!areq)
+                     mmc_prefetch_init(host->areq,
+                                       &host->areq->mrq->completion);
              mmc_wait_for_req_done(host, host->areq->mrq);
+             if (!areq) {
+                     mmc_prefetch_start(host->areq, false);
+                     if (mmc_prefetch_pending(host->areq))
+                             return NULL;
+             }
              err = host->areq->err_check(host->card, host->areq);
      }
 
include/linux/mmc/host.h +33 -0
index 65c64ee..ce5d03f 100644
@@ -15,6 +15,7 @@
 #include <linux/sched.h>
 #include <linux/device.h>
 #include <linux/fault-inject.h>
+#include <linux/completion.h>
 
 #include <linux/mmc/core.h>
 #include <linux/mmc/pm.h>
@@ -140,6 +141,13 @@ struct mmc_host_ops {
 
 struct mmc_card;
 struct device;
+struct mmc_async_req;
+
+struct mmc_async_prefetch {
+     void (*wait_req_init)(struct mmc_async_req *, struct completion *);
+     void (*wait_req_start)(struct mmc_async_req *, bool);
+     bool (*wait_req_pending)(struct mmc_async_req *);
+};
 
 struct mmc_async_req {
      /* active mmc request */
@@ -149,8 +157,33 @@ struct mmc_async_req {
       * Returns 0 if success otherwise non zero.
       */
      int (*err_check) (struct mmc_card *, struct mmc_async_req *);
+     struct mmc_async_prefetch *prefetch;
 };
 
+/* set completion variable, complete == NULL to reset completion */
+static inline void mmc_prefetch_init(struct mmc_async_req *areq,
+                                  struct completion *complete)
+{
+     if (areq->prefetch && areq->prefetch->wait_req_init)
+             areq->prefetch->wait_req_init(areq, complete);
+}
+
+/* enable or disable prefetch feature */
+static inline void mmc_prefetch_start(struct mmc_async_req *areq, bool enable)
+{
+     if (areq->prefetch && areq->prefetch->wait_req_start)
+             areq->prefetch->wait_req_start(areq, enable);
+}
+
+/* return true if new request is pending otherwise false */
+static inline bool mmc_prefetch_pending(struct mmc_async_req *areq)
+{
+     if (areq->prefetch && areq->prefetch->wait_req_pending)
+             return areq->prefetch->wait_req_pending(areq);
+     else
+             return false;
+}
+
 /**
  * struct mmc_slot - MMC slot functions
  *
....................................................................
Quoted 6 lines
Quoted 2 lines

BR
Per

I understand your motivation and idea for re-structure the patch. It is still not clear for me how exactly mmc thread will be awaken on new request notification in your version, but I have another problem:

mmc_request_fn() is called and it calls complete(mq->prefetch_completion) which wakes up the current thread. My patch is just an example. The intention is to make the patch cleaner. But I may have missed some of the HPI aspects.

If the API is not implemented the mmc core shall simply ignore it.

Quoted 10 lines

We want to expand this event based mechanism (unblock mmc thread from waiting for the running request) by adding another reason/event. This is URGENT_REQUEST event. When block layer has Urgent request to execute, it notifies mmc layer (similar to mmc_request() notification) and mmc layer handles this urgent request notification by correctly stopping running request, re-inserting back to I/O scheduler all not yet performed parts and fetching & starting the urgent request.
The reasoning and general idea are documented together with "New event" and will be submitted soon. The patch itself will be submitted in a week or so.

I have not consider use of HPI in my proposal. If the NEW_REQ is first in line in the mmc queue it will be fetched as the NEW_REQ. Then the current request must be interrupted and returned to mmc-queue or io-scheduler.

I don't see a direct contradiction between the two designs.

The main point is to make the NEW_REQ API more simple clear. My example is just an example.

Quoted 9 lines

As for our discussion - to handle both events mmc layer should be capable to be awaken not only in case of no mmc_prefetch_pending() (in your patch terms), but also when we have perfect case of async requests:
one running on the bus and second prepared and waiting for the first.

I think, that in case SDIO protocol driver need such functionality as NEW_REQUEST, one need to implement notification to the mmc layer similar to mmc_request() code in my patch.

SDIO needs to implement the new NEW_REQ API, but the API needs to be clean.

BR
Per

#14 lore raw

Hello Per,

Thank you for giving me an example, below I'm trying to explain some logic issues of it and asking you some questions about your vision of the patch.

Quoted 91 lines · Per Förlin
Quoted 90 lines · Konstantin Dorfman

Hello Per,

Quoted 42 lines · Per Forlin
Quoted 33 lines · Konstantin Dorfman

Hello,

Quoted 23 lines · Per Forlin

Hi,

I would like to move the focus of my concerns from root cause analysis to the actual patch,
My first reflection is that the patch is relatively complex and some of the code looks duplicated.
Would it be possible to simplify it and re-use the current execution flow.

Is the following flow feasible?

in mmc_start_req():
--------------
if (rqc == NULL && not_resend)
wait_for_both_mmc_and_arrival_of_new_req
else
wait_only_for_mmc

if (arrival_of_new_req) {
set flag to indicate fetch-new_req
return NULL;
}
-----------------

Quoted 6 lines

in queue.c:
if (fetch-new_req)
don't overwrite previous req.

BR
Per

Quoted 6 lines

You are talking about using both waiting mechanisms, old (wait on completion) and new - wait_event_interruptible()? But how done() callback, called on host controller irq context, will differentiate which one is relevant for the request?

I think it is better to use single wait point for mmc thread.

Quoted 8 lines

I have sketch a patch to better explain my point. It's not tested it barely compiles :)
The patch tries to introduce your feature and still keep the same code path. And it exposes an API that could be used by SDIO as well. The intention of my sketch patch is only to explain what I tried to visualize in the pseudo code previously in this thread.
The out come of your final patch should be documented here I think:
Documentation/mmc/mmc-async-req.txt

This document is ready, attaching it to this mail and will be included in next version of the patch (or RESEND).

Quoted 35 lines

Here follows my patch sketch:
........................................................

drivers/mmc/card/queue.c +9 -5
index e360a97..08036a1 100644
@@ -66,6 +66,8 @@ static int mmc_queue_thread(void *d)
              spin_unlock_irq(q->queue_lock);
 
              if (req || mq->mqrq_prev->req) {
+                     if (!req)
+                             mmc_prefetch_start(&mq->mqrq_prev->mmc_active, true);
                      set_current_state(TASK_RUNNING);
                      mq->issue_fn(mq, req);
              } else {
@@ -79,11 +81,13 @@ static int mmc_queue_thread(void *d)
              }
 
              /* Current request becomes previous request and vice versa. */
-             mq->mqrq_prev->brq.mrq.data = NULL;
-             mq->mqrq_prev->req = NULL;
-             tmp = mq->mqrq_prev;
-             mq->mqrq_prev = mq->mqrq_cur;
-             mq->mqrq_cur = tmp;
+             if (!mmc_prefetch_pending(&mq->mqrq_prev->mmc_active)) {
+                     mq->mqrq_prev->brq.mrq.data = NULL;
+                     mq->mqrq_prev->req = NULL;
+                     tmp = mq->mqrq_prev;
+                     mq->mqrq_prev = mq->mqrq_cur;
+                     mq->mqrq_cur = tmp;
+             }
      } while (1);
      up(&mq->thread_sem);
 
Quoted 8 lines
Quoted 8 lines

drivers/mmc/card/queue.c static void mmc_request_fn(struct request_queue *q) · line 119

Quoted 8 lines
drivers/mmc/card/queue.c +4 -0
@@ -109,10 +113,44 @@ static void mmc_request_fn(struct request_queue *q)
              return;
      }
 
+     if (mq->prefetch_enable) {
+             spin_lock(&mq->prefetch_lock);
+             if (mq->prefetch_completion)
+                     complete(mq->prefetch_completion);

Since mq->prefetch_completion init happens only in core.c after mmc_start_req(NULL), we can miss all new request notifications coming from fetching NULL request until then.

Quoted 75 lines
Quoted 75 lines
Quoted 75 lines
drivers/mmc/card/queue.c +36 -0
+             mq->prefetch_pending = true;
+             spin_unlock(&mq->prefetch_lock);
+     }
+
      if (!mq->mqrq_cur->req && !mq->mqrq_prev->req)
              wake_up_process(mq->thread);
 }
 
+static void mmc_req_init(struct mmc_async_req *areq, struct completion *compl)
+{
+     struct mmc_queue *mq =
+             container_of(areq->prefetch, struct mmc_queue, prefetch);
+
+     spin_lock(&mq->prefetch_lock);
+     mq->prefetch_completion = compl;
+     if (mq->prefetch_pending)
+             complete(mq->prefetch_completion);
+     spin_unlock(&mq->prefetch_lock);
+}
+
+static void mmc_req_start(struct mmc_async_req *areq, bool enable)
+{
+     struct mmc_queue *mq =
+             container_of(areq->prefetch, struct mmc_queue, prefetch);
+     mq->prefetch_enable = enable;
+}
+
+static bool mmc_req_pending(struct mmc_async_req *areq)
+{
+     struct mmc_queue *mq =
+             container_of(areq->prefetch, struct mmc_queue, prefetch);
+     return mq->prefetch_pending;
+}
+
 static struct scatterlist *mmc_alloc_sg(int sg_len, int *err)
 {
      struct scatterlist *sg;
@@ -166,6 +204,12 @@ int mmc_init_queue(struct mmc_queue *mq, struct
 mmc_card *card,
      int ret;
      struct mmc_queue_req *mqrq_cur = &mq->mqrq[0];
      struct mmc_queue_req *mqrq_prev = &mq->mqrq[1];
+     spin_lock_init(&mq->prefetch_lock);
+     mq->prefetch.wait_req_init = mmc_req_init;
+     mq->prefetch.wait_req_start = mmc_req_start;
+     mq->prefetch.wait_req_pending = mmc_req_pending;
+     mqrq_cur->mmc_active.prefetch = &mq->prefetch;
+     mqrq_prev->mmc_active.prefetch = &mq->prefetch;
 
      if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
              limit = *mmc_dev(host)->dma_mask;
drivers/mmc/card/queue.h +6 -0
index d2a1eb4..5afd467 100644
@@ -33,6 +33,12 @@ struct mmc_queue {
      struct mmc_queue_req    mqrq[2];
      struct mmc_queue_req    *mqrq_cur;
      struct mmc_queue_req    *mqrq_prev;
+
+     struct mmc_async_prefetch prefetch;
+     spinlock_t              prefetch_lock;
+     struct completion       *prefetch_completion;
+     bool                    prefetch_enable;
+     bool                    prefetch_pending;
 };
 
 extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *,
drivers/mmc/core/core.c +0 -0
index 9503cab..06fc036 100644
@@ -352,7 +352,15 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host,
              mmc_pre_req(host, areq->mrq, !host->areq);
 
Quoted 9 lines
Quoted 9 lines

drivers/mmc/core/core.c struct mmc_async_req *mmc_start_req(struct mmc_host *host, · line 362

Quoted 9 lines
drivers/mmc/core/core.c +7 -0
      if (host->areq) {
+             if (!areq)
+                     mmc_prefetch_init(host->areq,
+                                       &host->areq->mrq->completion);
              mmc_wait_for_req_done(host, host->areq->mrq);
+             if (!areq) {
+                     mmc_prefetch_start(host->areq, false);
+                     if (mmc_prefetch_pending(host->areq))
+                             return NULL;

In this case, mmc thread may be unblocked because done() arrived for current request and not because new request notification. In such a case we would like the done request to be handled before fetching the new request. In my code is_done_rcv flag used along with is_new_req flag in order to differentiate the reason for mmc thread awake.

Quoted 67 lines
Quoted 67 lines
Quoted 67 lines
drivers/mmc/core/core.c +1 -0
+             }
              err = host->areq->err_check(host->card, host->areq);
      }
 
include/linux/mmc/host.h +33 -0
index 65c64ee..ce5d03f 100644
@@ -15,6 +15,7 @@
 #include <linux/sched.h>
 #include <linux/device.h>
 #include <linux/fault-inject.h>
+#include <linux/completion.h>
 
 #include <linux/mmc/core.h>
 #include <linux/mmc/pm.h>
@@ -140,6 +141,13 @@ struct mmc_host_ops {
 
 struct mmc_card;
 struct device;
+struct mmc_async_req;
+
+struct mmc_async_prefetch {
+     void (*wait_req_init)(struct mmc_async_req *, struct completion *);
+     void (*wait_req_start)(struct mmc_async_req *, bool);
+     bool (*wait_req_pending)(struct mmc_async_req *);
+};
 
 struct mmc_async_req {
      /* active mmc request */
@@ -149,8 +157,33 @@ struct mmc_async_req {
       * Returns 0 if success otherwise non zero.
       */
      int (*err_check) (struct mmc_card *, struct mmc_async_req *);
+     struct mmc_async_prefetch *prefetch;
 };
 
+/* set completion variable, complete == NULL to reset completion */
+static inline void mmc_prefetch_init(struct mmc_async_req *areq,
+                                  struct completion *complete)
+{
+     if (areq->prefetch && areq->prefetch->wait_req_init)
+             areq->prefetch->wait_req_init(areq, complete);
+}
+
+/* enable or disable prefetch feature */
+static inline void mmc_prefetch_start(struct mmc_async_req *areq, bool enable)
+{
+     if (areq->prefetch && areq->prefetch->wait_req_start)
+             areq->prefetch->wait_req_start(areq, enable);
+}
+
+/* return true if new request is pending otherwise false */
+static inline bool mmc_prefetch_pending(struct mmc_async_req *areq)
+{
+     if (areq->prefetch && areq->prefetch->wait_req_pending)
+             return areq->prefetch->wait_req_pending(areq);
+     else
+             return false;
+}
+
 /**
  * struct mmc_slot - MMC slot functions
  *
....................................................................
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

BR
Per

I understand your motivation and idea for re-structure the patch. It is still not clear for me how exactly mmc thread will be awaken on new request notification in your version, but I have another problem:

mmc_request_fn() is called and it calls complete(mq->prefetch_completion) which wakes up the current thread. My patch is just an example. The intention is to make the patch cleaner. But I may have missed some of the HPI aspects.

Is it the lack of functions wrappers that you are using in your example? As I understand your example, you mean to implement generic logic on core/core.c level by using wrapper functions and leave final implementation for MMC to card/queue.c and for SDIO layer to card/..sdio.. (I'm not too familiar with sdio protocol implementation). Well, it is make a lot of sense.

But the devil is in details - there is a lot of work in mmc_wait_for_data_req_done(), done() callback and also error handling changes for card/block.c

Do you think, that wait_event() API used not suits the same semantic as completion API?

We would like to have a generic capability to handle additional events, such as HPI/stop flow, in addition to the NEW_REQUEST notification. Therefore, an event mechanism seems to be a better design than completion.

I've looked at SDIO code and from what I can understand, right now SDIO is not using async request mechanism and works from 'wait_for_cmd()` level. This means that such work as exposing MMC core API's is major change and definitely should be separate design and implementation effort, while my current patch right now will fix mmc thread behavior and give better performance for upper layers.

Quoted 27 lines

If the API is not implemented the mmc core shall simply ignore it.

Quoted 10 lines

We want to expand this event based mechanism (unblock mmc thread from waiting for the running request) by adding another reason/event. This is URGENT_REQUEST event. When block layer has Urgent request to execute, it notifies mmc layer (similar to mmc_request() notification) and mmc layer handles this urgent request notification by correctly stopping running request, re-inserting back to I/O scheduler all not yet performed parts and fetching & starting the urgent request.
The reasoning and general idea are documented together with "New event" and will be submitted soon. The patch itself will be submitted in a week or so.

I have not consider use of HPI in my proposal. If the NEW_REQ is first in line in the mmc queue it will be fetched as the NEW_REQ. Then the current request must be interrupted and returned to mmc-queue or io-scheduler.

I don't see a direct contradiction between the two designs.

The main point is to make the NEW_REQ API more simple clear. My example is just an example.

Quoted 6 lines

As for our discussion - to handle both events mmc layer should be capable to be awaken not only in case of no mmc_prefetch_pending() (in your patch terms), but also when we have perfect case of async requests:
one running on the bus and second prepared and waiting for the first.

Quoted 8 lines
Quoted 3 lines

I think, that in case SDIO protocol driver need such functionality as NEW_REQUEST, one need to implement notification to the mmc layer similar to mmc_request() code in my patch.

SDIO needs to implement the new NEW_REQ API, but the API needs to be clean.

BR
Per

Best regards,

Signature · 4 lines
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center,
Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#15 lore raw
Quoted 102 lines · Konstantin Dorfman

Hello Per,

Thank you for giving me an example, below I'm trying to explain some logic issues of it and asking you some questions about your vision of the patch.

Quoted 95 lines · Per Förlin
Quoted 94 lines · Konstantin Dorfman

Hello Per,

Quoted 42 lines · Per Forlin
Quoted 33 lines · Konstantin Dorfman

Hello,

Quoted 23 lines · Per Forlin

Hi,

I would like to move the focus of my concerns from root cause analysis to the actual patch,
My first reflection is that the patch is relatively complex and some of the code looks duplicated.
Would it be possible to simplify it and re-use the current execution flow.

Is the following flow feasible?

in mmc_start_req():
--------------
if (rqc == NULL && not_resend)
wait_for_both_mmc_and_arrival_of_new_req
else
wait_only_for_mmc

if (arrival_of_new_req) {
set flag to indicate fetch-new_req
return NULL;
}
-----------------

Quoted 6 lines

in queue.c:
if (fetch-new_req)
don't overwrite previous req.

BR
Per

Quoted 6 lines

You are talking about using both waiting mechanisms, old (wait on completion) and new - wait_event_interruptible()? But how done() callback, called on host controller irq context, will differentiate which one is relevant for the request?

I think it is better to use single wait point for mmc thread.

Quoted 8 lines

I have sketch a patch to better explain my point. It's not tested it barely compiles :)
The patch tries to introduce your feature and still keep the same code path. And it exposes an API that could be used by SDIO as well. The intention of my sketch patch is only to explain what I tried to visualize in the pseudo code previously in this thread.
The out come of your final patch should be documented here I think:
Documentation/mmc/mmc-async-req.txt

This document is ready, attaching it to this mail and will be included in next version of the patch (or RESEND).

Quoted 39 lines

Here follows my patch sketch:
........................................................

drivers/mmc/card/queue.c +9 -5
index e360a97..08036a1 100644
@@ -66,6 +66,8 @@ static int mmc_queue_thread(void *d)
              spin_unlock_irq(q->queue_lock);
 
              if (req || mq->mqrq_prev->req) {
+                     if (!req)
+                             mmc_prefetch_start(&mq->mqrq_prev->mmc_active, true);
                      set_current_state(TASK_RUNNING);
                      mq->issue_fn(mq, req);
              } else {
@@ -79,11 +81,13 @@ static int mmc_queue_thread(void *d)
              }
 
              /* Current request becomes previous request and vice versa. */
-             mq->mqrq_prev->brq.mrq.data = NULL;
-             mq->mqrq_prev->req = NULL;
-             tmp = mq->mqrq_prev;
-             mq->mqrq_prev = mq->mqrq_cur;
-             mq->mqrq_cur = tmp;
+             if (!mmc_prefetch_pending(&mq->mqrq_prev->mmc_active)) {
+                     mq->mqrq_prev->brq.mrq.data = NULL;
+                     mq->mqrq_prev->req = NULL;
+                     tmp = mq->mqrq_prev;
+                     mq->mqrq_prev = mq->mqrq_cur;
+                     mq->mqrq_cur = tmp;
+             }
      } while (1);
      up(&mq->thread_sem);
 
@@ -109,10 +113,44 @@ static void mmc_request_fn(struct request_queue *q)
              return;
      }
 
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

drivers/mmc/card/queue.c static void mmc_request_fn(struct request_queue *q) · line 119

Quoted 4 lines
drivers/mmc/card/queue.c +4 -0
+     if (mq->prefetch_enable) {
+             spin_lock(&mq->prefetch_lock);
+             if (mq->prefetch_completion)
+                     complete(mq->prefetch_completion);

Since mq->prefetch_completion init happens only in core.c after mmc_start_req(NULL), we can miss all new request notifications coming from fetching NULL request until then.

It's a mistake in the patch.
I meant check mq->prefetch_pending to know whether we need to wait in the first place.
That's why mq->prefetch_pending is assigned even if mq->prefetch_completion is not set yet.
Patch needs to be updated to take it into account. One could let mmc_prefecth_init() return and indicate if there is already a NEW_REQ pending. If this is the case skip wait.

Quoted 75 lines
Quoted 75 lines
Quoted 75 lines
Quoted 75 lines
drivers/mmc/card/queue.c +36 -0
+             mq->prefetch_pending = true;
+             spin_unlock(&mq->prefetch_lock);
+     }
+
      if (!mq->mqrq_cur->req && !mq->mqrq_prev->req)
              wake_up_process(mq->thread);
 }
 
+static void mmc_req_init(struct mmc_async_req *areq, struct completion *compl)
+{
+     struct mmc_queue *mq =
+             container_of(areq->prefetch, struct mmc_queue, prefetch);
+
+     spin_lock(&mq->prefetch_lock);
+     mq->prefetch_completion = compl;
+     if (mq->prefetch_pending)
+             complete(mq->prefetch_completion);
+     spin_unlock(&mq->prefetch_lock);
+}
+
+static void mmc_req_start(struct mmc_async_req *areq, bool enable)
+{
+     struct mmc_queue *mq =
+             container_of(areq->prefetch, struct mmc_queue, prefetch);
+     mq->prefetch_enable = enable;
+}
+
+static bool mmc_req_pending(struct mmc_async_req *areq)
+{
+     struct mmc_queue *mq =
+             container_of(areq->prefetch, struct mmc_queue, prefetch);
+     return mq->prefetch_pending;
+}
+
 static struct scatterlist *mmc_alloc_sg(int sg_len, int *err)
 {
      struct scatterlist *sg;
@@ -166,6 +204,12 @@ int mmc_init_queue(struct mmc_queue *mq, struct
 mmc_card *card,
      int ret;
      struct mmc_queue_req *mqrq_cur = &mq->mqrq[0];
      struct mmc_queue_req *mqrq_prev = &mq->mqrq[1];
+     spin_lock_init(&mq->prefetch_lock);
+     mq->prefetch.wait_req_init = mmc_req_init;
+     mq->prefetch.wait_req_start = mmc_req_start;
+     mq->prefetch.wait_req_pending = mmc_req_pending;
+     mqrq_cur->mmc_active.prefetch = &mq->prefetch;
+     mqrq_prev->mmc_active.prefetch = &mq->prefetch;
 
      if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
              limit = *mmc_dev(host)->dma_mask;
drivers/mmc/card/queue.h +6 -0
index d2a1eb4..5afd467 100644
@@ -33,6 +33,12 @@ struct mmc_queue {
      struct mmc_queue_req    mqrq[2];
      struct mmc_queue_req    *mqrq_cur;
      struct mmc_queue_req    *mqrq_prev;
+
+     struct mmc_async_prefetch prefetch;
+     spinlock_t              prefetch_lock;
+     struct completion       *prefetch_completion;
+     bool                    prefetch_enable;
+     bool                    prefetch_pending;
 };
 
 extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *,
drivers/mmc/core/core.c +0 -0
index 9503cab..06fc036 100644
@@ -352,7 +352,15 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host,
              mmc_pre_req(host, areq->mrq, !host->areq);
 
Quoted 13 lines
Quoted 9 lines
Quoted 9 lines

drivers/mmc/core/core.c struct mmc_async_req *mmc_start_req(struct mmc_host *host, · line 362

Quoted 9 lines
drivers/mmc/core/core.c +7 -0
      if (host->areq) {
+             if (!areq)
+                     mmc_prefetch_init(host->areq,
+                                       &host->areq->mrq->completion);
              mmc_wait_for_req_done(host, host->areq->mrq);
+             if (!areq) {
+                     mmc_prefetch_start(host->areq, false);
+                     if (mmc_prefetch_pending(host->areq))
+                             return NULL;

In this case, mmc thread may be unblocked because done() arrived for current request and not because new request notification. In such a case we would like the done request to be handled before fetching the new request.

I agree. We wake up and there is no pending new request execution should proceed normally by handling the completed request.

Quoted 2 lines

In my code is_done_rcv flag used along with is_new_req flag in order to differentiate the reason for mmc thread awake.

In my patch the return value of "mmc_prefetch_pending()" specifies if thee is a pending request.what should happen.
If both current request is done and mmc_prefetch_pending is done at the same time I see there is a problem with my patch. There needs to be a flag to indicate if current request is done.

Quoted 74 lines
Quoted 74 lines
Quoted 74 lines
Quoted 68 lines
drivers/mmc/core/core.c +1 -0
+             }
              err = host->areq->err_check(host->card, host->areq);
      }
 
include/linux/mmc/host.h +33 -0
index 65c64ee..ce5d03f 100644
@@ -15,6 +15,7 @@
 #include <linux/sched.h>
 #include <linux/device.h>
 #include <linux/fault-inject.h>
+#include <linux/completion.h>
 
 #include <linux/mmc/core.h>
 #include <linux/mmc/pm.h>
@@ -140,6 +141,13 @@ struct mmc_host_ops {
 
 struct mmc_card;
 struct device;
+struct mmc_async_req;
+
+struct mmc_async_prefetch {
+     void (*wait_req_init)(struct mmc_async_req *, struct completion *);
+     void (*wait_req_start)(struct mmc_async_req *, bool);
+     bool (*wait_req_pending)(struct mmc_async_req *);
+};
 
 struct mmc_async_req {
      /* active mmc request */
@@ -149,8 +157,33 @@ struct mmc_async_req {
       * Returns 0 if success otherwise non zero.
       */
      int (*err_check) (struct mmc_card *, struct mmc_async_req *);
+     struct mmc_async_prefetch *prefetch;
 };
 
+/* set completion variable, complete == NULL to reset completion */
+static inline void mmc_prefetch_init(struct mmc_async_req *areq,
+                                  struct completion *complete)
+{
+     if (areq->prefetch && areq->prefetch->wait_req_init)
+             areq->prefetch->wait_req_init(areq, complete);
+}
+
+/* enable or disable prefetch feature */
+static inline void mmc_prefetch_start(struct mmc_async_req *areq, bool enable)
+{
+     if (areq->prefetch && areq->prefetch->wait_req_start)
+             areq->prefetch->wait_req_start(areq, enable);
+}
+
+/* return true if new request is pending otherwise false */
+static inline bool mmc_prefetch_pending(struct mmc_async_req *areq)
+{
+     if (areq->prefetch && areq->prefetch->wait_req_pending)
+             return areq->prefetch->wait_req_pending(areq);
+     else
+             return false;
+}
+
 /**
  * struct mmc_slot - MMC slot functions
  *
....................................................................
Quoted 2 lines

BR
Per

I understand your motivation and idea for re-structure the patch. It is still not clear for me how exactly mmc thread will be awaken on new request notification in your version, but I have another problem:

Quoted 4 lines
Quoted 2 lines

mmc_request_fn() is called and it calls complete(mq->prefetch_completion) which wakes up the current thread. My patch is just an example. The intention is to make the patch cleaner. But I may have missed some of the HPI aspects.

Is it the lack of functions wrappers that you are using in your example?

It's fine to skip the functions wrappers if it makes no sense.
What I want to avoid is to create new functions for data_req_start and data_req_wait.
I would rather add this to the existing functions in core.c and keep changes in block.c and the flow minimal.

Quoted 6 lines

As I understand your example, you mean to implement generic logic on core/core.c level by using wrapper functions and leave final implementation for MMC to card/queue.c and for SDIO layer to card/..sdio.. (I'm not too familiar with sdio protocol implementation). Well, it is make a lot of sense.

I still have "plans" to add pre/post/async support in the SDIO framework too but I have not got to it. I would be nice to add your NEW_REQ feature along with the other mmc-async features, to make it usable from SDIO.

Quoted 3 lines

But the devil is in details - there is a lot of work in mmc_wait_for_data_req_done(), done() callback and also error handling changes for card/block.c

Things in core.c could be re-used in the SDIO case. In block.c there are only FS specific implementation not relevant for SDIO.

Quoted 3 lines

Do you think, that wait_event() API used not suits the same semantic as completion API?

The waiting mechanims may be wait_event or completion.
I'm not in favor of using both. Better to replace completion with wait_event if you prefer.

My main concern is to avoid adding new API to core.c in order to add the NEW_REQ feature. My patch is an example of changes to be done in core.c without adding new functions.

Quoted 11 lines

We would like to have a generic capability to handle additional events, such as HPI/stop flow, in addition to the NEW_REQUEST notification. Therefore, an event mechanism seems to be a better design than completion.

I've looked at SDIO code and from what I can understand, right now SDIO is not using async request mechanism and works from 'wait_for_cmd()` level. This means that such work as exposing MMC core API's is major change and definitely should be separate design and implementation effort, while my current patch right now will fix mmc thread behavior and give better performance for upper layers.

You are right. There is no support in the SDIO implementation for pre/post/async feature. Still I had it in mind design the "struct mmc_async". It's possible to re-use the mmc core parts in order to utilize this support in the SDIO case. I'm not saying we should design for SDIO but at least keep the API in a way that it's potential usable from SDIO too. The API of core.c (start/wait of requests) should make sense without the existence of MMC block driver (block/queue).

One way to test the design is to add a test in mmc_test.c for penging NEW_REQ. In mmc_test.c there is not block.c or queue.c. If the test case if simple to write in mmc_test.c it's means that the API is on a good level.

BR
Per

Quoted 44 lines
Quoted 29 lines

If the API is not implemented the mmc core shall simply ignore it.

Quoted 10 lines

We want to expand this event based mechanism (unblock mmc thread from waiting for the running request) by adding another reason/event. This is URGENT_REQUEST event. When block layer has Urgent request to execute, it notifies mmc layer (similar to mmc_request() notification) and mmc layer handles this urgent request notification by correctly stopping running request, re-inserting back to I/O scheduler all not yet performed parts and fetching & starting the urgent request.
The reasoning and general idea are documented together with "New event" and will be submitted soon. The patch itself will be submitted in a week or so.

I have not consider use of HPI in my proposal. If the NEW_REQ is first in line in the mmc queue it will be fetched as the NEW_REQ. Then the current request must be interrupted and returned to mmc-queue or io-scheduler.

I don't see a direct contradiction between the two designs.

The main point is to make the NEW_REQ API more simple clear. My example is just an example.

Quoted 6 lines

As for our discussion - to handle both events mmc layer should be capable to be awaken not only in case of no mmc_prefetch_pending() (in your patch terms), but also when we have perfect case of async requests:
one running on the bus and second prepared and waiting for the first.

Quoted 8 lines
Quoted 3 lines

I think, that in case SDIO protocol driver need such functionality as NEW_REQUEST, one need to implement notification to the mmc layer similar to mmc_request() code in my patch.

SDIO needs to implement the new NEW_REQ API, but the API needs to be clean.

BR
Per

Best regards,
--
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

#16 lore raw
Quoted 306 lines · Per Förlin
Quoted 102 lines · Konstantin Dorfman

Hello Per,

Thank you for giving me an example, below I'm trying to explain some logic issues of it and asking you some questions about your vision of the patch.

Quoted 95 lines · Per Förlin
Quoted 94 lines · Konstantin Dorfman

Hello Per,

Quoted 42 lines · Per Forlin
Quoted 33 lines · Konstantin Dorfman

Hello,

Quoted 23 lines · Per Forlin

Hi,

I would like to move the focus of my concerns from root cause analysis to the actual patch,
My first reflection is that the patch is relatively complex and some of the code looks duplicated.
Would it be possible to simplify it and re-use the current execution flow.

Is the following flow feasible?

in mmc_start_req():
--------------
if (rqc == NULL && not_resend)
wait_for_both_mmc_and_arrival_of_new_req
else
wait_only_for_mmc

if (arrival_of_new_req) {
set flag to indicate fetch-new_req
return NULL;
}
-----------------

Quoted 6 lines

in queue.c:
if (fetch-new_req)
don't overwrite previous req.

BR
Per

Quoted 6 lines

You are talking about using both waiting mechanisms, old (wait on completion) and new - wait_event_interruptible()? But how done() callback, called on host controller irq context, will differentiate which one is relevant for the request?

I think it is better to use single wait point for mmc thread.

Quoted 8 lines

I have sketch a patch to better explain my point. It's not tested it barely compiles :)
The patch tries to introduce your feature and still keep the same code path. And it exposes an API that could be used by SDIO as well. The intention of my sketch patch is only to explain what I tried to visualize in the pseudo code previously in this thread.
The out come of your final patch should be documented here I think:
Documentation/mmc/mmc-async-req.txt

This document is ready, attaching it to this mail and will be included in next version of the patch (or RESEND).

Quoted 39 lines

Here follows my patch sketch:
........................................................

drivers/mmc/card/queue.c +9 -5
index e360a97..08036a1 100644
@@ -66,6 +66,8 @@ static int mmc_queue_thread(void *d)
              spin_unlock_irq(q->queue_lock);
 
              if (req || mq->mqrq_prev->req) {
+                     if (!req)
+                             mmc_prefetch_start(&mq->mqrq_prev->mmc_active, true);
                      set_current_state(TASK_RUNNING);
                      mq->issue_fn(mq, req);
              } else {
@@ -79,11 +81,13 @@ static int mmc_queue_thread(void *d)
              }
 
              /* Current request becomes previous request and vice versa. */
-             mq->mqrq_prev->brq.mrq.data = NULL;
-             mq->mqrq_prev->req = NULL;
-             tmp = mq->mqrq_prev;
-             mq->mqrq_prev = mq->mqrq_cur;
-             mq->mqrq_cur = tmp;
+             if (!mmc_prefetch_pending(&mq->mqrq_prev->mmc_active)) {
+                     mq->mqrq_prev->brq.mrq.data = NULL;
+                     mq->mqrq_prev->req = NULL;
+                     tmp = mq->mqrq_prev;
+                     mq->mqrq_prev = mq->mqrq_cur;
+                     mq->mqrq_cur = tmp;
+             }
      } while (1);
      up(&mq->thread_sem);
 
@@ -109,10 +113,44 @@ static void mmc_request_fn(struct request_queue *q)
              return;
      }
 
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

drivers/mmc/card/queue.c static void mmc_request_fn(struct request_queue *q) · line 119

Quoted 4 lines
drivers/mmc/card/queue.c +4 -0
+     if (mq->prefetch_enable) {
+             spin_lock(&mq->prefetch_lock);
+             if (mq->prefetch_completion)
+                     complete(mq->prefetch_completion);

Since mq->prefetch_completion init happens only in core.c after mmc_start_req(NULL), we can miss all new request notifications coming from fetching NULL request until then.

It's a mistake in the patch.
I meant check mq->prefetch_pending to know whether we need to wait in the first place.
That's why mq->prefetch_pending is assigned even if mq->prefetch_completion is not set yet.
Patch needs to be updated to take it into account. One could let mmc_prefecth_init() return and indicate if there is already a NEW_REQ pending. If this is the case skip wait.

Quoted 75 lines
Quoted 75 lines
Quoted 75 lines
Quoted 75 lines
drivers/mmc/card/queue.c +36 -0
+             mq->prefetch_pending = true;
+             spin_unlock(&mq->prefetch_lock);
+     }
+
      if (!mq->mqrq_cur->req && !mq->mqrq_prev->req)
              wake_up_process(mq->thread);
 }
 
+static void mmc_req_init(struct mmc_async_req *areq, struct completion *compl)
+{
+     struct mmc_queue *mq =
+             container_of(areq->prefetch, struct mmc_queue, prefetch);
+
+     spin_lock(&mq->prefetch_lock);
+     mq->prefetch_completion = compl;
+     if (mq->prefetch_pending)
+             complete(mq->prefetch_completion);
+     spin_unlock(&mq->prefetch_lock);
+}
+
+static void mmc_req_start(struct mmc_async_req *areq, bool enable)
+{
+     struct mmc_queue *mq =
+             container_of(areq->prefetch, struct mmc_queue, prefetch);
+     mq->prefetch_enable = enable;
+}
+
+static bool mmc_req_pending(struct mmc_async_req *areq)
+{
+     struct mmc_queue *mq =
+             container_of(areq->prefetch, struct mmc_queue, prefetch);
+     return mq->prefetch_pending;
+}
+
 static struct scatterlist *mmc_alloc_sg(int sg_len, int *err)
 {
      struct scatterlist *sg;
@@ -166,6 +204,12 @@ int mmc_init_queue(struct mmc_queue *mq, struct
 mmc_card *card,
      int ret;
      struct mmc_queue_req *mqrq_cur = &mq->mqrq[0];
      struct mmc_queue_req *mqrq_prev = &mq->mqrq[1];
+     spin_lock_init(&mq->prefetch_lock);
+     mq->prefetch.wait_req_init = mmc_req_init;
+     mq->prefetch.wait_req_start = mmc_req_start;
+     mq->prefetch.wait_req_pending = mmc_req_pending;
+     mqrq_cur->mmc_active.prefetch = &mq->prefetch;
+     mqrq_prev->mmc_active.prefetch = &mq->prefetch;
 
      if (mmc_dev(host)->dma_mask && *mmc_dev(host)->dma_mask)
              limit = *mmc_dev(host)->dma_mask;
drivers/mmc/card/queue.h +6 -0
index d2a1eb4..5afd467 100644
@@ -33,6 +33,12 @@ struct mmc_queue {
      struct mmc_queue_req    mqrq[2];
      struct mmc_queue_req    *mqrq_cur;
      struct mmc_queue_req    *mqrq_prev;
+
+     struct mmc_async_prefetch prefetch;
+     spinlock_t              prefetch_lock;
+     struct completion       *prefetch_completion;
+     bool                    prefetch_enable;
+     bool                    prefetch_pending;
 };
 
 extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *,
drivers/mmc/core/core.c +0 -0
index 9503cab..06fc036 100644
@@ -352,7 +352,15 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host,
              mmc_pre_req(host, areq->mrq, !host->areq);
 
Quoted 13 lines
Quoted 9 lines
Quoted 9 lines

drivers/mmc/core/core.c struct mmc_async_req *mmc_start_req(struct mmc_host *host, · line 362

Quoted 9 lines
drivers/mmc/core/core.c +7 -0
      if (host->areq) {
+             if (!areq)
+                     mmc_prefetch_init(host->areq,
+                                       &host->areq->mrq->completion);
              mmc_wait_for_req_done(host, host->areq->mrq);
+             if (!areq) {
+                     mmc_prefetch_start(host->areq, false);
+                     if (mmc_prefetch_pending(host->areq))
+                             return NULL;

In this case, mmc thread may be unblocked because done() arrived for current request and not because new request notification. In such a case we would like the done request to be handled before fetching the new request.

I agree. We wake up and there is no pending new request execution should proceed normally by handling the completed request.

Quoted 2 lines

In my code is_done_rcv flag used along with is_new_req flag in order to differentiate the reason for mmc thread awake.

In my patch the return value of "mmc_prefetch_pending()" specifies if thee is a pending request.what should happen.
If both current request is done and mmc_prefetch_pending is done at the same time I see there is a problem with my patch. There needs to be a flag to indicate if current request is done.

Quoted 74 lines
Quoted 74 lines
Quoted 74 lines
Quoted 68 lines
drivers/mmc/core/core.c +1 -0
+             }
              err = host->areq->err_check(host->card, host->areq);
      }
 
include/linux/mmc/host.h +33 -0
index 65c64ee..ce5d03f 100644
@@ -15,6 +15,7 @@
 #include <linux/sched.h>
 #include <linux/device.h>
 #include <linux/fault-inject.h>
+#include <linux/completion.h>
 
 #include <linux/mmc/core.h>
 #include <linux/mmc/pm.h>
@@ -140,6 +141,13 @@ struct mmc_host_ops {
 
 struct mmc_card;
 struct device;
+struct mmc_async_req;
+
+struct mmc_async_prefetch {
+     void (*wait_req_init)(struct mmc_async_req *, struct completion *);
+     void (*wait_req_start)(struct mmc_async_req *, bool);
+     bool (*wait_req_pending)(struct mmc_async_req *);
+};
 
 struct mmc_async_req {
      /* active mmc request */
@@ -149,8 +157,33 @@ struct mmc_async_req {
       * Returns 0 if success otherwise non zero.
       */
      int (*err_check) (struct mmc_card *, struct mmc_async_req *);
+     struct mmc_async_prefetch *prefetch;
 };
 
+/* set completion variable, complete == NULL to reset completion */
+static inline void mmc_prefetch_init(struct mmc_async_req *areq,
+                                  struct completion *complete)
+{
+     if (areq->prefetch && areq->prefetch->wait_req_init)
+             areq->prefetch->wait_req_init(areq, complete);
+}
+
+/* enable or disable prefetch feature */
+static inline void mmc_prefetch_start(struct mmc_async_req *areq, bool enable)
+{
+     if (areq->prefetch && areq->prefetch->wait_req_start)
+             areq->prefetch->wait_req_start(areq, enable);
+}
+
+/* return true if new request is pending otherwise false */
+static inline bool mmc_prefetch_pending(struct mmc_async_req *areq)
+{
+     if (areq->prefetch && areq->prefetch->wait_req_pending)
+             return areq->prefetch->wait_req_pending(areq);
+     else
+             return false;
+}
+
 /**
  * struct mmc_slot - MMC slot functions
  *
....................................................................
Quoted 2 lines

BR
Per

I understand your motivation and idea for re-structure the patch. It is still not clear for me how exactly mmc thread will be awaken on new request notification in your version, but I have another problem:

Quoted 4 lines
Quoted 2 lines

mmc_request_fn() is called and it calls complete(mq->prefetch_completion) which wakes up the current thread. My patch is just an example. The intention is to make the patch cleaner. But I may have missed some of the HPI aspects.

Is it the lack of functions wrappers that you are using in your example?

It's fine to skip the functions wrappers if it makes no sense.
What I want to avoid is to create new functions for data_req_start and data_req_wait.
I would rather add this to the existing functions in core.c and keep changes in block.c and the flow minimal.

Quoted 6 lines

As I understand your example, you mean to implement generic logic on core/core.c level by using wrapper functions and leave final implementation for MMC to card/queue.c and for SDIO layer to card/..sdio.. (I'm not too familiar with sdio protocol implementation). Well, it is make a lot of sense.

I still have "plans" to add pre/post/async support in the SDIO framework too but I have not got to it. I would be nice to add your NEW_REQ feature along with the other mmc-async features, to make it usable from SDIO.

Quoted 3 lines

But the devil is in details - there is a lot of work in mmc_wait_for_data_req_done(), done() callback and also error handling changes for card/block.c

Quoted 8 lines

Things in core.c could be re-used in the SDIO case. In block.c there are only FS specific implementation not relevant for SDIO.

Quoted 3 lines

Do you think, that wait_event() API used not suits the same semantic as completion API?

The waiting mechanims may be wait_event or completion.
I'm not in favor of using both. Better to replace completion with wait_event if you prefer.

I'm fine with wait_event() (block request transfers) combined with completion (for other transfer), as long as the core.c API is intact. I don't see a reason for a new start_data_req()

mmc_start_req() is only used by the mmc block transfers.
Making a test case in mmc_test.c is a good way to stress test the feature (e.g. random timing of incoming new requests) and it will show how the API works too.

BR
Per

Quoted 67 lines

My main concern is to avoid adding new API to core.c in order to add the NEW_REQ feature. My patch is an example of changes to be done in core.c without adding new functions.

Quoted 11 lines

We would like to have a generic capability to handle additional events, such as HPI/stop flow, in addition to the NEW_REQUEST notification. Therefore, an event mechanism seems to be a better design than completion.

I've looked at SDIO code and from what I can understand, right now SDIO is not using async request mechanism and works from 'wait_for_cmd()` level. This means that such work as exposing MMC core API's is major change and definitely should be separate design and implementation effort, while my current patch right now will fix mmc thread behavior and give better performance for upper layers.

You are right. There is no support in the SDIO implementation for pre/post/async feature. Still I had it in mind design the "struct mmc_async". It's possible to re-use the mmc core parts in order to utilize this support in the SDIO case. I'm not saying we should design for SDIO but at least keep the API in a way that it's potential usable from SDIO too. The API of core.c (start/wait of requests) should make sense without the existence of MMC block driver (block/queue).

One way to test the design is to add a test in mmc_test.c for penging NEW_REQ. In mmc_test.c there is not block.c or queue.c. If the test case if simple to write in mmc_test.c it's means that the API is on a good level.

BR
Per

Quoted 44 lines
Quoted 29 lines

If the API is not implemented the mmc core shall simply ignore it.

Quoted 10 lines

We want to expand this event based mechanism (unblock mmc thread from waiting for the running request) by adding another reason/event. This is URGENT_REQUEST event. When block layer has Urgent request to execute, it notifies mmc layer (similar to mmc_request() notification) and mmc layer handles this urgent request notification by correctly stopping running request, re-inserting back to I/O scheduler all not yet performed parts and fetching & starting the urgent request.
The reasoning and general idea are documented together with "New event" and will be submitted soon. The patch itself will be submitted in a week or so.

I have not consider use of HPI in my proposal. If the NEW_REQ is first in line in the mmc queue it will be fetched as the NEW_REQ. Then the current request must be interrupted and returned to mmc-queue or io-scheduler.

I don't see a direct contradiction between the two designs.

The main point is to make the NEW_REQ API more simple clear. My example is just an example.

Quoted 6 lines

As for our discussion - to handle both events mmc layer should be capable to be awaken not only in case of no mmc_prefetch_pending() (in your patch terms), but also when we have perfect case of async requests:
one running on the bus and second prepared and waiting for the first.

Quoted 8 lines
Quoted 3 lines

I think, that in case SDIO protocol driver need such functionality as NEW_REQUEST, one need to implement notification to the mmc layer similar to mmc_request() code in my patch.

SDIO needs to implement the new NEW_REQ API, but the API needs to be clean.

BR
Per

Best regards,
--
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

#17 lore raw

Hello,

Quoted 13 lines · Per Förlin
Quoted 13 lines
Quoted 13 lines
Quoted 9 lines
Quoted 9 lines

drivers/mmc/core/core.c struct mmc_async_req *mmc_start_req(struct mmc_host *host, · line 362

Quoted 9 lines
       if (host->areq) {
drivers/mmc/core/core.c +7 -0
+             if (!areq)
+                     mmc_prefetch_init(host->areq,
+                                       &host->areq->mrq->completion);
               mmc_wait_for_req_done(host, host->areq->mrq);
+             if (!areq) {
+                     mmc_prefetch_start(host->areq, false);
+                     if (mmc_prefetch_pending(host->areq))
+                             return NULL;

In this case, mmc thread may be unblocked because done() arrived for current request and not because new request notification. In such a case we would like the done request to be handled before fetching the new request.

Quoted 6 lines
Quoted 6 lines

I agree. We wake up and there is no pending new request execution should proceed normally by handling the completed request.

Quoted 2 lines

In my code is_done_rcv flag used along with is_new_req flag in order to differentiate the reason for mmc thread awake.

In my patch the return value of "mmc_prefetch_pending()" specifies if thee is a pending request.what should happen.
If both current request is done and mmc_prefetch_pending is done at the same time I see there is a problem with my patch. There needs to be a flag to indicate if current request is done.

There is race between done() and NEW_REQUEST events, also when we got both of them, the order is to complete current and then to fetch new.

Quoted 28 lines
Quoted 28 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

I understand your motivation and idea for re-structure the patch. It is still not clear for me how exactly mmc thread will be awaken on new request notification in your version, but I have another problem:

mmc_request_fn() is called and it calls complete(mq->prefetch_completion) which wakes up the current thread. My patch is just an example. The intention is to make the patch cleaner. But I may have missed some of the HPI aspects.

Is it the lack of functions wrappers that you are using in your example?

It's fine to skip the functions wrappers if it makes no sense.
What I want to avoid is to create new functions for data_req_start and data_req_wait.
I would rather add this to the existing functions in core.c and keep changes in block.c and the flow minimal.

Quoted 6 lines

As I understand your example, you mean to implement generic logic on core/core.c level by using wrapper functions and leave final implementation for MMC to card/queue.c and for SDIO layer to card/..sdio.. (I'm not too familiar with sdio protocol implementation). Well, it is make a lot of sense.

I still have "plans" to add pre/post/async support in the SDIO framework too but I have not got to it. I would be nice to add your NEW_REQ feature along with the other mmc-async features, to make it usable from SDIO.

Quoted 3 lines

But the devil is in details - there is a lot of work in mmc_wait_for_data_req_done(), done() callback and also error handling changes for card/block.c

Things in core.c could be re-used in the SDIO case. In block.c there are only FS specific implementation not relevant for SDIO.

Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Do you think, that wait_event() API used not suits the same semantic as completion API?

The waiting mechanims may be wait_event or completion.
I'm not in favor of using both. Better to replace completion with wait_event if you prefer.

I'm fine with wait_event() (block request transfers) combined with completion (for other transfer), as long as the core.c API is intact. I don't see a reason for a new start_data_req()

mmc_start_req() is only used by the mmc block transfers.

The main idea is to change start_req() waiting point (mmc_wait_for_data_req_done() function) in such way that external events (in the MMC case it is coming from block layer) may awake MMC context from waiting for current request. This is done by change the original mmc_start_req() function and not changing its signature of mmc_start_req().

May I ask you to see [PATCH v2] patch? I think that is is no change in core.c API (by core.c API you mean all functions from core.h?).

Also to use new request feature of core.c one need to implement notification similar to mmc_request_fn() and I do not see difficulties to do it from SDIO.

Quoted 22 lines

Making a test case in mmc_test.c is a good way to stress test the feature (e.g. random timing of incoming new requests) and it will show how the API works too.

BR
Per

Quoted 17 lines

My main concern is to avoid adding new API to core.c in order to add the NEW_REQ feature. My patch is an example of changes to be done in core.c without adding new functions.

Quoted 11 lines

We would like to have a generic capability to handle additional events, such as HPI/stop flow, in addition to the NEW_REQUEST notification. Therefore, an event mechanism seems to be a better design than completion.

I've looked at SDIO code and from what I can understand, right now SDIO is not using async request mechanism and works from 'wait_for_cmd()` level. This means that such work as exposing MMC core API's is major change and definitely should be separate design and implementation effort, while my current patch right now will fix mmc thread behavior and give better performance for upper layers.

You are right. There is no support in the SDIO implementation for pre/post/async feature. Still I had it in mind design the "struct mmc_async". It's possible to re-use the mmc core parts in order to utilize this support in the SDIO case. I'm not saying we should design for SDIO but at least keep the API in a way that it's potential usable from SDIO too. The API of core.c (start/wait of requests) should make sense without the existence of MMC block driver (block/queue).

One way to test the design is to add a test in mmc_test.c for penging NEW_REQ. In mmc_test.c there is not block.c or queue.c. If the test case if simple to write in mmc_test.c it's means that the API is on a good level.

I have plans to implement new test in mmc_test.c, but current patch was tested using special test I/O scheduler, that is used instead of cfq I/O scheduler: "[PATCH v5 1/3] block: Add test-iosched scheduler"

This gives us great power to create any ut scenarios.

Signature · 4 lines
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center,
Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#18 lore raw

Correction inside

Quoted 90 lines · Konstantin Dorfman

Hello,

Quoted 18 lines · Per Förlin
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Review

Quoted 10 lines
       if (host->areq) {
(quoted diff) +3 -0
+             if (!areq)
+                     mmc_prefetch_init(host->areq,
+
&host->areq->mrq->completion);
               mmc_wait_for_req_done(host, host->areq->mrq);
(quoted diff) +4 -0
+             if (!areq) {
+                     mmc_prefetch_start(host->areq, false);
+                     if (mmc_prefetch_pending(host->areq))
+                             return NULL;
Quoted 5 lines

In this case, mmc thread may be unblocked because done() arrived for current request and not because new request notification. In such a case
we would like the done request to be handled before fetching the new request.

I agree. We wake up and there is no pending new request execution should proceed normally by handling the completed request.

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

In my code is_done_rcv flag used along with is_new_req flag in order to differentiate the reason for mmc thread awake.

In my patch the return value of "mmc_prefetch_pending()" specifies if thee is a pending request.what should happen.
If both current request is done and mmc_prefetch_pending is done at the same time I see there is a problem with my patch. There needs to be a flag to indicate if current request is done.

There is race between done() and NEW_REQUEST events, also when we got both of them, the order is to complete current and then to fetch new.

Quoted 45 lines
Quoted 38 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

I understand your motivation and idea for re-structure the patch. It is
still not clear for me how exactly mmc thread will be awaken on new request notification in your version, but I have another problem:

Quoted 7 lines
Quoted 4 lines

mmc_request_fn() is called and it calls complete(mq->prefetch_completion) which wakes up the current thread. My patch is just an example. The intention is to make the patch cleaner. But I may have missed some of the HPI aspects.

Is it the lack of functions wrappers that you are using in your example?

It's fine to skip the functions wrappers if it makes no sense. What I want to avoid is to create new functions for data_req_start and data_req_wait.
I would rather add this to the existing functions in core.c and keep changes in block.c and the flow minimal.

Quoted 7 lines

As I understand your example, you mean to implement generic logic on core/core.c level by using wrapper functions and leave final implementation for MMC to card/queue.c and for SDIO layer to card/..sdio.. (I'm not too familiar with sdio protocol implementation).
Well, it is make a lot of sense.

I still have "plans" to add pre/post/async support in the SDIO framework too but I have not got to it.
I would be nice to add your NEW_REQ feature along with the other mmc-async features, to make it usable from SDIO.

Quoted 3 lines

But the devil is in details - there is a lot of work in mmc_wait_for_data_req_done(), done() callback and also error handling changes for card/block.c

Things in core.c could be re-used in the SDIO case. In block.c there are only FS specific implementation not relevant for SDIO.

Quoted 1 line
Quoted 7 lines
Quoted 3 lines

Do you think, that wait_event() API used not suits the same semantic as
completion API?

The waiting mechanims may be wait_event or completion. I'm not in favor of using both. Better to replace completion with wait_event if you prefer.

Quoted 5 lines

I'm fine with wait_event() (block request transfers) combined with completion (for other transfer), as long as the core.c API is intact. I don't see a reason for a new start_data_req()

mmc_start_req() is only used by the mmc block transfers.

The main idea is to change start_req() waiting point (mmc_wait_for_data_req_done() function) in such way that external events (in the MMC case it is coming from block layer) may awake MMC context from waiting for current request. This is done by change the original mmc_start_req() function and not changing its signature of mmc_start_req().

Quoted 3 lines

May I ask you to see [PATCH v2] patch? I think that is is no change in core.c API (by core.c API you mean all functions from core.h?).

[PATCH v3] mmc: fix async request mechanism for sequential read scenarios

Quoted 58 lines

Also to use new request feature of core.c one need to implement notification similar to mmc_request_fn() and I do not see difficulties to do it from SDIO.

Quoted 4 lines

Making a test case in mmc_test.c is a good way to stress test the feature (e.g. random timing of incoming new requests) and it will show how the API works too.

Quoted 33 lines

BR
Per

Quoted 30 lines

My main concern is to avoid adding new API to core.c in order to add the NEW_REQ feature. My patch is an example of changes to be done in core.c without adding new functions.

Quoted 7 lines

We would like to have a generic capability to handle additional events,
such as HPI/stop flow, in addition to the NEW_REQUEST notification. Therefore, an event mechanism seems to be a better design than completion.

Quoted 7 lines

I've looked at SDIO code and from what I can understand, right now SDIO
is not using async request mechanism and works from 'wait_for_cmd()` level. This means that such work as exposing MMC core API's is major change and definitely should be separate design and implementation effort, while my current patch right now will fix mmc thread behavior and give better performance for upper layers.

You are right. There is no support in the SDIO implementation for pre/post/async feature. Still I had it in mind design the "struct mmc_async". It's possible to re-use the mmc core parts in order to utilize this support in the SDIO case. I'm not saying we should design for SDIO but at least keep the API in a way that it's potential usable from SDIO too. The API of core.c (start/wait of requests) should make sense without the existence of MMC block driver (block/queue).

One way to test the design is to add a test in mmc_test.c for penging NEW_REQ. In mmc_test.c there is not block.c or queue.c.
If the test case if simple to write in mmc_test.c it's means that the API is on a good level.

I have plans to implement new test in mmc_test.c, but current patch was tested using special test I/O scheduler, that is used instead of cfq I/O
scheduler: "[PATCH v5 1/3] block: Add test-iosched scheduler"

This gives us great power to create any ut scenarios.

--
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 3 lines
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#19 lore raw
In reply to Per Förlin

Hello,

Quoted 11 lines · Per Förlin
Quoted 2 lines · Per Förlin

On 11/19/2012 10:48 AM, Konstantin Dorfman wrote:

I'm fine with wait_event() (block request transfers) combined with completion (for other transfer), as long as the core.c API is intact. I don't see a reason for a new start_data_req()

mmc_start_req() is only used by the mmc block transfers.
Making a test case in mmc_test.c is a good way to stress test the feature (e.g. random timing of incoming new requests) and it will show how the API works too.

BR
Per

Right now there are couple of tests in mmc_test module that use async request mechanism. After applying my fix (v3 mmc: fix async request mechanism for sequential read scenarios), these test were broken.

The patch attached fixes those broken tests and also you can see exactly what is API change. It is not in mmc_start_req() signature, it is new context_info field that we need to synchronize with NEW_REQUEST notification. mmc_test is not uses the notification, but it is very easy to implement.

Quoted 1 line
Quoted 1 line

My main concern is to avoid adding new API to core.c in order to add the NEW_REQ feature. My patch is an example of changes to be done in core.c without adding new functions.

Now you can review API changes.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

We would like to have a generic capability to handle additional events, such as HPI/stop flow, in addition to the NEW_REQUEST notification. Therefore, an event mechanism seems to be a better design than completion.

I've looked at SDIO code and from what I can understand, right now SDIO is not using async request mechanism and works from 'wait_for_cmd()` level. This means that such work as exposing MMC core API's is major change and definitely should be separate design and implementation effort, while my current patch right now will fix mmc thread behavior and give better performance for upper layers.

Quoted 4 lines
Quoted 4 lines

You are right. There is no support in the SDIO implementation for pre/post/async feature. Still I had it in mind design the "struct mmc_async". It's possible to re-use the mmc core parts in order to utilize this support in the SDIO case. I'm not saying we should design for SDIO but at least keep the API in a way that it's potential usable from SDIO too. The API of core.c (start/wait of requests) should make sense without the existence of MMC block driver (block/queue).

One way to test the design is to add a test in mmc_test.c for penging NEW_REQ. In mmc_test.c there is not block.c or queue.c. If the test case if simple to write in mmc_test.c it's means that the API is on a good level.

I can simulate single NEW_PACKET notification in the mmc_test, but this will check only correctness, without real queue of requests we can't see/measure tpt/latency gain of this.

Kind reminder about patch v3, waiting for your review.

Thanks

Signature · 4 lines
Konstantin Dorfman,
QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center,
Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
Quoted 1 line

From 240fa5757e9c784679b391ba42ec58e70fe856d9 Mon Sep 17 00:00:00 2001

From: Konstantin Dorfman <[email protected]>
Date: Mon, 26 Nov 2012 11:50:35 +0200
Subject: [RFC/PATCH] mmc_test: fix non-blocking req test to support mmc core
wait_event mechanism

After introduce new wait_event synchronization mechanism at mmc/core/core.c level, non-blocking request tests from mmc_test ut module are broken.

This patch fixes the tests by updating test environment to work correctly on top of new wait_event mechanism.

drivers/mmc/card/mmc_test.c +13 -5
index 759714e..764471f 100644
@@ -764,7 +764,8 @@ static int mmc_test_check_broken_result(struct mmc_test_card *test,
 static void mmc_test_nonblock_reset(struct mmc_request *mrq,
 				    struct mmc_command *cmd,
 				    struct mmc_command *stop,
-				    struct mmc_data *data)
+				    struct mmc_data *data,
+				    struct mmc_context_info *context_info)
 {
 	memset(mrq, 0, sizeof(struct mmc_request));
 	memset(cmd, 0, sizeof(struct mmc_command));
@@ -774,6 +775,7 @@ static void mmc_test_nonblock_reset(struct mmc_request *mrq,
 	mrq->cmd = cmd;
 	mrq->data = data;
 	mrq->stop = stop;
+	mrq->context_info = context_info;
 }
 static int mmc_test_nonblock_transfer(struct mmc_test_card *test,
 				      struct scatterlist *sg, unsigned sg_len,
@@ -790,6 +792,8 @@ static int mmc_test_nonblock_transfer(struct mmc_test_card *test,
 	struct mmc_command stop2;
 	struct mmc_data data2;
 
+	struct mmc_context_info context_info;
+
 	struct mmc_test_async_req test_areq[2];
 	struct mmc_async_req *done_areq;
 	struct mmc_async_req *cur_areq = &test_areq[0].areq;
@@ -800,14 +804,18 @@ static int mmc_test_nonblock_transfer(struct mmc_test_card *test,
 	test_areq[0].test = test;
 	test_areq[1].test = test;
 
-	mmc_test_nonblock_reset(&mrq1, &cmd1, &stop1, &data1);
-	mmc_test_nonblock_reset(&mrq2, &cmd2, &stop2, &data2);
+	memset(&context_info, 0, sizeof(struct mmc_context_info));
+
+	mmc_test_nonblock_reset(&mrq1, &cmd1, &stop1, &data1, &context_info);
+	mmc_test_nonblock_reset(&mrq2, &cmd2, &stop2, &data2, &context_info);
 
 	cur_areq->mrq = &mrq1;
 	cur_areq->err_check = mmc_test_check_result_async;
 	other_areq->mrq = &mrq2;
 	other_areq->err_check = mmc_test_check_result_async;
 
+	spin_lock_init(&context_info.lock);
+	init_waitqueue_head(&context_info.wait);
 	for (i = 0; i < count; i++) {
 		mmc_test_prepare_mrq(test, cur_areq->mrq, sg, sg_len, dev_addr,
 				     blocks, blksz, write);
@@ -819,10 +827,10 @@ static int mmc_test_nonblock_transfer(struct mmc_test_card *test,
 		if (done_areq) {
 			if (done_areq->mrq == &mrq2)
 				mmc_test_nonblock_reset(&mrq2, &cmd2,
-							&stop2, &data2);
+							&stop2, &data2, &context_info);
 			else
 				mmc_test_nonblock_reset(&mrq1, &cmd1,
-							&stop1, &data1);
+							&stop1, &data1, &context_info);
 		}
 		done_areq = cur_areq;
 		cur_areq = other_areq;
Signature · 1 line
1.7.6