1: #
   2: #include "../param.h"
   3: #include "../systm.h"
   4: #include "../user.h"
   5: #include "../proc.h"
   6: 
   7: #define UMODE   0170000
   8: #define SCHMAG  10
   9: 
  10: /*
  11:  * clock is called straight from
  12:  * the real time clock interrupt.
  13:  *
  14:  * Functions:
  15:  *	reprime clock
  16:  *	copy *switches to display
  17:  *	implement callouts
  18:  *	maintain user/system times
  19:  *	maintain date
  20:  *	profile
  21:  *	tout wakeup (sys sleep)
  22:  *	lightning bolt wakeup (every 4 sec)
  23:  *	alarm clock signals
  24:  *	jab the scheduler
  25:  */
  26: clock(dev, sp, r1, nps, r0, pc, ps)
  27: {
  28:     register struct callo *p1, *p2;
  29:     register struct proc *pp;
  30: 
  31:     /*
  32: 	 * restart clock
  33: 	 */
  34: 
  35:     *lks = 0115;
  36: 
  37:     /*
  38: 	 * display register
  39: 	 */
  40: 
  41:     display();
  42: 
  43:     /*
  44: 	 * callouts
  45: 	 * if none, just return
  46: 	 * else update first non-zero time
  47: 	 */
  48: 
  49:     if(callout[0].c_func == 0)
  50:         goto out;
  51:     p2 = &callout[0];
  52:     while(p2->c_time<=0 && p2->c_func!=0)
  53:         p2++;
  54:     p2->c_time--;
  55: 
  56:     /*
  57: 	 * if ps is high, just return
  58: 	 */
  59: 
  60:     if((ps&0340) != 0)
  61:         goto out;
  62: 
  63:     /*
  64: 	 * callout
  65: 	 */
  66: 
  67:     spl5();
  68:     if(callout[0].c_time <= 0) {
  69:         p1 = &callout[0];
  70:         while(p1->c_func != 0 && p1->c_time <= 0) {
  71:             (*p1->c_func)(p1->c_arg);
  72:             p1++;
  73:         }
  74:         p2 = &callout[0];
  75:         while(p2->c_func = p1->c_func) {
  76:             p2->c_time = p1->c_time;
  77:             p2->c_arg = p1->c_arg;
  78:             p1++;
  79:             p2++;
  80:         }
  81:     }
  82: 
  83:     /*
  84: 	 * lightning bolt time-out
  85: 	 * and time of day
  86: 	 */
  87: 
  88: out:
  89:     if((ps&UMODE) == UMODE) {
  90:         u.u_utime++;
  91:         if(u.u_prof[3])
  92:             incupc(pc, u.u_prof);
  93:     } else
  94:         u.u_stime++;
  95:     pp = u.u_procp;
  96:     if(++pp->p_cpu == 0)
  97:         pp->p_cpu--;
  98:     if(++lbolt >= HZ) {
  99:         if((ps&0340) != 0)
 100:             return;
 101:         lbolt =- HZ;
 102:         if(++time[1] == 0)
 103:             ++time[0];
 104:         spl1();
 105:         if(time[1]==tout[1] && time[0]==tout[0])
 106:             wakeup(tout);
 107:         if((time[1]&03) == 0) {
 108:             runrun++;
 109:             wakeup(&lbolt);
 110:         }
 111:         for(pp = &proc[0]; pp < &proc[NPROC]; pp++)
 112:         if (pp->p_stat) {
 113:             if(pp->p_time != 127)
 114:                 pp->p_time++;
 115:             if((pp->p_cpu & 0377) > SCHMAG)
 116:                 pp->p_cpu =- SCHMAG; else
 117:                 pp->p_cpu = 0;
 118:             if(pp->p_pri > PUSER)
 119:                 setpri(pp);
 120:         }
 121:         if(runin!=0) {
 122:             runin = 0;
 123:             wakeup(&runin);
 124:         }
 125:         if((ps&UMODE) == UMODE) {
 126:             u.u_ar0 = &r0;
 127:             if(issig())
 128:                 psig();
 129:             setpri(u.u_procp);
 130:         }
 131:     }
 132: }
 133: 
 134: /*
 135:  * timeout is called to arrange that
 136:  * fun(arg) is called in tim/HZ seconds.
 137:  * An entry is sorted into the callout
 138:  * structure. The time in each structure
 139:  * entry is the number of HZ's more
 140:  * than the previous entry.
 141:  * In this way, decrementing the
 142:  * first entry has the effect of
 143:  * updating all entries.
 144:  */
 145: timeout(fun, arg, tim)
 146: {
 147:     register struct callo *p1, *p2;
 148:     register t;
 149:     int s;
 150: 
 151:     t = tim;
 152:     s = PS->integ;
 153:     p1 = &callout[0];
 154:     spl7();
 155:     while(p1->c_func != 0 && p1->c_time <= t) {
 156:         t =- p1->c_time;
 157:         p1++;
 158:     }
 159:     p1->c_time =- t;
 160:     p2 = p1;
 161:     while(p2->c_func != 0)
 162:         p2++;
 163:     while(p2 >= p1) {
 164:         (p2+1)->c_time = p2->c_time;
 165:         (p2+1)->c_func = p2->c_func;
 166:         (p2+1)->c_arg = p2->c_arg;
 167:         p2--;
 168:     }
 169:     p1->c_time = t;
 170:     p1->c_func = fun;
 171:     p1->c_arg = arg;
 172:     PS->integ = s;
 173: }

Defined functions

clock defined in line 26; never used
timeout defined in line 145; used 5 times

Defined macros

SCHMAG defined in line 8; used 2 times
UMODE defined in line 7; used 4 times
Last modified: 1975-07-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 886
Valid CSS Valid XHTML 1.0 Strict