Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1275180 > unrolled thread
| Started by | Ling Ma <ling.ma.program@gmail.com> |
|---|---|
| First post | 2015-11-23 10:50 +0100 |
| Last post | 2015-12-06 14:10 +0100 |
| Articles | 8 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Improve spinlock performance by moving work to one core Ling Ma <ling.ma.program@gmail.com> - 2015-11-23 10:50 +0100
Re: Improve spinlock performance by moving work to one core Ling Ma <ling.ma.program@gmail.com> - 2015-11-25 03:00 +0100
Re: Improve spinlock performance by moving work to one core Waiman Long <waiman.long@hpe.com> - 2015-11-25 20:10 +0100
Re: Improve spinlock performance by moving work to one core Ling Ma <ling.ma.program@gmail.com> - 2015-11-26 04:50 +0100
Re: Improve spinlock performance by moving work to one core Ling Ma <ling.ma.program@gmail.com> - 2015-11-26 10:10 +0100
Re: Improve spinlock performance by moving work to one core Ling Ma <ling.ma.program@gmail.com> - 2015-11-30 07:20 +0100
Re: Improve spinlock performance by moving work to one core Waiman Long <waiman.long@hpe.com> - 2015-11-30 22:00 +0100
Re: Improve spinlock performance by moving work to one core Ling Ma <ling.ma.program@gmail.com> - 2015-12-06 14:10 +0100
| From | Ling Ma <ling.ma.program@gmail.com> |
|---|---|
| Date | 2015-11-23 10:50 +0100 |
| Subject | Re: Improve spinlock performance by moving work to one core |
| Message-ID | <qxVV0-8qv-7@gated-at.bofh.it> |
[Multipart message — attachments visible in raw view] — view raw
Hi Longman, Attachments include user space application thread.c and kernel patch spinlock-test.patch based on kernel 4.3.0-rc4 we run thread.c with kernel patch, test original and new spinlock respectively, perf top -G indicates thread.c cause cache_alloc_refill and cache_flusharray functions to spend ~25% time on original spinlock, after introducing new spinlock in two functions, the cost time become ~22%. The printed data also tell us the new spinlock improves performance by about 15%( 93841765576 / 81036259588) on E5-2699V3 Appreciate your comments. Thanks Ling 2015-11-07 1:38 GMT+08:00 Waiman Long <waiman.long@hpe.com>: > > On 11/05/2015 11:28 PM, Ling Ma wrote: >> >> Longman >> >> Thanks for your suggestion. >> We will look for real scenario to test, and could you please introduce >> some benchmarks on spinlock ? >> >> Regards >> Ling >> >> > > The kernel has been well optimized for most common workloads that spinlock contention is usually not a performance bottleneck. There are still corner cases where there is heavy spinlock contention. > > I used a spinlock loop microbenchmark like what you are doing as well as AIM7 for application level testing. > > Cheers, > Longman > >
[toc] | [next] | [standalone]
| From | Ling Ma <ling.ma.program@gmail.com> |
|---|---|
| Date | 2015-11-25 03:00 +0100 |
| Message-ID | <qyxxg-7M5-7@gated-at.bofh.it> |
| In reply to | #1275180 |
Any comments about it ? Thanks Ling 2015-11-23 17:41 GMT+08:00 Ling Ma <ling.ma.program@gmail.com>: > Hi Longman, > > Attachments include user space application thread.c and kernel patch > spinlock-test.patch based on kernel 4.3.0-rc4 > > we run thread.c with kernel patch, test original and new spinlock respectively, > perf top -G indicates thread.c cause cache_alloc_refill and > cache_flusharray functions to spend ~25% time on original spinlock, > after introducing new spinlock in two functions, the cost time become ~22%. > > The printed data also tell us the new spinlock improves performance > by about 15%( 93841765576 / 81036259588) on E5-2699V3 > > Appreciate your comments. > > Thanks > Ling > > 2015-11-07 1:38 GMT+08:00 Waiman Long <waiman.long@hpe.com>: >> >> On 11/05/2015 11:28 PM, Ling Ma wrote: >>> >>> Longman >>> >>> Thanks for your suggestion. >>> We will look for real scenario to test, and could you please introduce >>> some benchmarks on spinlock ? >>> >>> Regards >>> Ling >>> >>> >> >> The kernel has been well optimized for most common workloads that spinlock contention is usually not a performance bottleneck. There are still corner cases where there is heavy spinlock contention. >> >> I used a spinlock loop microbenchmark like what you are doing as well as AIM7 for application level testing. >> >> Cheers, >> Longman >> >> -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Waiman Long <waiman.long@hpe.com> |
|---|---|
| Date | 2015-11-25 20:10 +0100 |
| Message-ID | <qyNC2-1Wc-15@gated-at.bofh.it> |
| In reply to | #1275180 |
On 11/23/2015 04:41 AM, Ling Ma wrote:
> Hi Longman,
>
> Attachments include user space application thread.c and kernel patch
> spinlock-test.patch based on kernel 4.3.0-rc4
>
> we run thread.c with kernel patch, test original and new spinlock respectively,
> perf top -G indicates thread.c cause cache_alloc_refill and
> cache_flusharray functions to spend ~25% time on original spinlock,
> after introducing new spinlock in two functions, the cost time become ~22%.
>
> The printed data also tell us the new spinlock improves performance
> by about 15%( 93841765576 / 81036259588) on E5-2699V3
>
> Appreciate your comments.
>
>
I saw that you make the following changes in the code:
static __always_inline void queued_spin_lock(struct qspinlock *lock)
{
u32 val;
-
+repeat:
val = atomic_cmpxchg(&lock->val, 0, _Q_LOCKED_VAL);
if (likely(val == 0))
return;
- queued_spin_lock_slowpath(lock, val);
+ goto repeat;
+ //queued_spin_lock_slowpath(lock, val);
}
This effectively changes the queued spinlock into an unfair byte lock.
Without a pause to moderate the cmpxchg() call, that is especially bad
for performance. Is the performance data above refers to the unfair byte
lock versus your new spinlock?
Cheers,
Longman
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Ling Ma <ling.ma.program@gmail.com> |
|---|---|
| Date | 2015-11-26 04:50 +0100 |
| Message-ID | <qyVJf-7nu-3@gated-at.bofh.it> |
| In reply to | #1277706 |
Hi Longman,
All compared data is from the below operation in spinlock-test.patch:
+#if ORG_QUEUED_SPINLOCK
+ org_queued_spin_lock((struct qspinlock *)&pa.n->list_lock);
+ refill_fn(&pa);
+ org_queued_spin_unlock((struct qspinlock *)&pa.n->list_lock);
+#else
+ new_spin_lock((struct nspinlock *)&pa.n->list_lock, refill_fn, &pa);
+#endif
and
+#if ORG_QUEUED_SPINLOCK
+ org_queued_spin_lock((struct qspinlock *)&pa.n->list_lock);
+ flusharray_fn(&pa);
+ org_queued_spin_unlock((struct qspinlock *)&pa.n->list_lock);
+#else
+ new_spin_lock((struct nspinlock *)&pa.n->list_lock, flusharray_fn, &pa);
+#endif
So the result is correct and fair.
Yes, we updated the code in include/asm-generic/qspinlock.h to
simplified modification and avoid kernel crash,
for example there are 10 lock scenarios to use new spin lock,
because bottle-neck is only from one or two scenarios, we only modify them,
other lock scenarios will continue to use the lock in qspinlock.h, we
must modify the code,
otherwise the operation will be hooked in the queued and never be waken up.
Thanks
Ling
2015-11-26 3:05 GMT+08:00 Waiman Long <waiman.long@hpe.com>:
> On 11/23/2015 04:41 AM, Ling Ma wrote:
>> Hi Longman,
>>
>> Attachments include user space application thread.c and kernel patch
>> spinlock-test.patch based on kernel 4.3.0-rc4
>>
>> we run thread.c with kernel patch, test original and new spinlock respectively,
>> perf top -G indicates thread.c cause cache_alloc_refill and
>> cache_flusharray functions to spend ~25% time on original spinlock,
>> after introducing new spinlock in two functions, the cost time become ~22%.
>>
>> The printed data also tell us the new spinlock improves performance
>> by about 15%( 93841765576 / 81036259588) on E5-2699V3
>>
>> Appreciate your comments.
>>
>>
>
> I saw that you make the following changes in the code:
>
> static __always_inline void queued_spin_lock(struct qspinlock *lock)
> {
> u32 val;
> -
> +repeat:
> val = atomic_cmpxchg(&lock->val, 0, _Q_LOCKED_VAL);
> if (likely(val == 0))
> return;
> - queued_spin_lock_slowpath(lock, val);
> + goto repeat;
> + //queued_spin_lock_slowpath(lock, val);
> }
>
>
> This effectively changes the queued spinlock into an unfair byte lock.
> Without a pause to moderate the cmpxchg() call, that is especially bad
> for performance. Is the performance data above refers to the unfair byte
> lock versus your new spinlock?
>
> Cheers,
> Longman
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Ling Ma <ling.ma.program@gmail.com> |
|---|---|
| Date | 2015-11-26 10:10 +0100 |
| Message-ID | <qz0IW-35e-15@gated-at.bofh.it> |
| In reply to | #1277963 |
Run thread.c with clean kernel 4.3.0-rc4, perf top -G also indicates
cache_flusharray and cache_alloc_refill functions spend 25.6% time
on queued_spin_lock_slowpath totally. it means the compared data
from our spinlock-test.patch is reliable.
Thanks
Ling
2015-11-26 11:49 GMT+08:00 Ling Ma <ling.ma.program@gmail.com>:
> Hi Longman,
>
> All compared data is from the below operation in spinlock-test.patch:
>
> +#if ORG_QUEUED_SPINLOCK
> + org_queued_spin_lock((struct qspinlock *)&pa.n->list_lock);
> + refill_fn(&pa);
> + org_queued_spin_unlock((struct qspinlock *)&pa.n->list_lock);
> +#else
> + new_spin_lock((struct nspinlock *)&pa.n->list_lock, refill_fn, &pa);
> +#endif
>
> and
>
> +#if ORG_QUEUED_SPINLOCK
> + org_queued_spin_lock((struct qspinlock *)&pa.n->list_lock);
> + flusharray_fn(&pa);
> + org_queued_spin_unlock((struct qspinlock *)&pa.n->list_lock);
> +#else
> + new_spin_lock((struct nspinlock *)&pa.n->list_lock, flusharray_fn, &pa);
> +#endif
>
> So the result is correct and fair.
>
> Yes, we updated the code in include/asm-generic/qspinlock.h to
> simplified modification and avoid kernel crash,
> for example there are 10 lock scenarios to use new spin lock,
> because bottle-neck is only from one or two scenarios, we only modify them,
> other lock scenarios will continue to use the lock in qspinlock.h, we
> must modify the code,
> otherwise the operation will be hooked in the queued and never be waken up.
>
> Thanks
> Ling
>
>
>
> 2015-11-26 3:05 GMT+08:00 Waiman Long <waiman.long@hpe.com>:
>> On 11/23/2015 04:41 AM, Ling Ma wrote:
>>> Hi Longman,
>>>
>>> Attachments include user space application thread.c and kernel patch
>>> spinlock-test.patch based on kernel 4.3.0-rc4
>>>
>>> we run thread.c with kernel patch, test original and new spinlock respectively,
>>> perf top -G indicates thread.c cause cache_alloc_refill and
>>> cache_flusharray functions to spend ~25% time on original spinlock,
>>> after introducing new spinlock in two functions, the cost time become ~22%.
>>>
>>> The printed data also tell us the new spinlock improves performance
>>> by about 15%( 93841765576 / 81036259588) on E5-2699V3
>>>
>>> Appreciate your comments.
>>>
>>>
>>
>> I saw that you make the following changes in the code:
>>
>> static __always_inline void queued_spin_lock(struct qspinlock *lock)
>> {
>> u32 val;
>> -
>> +repeat:
>> val = atomic_cmpxchg(&lock->val, 0, _Q_LOCKED_VAL);
>> if (likely(val == 0))
>> return;
>> - queued_spin_lock_slowpath(lock, val);
>> + goto repeat;
>> + //queued_spin_lock_slowpath(lock, val);
>> }
>>
>>
>> This effectively changes the queued spinlock into an unfair byte lock.
>> Without a pause to moderate the cmpxchg() call, that is especially bad
>> for performance. Is the performance data above refers to the unfair byte
>> lock versus your new spinlock?
>>
>> Cheers,
>> Longman
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Ling Ma <ling.ma.program@gmail.com> |
|---|---|
| Date | 2015-11-30 07:20 +0100 |
| Message-ID | <qApYC-8mg-11@gated-at.bofh.it> |
| In reply to | #1278100 |
Any comments, the patch is acceptable ?
Thanks
Ling
2015-11-26 17:00 GMT+08:00 Ling Ma <ling.ma.program@gmail.com>:
> Run thread.c with clean kernel 4.3.0-rc4, perf top -G also indicates
> cache_flusharray and cache_alloc_refill functions spend 25.6% time
> on queued_spin_lock_slowpath totally. it means the compared data
> from our spinlock-test.patch is reliable.
>
> Thanks
> Ling
>
> 2015-11-26 11:49 GMT+08:00 Ling Ma <ling.ma.program@gmail.com>:
>> Hi Longman,
>>
>> All compared data is from the below operation in spinlock-test.patch:
>>
>> +#if ORG_QUEUED_SPINLOCK
>> + org_queued_spin_lock((struct qspinlock *)&pa.n->list_lock);
>> + refill_fn(&pa);
>> + org_queued_spin_unlock((struct qspinlock *)&pa.n->list_lock);
>> +#else
>> + new_spin_lock((struct nspinlock *)&pa.n->list_lock, refill_fn, &pa);
>> +#endif
>>
>> and
>>
>> +#if ORG_QUEUED_SPINLOCK
>> + org_queued_spin_lock((struct qspinlock *)&pa.n->list_lock);
>> + flusharray_fn(&pa);
>> + org_queued_spin_unlock((struct qspinlock *)&pa.n->list_lock);
>> +#else
>> + new_spin_lock((struct nspinlock *)&pa.n->list_lock, flusharray_fn, &pa);
>> +#endif
>>
>> So the result is correct and fair.
>>
>> Yes, we updated the code in include/asm-generic/qspinlock.h to
>> simplified modification and avoid kernel crash,
>> for example there are 10 lock scenarios to use new spin lock,
>> because bottle-neck is only from one or two scenarios, we only modify them,
>> other lock scenarios will continue to use the lock in qspinlock.h, we
>> must modify the code,
>> otherwise the operation will be hooked in the queued and never be waken up.
>>
>> Thanks
>> Ling
>>
>>
>>
>> 2015-11-26 3:05 GMT+08:00 Waiman Long <waiman.long@hpe.com>:
>>> On 11/23/2015 04:41 AM, Ling Ma wrote:
>>>> Hi Longman,
>>>>
>>>> Attachments include user space application thread.c and kernel patch
>>>> spinlock-test.patch based on kernel 4.3.0-rc4
>>>>
>>>> we run thread.c with kernel patch, test original and new spinlock respectively,
>>>> perf top -G indicates thread.c cause cache_alloc_refill and
>>>> cache_flusharray functions to spend ~25% time on original spinlock,
>>>> after introducing new spinlock in two functions, the cost time become ~22%.
>>>>
>>>> The printed data also tell us the new spinlock improves performance
>>>> by about 15%( 93841765576 / 81036259588) on E5-2699V3
>>>>
>>>> Appreciate your comments.
>>>>
>>>>
>>>
>>> I saw that you make the following changes in the code:
>>>
>>> static __always_inline void queued_spin_lock(struct qspinlock *lock)
>>> {
>>> u32 val;
>>> -
>>> +repeat:
>>> val = atomic_cmpxchg(&lock->val, 0, _Q_LOCKED_VAL);
>>> if (likely(val == 0))
>>> return;
>>> - queued_spin_lock_slowpath(lock, val);
>>> + goto repeat;
>>> + //queued_spin_lock_slowpath(lock, val);
>>> }
>>>
>>>
>>> This effectively changes the queued spinlock into an unfair byte lock.
>>> Without a pause to moderate the cmpxchg() call, that is especially bad
>>> for performance. Is the performance data above refers to the unfair byte
>>> lock versus your new spinlock?
>>>
>>> Cheers,
>>> Longman
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Waiman Long <waiman.long@hpe.com> |
|---|---|
| Date | 2015-11-30 22:00 +0100 |
| Message-ID | <qADIf-8wf-23@gated-at.bofh.it> |
| In reply to | #1279579 |
On 11/30/2015 01:17 AM, Ling Ma wrote: > Any comments, the patch is acceptable ? > > Thanks > Ling > > Ling, The core idea of your current patch hasn't changed from your previous patch. My comment is that you should not attempt to sell it as a replacement of the current spinlock mechanism. I just don't see that will happen given the change in API semantics. Also, I think there are probably cases that your patch cannot be applied. So treat it as a separate synchronization mechanism that can be useful in some scenarios. Cheers, Longman -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Ling Ma <ling.ma.program@gmail.com> |
|---|---|
| Date | 2015-12-06 14:10 +0100 |
| Message-ID | <qCHeF-7kf-3@gated-at.bofh.it> |
| In reply to | #1280274 |
[Multipart message — attachments visible in raw view] — view raw
Longman, We further optimized the kernel spinlock in ali-spin-lock.patch as attachment based on kernel 4.3.0-rc4. Run thread.c in user space with kernel patch(ali-spin-lock.patch) on E5-2699v3, compare with original spinlock: The printed data indicates the performance in critical path is improved by 1.91x (92715428576 cycles/ 48475891244 cycles), perf top -d1 also tell us the spinlock cost time is reduced from 25% to 15% All compared data is from the below operation in ali-spin-lock.patch: +#if ORG_QUEUED_SPINLOCK + org_queued_spin_lock((struct qspinlock *)&pa.n->list_lock); + refill_fn(&pa); + org_queued_spin_unlock((struct qspinlock *)&pa.n->list_lock); +#else + ali_spin_lock((struct alispinlock *)&pa.n->list_lock, refill_fn, &pa); +#endif and +#if ORG_QUEUED_SPINLOCK + org_queued_spin_lock((struct qspinlock *)&pa.n->list_lock); + flusharray_fn(&pa); + org_queued_spin_unlock((struct qspinlock *)&pa.n->list_lock); +#else + ali_spin_lock((struct alispinlock *)&pa.n->list_lock, flusharray_fn, &pa); +#endif We will send the formal patch as a separate synchronization mechanism soon. Appreciate your comments. Thanks Ling 2015-12-01 4:55 GMT+08:00 Waiman Long <waiman.long@hpe.com>: > On 11/30/2015 01:17 AM, Ling Ma wrote: >> >> Any comments, the patch is acceptable ? >> >> Thanks >> Ling >> >> > Ling, > > The core idea of your current patch hasn't changed from your previous > patch. > > My comment is that you should not attempt to sell it as a replacement > of the current spinlock mechanism. I just don't see that will happen > given the change in API semantics. Also, I think there are probably > cases that your patch cannot be applied. So treat it as a separate > synchronization mechanism that can be useful in some scenarios. > > Cheers, > Longman >
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web