ProcessorScheduler.st
changeset 302 1f76060d58a4
parent 271 624d7d25dcea
child 308 f04744ef7b5d
equal deleted inserted replaced
301:35e40a6fc72b 302:1f76060d58a4
    15 				zombie
    15 				zombie
    16 				activeProcess currentPriority
    16 				activeProcess currentPriority
    17 				readFdArray readSemaphoreArray readCheckArray
    17 				readFdArray readSemaphoreArray readCheckArray
    18 				writeFdArray writeSemaphoreArray
    18 				writeFdArray writeSemaphoreArray
    19 				timeoutArray timeoutActionArray timeoutProcessArray timeoutSemaphoreArray
    19 				timeoutArray timeoutActionArray timeoutProcessArray timeoutSemaphoreArray
    20 				idleActions anyTimeouts dispatching interruptedProcess'
    20 				idleActions anyTimeouts dispatching interruptedProcess
       
    21 				useIOInterrupts'
    21 	 classVariableNames:'KnownProcesses KnownProcessIds
    22 	 classVariableNames:'KnownProcesses KnownProcessIds
    22 			     PureEventDriven
    23 			     PureEventDriven
    23 			     UserSchedulingPriority 
    24 			     UserSchedulingPriority 
    24 			     UserInterruptPriority
    25 			     UserInterruptPriority
    25 			     TimingPriority
    26 			     TimingPriority
    31 
    32 
    32 ProcessorScheduler comment:'
    33 ProcessorScheduler comment:'
    33 COPYRIGHT (c) 1993 by Claus Gittinger
    34 COPYRIGHT (c) 1993 by Claus Gittinger
    34 	     All Rights Reserved
    35 	     All Rights Reserved
    35 
    36 
    36 $Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.31 1995-02-19 16:14:17 claus Exp $
    37 $Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.32 1995-03-08 23:39:20 claus Exp $
    37 '!
    38 '!
    38 
    39 
    39 Smalltalk at:#Processor put:nil!
    40 Smalltalk at:#Processor put:nil!
    40 
    41 
    41 !ProcessorScheduler class methodsFor:'documentation'!
    42 !ProcessorScheduler class methodsFor:'documentation'!
    54 "
    55 "
    55 !
    56 !
    56 
    57 
    57 version
    58 version
    58 "
    59 "
    59 $Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.31 1995-02-19 16:14:17 claus Exp $
    60 $Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.32 1995-03-08 23:39:20 claus Exp $
    60 "
    61 "
    61 !
    62 !
    62 
    63 
    63 documentation
    64 documentation
    64 "
    65 "
    84     implement (threads require some assembler support functions). 
    85     implement (threads require some assembler support functions). 
    85     To allow pureEvent mode, kludges are built into some places in the
    86     To allow pureEvent mode, kludges are built into some places in the
    86     system, where either a process is forked, or a timeout is used instead 
    87     system, where either a process is forked, or a timeout is used instead 
    87     (for examples, see ProcessMonitor or MemoryMonitor).
    88     (for examples, see ProcessMonitor or MemoryMonitor).
    88 
    89 
    89     This pure-event mode may not be supported in the future.
    90     This pure-event mode may not be supported in the future (actually, it is no longer
       
    91     maintained in places where was present).
    90 
    92 
    91     class variables:
    93     class variables:
    92 
    94 
    93 	KnownProcesses          <Collection>    all known processes
    95 	KnownProcesses          <Collection>    all known processes
    94 	KnownProcessIds         <Collection>    and their IDs
    96 	KnownProcessIds         <Collection>    and their IDs
   455     timeoutSemaphoreArray := Array with:nil.
   457     timeoutSemaphoreArray := Array with:nil.
   456     timeoutActionArray := Array with:nil.
   458     timeoutActionArray := Array with:nil.
   457     timeoutProcessArray := Array with:nil.
   459     timeoutProcessArray := Array with:nil.
   458     anyTimeouts := false.
   460     anyTimeouts := false.
   459     dispatching := false.
   461     dispatching := false.
       
   462     useIOInterrupts := OperatingSystem supportsIOInterrupts.
   460 
   463 
   461     "
   464     "
   462      handcraft the first (dispatcher-) process - this one will never
   465      handcraft the first (dispatcher-) process - this one will never
   463      block, but go into a select if there is nothing to do.
   466      block, but go into a select if there is nothing to do.
   464      Also, it has a prio of max+1 - thus, it comes first when looking
   467      Also, it has a prio of max+1 - thus, it comes first when looking
  1051     anyTimeouts ifTrue:[
  1054     anyTimeouts ifTrue:[
  1052 	self evaluateTimeouts
  1055 	self evaluateTimeouts
  1053     ].
  1056     ].
  1054 
  1057 
  1055     "first do a quick check for semaphores using checkActions - this is needed for
  1058     "first do a quick check for semaphores using checkActions - this is needed for
  1056      devices like X-connection, where some events might be in the event
  1059      devices like the X-connection, where some events might be in the event
  1057      queue. Without these, a select might block even though there is work to do
  1060      queue. Without these checks, a select might block even though there is work to do
  1058     "
  1061     "
  1059     any := false.
  1062     any := false.
  1060     nActions := readCheckArray size.
  1063     nActions := readCheckArray size.
  1061     1 to:nActions do:[:index |
  1064     1 to:nActions do:[:index |
  1062 	|checkBlock sema action|
  1065 	|checkBlock sema action|
  1081 	^ self
  1084 	^ self
  1082     ].
  1085     ].
  1083 
  1086 
  1084     pri := p priority.
  1087     pri := p priority.
  1085 
  1088 
  1086     "want to give control to the process p.
  1089     "
       
  1090      want to give control to the process p.
  1087      If the switched-to processes priority is lower than the
  1091      If the switched-to processes priority is lower than the
  1088      userSchedulingPriority, we have to make certain, that the 
  1092      userSchedulingPriority, we have to make certain, that the 
  1089      next input or timer will bring us back for a reschedule.
  1093      next input or timer will bring us back for a reschedule.
  1090      This is done by enabling ioInterrupts for all file descriptors.
  1094      This is done by enabling ioInterrupts for all file descriptors.
  1091      If ioInterrupts are not available, we schedule a timer interrupt 
  1095      If ioInterrupts are not available (OS does not support them), 
  1092      to interrupt us after 1/20s of a second - effectively polling 
  1096      we schedule a timer interrupt to interrupt us after 1/20s of a second
  1093      the filedescriptors. - which is very bad, since low prio processes
  1097      - effectively polling the filedescriptors 20 times a second.
  1094      will be hurt in performance 
  1098      (which is bad, since low prio processes will be hurt in performance)
  1095      - dont let benchmarks run with low prio ...
  1099      Therefore, dont let benchmarks run with low prio ...
       
  1100 
  1096      Higher prio processes must be suspended, 
  1101      Higher prio processes must be suspended, 
  1097      same prio ones must yield or suspend to get back control"
  1102      same prio ones must yield or suspend to get back control
       
  1103     "
  1098 
  1104 
  1099 "
  1105 "
  1100  uncommenting this will make timeouts interrupt the current process
  1106  uncommenting this will make timeouts interrupt the current process
  1101  (i.e. as if the interrupt runs at TimingPrio); 
  1107  (i.e. as if the interrupt runs at TimingPrio); 
  1102  if left commented, they are handled at UserSchedulingPrio.
  1108  if left commented, they are handled at UserSchedulingPrio.
  1113     ].
  1119     ].
  1114 "
  1120 "
  1115 
  1121 
  1116     "
  1122     "
  1117      if the process to run has a lower than UserInterruptPriority,
  1123      if the process to run has a lower than UserInterruptPriority,
  1118      arrange for an interrupt to occur on IO.
  1124      arrange for an interrupt to occur on I/O.
  1119      This is done by enabling IO-signals (if the OS supports them)
  1125      This is done by enabling IO-signals (if the OS supports them)
  1120      or by installing a poll-interrupt after 50ms (if the OS does not).
  1126      or by installing a poll-interrupt after 50ms (if the OS does not).
  1121     "
  1127     "
  1122     pri < UserInterruptPriority ifTrue:[
  1128     pri < UserInterruptPriority ifTrue:[
  1123     
  1129     
  1126 	    millis := self timeToNextTimeout.
  1132 	    millis := self timeToNextTimeout.
  1127 	    millis == 0 ifTrue:[^ self].
  1133 	    millis == 0 ifTrue:[^ self].
  1128 	].
  1134 	].
  1129 "---"
  1135 "---"
  1130 
  1136 
  1131 	OperatingSystem supportsIOInterrupts ifTrue:[
  1137 	useIOInterrupts ifTrue:[
  1132 	    readFdArray do:[:fd |
  1138 	    readFdArray do:[:fd |
  1133 		fd notNil ifTrue:[
  1139 		fd notNil ifTrue:[
  1134 		    OperatingSystem enableIOInterruptsOn:fd
  1140 		    OperatingSystem enableIOInterruptsOn:fd
  1135 		].
  1141 		].
  1136 	    ].
  1142 	    ].
  1185      there is none"
  1191      there is none"
  1186 
  1192 
  1187     |aTime now delta minDelta n "{ Class: SmallInteger }"|
  1193     |aTime now delta minDelta n "{ Class: SmallInteger }"|
  1188 
  1194 
  1189     "find next timeout. since there are usually not many, just search.
  1195     "find next timeout. since there are usually not many, just search.
  1190      If there where many, the list should be kept sorted ... keeping deltas
  1196      If there were many, the list should be kept sorted ... keeping deltas
  1191      to next (as in Unix kernel)"
  1197      to next (as in Unix kernel)"
  1192 
  1198 
  1193     n := timeoutArray size.
  1199     n := timeoutArray size.
  1194     1 to:n do:[:index |
  1200     1 to:n do:[:index |
  1195 	aTime := timeoutArray at:index.
  1201 	aTime := timeoutArray at:index.