mmc: core: Use delayed work in clock gating framework
Subsystems (3)
PATCH v3 1/1 mmc: core: Use delayed work in clock gating framework
Current clock gating framework disables the MCI clock as soon as the request is completed and enables it when a request arrives. This aggressive clock gating framework, when enabled, cause following issues:
When there are back-to-back requests from the Queue layer, we unnecessarily end up disabling and enabling the clocks between these requests since 8MCLK clock cycles is a very short duration compared to the time delay between back to back requests reaching the MMC layer. This overhead can effect the overall performance depending on how long the clock enable and disable calls take which is platform dependent. For example on some platforms we can have clock control not on the local processor, but on a different subsystem and the time taken to perform the clock enable/disable can add significant overhead.
Also if the host controller driver decides to disable the host clock too when mmc_set_ios function is called with ios.clock=0, it adds additional delay and it is highly possible that the next request had already arrived and unnecessarily blocked in enabling the clocks. This is seen frequently when the processor is executing at high speeds and in multi-core platforms thus reduces the overall throughput compared to if clock gating is disabled.
Fix this by delaying turning off the clocks by posting request on delayed workqueue. Also cancel the unscheduled pending work, if any, when there is access to card.
sysfs entry is provided to tune the delay as needed, default value set to 200ms.
---
Changes in v3:
- Documentation for sysfs entry is added.
Changes in v2:
- support for tuning delay via sysfs entry.
--- Documentation/mmc/mmc-dev-attrs.txt | 10 ++++++ drivers/mmc/core/host.c | 57 ++++++++++++++++++++++++++++++++-- include/linux/mmc/host.h | 4 ++- 3 files changed, 66 insertions(+), 5 deletions(-)
Documentation/mmc/mmc-dev-attrs.txt +10 -0
@@ -64,3 +64,13 @@ Note on Erase Size and Preferred Erase Size: size specified by the card. "preferred_erase_size" is in bytes. + +SD/MMC/SDIO Clock Gating Attribute +================================== + +Read and write access is provided to following attribute. +This attribute appears only if CONFIG_MMC_CLKGATE is enabled. + + clkgate_delay Tune the clock gating delay with desired value in milli seconds. + +echo <desired delay> > /sys/class/mmc_host/mmcX/clkgate_delay
drivers/mmc/core/host.c +53 -4
112 lines not on this page · raw message
include/linux/mmc/host.h +3 -1
@@ -253,10 +253,12 @@ struct mmc_host {int clk_requests;/* internal reference counter */ unsigned int clk_delay;/* number of MCI clk hold cycles */ bool clk_gated;/* clock gated */ -struct work_struct clk_gate_work;/* delayed clock gate */ +struct delayed_work clk_gate_work;/* delayed clock gate */ unsigned int clk_old;/* old clock value cache */ spinlock_t clk_lock;/* lock for clk fields */ struct mutex clk_gate_mutex;/* mutex for clock gating */ +struct device_attribute clkgate_delay_attr; +unsigned long clkgate_delay;#endif /* host specific block data */
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Hi Sujit,
Quoted 26 lines · Sujit Reddy Thumma
Current clock gating framework disables the MCI clock as soon as the request is completed and enables it when a request arrives. This aggressive clock gating framework, when enabled, cause following issues:
When there are back-to-back requests from the Queue layer, we unnecessarily end up disabling and enabling the clocks between these requests since 8MCLK clock cycles is a very short duration compared to the time delay between back to back requests reaching the MMC layer. This overhead can effect the overall performance depending on how long the clock enable and disable calls take which is platform dependent. For example on some platforms we can have clock control not on the local processor, but on a different subsystem and the time taken to perform the clock enable/disable can add significant overhead.
Also if the host controller driver decides to disable the host clock too when
mmc_set_iosfunction is called with ios.clock=0, it adds additional delay and it is highly possible that the next request had already arrived and unnecessarily blocked in enabling the clocks. This is seen frequently when the processor is executing at high speeds and in multi-core platforms thus reduces the overall throughput compared to if clock gating is disabled.Fix this by delaying turning off the clocks by posting request on delayed workqueue. Also cancel the unscheduled pending work, if any, when there is access to card.
Quoted 5 lines
sysfs entry is provided to tune the delay as needed, default value set to 200ms.
Signed-off-by Sujit Reddy Thumma <[email protected]>Acked-by Linus Walleij <[email protected]>
error: patch failed: drivers/mmc/core/host.c:53
error: drivers/mmc/core/host.c: patch does not apply
error: patch failed: include/linux/mmc/host.h:253
error: include/linux/mmc/host.h: patch does not apply
Please could you resend against current mmc-next?
Thanks,
- Chris.
Signature · 2 lines
Chris Ball <[email protected]> <http://printf.net/> One Laptop Per Child
Hi Chris,
Quoted 35 lines · Chris Ball
Hi Sujit,
Quoted 26 lines · Sujit Reddy Thumma
Current clock gating framework disables the MCI clock as soon as the request is completed and enables it when a request arrives. This aggressive clock gating framework, when enabled, cause following issues:
When there are back-to-back requests from the Queue layer, we unnecessarily end up disabling and enabling the clocks between these requests since 8MCLK clock cycles is a very short duration compared to the time delay between back to back requests reaching the MMC layer. This overhead can effect the overall performance depending on how long the clock enable and disable calls take which is platform dependent. For example on some platforms we can have clock control not on the local processor, but on a different subsystem and the time taken to perform the clock enable/disable can add significant overhead.
Also if the host controller driver decides to disable the host clock too when
mmc_set_iosfunction is called with ios.clock=0, it adds additional delay and it is highly possible that the next request had already arrived and unnecessarily blocked in enabling the clocks. This is seen frequently when the processor is executing at high speeds and in multi-core platforms thus reduces the overall throughput compared to if clock gating is disabled.Fix this by delaying turning off the clocks by posting request on delayed workqueue. Also cancel the unscheduled pending work, if any, when there is access to card.
Quoted 5 lines
sysfs entry is provided to tune the delay as needed, default value set to 200ms.
Signed-off-by Sujit Reddy Thumma<[email protected]>Acked-by Linus Walleij<[email protected]>
Quoted 6 lines
error: patch failed:
drivers/mmc/core/host.c:53
error:drivers/mmc/core/host.c: patch does not apply
error: patch failed:include/linux/mmc/host.h:253
error:include/linux/mmc/host.h: patch does not applyPlease could you resend against current mmc-next?
I see that the patch is already applied on mmc-next, hence the conflicts.
Can we rebase the tree and apply V3?
Quoted 4 lines
Thanks,
- Chris.
Signature · 2 lines
Thanks, Sujit
Hi,
Quoted 5 lines · Sujit Reddy Thumma
I see that the patch is already applied on mmc-next, hence the conflicts.
Can we rebase the tree and apply V3?
Done. Thanks!
- Chris.
Signature · 2 lines
Chris Ball <[email protected]> <http://printf.net/> One Laptop Per Child
Quoted 6 lines · Sujit Reddy Thumma
Documentation/mmc/mmc-dev-attrs.txt +0
-0@@ -64,3 +64,13 @@ Note on Erase Size and Preferred Erase Size: size specified by the card.
Documentation/mmc/mmc-dev-attrs.txt Note on Erase Size and Preferred Erase Size: · line 74
Quoted 10 lines
Documentation/mmc/mmc-dev-attrs.txt +8
-0"preferred_erase_size" is in bytes. + +SD/MMC/SDIO Clock Gating Attribute +================================== + +Read and write access is provided to following attribute. +This attribute appears only if CONFIG_MMC_CLKGATE is enabled. + + clkgate_delay Tune the clock gating delay with desired value in milli seconds.
milliseconds is one word.
drivers/mmc/core/host.c static DEFINE_IDR(mmc_host_idr); · line 60
Quoted 13 lines
drivers/mmc/core/host.c +5
-0@@ -53,6 +53,31 @@ static DEFINE_IDR(mmc_host_idr);static DEFINE_SPINLOCK (mmc_host_lock);#ifdef CONFIG_MMC_CLKGATE +static ssize_t clkgate_delay_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct mmc_host *host =cls_dev_to_mmc_host (dev); + return snprintf(buf, PAGE_SIZE, "%lu millisecs\n",
Perhaps this should just be %lu to simplify userspace parsing.
Quoted 5 lines
drivers/mmc/core/host.c +5
-0+static ssize_t clkgate_delay_store (struct device *dev, +struct device_attribute *attr,const char *buf,size_t count) +{ +struct mmc_host *host =cls_dev_to_mmc_host (dev); +unsigned long flags, value;
drivers/mmc/core/host.c static DEFINE_IDR(mmc_host_idr); · line 78
Quoted 10 lines
drivers/mmc/core/host.c +10
-0+ +if (kstrtoul (buf,0 , &value)) +return -EINVAL ; + +spin_lock_irqsave (&host->clk_lock, flags); + host->clkgate_delay = value; +spin_unlock_irqrestore (&host->clk_lock, flags); + +pr_info ("%s: clock gate delay set to %lu ms\n" , +mmc_hostname (host), value);
Is this pr_info() necessary?
Quoted 5 lines
drivers/mmc/core/host.c +1
-0@@ -236,6 +269,17 @@ static inline void mmc_host_clk_exit(struct mmc_host *host)WARN_ON (host->clk_requests >1 ); } +static inline void mmc_host_clk_sysfs_init (struct mmc_host *host)
drivers/mmc/core/host.c static inline void mmc_host_clk_exit(struct mmc_host *host) · line 282
Quoted 10 lines
drivers/mmc/core/host.c +10
-0+{ + host->clkgate_delay_attr.show = clkgate_delay_show; + host->clkgate_delay_attr.store = clkgate_delay_store; +sysfs_attr_init (&host->clkgate_delay_attr.attr); + host->clkgate_delay_attr.attr.name ="clkgate_delay" ; + host->clkgate_delay_attr.attr.mode =S_IRUGO |S_IWUSR ; +if (device_create_file (&host->class_dev, &host->clkgate_delay_attr)) +pr_err ("%s: Failed to create clkgate_delay sysfs entry\n" , +mmc_hostname (host)); +}
Would it be simpler to assign dev_attrs in the mmc_host_class instead?
Quoted 5 lines
include/linux/mmc/host.h +0
-0
include/linux/mmc/host.h struct mmc_host { · line 260
Quoted 9 lines
include/linux/mmc/host.h +2
-1@@ -253,10 +253,12 @@ struct mmc_host {int clk_requests;/* internal reference counter */ unsigned int clk_delay;/* number of MCI clk hold cycles */ bool clk_gated;/* clock gated */ -struct work_struct clk_gate_work;/* delayed clock gate */ +struct delayed_work clk_gate_work;/* delayed clock gate */ unsigned int clk_old;/* old clock value cache */ spinlock_t clk_lock;/* lock for clk fields */ struct mutex clk_gate_mutex;/* mutex for clock gating */ +struct device_attribute clkgate_delay_attr;
If you used the class device attributes then this would probably go away.
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
[PATCH-next] mmc: core: Fixup delayed work clock gating patch
c31b50e (mmc: core: Use delayed work in clock gating framework, 2011-11-14) missed a few things during review:
o A useless pr_info()
o milliseconds was written as two words
o The sysfs file had units in its output
Fix all three problems.
---
Feel free to squash if desired.
Documentation/mmc/mmc-dev-attrs.txt | 2 +- drivers/mmc/core/host.c | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-)
Documentation/mmc/mmc-dev-attrs.txt +1 -1
@@ -71,6 +71,6 @@ SD/MMC/SDIO Clock Gating Attribute Read and write access is provided to following attribute. This attribute appears only if CONFIG_MMC_CLKGATE is enabled. - clkgate_delay Tune the clock gating delay with desired value in milli seconds. + clkgate_delay Tune the clock gating delay with desired value in milliseconds. echo <desired delay> > /sys/class/mmc_host/mmcX/clkgate_delay
drivers/mmc/core/host.c +1 -5
@@ -58,8 +58,7 @@ static ssize_t clkgate_delay_show(struct device *dev, struct device_attribute *attr, char *buf) { struct mmc_host *host = cls_dev_to_mmc_host(dev); -return snprintf (buf,PAGE_SIZE ,"%lu millisecs\n" , - host->clkgate_delay); +return snprintf (buf,PAGE_SIZE ,"%lu\n" , host->clkgate_delay); } static ssize_t clkgate_delay_store(struct device *dev,
@@ -74,9 +73,6 @@ static ssize_t clkgate_delay_store(struct device *dev,spin_lock_irqsave (&host->clk_lock, flags); host->clkgate_delay = value;spin_unlock_irqrestore (&host->clk_lock, flags); - -pr_info ("%s: clock gate delay set to %lu ms\n" , -mmc_hostname (host), value);return count; }
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH-next] mmc: core: Fixup delayed work clock gating patch
Quoted 13 lines · Stephen Boyd
c31b50e (mmc: core: Use delayed work in clock gating framework, 2011-11-14) missed a few things during review:
o A useless
pr_info()o milliseconds was written as two words
o The sysfs file had units in its output
Fix all three problems.
Cc Sujit Reddy Thumma<[email protected]>Signed-off-by Stephen Boyd<[email protected]>
Quoted 7 lines
---
Feel free to squash if desired.
Documentation/mmc/mmc-dev-attrs.txt | 2 +- drivers/mmc/core/host.c | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-)
Thanks Stephen.
Quoted 37 lines
Documentation/mmc/mmc-dev-attrs.txt +1
-1@@ -71,6 +71,6 @@ SD/MMC/SDIO Clock Gating Attribute Read and write access is provided to following attribute. This attribute appears only if CONFIG_MMC_CLKGATE is enabled. - clkgate_delay Tune the clock gating delay with desired value in milli seconds. + clkgate_delay Tune the clock gating delay with desired value in milliseconds. echo<desired delay> > /sys/class/mmc_host/mmcX/clkgate_delaydrivers/mmc/core/host.c +1
-5@@ -58,8 +58,7 @@ static ssize_t clkgate_delay_show(struct device *dev, struct device_attribute *attr, char *buf) { struct mmc_host *host = cls_dev_to_mmc_host(dev); -return snprintf (buf,PAGE_SIZE ,"%lu millisecs\n" , - host->clkgate_delay); +return snprintf (buf,PAGE_SIZE ,"%lu\n" , host->clkgate_delay); } static ssize_t clkgate_delay_store(struct device *dev,@@ -74,9 +73,6 @@ static ssize_t clkgate_delay_store(struct device *dev,spin_lock_irqsave (&host->clk_lock, flags); host->clkgate_delay = value;spin_unlock_irqrestore (&host->clk_lock, flags); - -pr_info ("%s: clock gate delay set to %lu ms\n" , -mmc_hostname (host), value);return count; }
Re: [PATCH-next] mmc: core: Fixup delayed work clock gating patch
In reply to Stephen BoydHi Stephen,
Quoted 48 lines · Stephen Boyd
c31b50e (mmc: core: Use delayed work in clock gating framework, 2011-11-14) missed a few things during review:
o A useless
pr_info()o milliseconds was written as two words
o The sysfs file had units in its output
Fix all three problems.
Cc Sujit Reddy Thumma <[email protected]>Signed-off-by Stephen Boyd <[email protected]>---
Feel free to squash if desired.
Documentation/mmc/mmc-dev-attrs.txt | 2 +- drivers/mmc/core/host.c | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-)Documentation/mmc/mmc-dev-attrs.txt +1
-1@@ -71,6 +71,6 @@ SD/MMC/SDIO Clock Gating Attribute Read and write access is provided to following attribute. This attribute appears only if CONFIG_MMC_CLKGATE is enabled. - clkgate_delay Tune the clock gating delay with desired value in milli seconds. + clkgate_delay Tune the clock gating delay with desired value in milliseconds. echo <desired delay> > /sys/class/mmc_host/mmcX/clkgate_delaydrivers/mmc/core/host.c +1
-2@@ -58,8 +58,7 @@ static ssize_t clkgate_delay_show(struct device *dev, struct device_attribute *attr, char *buf) { struct mmc_host *host = cls_dev_to_mmc_host(dev); -return snprintf (buf,PAGE_SIZE ,"%lu millisecs\n" , - host->clkgate_delay); +return snprintf (buf,PAGE_SIZE ,"%lu\n" , host->clkgate_delay); } static ssize_t clkgate_delay_store(struct device *dev,
drivers/mmc/core/host.c static ssize_t clkgate_delay_store(struct device *dev, · line 77
Quoted 8 lines
drivers/mmc/core/host.c +0
-3@@ -74,9 +73,6 @@ static ssize_t clkgate_delay_store(struct device *dev,spin_lock_irqsave (&host->clk_lock, flags); host->clkgate_delay = value;spin_unlock_irqrestore (&host->clk_lock, flags); - -pr_info ("%s: clock gate delay set to %lu ms\n" , -mmc_hostname (host), value);return count; }
Thanks, pushed to mmc-next for 3.3.
- Chris.
Signature · 2 lines
Chris Ball <[email protected]> <http://printf.net/> One Laptop Per Child