Skip to content

Commit

Permalink
Pull ticket-spinaphore into release branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Luck committed Oct 24, 2009
2 parents 48fade6 + 883a3ac commit 8add570
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions arch/ia64/mm/tlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,36 @@ wrap_mmu_context (struct mm_struct *mm)
* this primitive it can be moved up to a spinaphore.h header.
*/
struct spinaphore {
atomic_t cur;
unsigned long ticket;
unsigned long serve;
};

static inline void spinaphore_init(struct spinaphore *ss, int val)
{
atomic_set(&ss->cur, val);
ss->ticket = 0;
ss->serve = val;
}

static inline void down_spin(struct spinaphore *ss)
{
while (unlikely(!atomic_add_unless(&ss->cur, -1, 0)))
while (atomic_read(&ss->cur) == 0)
cpu_relax();
unsigned long t = ia64_fetchadd(1, &ss->ticket, acq), serve;

if (time_before(t, ss->serve))
return;

ia64_invala();

for (;;) {
asm volatile ("ld4.c.nc %0=[%1]" : "=r"(serve) : "r"(&ss->serve) : "memory");
if (time_before(t, serve))
return;
cpu_relax();
}
}

static inline void up_spin(struct spinaphore *ss)
{
atomic_add(1, &ss->cur);
ia64_fetchadd(1, &ss->serve, rel);
}

static struct spinaphore ptcg_sem;
Expand Down

0 comments on commit 8add570

Please sign in to comment.