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.

344 lines
12 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. DRRSeq.c
  5. Abstract:
  6. Priority/DRR Sequencer. This module is a scheduling component that
  7. determines the order in which submitted packets should be sent.
  8. Author:
  9. Environment:
  10. Kernel Mode
  11. Revision History:
  12. --*/
  13. #ifndef _DRRSEQ_H_FILE
  14. #define _DRRSEQ_H_FILE
  15. // The sequencer classifies each flow into an internal "priority group" based
  16. // on the flow's service type and conformance status. Within each priority
  17. // group, there may be one or more priority levels or offsets. The total
  18. // number of internal priority levels is the sum of the priority levels for
  19. // each priority group. The internal priority assigned to each flow is
  20. // calculated from the priority group and the relative priority within the
  21. // group, which is obtained from the QOS Priority object. The 802.1 priority,
  22. // is set by the wrapper. The non conforming values are obtained from the
  23. // packet.
  24. //
  25. // The flows of the following servicetypes have no internal priority.
  26. // SERVICETYPE_BESTEFFORT
  27. // SERVICETYPE_NONCONFORMING
  28. // SERVICETYPE_QUALITATIVE.
  29. //
  30. // SERVICETYPE_BESTEFFORT is treated as SERVICETYPE_QUALITATIVE in the sequencer, so the no of priority
  31. // groups is 1 less than the no. of servicetypes.
  32. #define RELATIVE_PRIORITIES 8
  33. #define PRIORITY_GROUPS (NUM_TC_SERVICETYPES - 1)
  34. #define INTERNAL_PRIORITIES (((PRIORITY_GROUPS - 2) * RELATIVE_PRIORITIES) + 2)
  35. #define DEFAULT_PRIORITY_OFFSET 3
  36. #define DEFAULT_MIN_QUANTUM 1500
  37. #define PRIORITY_GROUP_NON_CONFORMING 0
  38. #define PRIORITY_GROUP_BEST_EFFORT 1
  39. #define PRIORITY_GROUP_CONTROLLED_LOAD 2
  40. #define PRIORITY_GROUP_GUARANTEED 3
  41. #define PRIORITY_GROUP_NETWORK_CONTROL 4
  42. //
  43. // For maintaining stats
  44. //
  45. #define SEQUENCER_AVERAGING_ARRAY_SIZE 256
  46. #define NETCARD_AVERAGING_ARRAY_SIZE 256
  47. #define SEQUENCER_FLOW_AVERAGING_ARRAY_SIZE 256
  48. // The DRR Sequencer's pipe information
  49. typedef struct _DSEQ_PIPE {
  50. // ContextInfo - Generic context info
  51. // Lock - Protects pipe and flow data
  52. // Flags - See below
  53. // Flows - List of all installed flows
  54. // ActiveFlows - Lists of flows that are waiting to send packets
  55. // PriorityLevels - Number of priority offsets for each priority group
  56. // StartPriority - Lowest internal priority value for each priority group
  57. // ActiveFlowCount - Number of active flows for each service type
  58. // MaxOutstandingSends - Maximum number of outstanding sends
  59. // OutstandingSends - Number of outstanding sends
  60. // PacketsInNetcardAveragingArray
  61. // PacketsInSequencer - Current number packets in sequencer
  62. // PacketsInSequencerAveragingArray
  63. // Bandwidth - Link speed
  64. // MinimumQuantum - Minimum quantum size for DRR
  65. // MinimumRate - Smallest rate currently assigned to a flow
  66. // TimerResolution - Timer resolution in OS time units
  67. // PsFlags - Flags from pipe parameters
  68. // PsPipeContext - PS's pipe context value
  69. PS_PIPE_CONTEXT ContextInfo;
  70. #ifdef INSTRUMENT
  71. PS_DRRSEQ_STATS Stats;
  72. PRUNNING_AVERAGE PacketsInNetcardAveragingArray;
  73. ULONG PacketsInSequencer;
  74. PRUNNING_AVERAGE PacketsInSequencerAveragingArray;
  75. #endif
  76. NDIS_SPIN_LOCK Lock;
  77. ULONG Flags;
  78. LIST_ENTRY Flows;
  79. LIST_ENTRY ActiveFlows[INTERNAL_PRIORITIES];
  80. ULONG PriorityLevels[PRIORITY_GROUPS];
  81. ULONG StartPriority[PRIORITY_GROUPS];
  82. ULONG ActiveFlowCount[PRIORITY_GROUPS];
  83. ULONG TotalActiveFlows;
  84. ULONG MaxOutstandingSends;
  85. ULONG OutstandingSends;
  86. ULONG Bandwidth;
  87. ULONG MinimumQuantum;
  88. ULONG MinimumRate;
  89. ULONG TimerResolution;
  90. ULONG PsFlags;
  91. HANDLE PsPipeContext;
  92. PPS_PROCS PsProcs;
  93. PSU_SEND_COMPLETE PreviousUpcallsSendComplete;
  94. PPS_PIPE_CONTEXT PreviousUpcallsSendCompletePipeContext;
  95. } DSEQ_PIPE, *PDSEQ_PIPE;
  96. // Pipe flag values
  97. #define DSEQ_DEQUEUE 1
  98. #define DSEQ_PASSTHRU 2
  99. typedef enum _FLOW_STATE {
  100. DRRSEQ_FLOW_CREATED = 1,
  101. DRRSEQ_FLOW_DELETED
  102. } FLOW_STATE;
  103. // The DRR Sequencer's flow information
  104. typedef struct _DSEQ_FLOW {
  105. // ContextInfo - Generic context info
  106. // ActiveLinks - Links in active flow list
  107. // Links - Links in installed flow list
  108. // PacketQueue - Self-explanatory
  109. // PacketSendTime - Send time for current packet
  110. // LastConformanceTime - Absolute conformance time of last packet
  111. // TokenRate - TokenRate from GQOS
  112. // UserPriority - Priority offset assigned by user
  113. // Priority - Internal priority
  114. // PriorityGroup - Priority group for flow
  115. // Quantum - Quantum assigned to flow for DRR
  116. // DeficitCounter - Current value of DRR deficit counter
  117. // Flags - See below
  118. // PsFlowContext - PS's flow context value
  119. // BucketSize - TokenBucketSize from GQOS
  120. // NumPacketsInSeq - Number of packets from this flow in the sequencer
  121. // PacketsInSeqAveragingArray-Data for computing average packets in seq from this flow
  122. PS_FLOW_CONTEXT ContextInfo;
  123. LIST_ENTRY ActiveLinks;
  124. LIST_ENTRY Links;
  125. LIST_ENTRY PacketQueue;
  126. LARGE_INTEGER PacketSendTime;
  127. LARGE_INTEGER LastConformanceTime;
  128. ULONG TokenRate;
  129. ULONG UserPriority;
  130. ULONG Priority;
  131. ULONG PriorityGroup;
  132. ULONG Quantum;
  133. ULONG DeficitCounter;
  134. ULONG Flags;
  135. HANDLE PsFlowContext;
  136. ULONG BucketSize;
  137. #ifdef INSTRUMENT
  138. ULONG PacketsInSequencer;
  139. PS_DRRSEQ_STATS Stats;
  140. PRUNNING_AVERAGE PacketsInSeqAveragingArray;
  141. #endif
  142. FLOW_STATE State;
  143. } DSEQ_FLOW, *PDSEQ_FLOW;
  144. #define MAX_DEQUEUED_PACKETS 8
  145. #define FLOW_USER_PRIORITY 0x00000002
  146. // The following macro checks a packet for conformance based on the flow's
  147. // LastPacketTime, the current time, and the timer resolution.
  148. #define PacketIsConforming(_flow, _curtime, _r) \
  149. ( (_flow)->PacketSendTime.QuadPart <= ((_curtime).QuadPart + (_r)) )
  150. #define AdjustLastPacketTime(_flow, _curtime, _r) \
  151. if ((_curtime).QuadPart > ((_flow)->PacketSendTime.QuadPart + (_r))) \
  152. if ((_curtime).QuadPart > ((_flow)->LastConformanceTime.QuadPart - (_r))) \
  153. (_flow)->PacketSendTime = (_flow)->LastConformanceTime; \
  154. else \
  155. (_flow)->PacketSendTime = (_curtime);
  156. // The Shaper's pipe information
  157. typedef struct _TS_PIPE {
  158. // ContextInfo - Generic context info
  159. // Lock - Protects pipe data
  160. // ActiveFlows - List of flows that are waiting to send packets
  161. // Timer - Timer struct
  162. // TimerStatus - Status of timer
  163. // TimerResolution - Timer resolution in OS time units
  164. // PsPipeContext - PS's pipe context value
  165. // DropPacket - PS's drop packet routine
  166. // ControlledLoadMode - Default mode for non-conforming traffic from
  167. // controlled load flows
  168. // GuaranteedMode - Default mode for non-conforming traffic from
  169. // guaranteed service flows
  170. // IntermediateSystem - TRUE if "IS" mode should be used for implementing discard semantics
  171. // Stats - Per Pipe stats.
  172. // PacketsInShaperAveragingArray
  173. PS_PIPE_CONTEXT ContextInfo;
  174. #ifdef INSTRUMENT
  175. PS_SHAPER_STATS Stats;
  176. PRUNNING_AVERAGE PacketsInShaperAveragingArray;
  177. ULONG PacketsInShaper;
  178. #endif
  179. NDIS_SPIN_LOCK Lock;
  180. LIST_ENTRY ActiveFlows;
  181. NDIS_MINIPORT_TIMER Timer;
  182. ULONG TimerStatus;
  183. ULONG TimerResolution;
  184. HANDLE PsPipeContext;
  185. PPS_PROCS PsProcs;
  186. ULONG ControlledLoadMode;
  187. ULONG GuaranteedMode;
  188. ULONG NetworkControlMode;
  189. ULONG Qualitative;
  190. ULONG IntermediateSystem;
  191. } TS_PIPE, *PTS_PIPE;
  192. #define TIMER_UNINITIALIZED 0
  193. #define TIMER_INACTIVE 1
  194. #define TIMER_SET 2
  195. #define TIMER_PROC_EXECUTING 3
  196. // The Shaper's flow information
  197. typedef struct _TS_FLOW {
  198. // ContextInfo - Generic context info
  199. // Flags - See below
  200. // Links - Links in active flow list
  201. // Mode - Shape/Discard mode
  202. // Shape - Indicates whether to shape traffic
  203. // PacketQueue - Self-explanatory
  204. // FlowEligibilityTime - Absolute conformance time of 1st packet in queue
  205. // PsFlowContext - PS's flow context value
  206. // Stats - Per flow stats.
  207. // PacketsInShaperAveragingArray - Per flow averaging data
  208. // State - State of the flow
  209. PS_FLOW_CONTEXT ContextInfo;
  210. ULONG Flags;
  211. LIST_ENTRY Links;
  212. ULONG Mode;
  213. ULONG Shape;
  214. LIST_ENTRY PacketQueue;
  215. LARGE_INTEGER FlowEligibilityTime;
  216. HANDLE PsFlowContext;
  217. #ifdef QUEUE_LIMIT
  218. ULONG QueueSize;
  219. ULONG QueueSizeLimit;
  220. ULONG DropOverLimitPacketsFromHead;
  221. ULONG UseDefaultQueueLimit;
  222. #endif // QUEUE_LIMIT
  223. #ifdef INSTRUMENT
  224. ULONG PacketsInShaper;
  225. PS_SHAPER_STATS Stats;
  226. PRUNNING_AVERAGE PacketsInShaperAveragingArray;
  227. #endif
  228. FLOW_STATE State;
  229. } TS_FLOW, *PTS_FLOW;
  230. typedef struct _TBC_PIPE {
  231. // ContextInfo - Generic context info
  232. // MaxPacket - Maximum packet size for pipe
  233. // PsPipeContext - PS's pipe context value
  234. // DropPacket - PS's drop packet routine
  235. // HeaderLength - Length of MAC header for this pipe
  236. // ControlledLoadMode - Default mode for non-conforming traffic from
  237. // controlled load flows
  238. // GuaranteedMode - Default mode for non-conforming traffic from
  239. // guaranteed service flows
  240. // IntermediateSystem - TRUE if "IS" mode should be used for implementing discard semantics
  241. // Stats - Per Pipe stats.
  242. PS_PIPE_CONTEXT ContextInfo;
  243. #ifdef INSTRUMENT
  244. PS_CONFORMER_STATS Stats;
  245. #endif // INSTRUMENT
  246. ULONG MaxPacket;
  247. HANDLE PsPipeContext;
  248. ULONG TimerResolution;
  249. PPS_PROCS PsProcs;
  250. ULONG HeaderLength;
  251. ULONG ControlledLoadMode;
  252. ULONG GuaranteedMode;
  253. ULONG NetworkControlMode;
  254. ULONG Qualitative;
  255. ULONG IntermediateSystem;
  256. } TBC_PIPE, *PTBC_PIPE;
  257. // The conformer's flow information
  258. typedef struct _TBC_FLOW {
  259. // ContextInfo - Generic context info
  260. // Lock - Protects flow data
  261. // TokenRate - TokenRate from generic QoS
  262. // Capacity - TokenBucketSize from generic QoS
  263. // PeakRate - PeakBandwidth from generic QoS
  264. // MinPolicedUnit - MinimumPolicedUnit from generic QoS
  265. // Mode - Flow S/D mode
  266. // NoConformance - Indicates whether flow is exempt from conformance algorithm
  267. // LastConformanceTime - Absolute tb conformance time of last non-discarded packet
  268. // LastPeakTime - Absolute peak conformance time of last non-discarded packet
  269. // PeakConformanceTime - Earliest time next packet can be sent, based on peak rate
  270. // LastConformanceCredits - Number of credits at LastConformanceTime
  271. // PsFlowContext - PS's flow context value
  272. // Stats - Per flow stats.
  273. PS_FLOW_CONTEXT ContextInfo;
  274. NDIS_SPIN_LOCK Lock;
  275. ULONG TokenRate;
  276. ULONG Capacity;
  277. ULONG PeakRate;
  278. ULONG MinPolicedUnit;
  279. ULONG Mode;
  280. ULONG NoConformance;
  281. LARGE_INTEGER LastConformanceTime;
  282. LARGE_INTEGER LastPeakTime;
  283. LARGE_INTEGER PeakConformanceTime;
  284. ULONG LastConformanceCredits;
  285. HANDLE PsFlowContext;
  286. #ifdef INSTRUMENT
  287. PS_CONFORMER_STATS Stats;
  288. #endif // INSTRUMENT
  289. } TBC_FLOW, *PTBC_FLOW;
  290. #endif