mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
atomic: analyze further
This commit is contained in:
@@ -28,23 +28,26 @@ void threadMain() {
|
||||
#if LKMC_USERLAND_ATOMIC_X86_64_INC
|
||||
__asm__ __volatile__ (
|
||||
"incq %0;"
|
||||
: "+g" (global)
|
||||
: "+g" (global),
|
||||
"+g" (i) // to prevent loop unrolling, and make results more comparable across methods,
|
||||
// see also: https://cirosantilli.com/linux-kernel-module-cheat#infinite-busy-loop
|
||||
:
|
||||
:
|
||||
);
|
||||
#elif LKMC_USERLAND_ATOMIC_X86_64_LOCK_INC
|
||||
// https://cirosantilli.com/linux-kernel-module-cheat#x86-lock-prefix
|
||||
__asm__ __volatile__ (
|
||||
"lock;"
|
||||
"incq %0;"
|
||||
: "+m" (global)
|
||||
"lock incq %0;"
|
||||
: "+m" (global),
|
||||
"+g" (i) // to prevent loop unrolling
|
||||
:
|
||||
:
|
||||
);
|
||||
#elif LKMC_USERLAND_ATOMIC_AARCH64_ADD
|
||||
__asm__ __volatile__ (
|
||||
"add %0, %0, 1;"
|
||||
: "+r" (global)
|
||||
: "+r" (global),
|
||||
"+g" (i) // to prevent loop unrolling
|
||||
:
|
||||
:
|
||||
);
|
||||
@@ -52,18 +55,24 @@ void threadMain() {
|
||||
// https://cirosantilli.com/linux-kernel-module-cheat#arm-lse
|
||||
__asm__ __volatile__ (
|
||||
"ldadd %[inc], xzr, [%[addr]];"
|
||||
: "=m" (global)
|
||||
: "=m" (global),
|
||||
"+g" (i) // to prevent loop unrolling
|
||||
: [inc] "r" (1),
|
||||
[addr] "r" (&global)
|
||||
:
|
||||
);
|
||||
#else
|
||||
__asm__ __volatile__ (
|
||||
""
|
||||
: "+g" (i) // to prevent he loop from being optimized to a single add
|
||||
// see also: https://stackoverflow.com/questions/37786547/enforcing-statement-order-in-c/56865717#56865717
|
||||
: "g" (global)
|
||||
:
|
||||
);
|
||||
global++;
|
||||
#endif
|
||||
#if LKMC_USERLAND_ATOMIC_MUTEX
|
||||
mutex.unlock();
|
||||
#endif
|
||||
#if 0
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user