From 76ff7c4a22a87506651c81471c10e21bcff57898 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 3 Mar 1996 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1996-03-03 --- carrera/clock.c | 8 ++++++-- pc/clock.c | 4 +++- pc/devi82365.c | 3 ++- port/devproc.c | 51 +++++++++++++++++++++++++++++++++++++++++++------ port/portdat.h | 6 ++++++ port/portfns.h | 1 + port/segment.c | 18 +++++++++++++++++ 7 files changed, 81 insertions(+), 10 deletions(-) diff --git a/carrera/clock.c b/carrera/clock.c index 885eee6b893675ab41f284c5735a81a1ee662652..193463ebb8debcbe9e272d37fe744f155f9f1ab2 100644 --- a/carrera/clock.c +++ b/carrera/clock.c @@ -47,6 +47,8 @@ clockinit(void) void clock(Ureg *ur) { + int l; + Segment *s; wrcompare(rdcount()+(m->speed*1000000)/HZ); @@ -82,6 +84,8 @@ clock(Ureg *ur) sched(); /* user profiling clock */ - if(ur->status & KUSER) - (*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1); + if(ur->status & KUSER) { + (*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1); + segclock(ur->pc); + } } diff --git a/pc/clock.c b/pc/clock.c index e5513ec7940bb88cedd618e7acfb1ff89ae7a56b..9b299f7efbf94aa33853dba4e2abcc3199143d1d 100644 --- a/pc/clock.c +++ b/pc/clock.c @@ -54,8 +54,10 @@ clock(Ureg *ur, void *arg) sched(); /* user profiling clock */ - if((ur->cs&0xffff) == UESEL) + if((ur->cs&0xffff) == UESEL) { (*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1); + segclock(ur->pc); + } } } diff --git a/pc/devi82365.c b/pc/devi82365.c index bb8151676349b7d10fc1c2de26bc0a5e571614fd..8141dbce899ffd41b51481435981a62fd7517025 100644 --- a/pc/devi82365.c +++ b/pc/devi82365.c @@ -5,7 +5,6 @@ #include "fns.h" #include "../port/error.h" #include "io.h" -#include "devtab.h" /* * Support for up to 4 Slot card slots. Generalizing above that is hard @@ -189,6 +188,8 @@ static int pcmio(int, ISAConf*); static long pcmread(int, int, void*, long, ulong); static long pcmwrite(int, int, void*, long, ulong); +void i82365reset(void); + /* * reading and writing card registers */ diff --git a/port/devproc.c b/port/devproc.c index 1885a729bc3c1b1076f0aa850d00a5628724fdaf..0bc440171a7448a2bf3016d209a17e27d59a7e2e 100644 --- a/port/devproc.c +++ b/port/devproc.c @@ -6,7 +6,6 @@ #include "../port/error.h" #include "ureg.h" - enum { Qctl, @@ -24,6 +23,7 @@ enum Qstatus, Qtext, Qwait, + Qprofile, }; #define STATSIZE (2*NAMELEN+12+9*12) @@ -43,6 +43,7 @@ Dirtab procdir[] = "status", {Qstatus}, STATSIZE, 0444, "text", {Qtext}, 0, 0000, "wait", {Qwait}, 0, 0400, + "profile", {Qprofile}, 0, 0400, }; /* Segment type from portdat.h */ @@ -76,6 +77,7 @@ procgen(Chan *c, Dirtab *tab, int, int s, Dir *dp) { Qid qid; Proc *p; + Segment *q; char buf[NAMELEN]; ulong pid, path, perm, len; @@ -105,8 +107,18 @@ procgen(Chan *c, Dirtab *tab, int, int s, Dir *dp) perm = p->procmode; len = tab->length; - if(QID(c->qid) == Qwait) + switch(QID(c->qid)) { + case Qwait: len = p->nwait * sizeof(Waitmsg); + break; + case Qprofile: + q = p->seg[TSEG]; + if(q && q->profile) { + len = (q->top-q->base)>>LRESPROF; + len *= sizeof(*q->profile); + } + break; + } qid = (Qid){path|tab->qid.path, c->qid.vers}; devdir(c, qid, tab->name, len, p->user, perm, dp); @@ -182,6 +194,7 @@ procopen(Chan *c, int omode) case Qproc: case Qkregs: case Qsegment: + case Qprofile: if(omode != OREAD) error(Eperm); break; @@ -311,6 +324,18 @@ procread(Chan *c, void *va, long n, ulong offset) return n; } error(Ebadarg); + case Qprofile: + s = p->seg[TSEG]; + if(s == 0 || s->profile == 0) + error("profile is off"); + i = (s->top-s->base)>>LRESPROF; + i *= sizeof(*s->profile); + if(offset >= i) + return 0; + if(offset+n > i) + n = i - offset; + memmove(a, ((char*)s->profile)+offset, n); + return n; case Qnote: qlock(&p->debug); @@ -408,9 +433,10 @@ procread(Chan *c, void *va, long n, ulong offset) sg = p->seg[i]; if(sg == 0) continue; - j += sprint(&statbuf[j], "%-6s %c %.8lux %.8lux %4d\n", + j += sprint(statbuf+j, "%-6s %c%c %.8lux %.8lux %4d\n", sname[sg->type&SG_TYPE], sg->type&SG_RONLY ? 'R' : ' ', + sg->profile ? 'P' : ' ', sg->base, sg->top, sg->ref); } if(offset >= j) @@ -726,7 +752,8 @@ procctlfgrp(Fgrp *f) void procctlreq(Proc *p, char *va, int n) { - int i; + Segment *s; + int i, npc; char buf[NAMELEN]; if(n > NAMELEN) @@ -778,7 +805,7 @@ procctlreq(Proc *p, char *va, int n) if(strncmp(buf, "closefgrp", 9) == 0) procctlfgrp(p->fgrp); else - if(strncmp(buf, "pri", 3) == 0){ + if(strncmp(buf, "pri", 3) == 0) { if(n < 4) error(Ebadctl); i = atoi(buf+4); @@ -791,13 +818,25 @@ procctlreq(Proc *p, char *va, int n) p->basepri = i; } else - if(strncmp(buf, "wired", 5) == 0){ + if(strncmp(buf, "wired", 5) == 0) { if(n < 6) error(Ebadctl); i = atoi(buf+6); if(i) procwired(p); } + else + if(strncmp(buf, "profile", 7) == 0) { + s = p->seg[TSEG]; + if(s == 0 || (s->type&SG_TYPE) != SG_TEXT) + error(Ebadctl); + if(s->profile != 0) + free(s->profile); + npc = (s->top-s->base)>>LRESPROF; + s->profile = malloc(npc*sizeof(*s->profile)); + if(s->profile == 0) + error(Enomem); + } else error(Ebadctl); } diff --git a/port/portdat.h b/port/portdat.h index ffd35fae23cfeee1040db2133a8b501f0efab2b8..ef34aa59cca951b65a26f91affd19ea9907fe407 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -377,6 +377,7 @@ struct Segment int flushme; /* maintain icache for this segment */ Image *image; /* text in file attached to this segment */ Physseg *pseg; + ulong* profile; /* Tick profile area */ Pte *map[SEGMAPSIZE]; }; @@ -700,6 +701,11 @@ extern int mouseshifted; extern int mousetype; extern int mouseswap; +enum +{ + LRESPROF = 3, +}; + extern int nsyscall; extern Physseg physseg[]; extern ulong crasharea; diff --git a/port/portfns.h b/port/portfns.h index 0e35d4b22b3bcf5992679b0bb4287cf6a93baa29..7eae7faeb59889840c02e64a935b3c672da55540 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -257,6 +257,7 @@ int scsitest(Target*, char); Target* scsiunit(int, int); long seconds(void); ulong segattach(Proc*, ulong, char *, ulong, ulong); +void segclock(ulong); void segpage(Segment*, Page*); int setcolor(ulong, ulong, ulong, ulong); void setkernur(Ureg*, Proc*); diff --git a/port/segment.c b/port/segment.c index 1cebd6eb5693db6dc2a407495dfa0f444d7d5edf..f199700810685c385cd38aa476c59f3cfe936726 100644 --- a/port/segment.c +++ b/port/segment.c @@ -88,6 +88,8 @@ putseg(Segment *s) freepte(s, *pp); qunlock(&s->lk); + if(s->profile != 0) + free(s->profile); free(s); } @@ -542,3 +544,19 @@ syssegflush(ulong *arg) flushmmu(); return 0; } + +void +segclock(ulong pc) +{ + Segment *s; + + s = up->seg[TSEG]; + if(s == 0 || s->profile == 0) + return; + + s->profile[0] += TK2MS(1); + if(pc >= s->base && pc < s->top) { + pc -= s->base; + s->profile[pc>>LRESPROF] += TK2MS(1); + } +}