[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAFULd4Z4QzS0J_BztD7jDSNwoXM2vF9PWNX5eJBrQZsUbu-gJQ@mail.gmail.com>
Date: Thu, 5 Sep 2024 14:02:33 +0200
From: Uros Bizjak <ubizjak@...il.com>
To: Huacai Chen <chenhuacai@...nel.org>
Cc: loongarch@...ts.linux.dev, linux-kernel@...r.kernel.org,
WANG Xuerui <kernel@...0n.name>, Xi Ruoyao <xry111@...111.site>,
Thomas Gleixner <tglx@...utronix.de>
Subject: Re: [PATCH v3] LoongArch/percpu: Simplify _percpu_read() and _percpu_write()
On Thu, Sep 5, 2024 at 1:47 PM Huacai Chen <chenhuacai@...nel.org> wrote:
>
> Hi, Uros,
>
> On Thu, Sep 5, 2024 at 2:54 PM Uros Bizjak <ubizjak@...il.com> wrote:
> >
> > _percpu_read() and _percpu_write() macros call __percpu_read()
> > and __percpu_write() static inline functions that result in a single
> > assembly instruction. Percpu infrastructure expects its leaf
> > definitions to encode the size of their percpu variable, so the patch
> > merges asm clauses from the static inline function into the
> > corresponding leaf macros.
> >
> > The secondary effect of this change is to avoid explicit __percpu
> > function arguments. Currently, __percpu macro is defined in
> > include/linux/compiler_types.h, but with proposed patch [1],
> > __percpu definition will need macros from include/asm-generic/percpu.h,
> > creating forward dependency loop.
> >
> > The proposed solution is the same as x86 architecture uses.
> > +#define _percpu_read(size, _pcp) \
> > +({ \
> > + unsigned long __pcp_ret; \
> > + \
> > + __asm__ __volatile__( \
> > + __pcpu_op_##size("ldx") "%[ret], $r21, %[ptr] \n" \
> > + : [ret] "=&r"(__pcp_ret) \
> > + : [ptr] "r"(&(_pcp)) \
> > + : "memory"); \
> > + (typeof(_pcp))__pcp_ret; \
> > +})
> > +
> > +#define __pcpu_cast_1(val) (((unsigned long) val) & 0xff)
> If the input value is less than 0xff, then "& 0xff" is meaningless, if
> the input value is more than 0xff, this conversion still cannot give a
> correct result for the caller. So I think for all sizes it is enough
> to just use "((unsigned long) val)".
This part is used to force unsigned extension, otherwise the compiler
will use sign-extension of the possibly signed variable.
Uros.
Powered by blists - more mailing lists