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.

220 lines
7.9 KiB

  1. // scheduling algorithm for split periodic
  2. #ifndef __SCHED_H__
  3. #define __SCHED_H__
  4. #define MAXCEPS 30
  5. // all times are in units of bytes
  6. #define FS_BYTES_PER_MICROFRAME 188
  7. #define MICROFRAMES_PER_FRAME 8
  8. #define FS_SOF 6 // number of byte times allocated to an SOF packet at the beginning of a frame
  9. //#define MAXFRAMES 8 // scheduling window for budget tracking, periods longer than
  10. #define MAXFRAMES 32 // scheduling window for budget tracking, periods longer than
  11. // this are reduced to this. Also impacts space required for
  12. // tracking data structures. Otherwise fairly arbitrary.
  13. #define MAXMICROFRAMES (MAXFRAMES * 8)
  14. // 4 byte sync, 4 byte split token, 1 byte EOP, 11 byte ipg, plus
  15. // 4 byte sync, 3 byte regular token, 1 byte EOP, 11 byte ipg
  16. #define HS_SPLIT_SAME_OVERHEAD 39
  17. // 4 byte sync, 4 byte split token, 1 byte EOP, 11 byte ipg, plus
  18. // 4 byte sync, 3 byte regular token, 1 byte EOP, 1 byte bus turn
  19. #define HS_SPLIT_TURN_OVERHEAD 29
  20. // 4 byte sync, 1 byte PID, 2 bytes CRC16, 1 byte EOP, 11 byte ipg
  21. #define HS_DATA_SAME_OVERHEAD 19
  22. // 4 byte sync, 1 byte PID, 2 bytes CRC16, 1 byte EOP, 1 byte bus turn
  23. #define HS_DATA_TURN_OVERHEAD 9
  24. // 4 byte sync, 1 byte PID, 1 byte EOP, 1 byte bus turn
  25. #define HS_HANDSHAKE_OVERHEAD 7
  26. //#define HS_MAX_PERIODIC_ALLOCATION 6000 // floor(0.8*7500)
  27. #define HS_MAX_PERIODIC_ALLOCATION 7000 // floor(0.8*7500)
  28. // This could actually be a variable based on an HC implementation
  29. // some measurements have shown 3?us between transactions or about 3% of a microframe
  30. // which is about 200+ byte times. We'll use about half that for budgeting purposes.
  31. #define HS_HC_THINK_TIME 100
  32. // 4 byte sync, 3 byte regular token, 1 byte EOP, 11 byte ipg
  33. #define HS_TOKEN_SAME_OVERHEAD 19
  34. // 4 byte sync, 3 byte regular token, 1 byte EOP, 1 byte bus turn
  35. #define HS_TOKEN_TURN_OVERHEAD 9
  36. // TOKEN: 1 byte sync, 3 byte token, 3 bit EOP, 1 byte ipg
  37. // DATA: 1 byte sync, 1 byte PID, 2 bytes CRC16, 3 bit EOP, 1 byte ipg
  38. // HANDSHAKE: 1 byte sync, 1 byte PID, 3 bit EOP, 1 byte ipg
  39. #define FS_ISOCH_OVERHEAD 9
  40. #define FS_INT_OVERHEAD 13
  41. //#define LS_INT_OVERHEAD (19*8)
  42. #define LS_INT_OVERHEAD ((14 *8) + 5)
  43. #define HUB_FS_ADJ 30 // periodic allocation at beginning of frame for use by hubs, maximum allowable is 60 bytes
  44. #define FS_MAX_PERIODIC_ALLOCATION (1157) // floor(0.9*1500/1.16)
  45. #define FS_BS_MAX_PERIODIC_ALLOCATION 1350 // floor(0.9*1500), includes bitstuffing allowance (for HC classic allocation)
  46. // byte time to qualify as a large FS isoch transaction
  47. // 673 = 1023/1.16 (i.e. 881) - 1microframe (188) - adj (30) or
  48. // 1/2 of max allocation in this case
  49. // #define LARGEXACT (881-FS_BYTES_PER_MICROFRAME)
  50. #define LARGEXACT (579)
  51. typedef struct _Endpoint *PEndpoint;
  52. typedef struct _frame_rec
  53. {
  54. unsigned time_used:16; // The number of bytes that are budgeted for all endpoints in this frame
  55. PEndpoint allocated_large; // endpoint if xact over LARGEXACT bytes is allocated in this frame
  56. PEndpoint isoch_ehead; // many frames can point to the same endpoint. endpoints are linked
  57. PEndpoint int_ehead; // in longest to shortest period.
  58. //
  59. // NOTE: always start with a "dummy" endpoint for SOF on the lists to avoid empty list corner condition
  60. //
  61. } frame_rec;
  62. typedef struct _HC *PHC;
  63. typedef struct _TT *PTT;
  64. typedef enum {bulk, control, interrupt, isoch} eptype;
  65. #define HSSPEED 2
  66. #define FSSPEED 1
  67. #define LSSPEED 0
  68. #define INDIR 0
  69. #define OUTDIR 1
  70. typedef struct _Endpoint
  71. {
  72. unsigned type;
  73. // These fields have static information that is valid/constant as long as an
  74. // endpoint is configured
  75. unsigned max_packet:16; // maximum number of data bytes allowed for this
  76. // endpoint. 0-8 for LS_int, 0-64 for FS_int,
  77. // 0-1023 for FS_isoch.
  78. unsigned period:16; // desired period of transactions, assumed to be a power of 2
  79. eptype ep_type:4;
  80. unsigned direction:1;
  81. unsigned speed:2;
  82. unsigned moved_this_req:1; // 1 when this endpoint has been changed during this allocation request
  83. PTT mytt; // the TT that roots this classic device.
  84. // These fields hold dynamically calculated information that changes as (other)
  85. // endpoints are added/removed.
  86. unsigned calc_bus_time:16; // bytes of FS/LS bus time this endpoint requires
  87. // including overhead. This can be calculated once.
  88. unsigned start_time:16; // classic bus time at which this endpoint is budgeted to occupy the classic bus
  89. unsigned actual_period:16; // requested period can be modified:
  90. // 1. when period is greater than scheduling window (MAXFRAMES)
  91. // 2. if period is reduced (not currently done by algorithm)
  92. unsigned start_frame:8; // first bus frame that is allocated to this endpoint.
  93. int start_microframe:8; // first bus microframe (in a frame) that can have a
  94. // start-split for this ep.
  95. // Complete-splits always start 2 microframes after a
  96. // start-split.
  97. unsigned num_starts:4; // the number of start splits.
  98. unsigned num_completes:4; // the number of complete splits.
  99. /* The numbers above could be (better?) represented as bitmasks. */
  100. /* corner conditions above: coder beware!!
  101. patterns can have the last CS in the "next" frame
  102. This is indicated in this design when:
  103. (start_microframe + num_completes + 1) > 7
  104. patterns can have the first SS in the previous frame
  105. This is indicated in this design when:
  106. start_microframe = -1
  107. */
  108. PEndpoint next_ep; // pointer to next (faster/equal period) endpoint in budget
  109. int id:16; // not needed for real budgeter
  110. unsigned saved_period:16; // used during period promotion to hold original period
  111. unsigned promoted_this_time:1;
  112. } Endpoint;
  113. typedef struct _TT
  114. {
  115. unsigned HS_split_data_time[MAXFRAMES][MICROFRAMES_PER_FRAME]; // HS data bytes used for split completes
  116. // the above time tracks the data time for all devices rooted in this TT.
  117. // when the time is below 188 in a microframe, that time is allocated in the
  118. // HS microframe (in the HS HC budget). When the time is greater than 188
  119. // only 188 byte times (bit stuffed) is allocated on the HS microframe budget.
  120. unsigned num_starts[MAXFRAMES][MICROFRAMES_PER_FRAME];
  121. frame_rec frame_budget[MAXFRAMES];
  122. PHC myHC;
  123. unsigned think_time; // TT reports it inter transaction "think" time. Keep it here.
  124. unsigned allocation_limit; // maximum allocation allowed for this TT's classic bus
  125. struct _Endpoint isoch_head[MAXFRAMES];
  126. struct _Endpoint int_head[MAXFRAMES];
  127. } TT;
  128. typedef struct _microframe_rec
  129. {
  130. unsigned time_used;
  131. } microframe_rec;
  132. typedef struct _HC
  133. {
  134. microframe_rec HS_microframe_info[MAXFRAMES][MICROFRAMES_PER_FRAME]; // HS bus time allocated to
  135. //this host controller
  136. PTT tthead; // head of list of TTs attached to this HC
  137. unsigned thinktime;
  138. unsigned allocation_limit; // maximum allocation allowed for this HC
  139. int speed; // HS or FS
  140. } HC;
  141. #if 0
  142. typedef struct _command {
  143. char cmd_code;
  144. int endpoint_number;
  145. } Cmd_t;
  146. #endif
  147. /* protoypes */
  148. void init_hc(PHC myHC);
  149. Set_endpoint(
  150. PEndpoint ep,
  151. eptype t,
  152. unsigned d,
  153. unsigned s,
  154. unsigned p,
  155. unsigned m,
  156. TT *thistt
  157. );
  158. int Allocate_time_for_endpoint(
  159. PEndpoint ep,
  160. PEndpoint changed_ep_list[],
  161. int *max_changed_eps
  162. );
  163. void
  164. init_tt(PHC myHC, PTT myTT);
  165. void
  166. Deallocate_time_for_endpoint(
  167. PEndpoint ep, // endpoint that needs to be removed (bus time deallocated)
  168. PEndpoint changed_ep_list[], // pointer to array to set (on return) with list of
  169. // changed endpoints
  170. int *max_changed_eps // input: maximum size of (returned) list
  171. // on return: number of changed endpoints
  172. );
  173. #endif // __SCHED_H__