123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- include("/sys/src/libthread/sched.acid");
- defn labstk(l)
- {
- if objtype == "386" then
- _stk(longjmp, *l, linkreg(0), 0);
- else
- _stk(*(l+4), *l, linkreg(0), 0);
- }
- defn lablstk(l)
- {
- if objtype == "386" then
- _stk(longjmp, *l, linkreg(0), 1);
- else
- _stk(*(l+4), *l, linkreg(0), 1);
- }
- defn altfmt(A){
- local i, s, yes;
- complex Alt A;
- s = "alt(";
- s = s + "tag(*" + itoa(A.tag\X) + "=" + itoa(*A.tag\X) + ") ";
- i = 0;
- yes = 0;
- while A.op != CHANEND && A.op != CHANNOBLK do{
- if A.op != CHANNOP then{
- if yes then s = s + ", ";
- s = s + itoa(i);
- s = s + ": ";
- if A.op == CHANSND then s = s + "send";
- if A.op == CHANRCV then s = s + "recv";
- s = s + "(channel(";
- s = s + itoa(A.c);
- s = s + "))";
- yes = 1;
- }
- i = i + 1;
- A = (Alt)(A + sizeofAlt);
- }
- if A.op==CHANNOBLK then{
- if yes then s = s + ", ";
- s = s + "noblock";
- }
- s = s + ")";
- return s;
- }
- defn alt(A){
- print(altfmt(A), "\n");
- }
- defn thread(T){
- complex Thread T;
- local A, yes, i, P;
- P = (Proc)T.proc;
- if T.cmdname != 0 then{
- print("\t", *(T.cmdname\s), ":\n");
- }
- print("\t", T\X, "\t", T.id);
- if T.state == Running then{
- print("\t\tRunning ");
- } else if T.state == Ready then{
- print("\t\tReady ");
- } else if T.state == Rendezvous then{
- print("\t\tRendezvous ");
- }else{
- print("\t\tBad state ", T.state\X, " ");
- }
- if T.chan == Chanalt then{
- print("\t\t", altfmt(T.alt), "\n");
- } else if T.chan == Chansend then{
- A = (Alt)T.alt;
- print("\t\tsend(Channel(", A.c\X, "))");
- } else if T.chan == Chanrecv then{
- A = (Alt)T.alt;
- print("\t\trecv(Channel(", A.c\X, "))");
- }
- if T.moribund == 1 then{
- print(" (Moribund)");
- }
- print("\n");
- }
- defn pthreads(P){
- complex Proc P;
- local T, Tq;
- mainpid = pid;
- setproc(P.pid);
- Tq = (Tqueue)P.threads;
- T = (Thread)Tq.$head;
- while T != 0 do{
- thread(T);
- T = T.nextt;
- }
- setproc(mainpid);
- }
- defn threads(){
- local P;
- P = (Proc)_threadpq.$head;
- while P != 0 do{
- if P != (Proc)_threadpq.$head then print("\n");
- lproc(P);
- P = P.next;
- }
- }
- defn stacks(){
- local P;
- mainpid = pid;
- P = (Proc)_threadpq.$head;
- while P != 0 do{
- print("=========================================================\n");
- proc(P);
- setproc(P.pid);
- if P.thread==0 then{
- print("=== thread scheduler stack\n");
- stk();
- }
- threadstks(P);
- P = P.next;
- }
- setproc(mainpid);
- }
- defn stacksizes(){
- local P, T, Tq, top, sp;
- mainpid = pid;
- P = (Proc)_threadpq.$head;
- while P != 0 do{
- P = (Proc)P;
- Tq = (Tqueue)P.threads;
- T = (Thread)Tq.$head;
- while T != 0 do{
- top = T.stk+T.stksize;
- if T.state==Running then {
- sp = *SP;
- }else{
- sp = *(T.sched);
- }
- sp = *(T.sched);
- print(top-sp\D, "\n");
- T = T.nextt;
- }
- P = P.next;
- }
- setproc(mainpid);
- }
- defn lproc(P){
- proc(P);
- pthreads(P);
- }
- defn threadstks(P){
- complex Proc P;
- local T, Tq;
- mainpid = pid;
- setproc(P.pid);
- Tq = (Tqueue)P.threads;
- T = (Thread)Tq.$head;
- while T != 0 do{
- print("=============================\n");
- thread(T);
- print("\n");
- threadstk(T);
- T = T.nextt;
- }
- setproc(mainpid);
- }
- defn proc(P){
- complex Proc P;
- print("Proc *p=", P\X, ", p->pid=", P.pid\D);
- if P.thread==0 then{
- print(", p->state=Sched, p->tag=", P\X);
- }else{
- print(", p->state=Running");
- }
- print("\n");
- }
- defn procs(){
- local P;
- P = (Proc)_threadpq.$head;
- while P != 0 do{
- proc(P);
- P = P.next;
- }
- }
- defn threadlstk(T){
- complex Thread T;
- local P, mainpid;
- P = (Proc)T.proc;
- mainpid = pid;
- setproc(P.pid);
- if T.state == Running then{
- lstk();
- } else {
- lablstk(T.sched);
- }
- setproc(mainpid);
- }
- defn threadstk(T){
- complex Thread T;
- local P, mainpid;
- P = (Proc)T.proc;
- mainpid = pid;
- setproc(P.pid);
- if T.state == Running then{
- stk();
- } else {
- labstk(T.sched);
- }
- setproc(mainpid);
- }
- defn tqueue(Q) {
- complex Tqueue Q;
- while Q != 0 do {
- print(Q.$head\X, " ");
- Q = *(Q.$tail);
-
- }
- print("#\n");
- }
- defn channel(C) {
- complex Channel C;
- local i, p;
- print("channel ", C\X);
- if C.freed then {
- print(" (moribund)");
- }
- print("\n");
- print("\telementsize=", C.e\D, " buffersize=", C.s, "\n");
- if C.s then {
- print("\t", C.n\D, " values in channel:\n");
- print("\t");
- p = C.v+C.e*(C.f%C.s);
- loop 1,C.n do {
- if C.e==4 then {
- print((*p)\X, " ");
- }else {
- print("data(", (*p)\X, ") ");
- }
- p = p+C.e;
- if p == C.v+C.s*C.e then {
- p = C.v;
- }
- }
- }
- print("\n");
- print(C.nentry\D, " queue slots:\n");
- i=0;
- loop 1,C.nentry do {
- if C.qentry[i] then
- print("\t", altfmt(C.qentry[i]), "\n");
- else
- print("\t<empty>\n");
- i=i+1;
- }
- }
- print("/sys/lib/acid/thread");
|