Skip to contentSkip to conversation

cpuidle - fix lock contention in the idle path

PATCH In review Daniel Lezcano 3 participants 7 messages Dec 26, 2012 – Jan 6, 2013 CPU idle time management framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpuidle - fix lock contention in the idle path

The commit bf4d1b5ddb78f86078ac6ae0415802d5f0c68f92 introduces a lock in the cpuidle_get_cpu_driver function. This function is used in the idle_call function.

The problem is the contention with a large number of cpus because they try to access the idle routine at the same time.

The lock could be safely removed because of how is used the cpuidle api. The cpuidle_register_driver is called first but until the cpuidle_register_device is not called we don't enter in the cpuidle idle call function because the device is not enabled.

The cpuidle_unregister_driver function, leading the a NULL driver, is not called before the cpuidle_unregister_device.

This is how is used the cpuidle api from the different drivers.

However, a cleanup around the lock and a proper refcounting mechanism should be used to ensure the consistency in the api, like cpuidle_unregister_driver should failed if its refcounting is not 0.

These modifications will need some code reorganization and rewrite which does not fit with a fix.

The following patch is a hot fix by returning to the initial behavior by removing the lock when getting the driver.

---
 drivers/cpuidle/driver.c |    8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/cpuidle/driver.c +1 -7
index 3af841f..c2b281a 100644
@@ -235,16 +235,10 @@ EXPORT_SYMBOL_GPL(cpuidle_get_driver);
  */
 struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev)
 {
-	struct cpuidle_driver *drv;
-
 	if (!dev)
 		return NULL;
 
-	spin_lock(&cpuidle_driver_lock);
-	drv = __cpuidle_get_cpu_driver(dev->cpu);
-	spin_unlock(&cpuidle_driver_lock);
-
-	return drv;
+	return __cpuidle_get_cpu_driver(dev->cpu);
 }
 EXPORT_SYMBOL_GPL(cpuidle_get_cpu_driver);
 
Signature · 1 line
1.7.9.5
#1 lore raw

Hi Russ,

Is it possible you try this patch on your 2048 cpus ?

Thanks

-- Daniel

Quoted 57 lines · Daniel Lezcano

The commit bf4d1b5ddb78f86078ac6ae0415802d5f0c68f92 introduces a lock in the cpuidle_get_cpu_driver function. This function is used in the idle_call function.

The problem is the contention with a large number of cpus because they try to access the idle routine at the same time.

The lock could be safely removed because of how is used the cpuidle api. The cpuidle_register_driver is called first but until the cpuidle_register_device is not called we don't enter in the cpuidle idle call function because the device is not enabled.

The cpuidle_unregister_driver function, leading the a NULL driver, is not called before the cpuidle_unregister_device.

This is how is used the cpuidle api from the different drivers.

However, a cleanup around the lock and a proper refcounting mechanism should be used to ensure the consistency in the api, like cpuidle_unregister_driver should failed if its refcounting is not 0.

These modifications will need some code reorganization and rewrite which does not fit with a fix.

The following patch is a hot fix by returning to the initial behavior by removing the lock when getting the driver.

---
 drivers/cpuidle/driver.c |    8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/cpuidle/driver.c +1 -7
index 3af841f..c2b281a 100644
@@ -235,16 +235,10 @@ EXPORT_SYMBOL_GPL(cpuidle_get_driver);
  */
 struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev)
 {
-	struct cpuidle_driver *drv;
-
 	if (!dev)
 		return NULL;
 
-	spin_lock(&cpuidle_driver_lock);
-	drv = __cpuidle_get_cpu_driver(dev->cpu);
-	spin_unlock(&cpuidle_driver_lock);
-
-	return drv;
+	return __cpuidle_get_cpu_driver(dev->cpu);
 }
 EXPORT_SYMBOL_GPL(cpuidle_get_cpu_driver);
 
Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#2 lore raw
Quoted 4 lines · Daniel Lezcano

Hi Russ,

Is it possible you try this patch on your 2048 cpus ?

Yes, I will try it later today.
Thanks

Quoted 70 lines

Thanks

-- Daniel

Quoted 57 lines · Daniel Lezcano

The commit bf4d1b5ddb78f86078ac6ae0415802d5f0c68f92 introduces a lock in the cpuidle_get_cpu_driver function. This function is used in the idle_call function.

The problem is the contention with a large number of cpus because they try to access the idle routine at the same time.

The lock could be safely removed because of how is used the cpuidle api. The cpuidle_register_driver is called first but until the cpuidle_register_device is not called we don't enter in the cpuidle idle call function because the device is not enabled.

The cpuidle_unregister_driver function, leading the a NULL driver, is not called before the cpuidle_unregister_device.

This is how is used the cpuidle api from the different drivers.

However, a cleanup around the lock and a proper refcounting mechanism should be used to ensure the consistency in the api, like cpuidle_unregister_driver should failed if its refcounting is not 0.

These modifications will need some code reorganization and rewrite which does not fit with a fix.

The following patch is a hot fix by returning to the initial behavior by removing the lock when getting the driver.

---
 drivers/cpuidle/driver.c |    8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/cpuidle/driver.c +1 -7
index 3af841f..c2b281a 100644
@@ -235,16 +235,10 @@ EXPORT_SYMBOL_GPL(cpuidle_get_driver);
  */
 struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev)
 {
-	struct cpuidle_driver *drv;
-
 	if (!dev)
 		return NULL;
 
-	spin_lock(&cpuidle_driver_lock);
-	drv = __cpuidle_get_cpu_driver(dev->cpu);
-	spin_unlock(&cpuidle_driver_lock);
-
-	return drv;
+	return __cpuidle_get_cpu_driver(dev->cpu);
 }
 EXPORT_SYMBOL_GPL(cpuidle_get_cpu_driver);
 
Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
Signature · 2 lines
Russ Anderson, OS RAS/Partitioning Project Lead  
SGI - Silicon Graphics Inc          [email protected]
Acked-by on v1 1/1
#3 lore raw
In reply to Daniel Lezcano
Quoted 18 lines · Daniel Lezcano

The commit bf4d1b5ddb78f86078ac6ae0415802d5f0c68f92 introduces a lock in the cpuidle_get_cpu_driver function. This function is used in the idle_call function.

The problem is the contention with a large number of cpus because they try to access the idle routine at the same time.

The lock could be safely removed because of how is used the cpuidle api. The cpuidle_register_driver is called first but until the cpuidle_register_device is not called we don't enter in the cpuidle idle call function because the device is not enabled.

The cpuidle_unregister_driver function, leading the a NULL driver, is not called before the cpuidle_unregister_device.

This is how is used the cpuidle api from the different drivers.

Quoted 7 lines

However, a cleanup around the lock and a proper refcounting mechanism should be used to ensure the consistency in the api, like cpuidle_unregister_driver should failed if its refcounting is not 0.

These modifications will need some code reorganization and rewrite which does not fit with a fix.

I agree.

Quoted 2 lines

The following patch is a hot fix by returning to the initial behavior by removing the lock when getting the driver.

The patch fixes the problem. Verified on a system with 1024 cpus. Thanks.

Quoted 1 line
Quoted 28 lines
---
 drivers/cpuidle/driver.c |    8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/cpuidle/driver.c +1 -7
index 3af841f..c2b281a 100644
@@ -235,16 +235,10 @@ EXPORT_SYMBOL_GPL(cpuidle_get_driver);
  */
 struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev)
 {
-	struct cpuidle_driver *drv;
-
 	if (!dev)
 		return NULL;
 
-	spin_lock(&cpuidle_driver_lock);
-	drv = __cpuidle_get_cpu_driver(dev->cpu);
-	spin_unlock(&cpuidle_driver_lock);
-
-	return drv;
+	return __cpuidle_get_cpu_driver(dev->cpu);
 }
 EXPORT_SYMBOL_GPL(cpuidle_get_cpu_driver);
 
Signature · 1 line
1.7.9.5
Signature · 2 lines
Russ Anderson, OS RAS/Partitioning Project Lead  
SGI - Silicon Graphics Inc          [email protected]
#4 lore raw
Quoted 32 lines · Russ Anderson
Quoted 18 lines · Daniel Lezcano

The commit bf4d1b5ddb78f86078ac6ae0415802d5f0c68f92 introduces a lock in the cpuidle_get_cpu_driver function. This function is used in the idle_call function.

The problem is the contention with a large number of cpus because they try to access the idle routine at the same time.

The lock could be safely removed because of how is used the cpuidle api. The cpuidle_register_driver is called first but until the cpuidle_register_device is not called we don't enter in the cpuidle idle call function because the device is not enabled.

The cpuidle_unregister_driver function, leading the a NULL driver, is not called before the cpuidle_unregister_device.

This is how is used the cpuidle api from the different drivers.

Quoted 7 lines

However, a cleanup around the lock and a proper refcounting mechanism should be used to ensure the consistency in the api, like cpuidle_unregister_driver should failed if its refcounting is not 0.

These modifications will need some code reorganization and rewrite which does not fit with a fix.

I agree.

Quoted 2 lines

The following patch is a hot fix by returning to the initial behavior by removing the lock when getting the driver.

Quoted 7 lines

The patch fixes the problem. Verified on a system with 1024 cpus. Thanks.

Quoted 1 line

Hi Rafael,

could you consider this patch for merging ?

Thanks
-- Daniel

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#5 lore raw
Quoted 36 lines · Daniel Lezcano
Quoted 35 lines · Russ Anderson
Quoted 18 lines · Daniel Lezcano

The commit bf4d1b5ddb78f86078ac6ae0415802d5f0c68f92 introduces a lock in the cpuidle_get_cpu_driver function. This function is used in the idle_call function.

The problem is the contention with a large number of cpus because they try to access the idle routine at the same time.

The lock could be safely removed because of how is used the cpuidle api. The cpuidle_register_driver is called first but until the cpuidle_register_device is not called we don't enter in the cpuidle idle call function because the device is not enabled.

The cpuidle_unregister_driver function, leading the a NULL driver, is not called before the cpuidle_unregister_device.

This is how is used the cpuidle api from the different drivers.

Quoted 7 lines

However, a cleanup around the lock and a proper refcounting mechanism should be used to ensure the consistency in the api, like cpuidle_unregister_driver should failed if its refcounting is not 0.

These modifications will need some code reorganization and rewrite which does not fit with a fix.

I agree.

Quoted 2 lines

The following patch is a hot fix by returning to the initial behavior by removing the lock when getting the driver.

The patch fixes the problem. Verified on a system with 1024 cpus. Thanks.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Hi Rafael,

could you consider this patch for merging ?

Yes, I've taken it already.

I'll include it into the next pull request.

Thanks,
Rafael

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#6 lore raw

[ ... ]

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 2 lines

The following patch is a hot fix by returning to the initial behavior by removing the lock when getting the driver.

The patch fixes the problem. Verified on a system with 1024 cpus. Thanks.

Quoted 1 line
Quoted 7 lines
Quoted 3 lines

Hi Rafael,

could you consider this patch for merging ?

Yes, I've taken it already.

I'll include it into the next pull request.

Ok, thanks.

I noticed you rephrased the changelog. Thanks for that also.

-- Daniel

Signature · 14 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

  * English - detected
  * English
  * French

  * English
  * French

 <javascript:void(0);> <#>