home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / os2 / misc / 27190 < prev    next >
Encoding:
Internet Message Format  |  1992-08-12  |  5.7 KB

  1. Xref: sparky comp.os.os2.misc:27190 comp.os.os2.programmer:4170
  2. Newsgroups: comp.os.os2.misc,comp.os.os2.programmer
  3. Path: sparky!uunet!newsgate.watson.ibm.com!news.ans.net!ans.net!db3l
  4. From: db3l@ans.net (David Bolen)
  5. Subject: Re: Request for info about kernel pre-emption and priorities
  6. Sender: news@ans.net (News Administrator)
  7. Message-ID: <1992Aug12.163357.34974@ans.net>
  8. In-Reply-To: terence@tanru.tti.com's message of Mon, 10 Aug 1992 23: 36:36 GMT
  9. Date: Wed, 12 Aug 1992 12:34:59 GMT
  10. References: <1992Aug10.233636.24891@ttinews.tti.com>
  11. Organization: Advanced Network & Services, Inc. - Elmsford, NY
  12. Lines: 96
  13.  
  14. In article <1992Aug10.233636.24891@ttinews.tti.com> terence@tanru.tti.com ( Terry) writes:
  15.  
  16. >First off, is the kernel really multi-threaded and can it be pre-empted.  I
  17. >know there's a number of threads for the WPS but is the underlying base
  18. >kernel multi-threaded.  On a related note, can the kernel be pre-empted;
  19. >for another kernel entry or in favor of a high-priority user thread.
  20. >
  21. >I believe the answer is yes.
  22.  
  23. I believe so to - multiple threads may enter the kernel concurrently.  If they
  24. are for completely unrelated system calls they should truly execute in
  25. parallel, but for related calls, there is probably a variety of internal
  26. synchronization and blocking that occurs in order to prevent resource clashes.
  27. If this weren't true, OS/2 multitasking wouldn't be much more than what
  28. Windows does in terms of preventing multiple tasks from entering into the
  29. "single-threaded, non-reentrant" DOS kernel.
  30.  
  31. In terms of preemption, a lower priority thread that is executing a kernel
  32. call may be suspended in favor of a higher priority thread even if that thread
  33. will issue kernel calls.  However, if the higher priority thread requires
  34. access to resources that the lower priority thread already has locked (either
  35. through semaphores or internal kernel locking), the higher priority thread
  36. will get blocked until the resource is released by the lower priority thread.
  37.  
  38. This "preemption" can occur either through the basic scheduling interrupt
  39. (32x/sec), or by a process releasing a resource that a higher priority thread
  40. is waiting on.  For example, if a low priority thread sits in a loop, it will
  41. still get interrupted every 31.25ms, and if during one of those interrupts a
  42. higher priority thread is ready to run, the CPU will be given to that task
  43. rather than to the low priority thread.  If, on the other hand, the low
  44. priority thread has a semaphore lock that a higher priority thread wants, when
  45. the low priority thread issues the semaphore release call, that call will
  46. never return, but control will switch directly to the high priority thread
  47. (rather than waiting for the next scheduler interrupt of the lower priority
  48. thread).  The TIMESLICE parameter in CONFIG.SYS come into play when tasks
  49. at the same priority are competing for the CPU, which is handled by a
  50. "round-robin" scheduling mechanism.
  51.  
  52. In OS/2 1.x, I believe the time latency from when a high priority thread
  53. became "ready to run" (either resource released, or the thread was unblocked
  54. due to some other mechanism, such as a timer firing) until it got control of
  55. the CPU was guaranteed to be <1ms.  Not the greatest in terms of real-time
  56. operation, but not bad for a multitasking OS.  I'm not how much, if at all,
  57. that figure has been adjusted for v2.0.
  58.  
  59. >About process priorities, there's three major categories with 32 levels
  60. >per category but if a process is starved for CPU, does it's priority get
  61. >artifically raised so it gets the CPU.
  62. >
  63. >I believe the answer to this one is no.
  64.  
  65. It depends on the category of the thread's priority.  Note that the OS/2
  66. scheduler knows only about threads, so all of the priority and task switching
  67. issues occur at the thread level, rather than process.
  68.  
  69. There are 4 priority categories, or classes (my names may not exactly match
  70. the official names):
  71.  
  72.      Idle        Lowest priority class.  Only runs when no other
  73.             thread has a higher priority.  No dynamic variation.
  74.  
  75.      Normal/Regular    Standard priority class.  Most threads run within
  76.             this priority.  Allows dynamic variation.
  77.  
  78.      Fixed-High/    Recently added class (I think with OS/2 1.3).  Fixed
  79.      Foreground Server    priority level.  No dynamic variation.
  80.  
  81.      Time-Critical    Highest priority class.  No dynamic variation.
  82.  
  83. Every category is split into 32 priority levels.  Threads are dispatched within
  84. the system first according to their priority class, and then according to the
  85. level within the class.  Thus, Fixed-High level 0 is still higher than Regular
  86. level 31.  Within a class, threads at the same priority level are dispatched
  87. in a round-robin fashion, according to TIMESLICE config.sys parameters.
  88.  
  89. In the Regular class, threads may have their priority levels dynamically
  90. varied (unless PRIORITY=ABSOLUTE is set in config.sys).  Threads are assigned
  91. a base level within the class, and may have a delta applied to that base in
  92. order to raise or lower their priority.  When dynamic variation is enabled,
  93. regular class threads that do not get the CPU for MAXWAIT seconds (as set in
  94. config.sys) will have a delta applied to their base level, in order to give
  95. them a higher priority and a better chance of running.  At the same time,
  96. threads that consume a large amount of CPU will have a negative delta applied,
  97. in order to free up the CPU for other threads.
  98.  
  99. This dynamic adjustment does not occur in any of the other classes (or at
  100. least it didn't under OS/2 1.3, and I don't think that changed).
  101.  
  102. --
  103. -- David
  104. --
  105. /-----------------------------------------------------------------------\
  106.  \              David Bolen             \  Internet: db3l@ans.net      /
  107.   |   Advanced Network & Services, Inc.   \   Phone: (914) 789-5327   |
  108.  / 100 Clearbrook Road, Elmsford, NY 10523  \   Fax: (914) 789-5310    \
  109. \-----------------------------------------------------------------------/
  110.