Annotation of coherent/b/STREAMS/coh.386/misc.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * coh.386/misc.c
                      3:  *
                      4:  * Miscellaneous routines.
                      5:  *
                      6:  * Revised: Thu Jul 15 14:18:13 1993 CDT
                      7:  */
                      8: #include <sys/coherent.h>
                      9: #include <sys/acct.h>
                     10: #include <sys/errno.h>
                     11: #include <sys/ino.h>
                     12: #include <sys/stat.h>
                     13: 
                     14: #ifdef TRACER
                     15: extern unsigned t_piggy;
                     16: #endif
                     17: 
                     18: /*
                     19:  * Make sure we are the super user.
                     20:  */
                     21: 
                     22: super()
                     23: {
                     24:        if (u.u_uid) {
                     25:                u.u_error = EPERM;
                     26:                return 0;
                     27:        }
                     28:        u.u_flag |= ASU;
                     29:        return 1;
                     30: }
                     31: 
                     32: /*
                     33:  * Make sure we are the gived `uid' or the super user.
                     34:  */
                     35: 
                     36: owner(uid)
                     37: {
                     38:        if (u.u_uid == uid)
                     39:                return 1;
                     40:        if (u.u_uid == 0) {
                     41:                u.u_flag |= ASU;
                     42:                return 1;
                     43:        }
                     44:        u.u_error = EPERM;
                     45:        return 0;
                     46: }
                     47: 
                     48: /*
                     49:  * Use printf to generate a call-trace.
                     50:  */
                     51: 
                     52: void backtrace (dummy)
                     53: long           dummy;
                     54: {
                     55:        long          * bp = (& dummy) - 2;
                     56: 
                     57:        printf ("Call backtrace: ");
                     58:        do {
                     59:                bp = (long *) * bp;
                     60:                printf (" -> %x", * (bp + 1));
                     61:        } while (* bp != NULL);
                     62:        printf ("\n");
                     63: }
                     64: 
                     65: /*
                     66:  * Panic.
                     67:  */
                     68: void
                     69: panic(a1)
                     70: char *a1;
                     71: {
                     72:        static panflag;
                     73: 
                     74:        sphi ();
                     75: 
                     76: #ifdef TRACER
                     77:        if (t_piggy & 0x80) {
                     78:                if (panflag ++ == 0) {
                     79:                        printf ("Panic: %r", &a1);
                     80:                        putchar ('\n');
                     81:                        usync ();
                     82:                }
                     83:                printf ("relax! It really isn't so bad.\n");
                     84:        } else {
                     85:                if (panflag ++ == 0) {
                     86:                        if (paging ()) {
                     87:                                printf ("Panic: %r", &a1);
                     88:                                putchar ('\n');
                     89:                        } else {
                     90:                                strchirp ("Panic: ");
                     91:                                strchirp (a1);
                     92:                        }
                     93:                        backtrace (0);
                     94:                        for (;;)
                     95:                                /* DO NOTHING */ ;
                     96:                        usync ();
                     97:                }
                     98:                halt ();
                     99:        }
                    100: #else
                    101:        if (panflag ++ == 0) {
                    102:                printf ("Panic: %r", &a1);
                    103:                putchar ('\n');
                    104:                for (;;)
                    105:                        /* DO NOTHING */ ;
                    106:                usync ();
                    107:        }
                    108:        halt ();
                    109: #endif /* TRACER */
                    110: 
                    111:        -- panflag;
                    112: }
                    113: 
                    114: /*
                    115:  * Print a message from a device driver.
                    116:  */
                    117: devmsg(dev, a1)
                    118: dev_t dev;
                    119: char *a1;
                    120: {
                    121:        printf ("(%d,%d): %r", major(dev), minor(dev), &a1);
                    122:        printf ("\n");
                    123: }
                    124: 
                    125: /*
                    126:  * Wait up to "ticks" clock ticks for an event to occur.
                    127:  * A tick is 1/HZ seconds (10 msec).
                    128:  * Works whether interrupts are enabled or not.
                    129:  * Busy-waits the system.
                    130:  * The event occurs when (*fn)() returns a nonzero value.
                    131:  * If fn is NULL, delay unconditionally.
                    132:  *
                    133:  * Return 0 if timeout occurred, 1 if the desired event occurred.
                    134:  */
                    135: 
                    136: #define THRESH (T0_RATE/2)     /* half of 11932 */
                    137: 
                    138: int
                    139: busyWait(fn, ticks)
                    140: int (*fn)();
                    141: int ticks;
                    142: {
                    143:        /*
                    144:         * p0, p1 are 0 if in low half of counting cycle, else 1.
                    145:         * flips counts the number of changes from low-to-high or vice versa.
                    146:         * tickCt counts the number of clock ticks at rate HZ.
                    147:         */
                    148: 
                    149:        int tickCt = 0;
                    150:        int flips = 0;
                    151:        int p0 = read_t0 () < THRESH ? 0 : 1;
                    152:        int p1;
                    153: 
                    154:        for (;;) {
                    155:                if (fn && (* fn) ())
                    156:                        return 1;
                    157: 
                    158:                /* did we change halves of counter cycle? */
                    159:                p1 = read_t0 () < THRESH ? 0 : 1;
                    160:                if (p0 != p1) {
                    161:                        p0 = p1;
                    162:                        flips ++;
                    163: 
                    164:                        /* two phase flips make a tick */
                    165:                        if (flips >= 2) {
                    166:                                flips = 0;
                    167:                                tickCt ++;
                    168:                                if (tickCt > ticks)
                    169:                                        return 0;
                    170:                        }
                    171:                }
                    172:                
                    173:        }
                    174: }
                    175: 
                    176: /*
                    177:  * busyWait2() has finer granularity than busyWait().
                    178:  *
                    179:  * Wait up to "counts" clock counts for an event to occur.
                    180:  * A count is 1/(11932*HZ) seconds (about 0.84 usec).
                    181:  * Works whether interrupts are enabled or not.
                    182:  * Busy-waits the system.
                    183:  * The event occurs when (*fn)() returns a nonzero value.
                    184:  * If fn is NULL, delay unconditionally.
                    185:  *
                    186:  * Return 0 if timeout occurred, 1 if the desired event occurred.
                    187:  */
                    188: 
                    189: int
                    190: busyWait2 (fn, counts)
                    191: int (*fn)();
                    192: unsigned int counts;
                    193: {
                    194:        /*
                    195:         * ct0 is previous t0 reading, ct1 is current reading.
                    196:         * We have timer rollover when ct1 < ct0.
                    197:         */
                    198: 
                    199:        unsigned int totCt = 0;
                    200:        unsigned int ct0 = read_t0 ();
                    201:        unsigned int ct1;
                    202: 
                    203:        for (;;) {
                    204:                if (fn && (* fn) ())
                    205:                        return 1;
                    206: 
                    207:                ct1 = read_t0 ();
                    208:                if (ct1 > ct0) {
                    209:                        /* no timer 0 rollover */
                    210:                        totCt += ct1 - ct0;
                    211:                } else {
                    212:                        /* timer 0 rollover */
                    213:                        totCt += ct1 + T0_RATE - ct0;
                    214:                }
                    215:                if (totCt > counts)
                    216:                        return 0;
                    217:                ct0 = ct1;
                    218:        }
                    219: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.