Annotation of coherent/d/286_KERNEL/USRSRC/286/krunch.c, revision 1.1.1.1

1.1       root        1: /* $Header: /usr/src/sys/i8086/src/RCS/krunch.c,v 1.1 88/03/24 17:39:33 src Exp $ */
                      2: /*
                      3:  *     The  information  contained herein  is a trade secret  of INETCO
                      4:  *     Systems, and is confidential information.   It is provided under
                      5:  *     a license agreement,  and may be copied or disclosed  only under
                      6:  *     the terms of that agreement.   Any reproduction or disclosure of
                      7:  *     this  material  without  the express  written  authorization  of
                      8:  *     INETCO Systems or persuant to the license agreement is unlawful.
                      9:  *
                     10:  *     Copyright (c) 1987.
                     11:  *     An unpublished work by INETCO Systems, Ltd.
                     12:  *     All rights reserved.
                     13:  */
                     14: 
                     15: /*
                     16:  * Coherent.
                     17:  * Segment crunch.
                     18:  *
                     19:  * $Log:       /usr/src/sys/i8086/src/RCS/krunch.c,v $
                     20:  * Revision 1.1        88/03/24  17:39:33      src
                     21:  * Initial revision
                     22:  * 
                     23:  * 87/12/02    Allan Cornish   /usr/src/sys/i8086/src/krunch.c
                     24:  * krunch() now locks/unlocks segment gate.
                     25:  *
                     26:  * 87/11/26    Allan Cornish   /usr/src/sys/i8086/src/krunch.c
                     27:  * krunch() now called to merge unused memory by moving segments.
                     28:  */
                     29: #include <sys/coherent.h>
                     30: #include <sys/i8086.h>
                     31: #include <sys/proc.h>
                     32: #include <sys/seg.h>
                     33: 
                     34: /*
                     35:  * Time interval in clock ticks between krunch attempts: default 2 seconds.
                     36:  */
                     37: int KRUNCH = 200;
                     38: 
                     39: /**
                     40:  *
                     41:  * krunch( n )
                     42:  * int n;
                     43:  *
                     44:  *     Input:  n = maximum number of segments to be moved.
                     45:  *
                     46:  *     Action: Scan the segmentation list, looking for unused memory
                     47:  *             immediately below unlocked application segments,
                     48:  *             moving the segment down into the unused memory.
                     49:  */
                     50: krunch( n )
                     51: int n;
                     52: {
                     53:        register SEG *sp;
                     54:        paddr_t paddr;
                     55:        saddr_t osel;
                     56:        static TIM tim;
                     57:        int s;
                     58: 
                     59:        if ( depth != 0 ) {
                     60:                printf("krunch(%d,depth=%d) ", n, depth );      /** DEBUG **/
                     61:                return;
                     62:        }
                     63: 
                     64:        /*
                     65:         * Do not crunch segment list if swapper is active.
                     66:         */
                     67:        if ( (KRUNCH == 0) || (sexflag != 0) )
                     68:                return;
                     69: 
                     70:        /*
                     71:         * Segment count of 0 indicates a request to schedule delayed krunch(1).
                     72:         */
                     73:        if ( n <= 0 ) {
                     74:                if ( tim.t_last != NULL )
                     75:                        timeout( &tim, KRUNCH, krunch, 1 );
                     76:                return;
                     77:        }
                     78: 
                     79:        /*
                     80:         * Segmentation is locked - retry later.
                     81:         */
                     82:        s = sphi();
                     83:        if ( locked(seglink) ) {
                     84:                timeout( &tim, KRUNCH, krunch, n );
                     85:                spl(s);
                     86:                return;
                     87:        }
                     88:        lock(seglink);
                     89:        spl(s);
                     90: 
                     91: #if EBUG > 1
                     92:        printf("krunch(%d) ", n );
                     93: #endif
                     94: 
                     95:        for ( paddr = corebot, sp = &segmq;
                     96:              (sp = sp->s_forw) != &segmq ;
                     97:              paddr = sp->s_paddr + sp->s_size ) {
                     98: 
                     99:                /*
                    100:                 * No hole exists.
                    101:                 */
                    102:                if ( paddr == sp->s_paddr )
                    103:                        continue;
                    104: 
                    105: #if EBUG > 1
                    106:                printf("hole(p=%X,n=%X) seg(p=%X,n=%X,f=%x,u=%x,l=%x) ",
                    107:                        paddr,
                    108:                        sp->s_paddr - paddr,
                    109:                        sp->s_paddr,
                    110:                        sp->s_size,
                    111:                        sp->s_flags & (SFSYST|SFHIGH),
                    112:                        sp->s_urefc,
                    113:                        sp->s_lrefc );
                    114: #endif
                    115: 
                    116:                /*
                    117:                 * Don't try to shuffle high segments into low memory.
                    118:                 */
                    119:                if ( sp->s_flags & SFHIGH )
                    120:                        break;
                    121: 
                    122:                /*
                    123:                 * System segment.
                    124:                 */
                    125:                if ( sp->s_flags & SFSYST )
                    126:                        continue;
                    127: 
                    128:                /*
                    129:                 * Segment may be in process of being swapped in/out.
                    130:                 */
                    131:                if ( (sp->s_flags & SFCORE) == 0 )
                    132:                        continue;
                    133: 
                    134:                /*
                    135:                 * Segment is locked for I/O.
                    136:                 */
                    137:                if ( sp->s_lrefc != sp->s_urefc )
                    138:                        continue;
                    139: 
                    140: #if EBUG > 0
                    141:                printf("move(dst=%X,src=%X,len=%X) ",
                    142:                        paddr, sp->s_paddr,sp->s_size );
                    143: #endif
                    144:                /*
                    145:                 * Remember previous virtual address.
                    146:                 */
                    147:                osel = FP_SEL(sp->s_faddr);
                    148: 
                    149:                /*
                    150:                 * Shift segment into the hole.
                    151:                 */
                    152:                plrcopy( sp->s_paddr, paddr, sp->s_size );
                    153:                sp->s_paddr = paddr;
                    154:                vremap( sp );
                    155: 
                    156: #if EBUG > 0
                    157:                if ( FP_SEL(sp->s_faddr) != osel ) {
                    158:                        printf("krunch: osel=%x nsel=%x\n",
                    159:                                osel, FP_SEL(sp->s_faddr) );
                    160:                }
                    161: #endif
                    162: 
                    163:                /*
                    164:                 * Ensure user segmentation is updated.
                    165:                 * We may have moved the current process.
                    166:                 */
                    167:                if ( (SELF->p_pid != 0) && ((ucs == osel) || (uds == osel)) )
                    168:                        segload();
                    169:                if ( uasa == osel )
                    170:                        uasa = FP_SEL(sp->s_faddr);
                    171: 
                    172:                /*
                    173:                 * Crunch count reached.
                    174:                 */
                    175:                if ( --n <= 0 )
                    176:                        break;
                    177:        }
                    178: 
                    179:        /*
                    180:         * Cancel timer if all low memory holes eliminated.
                    181:         */
                    182:        if ( (KRUNCH == 0) || (sp == &segmq) || (sp->s_flags & SFHIGH) )
                    183:                timeout( &tim, 0, NULL, 0 );
                    184: 
                    185:        /*
                    186:         * Attempt to crunch another segment in KRUNCH clock ticks.
                    187:         */
                    188:        else
                    189:                timeout( &tim, KRUNCH, krunch, 1 );
                    190: 
                    191:        unlock(seglink);
                    192: 
                    193: #if EBUG > 0
                    194:        printf("\n");
                    195: #endif
                    196: }

unix.superglobalmegacorp.com

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