mmc: core: Add support for idle time BKOPS
Subsystems (3)
PATCH v5 1/3 mmc: core: Add support for idle time BKOPS
Devices have various maintenance operations need to perform internally. In order to reduce latencies during time critical operations like read and write, it is better to execute maintenance operations in other times - when the host is not being serviced. Such operations are called Background operations (BKOPS).
The device notifies the status of the BKOPS need by updating BKOPS_STATUS (EXT_CSD byte [246]).
According to the standard a host that supports BKOPS shall check the status periodically and start background operations as needed, so that the device has enough time for its maintenance operations.
This patch adds support for this periodic check of the BKOPS status. Since foreground operations are of higher priority than background operations the host will check the need for BKOPS when it is idle, and in case of an incoming request the BKOPS operation will be interrupted.
When the mmcqd thread is idle, a delayed work is created to check the need for BKOPS. The time to start the delayed work can be set by the host controller. If this time is not set, a default time is used. If the card raised an exception with need for urgent BKOPS (level 2/3) a flag will be set to indicate MMC to start the BKOPS activity when it becomes idle.
Since running the BKOPS too often can impact the eMMC endurance, the card need for BKOPS is not checked every time MMC is idle (despite of cases of exception raised). In order to estimate when is the best time to check for BKOPS need the host will take into account the card capacity and percentages of changed sectors in the card. A future enhancement can be to check the card need for BKOPS only in case of random activity.
--- Documentation/mmc/mmc-dev-attrs.txt | 9 ++ drivers/mmc/card/block.c | 96 +++++++++++++++++++++- drivers/mmc/card/queue.c | 2 + drivers/mmc/core/core.c | 155 +++++++++++++++++++++++++++-------- drivers/mmc/core/mmc.c | 17 ++++ include/linux/mmc/card.h | 47 ++++++++++- include/linux/mmc/core.h | 2 + 7 files changed, 291 insertions(+), 37 deletions(-)
Documentation/mmc/mmc-dev-attrs.txt +9 -0
@@ -8,6 +8,15 @@ The following attributes are read/write. force_ro Enforce read-only access even if write protect switch is off. + bkops_check_threshold This attribute is used to determine whether + the status bit that indicates the need for BKOPS should be checked. + The value should be given in percentages of the card size. + This value is used to calculate the minimum number of sectors that + needs to be changed in the device (written or discarded) in order to + require the status-bit of BKOPS to be checked. + The value can modified via sysfs by writing the required value to: + /sys/block/<block_dev_name>/bkops_check_threshold + SD and MMC Device Attributes ============================
drivers/mmc/card/block.c +94 -2
156 lines not on this page · raw message
drivers/mmc/card/queue.c +2 -0
@@ -51,6 +51,7 @@ static int mmc_queue_thread(void *d) {struct mmc_queue *mq = d;struct request_queue *q = mq->queue; +struct mmc_card *card = mq->card; current->flags |=PF_MEMALLOC ;
@@ -83,6 +84,7 @@ static int mmc_queue_thread(void *d)set_current_state (TASK_RUNNING );break ; } +mmc_start_delayed_bkops (card);up (&mq->thread_sem);schedule ();down (&mq->thread_sem);
drivers/mmc/core/core.c +121 -34
221 lines not on this page · raw message
drivers/mmc/core/mmc.c +17 -0
@@ -1546,6 +1546,23 @@ int mmc_attach_mmc(struct mmc_host *host)if (err) goto err; +if (host->card->ext_csd.bkops_en) { +INIT_DELAYED_WORK (&host->card->bkops_info.dw, + mmc_start_idle_time_bkops); + +/* +* The host controller can set the time to start the BKOPS in +* order to prevent a race condition before starting BKOPS +* and going into suspend. +* If the host controller didn't set this time, +* a default value is used. +*/ + host->card->bkops_info.delay_ms =MMC_IDLE_BKOPS_TIME_MS ; +if (host->card->bkops_info.host_delay_ms) + host->card->bkops_info.delay_ms = + host->card->bkops_info.host_delay_ms; + } +mmc_release_host (host); err =mmc_add_card (host->card);mmc_claim_host (host);
include/linux/mmc/card.h +46 -1
77 lines not on this page · raw message
include/linux/mmc/core.h +2 -0
@@ -145,6 +145,8 @@ extern int mmc_app_cmd(struct mmc_host *, struct mmc_card *);extern int mmc_wait_for_app_cmd (struct mmc_host *,struct mmc_card *,struct mmc_command *,int );extern void mmc_start_bkops (struct mmc_card *card,bool from_exception); +extern void mmc_start_delayed_bkops (struct mmc_card *card); +extern void mmc_start_idle_time_bkops (struct work_struct *work);extern int __mmc_switch (struct mmc_card *,u8 ,u8 ,u8 ,unsigned int ,bool );extern int mmc_switch (struct mmc_card *,u8 ,u8 ,u8 ,unsigned int );
Signature · 4 lines
1.7.3.3 -- QUALCOMM ISRAEL, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation