diff mbox

Lock 7 is cpuidle specific, use non-generic value for locking

Message ID 1426189108-35488-1-git-send-email-lina.iyer@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Lina Iyer March 12, 2015, 7:38 p.m. UTC
---
 drivers/hwspinlock/qcom_hwspinlock.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Comments

Stephen Boyd March 12, 2015, 8:35 p.m. UTC | #1
On 03/12/15 12:38, Lina Iyer wrote:
> ---

sign off?

>  drivers/hwspinlock/qcom_hwspinlock.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/hwspinlock/qcom_hwspinlock.c b/drivers/hwspinlock/qcom_hwspinlock.c
> index 93b62e0..7642524 100644
> --- a/drivers/hwspinlock/qcom_hwspinlock.c
> +++ b/drivers/hwspinlock/qcom_hwspinlock.c
> @@ -25,16 +25,23 @@
>  
>  #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 int qcom_hwspinlock_trylock(struct hwspinlock *lock)
>  {
>  	struct regmap_field *field = lock->priv;
>  	u32 lock_owner;
>  	int ret;
> +	u32 proc_id;
>  
> -	ret = regmap_field_write(field, QCOM_MUTEX_APPS_PROC_ID);
> +	proc_id = hwspin_lock_get_id(lock) == QCOM_CPUIDLE_LOCK ?
> +			QCOM_MUTEX_CPUIDLE_OFFSET + smp_processor_id():

So we assume that the caller will always be the CPU that is locking the
lock? Also, do we assume that the remote side knows our CPU scheme here?
smp_processor_id() returns the logical CPU and not the physical CPU
number so hopefully the remote side doesn't care about logical CPU
numbers being written to the lock value.

Perhaps it would be better to have a way to tell the hwspinlock
framework what value we want written to the lock value.

> +			QCOM_MUTEX_APPS_PROC_ID;
> +
> +	ret = regmap_field_write(field, proc_id);
>  	if (ret)
>  		return ret;
>  
> @@ -42,7 +49,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)

The unlock path checks proc_id so we need to update the path there too.
Lina Iyer March 12, 2015, 8:48 p.m. UTC | #2
On Thu, Mar 12 2015 at 14:35 -0600, Stephen Boyd wrote:
>On 03/12/15 12:38, Lina Iyer wrote:
>> ---
>
>sign off?
>
:) I was just hacking it to make it easier to understand. Sure.

>>  drivers/hwspinlock/qcom_hwspinlock.c | 15 +++++++++++----
>>  1 file changed, 11 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/hwspinlock/qcom_hwspinlock.c b/drivers/hwspinlock/qcom_hwspinlock.c
>> index 93b62e0..7642524 100644
>> --- a/drivers/hwspinlock/qcom_hwspinlock.c
>> +++ b/drivers/hwspinlock/qcom_hwspinlock.c
>> @@ -25,16 +25,23 @@
>>
>>  #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 int qcom_hwspinlock_trylock(struct hwspinlock *lock)
>>  {
>>  	struct regmap_field *field = lock->priv;
>>  	u32 lock_owner;
>>  	int ret;
>> +	u32 proc_id;
>>
>> -	ret = regmap_field_write(field, QCOM_MUTEX_APPS_PROC_ID);
>> +	proc_id = hwspin_lock_get_id(lock) == QCOM_CPUIDLE_LOCK ?
>> +			QCOM_MUTEX_CPUIDLE_OFFSET + smp_processor_id():
>
>So we assume that the caller will always be the CPU that is locking the
>lock? Also, do we assume that the remote side knows our CPU scheme here?
>smp_processor_id() returns the logical CPU and not the physical CPU
>number so hopefully the remote side doesn't care about logical CPU
>numbers being written to the lock value.

The remote side (SCM) doesnt care the value written. We use 128+cpu to
be unique in Linux(128 is to make sure it doesnt clash with predefined
values used across by other processors.

>
>Perhaps it would be better to have a way to tell the hwspinlock
>framework what value we want written to the lock value.
>
That would be good, if there is value in that for other platforms, I
will gladly make the change.

Thoughts?

>> +			QCOM_MUTEX_APPS_PROC_ID;
>> +
>> +	ret = regmap_field_write(field, proc_id);
>>  	if (ret)
>>  		return ret;
>>
>> @@ -42,7 +49,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)
>
>The unlock path checks proc_id so we need to update the path there too.
>
Good point. I missed it.

>-- 
>Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
>a Linux Foundation Collaborative Project
>
--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andy Gross March 12, 2015, 8:49 p.m. UTC | #3
On Thu, Mar 12, 2015 at 01:38:28PM -0600, Lina Iyer wrote:

<snip>

>  static int qcom_hwspinlock_trylock(struct hwspinlock *lock)
>  {
>  	struct regmap_field *field = lock->priv;
>  	u32 lock_owner;
>  	int ret;
> +	u32 proc_id;
>  
> -	ret = regmap_field_write(field, QCOM_MUTEX_APPS_PROC_ID);
> +	proc_id = hwspin_lock_get_id(lock) == QCOM_CPUIDLE_LOCK ?
> +			QCOM_MUTEX_CPUIDLE_OFFSET + smp_processor_id():
> +			QCOM_MUTEX_APPS_PROC_ID;
> +
> +	ret = regmap_field_write(field, proc_id);

I think I'd rather have a qcom specific function and EXPORT_SYMBOL that to deal
with this special case.

>  	if (ret)
>  		return ret;
>  
> @@ -42,7 +49,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)
> -- 
> 2.1.0
>
Lina Iyer March 12, 2015, 8:56 p.m. UTC | #4
On Thu, Mar 12 2015 at 14:49 -0600, Andy Gross wrote:
>On Thu, Mar 12, 2015 at 01:38:28PM -0600, Lina Iyer wrote:
>
><snip>
>
>>  static int qcom_hwspinlock_trylock(struct hwspinlock *lock)
>>  {
>>  	struct regmap_field *field = lock->priv;
>>  	u32 lock_owner;
>>  	int ret;
>> +	u32 proc_id;
>>
>> -	ret = regmap_field_write(field, QCOM_MUTEX_APPS_PROC_ID);
>> +	proc_id = hwspin_lock_get_id(lock) == QCOM_CPUIDLE_LOCK ?
>> +			QCOM_MUTEX_CPUIDLE_OFFSET + smp_processor_id():
>> +			QCOM_MUTEX_APPS_PROC_ID;
>> +
>> +	ret = regmap_field_write(field, proc_id);
>
>I think I'd rather have a qcom specific function and EXPORT_SYMBOL that to deal
>with this special case.
>
I was going back and forth between a function and inlining this here.
But Stephen just made a good point that this is needed for unlock as
well. A function would be good.


>>  	if (ret)
>>  		return ret;
>>
>> @@ -42,7 +49,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)
>> --
>> 2.1.0
>>
>
>-- 
>Qualcomm Innovation Center, Inc.
>The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
>a Linux Foundation Collaborative Project
>
--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stephen Boyd March 12, 2015, 9:12 p.m. UTC | #5
On 03/12/15 13:48, Lina Iyer wrote:
> On Thu, Mar 12 2015 at 14:35 -0600, Stephen Boyd wrote:
>> On 03/12/15 12:38, Lina Iyer wrote:
>>> ---
>>
>> sign off?
>>
> :) I was just hacking it to make it easier to understand. Sure.
>
>>>  drivers/hwspinlock/qcom_hwspinlock.c | 15 +++++++++++----
>>>  1 file changed, 11 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/drivers/hwspinlock/qcom_hwspinlock.c
>>> b/drivers/hwspinlock/qcom_hwspinlock.c
>>> index 93b62e0..7642524 100644
>>> --- a/drivers/hwspinlock/qcom_hwspinlock.c
>>> +++ b/drivers/hwspinlock/qcom_hwspinlock.c
>>> @@ -25,16 +25,23 @@
>>>
>>>  #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 int qcom_hwspinlock_trylock(struct hwspinlock *lock)
>>>  {
>>>      struct regmap_field *field = lock->priv;
>>>      u32 lock_owner;
>>>      int ret;
>>> +    u32 proc_id;
>>>
>>> -    ret = regmap_field_write(field, QCOM_MUTEX_APPS_PROC_ID);
>>> +    proc_id = hwspin_lock_get_id(lock) == QCOM_CPUIDLE_LOCK ?
>>> +            QCOM_MUTEX_CPUIDLE_OFFSET + smp_processor_id():
>>
>> So we assume that the caller will always be the CPU that is locking the
>> lock? Also, do we assume that the remote side knows our CPU scheme here?
>> smp_processor_id() returns the logical CPU and not the physical CPU
>> number so hopefully the remote side doesn't care about logical CPU
>> numbers being written to the lock value.
>
> The remote side (SCM) doesnt care the value written. We use 128+cpu to
> be unique in Linux(128 is to make sure it doesnt clash with predefined
> values used across by other processors.
>
>

It looks like the remote side unlocks it too? It doesn't seem like this
will work with the framework very well. The framework has a kernel
spinlock attached to the hwspinlock so when we lock the hwspinlock we
also lock the kernel spinlock and we only release the kernel spinlock
when the kernel unlocks the hwspinlock. In this case it seems like
cpuidle wants to have it's own kernel spinlock and just use the trylock
loop part of __hwspin_lock_timeout() without taking any kernel side
locks. Plus it wants to write a specific value to the lock.
Lina Iyer March 12, 2015, 10:16 p.m. UTC | #6
On Thu, Mar 12 2015 at 15:12 -0600, Stephen Boyd wrote:
>On 03/12/15 13:48, Lina Iyer wrote:
>> On Thu, Mar 12 2015 at 14:35 -0600, Stephen Boyd wrote:
>>> On 03/12/15 12:38, Lina Iyer wrote:
>>>> ---
>>>
>>> sign off?
>>>
>> :) I was just hacking it to make it easier to understand. Sure.
>>
>>>>  drivers/hwspinlock/qcom_hwspinlock.c | 15 +++++++++++----
>>>>  1 file changed, 11 insertions(+), 4 deletions(-)
>>>>
>>>> diff --git a/drivers/hwspinlock/qcom_hwspinlock.c
>>>> b/drivers/hwspinlock/qcom_hwspinlock.c
>>>> index 93b62e0..7642524 100644
>>>> --- a/drivers/hwspinlock/qcom_hwspinlock.c
>>>> +++ b/drivers/hwspinlock/qcom_hwspinlock.c
>>>> @@ -25,16 +25,23 @@
>>>>
>>>>  #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 int qcom_hwspinlock_trylock(struct hwspinlock *lock)
>>>>  {
>>>>      struct regmap_field *field = lock->priv;
>>>>      u32 lock_owner;
>>>>      int ret;
>>>> +    u32 proc_id;
>>>>
>>>> -    ret = regmap_field_write(field, QCOM_MUTEX_APPS_PROC_ID);
>>>> +    proc_id = hwspin_lock_get_id(lock) == QCOM_CPUIDLE_LOCK ?
>>>> +            QCOM_MUTEX_CPUIDLE_OFFSET + smp_processor_id():
>>>
>>> So we assume that the caller will always be the CPU that is locking the
>>> lock? Also, do we assume that the remote side knows our CPU scheme here?
>>> smp_processor_id() returns the logical CPU and not the physical CPU
>>> number so hopefully the remote side doesn't care about logical CPU
>>> numbers being written to the lock value.
>>
>> The remote side (SCM) doesnt care the value written. We use 128+cpu to
>> be unique in Linux(128 is to make sure it doesnt clash with predefined
>> values used across by other processors.
>>
>>
>
>It looks like the remote side unlocks it too? It doesn't seem like this
>will work with the framework very well. The framework has a kernel
>spinlock attached to the hwspinlock so when we lock the hwspinlock we
>also lock the kernel spinlock and we only release the kernel spinlock
>when the kernel unlocks the hwspinlock. In this case it seems like
>cpuidle wants to have it's own kernel spinlock and just use the trylock
>loop part of __hwspin_lock_timeout() without taking any kernel side
>locks. Plus it wants to write a specific value to the lock.
>
Right.
Just noticed that part of the hwspinlock. Yes SCM unlocks the
hwspinlock. So I cannot hold any lock in Linux. May need changes in the
hwspinlock framework. Seems like an additional flag in hwspinlock to not
lock any in the trylock path work work. Hmm....



>-- 
>Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
>a Linux Foundation Collaborative Project
>
--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andy Gross March 13, 2015, 8:02 p.m. UTC | #7
On Thu, Mar 12, 2015 at 04:16:00PM -0600, Lina Iyer wrote:

<snip>

> >It looks like the remote side unlocks it too? It doesn't seem like this
> >will work with the framework very well. The framework has a kernel
> >spinlock attached to the hwspinlock so when we lock the hwspinlock we
> >also lock the kernel spinlock and we only release the kernel spinlock
> >when the kernel unlocks the hwspinlock. In this case it seems like
> >cpuidle wants to have it's own kernel spinlock and just use the trylock
> >loop part of __hwspin_lock_timeout() without taking any kernel side
> >locks. Plus it wants to write a specific value to the lock.
> >
> Right.
> Just noticed that part of the hwspinlock. Yes SCM unlocks the
> hwspinlock. So I cannot hold any lock in Linux. May need changes in the
> hwspinlock framework. Seems like an additional flag in hwspinlock to not
> lock any in the trylock path work work. Hmm....

Or a specific EXPORT function for this one usecase which is unlike anyone elses
usage.
Lina Iyer March 13, 2015, 9:27 p.m. UTC | #8
On Fri, Mar 13 2015 at 14:02 -0600, Andy Gross wrote:
>On Thu, Mar 12, 2015 at 04:16:00PM -0600, Lina Iyer wrote:
>
><snip>
>
>> >It looks like the remote side unlocks it too? It doesn't seem like this
>> >will work with the framework very well. The framework has a kernel
>> >spinlock attached to the hwspinlock so when we lock the hwspinlock we
>> >also lock the kernel spinlock and we only release the kernel spinlock
>> >when the kernel unlocks the hwspinlock. In this case it seems like
>> >cpuidle wants to have it's own kernel spinlock and just use the trylock
>> >loop part of __hwspin_lock_timeout() without taking any kernel side
>> >locks. Plus it wants to write a specific value to the lock.
>> >
>> Right.
>> Just noticed that part of the hwspinlock. Yes SCM unlocks the
>> hwspinlock. So I cannot hold any lock in Linux. May need changes in the
>> hwspinlock framework. Seems like an additional flag in hwspinlock to not
>> lock any in the trylock path work work. Hmm....
>
>Or a specific EXPORT function for this one usecase which is unlike anyone elses
>usage.

I think, this can be handled well within the QCOM driver. I will submit
a patch for it and we can discuss then later. For now, this will work
fine as is.

Lina

>
>-- 
>Qualcomm Innovation Center, Inc.
>The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
>a Linux Foundation Collaborative Project
>
--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/hwspinlock/qcom_hwspinlock.c b/drivers/hwspinlock/qcom_hwspinlock.c
index 93b62e0..7642524 100644
--- a/drivers/hwspinlock/qcom_hwspinlock.c
+++ b/drivers/hwspinlock/qcom_hwspinlock.c
@@ -25,16 +25,23 @@ 
 
 #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 int qcom_hwspinlock_trylock(struct hwspinlock *lock)
 {
 	struct regmap_field *field = lock->priv;
 	u32 lock_owner;
 	int ret;
+	u32 proc_id;
 
-	ret = regmap_field_write(field, QCOM_MUTEX_APPS_PROC_ID);
+	proc_id = hwspin_lock_get_id(lock) == QCOM_CPUIDLE_LOCK ?
+			QCOM_MUTEX_CPUIDLE_OFFSET + smp_processor_id():
+			QCOM_MUTEX_APPS_PROC_ID;
+
+	ret = regmap_field_write(field, proc_id);
 	if (ret)
 		return ret;
 
@@ -42,7 +49,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)