2 #include "../port/lib.h"
6 #include "../port/error.h"
24 dumplockmem(char *tag, Lock *l)
31 for(i = 0; i < 64; i++)
32 iprint("%2.2ux ", cp[i]);
37 lockloop(Lock *l, uintptr pc)
42 print("lock %#p loop key %#lux pc %#p held by pc %#p proc %lud\n",
43 l, l->key, pc, l->pc, p ? p->pid : 0);
59 up->nlocks++; /* prevent being scheded */
60 if(tas(&l->key) == 0){
65 l->m = MACHP(m->machno);
68 l->lockcycles = -lcycles();
80 if(conf.nmach < 2 && up && up->edf && (up->edf->flags & Admitted)){
82 * Priority inversion, yield on a uniprocessor; on a
83 * multiprocessor, the other processor will unlock
85 print("inversion %#p pc %#p proc %lud held by pc %#p proc %lud\n",
86 l, pc, up ? up->pid : 0, l->pc, l->p ? l->p->pid : 0);
87 up->edf->d = todget(nil); /* yield to process with lock */
96 if(tas(&l->key) == 0){
101 l->m = MACHP(m->machno);
104 l->lockcycles = -lcycles();
119 pc = getcallerpc(&l);
123 if(tas(&l->key) != 0){
126 * Cannot also check l->pc, l->m, or l->isilock here
127 * because they might just not be set yet, or
128 * (for pc and m) the lock might have just been unlocked.
136 if(tas(&l->key) == 0)
147 l->m = MACHP(m->machno);
150 l->lockcycles = -lcycles();
167 l->pc = getcallerpc(&l);
169 l->m = MACHP(m->machno);
172 l->lockcycles = -lcycles();
181 l->lockcycles += lcycles();
182 cumlockcycles += l->lockcycles;
183 if(l->lockcycles > maxlockcycles){
184 maxlockcycles = l->lockcycles;
189 print("unlock: not locked: pc %#p\n", getcallerpc(&l));
191 print("unlock of ilock: pc %#p, held by %#p\n", getcallerpc(&l), l->pc);
193 print("unlock: up changed: pc %#p, acquired at pc %#p, lock p %#p, unlock up %#p\n", getcallerpc(&l), l->pc, l->p, up);
198 if(up && --up->nlocks == 0 && up->delaysched && islo()){
200 * Call sched if the need arose while locks were held
201 * But, don't do it from interrupt routines, hence the islo() test
207 uintptr ilockpcs[0x100] = { [0xff] = 1 };
216 l->lockcycles += lcycles();
217 cumilockcycles += l->lockcycles;
218 if(l->lockcycles > maxilockcycles){
219 maxilockcycles = l->lockcycles;
222 if(l->lockcycles > 2400)
223 ilockpcs[n++ & 0xff] = l->pc;
226 print("iunlock: not locked: pc %#p\n", getcallerpc(&l));
228 print("iunlock of lock: pc %#p, held by %#p\n", getcallerpc(&l), l->pc);
230 print("iunlock while lo: pc %#p, held by %#p\n", getcallerpc(&l), l->pc);