* [PATCH] m68k: implement runtime consts
@ 2025-11-27 0:05 Daniel Palmer
2025-11-27 1:59 ` kernel test robot
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Palmer @ 2025-11-27 0:05 UTC (permalink / raw)
To: geert; +Cc: kas, mingo, seanjc, bp, linux-m68k, linux-kernel, Daniel Palmer
This implements runtime consts for m68k which hopefully improves
performance a tiny bit, maybe, hopefully... going downhill with
the wind behind us.
Constant pointers are just a register load with an immediate that is
fixed up.
Constant shifts are a very small register load with an immediate that
is fixed up and then the val is shifted by the register. Putting the
shift amount in a register is needed as the shift instruction can only
encode a maximum of shift by 8 with an immediate.
Before:
0013c6ea <__d_lookup_rcu_op_compare>:
...
13c6fc: 2003 movel %d3,%d0
13c6fe: 2239 0069 a980 movel 69a980 <d_hash_shift>,%d1
13c704: e2a8 lsrl %d1,%d0
13c706: e588 lsll #2,%d0
13c708: d0b9 0069 a97c addl 69a97c <dentry_hashtable>,%d0
...
After:
0013c6c0 <__d_lookup_rcu_op_compare>:
...
13c6d2: 207c cafe f00d moveal #-889262067,%a0
13c6d8: 2003 movel %d3,%d0
13c6da: 720c moveq #12,%d1
13c6dc: e2a8 lsrl %d1,%d0
13c6de: e588 lsll #2,%d0
13c6e0: d1c0 addal %d0,%a0
...
Signed-off-by: Daniel Palmer <daniel@thingy.jp>
---
arch/m68k/include/asm/runtime-const.h | 76 +++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
create mode 100644 arch/m68k/include/asm/runtime-const.h
diff --git a/arch/m68k/include/asm/runtime-const.h b/arch/m68k/include/asm/runtime-const.h
new file mode 100644
index 000000000000..576031c5b808
--- /dev/null
+++ b/arch/m68k/include/asm/runtime-const.h
@@ -0,0 +1,76 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * runtime const implementation for m68k
+ * Copyright (C) 2025 Daniel Palmer<daniel@thingy.jp>
+ *
+ * Based on arm64 version.
+ */
+#ifndef _ASM_RUNTIME_CONST_H
+#define _ASM_RUNTIME_CONST_H
+
+#include <asm/cacheflush.h>
+#include <linux/bitfield.h>
+
+#define runtime_const_ptr(sym) ({ \
+ typeof(sym) __ret; \
+ asm_inline("1:\t" \
+ "mov.l #0xcafef00d,%0\n\t" \
+ ".pushsection runtime_ptr_" #sym ",\"a\"\n\t" \
+ ".long 1b - .\n\t" \
+ ".popsection" \
+ : "=a" (__ret)); \
+ __ret; })
+
+static inline void __runtime_fixup_ptr(void *where, unsigned long val)
+{
+ u32 *value = where + 2;
+ const unsigned long start = ((unsigned long) where) + 2;
+ const unsigned long end = start + sizeof(*value);
+
+ *value = val;
+
+ flush_icache_range(start, end);
+}
+
+#define runtime_const_shift_right_32(val, sym) ({ \
+ u32 __tmp; \
+ asm_inline("1:\t" \
+ "moveq #12, %0\n\t" \
+ "lsr.l %0, %1\n\t" \
+ ".pushsection runtime_shift_" #sym ",\"a\"\n\t" \
+ ".long 1b - .\n\t" \
+ ".popsection" \
+ : "=&d" (__tmp), "+d" (val)); \
+ val; })
+
+#define MOVEQ_DATA GENMASK(7, 0)
+static inline void __runtime_fixup_shift(void *where, unsigned long val)
+{
+ u16 *insn = where;
+ const unsigned long start = (unsigned long) where;
+ const unsigned long end = start + sizeof(*insn);
+
+ FIELD_MODIFY(MOVEQ_DATA, insn, val);
+
+ flush_icache_range(start, end);
+}
+
+#define runtime_const_init(type, sym) do { \
+ extern s32 __start_runtime_##type##_##sym[]; \
+ extern s32 __stop_runtime_##type##_##sym[]; \
+ runtime_const_fixup(__runtime_fixup_##type, \
+ (unsigned long)(sym), \
+ __start_runtime_##type##_##sym, \
+ __stop_runtime_##type##_##sym); \
+} while (0)
+
+static inline void runtime_const_fixup(void (*fn)(void *, unsigned long),
+ unsigned long val, s32 *start, s32 *end)
+{
+ while (start < end) {
+ fn(*start + (void *)start, val);
+ start++;
+ }
+}
+
+#endif
--
2.51.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] m68k: implement runtime consts
2025-11-27 0:05 [PATCH] m68k: implement runtime consts Daniel Palmer
@ 2025-11-27 1:59 ` kernel test robot
2025-11-27 10:13 ` Daniel Palmer
0 siblings, 1 reply; 7+ messages in thread
From: kernel test robot @ 2025-11-27 1:59 UTC (permalink / raw)
To: Daniel Palmer, geert
Cc: oe-kbuild-all, kas, mingo, seanjc, bp, linux-m68k, linux-kernel,
Daniel Palmer
Hi Daniel,
kernel test robot noticed the following build warnings:
[auto build test WARNING on geert-m68k/for-next]
[also build test WARNING on geert-m68k/for-linus linus/master v6.18-rc7 next-20251126]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Daniel-Palmer/m68k-implement-runtime-consts/20251127-080652
base: https://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git for-next
patch link: https://lore.kernel.org/r/20251127000505.2117956-1-daniel%40thingy.jp
patch subject: [PATCH] m68k: implement runtime consts
config: m68k-allnoconfig (https://download.01.org/0day-ci/archive/20251127/202511270956.hzGiPzdZ-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251127/202511270956.hzGiPzdZ-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511270956.hzGiPzdZ-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from fs/dcache.c:38:
arch/m68k/include/asm/runtime-const.h: In function '__runtime_fixup_ptr':
>> arch/m68k/include/asm/runtime-const.h:28:29: warning: unused variable 'end' [-Wunused-variable]
28 | const unsigned long end = start + sizeof(*value);
| ^~~
arch/m68k/include/asm/runtime-const.h: In function '__runtime_fixup_shift':
arch/m68k/include/asm/runtime-const.h:51:29: warning: unused variable 'end' [-Wunused-variable]
51 | const unsigned long end = start + sizeof(*insn);
| ^~~
vim +/end +28 arch/m68k/include/asm/runtime-const.h
13
14 #define runtime_const_ptr(sym) ({ \
15 typeof(sym) __ret; \
16 asm_inline("1:\t" \
17 "mov.l #0xcafef00d,%0\n\t" \
18 ".pushsection runtime_ptr_" #sym ",\"a\"\n\t" \
19 ".long 1b - .\n\t" \
20 ".popsection" \
21 : "=a" (__ret)); \
22 __ret; })
23
24 static inline void __runtime_fixup_ptr(void *where, unsigned long val)
25 {
26 u32 *value = where + 2;
27 const unsigned long start = ((unsigned long) where) + 2;
> 28 const unsigned long end = start + sizeof(*value);
29
30 *value = val;
31
32 flush_icache_range(start, end);
33 }
34
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] m68k: implement runtime consts
2025-11-27 1:59 ` kernel test robot
@ 2025-11-27 10:13 ` Daniel Palmer
2025-11-27 10:22 ` Geert Uytterhoeven
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Palmer @ 2025-11-27 10:13 UTC (permalink / raw)
To: kernel test robot
Cc: geert, oe-kbuild-all, kas, mingo, seanjc, bp, linux-m68k,
linux-kernel
Hi test robot,
On Thu, 27 Nov 2025 at 10:59, kernel test robot <lkp@intel.com> wrote:
> All warnings (new ones prefixed by >>):
>
> In file included from fs/dcache.c:38:
> arch/m68k/include/asm/runtime-const.h: In function '__runtime_fixup_ptr':
> >> arch/m68k/include/asm/runtime-const.h:28:29: warning: unused variable 'end' [-Wunused-variable]
> 28 | const unsigned long end = start + sizeof(*value);
> | ^~~
> arch/m68k/include/asm/runtime-const.h: In function '__runtime_fixup_shift':
> arch/m68k/include/asm/runtime-const.h:51:29: warning: unused variable 'end' [-Wunused-variable]
> 51 | const unsigned long end = start + sizeof(*insn);
> | ^~~
I guess this is because allnoconfig results in CONFIG_MMU=n and that means
that the nommu defines for cache operations are used and those look like:
#define flush_icache_range(start, len) __flush_icache_all()
And the arguments getting passed aren't used. Also noticed that it's
start and len
there not start and end like everywhere else seems to be...
I guess the flush_icache_range macro needs to be tweaked to not
trigger the unused
warning but I'm not sure how right now.
Cheers,
Daniel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] m68k: implement runtime consts
2025-11-27 10:13 ` Daniel Palmer
@ 2025-11-27 10:22 ` Geert Uytterhoeven
2025-12-03 8:06 ` Daniel Palmer
0 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2025-11-27 10:22 UTC (permalink / raw)
To: Daniel Palmer
Cc: kernel test robot, oe-kbuild-all, kas, mingo, seanjc, bp,
linux-m68k, linux-kernel
Hi Daniel,
On Thu, 27 Nov 2025 at 11:13, Daniel Palmer <daniel@thingy.jp> wrote:
> On Thu, 27 Nov 2025 at 10:59, kernel test robot <lkp@intel.com> wrote:
> > All warnings (new ones prefixed by >>):
> >
> > In file included from fs/dcache.c:38:
> > arch/m68k/include/asm/runtime-const.h: In function '__runtime_fixup_ptr':
> > >> arch/m68k/include/asm/runtime-const.h:28:29: warning: unused variable 'end' [-Wunused-variable]
> > 28 | const unsigned long end = start + sizeof(*value);
> > | ^~~
> > arch/m68k/include/asm/runtime-const.h: In function '__runtime_fixup_shift':
> > arch/m68k/include/asm/runtime-const.h:51:29: warning: unused variable 'end' [-Wunused-variable]
> > 51 | const unsigned long end = start + sizeof(*insn);
> > | ^~~
>
> I guess this is because allnoconfig results in CONFIG_MMU=n and that means
> that the nommu defines for cache operations are used and those look like:
> #define flush_icache_range(start, len) __flush_icache_all()
>
> And the arguments getting passed aren't used. Also noticed that it's
> start and len
> there not start and end like everywhere else seems to be...
>
> I guess the flush_icache_range macro needs to be tweaked to not
> trigger the unused
> warning but I'm not sure how right now.
Replacing the macros by static inline functions should fix that.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] m68k: implement runtime consts
2025-11-27 10:22 ` Geert Uytterhoeven
@ 2025-12-03 8:06 ` Daniel Palmer
2025-12-04 9:57 ` Jean-Michel Hautbois
0 siblings, 1 reply; 7+ messages in thread
From: Daniel Palmer @ 2025-12-03 8:06 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: kernel test robot, oe-kbuild-all, kas, mingo, seanjc, bp,
linux-m68k, linux-kernel
Hi Geert,
On Thu, 27 Nov 2025 at 19:22, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Replacing the macros by static inline functions should fix that.
Thanks. I've done that now. Any comments on the rest of this?
I have a few things like implementing jump labels, a vDSO to get
around the sys_get_thread_area() bottleneck to come after this.
Cheers,
Daniel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] m68k: implement runtime consts
2025-12-03 8:06 ` Daniel Palmer
@ 2025-12-04 9:57 ` Jean-Michel Hautbois
2025-12-05 9:23 ` Daniel Palmer
0 siblings, 1 reply; 7+ messages in thread
From: Jean-Michel Hautbois @ 2025-12-04 9:57 UTC (permalink / raw)
To: Daniel Palmer
Cc: Geert Uytterhoeven, kernel test robot, oe-kbuild-all, kas, mingo,
seanjc, bp, linux-m68k, linux-kernel
On Wed, Dec 03, 2025 at 05:06:52PM +0900, Daniel Palmer wrote:
> Hi Geert,
>
> On Thu, 27 Nov 2025 at 19:22, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> >
> > Replacing the macros by static inline functions should fix that.
>
> Thanks. I've done that now. Any comments on the rest of this?
> I have a few things like implementing jump labels, a vDSO to get
> around the sys_get_thread_area() bottleneck to come after this.
Hi Daniel,
It would be great to have vDSO at least for sys_get_thread_area() ! I
implemented something, but if you already have it, please, submit a RFC
I will test on coldfire !
Thanks,
JM
> Cheers,
>
> Daniel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] m68k: implement runtime consts
2025-12-04 9:57 ` Jean-Michel Hautbois
@ 2025-12-05 9:23 ` Daniel Palmer
0 siblings, 0 replies; 7+ messages in thread
From: Daniel Palmer @ 2025-12-05 9:23 UTC (permalink / raw)
To: Jean-Michel Hautbois
Cc: Geert Uytterhoeven, kernel test robot, oe-kbuild-all, kas, mingo,
seanjc, bp, linux-m68k, linux-kernel
Hi Jean-Michel,
On Thu, 4 Dec 2025 at 18:57, Jean-Michel Hautbois
<jeanmichel.hautbois@yoseli.org> wrote:
> It would be great to have vDSO at least for sys_get_thread_area() ! I
> implemented something, but if you already have it, please, submit a RFC
> I will test on coldfire !
I will try to clean it up and send it. A very untidy version along
with other stuff I'm messing with is on github[0].
You will also need a patch for your libc to use it. So far I have
worked out how to get glibc[1] and uclibng[2] to work but I haven't
managed to get musl to work yet[3].
Note that I have no idea if it's safe to do what it's doing. ;)
0 - https://github.com/fifteenhex/linux/tree/m68kvdso-20251201
1 - https://github.com/fifteenhex/glibc/tree/m68kgetthreadarea-20251203
2 - https://github.com/fifteenhex/uclibc-ng/tree/m68k-vdsogetthreadarea
3 - https://github.com/fifteenhex/musl/tree/m68kgetthreadarea-20251203
Cheers,
Daniel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-12-06 14:49 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-27 0:05 [PATCH] m68k: implement runtime consts Daniel Palmer
2025-11-27 1:59 ` kernel test robot
2025-11-27 10:13 ` Daniel Palmer
2025-11-27 10:22 ` Geert Uytterhoeven
2025-12-03 8:06 ` Daniel Palmer
2025-12-04 9:57 ` Jean-Michel Hautbois
2025-12-05 9:23 ` Daniel Palmer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox