2 #include "../port/lib.h"
6 #include "../port/error.h"
36 panic("deccnt pc=%#p", getcallerpc(&r));
41 dumplockmem(char *tag, Lock *l)
48 for(i = 0; i < 64; i++)
49 iprint("%2.2ux ", cp[i]);
54 lockloop(Lock *l, uintptr pc)
59 print("lock %#p loop key %#lux pc %#p held by pc %#p proc %lud\n",
60 l, l->key, pc, l->pc, p ? p->pid : 0);
76 inccnt(&up->nlocks); /* prevent being scheded */
77 if(tas(&l->key) == 0){
84 l->lockcycles = -lcycles();
96 if(conf.nmach < 2 && up && up->edf && (up->edf->flags & Admitted)){
98 * Priority inversion, yield on a uniprocessor; on a
99 * multiprocessor, the other processor will unlock
101 print("inversion %#p pc %#p proc %lud held by pc %#p proc %lud\n",
102 l, pc, up ? up->pid : 0, l->pc, l->p ? l->p->pid : 0);
103 up->edf->d = todget(nil); /* yield to process with lock */
112 if(tas(&l->key) == 0){
119 l->lockcycles = -lcycles();
134 pc = getcallerpc(&l);
138 if(tas(&l->key) != 0){
141 * Cannot also check l->pc, l->m, or l->isilock here
142 * because they might just not be set yet, or
143 * (for pc and m) the lock might have just been unlocked.
151 if(tas(&l->key) == 0)
163 l->m = MACHP(m->machno);
165 l->lockcycles = -lcycles();
182 l->pc = getcallerpc(&l);
184 l->m = MACHP(m->machno);
187 l->lockcycles = -lcycles();
196 l->lockcycles += lcycles();
197 cumlockcycles += l->lockcycles;
198 if(l->lockcycles > maxlockcycles){
199 maxlockcycles = l->lockcycles;
204 print("unlock: not locked: pc %#p\n", getcallerpc(&l));
206 print("unlock of ilock: pc %#p, held by %#p\n", getcallerpc(&l), l->pc);
208 print("unlock: up changed: pc %#p, acquired at pc %#p, lock p %#p, unlock up %#p\n", getcallerpc(&l), l->pc, l->p, up);
213 if(up && deccnt(&up->nlocks) == 0 && up->delaysched && islo()){
215 * Call sched if the need arose while locks were held
216 * But, don't do it from interrupt routines, hence the islo() test
222 ulong ilockpcs[0x100] = { [0xff] = 1 };
231 l->lockcycles += lcycles();
232 cumilockcycles += l->lockcycles;
233 if(l->lockcycles > maxilockcycles){
234 maxilockcycles = l->lockcycles;
237 if(l->lockcycles > 2400)
238 ilockpcs[n++ & 0xff] = l->pc;
241 print("iunlock: not locked: pc %#p\n", getcallerpc(&l));
243 print("iunlock of lock: pc %#p, held by %#p\n", getcallerpc(&l), l->pc);
245 print("iunlock while lo: pc %#p, held by %#p\n", getcallerpc(&l), l->pc);