public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hwspinlock: qcom: Lock #7 is special lock, uses dynamic proc_id
@ 2015-05-01 17:06 Lina Iyer
  2015-05-01 17:27 ` Jeffrey Hugo
  0 siblings, 1 reply; 3+ messages in thread
From: Lina Iyer @ 2015-05-01 17:06 UTC (permalink / raw)
  To: ohad, s-anna, Bjorn.Andersson, agross
  Cc: linux-arm-msm, linux-kernel, galak, jhugo, Lina Iyer,
	Bjorn Andersson

Hwspinlocks are widely used between processors in an SoC, and also
between elevation levels within in the same processor.  QCOM SoC's use
hwspinlock to serialize entry into a low power mode when the context
switches from Linux to secure monitor.

Lock #7 has been assigned for this purpose. In order to differentiate
between one cpu core holding a lock while another cpu is contending for
the same lock, the proc id written into the lock is (128 + cpu id). This
makes it unique value among the cpu cores and therefore when a core
locks the hwspinlock, other cores would wait for the lock to be released
since they would have a different proc id.  This value is specific for
the lock #7 only.

Cc: Jeffrey Hugo <jhugo@codeaurora.org>
Cc: Bjorn Andersson <bjorn.andersson@sonymobile.com>
Cc: Andy Gross <agross@codeaurora.org>
Signed-off-by: Lina Iyer <lina.iyer@linaro.org>
---
 drivers/hwspinlock/qcom_hwspinlock.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/hwspinlock/qcom_hwspinlock.c b/drivers/hwspinlock/qcom_hwspinlock.c
index 93b62e0..043c62c 100644
--- a/drivers/hwspinlock/qcom_hwspinlock.c
+++ b/drivers/hwspinlock/qcom_hwspinlock.c
@@ -25,16 +25,26 @@
 
 #include "hwspinlock_internal.h"
 
-#define QCOM_MUTEX_APPS_PROC_ID	1
-#define QCOM_MUTEX_NUM_LOCKS	32
+#define QCOM_MUTEX_APPS_PROC_ID		1
+#define QCOM_MUTEX_CPUIDLE_OFFSET	128
+#define QCOM_CPUIDLE_LOCK		7
+#define QCOM_MUTEX_NUM_LOCKS		32
+
+static inline u32 __qcom_get_proc_id(struct hwspinlock *lock)
+{
+	return hwspin_lock_get_id(lock) == QCOM_CPUIDLE_LOCK ?
+			(QCOM_MUTEX_CPUIDLE_OFFSET + smp_processor_id()) :
+			QCOM_MUTEX_APPS_PROC_ID;
+}
 
 static int qcom_hwspinlock_trylock(struct hwspinlock *lock)
 {
 	struct regmap_field *field = lock->priv;
 	u32 lock_owner;
 	int ret;
+	u32 proc_id = __qcom_get_proc_id(lock);
 
-	ret = regmap_field_write(field, QCOM_MUTEX_APPS_PROC_ID);
+	ret = regmap_field_write(field, proc_id);
 	if (ret)
 		return ret;
 
@@ -42,7 +52,7 @@ static int qcom_hwspinlock_trylock(struct hwspinlock *lock)
 	if (ret)
 		return ret;
 
-	return lock_owner == QCOM_MUTEX_APPS_PROC_ID;
+	return lock_owner == proc_id;
 }
 
 static void qcom_hwspinlock_unlock(struct hwspinlock *lock)
@@ -57,7 +67,7 @@ static void qcom_hwspinlock_unlock(struct hwspinlock *lock)
 		return;
 	}
 
-	if (lock_owner != QCOM_MUTEX_APPS_PROC_ID) {
+	if (lock_owner != __qcom_get_proc_id(lock)) {
 		pr_err("%s: spinlock not owned by us (actual owner is %d)\n",
 				__func__, lock_owner);
 	}
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] hwspinlock: qcom: Lock #7 is special lock, uses dynamic proc_id
  2015-05-01 17:06 [PATCH] hwspinlock: qcom: Lock #7 is special lock, uses dynamic proc_id Lina Iyer
@ 2015-05-01 17:27 ` Jeffrey Hugo
  2015-05-01 17:31   ` Lina Iyer
  0 siblings, 1 reply; 3+ messages in thread
From: Jeffrey Hugo @ 2015-05-01 17:27 UTC (permalink / raw)
  To: Lina Iyer, ohad, s-anna, Bjorn.Andersson, agross
  Cc: linux-arm-msm, linux-kernel, galak

On 5/1/2015 11:06 AM, Lina Iyer wrote:

> diff --git a/drivers/hwspinlock/qcom_hwspinlock.c b/drivers/hwspinlock/qcom_hwspinlock.c
> index 93b62e0..043c62c 100644
> --- a/drivers/hwspinlock/qcom_hwspinlock.c
> +++ b/drivers/hwspinlock/qcom_hwspinlock.c
> @@ -25,16 +25,26 @@
>
>   #include "hwspinlock_internal.h"
>
> -#define QCOM_MUTEX_APPS_PROC_ID	1
> -#define QCOM_MUTEX_NUM_LOCKS	32
> +#define QCOM_MUTEX_APPS_PROC_ID		1
> +#define QCOM_MUTEX_CPUIDLE_OFFSET	128
> +#define QCOM_CPUIDLE_LOCK		7
> +#define QCOM_MUTEX_NUM_LOCKS		32
> +

This part of the diff doesn't look right.  Why is it showing that 
QCOM_MUTEX_APPS_PROC_ID and QCOM_MUTEX_NUM_LOCKS are deleted and added 
lines?  Shouldn't they be unchanged by this patch?

-- 
Jeffrey Hugo
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora 
Forum, a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] hwspinlock: qcom: Lock #7 is special lock, uses dynamic proc_id
  2015-05-01 17:27 ` Jeffrey Hugo
@ 2015-05-01 17:31   ` Lina Iyer
  0 siblings, 0 replies; 3+ messages in thread
From: Lina Iyer @ 2015-05-01 17:31 UTC (permalink / raw)
  To: Jeffrey Hugo
  Cc: ohad, s-anna, Bjorn.Andersson, agross, linux-arm-msm,
	linux-kernel, galak

On Fri, May 01 2015 at 11:27 -0600, Jeffrey Hugo wrote:
>On 5/1/2015 11:06 AM, Lina Iyer wrote:
>
>>diff --git a/drivers/hwspinlock/qcom_hwspinlock.c b/drivers/hwspinlock/qcom_hwspinlock.c
>>index 93b62e0..043c62c 100644
>>--- a/drivers/hwspinlock/qcom_hwspinlock.c
>>+++ b/drivers/hwspinlock/qcom_hwspinlock.c
>>@@ -25,16 +25,26 @@
>>
>>  #include "hwspinlock_internal.h"
>>
>>-#define QCOM_MUTEX_APPS_PROC_ID	1
>>-#define QCOM_MUTEX_NUM_LOCKS	32
>>+#define QCOM_MUTEX_APPS_PROC_ID		1
>>+#define QCOM_MUTEX_CPUIDLE_OFFSET	128
>>+#define QCOM_CPUIDLE_LOCK		7
>>+#define QCOM_MUTEX_NUM_LOCKS		32
>>+
>
>This part of the diff doesn't look right.  Why is it showing that 
>QCOM_MUTEX_APPS_PROC_ID and QCOM_MUTEX_NUM_LOCKS are deleted and added 
>lines?  Shouldn't they be unchanged by this patch?
>
Sigh. I must have updated the tabs to play nice. Will fix in the next
spin.

Thanks for the review.

--Lina

>-- 
>Jeffrey Hugo
>Qualcomm Innovation Center, Inc.
>The Qualcomm Innovation Center, Inc. is a member of the Code Aurora 
>Forum, a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-05-01 17:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-01 17:06 [PATCH] hwspinlock: qcom: Lock #7 is special lock, uses dynamic proc_id Lina Iyer
2015-05-01 17:27 ` Jeffrey Hugo
2015-05-01 17:31   ` Lina Iyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox