Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
8.1 KiB

  1. /****************************************************************************/
  2. /* nschapi.cpp */
  3. /* */
  4. /* Scheduling component API */
  5. /* */
  6. /* Copyright(c) Microsoft Corporation 1996-1999 */
  7. /****************************************************************************/
  8. #include <precomp.h>
  9. #pragma hdrstop
  10. #define TRC_FILE "nschapi"
  11. #include <as_conf.hpp>
  12. #include <nprcount.h>
  13. /****************************************************************************/
  14. /* Name: SCH_Init */
  15. /* */
  16. /* Purpose: Scheduler initialization function. */
  17. /****************************************************************************/
  18. void RDPCALL SHCLASS SCH_Init(void)
  19. {
  20. DC_BEGIN_FN("SCH_Init");
  21. #define DC_INIT_DATA
  22. #include <nschdata.c>
  23. #undef DC_INIT_DATA
  24. // ASLEEP mode gets no timer.
  25. schPeriods[SCH_MODE_ASLEEP] = SCH_NO_TIMER;
  26. // Get scheduling periods that were saved in WD_Open.
  27. schPeriods[SCH_MODE_NORMAL] = m_pTSWd->outBufDelay;
  28. // If compression is enabled (ie it's a slow link) then crank up the
  29. // turbo period to improve responsiveness.
  30. if (m_pTSWd->bCompress) {
  31. TRC_ALT((TB, "Slow link"));
  32. schPeriods[SCH_MODE_TURBO] = SCH_TURBO_PERIOD_SLOW_LINK_DELAY;
  33. schTurboModeDuration = SCH_TURBO_MODE_SLOW_LINK_DURATION;
  34. m_pShm->sch.MPPCCompressionEst = SCH_MPPC_INIT_EST;
  35. }
  36. else {
  37. TRC_ALT((TB, "Fast link"));
  38. schPeriods[SCH_MODE_TURBO] = m_pTSWd->interactiveDelay;
  39. schTurboModeDuration = SCH_TURBO_MODE_FAST_LINK_DURATION;
  40. // To avoid branching, we set the compression ratio for non-compressed
  41. // to the same size as the divisor to create a 1:1 calculation.
  42. m_pShm->sch.MPPCCompressionEst = SCH_UNCOMP_BYTES;
  43. }
  44. TRC_ALT((TB, "Normal period=%u ms, turbo period=%u ms, turbo duration=%u ms",
  45. schPeriods[SCH_MODE_NORMAL], schPeriods[SCH_MODE_TURBO],
  46. schTurboModeDuration / 10000));
  47. DC_END_FN();
  48. }
  49. /****************************************************************************/
  50. // Updates the SHM
  51. /****************************************************************************/
  52. void RDPCALL SHCLASS SCH_UpdateShm(void)
  53. {
  54. DC_BEGIN_FN("SCH_UpdateShm");
  55. m_pShm->sch.schSlowLink = m_pTSWd->bCompress;
  56. // Set up packing sizes based on link speed.
  57. if (m_pTSWd->bCompress) {
  58. m_pShm->sch.SmallPackingSize = SMALL_SLOWLINK_PAYLOAD_SIZE;
  59. m_pShm->sch.LargePackingSize = LARGE_SLOWLINK_PAYLOAD_SIZE;
  60. }
  61. else {
  62. m_pShm->sch.SmallPackingSize = SMALL_LAN_PAYLOAD_SIZE;
  63. m_pShm->sch.LargePackingSize = LARGE_LAN_PAYLOAD_SIZE;
  64. }
  65. SET_INCOUNTER(IN_SCH_SMALL_PAYLOAD, m_pShm->sch.SmallPackingSize);
  66. SET_INCOUNTER(IN_SCH_LARGE_PAYLOAD, m_pShm->sch.LargePackingSize);
  67. DC_END_FN();
  68. }
  69. /****************************************************************************/
  70. /* Name: SCH_ContinueScheduling */
  71. /* */
  72. /* Purpose: Called by components when they want periodic scheduling to */
  73. /* continue. They are guaranteed to get at least one more */
  74. /* periodic callback following a call to this function. */
  75. /* If they want further callbacks then they must call this */
  76. /* function again during their periodic processing. */
  77. /* */
  78. /* Params: schedulingMode - either SCH_MODE_NORMAL or SCH_MODE_TURBO */
  79. /* */
  80. /* Operation: - */
  81. /* SCH_MODE_NORMAL triggers periodic processing at 200ms */
  82. /* intervals (5 times a second) */
  83. /* */
  84. /* SCH_MODE_TURBO triggers periodic processing at 100ms */
  85. /* intervals (10 times a second) */
  86. /* */
  87. /* The scheduler automatically drops from SCH_MODE_TURBO back */
  88. /* to SCH_MODE_NORMAL after 1 second of turbo mode processing. */
  89. /* */
  90. /* SCH_MODE_TURBO overrides SCH_MODE_NORMAL, so if calls to */
  91. /* this function are made with SCH_MODE_NORMAL when the */
  92. /* scheduler is in TURBO mode, TURBO mode continues. */
  93. /* */
  94. /* If this function is not called during one pass through */
  95. /* DCS_TimeToDoStuff then the scheduler enters */
  96. /* SLEEP mode - and will not generate any more periodic */
  97. /* callbacks until it is woken by another call to */
  98. /* this function, or until the output accumulation code */
  99. /* IOCtls into the WD again. */
  100. /****************************************************************************/
  101. void RDPCALL SHCLASS SCH_ContinueScheduling(unsigned schedulingMode)
  102. {
  103. BOOL restart = FALSE;
  104. DC_BEGIN_FN("SCH_ContinueScheduling");
  105. TRC_ASSERT( ((schedulingMode == SCH_MODE_NORMAL) ||
  106. (schedulingMode == SCH_MODE_TURBO)),
  107. (TB, "Invalid scheduling state: %u", schedulingMode) );
  108. if (schedulingMode == SCH_MODE_TURBO)
  109. {
  110. // TURBO mode is often turned off because of packets that need to
  111. // be sent out IMMEDIATELY. This makes it very difficult to actually
  112. // ask the question, "has input come accross in the last n milliseconds.
  113. // This is what we use schInputKickMode for!
  114. schInputKickMode = TRUE;
  115. }
  116. TRC_DBG((TB, "Continue scheduling (%s) -> (%s), InTTDS(%d)",
  117. schCurrentMode == SCH_MODE_TURBO ? "Turbo" :
  118. schCurrentMode == SCH_MODE_NORMAL ? "Normal" : "Asleep",
  119. schedulingMode == SCH_MODE_TURBO ? "Turbo" :
  120. schedulingMode == SCH_MODE_NORMAL ? "Normal" : "Asleep",
  121. schInTTDS));
  122. if (schCurrentMode == SCH_MODE_TURBO) {
  123. // If we're in TURBO mode, then the only interesting event is a
  124. // requirement to stay there longer than currently planned.
  125. if (schedulingMode == SCH_MODE_TURBO) {
  126. COM_GETTICKCOUNT(schLastTurboModeSwitch);
  127. TRC_DBG((TB, "New Turbo switch time %lu",
  128. schLastTurboModeSwitch));
  129. }
  130. }
  131. else {
  132. if (schedulingMode == SCH_MODE_TURBO) {
  133. COM_GETTICKCOUNT(schLastTurboModeSwitch);
  134. restart = TRUE;
  135. TRC_DBG((TB, "New Turbo switch time %lu",
  136. schLastTurboModeSwitch));
  137. }
  138. /********************************************************************/
  139. /* We're waking up. If we're not in the middle of a TTDS pass, */
  140. /* then start the new timer straight away. */
  141. /********************************************************************/
  142. if (!schInTTDS && ((schCurrentMode == SCH_MODE_ASLEEP) || restart)) {
  143. TRC_DBG((TB, "Starting a timer for %lu ms",
  144. schPeriods[schedulingMode]));
  145. WDW_StartRITTimer(m_pTSWd, schPeriods[schedulingMode]);
  146. }
  147. schCurrentMode = schedulingMode;
  148. }
  149. DC_END_FN();
  150. }