ref: d2d1396f315b02900bd46a776b4837ad74f0795c
parent: 63803922ee18701c20767be70f1b5d2d9aa82ecb
author: 9ferno <[email protected]>
date: Sat Oct 23 17:10:08 EDT 2021
got the native shell prompt for amd64
--- a/os/pc64/dat.h
+++ b/os/pc64/dat.h
@@ -34,9 +34,9 @@
struct Lock
{
u32 key;
- u32 sr;
- uintptr pc;
- u32 pri;
+ u32 sr; /* value returned by splhi() */
+ uintptr pc; /* lock() caller */
+ u32 priority;
void *p; /* Proc */
Mach *m;
u16 isilock;
--- a/os/pc64/main.c
+++ b/os/pc64/main.c
@@ -233,6 +233,7 @@
m->pml4 = pml4;
m->gdt = gdt;
m->perf.period = 1;
+ m->ilockdepth = 0;
/*
* For polled uart output at boot, need
@@ -302,7 +303,7 @@
* Kernel Stack
*
* N.B. make sure there's
- * 4 bytes for gotolabel's return PC
+ * 8 bytes for gotolabel's return PC
*/
p->sched.pc = (uintptr)init0;
p->sched.sp = (uintptr)p->kstack+KSTACK-sizeof(uintptr);
--- a/os/port/alarm.c
+++ b/os/port/alarm.c
@@ -4,38 +4,103 @@
#include "dat.h"
#include "fns.h"
-Talarm talarm;
+static Alarms alarms;
+static Rendez alarmr;
+void
+alarmkproc(void*)
+{
+ Proc *rp;
+ ulong now, when;
+
+ while(waserror())
+ ;
+
+ for(;;){
+ now = MACHP(0)->ticks;
+ qlock(&alarms);
+ for(rp = alarms.head; rp != nil; rp = rp->palarm){
+ if((when = rp->alarm) == 0)
+ continue;
+ if((long)(now - when) < 0)
+ break;
+/* TODO if(!canqlock(&rp->debug))
+ break;
+ if(rp->alarm != 0){
+ postnote(rp, 0, "alarm", NUser);
+ rp->alarm = 0;
+ }
+ qunlock(&rp->debug);
+*/
+ }
+ alarms.head = rp;
+ qunlock(&alarms);
+
+ sleep(&alarmr, return0, 0);
+ }
+}
+
/*
- * called every clock tick
+ * called every clock tick on cpu0
*/
void
checkalarms(void)
{
Proc *p;
- ulong now;
+ u64 now, when;
- now = MACHP(0)->ticks;
+ p = alarms.head;
+ if(p != nil){
+ now = MACHP(0)->ticks;
+ when = p->alarm;
+ if(when == 0 || (s64)(now - when) >= 0)
+ wakeup(&alarmr);
+ }
+}
- if(talarm.list == 0 || canlock(&talarm) == 0)
- return;
+ulong
+procalarm(ulong time)
+{
+ Proc **l, *f;
+ u64 when, old;
- for(;;) {
- p = talarm.list;
- if(p == 0)
- break;
+ when = MACHP(0)->ticks;
+ old = up->alarm;
+ if(old) {
+ old -= when;
+ if((long)old > 0)
+ old = tk2ms(old);
+ else
+ old = 0;
+ }
+ if(time == 0) {
+ up->alarm = 0;
+ return old;
+ }
+ when += (u64)ms2tk(time);
+ if(when == 0)
+ when = 1;
- if(p->twhen == 0) {
- talarm.list = p->tlink;
- p->trend = 0;
- continue;
+ qlock(&alarms);
+ l = &alarms.head;
+ for(f = *l; f; f = f->palarm) {
+ if(up == f){
+ *l = f->palarm;
+ break;
}
- if(now < p->twhen)
+ l = &f->palarm;
+ }
+ l = &alarms.head;
+ for(f = *l; f; f = f->palarm) {
+ time = f->alarm;
+ if(time != 0 && (long)(time - when) >= 0)
break;
- wakeup(p->trend);
- talarm.list = p->tlink;
- p->trend = 0;
+ l = &f->palarm;
}
+ up->palarm = f;
+ *l = up;
+ up->alarm = when;
+ qunlock(&alarms);
- unlock(&talarm);
+ return old;
}
--- a/os/port/proc.c
+++ b/os/port/proc.c
@@ -210,7 +210,7 @@
Schedq *rq;
if(p->state == Ready){
- print("double ready %s %zud pc %p\n", p->text, p->pid, getcallerpc(&p));
+ print("double ready %s %ud pc %p\n", p->text, p->pid, getcallerpc(&p));
return;
}
@@ -222,7 +222,7 @@
}
*/
-/* 9front does this. Not sure what it does yet
+ /* 9front does this. Not sure what it does yet
if(up != p && (p->wired == nil || p->wired == MACHP(m->machno)))
m->readied = p; *//* group scheduling */
@@ -376,7 +376,7 @@
goto loop;
}
if(p->state != Ready)
- print("runproc %s %zud %s\n", p->text, p->pid, statename[p->state]);
+ print("runproc %s %ud %s\n", p->text, p->pid, statename[p->state]);
unlock(runq);
p->state = Scheding;
@@ -472,7 +472,7 @@
p = xalloc(conf.nproc*sizeof(Proc));
if(p == nil){
xsummary();
- panic("cannot allocate %zud procs (%zudMB)", conf.nproc, conf.nproc*sizeof(Proc)/(1024*1024));
+ panic("cannot allocate %ud procs (%udMB)", conf.nproc, conf.nproc*sizeof(Proc)/(1024*1024));
}
procalloc.arena = p;
procalloc.free = p;
@@ -509,7 +509,7 @@
s = splhi();
if(up->nlocks)
- print("process %zd name %s sleeps with %d locks held,"
+ print("process %d name %s sleeps with %d locks held,"
" last lock %#p locked at pc %#p, sleep called from %#p\n",
up->pid, up->text, up->nlocks,
up->lastlock, up->lastlock->pc, getcallerpc(&r));
@@ -517,7 +517,7 @@
lock(r);
lock(&up->rlock);
if(r->p != nil){
- print("double sleep called from %#p, %zud %zud\n", getcallerpc(&r), r->p->pid, up->pid);
+ print("double sleep called from %#p, %ud %ud\n", getcallerpc(&r), r->p->pid, up->pid);
dumpstack();
panic("sleep");
}
@@ -585,7 +585,7 @@
tsleep(Rendez *r, int (*fn)(void*), void *arg, s32 ms)
{
if(up->tt != nil){
- print("%s %lud: tsleep timer active: mode %d, tf %#p, pc %#p\n",
+ print("%s %ud: tsleep timer active: mode %d, tf %#p, pc %#p\n",
up->text, up->pid, up->tmode, up->tf, getcallerpc(&r));
timerdel(up);
}
--- a/os/port/taslock.c
+++ b/os/port/taslock.c
@@ -63,8 +63,11 @@
if(up)
up->nlocks++; /* prevent being scheded */
if(tas(&l->key) == 0){ /* got the lock on the 1st attempt, done */
- if(up)
- up->lastlock = l;
+ if(up){
+ up->lastlock = l;
+ l->priority = up->priority;
+ up->priority = PriLock;
+ }
l->pc = pc;
l->p = up;
l->m = MACHP(m->machno);
@@ -205,20 +208,22 @@
}
#endif
if(l->key == 0)
- print("unlock(%#p): not locked: pc %#p\n",
- l, getcallerpc(&l));
+ print("unlock(%#p): not locked: pc %#p up->pid %d up->text %s\n",
+ l, getcallerpc(&l), up->pid, up->text);
if(l->isilock)
- print("unlock(%#p) of ilock: pc %#p, held by %#p\n",
- l, getcallerpc(&l), l->pc);
+ print("unlock(%#p) of ilock: pc %#p, held by %#p up->pid %d up->text %s\n",
+ l, getcallerpc(&l), l->pc, up->pid, up->text);
if(l->p != up){
- print("unlock(%#p): up changed: pc %#p, acquired at pc %#p, lock p %#p, unlock up %#p\n",
- l, getcallerpc(&l), l->pc, l->p, up);
+ print("unlock(%#p): up changed: pc %#p, acquired at pc %#p,"
+ " lock p %#p, unlock up %#p up->pid %d up->text %s up->mach->machno %d\n",
+ l, getcallerpc(&l), l->pc, l->p, up, up->pid, up->text, up->mach->machno);
dumpaproc(l->p);
dumpaproc(up);
}
pri = l->priority;
- l->m = l->p = nil;
l->pc = 0;
+ l->p = nil;
+ l->m = nil;
coherence();
l->key = 0;
@@ -261,8 +266,10 @@
print("iunlock(%#p) while lo: pc %#p, held by %#p\n", l, getcallerpc(&l), l->pc);
sr = l->sr;
- l->m = l->p = nil;
- l->sr = l->pc = 0;
+ l->sr = 0;
+ l->pc = 0;
+ l->p = nil;
+ l->m = nil;
coherence();
l->key = 0;
m->ilockdepth--;