microblaze: Define SMP safe operations
cover microblaze: Define SMP safe operations
Hi,
This is follow up series on the top of cleanup series available here.
https://lkml.org/lkml/2020/2/12/215
There are two things together.
1. Changes in cpuinfo structure in patches 1 and 2
2. Defining SMP safe operations instead of IRQ disabling
Microblaze has 32bit exclusive load/store instructions which should be used instead of irq enable/disable. For more information take a look at
https://www.xilinx.com/support/documentation/sw_manuals/xilinx2019_2/ug984-vivado-microblaze-ref.pdf
starting from page 25.
Thanks,
Michal
Michal Simek (1):
microblaze: timer: Don't use cpu timer setting
Stefan Asserhall (5):
microblaze: Make cpuinfo structure SMP aware
microblaze: Define SMP safe bit operations
microblaze: Add SMP implementation of xchg and cmpxchg
microblaze: Remove disabling IRQ while pte_update() run
microblaze: Implement architecture spinlock
Stefan Asserhall load and store (1):
microblaze: Do atomic operations by using exclusive ops
arch/microblaze/include/asm/Kbuild | 1 - arch/microblaze/include/asm/atomic.h | 265 ++++++++++++++++++- arch/microblaze/include/asm/bitops.h | 189 +++++++++++++ arch/microblaze/include/asm/cmpxchg.h | 87 ++++++ arch/microblaze/include/asm/cpuinfo.h | 2 +- arch/microblaze/include/asm/pgtable.h | 19 +- arch/microblaze/include/asm/spinlock.h | 240 +++++++++++++++++ arch/microblaze/include/asm/spinlock_types.h | 25 ++ arch/microblaze/kernel/cpu/cache.c | 154 ++++++----- arch/microblaze/kernel/cpu/cpuinfo.c | 38 ++- arch/microblaze/kernel/cpu/mb.c | 207 ++++++++------- arch/microblaze/kernel/timer.c | 2 +- arch/microblaze/mm/consistent.c | 8 +- 13 files changed, 1040 insertions(+), 197 deletions(-) create mode 100644 arch/microblaze/include/asm/bitops.h create mode 100644 arch/microblaze/include/asm/spinlock.h create mode 100644 arch/microblaze/include/asm/spinlock_types.h
Signature · 1 line
2.25.0
PATCH 2/7 microblaze: Make cpuinfo structure SMP aware
From: Stefan Asserhall <[email protected]>
Define struct cpuinfo per cpu and also fill it based on information from DT or PVR.
---
arch/microblaze/include/asm/cpuinfo.h | 2 +- arch/microblaze/kernel/cpu/cache.c | 154 +++++++++++-------- arch/microblaze/kernel/cpu/cpuinfo.c | 38 +++-- arch/microblaze/kernel/cpu/mb.c | 207 ++++++++++++++------------ arch/microblaze/mm/consistent.c | 8 +- 5 files changed, 236 insertions(+), 173 deletions(-)
arch/microblaze/include/asm/cpuinfo.h +1 -1
@@ -84,7 +84,7 @@ struct cpuinfo {u32 pvr_user2; }; -extern struct cpuinfo cpuinfo; +DECLARE_PER_CPU(struct cpuinfo, cpu_info);/* fwd declarations of the various CPUinfo populators */ void setup_cpuinfo (void );
arch/microblaze/kernel/cpu/cache.c +91 -63
415 lines not on this page · raw message
arch/microblaze/kernel/cpu/cpuinfo.c +25 -13
@@ -1,4 +1,5 @@/* +* Copyright (C) 2013-2020 Xilinx, Inc. All rights reserved. * Copyright (C) 2007-2009 Michal Simek <[email protected]> * Copyright (C) 2007-2009 PetaLogix * Copyright (C) 2007 John Williams <[email protected]>
@@ -10,6 +11,7 @@#include <linux/clk.h> #include <linux/init.h> +#include <linux/smp.h> #include <asm/cpuinfo.h> #include <asm/pvr.h>
@@ -56,7 +58,7 @@ const struct cpu_ver_key cpu_ver_lookup[] = { };/* -* FIXME Not sure if the actual key is defined by Xilinx in the PVR +* The actual key is defined by Xilinx in the PVR */ const struct family_string_key family_string_lookup[] = { {"virtex2" ,0x4 },
@@ -85,37 +87,40 @@ const struct family_string_key family_string_lookup[] = { {NULL, 0}, }; -struct cpuinfo cpuinfo; -static struct device_node *cpu; +DEFINE_PER_CPU(struct cpuinfo, cpu_info);void __init setup_cpuinfo (void ) { - cpu =of_get_cpu_node (0 ,NULL ); +struct device_node *cpu; +unsigned int cpu_id =smp_processor_id (); +struct cpuinfo *cpuinfo =per_cpu_ptr (&cpu_info, cpu_id); + + cpu =of_get_cpu_node (cpu_id,NULL );if (!cpu)pr_err ("You don't have cpu or are missing cpu reg property!!!\n" ); -pr_info ("%s: initialising\n" , __func__); +pr_info ("%s: initialising cpu %d\n" , __func__, cpu_id);switch (cpu_has_pvr ()) {case 0 :pr_warn ("%s: No PVR support. Using static CPU info from FDT\n" , __func__); -set_cpuinfo_static (&cpuinfo, cpu); +set_cpuinfo_static (cpuinfo, cpu);break ;/* FIXME I found weird behavior with MB 7.00.a/b 7.10.a * please do not use FULL PVR with MMU */ case 1 :pr_info ("%s: Using full CPU PVR support\n" , __func__); -set_cpuinfo_static (&cpuinfo, cpu); -set_cpuinfo_pvr_full (&cpuinfo, cpu); +set_cpuinfo_static (cpuinfo, cpu); +set_cpuinfo_pvr_full (cpuinfo, cpu);break ;default :pr_warn ("%s: Unsupported PVR setting\n" , __func__); -set_cpuinfo_static (&cpuinfo, cpu); +set_cpuinfo_static (cpuinfo, cpu); } -if (cpuinfo.mmu_privins) +if (cpuinfo->mmu_privins)pr_warn ("%s: Stream instructions enabled" " - USERSPACE CAN LOCK THIS KERNEL!\n" , __func__);
@@ -125,17 +130,24 @@ void __init setup_cpuinfo(void)void __init setup_cpuinfo_clk (void ) {struct clk *clk; +struct device_node *cpu; +unsigned int cpu_id =smp_processor_id (); +struct cpuinfo *cpuinfo =per_cpu_ptr (&cpu_info, cpu_id); + + cpu =of_get_cpu_node (cpu_id,NULL ); +if (!cpu) +pr_err ("You don't have cpu or are missing cpu reg property!!!\n" ); clk =of_clk_get (cpu,0 );if (IS_ERR (clk)) {pr_err ("ERROR: CPU CCF input clock not found\n" );/* take timebase-frequency from DTS */ - cpuinfo.cpu_clock_freq =fcpu (cpu,"timebase-frequency" ); + cpuinfo->cpu_clock_freq =fcpu (cpu,"timebase-frequency" ); }else { - cpuinfo.cpu_clock_freq =clk_get_rate (clk); + cpuinfo->cpu_clock_freq =clk_get_rate (clk); } -if (!cpuinfo.cpu_clock_freq) { +if (!cpuinfo->cpu_clock_freq) {pr_err ("ERROR: CPU clock frequency not setup\n" );BUG (); }
arch/microblaze/kernel/cpu/mb.c +113 -94
236 lines not on this page · raw message
arch/microblaze/mm/consistent.c +6 -2
@@ -35,7 +35,7 @@ void arch_dma_prep_coherent(struct page *page, size_t size)* I have to use dcache values because I can't relate on ram size: */ #ifdef CONFIG_XILINX_UNCACHED_SHADOW -#define UNCACHED_SHADOW_MASK (cpuinfo.dcache_high - cpuinfo.dcache_base + 1) +#define UNCACHED_SHADOW_MASK (cpuinfo->dcache_high - cpuinfo->dcache_base + 1)#else #define UNCACHED_SHADOW_MASK 0#endif /* CONFIG_XILINX_UNCACHED_SHADOW */
@@ -43,9 +43,11 @@ void arch_dma_prep_coherent(struct page *page, size_t size)void *uncached_kernel_address (void *ptr) {unsigned long addr = (unsigned long )ptr; +unsigned int cpu =smp_processor_id (); +struct cpuinfo *cpuinfo =per_cpu_ptr (&cpu_info, cpu); addr |=UNCACHED_SHADOW_MASK ; -if (addr > cpuinfo.dcache_base && addr < cpuinfo.dcache_high) +if (addr > cpuinfo->dcache_base && addr < cpuinfo->dcache_high)pr_warn ("ERROR: Your cache coherent area is CACHED!!!\n" );return (void *)addr; }
@@ -53,6 +55,8 @@ void *uncached_kernel_address(void *ptr)void *cached_kernel_address (void *ptr) {unsigned long addr = (unsigned long )ptr; +unsigned int cpu =smp_processor_id (); +struct cpuinfo *cpuinfo =per_cpu_ptr (&cpu_info, cpu);return (void *)(addr & ~UNCACHED_SHADOW_MASK ); }
Signature · 1 line
2.25.0
PATCH 1/7 microblaze: timer: Don't use cpu timer setting
In reply to Michal SimekThere is no longer valid that timer runs at the same frequency as cpu. That's why don't use cpuinfo setup for timer clock base. Better is to error out instead of using incorrect frequency.
---
arch/microblaze/kernel/timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/microblaze/kernel/timer.c +1 -1
@@ -304,7 +304,7 @@ static int __init xilinx_timer_init(struct device_node *timer)if (!timer_clock_freq) {pr_err ("ERROR: Using CPU clock frequency\n" ); - timer_clock_freq = cpuinfo.cpu_clock_freq; +return -EINVAL ; } freq_div_hz = timer_clock_freq /HZ ;
Signature · 1 line
2.25.0
PATCH 3/7 microblaze: Define SMP safe bit operations
In reply to Michal SimekFrom: Stefan Asserhall <[email protected]>
For SMP based system there is a need to have proper bit operations. Microblaze is using exclusive load and store instructions.
---
arch/microblaze/include/asm/Kbuild | 1 - arch/microblaze/include/asm/bitops.h | 189 +++++++++++++++++++++++++++ 2 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 arch/microblaze/include/asm/bitops.h
arch/microblaze/include/asm/Kbuild +0 -1
@@ -1,6 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 generated-y += syscall_table.h -generic-y += bitops.h generic-y += bug.h generic-y += bugs.h generic-y += compat.h
arch/microblaze/include/asm/bitops.h new file +189 -0
189 lines not on this page · raw message
Signature · 1 line
2.25.0
PATCH 4/7 microblaze: Add SMP implementation of xchg and cmpxchg
In reply to Michal SimekFrom: Stefan Asserhall <[email protected]>
Microblaze support only 32bit loads and stores that's why only 4 byte operations are supported by SMP.
---
arch/microblaze/include/asm/cmpxchg.h | 87 +++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)
arch/microblaze/include/asm/cmpxchg.h +87 -0
@@ -4,6 +4,93 @@#ifndef CONFIG_SMP # include <asm-generic/cmpxchg.h> +#else + +extern void __xchg_called_with_bad_pointer (void ); + +static inline unsigned long __xchg_u32 (volatile void *p,unsigned long val) +{ +unsigned long prev, temp; + + __asm__ __volatile__ ( +/* load conditional address in %3 to %0 */ +"1: lwx %0, %3, r0;\n" +/* attempt store of new value */ +" swx %4, %3, r0;\n" +/* checking msr carry flag */ +" addic %1, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %1, 1b;\n" +/* Outputs: result value */ + :"=&r" (prev),"=&r" (temp),"+m" (*(volatile unsigned int *)p) +/* Inputs: counter address */ + :"r" (p),"r" (val) + :"cc" ,"memory" + ); + +return prev; +} + +static inline unsigned long __xchg (unsigned long x,volatile void *ptr, +int size) +{ +if (size ==4 ) +return __xchg_u32 (ptr, x); + +__xchg_called_with_bad_pointer (); +return x; +} + +#define xchg (ptr, x) ({ \ + ((__typeof__(*(ptr))) \ + __xchg((unsigned long)(x), (ptr), sizeof(*(ptr)))); \ +}) + +static inline unsigned long __cmpxchg_u32 (volatile unsigned int *p, +unsigned long old,unsigned long new) +{ +int result, tmp; + + __asm__ __volatile__ ( +/* load conditional address in %3 to %0 */ +"1: lwx %0, %3, r0;\n" +/* compare loaded value with old value */ +" cmp %2, %0, %4;\n" +/* not equal to old value, write old value */ +" bnei %2, 2f;\n" +/* attempt store of new value*/ +" swx %5, %3, r0;\n" +/* checking msr carry flag */ +" addic %2, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %2, 1b;\n" +"2: " +/* Outputs : result value */ + :"=&r" (result),"+m" (*p),"=&r" (tmp) +/* Inputs : counter address, old, new */ + :"r" (p),"r" (old),"r" (new),"r" (&tmp) + :"cc" ,"memory" + ); + +return result; +} + +static inline unsigned long __cmpxchg (volatile void *ptr,unsigned long old, +unsigned long new,unsigned int size) +{ +if (size ==4 ) +return __cmpxchg_u32 (ptr, old, new); + +__xchg_called_with_bad_pointer (); +return old; +} + +#define cmpxchg (ptr, o, n) ({ \ + ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \ + (unsigned long)(n), sizeof(*(ptr)))); \ +}) + +#endif #endif /* _ASM_MICROBLAZE_CMPXCHG_H */
Signature · 1 line
2.25.0
PATCH 5/7 microblaze: Remove disabling IRQ while pte_update() run
In reply to Michal SimekFrom: Stefan Asserhall <[email protected]>
There is no need to disable local IRQ for pte update. Use exclusive load/store instruction for it.
---
arch/microblaze/include/asm/pgtable.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
arch/microblaze/include/asm/pgtable.h +9 -10
@@ -372,20 +372,19 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)static inline unsigned long pte_update (pte_t *p,unsigned long clr,unsigned long set) { -unsigned long flags, old, tmp; - -raw_local_irq_save (flags); - - __asm__ __volatile__("lw %0, %2, r0 \n" -"andn %1, %0, %3 \n" -"or %1, %1, %4 \n" -"sw %1, %2, r0 \n" +unsigned long old, tmp; + + __asm__ __volatile__( +"1: lwx %0, %2, r0;\n" +" andn %1, %0, %3;\n" +" or %1, %1, %4;\n" +" swx %1, %2, r0;\n" +" addic %1, r0, 0;\n" +" bnei %1, 1b;\n" :"=&r" (old),"=&r" (tmp) :"r" ((unsigned long )(p +1 ) -4 ),"r" (clr),"r" (set) :"cc" ); -raw_local_irq_restore (flags); -return old; }
Signature · 1 line
2.25.0
PATCH 6/7 microblaze: Implement architecture spinlock
In reply to Michal SimekFrom: Stefan Asserhall <[email protected]>
Using exclusive loads/stores to implement spinlocks which can be used on SMP systems.
---
arch/microblaze/include/asm/spinlock.h | 240 +++++++++++++++++++ arch/microblaze/include/asm/spinlock_types.h | 25 ++ 2 files changed, 265 insertions(+) create mode 100644 arch/microblaze/include/asm/spinlock.h create mode 100644 arch/microblaze/include/asm/spinlock_types.h
arch/microblaze/include/asm/spinlock.h new file +240 -0
@@ -0,0 +1,240 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2013-2020 Xilinx, Inc. +*/ + +#ifndef _ASM_MICROBLAZE_SPINLOCK_H +#define _ASM_MICROBLAZE_SPINLOCK_H + +/* +* Unlocked value: 0 +* Locked value: 1 +*/ +#define arch_spin_is_locked (x) (READ_ONCE((x)->lock) != 0) + +static inline void arch_spin_lock (arch_spinlock_t *lock) +{ +unsigned long tmp; + + __asm__ __volatile__ ( +/* load conditional address in %1 to %0 */ +"1: lwx %0, %1, r0;\n" +/* not zero? try again */ +" bnei %0, 1b;\n" +/* increment lock by 1 */ +" addi %0, r0, 1;\n" +/* attempt store */ +" swx %0, %1, r0;\n" +/* checking msr carry flag */ +" addic %0, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %0, 1b;\n" +/* Outputs: temp variable for load result */ + :"=&r" (tmp) +/* Inputs: lock address */ + :"r" (&lock->lock) + :"cc" ,"memory" + ); +} + +static inline int arch_spin_trylock (arch_spinlock_t *lock) +{ +unsigned long prev, tmp; + + __asm__ __volatile__ ( +/* load conditional address in %2 to %0 */ +"1: lwx %0, %2, r0;\n" +/* not zero? clear reservation */ +" bneid %0, 2f;\n" +/* increment lock by one if lwx was sucessful */ +" addi %1, r0, 1;\n" +/* attempt store */ +" swx %1, %2, r0;\n" +/* checking msr carry flag */ +" addic %1, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %1, 1b;\n" +"2:" +/* Outputs: temp variable for load result */ + :"=&r" (prev),"=&r" (tmp) +/* Inputs: lock address */ + :"r" (&lock->lock) + :"cc" ,"memory" + ); + +return (prev ==0 ); +} + +static inline void arch_spin_unlock (arch_spinlock_t *lock) +{ +unsigned long tmp; + + __asm__ __volatile__ ( +/* load conditional address in %1 to %0 */ +"1: lwx %0, %1, r0;\n" +/* clear */ +" swx r0, %1, r0;\n" +/* checking msr carry flag */ +" addic %0, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %0, 1b;\n" +/* Outputs: temp variable for load result */ + :"=&r" (tmp) +/* Inputs: lock address */ + :"r" (&lock->lock) + :"cc" ,"memory" + ); +} + +/* RWLOCKS */ +static inline void arch_write_lock (arch_rwlock_t *rw) +{ +unsigned long tmp; + + __asm__ __volatile__ ( +/* load conditional address in %1 to %0 */ +"1: lwx %0, %1, r0;\n" +/* not zero? try again */ +" bneid %0, 1b;\n" +/* set tmp to -1 */ +" addi %0, r0, -1;\n" +/* attempt store */ +" swx %0, %1, r0;\n" +/* checking msr carry flag */ +" addic %0, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %0, 1b;\n" +/* Outputs: temp variable for load result */ + :"=&r" (tmp) +/* Inputs: lock address */ + :"r" (&rw->lock) + :"cc" ,"memory" + ); +} + +static inline int arch_write_trylock (arch_rwlock_t *rw) +{ +unsigned long prev, tmp; + + __asm__ __volatile__ ( +/* load conditional address in %1 to tmp */ +"1: lwx %0, %2, r0;\n" +/* not zero? abort */ +" bneid %0, 2f;\n" +/* set tmp to -1 */ +" addi %1, r0, -1;\n" +/* attempt store */ +" swx %1, %2, r0;\n" +/* checking msr carry flag */ +" addic %1, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %1, 1b;\n" +"2:" +/* Outputs: temp variable for load result */ + :"=&r" (prev),"=&r" (tmp) +/* Inputs: lock address */ + :"r" (&rw->lock) + :"cc" ,"memory" + ); +/* prev value should be zero and MSR should be clear */ +return (prev ==0 ); +} + +static inline void arch_write_unlock (arch_rwlock_t *rw) +{ +unsigned long tmp; + + __asm__ __volatile__ ( +/* load conditional address in %1 to %0 */ +"1: lwx %0, %1, r0;\n" +/* clear */ +" swx r0, %1, r0;\n" +/* checking msr carry flag */ +" addic %0, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %0, 1b;\n" +/* Outputs: temp variable for load result */ + :"=&r" (tmp) +/* Inputs: lock address */ + :"r" (&rw->lock) + :"cc" ,"memory" + ); +} + +/* Read locks */ +static inline void arch_read_lock (arch_rwlock_t *rw) +{ +unsigned long tmp; + + __asm__ __volatile__ ( +/* load conditional address in %1 to %0 */ +"1: lwx %0, %1, r0;\n" +/* < 0 (WRITE LOCK active) try again */ +" bltid %0, 1b;\n" +/* increment lock by 1 if lwx was sucessful */ +" addi %0, %0, 1;\n" +/* attempt store */ +" swx %0, %1, r0;\n" +/* checking msr carry flag */ +" addic %0, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %0, 1b;\n" +/* Outputs: temp variable for load result */ + :"=&r" (tmp) +/* Inputs: lock address */ + :"r" (&rw->lock) + :"cc" ,"memory" + ); +} + +static inline void arch_read_unlock (arch_rwlock_t *rw) +{ +unsigned long tmp; + + __asm__ __volatile__ ( +/* load conditional address in %1 to tmp */ +"1: lwx %0, %1, r0;\n" +/* tmp = tmp - 1 */ +" addi %0, %0, -1;\n" +/* attempt store */ +" swx %0, %1, r0;\n" +/* checking msr carry flag */ +" addic %0, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %0, 1b;\n" +/* Outputs: temp variable for load result */ + :"=&r" (tmp) +/* Inputs: lock address */ + :"r" (&rw->lock) + :"cc" ,"memory" + ); +} + +static inline int arch_read_trylock (arch_rwlock_t *rw) +{ +unsigned long prev, tmp; + + __asm__ __volatile__ ( +/* load conditional address in %1 to %0 */ +"1: lwx %0, %2, r0;\n" +/* < 0 bail, release lock */ +" bltid %0, 2f;\n" +/* increment lock by 1 */ +" addi %1, %0, 1;\n" +/* attempt store */ +" swx %1, %2, r0;\n" +/* checking msr carry flag */ +" addic %1, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %1, 1b;\n" +"2:" +/* Outputs: temp variable for load result */ + :"=&r" (prev),"=&r" (tmp) +/* Inputs: lock address */ + :"r" (&rw->lock) + :"cc" ,"memory" + ); +return (prev >=0 ); +} + +#endif /* _ASM_MICROBLAZE_SPINLOCK_H */
arch/microblaze/include/asm/spinlock_types.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2013-2020 Xilinx, Inc. +*/ + +#ifndef __ASM_MICROBLAZE_SPINLOCK_TYPES_H +#define __ASM_MICROBLAZE_SPINLOCK_TYPES_H + +#ifndef __LINUX_SPINLOCK_TYPES_H +# error "please don't include this file directly" +#endif + +typedef struct { +volatile unsigned int lock; +}arch_spinlock_t ; + +#define __ARCH_SPIN_LOCK_UNLOCKED { 0 } + +typedef struct { +volatile signed int lock; +}arch_rwlock_t ; + +#define __ARCH_RW_LOCK_UNLOCKED { 0 } + +#endif
Signature · 1 line
2.25.0
PATCH 7/7 microblaze: Do atomic operations by using exclusive ops
In reply to Michal SimekFrom: Stefan Asserhall load and store <[email protected]>
Implement SMP aware atomic operations.
---
arch/microblaze/include/asm/atomic.h | 265 +++++++++++++++++++++++++-- 1 file changed, 253 insertions(+), 12 deletions(-)
arch/microblaze/include/asm/atomic.h +253 -12
@@ -1,28 +1,269 @@/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2013-2020 Xilinx, Inc. +*/ +#ifndef _ASM_MICROBLAZE_ATOMIC_H#define _ASM_MICROBLAZE_ATOMIC_H +#include <linux/types.h> #include <asm/cmpxchg.h> -#include <asm-generic/atomic.h> -#include <asm-generic/atomic64.h> + +#define ATOMIC_INIT (i) { (i) } + +#define atomic_read (v) READ_ONCE((v)->counter) + +static inline void atomic_set (atomic_t *v,int i) +{ +int result, tmp; + + __asm__ __volatile__ ( +/* load conditional address in %2 to %0 */ +"1: lwx %0, %2, r0;\n" +/* attempt store */ +" swx %3, %2, r0;\n" +/* checking msr carry flag */ +" addic %1, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %1, 1b;\n" +/* Outputs: result value */ + :"=&r" (result),"=&r" (tmp) +/* Inputs: counter address */ + :"r" (&v->counter),"r" (i) + :"cc" ,"memory" + ); +} +#define atomic_set atomic_set + +/* Atomically perform op with v->counter and i, return result */ +#define ATOMIC_OP_RETURN (op, asm) \ +static inline int atomic_##op##_return_relaxed(int i, atomic_t *v) \ +{ \ + int result, tmp; \ + \ + __asm__ __volatile__ ( \ +/* load conditional address in %2 to %0 */ \ + "1: lwx %0, %2, r0;\n" \ + /* perform operation and save it to result */ \ + #asm " %0, %3, %0;\n" \ + /* attempt store */ \ + " swx %0, %2, r0;\n" \ + /* checking msr carry flag */ \ + " addic %1, r0, 0;\n" \ + /* store failed (MSR[C] set)? try again */ \ + " bnei %1, 1b;\n" \ + /* Outputs: result value */ \ + : "=&r" (result), "=&r" (tmp) \ + /* Inputs: counter address */ \ + : "r" (&v->counter), "r" (i) \ + : "cc", "memory" \ + ); \ + \ + return result; \ +} \ + \ +static inline void atomic_##op(int i, atomic_t *v) \ +{ \ + atomic_##op##_return_relaxed(i, v); \ +} + +/* Atomically perform op with v->counter and i, return orig v->counter */ +#define ATOMIC_FETCH_OP_RELAXED(op, asm) \ +static inline int atomic_fetch_##op##_relaxed(int i, atomic_t *v) \ +{ \ + int old, tmp; \ + \ + __asm__ __volatile__ ( \ +/* load conditional address in %2 to %0 */ \ +"1: lwx %0, %2, r0;\n" \ +/* perform operation and save it to tmp */ \ + #asm " %1, %3, %0;\n" \ +/* attempt store */ \ +" swx %1, %2, r0;\n" \ +/* checking msr carry flag */ \ +" addic %1, r0, 0;\n" \ +/* store failed (MSR[C] set)? try again */ \ +" bnei %1, 1b;\n" \ +/* Outputs: old value */ \ + : "=&r" (old), "=&r" (tmp) \ +/* Inputs: counter address */ \ +: " r" (&v->counter), " r" (i) \ + : "cc", "memory" \ + ); \ + \ + return old; \ +} + +#define ATOMIC_OPS(op, asm) \ + ATOMIC_FETCH_OP_RELAXED(op, asm) \ + ATOMIC_OP_RETURN(op, asm) + +ATOMIC_OPS(and, and) +#define atomic_and atomic_and +#define atomic_and_return_relaxed atomic_and_return_relaxed +#define atomic_fetch_and_relaxed atomic_fetch_and_relaxed + +ATOMIC_OPS(add, add) +#define atomic_add atomic_add +#define atomic_add_return_relaxed atomic_add_return_relaxed +#define atomic_fetch_add_relaxed atomic_fetch_add_relaxed + +ATOMIC_OPS(xor, xor) +#define atomic_xor atomic_xor +#define atomic_xor_return_relaxed atomic_xor_return_relaxed +#define atomic_fetch_xor_relaxed atomic_fetch_xor_relaxed + +ATOMIC_OPS(or, or) +#define atomic_or atomic_or +#define atomic_or_return_relaxed atomic_or_return_relaxed +#define atomic_fetch_or_relaxed atomic_fetch_or_relaxed + +ATOMIC_OPS(sub, rsub) +#define atomic_sub atomic_sub +#define atomic_sub_return_relaxed atomic_sub_return_relaxed +#define atomic_fetch_sub_relaxed atomic_fetch_sub_relaxed + +static inline int atomic_inc_return_relaxed(atomic_t *v) +{ +int result, tmp; + + __asm__ __volatile__ ( +/* load conditional address in %2 to %0 */ +"1: lwx %0, %2, r0;\n" +/* increment counter by 1 */ +" addi %0, %0, 1;\n" +/* attempt store */ +" swx %0, %2, r0;\n" +/* checking msr carry flag */ +" addic %1, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %1, 1b;\n" +/* Outputs: result value */ + :"=&r" (result),"=&r" (tmp) +/* Inputs: counter address */ + :"r" (&v->counter) + :"cc" ,"memory" + ); + +return result; +} +#define atomic_inc_return_relaxed atomic_inc_return_relaxed + +#define atomic_inc_and_test (v) (atomic_inc_return(v) == 0) + +static inline int atomic_dec_return (atomic_t *v) +{ +int result, tmp; + + __asm__ __volatile__ ( +/* load conditional address in %2 to %0 */ +"1: lwx %0, %2, r0;\n" +/* increment counter by -1 */ +" addi %0, %0, -1;\n" +/* attempt store */ +" swx %0, %2, r0;\n" +/* checking msr carry flag */ +" addic %1, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %1, 1b;\n" +/* Outputs: result value */ + :"=&r" (result),"=&r" (tmp) +/* Inputs: counter address */ + :"r" (&v->counter) + :"cc" ,"memory" + ); + +return result; +} +#define atomic_dec_return atomic_dec_return + +static inline void atomic_dec (atomic_t *v) +{ +atomic_dec_return (v); +} +#define atomic_dec atomic_dec + +#define atomic_sub_and_test (a, v) (atomic_sub_return((a), (v)) == 0) +#define atomic_dec_and_test (v) (atomic_dec_return((v)) == 0) + +#define atomic_cmpxchg (v, o, n) (cmpxchg(&((v)->counter), (o), (n))) +#define atomic_xchg (v, new) (xchg(&((v)->counter), new)) + +/** +* atomic_add_unless - add unless the number is a given value +* @v: pointer of type atomic_t +* @a: the amount to add to v... +* @u: ...unless v is equal to u. +* +* Atomically adds @a to @v, so long as it was not @u. +* Returns the old value of @v. +*/ +static inline int __atomic_add_unless (atomic_t *v,int a,int u) +{ +int result, tmp; + + __asm__ __volatile__ ( +/* load conditional address in %2 to %0 */ +"1: lwx %0, %2, r0;\n" +/* compare loaded value with old value*/ +" cmp %1, %0, %3;\n" +/* equal to u, don't increment */ +" beqid %1, 2f;\n" +/* increment counter by i */ +" add %1, %0, %4;\n" +/* attempt store of new value*/ +" swx %1, %2, r0;\n" +/* checking msr carry flag */ +" addic %1, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %1, 1b;\n" +"2:" +/* Outputs: result value */ + :"=&r" (result),"=&r" (tmp) +/* Inputs: counter address, old, new */ + :"r" (&v->counter),"r" (u),"r" (a) + :"cc" ,"memory" + ); + +return result; +}/* * Atomically test *v and decrement if it is greater than 0. -* The function returns the old value of *v minus 1. +* The function returns the old value of *v minus 1, even if +* the atomic variable, v, was not decremented. */ static inline int atomic_dec_if_positive (atomic_t *v) { -unsigned long flags; -int res; +int result, tmp; -local_irq_save (flags); - res = v->counter -1 ; -if (res >=0 ) - v->counter = res; -local_irq_restore (flags); + __asm__ __volatile__ ( +/* load conditional address in %2 to %0 */ +"1: lwx %0, %2, r0;\n" +/* decrement counter by 1*/ +" addi %0, %0, -1;\n" +/* if < 0 abort (*v was <= 0)*/ +" blti %0, 2f;\n" +/* attempt store of new value*/ +" swx %0, %2, r0;\n" +/* checking msr carry flag */ +" addic %1, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %1, 1b;\n" +"2: " +/* Outputs: result value */ + :"=&r" (result),"=&r" (tmp) +/* Inputs: counter address */ + :"r" (&v->counter) + :"cc" ,"memory" + ); -return res; +return result; } -#define atomic_dec_if_positive atomic_dec_if_positive +#define atomic_dec_if_positive atomic_dec_if_positive + +#define atomic_add_negative (i, v) (atomic_add_return(i, v) < 0) + +#include <asm-generic/atomic64.h> #endif /* _ASM_MICROBLAZE_ATOMIC_H */
Signature · 1 line
2.25.0
Peter Zijlstra
maintainerRe: [PATCH 6/7] microblaze: Implement architecture spinlock
In reply to Michal SimekQuoted 49 lines · Michal Simek
From: Stefan Asserhall <[email protected]>
Using exclusive loads/stores to implement spinlocks which can be used on SMP systems.
Signed-off-by Stefan Asserhall <[email protected]>Signed-off-by Michal Simek <[email protected]>---
arch/microblaze/include/asm/spinlock.h | 240 +++++++++++++++++++ arch/microblaze/include/asm/spinlock_types.h | 25 ++ 2 files changed, 265 insertions(+) create mode 100644 arch/microblaze/include/asm/spinlock.h create mode 100644 arch/microblaze/include/asm/spinlock_types.harch/microblaze/include/asm/spinlock.h new file +28
-0@@ -0,0 +1,240 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2013-2020 Xilinx, Inc. +*/ + +#ifndef _ASM_MICROBLAZE_SPINLOCK_H +#define _ASM_MICROBLAZE_SPINLOCK_H + +/* +* Unlocked value: 0 +* Locked value: 1 +*/ +#define arch_spin_is_locked (x) (READ_ONCE((x)->lock) != 0) + +static inline void arch_spin_lock (arch_spinlock_t *lock) +{ +unsigned long tmp; + + __asm__ __volatile__ ( +/* load conditional address in %1 to %0 */ +"1: lwx %0, %1, r0;\n" +/* not zero? try again */ +" bnei %0, 1b;\n" +/* increment lock by 1 */ +" addi %0, r0, 1;\n" +/* attempt store */ +" swx %0, %1, r0;\n" + /* checking msr carry flag */
arch/microblaze/include/asm/spinlock.h line 38
Quoted 10 lines
arch/microblaze/include/asm/spinlock.h new file +10
-0+" addic %0, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %0, 1b;\n" +/* Outputs: temp variable for load result */ + : "=&r" (tmp) +/* Inputs: lock address */ + : "r" (&lock->lock) + : "cc", "memory" + ); +}
That's a test-and-set spinlock if I read it correctly. Why? that's the worst possible spinlock implementation possible.
Peter Zijlstra
maintainerRe: [PATCH 3/7] microblaze: Define SMP safe bit operations
In reply to Michal Simekarch/microblaze/include/asm/bitops.h line 50
Quoted 13 lines · Michal Simek
From: Stefan Asserhall <[email protected]>
For SMP based system there is a need to have proper bit operations. Microblaze is using exclusive load and store instructions.
Signed-off-by Stefan Asserhall <[email protected]>Signed-off-by Michal Simek <[email protected]>arch/microblaze/include/asm/bitops.h new file +5
-0+/* +* clear_bit doesn't imply a memory barrier +*/ +#define smp_mb__before_clear_bit () smp_mb() +#define smp_mb__after_clear_bit () smp_mb()
These macros no longer exist.
Also, might I draw your attention to:
include/asm-generic/bitops/atomic.h
This being a ll/sc arch, I'm thinking that if you do your atomic_t implementation right, the generic atomic bitop code should be near optimal.
Peter Zijlstra
maintainerRe: [PATCH 7/7] microblaze: Do atomic operations by using exclusive ops
In reply to Michal SimekQuoted 44 lines · Michal Simek
From: Stefan Asserhall load and store <[email protected]>
Implement SMP aware atomic operations.
Signed-off-by Stefan Asserhall <[email protected]>Signed-off-by Michal Simek <[email protected]>---
arch/microblaze/include/asm/atomic.h | 265 +++++++++++++++++++++++++-- 1 file changed, 253 insertions(+), 12 deletions(-)arch/microblaze/include/asm/atomic.h +21
-2@@ -1,28 +1,269 @@/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2013-2020 Xilinx, Inc. +*/ +#ifndef _ASM_MICROBLAZE_ATOMIC_H#define _ASM_MICROBLAZE_ATOMIC_H +#include <linux/types.h> #include <asm/cmpxchg.h> -#include <asm-generic/atomic.h> -#include <asm-generic/atomic64.h> + +#define ATOMIC_INIT (i) { (i) } + +#define atomic_read (v) READ_ONCE((v)->counter) + +static inline void atomic_set (atomic_t *v,int i) +{ +int result, tmp; + + __asm__ __volatile__ ( +/* load conditional address in %2 to %0 */ +"1: lwx %0, %2, r0;\n" +/* attempt store */ +" swx %3, %2, r0;\n" +/* checking msr carry flag */ + " addic %1, r0, 0;\n"
arch/microblaze/include/asm/atomic.h line 36
Quoted 10 lines
arch/microblaze/include/asm/atomic.h +10
-0+/* store failed (MSR[C] set)? try again */ +" bnei %1, 1b;\n" +/* Outputs: result value */ + : "=&r" (result), "=&r" (tmp) +/* Inputs: counter address */ + : "r" (&v->counter), "r" (i) + : "cc", "memory" + ); +} +#define atomic_set atomic_set
Uuuuhh.. *what* ?!?
Are you telling me your LL/SC implementation is so bugger that atomic_set() being a WRITE_ONCE() does not in fact work?
Peter Zijlstra
maintainerQuoted 14 lines · Michal Simek
Microblaze has 32bit exclusive load/store instructions which should be used instead of irq enable/disable. For more information take a look at
https://www.xilinx.com/support/documentation/sw_manuals/xilinx2019_2/ug984-vivado-microblaze-ref.pdf
starting from page 25.arch/microblaze/include/asm/Kbuild | 1 - arch/microblaze/include/asm/atomic.h | 265 ++++++++++++++++++- arch/microblaze/include/asm/bitops.h | 189 +++++++++++++ arch/microblaze/include/asm/cmpxchg.h | 87 ++++++ arch/microblaze/include/asm/cpuinfo.h | 2 +- arch/microblaze/include/asm/pgtable.h | 19 +- arch/microblaze/include/asm/spinlock.h | 240 +++++++++++++++++ arch/microblaze/include/asm/spinlock_types.h | 25 ++ arch/microblaze/kernel/cpu/cache.c | 154 ++++++-----
Quoted 8 lines
arch/microblaze/kernel/cpu/cpuinfo.c | 38 ++- arch/microblaze/kernel/cpu/mb.c | 207 ++++++++------- arch/microblaze/kernel/timer.c | 2 +- arch/microblaze/mm/consistent.c | 8 +- 13 files changed, 1040 insertions(+), 197 deletions(-) create mode 100644 arch/microblaze/include/asm/bitops.h create mode 100644 arch/microblaze/include/asm/spinlock.h create mode 100644 arch/microblaze/include/asm/spinlock_types.h
I'm missing asm/barrier.h
Also that PDF (thanks for that!), seems light on memory ordering details.
Your comment:
+/*
+ * clear_bit doesn't imply a memory barrier
+ */
worries me, because that would imply your ll/sc does not impose order, but then you also don't have any explicit barriers in your locking primitives or atomics where required.
In the PDF I only find MBAR; is that what smp_mb() ends up being?
Peter Zijlstra
maintainerQuoted 36 lines · Peter Zijlstra
Quoted 14 lines · Michal Simek
Microblaze has 32bit exclusive load/store instructions which should be used instead of irq enable/disable. For more information take a look at
https://www.xilinx.com/support/documentation/sw_manuals/xilinx2019_2/ug984-vivado-microblaze-ref.pdf
starting from page 25.arch/microblaze/include/asm/Kbuild | 1 - arch/microblaze/include/asm/atomic.h | 265 ++++++++++++++++++- arch/microblaze/include/asm/bitops.h | 189 +++++++++++++ arch/microblaze/include/asm/cmpxchg.h | 87 ++++++ arch/microblaze/include/asm/cpuinfo.h | 2 +- arch/microblaze/include/asm/pgtable.h | 19 +- arch/microblaze/include/asm/spinlock.h | 240 +++++++++++++++++ arch/microblaze/include/asm/spinlock_types.h | 25 ++ arch/microblaze/kernel/cpu/cache.c | 154 ++++++-----Quoted 8 lines
arch/microblaze/kernel/cpu/cpuinfo.c | 38 ++- arch/microblaze/kernel/cpu/mb.c | 207 ++++++++------- arch/microblaze/kernel/timer.c | 2 +- arch/microblaze/mm/consistent.c | 8 +- 13 files changed, 1040 insertions(+), 197 deletions(-) create mode 100644 arch/microblaze/include/asm/bitops.h create mode 100644 arch/microblaze/include/asm/spinlock.h create mode 100644 arch/microblaze/include/asm/spinlock_types.hI'm missing
asm/barrier.hAlso that PDF (thanks for that!), seems light on memory ordering details.
Your comment:
+/*
+ *clear_bitdoesn't imply a memory barrier
+ */
Quoted 5 lines
worries me, because that would imply your ll/sc does not impose order, but then you also don't have any explicit barriers in your locking primitives or atomics where required.
In the PDF I only find MBAR; is that what
smp_mb()ends up being?
Bah, I'm sure I did patches at some point that made asm-generic/barrier.h #error if you didn't define at least one memory barrier on CONFIG_SMP, but it seems that all got lost somewhere.
Re: [PATCH 2/7] microblaze: Make cpuinfo structure SMP aware
In reply to Michal SimekReview
Quoted 4 lines · Michal Simek
static void
__flush_icache_range_msr_irq(unsigned long start, unsigned long end){(quoted diff) +2
-0+ unsigned int cpu = smp_processor_id(); + struct cpuinfo *cpuinfo = per_cpu_ptr(&cpu_info, cpu);
I think all the instances of smp_processor_id()/per_cpu_ptr() should be replaced with get_cpu_ptr()/put_cpu_ptr(). Same for per_cpu_var()
-> get_cpu_var().
Arnd
Quoted 25 lines · Peter Zijlstra
Quoted 14 lines · Michal Simek
Microblaze has 32bit exclusive load/store instructions which should be used instead of irq enable/disable. For more information take a look at
https://www.xilinx.com/support/documentation/sw_manuals/xilinx2019_2/ug984-vivado-microblaze-ref.pdf
starting from page 25.arch/microblaze/include/asm/Kbuild | 1 - arch/microblaze/include/asm/atomic.h | 265 ++++++++++++++++++- arch/microblaze/include/asm/bitops.h | 189 +++++++++++++ arch/microblaze/include/asm/cmpxchg.h | 87 ++++++ arch/microblaze/include/asm/cpuinfo.h | 2 +- arch/microblaze/include/asm/pgtable.h | 19 +- arch/microblaze/include/asm/spinlock.h | 240 +++++++++++++++++ arch/microblaze/include/asm/spinlock_types.h | 25 ++ arch/microblaze/kernel/cpu/cache.c | 154 ++++++-----Quoted 8 lines
arch/microblaze/kernel/cpu/cpuinfo.c | 38 ++- arch/microblaze/kernel/cpu/mb.c | 207 ++++++++------- arch/microblaze/kernel/timer.c | 2 +- arch/microblaze/mm/consistent.c | 8 +- 13 files changed, 1040 insertions(+), 197 deletions(-) create mode 100644 arch/microblaze/include/asm/bitops.h create mode 100644 arch/microblaze/include/asm/spinlock.h create mode 100644 arch/microblaze/include/asm/spinlock_types.h
Quoted 1 line
I'm missing
asm/barrier.h
This has been sent in previous patchset. Link was in this email.
Quoted 6 lines
Also that PDF (thanks for that!), seems light on memory ordering details.
Your comment:
Quoted 7 lines
+/*
+ *clear_bitdoesn't imply a memory barrier
+ */worries me, because that would imply your ll/sc does not impose order, but then you also don't have any explicit barriers in your locking primitives or atomics where required.
I think this is just comment which shouldn't be there. clear_bit is calling clear_bits which is using exclusive load/store instruction which should impose ordering.
Quoted 2 lines
In the PDF I only find MBAR; is that what
smp_mb()ends up being?
yes. All barriers should end up with mbar.
Stefan: Please correct me if I am wrong?
Thanks,
Michal
Re: [PATCH 6/7] microblaze: Implement architecture spinlock
In reply to Peter ZijlstraQuoted 55 lines · Peter Zijlstra
Quoted 54 lines · Michal Simek
From: Stefan Asserhall <[email protected]>
Using exclusive loads/stores to implement spinlocks which can be used on SMP systems.
Signed-off-by Stefan Asserhall <[email protected]>Signed-off-by Michal Simek <[email protected]>---
arch/microblaze/include/asm/spinlock.h | 240 +++++++++++++++++++ arch/microblaze/include/asm/spinlock_types.h | 25 ++ 2 files changed, 265 insertions(+) create mode 100644 arch/microblaze/include/asm/spinlock.h create mode 100644 arch/microblaze/include/asm/spinlock_types.harch/microblaze/include/asm/spinlock.h new file +33
-0@@ -0,0 +1,240 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2013-2020 Xilinx, Inc. +*/ + +#ifndef _ASM_MICROBLAZE_SPINLOCK_H +#define _ASM_MICROBLAZE_SPINLOCK_H + +/* +* Unlocked value: 0 +* Locked value: 1 +*/ +#define arch_spin_is_locked (x) (READ_ONCE((x)->lock) != 0) + +static inline void arch_spin_lock (arch_spinlock_t *lock) +{ +unsigned long tmp; + + __asm__ __volatile__ ( +/* load conditional address in %1 to %0 */ +"1: lwx %0, %1, r0;\n" +/* not zero? try again */ +" bnei %0, 1b;\n" +/* increment lock by 1 */ +" addi %0, r0, 1;\n" +/* attempt store */ +" swx %0, %1, r0;\n" +/* checking msr carry flag */ +" addic %0, r0, 0;\n" +/* store failed (MSR[C] set)? try again */ +" bnei %0, 1b;\n" +/* Outputs: temp variable for load result */ + : "=&r" (tmp)
Quoted 8 lines
arch/microblaze/include/asm/spinlock.h line 38
Quoted 5 lines
arch/microblaze/include/asm/spinlock.h new file +5
-0+/* Inputs: lock address */ + : "r" (&lock->lock) + : "cc", "memory" + ); +}That's a test-and-set spinlock if I read it correctly. Why? that's the worst possible spinlock implementation possible.
This was written by Stefan and it is aligned with recommended implementation. What other options do we have?
Thanks,
Michal
Peter Zijlstra
maintainerRe: [PATCH 6/7] microblaze: Implement architecture spinlock
Quoted 8 lines · Michal Simek
Quoted 3 lines · Peter Zijlstra
That's a test-and-set spinlock if I read it correctly. Why? that's the worst possible spinlock implementation possible.
This was written by Stefan and it is aligned with recommended implementation. What other options do we have?
A ticket lock should be simple enough; ARM has one you can borrow from.
The problem with TaS spinlocks is that they're unfair and exhibit horrible starvation issues.
Re: [PATCH 7/7] microblaze: Do atomic operations by using exclusive ops
In reply to Peter ZijlstraQuoted 58 lines · Peter Zijlstra
Quoted 44 lines · Michal Simek
From: Stefan Asserhall load and store <[email protected]>
Implement SMP aware atomic operations.
Signed-off-by Stefan Asserhall <[email protected]>Signed-off-by Michal Simek <[email protected]>---
arch/microblaze/include/asm/atomic.h | 265 +++++++++++++++++++++++++-- 1 file changed, 253 insertions(+), 12 deletions(-)arch/microblaze/include/asm/atomic.h +21
-2@@ -1,28 +1,269 @@/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2013-2020 Xilinx, Inc. +*/ +#ifndef _ASM_MICROBLAZE_ATOMIC_H#define _ASM_MICROBLAZE_ATOMIC_H +#include <linux/types.h> #include <asm/cmpxchg.h> -#include <asm-generic/atomic.h> -#include <asm-generic/atomic64.h> + +#define ATOMIC_INIT (i) { (i) } + +#define atomic_read (v) READ_ONCE((v)->counter) + +static inline void atomic_set (atomic_t *v,int i) +{ +int result, tmp; + + __asm__ __volatile__ ( +/* load conditional address in %2 to %0 */ +"1: lwx %0, %2, r0;\n" +/* attempt store */ +" swx %3, %2, r0;\n" +/* checking msr carry flag */ + " addic %1, r0, 0;\n"arch/microblaze/include/asm/atomic.h line 36
Quoted 10 lines
arch/microblaze/include/asm/atomic.h +10
-0+/* store failed (MSR[C] set)? try again */ +" bnei %1, 1b;\n" +/* Outputs: result value */ + : "=&r" (result), "=&r" (tmp) +/* Inputs: counter address */ + : "r" (&v->counter), "r" (i) + : "cc", "memory" + ); +} +#define atomic_set atomic_setUuuuhh.. *what* ?!?
Quoted 2 lines
Are you telling me your LL/SC implementation is so bugger that
atomic_set()being aWRITE_ONCE()does not in fact work?
Just keep in your mind that this code was written long time ago and there could be a lot of things/technique used at that time by IIRC powerpc and I hope that review process will fix these things and I really appreciation your comments.
Stefan is the right person to say if we really need to use exclusive loads/stores instructions or use what I see in include/linux/compiler.h.
Please correct me if I am wrong.WRITE_ONCE is __write_once_size which is normal write in C which I expect will be converted in asm to non exclusive writes. And barrier is called only for cases above 8bytes.
READ_ONCE is normal read follow by barrier all the time.
Also is there any testsuite I should run to verify all these atomics operations? That would really help but I haven't seen any tool (but also didn't try hard to find it out).
Thanks,
Michal
Peter Zijlstra
maintainerQuoted 26 lines · Michal Simek
Quoted 25 lines · Peter Zijlstra
Quoted 22 lines · Michal Simek
Microblaze has 32bit exclusive load/store instructions which should be used instead of irq enable/disable. For more information take a look at
https://www.xilinx.com/support/documentation/sw_manuals/xilinx2019_2/ug984-vivado-microblaze-ref.pdf
starting from page 25.arch/microblaze/include/asm/Kbuild | 1 - arch/microblaze/include/asm/atomic.h | 265 ++++++++++++++++++- arch/microblaze/include/asm/bitops.h | 189 +++++++++++++ arch/microblaze/include/asm/cmpxchg.h | 87 ++++++ arch/microblaze/include/asm/cpuinfo.h | 2 +- arch/microblaze/include/asm/pgtable.h | 19 +- arch/microblaze/include/asm/spinlock.h | 240 +++++++++++++++++ arch/microblaze/include/asm/spinlock_types.h | 25 ++ arch/microblaze/kernel/cpu/cache.c | 154 ++++++----- arch/microblaze/kernel/cpu/cpuinfo.c | 38 ++- arch/microblaze/kernel/cpu/mb.c | 207 ++++++++------- arch/microblaze/kernel/timer.c | 2 +- arch/microblaze/mm/consistent.c | 8 +- 13 files changed, 1040 insertions(+), 197 deletions(-) create mode 100644 arch/microblaze/include/asm/bitops.h create mode 100644 arch/microblaze/include/asm/spinlock.h create mode 100644 arch/microblaze/include/asm/spinlock_types.h
Quoted 3 lines
Quoted 1 line
I'm missing
asm/barrier.hThis has been sent in previous patchset. Link was in this email.
lkml.org link, please don't use them. The kernel.org links (example below) have the Message-Id in them, which allows me to search for them in my local storage without having to use a web browser.
You mean this one, right?
So the PDF says this is a completion barrier, needed for DMA. This is a very expensive option for smp_mb(), but if it is all you have and is required, then yes, that should do.
Quoted 35 lines · Peter Zijlstra
Quoted 26 lines · Michal Simek
Quoted 25 lines · Peter Zijlstra
Quoted 22 lines · Michal Simek
Microblaze has 32bit exclusive load/store instructions which should be used instead of irq enable/disable. For more information take a look at
https://www.xilinx.com/support/documentation/sw_manuals/xilinx2019_2/ug984-vivado-microblaze-ref.pdf
starting from page 25.arch/microblaze/include/asm/Kbuild | 1 - arch/microblaze/include/asm/atomic.h | 265 ++++++++++++++++++- arch/microblaze/include/asm/bitops.h | 189 +++++++++++++ arch/microblaze/include/asm/cmpxchg.h | 87 ++++++ arch/microblaze/include/asm/cpuinfo.h | 2 +- arch/microblaze/include/asm/pgtable.h | 19 +- arch/microblaze/include/asm/spinlock.h | 240 +++++++++++++++++ arch/microblaze/include/asm/spinlock_types.h | 25 ++ arch/microblaze/kernel/cpu/cache.c | 154 ++++++----- arch/microblaze/kernel/cpu/cpuinfo.c | 38 ++- arch/microblaze/kernel/cpu/mb.c | 207 ++++++++------- arch/microblaze/kernel/timer.c | 2 +- arch/microblaze/mm/consistent.c | 8 +- 13 files changed, 1040 insertions(+), 197 deletions(-) create mode 100644 arch/microblaze/include/asm/bitops.h create mode 100644 arch/microblaze/include/asm/spinlock.h create mode 100644 arch/microblaze/include/asm/spinlock_types.hQuoted 3 lines
Quoted 1 line
I'm missing
asm/barrier.hThis has been sent in previous patchset. Link was in this email.
lkml.org link, please don't use them. The kernel.org links (example below) have the Message-Id in them, which allows me to search for them in my local storage without having to use a web browser.
Quoted 7 lines
You mean this one, right?
So the PDF says this is a completion barrier, needed for DMA. This is a very expensive option for
smp_mb(), but if it is all you have and is required, then yes, that should do.
Yes that's the one.
Thanks,
Michal
Re: [PATCH 3/7] microblaze: Define SMP safe bit operations
In reply to Peter ZijlstraQuoted 9 lines · Peter Zijlstra
Quoted 7 lines · Michal Simek
From: Stefan Asserhall <[email protected]>
For SMP based system there is a need to have proper bit operations. Microblaze is using exclusive load and store instructions.
Signed-off-by Stefan Asserhall <[email protected]>Signed-off-by Michal Simek <[email protected]>
Quoted 7 lines
arch/microblaze/include/asm/bitops.h line 50
Quoted 5 lines
arch/microblaze/include/asm/bitops.h new file +5
-0+/* +* clear_bit doesn't imply a memory barrier +*/ +#define smp_mb__before_clear_bit () smp_mb() +#define smp_mb__after_clear_bit () smp_mb()These macros no longer exist.
ok. Easy to remove.
Quoted 9 lines
Also, might I draw your attention to:
include/asm-generic/bitops/atomic.hThis being a ll/sc arch, I'm thinking that if you do your
atomic_timplementation right, the generic atomic bitop code should be near optimal.
Based on my look it looks like that I can replace implementations in this file by sourcing which will be using atomic operations.
#include <asm-generic/bitops/atomic.h>
#include <asm-generic/bitops/lock.h>
Correct?
Would be good to run any testsuite to prove that all operations works as expected. Is there any testsuite I can use to confirm it?
Thanks,
Michal
Peter Zijlstra
maintainerRe: [PATCH 7/7] microblaze: Do atomic operations by using exclusive ops
In reply to Michal SimekQuoted 27 lines · Michal Simek
Quoted 26 lines · Peter Zijlstra
Quoted 11 lines · Michal Simek
arch/microblaze/include/asm/atomic.h +11
-0+static inline void atomic_set (atomic_t *v,int i) +{ +int result, tmp; + + __asm__ __volatile__ ( +/* load conditional address in %2 to %0 */ +"1: lwx %0, %2, r0;\n" +/* attempt store */ +" swx %3, %2, r0;\n" +/* checking msr carry flag */ + " addic %1, r0, 0;\n"arch/microblaze/include/asm/atomic.h line 36
Quoted 10 lines
arch/microblaze/include/asm/atomic.h +10
-0+/* store failed (MSR[C] set)? try again */ +" bnei %1, 1b;\n" +/* Outputs: result value */ + : "=&r" (result), "=&r" (tmp) +/* Inputs: counter address */ + : "r" (&v->counter), "r" (i) + : "cc", "memory" + ); +} +#define atomic_set atomic_setUuuuhh.. *what* ?!?
Quoted 7 lines
Quoted 2 lines
Are you telling me your LL/SC implementation is so bugger that
atomic_set()being aWRITE_ONCE()does not in fact work?Just keep in your mind that this code was written long time ago and there could be a lot of things/technique used at that time by IIRC powerpc and I hope that review process will fix these things and I really appreciation your comments.
I don't think I've ever seen Power do this, but I've not checked the git history.
Quoted 9 lines
Stefan is the right person to say if we really need to use exclusive loads/stores instructions or use what I see in
include/linux/compiler.h.Please correct me if I am wrong.
WRITE_ONCEis__write_once_sizewhich is normal write in C which I expect will be converted in asm to non exclusive writes. And barrier is called only for cases above 8bytes.
READ_ONCEis normal read follow by barrier all the time.
Right:
WRITE_ONCE() is something like:
*(volatile typeof(var)*)(&(var)) = val;
And should translate to just a regular store; the volatile just tells the C compiler it should not do funny things with it.
READ_ONCE() is something like:
val = *(volatile typeof(var)*)(&(var));
And should translate to just a regular load; the volatile again tells the compiler to not be funny about it.
No memory barriers what so ever, not even a compiler barrier as such.
The thing is, your bog standard LL/SC _SHOULD_ fail the SC if someone else does a regular store to the same variable. See the example in Documentation/atomic_t.txt.
That is, a competing SW/SWI should result in the interconnect responding with something other than EXOKAY, the SWX should fail and MSR[C] <- 1.
Quoted 3 lines
Also is there any testsuite I should run to verify all these atomics operations? That would really help but I haven't seen any tool (but also didn't try hard to find it out).
Will, Paul; can't this LKMM thing generate kernel modules to run? And do we have a 'nice' collection of litmus tests that cover atomic_t ?
The one in atomic_t.txt should cover this one at least.
RE: [PATCH 3/7] microblaze: Define SMP safe bit operations
In reply to Michal SimekQuoted 35 lines · Peter Zijlstra
Quoted 9 lines · Michal Simek
Quoted 7 lines
From: Stefan Asserhall <[email protected]>
For SMP based system there is a need to have proper bit operations. Microblaze is using exclusive load and store instructions.
Signed-off-by Stefan Asserhall <[email protected]>Signed-off-by Michal Simek <[email protected]>Quoted 6 lines
arch/microblaze/include/asm/bitops.h line 50
Quoted 4 lines
arch/microblaze/include/asm/bitops.h new file +4
-0+/* +* clear_bit doesn't imply a memory barrier */ +#define smp_mb__before_clear_bit () smp_mb() +#define smp_mb__after_clear_bit () smp_mb()These macros no longer exist.
ok. Easy to remove.
Quoted 9 lines
Also, might I draw your attention to:
include/asm-generic/bitops/atomic.hThis being a ll/sc arch, I'm thinking that if you do your
atomic_timplementation right, the generic atomic bitop code should be near optimal.Based on my look it looks like that I can replace implementations in this file by sourcing which will be using atomic operations.
#include <
asm-generic/bitops/atomic.h>
#include <asm-generic/bitops/lock.h>
Quoted 7 lines
Correct?
Would be good to run any testsuite to prove that all operations works as expected. Is there any testsuite I can use to confirm it?
Thanks,
Michal
The comment in the generic bitops.h says "You should recode these in the native assembly language, if at all possible". I don't think using the generic implementation will be as efficient as the current arch specific one.
My recommendation is to stick with the arch specific implementation.
Thanks,
Stefan
Peter Zijlstra
maintainerRe: [PATCH 3/7] microblaze: Define SMP safe bit operations
Quoted 3 lines · Stefan Asserhall
The comment in the generic
bitops.hsays "You should recode these in the native assembly language, if at all possible". I don't think using the generic implementation will be as efficient as the current arch specific one.
That is a very crusty old recommendation. Please look at the compiler generated code.
We've extended the atomic_t operations the past few years and Will wrote the generic atomic bitops for Arm64, we're looking to convert more LL/SC archs to them.
There is currently one known issue with it, but Will has a patch-set pending to solve that (IIRC that only matters if you have stack protector on).
Also see this thread:
https://lkml.kernel.org/r/[email protected]
And these patches:
Peter Zijlstra
maintainerRe: [PATCH 7/7] microblaze: Do atomic operations by using exclusive ops
In reply to Peter ZijlstraQuoted 6 lines · Peter Zijlstra
The thing is, your bog standard LL/SC _SHOULD_ fail the SC if someone else does a regular store to the same variable. See the example in
Documentation/atomic_t.txt.That is, a competing SW/SWI should result in the interconnect responding with something other than EXOKAY, the SWX should fail and MSR[C] <- 1.
The thing is; we have code that relies on this behaviour. There are a few crusty SMP archs that sorta-kinda limp along (mostly by disabling some of the code and praying the rest doesn't trigger too often), but we really should not allow more broken SMP archs.
RE: [PATCH 3/7] microblaze: Define SMP safe bit operations
In reply to Peter ZijlstraQuoted 15 lines · Stefan Asserhall
Quoted 3 lines
The comment in the generic
bitops.hsays "You should recode these in the native assembly language, if at all possible". I don't think using the generic implementation will be as efficient as the current arch specific one.That is a very crusty old recommendation. Please look at the compiler generated code.
We've extended the
atomic_toperations the past few years and Will wrote the generic atomic bitops for Arm64, we're looking to convert more LL/SC archs to them.There is currently one known issue with it, but Will has a patch-set pending to solve that (IIRC that only matters if you have stack protector on).
Quoted 7 lines
Also see this thread:
https://lkml.kernel.org/r/[email protected]
And these patches:
Thanks for the links. Sure, I agree that it is better to use the generic implementation if it is as efficient as the arch specific one, but I don't think we should assume that it is.
Michal, would it be possible to replace the arch specific code and check what we get?
Stefan
Will Deacon
maintainerRe: [PATCH 7/7] microblaze: Do atomic operations by using exclusive ops
In reply to Peter ZijlstraQuoted 6 lines · Peter Zijlstra
Quoted 4 lines · Peter Zijlstra
The thing is, your bog standard LL/SC _SHOULD_ fail the SC if someone else does a regular store to the same variable. See the example in
Documentation/atomic_t.txt.
Quoted 7 lines
Quoted 2 lines
That is, a competing SW/SWI should result in the interconnect responding with something other than EXOKAY, the SWX should fail and MSR[C] <- 1.
The thing is; we have code that relies on this behaviour. There are a few crusty SMP archs that sorta-kinda limp along (mostly by disabling some of the code and praying the rest doesn't trigger too often), but we really should not allow more broken SMP archs.
I did find this in the linked pdf:
| If the store [swx] is successful, the sequence of instructions from | the semaphore load to the semaphore store appear to be executed | atomically - no other device modified the semaphore location between | the read and the update.
which sounds like we're ok, although it could be better worded.
One part I haven't figured out is what happens if you take an interrupt between the lwx and the swx and whether you can end up succeeding thanks to somebody else's reservation. Also, the manual is silent about the interaction with TLB invalidation and just refers to "address" when talking about the reservation. What happens if a user thread triggers CoW while another is in the middle of a lwx/swx?
Will
RE: [PATCH 7/7] microblaze: Do atomic operations by using exclusive ops
Quoted 25 lines · Peter Zijlstra
Quoted 8 lines · Peter Zijlstra
Quoted 7 lines
The thing is, your bog standard LL/SC _SHOULD_ fail the SC if someone else does a regular store to the same variable. See the example in
Documentation/atomic_t.txt.That is, a competing SW/SWI should result in the interconnect responding with something other than EXOKAY, the SWX should fail and
MSR[C] <- 1.
Quoted 5 lines
The thing is; we have code that relies on this behaviour. There are a few crusty SMP archs that sorta-kinda limp along (mostly by disabling some of the code and praying the rest doesn't trigger too often), but we really should not allow more broken SMP archs.
I did find this in the linked pdf:
| If the store [swx] is successful, the sequence of instructions from | the semaphore load to the semaphore store appear to be executed | atomically - no other device modified the semaphore location between | the read and the update.which sounds like we're ok, although it could be better worded.
Quoted 8 lines
One part I haven't figured out is what happens if you take an interrupt between the lwx and the swx and whether you can end up succeeding thanks to somebody else's reservation. Also, the manual is silent about the interaction with TLB invalidation and just refers to "address" when talking about the reservation. What happens if a user thread triggers CoW while another is in the middle of a lwx/swx?
Will
The manual says "Reset, interrupts, exceptions, and breaks (including the BRK and BRKI instructions) all clear the reservation." In case of a TLB invalidation between lwx and swx, you will get a TLB miss exception when attempting the swx, and the reservation will be cleared due to the exception.
Stefan
Peter Zijlstra
maintainerRe: [PATCH 7/7] microblaze: Do atomic operations by using exclusive ops
In reply to Will DeaconQuoted 22 lines · Will Deacon
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Peter Zijlstra
The thing is, your bog standard LL/SC _SHOULD_ fail the SC if someone else does a regular store to the same variable. See the example in
Documentation/atomic_t.txt.Quoted 7 lines
Quoted 2 lines
That is, a competing SW/SWI should result in the interconnect responding with something other than EXOKAY, the SWX should fail and MSR[C] <- 1.
The thing is; we have code that relies on this behaviour. There are a few crusty SMP archs that sorta-kinda limp along (mostly by disabling some of the code and praying the rest doesn't trigger too often), but we really should not allow more broken SMP archs.
I did find this in the linked pdf:
| If the store [swx] is successful, the sequence of instructions from | the semaphore load to the semaphore store appear to be executed | atomically - no other device modified the semaphore location between | the read and the update.
Quoted 8 lines
which sounds like we're ok, although it could be better worded.
One part I haven't figured out is what happens if you take an interrupt between the lwx and the swx and whether you can end up succeeding thanks to somebody else's reservation. Also, the manual is silent about the interaction with TLB invalidation and just refers to "address" when talking about the reservation. What happens if a user thread triggers CoW while another is in the middle of a lwx/swx?
Page 79, Table 2-40 has the note:
"All of these events will clear the reservation bit, used together with the LWX and SWX instructions to implement mutual exclusion,..."
Will Deacon
maintainerRe: [PATCH 7/7] microblaze: Do atomic operations by using exclusive ops
In reply to Stefan AsserhallQuoted 32 lines · Stefan Asserhall
Quoted 32 lines · Peter Zijlstra
Quoted 8 lines · Peter Zijlstra
Quoted 7 lines
The thing is, your bog standard LL/SC _SHOULD_ fail the SC if someone else does a regular store to the same variable. See the example in
Documentation/atomic_t.txt.That is, a competing SW/SWI should result in the interconnect responding with something other than EXOKAY, the SWX should fail and
MSR[C] <- 1.
Quoted 5 lines
The thing is; we have code that relies on this behaviour. There are a few crusty SMP archs that sorta-kinda limp along (mostly by disabling some of the code and praying the rest doesn't trigger too often), but we really should not allow more broken SMP archs.
I did find this in the linked pdf:
| If the store [swx] is successful, the sequence of instructions from | the semaphore load to the semaphore store appear to be executed | atomically - no other device modified the semaphore location between | the read and the update.which sounds like we're ok, although it could be better worded.
One part I haven't figured out is what happens if you take an interrupt between the lwx and the swx and whether you can end up succeeding thanks to somebody else's reservation. Also, the manual is silent about the interaction with TLB invalidation and just refers to "address" when talking about the reservation. What happens if a user thread triggers CoW while another is in the middle of a lwx/swx?
Quoted 6 lines
Quoted 1 line
Will
The manual says "Reset, interrupts, exceptions, and breaks (including the BRK and BRKI instructions) all clear the reservation." In case of a TLB invalidation between lwx and swx, you will get a TLB miss exception when attempting the swx, and the reservation will be cleared due to the exception.
Perfect, then I think we're good to go!
Will
Re: [PATCH 7/7] microblaze: Do atomic operations by using exclusive ops
In reply to Peter ZijlstraOn Thu, Feb 13, 2020 at 09:58:49AM +0100, Peter Zijlstra wrote:
[...]
Quoted 6 lines
Quoted 4 lines
Also is there any testsuite I should run to verify all these atomics operations? That would really help but I haven't seen any tool (but also didn't try hard to find it out).
Will, Paul; can't this LKMM thing generate kernel modules to run? And do
The herd toolset does have something called klitmus:
"an experimental tool, similar to litmus7 that runs kernel memory model tests as kernel modules."
I think Andrea knows more about how to use it.
Quoted 2 lines
we have a 'nice' collection of litmus tests that cover
atomic_t?
There is a few in Paul's litmus repo:
https://github.com/paulmckrcu/litmus/tree/master/manual/atomic
Maybe a good start?
Regards,
Boqun
Quoted 1 line
The one in atomic_t.txt should cover this one at least.
Re: [PATCH 7/7] microblaze: Do atomic operations by using exclusive ops
(Forget to copy Andrea in the previous email)
Andrea, could you tell us more about how to use klitmus to generate test modules from litmus test?
Regards,
Boqun
Quoted 29 lines · Boqun Feng
On Thu, Feb 13, 2020 at 09:58:49AM +0100, Peter Zijlstra wrote:
[...]Quoted 6 lines
Quoted 4 lines
Also is there any testsuite I should run to verify all these atomics operations? That would really help but I haven't seen any tool (but also didn't try hard to find it out).
Will, Paul; can't this LKMM thing generate kernel modules to run? And do
The herd toolset does have something called klitmus:
"an experimental tool, similar to litmus7 that runs kernel memory model tests as kernel modules."
I think Andrea knows more about how to use it.
Quoted 2 lines
we have a 'nice' collection of litmus tests that cover
atomic_t?There is a few in Paul's litmus repo:
https://github.com/paulmckrcu/litmus/tree/master/manual/atomic
Maybe a good start?
Regards,
BoqunQuoted 1 line
The one in atomic_t.txt should cover this one at least.
Re: [PATCH 7/7] microblaze: Do atomic operations by using exclusive ops
Hi,
Quoted 4 lines · Boqun Feng
(Forget to copy Andrea in the previous email)
Andrea, could you tell us more about how to use klitmus to generate test modules from litmus test?
The basic usage is described in "tools/memory-model/README", cf., in particular, the section dedicated to klitmus7 and the "REQUIREMENTS" section. For example, given the test,
andrea@andrea:~$ cat atomicity.litmus C atomicity
{
atomic_t x = ATOMIC_INIT(0);
}P0(atomic_t *x)
{
int r0;
r0 = atomic_fetch_inc_relaxed(x);
}P1(atomic_t *x)
{
atomic_set(x, 2);
}exists (0:r0=0 /\ x=1)
You should be able to do:
$ mkdir mymodules $ klitmus7 -o mymodules atomicity.litmus $ cd mymodules ; make [...]
$ sudo sh run.sh Thu 13 Feb 2020 02:21:52 PM CET Compilation command: klitmus7 -o mymodules atomicity.litmus OPT= uname -r=5.3.0-29-generic
Test atomicity Allowed
Histogram (2 states)
1963399 :>0:r0=0; x=2;
2036601 :>0:r0=2; x=3;
No
Witnesses
Positive: 0, Negative: 4000000
Condition exists (0:r0=0 /\ x=1) is NOT validated
Hash=11bd2c90c4ca7a8acd9ca728a3d61d5f
Observation atomicity Never 0 4000000
Time atomicity 0.15
Thu 13 Feb 2020 02:21:52 PM CET
Where the "Positive: 0 Negative: 4000000" indicates that, during four million trials, the state specified in the test's "exists" clause was not reached/observed (as expected).
More information are available at:
http://diy.inria.fr/doc/litmus.html#klitmus
Thanks,
Andrea
Re: [PATCH 7/7] microblaze: Do atomic operations by using exclusive ops
Quoted 61 lines · Andrea Parri
Hi,
Quoted 4 lines · Boqun Feng
(Forget to copy Andrea in the previous email)
Andrea, could you tell us more about how to use klitmus to generate test modules from litmus test?
The basic usage is described in "
tools/memory-model/README", cf., in particular, the section dedicated to klitmus7 and the "REQUIREMENTS" section. For example, given the test,andrea@andrea:~$ cat atomicity.litmus C atomicity{ atomic_t x = ATOMIC_INIT(0); }
P0(atomic_t *x){ int r0; r0 = atomic_fetch_inc_relaxed(x); }
P1(atomic_t *x){ atomic_set(x, 2); }exists (0:r0=0 /\ x=1)
You should be able to do:
$ mkdir mymodules $ klitmus7 -o mymodules atomicity.litmus $ cd mymodules ; make [...]$ sudo sh run.sh Thu 13 Feb 2020 02:21:52 PM CET Compilation command: klitmus7 -o mymodules atomicity.litmus OPT= uname -r=5.3.0-29-genericTest atomicity Allowed
Histogram (2 states)
1963399 :>0:r0=0; x=2;
2036601 :>0:r0=2; x=3;
NoWitnesses
Positive: 0, Negative: 4000000
Condition exists (0:r0=0 /\ x=1) is NOT validated
Hash=11bd2c90c4ca7a8acd9ca728a3d61d5f
Observation atomicity Never 0 4000000
Time atomicity 0.15Thu 13 Feb 2020 02:21:52 PM CET
Quoted 7 lines
Where the "Positive: 0 Negative: 4000000" indicates that, during four million trials, the state specified in the test's "exists" clause was not reached/observed (as expected).
More information are available at:
And I forgot to Cc: Luc and Jade, the main developers (and current maintainers) of the tool suite in question.
Thanks,
Andrea