cregit-Linux how code gets into the kernel

Release 4.15 arch/arm64/include/asm/spinlock.h

/*
 * Copyright (C) 2012 ARM Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef __ASM_SPINLOCK_H

#define __ASM_SPINLOCK_H

#include <asm/lse.h>
#include <asm/spinlock_types.h>
#include <asm/processor.h>

/*
 * Spinlock implementation.
 *
 * The memory barriers are implicit with the load-acquire and store-release
 * instructions.
 */


static inline void arch_spin_lock(arch_spinlock_t *lock) { unsigned int tmp; arch_spinlock_t lockval, newval; asm volatile( /* Atomically increment the next ticket. */ ARM64_LSE_ATOMIC_INSN( /* LL/SC */ " prfm pstl1strm, %3\n" "1: ldaxr %w0, %3\n" " add %w1, %w0, %w5\n" " stxr %w2, %w1, %3\n" " cbnz %w2, 1b\n", /* LSE atomics */ " mov %w2, %w5\n" " ldadda %w2, %w0, %3\n" __nops(3) ) /* Did we get the lock? */ " eor %w1, %w0, %w0, ror #16\n" " cbz %w1, 3f\n" /* * No: spin on the owner. Send a local event to avoid missing an * unlock before the exclusive load. */ " sevl\n" "2: wfe\n" " ldaxrh %w2, %4\n" " eor %w1, %w2, %w0, lsr #16\n" " cbnz %w1, 2b\n" /* We got the lock. Critical section starts here. */ "3:" : "=&r" (lockval), "=&r" (newval), "=&r" (tmp), "+Q" (*lock) : "Q" (lock->owner), "I" (1 << TICKET_SHIFT) : "memory"); }

Contributors

PersonTokensPropCommitsCommitProp
Will Deacon1851.43%375.00%
Catalin Marinas1748.57%125.00%
Total35100.00%4100.00%


static inline int arch_spin_trylock(arch_spinlock_t *lock) { unsigned int tmp; arch_spinlock_t lockval; asm volatile(ARM64_LSE_ATOMIC_INSN( /* LL/SC */ " prfm pstl1strm, %2\n" "1: ldaxr %w0, %2\n" " eor %w1, %w0, %w0, ror #16\n" " cbnz %w1, 2f\n" " add %w0, %w0, %3\n" " stxr %w1, %w0, %2\n" " cbnz %w1, 1b\n" "2:", /* LSE atomics */ " ldr %w0, %2\n" " eor %w1, %w0, %w0, ror #16\n" " cbnz %w1, 1f\n" " add %w1, %w0, %3\n" " casa %w0, %w1, %2\n" " and %w1, %w1, #0xffff\n" " eor %w1, %w1, %w0, lsr #16\n" "1:") : "=&r" (lockval), "=&r" (tmp), "+Q" (*lock) : "I" (1 << TICKET_SHIFT) : "memory"); return !tmp; }

Contributors

PersonTokensPropCommitsCommitProp
Catalin Marinas2172.41%133.33%
Will Deacon827.59%266.67%
Total29100.00%3100.00%


static inline void arch_spin_unlock(arch_spinlock_t *lock) { unsigned long tmp; asm volatile(ARM64_LSE_ATOMIC_INSN( /* LL/SC */ " ldrh %w1, %0\n" " add %w1, %w1, #1\n" " stlrh %w1, %0", /* LSE atomics */ " mov %w1, #1\n" " staddlh %w1, %0\n" __nops(1)) : "=Q" (lock->owner), "=&r" (tmp) : : "memory"); }

Contributors

PersonTokensPropCommitsCommitProp
Catalin Marinas1254.55%120.00%
Will Deacon1045.45%480.00%
Total22100.00%5100.00%


static inline int arch_spin_value_unlocked(arch_spinlock_t lock) { return lock.owner == lock.next; }

Contributors

PersonTokensPropCommitsCommitProp
Will Deacon19100.00%1100.00%
Total19100.00%1100.00%


static inline int arch_spin_is_locked(arch_spinlock_t *lock) { /* * Ensure prior spin_lock operations to other locks have completed * on this CPU before we test whether "lock" is locked. */ smp_mb(); /* ^^^ */ return !arch_spin_value_unlocked(READ_ONCE(*lock)); }

Contributors

PersonTokensPropCommitsCommitProp
Will Deacon2385.19%350.00%
Paul E. McKenney27.41%116.67%
Catalin Marinas13.70%116.67%
Christian Bornträger13.70%116.67%
Total27100.00%6100.00%


static inline int arch_spin_is_contended(arch_spinlock_t *lock) { arch_spinlock_t lockval = READ_ONCE(*lock); return (lockval.next - lockval.owner) > 1; }

Contributors

PersonTokensPropCommitsCommitProp
Will Deacon3296.97%150.00%
Christian Bornträger13.03%150.00%
Total33100.00%2100.00%

#define arch_spin_is_contended arch_spin_is_contended #include <asm/qrwlock.h> /* See include/linux/spinlock.h */ #define smp_mb__after_spinlock() smp_mb() #endif /* __ASM_SPINLOCK_H */

Overall Contributors

PersonTokensPropCommitsCommitProp
Will Deacon12563.13%866.67%
Catalin Marinas6733.84%18.33%
Christian Bornträger21.01%18.33%
Paul E. McKenney21.01%18.33%
Peter Zijlstra21.01%18.33%
Total198100.00%12100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.