arch/s390/include/asm/spinlock.h

Source file repositories/reference/linux-study-clean/arch/s390/include/asm/spinlock.h

File Facts

System
Linux kernel
Corpus path
arch/s390/include/asm/spinlock.h
Extension
.h
Size
3922 bytes
Lines
169
Domain
Architecture Layer
Bucket
arch/s390
Inferred role
Architecture Layer: implementation source
Status
source implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

#ifndef __ASM_SPINLOCK_H
#define __ASM_SPINLOCK_H

#include <linux/smp.h>
#include <asm/atomic_ops.h>
#include <asm/barrier.h>
#include <asm/processor.h>
#include <asm/alternative.h>

static __always_inline unsigned int spinlock_lockval(void)
{
	unsigned long lc_lockval;
	unsigned int lockval;

	BUILD_BUG_ON(sizeof_field(struct lowcore, spinlock_lockval) != sizeof(lockval));
	lc_lockval = offsetof(struct lowcore, spinlock_lockval);
	asm_inline(
		ALTERNATIVE("   ly      %[lockval],%[offzero](%%r0)\n",
			    "   ly      %[lockval],%[offalt](%%r0)\n",
			    ALT_FEATURE(MFEATURE_LOWCORE))
		: [lockval] "=d" (lockval)
		: [offzero] "i" (lc_lockval),
		  [offalt] "i" (lc_lockval + LOWCORE_ALT_ADDRESS),
		  "m" (((struct lowcore *)0)->spinlock_lockval));
	return lockval;
}

extern int spin_retry;

bool arch_vcpu_is_preempted(int cpu);

#define vcpu_is_preempted arch_vcpu_is_preempted

/*
 * Simple spin lock operations.  There are two variants, one clears IRQ's
 * on the local processor, one does not.
 *
 * We make no fairness assumptions. They have a cost.
 *
 * (the type definitions are in asm/spinlock_types.h)
 */

void arch_spin_relax(arch_spinlock_t *lock);
#define arch_spin_relax	arch_spin_relax

void arch_spin_lock_wait(arch_spinlock_t *);
int arch_spin_trylock_retry(arch_spinlock_t *);
void arch_spin_lock_setup(int cpu);

static inline u32 arch_spin_lockval(int cpu)
{
	return cpu + 1;
}

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

static inline int arch_spin_is_locked(arch_spinlock_t *lp)
{
	return READ_ONCE(lp->lock) != 0;
}

static inline int arch_spin_trylock_once(arch_spinlock_t *lp)
{
	int old = 0;

	barrier();
	return likely(arch_try_cmpxchg(&lp->lock, &old, spinlock_lockval()));
}

static inline void arch_spin_lock(arch_spinlock_t *lp)
{
	if (!arch_spin_trylock_once(lp))
		arch_spin_lock_wait(lp);
}

static inline int arch_spin_trylock(arch_spinlock_t *lp)
{
	if (!arch_spin_trylock_once(lp))
		return arch_spin_trylock_retry(lp);
	return 1;
}

static inline void arch_spin_unlock(arch_spinlock_t *lp)
{
	typecheck(int, lp->lock);
	kcsan_release();
	asm_inline volatile(

Annotation

Implementation Notes