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