Re: svn commit: r357728 - head/sys/sys
On Mon, Feb 10, 2020 at 01:52:26PM +, Mateusz Guzik wrote: M> Author: mjg M> Date: Mon Feb 10 13:52:25 2020 M> New Revision: 357728 M> URL: https://svnweb.freebsd.org/changeset/base/357728 M> M> Log: M> Tidy up zpcpu_replace* M> M> - only compute the target address once M> - remove spurious type casting, zpcpu_get already return the correct type M> M> While here add missing newlines to other routines. M> M> Modified: M> head/sys/sys/pcpu.h M> M> Modified: head/sys/sys/pcpu.h M> == M> --- head/sys/sys/pcpu.h Mon Feb 10 13:24:14 2020(r357727) M> +++ head/sys/sys/pcpu.h Mon Feb 10 13:52:25 2020(r357728) M> @@ -245,32 +245,41 @@ extern struct pcpu *cpuid_to_pcpu[]; M> * If you need atomicity use xchg. M> * */ M> #define zpcpu_replace(base, val) ({ \ M> -__typeof(val) _old = *(__typeof(base))zpcpu_get(base); \ M> -*(__typeof(val) *)zpcpu_get(base) = val;\ M> +__typeof(val) *_ptr = zpcpu_get(base); \ M> +__typeof(val) _old; \ M> +\ M> +_old = *_ptr; \ M> +*_ptr = val;\ M> _old; \ M> }) I think this function must have only protected variant that asserts that curthread->td_critnest is on. zpcpu_get() sometimes can be used without critical section, when we are fine with getting a value from a different CPU. However, can't imagine a situation where migrating during a replace operation is acceptable. -- Gleb Smirnoff ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
Re: svn commit: r357728 - head/sys/sys
Hi; On 10/02/2020 08:52, Mateusz Guzik wrote: Author: mjg Date: Mon Feb 10 13:52:25 2020 New Revision: 357728 URL: https://svnweb.freebsd.org/changeset/base/357728 Log: Tidy up zpcpu_replace* - only compute the target address once - remove spurious type casting, zpcpu_get already return the correct type While here add missing newlines to other routines. Modified: head/sys/sys/pcpu.h For the record, this file (and many others), uses a space after #define, when we should be using a tab to conform with style(9). One of the many lessons from bde. I have a huge patch to fix those, which I won't commit because it wouldl obliterate all VCS annotations. Pedro. Modified: head/sys/sys/pcpu.h == --- head/sys/sys/pcpu.h Mon Feb 10 13:24:14 2020(r357727) +++ head/sys/sys/pcpu.h Mon Feb 10 13:52:25 2020(r357728) @@ -245,32 +245,41 @@ extern struct pcpu *cpuid_to_pcpu[]; * If you need atomicity use xchg. * */ #define zpcpu_replace(base, val) ({ \ - __typeof(val) _old = *(__typeof(base))zpcpu_get(base); \ - *(__typeof(val) *)zpcpu_get(base) = val;\ + __typeof(val) *_ptr = zpcpu_get(base); \ + __typeof(val) _old; \ + \ + _old = *_ptr; \ + *_ptr = val;\ _old; \ }) #define zpcpu_replace_cpu(base, val, cpu) ({\ - __typeof(val) _old = *(__typeof(base))zpcpu_get_cpu(base, cpu); \ - *(__typeof(val) *)zpcpu_get_cpu(base, cpu) = val; \ + __typeof(val) *_ptr = zpcpu_get_cpu(base, cpu); \ + __typeof(val) _old; \ + \ + _old = *_ptr; \ + *_ptr = val;\ _old; \ }) #define zpcpu_set_protected(base, val) ({\ MPASS(curthread->td_critnest > 0);\ __typeof(val) *_ptr = zpcpu_get(base); \ + \ *_ptr = (val); \ }) #define zpcpu_add_protected(base, val) ({\ MPASS(curthread->td_critnest > 0);\ __typeof(val) *_ptr = zpcpu_get(base); \ + \ *_ptr += (val); \ }) #define zpcpu_sub_protected(base, val) ({\ MPASS(curthread->td_critnest > 0);\ __typeof(val) *_ptr = zpcpu_get(base); \ + \ *_ptr -= (val); \ }) ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
svn commit: r357728 - head/sys/sys
Author: mjg Date: Mon Feb 10 13:52:25 2020 New Revision: 357728 URL: https://svnweb.freebsd.org/changeset/base/357728 Log: Tidy up zpcpu_replace* - only compute the target address once - remove spurious type casting, zpcpu_get already return the correct type While here add missing newlines to other routines. Modified: head/sys/sys/pcpu.h Modified: head/sys/sys/pcpu.h == --- head/sys/sys/pcpu.h Mon Feb 10 13:24:14 2020(r357727) +++ head/sys/sys/pcpu.h Mon Feb 10 13:52:25 2020(r357728) @@ -245,32 +245,41 @@ extern struct pcpu *cpuid_to_pcpu[]; * If you need atomicity use xchg. * */ #define zpcpu_replace(base, val) ({\ - __typeof(val) _old = *(__typeof(base))zpcpu_get(base); \ - *(__typeof(val) *)zpcpu_get(base) = val;\ + __typeof(val) *_ptr = zpcpu_get(base); \ + __typeof(val) _old; \ + \ + _old = *_ptr; \ + *_ptr = val;\ _old; \ }) #define zpcpu_replace_cpu(base, val, cpu) ({ \ - __typeof(val) _old = *(__typeof(base))zpcpu_get_cpu(base, cpu); \ - *(__typeof(val) *)zpcpu_get_cpu(base, cpu) = val; \ + __typeof(val) *_ptr = zpcpu_get_cpu(base, cpu); \ + __typeof(val) _old; \ + \ + _old = *_ptr; \ + *_ptr = val;\ _old; \ }) #define zpcpu_set_protected(base, val) ({ \ MPASS(curthread->td_critnest > 0); \ __typeof(val) *_ptr = zpcpu_get(base); \ + \ *_ptr = (val); \ }) #define zpcpu_add_protected(base, val) ({ \ MPASS(curthread->td_critnest > 0); \ __typeof(val) *_ptr = zpcpu_get(base); \ + \ *_ptr += (val); \ }) #define zpcpu_sub_protected(base, val) ({ \ MPASS(curthread->td_critnest > 0); \ __typeof(val) *_ptr = zpcpu_get(base); \ + \ *_ptr -= (val); \ }) ___ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"