return (ureg->psr & PsrMask) == PsrMusr;
}
-/*
- * atomic ops
- * make sure that we don't drag in the C library versions
- */
-int
-ainc(int *p)
-{
- int s, v;
-
- s = splhi();
- v = ++*p;
- splx(s);
- return v;
-}
-
-int
-adec(int *p)
-{
- int s, v;
-
- s = splhi();
- v = --*p;
- splx(s);
- return v;
-}
-
int
cas32(void* addr, u32int old, u32int new)
{
return (ureg->psr & PsrMask) == PsrMusr;
}
-/*
- * atomic ops
- * make sure that we don't drag in the C library versions
- */
-int
-ainc(int *p)
-{
- int s, v;
-
- s = splhi();
- v = ++*p;
- splx(s);
- return v;
-}
-
-int
-adec(int *p)
-{
- int s, v;
-
- s = splhi();
- v = --*p;
- splx(s);
- return v;
-}
-
int
cas32(void* addr, u32int old, u32int new)
{
struct Diag {
Cacheline c0;
Lock;
- long cnt;
- long sync;
+ Ref cnt;
+ Ref sync;
Cacheline c1;
};
}
static void
-synccpus(volatile long *cntp, int n)
+synccpus(Ref *cntp, int n)
{
- ainc(cntp);
- while (*cntp < n)
+ incref(cntp);
+ while (cntp->ref < n)
;
/* all cpus should now be here */
}
if(m->machno == 0)
iprint(" %d", pass);
for (i = 1000*1000; --i > 0; ) {
- ainc(&dp->cnt);
- adec(&dp->cnt);
+ incref(&dp->cnt);
+ incref(&dp->cnt);
}
synccpus(&dp->sync, navailcpus);
/* all cpus are now here */
ilock(dp);
- if(dp->cnt != 0)
- panic("cpu%d: diag: failed w count %ld", m->machno, dp->cnt);
+ if(dp->cnt.ref != 0)
+ panic("cpu%d: diag: failed w count %ld", m->machno, dp->cnt.ref);
iunlock(dp);
synccpus(&dp->sync, 2 * navailcpus);
/* all cpus are now here */
- adec(&dp->sync);
- adec(&dp->sync);
+ decref(&dp->sync);
+ decref(&dp->sync);
}
/*
iunlock(dp);
synccpus(&dp->sync, 2 * navailcpus);
- adec(&dp->sync);
- adec(&dp->sync);
+ decref(&dp->sync);
+ decref(&dp->sync);
/*
* cpus contend
*/
synccpus(&dp->sync, navailcpus);
- if(dp->sync < navailcpus || dp->sync >= 2 * navailcpus)
+ if(dp->sync.ref < navailcpus || dp->sync.ref >= 2 * navailcpus)
panic("cpu%d: diag: failed w dp->sync %ld", m->machno,
- dp->sync);
- if(dp->cnt != 0)
+ dp->sync.ref);
+ if(dp->cnt.ref != 0)
panic("cpu%d: diag: failed w dp->cnt %ld", m->machno,
- dp->cnt);
+ dp->cnt.ref);
ilock(dp);
iprint(" cpu%d ok", m->machno);
iunlock(dp);
synccpus(&dp->sync, 2 * navailcpus);
- adec(&dp->sync);
- adec(&dp->sync);
+ decref(&dp->sync);
+ decref(&dp->sync);
l1cache->wb();
/*
#pragma varargck argpos _uartprint 1
-extern long ainc(long *);
-extern long adec(long *);
extern void allcacheinfo(Memcache *);
extern void allcacheson(void);
extern int archether(unsigned, Ether *);
#include "cache.v7.s"
+TEXT cas+0(SB),0,$12 /* r0 holds p */
+ MOVW ov+4(FP), R1
+ MOVW nv+8(FP), R2
+spin:
+/* LDREX 0(R0),R3 */
+ LDREX(0,3)
+ CMP.S R3, R1
+ BNE fail
+/* STREX 0(R0),R2,R4 */
+ STREX(0,2,4)
+ CMP.S $0, R4
+ BNE spin
+ MOVW $1, R0
+ DMB
+ RET
+fail:
+ MOVW $0, R0
+ RET
+
TEXT tas(SB), $-4 /* _tas(ulong *) */
/* returns old (R0) after modifying (R0) */
MOVW R0,R5