Skip to contentSkip to conversation

mmc : Use wait_for_completion_timeout() instead of wait_for_completion in case of write.

PATCH In review Namjae Jeon 4 participants 10 messages Sep 18, 2011 – Sep 21, 2011 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc : Use wait_for_completion_timeout() instead of wait_for_completion in case of write.

host controller can not rise timeout interrupt in write not read in DMA status.
because host can just know whether card is finish to program to use busy line.
If unstable card is keep holding busy line while writing using DMA.
hang problem happen by wait_for_completion. so I think that mmc driver need some exception to avoid this problem. I suggest to use wait_for_completion_timeout instead of wait_for_completion.

---
 drivers/mmc/core/core.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
drivers/mmc/core/core.c +14 -1
index 557856b..0fe83d3 100644
@@ -253,7 +253,20 @@ static void __mmc_start_req(struct mmc_host *host, struct mmc_request *mrq)
 static void mmc_wait_for_req_done(struct mmc_host *host,
 				  struct mmc_request *mrq)
 {
-	wait_for_completion(&mrq->completion);
+	unsigned int timeout_us;
+
+	if ((mrq->data != NULL) && (mrq->data->flags & MMC_DATA_WRITE)) {
+		timeout_us = mrq->data->timeout_ns / 1000;
+		if (mmc_host_clk_rate(host))
+			timeout_us += mrq->data->timeout_clks * 1000 /
+				(mmc_host_clk_rate(host) / 1000);
+		if (!timeout_us)
+			timeout_us = 1000000;
+		if (!wait_for_completion_timeout(&mrq->completion,
+				usecs_to_jiffies(timeout_us)))
+			mrq->cmd->error = -ETIMEDOUT;
+	} else
+		wait_for_completion(&mrq->completion);
 }
 
 /**
Signature · 1 line
1.7.4.4
#1 lore raw
Quoted 4 lines · Namjae Jeon

host controller can not rise timeout interrupt in write not read in DMA status. because host can just know whether card is finish to program to use busy line. If unstable card is keep holding busy line while writing using DMA. hang problem happen by wait_for_completion. so I think that mmc driver need some exception to avoid this problem.
I suggest to use wait_for_completion_timeout instead of wait_for_completion.

I see what you are trying to solve, but you can never calculate the timeout for this type of operation in such a way. Your timeout involves the entire data write operation, how can you ever know how long this will take?

I think a much better approach is to make you host driver not using "busy signaling" (if that is possible), thus when the DMA job is done call mmc_request_done to finalize the data transfer. The mmc framework will then send a CMD13 (SEND_STATUS) to make sure the data is written before issuing the next request.

BR
Ulf Hansson

#2 lore raw
Quoted 8 lines · Ulf Hansson
Quoted 5 lines · Namjae Jeon

host controller can not rise timeout interrupt in write not read in DMA status. because host can just know whether card is finish to program to use busy line. If unstable card is keep holding busy line while writing using DMA. hang problem happen by wait_for_completion. so I think that mmc driver need some exception to avoid this problem.
I suggest to use wait_for_completion_timeout instead of wait_for_completion.

Quoted 6 lines

I see what you are trying to solve, but you can never calculate the timeout for this type of operation in such a way. Your timeout involves the entire data write operation, how can you ever know how long this will take?

I think a much better approach is to make you host driver not using "busy signaling" (if that is possible), thus when the DMA job is done call mmc_request_done to finalize the data transfer. The mmc framework will then send a CMD13 (SEND_STATUS) to make sure the data is written before issuing the next request.

BR
Ulf Hansson

To add to what Hansson mentioned, the timeout mechanism should not be implemented at the MMC core layer. If the core layer simply times out like this, the host controller driver still remains in the same state which is not right. If such a timeout mechanism is needed, it is best to implement in the host controller driver layer and inform the core layer by calling mmc_request_done() when the time out happens. This will also give a chance to the host controller driver to do any required clean up at the controller layer so that it is in a known good state to handle further requests from the core layer.

Regards,
Murali Krishna

#3 lore raw

2011/9/20 Murali Krishna Palnati <[email protected]>:

Quoted 27 lines · Ulf Hansson
Quoted 8 lines
Quoted 5 lines · Namjae Jeon

host controller can not rise timeout interrupt in write not read in DMA status. because host can just know whether card is finish to program to use busy line. If unstable card is keep holding busy line while writing using DMA. hang problem happen by wait_for_completion. so I think that mmc driver need some exception to avoid this problem.
I suggest to use wait_for_completion_timeout instead of wait_for_completion.

Quoted 6 lines

I see what you are trying to solve, but you can never calculate the timeout for this type of operation in such a way. Your timeout involves the entire data write operation, how can you ever know how long this will take?

I think a much better approach is to make you host driver not using "busy signaling" (if that is possible), thus when the DMA job is done call mmc_request_done to finalize the data transfer. The mmc framework will then send a CMD13 (SEND_STATUS) to make sure the data is written before issuing the next request.

BR
Ulf Hansson

To add to what Hansson mentioned, the timeout mechanism should not be implemented at the MMC core layer. If the core layer simply times out like this, the host controller driver still remains in the same state which is not right. If such a timeout mechanism is needed, it is best to implement in the host controller driver layer and inform the core layer by calling mmc_request_done() when the time out happens. This will also give a chance to the host controller driver to do any required clean up at the controller layer so that it is in a known good state to handle further requests from the core layer.

Quoted 3 lines

Regards,
Murali Krishna

yes, I knew. But if card keep holding busy line(data 0) in the middle of DMA operation(multi blocks write), host driver layer can not know card status in this situation. addtionally, After timeout happen, host driver should send stop cmd to card for putting out busyline. and we should reset/cleanup host contoller to intialize DMA controller. and it should be impremented in host driver. so after returing write fail, host can access card again.

Write_timeout is calculated by the R2W_FACTOR field * mult in the CSD. but it is timeout about only one block. so I think that timeout value is multiplied with number of blocks.
I will modify v2 patch by adding this code.

timeout_us = (mrq->data->timeout_ns * mrq->data->blocks) / 1000;

I think that this exception should be like this.
If write 128KB request -> timeout is calculated to 6.4 sec if it spend 250ms per block -> timeout error happen -> mmc core send stop cmd -> mmc core try to call host reset/cleanup -> return write cmd error.

How do you think ?

#4 lore raw
Quoted 3 lines · NamJae Jeon

yes, I knew. But if card keep holding busy line(data 0) in the middle of DMA operation(multi blocks write),  host driver layer can not know card status in this situation.

The host driver shall start a software timer and indpendently needs to watch out for the expiry of the timeout. If the host doesn't hear back from the
controller/DMA engine even after waiting for the specified timeout, then the timer handler that gets invoked can then do the necessary cleanup and
inform the MMC core layer that the request failed. Does this sound feasible?

#5 lore raw

2011/9/20 Murali Krishna Palnati <[email protected]>:

Quoted 5 lines · NamJae Jeon
Quoted 3 lines

yes, I knew. But if card keep holding busy line(data 0) in the middle of DMA operation(multi blocks write),  host driver layer can not know card status in this situation.

Quoted 8 lines

The host driver shall start a software timer and indpendently needs to watch out for the expiry of the timeout. If the host doesn't hear back from the
controller/DMA engine even after waiting for the specified timeout, then the timer handler that gets invoked can then do the necessary cleanup and
inform the MMC core layer that the request failed. Does this sound feasible?

It may be no good choice that sw timer is on host driver. also I don't know what is different.
It is the same as the ata driver's dma_map_sg.
dma_map_sg is repectively called in mmc host driver. but it is being processed in ata core of ata driver.
because it is common routine, ata core have called it instead of host driver. if it is processed in mmc core, there is no need to modify several hosts.(except dma controller reset)

#6 lore raw
Quoted 2 lines · NamJae Jeon

It may be no good choice that sw timer is on host driver. also I don't know what is different.

It helps to have this functionality implemented at host controller layer so that the host layer is informed about this. If we just end the request from the MMC core layer, host controller driver doesnt even kow about that and it remains in the same state processing the request (that already got timed out at core layer). It is good to have the host layer trigger this timeout, do necessary clean up and then duly end the request by informing the core layer by calling mmc_request_done().

Let me put the question in this way. If the core layer times out (because of wait_for_completion_timeout) then in the patch that you have submitted, i dont see how the host layer knows about it. Apologize, if i sound like a broken record saying the same thing again and again.

#7 lore raw

2011/9/21 Murali Krishna Palnati <[email protected]>:

Quoted 13 lines · NamJae Jeon
Quoted 2 lines

It may be no good choice that sw timer is on host driver. also I don't know what is different.

It helps to have this functionality implemented at host controller layer so that the host layer is informed about this. If we just end the request from the MMC core layer, host controller driver doesnt even kow about that and it remains in the same state processing the request (that already got timed out at core layer). It is good to have the host layer trigger this timeout, do necessary clean up and then duly end the request by informing the core layer by calling mmc_request_done().

Quoted 6 lines

Let me put the question in this way. If the core layer times out (because of wait_for_completion_timeout) then in the patch that you have submitted, i dont see how the host layer knows about it. Apologize, if i sound like a broken record saying the same thing again and again.

I understand what you want. So I will add emergency_cleanup for host driver like this.
struct mmc_host_ops {
................
.................
void (*emergency_cleanup)(struct mmc_host *host);

}

When timeout error happen, mmc core will call this function as soon as sending stop cmd.
And when timeout error happen by wait_for_completion_timeout, calling mmc_request_done is not needed.

Thanks.

#8 lore raw

2011/9/21 NamJae Jeon <[email protected]>:

Quoted 28 lines

2011/9/21 Murali Krishna Palnati <[email protected]>:

Quoted 13 lines · NamJae Jeon
Quoted 2 lines

It may be no good choice that sw timer is on host driver. also I don't know what is different.

It helps to have this functionality implemented at host controller layer so that the host layer is informed about this. If we just end the request from the MMC core layer, host controller driver doesnt even kow about that and it remains in the same state processing the request (that already got timed out at core layer). It is good to have the host layer trigger this timeout, do necessary clean up and then duly end the request by informing the core layer by calling mmc_request_done().

Quoted 6 lines

Let me put the question in this way. If the core layer times out (because of wait_for_completion_timeout) then in the patch that you have submitted, i dont see how the host layer knows about it. Apologize, if i sound like a broken record saying the same thing again and again.

I understand what you want. So I will add emergency_cleanup for host driver like this.
struct mmc_host_ops {
................
.................
void (*emergency_cleanup)(struct mmc_host *host);

Quoted 9 lines

}

When timeout error happen, mmc core will call this function as soon as sending stop cmd.
And when timeout error happen by wait_for_completion_timeout, calling mmc_request_done is not needed.

Thanks.

I'll follow the opinion of chris.

Thanks.

#9 lore raw
In reply to Namjae Jeon
Quoted 2 lines · Namjae Jeon

+                       timeout_us += mrq->data->timeout_clks * 1000 /
+                               (mmc_host_clk_rate(host) / 1000);

The math teacher says this is equivalent to:

timeout_us += (mrq->data->timeout_clks / mmc_host_clk_rate) * 1000000 ;

Yours,
Linus Walleij