A traffic shaping method and system based on asynchronous dual authorization value
Patent Information
- Application Number
- CN202611195427.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-07
- Publication Date
- 2026-09-04
AI Technical Summary
然而,当计数周期增大时,每次需添加的令牌数量随之大幅增加,令牌桶在较长的时间间隔内无法获得新令牌,一旦获得便一次性大量涌入,造成严重的流量突发(burst),这与流量整形“平滑流量”的初衷相矛盾
[0025] 1. Achieve near-zero error in integer shaping accuracy, fundamentally solving the problem of insufficient precision caused by integer rounding.
Smart Images

Figure CN122698535A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of network traffic shaping, and in particular to a traffic shaping method and system based on asynchronous dual-authorization value. Background Technology
[0002] Traffic shaping is used to limit outflow and bursts from a network, ensuring packets are sent at a more uniform rate. It is typically implemented using a token bucket algorithm. The system adds tokens to the token bucket at a fixed period according to a configured shaping rate, and consumes the corresponding number of tokens from the bucket whenever a data packet needs to be sent.
[0003] In the actual hardware implementation of network chips, traffic shaping involves the collaborative work of multiple hardware modules, including the Data Path Module (DPM) and the Token Management Module (Shaper Module). The DPM module is responsible for managing token consumption during data transmission, while the Shaper Module is responsible for adding and managing the total amount of tokens.
[0004] Taking PPS (Packets Per Second) mode as an example, the shaping requirement ranges from a minimum granularity of 1 PPS to a maximum of 400 Mbps, with a dynamic range of 4 × 10⁻⁶. 8 This places extremely high demands on the accuracy of the authorization value (a conversion parameter that defines how many data packets a token represents).
[0005] In existing technologies, DPM modules only support integer operations, so the licensed value must be rounded to an integer. For example, at a 1.2GHz clock frequency and a 32-cycle counting period, the theoretical number of packets to be processed in each scheduling cycle is 10.667, which is rounded up to 11, thus introducing a rounding error.
[0006] To address the aforementioned accuracy issues, existing technologies have attempted to reduce errors by adjusting the counting period. This involves selecting specific counting period values to ensure that the number of tokens added each time is as close as possible to the theoretical value, thus keeping the shaping error within an acceptable range. However, as the counting period increases, the number of tokens required to be added each time also increases significantly. The token bucket may not receive new tokens for extended periods, and once new tokens are acquired, they flood in all at once, causing severe traffic bursts. This contradicts the original intention of traffic shaping to "smooth traffic."
[0007] Furthermore, at a minimum shaping granularity of 1 PPS, the number of tokens required to be added per counting cycle is extremely small (approximately 2.5 × 10⁻⁶). -9(Each authorized value unit) requires sufficient decimal places to accurately store and accumulate these tiny amounts to avoid the accumulation of rounding errors in the decimal part.
[0008] Therefore, how to eliminate burst traffic and optimize hardware implementation while achieving zero-rounding accuracy is a technical problem that urgently needs to be solved. Summary of the Invention
[0009] To address one of the aforementioned technical problems, the present invention adopts the following technical solution:
[0010] According to one aspect of the present invention, a traffic shaping method based on asynchronous dual-authorization value is provided, characterized in that it includes:
[0011] The fractional width is determined based on the smallest integer granularity; the fractional width is used to store the fractional part of the token.
[0012] Under the precision constraint of decimal places, and with the goal of zero shaping error, the first authorization value used by the token management side is derived in reverse. ;
[0013] On the data path side, use the second authorization value. Manage token consumption. It is an integer;
[0014] Establish and The mapping relationship between them;
[0015] According to the scheduling cycle, use Add tokens to the token bucket and store the fractional part of the tokens with a fractional bit width;
[0016] When a token is consumed on the data path side, the token consumed on the data path side will be allocated according to the mapping relationship. quantity The conversion to token management requires the following: The quantity.
[0017] According to a second aspect of the present invention, a traffic shaping system based on asynchronous dual-authorization value is provided, comprising:
[0018] The fractional width determination module is used to determine the fractional width based on the smallest integer granularity; the fractional width is used to store the fractional part of the token.
[0019] The first authorization value determination module is used to deduce the first authorization value used by the token management side in reverse, with the precision constraint of decimal places and the goal of zero shaping error. ;
[0020] The token consumption management module is used on the data path side to use a second authorization value. Manage token consumption. It is an integer;
[0021] The mapping relationship establishment module is used to establish... and The mapping relationship between them;
[0022] The token addition module is used to add tokens according to the scheduling cycle. Add tokens to the token bucket and store the fractional part of the tokens with a fractional bit width;
[0023] The token consumption conversion module is used to convert the tokens consumed on the data path side into a valid token consumption conversion value based on the mapping relationship. quantity The conversion to token management requires the following: The quantity.
[0024] This invention has at least one of the following beneficial effects:
[0025] 1. Achieve near-zero error in integer shaping accuracy, fundamentally solving the problem of insufficient precision caused by integer rounding.
[0026] In the existing technology, the data path module only supports integer operations, and the authorized value must be rounded to an integer (e.g., 10.667 is rounded to 11), which inevitably introduces rounding error.
[0027] According to the present invention, "under the precision constraint of the decimal width, with the goal of zero shaping error, the first authorized value used by the token management side is derived in reverse." As can be seen from the technical means, this invention uses zero error as the target constraint for reverse derivation, rather than passively accepting error under a fixed authorized value, so that the derived result... Under this fractional-bit precision constraint, the number of tokens corresponding to each integer forming rate can be accurately represented, thus avoiding calculation errors introduced by rounding the grant value. Because It is derived from the reverse derivation of the fractional digit width precision. The fractional digit width itself is determined based on the smallest integer granularity. Therefore, even at the smallest integer granularity, the calculation of the number of tokens does not produce rounding error, thus achieving an essential improvement in integer precision.
[0028] 2. It achieves lossless storage of the decimal part of the token, avoiding the accumulation of rounding errors in the decimal part during long-term operation.
[0029] Based on the technical means described in this invention, namely "determining the decimal width according to the minimum shaping granularity" and "storing the decimal part of the token with the stated decimal width," this invention determines the decimal width according to the minimum shaping granularity, ensuring that the decimal width accurately represents the decimal part of the number of tokens to be added in each scheduling cycle under the minimum shaping granularity. Therefore, the decimal part generated each time a token is added can be stored losslessly, avoiding rounding errors caused by insufficient decimal width. Furthermore, the decimal part remains accurate throughout the accumulation process, preventing the accumulation of rounding errors from affecting the accuracy of the token bucket balance, thus ensuring the stability of traffic shaping during long-term operation.
[0030] 3. By using asynchronous dual authorization values, the contradiction between the inability of the same authorization value to simultaneously satisfy integer operation constraints and high precision requirements is resolved. This achieves unified measurement of token addition and consumption, ensuring the accuracy of the token bucket balance in long-term operation.
[0031] According to the present invention, "on the token management side, the first authorized value is used..." "On the data path side, use the second authorized value." "For integers" "Establish" and The mapping relationship between them” and “according to the mapping relationship, the data path side consumed” quantity The conversion to the token management side requires consumption. Using the technical means of "quantity", this invention maintains the fractional authorization value on both the token management side and the data path side. And integer authorized value Both sides operate independently and are not dependent on each other—the token management side uses... The add operation is performed independently, and the data path is used. Independent execution of consumption management operations constitutes the characteristic value of asynchronous dual authorization. Based on this, by establishing a mapping relationship between the two, each time a token is consumed on the data path side, the consumed token can be recorded. The quantity is precisely converted to the corresponding token management side. Quantity. Through the combined benefits of the aforementioned asynchronous dual authorization, this invention enables the data path side to function normally without modifying its integer arithmetic hardware, while the token management side can use decimals. This achieves high-precision addition, overcoming the contradiction that a single authorization value cannot simultaneously satisfy integer operation constraints and high-precision requirements; furthermore, because consumption is converted through mapping... Both the addition and consumption of tokens on the token management side are measured in the same unit. By measuring the token bucket balance, systematic deviations in the balance due to the use of different units of measurement for addition and consumption are avoided, thus ensuring long-term consistency between the token bucket balance and the theoretical value. Attached Figure Description
[0032] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0033] Figure 1 A flowchart of a flow shaping method based on counting cycle optimization provided in an embodiment of the present invention.
[0034] Figure 2 A flowchart illustrating a traffic shaping method based on asynchronous dual-authorization value provided in an embodiment of the present invention. Detailed Implementation
[0035] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0036] As a possible first embodiment of the present invention, such as Figure 1 As shown, this embodiment provides a flow shaping method based on counting period optimization, including the following steps:
[0037] Step 101: Starting from the baseline value, generate candidate counting cycle values sequentially by incrementing the value. For each candidate counting cycle value... Perform the following steps respectively and steps The candidate counting cycle value is obtained. The corresponding shaping error and the candidate counting period value The number of multipliers required for computation is added by the execution token. The baseline value is the scheduling period.
[0038] Step 101 generates candidate counting cycle values by sequentially incrementing from the baseline value, specifically including:
[0039] Starting from the base value, the candidate count cycle value is incremented one by one in a step of one clock cycle.
[0040] The scheduling cycle is 32 clock cycles.
[0041] The scheduling cycle (32 clock cycles) is the minimum number of clock cycles for a chip to perform a scheduling operation, and it is also the minimum time unit for hardware pipeline processing. The time interval for any token addition operation cannot be less than this value. Therefore, the scheduling cycle is used as the base value for enumeration.
[0042] Enumeration is performed by incrementing the count by one clock cycle to ensure that no candidate cycle value is missed, thus enabling the precise finding of the optimal solution that simultaneously satisfies accuracy and hardware simplification requirements. The upper limit of the enumeration does not need to be preset; it stops once a value satisfying the conditions is found. This ensures that the obtained count cycle value is the smallest value that satisfies the conditions, thereby avoiding other problems caused by excessively large count cycles.
[0043] By systematically enumerating candidate counting cycle values, a foundation is laid for subsequent screening of counting cycles that can simultaneously meet the two conditions of "high precision" and "single multiplier".
[0044] Step A: Calculate the shaping error Error, which satisfies the following condition:
[0045]
[0046] in, For the configured shaping rate, For licensing value, Main frequency, This is for rounding down.
[0047] Licensing value The following conditions must be met:
[0048]
[0049] in, To achieve the maximum shaping rate, For the scheduling period, Main frequency, This is for rounding up.
[0050] In the data path module, all calculations are integer operations and decimals are not supported; therefore, the licensing value is limited. The number of tokens must be rounded to the nearest integer. If the actual calculated theoretical number of tokens is not... When the value is an integer multiple of the integer, only the decimal part can be discarded (i.e., rounded down to the nearest integer). (integer multiples of), thus causing a deviation in the number of tokens. It is the theoretical number of tokens that should be added; it is a continuous value. This is the actual number of tokens that can be added; it must be... The absolute value of the difference between the two is an integer multiple of the total. This is the relative error, which reflects the degree to which the rounding operation affects the accuracy of the rounding operation.
[0051] Licensing value The maximum shaping rate, scheduling cycle, and clock frequency jointly determine the throughput: at the maximum shaping rate, the number of packets to be processed in each scheduling cycle is rounded up. The resulting integer value ensures that the throughput is not insufficient due to rounding at the maximum rate, while also ensuring... The value of has a fixed physical meaning, which facilitates uniform calculation at different rates.
[0052] This step enables a quantitative evaluation of any candidate counting period value. The impact on shaping accuracy provides a comparable quantitative indicator for subsequent screening of counting cycles that meet accuracy requirements.
[0053] Step B: Determine whether adding the execution token can reduce the number of multipliers.
[0054] when At that time, determine the multiplication by the candidate counting period value. Divide by the clock speed The operation can be replaced by a right shift. For bit shifting operations, only one multiplier is required.
[0055] when At that time, determine the multiplication by the candidate counting period value. Divide by the clock speed The operation still requires a multiplier, and two multipliers are needed.
[0056] In the token addition calculation, the complete formula is: If you calculate directly using this formula, you need to first... Multiply and divide by This involves the cascading of two multipliers.
[0057] However, in digital logic, dividing by (Frequency) and multiplied by (Counting period) can be combined into multiplication by .when Multiplying by this value is equivalent to shifting to the right. Bitwise shifting operations can be implemented in hardware with just wiring, without consuming multiplier resources, and the latency is much lower than that of a multiplier. When this condition is not met, a second multiplier must be used to complete the multiplication and division operations.
[0058] The purpose of step B is to filter out candidate counting cycle values that can reduce the number of multipliers from two to one, thereby simplifying the hardware implementation as much as possible while meeting accuracy requirements. This criterion allows us to filter out special values "related to powers of 2" from the numerous enumerated candidate values, enabling the hardware design to use an architecture of one multiplier and one shifter, avoiding the critical path delay problem caused by cascading two multipliers.
[0059] Step 102: Select candidate counting cycle values that simultaneously satisfy the first and second conditions. The optimal counting period is determined by the following conditions: the first condition is that Error is less than or equal to the preset precision threshold, and the second condition is that the number of multipliers is one.
[0060] Specifically, the preset accuracy threshold can be one-thousandth.
[0061] Step A provides the error quantification metric, and step B provides the result of determining the number of multipliers. However, these two conditions are separate: one value may meet the accuracy requirements but require two multipliers (due to timing pressure), while the other value may only require one multiplier but fail to meet the accuracy requirements. Only by simultaneously satisfying both conditions can we ensure both shaping accuracy and optimize hardware implementation.
[0062] The preset accuracy threshold is one-thousandth, which is sufficient to meet the needs of most traffic shaping applications. However, this accuracy value is not fixed; those skilled in the art can adjust the threshold adaptively according to specific usage scenarios and accuracy requirements.
[0063] The second condition of having only one multiplier is that the architecture of a single multiplier plus a shifter can completely avoid the critical path delay problem caused by the cascading of two multipliers, while two multipliers cannot achieve this optimization goal.
[0064] By filtering under two conditions, a unique optimal counting cycle value can be obtained, which ensures that the shaping error is within an acceptable range and achieves the simplification of the hardware architecture.
[0065] As an example, in the clock speed The scheduling cycle is 32 clock cycles, and the authorized value is... Under the given conditions, the optimal counting period can be obtained through the above enumeration and screening. ,and Based on this, we can further solve for... .
[0066] The detailed derivation process is as follows:
[0067] The first step is to determine the value of the license. .
[0068] At maximum shaping rate Mega PPS, main frequency Scheduling cycle During the shooting, 11.
[0069] The second step is to enumerate candidate counting cycle values.
[0070] from Initially, the step size is increased gradually by 1 beat, for each... Calculate separately:
[0071] (1) Accuracy condition verification:
[0072] Calculate the error. Verify the minimum reshaping rate. PPS and maximum shaping rate At megaPPS, are the error rates all below one in a thousand?
[0073] (2) Verification of the number of multipliers: Verification Is it equal to .
[0074] When enumeration reaches hour, ,and The closest to that value, i.e. ,satisfy The conditions. At the same time, At that point, the error had dropped to below one-thousandth, meeting the preset accuracy threshold. Therefore... It was determined to be the optimal counting period.
[0075] The above example illustrates that, under actual hardware configuration (1.2GHz clock speed, 32-cycle scheduling period) and shaping requirements (1PPS to 400 Mbps), the enumeration filtering method of this invention, when enumerating to... At that time, both conditions are satisfied simultaneously, therefore It is determined to be the optimal counting period, at this time .
[0076] Step 103: According to the optimal counting cycle, use a multiplier to perform token addition calculation and add tokens to the token bucket.
[0077] Step 103 specifically includes:
[0078] Configure the shaping rate With the value of licensing Multiply them to get the first product.
[0079] Shift the first product to the right The system retrieves the number of tokens to be added and adds that number of tokens to the token bucket.
[0080] When the optimal counting period satisfy At that time, the complete token addition calculation It can be rewritten as .because and The product is done in the first multiplier, multiplied by In binary arithmetic, this is equivalent to a right shift. Therefore, the entire calculation process requires only one multiplication ( ). ) and one shift (right shift) It can be completed in one step (1), without the need for a second multiplier.
[0081] By replacing multiplication operations with shift operations, the critical path delay problem caused by cascading two multipliers is avoided, significantly reducing the pressure on chip timing convergence. Furthermore, the shifter only requires wiring in hardware implementation, without introducing additional latency and area overhead, making the overall hardware architecture simpler and more efficient.
[0082] Example 1 improves shaping accuracy by enumerating and selecting the optimal counting period, while utilizing... The characteristic of this method reduces the number of multipliers from two to one, effectively alleviating the timing convergence pressure caused by cascading two multipliers. However, this scheme has an inherent limitation: when the optimal counting period... When the time is much greater than the scheduling period (32 cycles) (e.g.) The number of tokens that need to be added each time increases significantly. The token bucket cannot obtain new tokens during a long counting period. Once it does obtain new tokens, they flood in all at once, causing a traffic burst. This contradicts the original intention of traffic shaping to "smooth traffic".
[0083] Therefore, based on Example 1, Example 2 fundamentally solves the above problems by introducing an asynchronous dual-authorization value mechanism. The core idea of Example 2 is to maintain two different authorization values on the token management side and the data path side respectively: the token management side uses a fractional authorization value. Perform high-precision addition, using integer authorization values on the data path side. Consumption management is implemented, and the two are accurately converted through a mapping relationship, thereby achieving zero-error shaping while maintaining high-frequency addition (short counting cycle) and completely eliminating sudden traffic.
[0084] like Figure 2 As shown, as a second possible embodiment of the present invention, a traffic shaping method based on asynchronous dual-authorization value is provided, including the following steps:
[0085] Step 201: Determine the decimal width based on the minimum integer granularity; the decimal width is used to store the fractional part of the token.
[0086] Step 201 specifically includes:
[0087] Step 201.1: Obtain the minimum shaping granularity .
[0088] Step 201.2: According to Calculate the theoretical number of tokens to be added per scheduling cycle at the minimum integer granularity. For the scheduling period, Main frequency.
[0089] Step 201.3: Convert the theoretical token quantity into authorized value units to obtain... .
[0090] Step 201.4: Under the minimum shaping granularity, when using a bit width of When storing binary decimals, the storage precision is 1. .
[0091] Step 201.5: [The following is a list of steps / conditions] The smallest The value is determined as the decimal places width.
[0092] Based on the above, the decimal width can specifically be 29 bits.
[0093] At the smallest integer granularity (e.g., 1 PPS), the number of tokens to be added in each scheduling cycle is extremely small. If the decimal width is insufficient, this tiny amount cannot be accurately represented and can only be rounded to 0 or an approximate value. This results in tokens never being added at the smallest granularity, or the amount added deviating from the theoretical value, causing the integer function to fail.
[0094] By determining the fractional bit width based on the smallest integer granularity, this fractional bit width can accurately represent the amount of tokens added at the smallest granularity, thereby ensuring storage accuracy across the entire rate range.
[0095] As an example, in the clock speed Scheduling cycle Shot, maximum shaping rate Under a typical configuration of megaPPS:
[0096] Step 201.1: Minimum Shaping Granularity PPS;
[0097] Step 201.2: Calculate the Token (a packet);
[0098] Step 201.3: Convert the theoretical token quantity into authorized value units. The conversion method is to divide by the authorized value, here rounded up to the nearest integer at the maximum rate. Based on the conversion, we obtain the Token. (Each authorized unit of value);
[0099] Step 201.4: When using a bit width of When storing binary decimals, the storage precision is 1. ;
[0100] Step 201.5: Verify each Does the value satisfy? .
[0101] The following table gives the various Validation results of the value:
[0102] Table 1
[0103]
[0104] As shown in Table 1, when When storage precision is insufficient, The requirement for precise representation is first met at this time, therefore the minimum value that satisfies the condition is... The value is 29, meaning the decimal width is 29 bits.
[0105] Step 202: Under the precision constraint of decimal places, and with the goal of zero shaping error, deduce the first authorized value used by the token management side in reverse. .
[0106] Step 202 specifically includes:
[0107] Step 202.1: Under the precision constraint of decimal place width, establish the error equation Error, which satisfies the following conditions.
[0108]
[0109]
[0110]
[0111] in, For the configured shaping rate, For the scheduling period, Main frequency, To round down;
[0112] Step 202.2: Let Error Solving under the precision constraint of decimal place width .
[0113] As an example, in the clock speed Scheduling cycle Clock cycles, maximum shaping rate Under the condition of megaPPS, the value of the second license According to the formula Calculated Further reverse derivation as described above yields the value of the first authorization. .
[0114] Secondary Authorization Value The following conditions must be met:
[0115]
[0116] in, To achieve the maximum shaping rate, For the scheduling period, Main frequency, For rounding up; maximum shaping rate As mentioned above The values are the same.
[0117] It should be noted that the second authorized value in this embodiment Compared with the authorized value in Example 1 Although the calculation formulas are the same, they play different roles in this invention: in Example 1 It is the sole authorized value, used for token addition calculations within a single value system; while in this embodiment... It is the second authorization value in the asynchronous dual authorization value system, which is related to the first authorization value on the data path side. When used together, the two constitute the asynchronous dual-licensing value feature of this invention.
[0118] The existing approach is to first determine the licensing value (rounded to an integer), then calculate the resulting error, and finally try to reduce the error. The present invention takes the opposite approach: it first sets "zero error" as the target constraint, and then works backward to determine the required licensing value to achieve this goal. Under the constraint of a given decimal place width precision, This is the theoretical number of tokens that should be added. This is the actual number of tokens that can be added (it must be) (integer multiples of). Let Error That is, requirements This means It must be exactly The value is an integer multiple of the given value. Solving this equation under the constraint of decimal place width precision yields the authorized value that satisfies the zero-error condition.
[0119] Since this value is derived by working backward from the decimal place width precision, and the decimal place width itself is determined based on the minimum integer granularity, this value can ensure that token addition does not produce rounding errors even at the minimum integer granularity, thus fundamentally solving the problem of accumulated errors introduced by rounding fixed authorization values in existing technologies.
[0120] The specific process of reverse derivation is as follows:
[0121] In Error Under the constraints, requirements ,Right now:
[0122] The condition for the above formula to be true is It is an integer, that is It must be Integer multiples of. For any configured integer shaping rate. MegaPPS , .
[0123] Given the precision constraint of 29 bits for the fractional part, a solution needs to be found across the entire data rate range. This makes all All Integer multiples of. Through the... Solving for all possible values from 1 to 400M yields a unique result. .
[0124] Specific verification:
[0125] when During PPS, After dividing by 14.31, it is approximately This value has a precision of 29 bits (minimum precision). The following can be precisely represented, that is It is an integer.
[0126] when At 1 megaPPS, Dividing by 14.31 yields approximately 0.745, which can also be accurately represented with 29-bit precision.
[0127] For any value between 1 and 400 megabytes The calculation results are similar for all of them. Therefore, it can be seen that... It can achieve full-rate range at 29-bit precision. All Multiples of integers, thus implementing Error. .
[0128] Step 203: On the data path side, use the second authorization value. Manage token consumption. It is an integer.
[0129] Based on the above, the scheduling cycle is specifically 32 clock cycles.
[0130] The hardware architecture of the data path module is fixed, supporting only integer operations and unable to perform high-precision decimal operations. Forcing the DPM module to support decimal operations would significantly increase hardware complexity and path latency.
[0131] Therefore, this invention retains an integer license value on the data path side. (e.g., 11) This ensures full compatibility with existing hardware, requiring no modifications to the data path module. Simultaneously, the scheduling cycle remains at 32 clock cycles, enabling frequent token addition operations with only a small number of tokens added each time, thus completely avoiding the problem of large token backlogs caused by increased counting cycles.
[0132] By using integer authorization values on the data path side This allows the present invention to be fully compatible with existing data path module integer arithmetic hardware without any hardware modification, significantly reducing implementation costs.
[0133] Step 204: Establish and The mapping relationship between them.
[0134] Step 204 specifically includes:
[0135] Step 204.1: According to and Calculate the ratio satisfy
[0136] Step 204.2: [The text appears to be incomplete and contains several grammatical errors. A more accurate translation It is stored in the configuration register as a fixed-point number; the decimal width of the fixed-point number is the decimal width.
[0137] Because the token management side uses Add (decimals), used on the data path side. Consumption management is based on (integers), and these are two independent value systems. When a data packet is sent, the data path consumes [amount / cost]. indivual If a unit has tokens, how many should the token management side deduct? Unit tokens? This requires a conversion relationship.
[0138] because and All are known fixed values, and their ratio It is a fixed constant, By pre-storing the fixed-point numbers in the configuration register, conversions can be performed quickly each time they are consumed. The decimal width of the fixed-point numbers remains consistent with the aforementioned decimal width to ensure no loss of conversion accuracy.
[0139] This was achieved by pre-storing the ratio. and The precise conversion between them ensures that the consumption on the data path side is accurately reflected in the token balance on the token management side, ensuring consistent measurement of additions and consumptions.
[0140] Step 205: According to the scheduling cycle, use Add a token to the token bucket and store the fractional part of the token with a fractional bit width.
[0141] A scheduling cycle (e.g., 32 clock cycles) is the smallest unit of time for hardware to perform scheduling operations. It is used according to the scheduling cycle. Adding tokens means that tokens are added frequently, with a small number of tokens added each time, thus avoiding the problem of a large influx of tokens at once after they have been accumulating in the bucket for a long time.
[0142] Meanwhile, since the number of tokens added each time may not be an integer (especially when the configured integer rate is low), the resulting decimal part must be stored and accumulated into the next addition; otherwise, accumulated errors will occur due to rounding. Storing the decimal part of the tokens with the bit width determined in step 201 ensures that the decimal part of each addition is accurately recorded and accumulated. By maintaining a high frequency of token additions during the scheduling cycle, the problem of traffic bursts is fundamentally eliminated, achieving true traffic smoothing. Simultaneously, the lossless storage of the decimal part guarantees the accuracy of the token bucket balance during long-term operation.
[0143] Step 206: When the data path side consumes a token, according to the mapping relationship, the token consumed by the data path side... quantity The conversion to token management requires the following: The quantity.
[0144] Step 206 specifically includes:
[0145] Quantity used With the configuration register stored Multiply them to get the product;
[0146] Shifting the product right by the number of decimal places gives the amount of data required by the token management side. The quantity.
[0147] Each time a data packet is sent, the data path side consumes a certain amount of resources. Tokens. To keep the token balance on the token management side synchronized with the consumption on the data path side, the consumed tokens must be... Quantity converted to corresponding The quantity is deducted from the token management side.
[0148] The conversion method is as follows:
[0149] Consumed quantity Multiply by the ratio ,because Stored in fixed-point format. Its decimal places are [number]. Therefore, the product is shifted to the right. The corresponding bit can be obtained. Quantity. This entire operation is completed on the token management side; the data path side only needs to report the consumption. quantity There's no need to worry about the conversion process.
[0150] Through mapping calculations, it is ensured that the token balance on the token management side is always precisely synchronized with actual consumption, with both additions and consumptions made in accordance with the mapping relationship. To standardize the units of measurement and avoid systematic deviations in the token bucket balance caused by inconsistent units of measurement, the long-term consistency between the token bucket balance and the theoretical value is guaranteed.
[0151] In summary, Implementation Example 2 maintains fractional authorization values on both the token management side and the data path side through an "asynchronous dual authorization value" mechanism. And integer authorized value Both sides operate independently and are not dependent on each other, which constitutes the core characteristic of asynchronous dual authorization. This is achieved through determining the decimal width and reverse derivation. By combining a series of methods such as establishing mapping relationships, high-frequency addition, and accurate conversion, Example 2 simultaneously achieves several beneficial effects, including zero-error lossless storage of the decimal part of the shaped fraction, and a balance between hardware compatibility and high precision.
[0152] Furthermore, although the steps of the method in this disclosure are described in a specific order in the accompanying drawings, this does not require or imply that the steps must be performed in that specific order, or that all the steps shown must be performed to achieve the desired result. Additional or alternative steps may be omitted, multiple steps may be combined into one step, and / or a step may be broken down into multiple steps.
[0153] Furthermore, the accompanying drawings are merely illustrative of the processes included in the method according to exemplary embodiments of the present invention and are not intended to be limiting. It is readily understood that the processes shown in the above drawings do not indicate or limit the temporal order of these processes. Additionally, it is readily understood that these processes may be executed synchronously or asynchronously, for example, in multiple modules.
[0154] It should be noted that although several modules or units for the device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to embodiments of this disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0155] The above are merely specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A traffic shaping method based on asynchronous dual-authorization value, characterized in that, include: Determine the decimal place width based on the minimum granularity of the forming process; The fractional bit width is used to store the fractional part of the token; Under the precision constraint of the aforementioned decimal place width, and with the objective of zero shaping error, the first authorization value used by the token management side is derived in reverse. ; On the data path side, use the second authorization value. Manage token consumption. It is an integer; Establish and The mapping relationship between them; According to the scheduling cycle, use Add a token to the token bucket and store the fractional part of the token with the fractional bit width; When the data path side consumes a token, according to the mapping relationship, the token consumed by the data path side... quantity The conversion to the token management side requires consumption. The quantity.
2. The method according to claim 1, characterized in that, The step of determining the decimal width based on the minimum granularity of the forming process includes: Obtain the smallest shaping granularity ; according to Calculate the theoretical number of tokens to be added per scheduling cycle at the minimum integer granularity; where For the scheduling period, Main frequency; The theoretical token quantity is converted into authorized value units, and the converted theoretical token quantity is... ; At the minimum shaping granularity, when a bit width of When storing binary decimals, the storage precision is 1. ; Will satisfy The smallest The value is determined to be the decimal width.
3. The method according to claim 2, characterized in that, The decimal width is 29 bits.
4. The method according to claim 1, characterized in that, The reverse-derivative token management side uses include: Under the precision constraint of the aforementioned decimal place width, an error equation is established. , The following conditions must be met: ; ; ; in, For the configured shaping rate, For the scheduling period, Main frequency, To round down; make Solve under the precision constraint of the decimal place width .
5. The method according to claim 4, characterized in that, At the main frequency The scheduling period One clock cycle, large shaping rate The second authorized value Under the conditions, the first authorized value .
6. The method according to claim 1, characterized in that, The establishment and The mapping relationships between them include: according to and Calculate the ratio ; satisfy ; Will It is stored in the configuration register in the form of a fixed-point number; wherein the decimal width of the fixed-point number is the decimal width.
7. The method according to claim 6, characterized in that, When the data path side consumes a token, according to the mapping relationship, the token consumed by the data path side... quantity The conversion to the token management side requires consumption. The quantity includes: Quantity used With the configuration register stored Multiply them to get the product; Shifting the product right by the number of decimal places corresponding to the decimal width yields the amount of data required by the token management side. The quantity.
8. The method according to claim 1, characterized in that, The scheduling cycle is 32 clock cycles.
9. The method according to claim 1, characterized in that, Second authorized value The following conditions must be met: ; in, To achieve the maximum shaping rate, The scheduling period is... Main frequency, This is for rounding up.
10. A traffic shaping system based on asynchronous dual-authorization value, characterized in that, include: The decimal width determination module is used to determine the decimal width based on the minimum integer granularity. The fractional bit width is used to store the fractional part of the token; The first authorization value determination module is used to deduce the first authorization value used by the token management side in reverse, with the goal of zero shaping error, under the precision constraint of the decimal width. ; The token consumption management module is used on the data path side to use a second authorization value. Manage token consumption. It is an integer; The mapping relationship establishment module is used to establish... and The mapping relationship between them; The token addition module is used to add tokens according to the scheduling cycle. Add a token to the token bucket and store the fractional part of the token with the fractional bit width; The token consumption conversion module is used to convert the tokens consumed on the data path side into a token consumption conversion value according to the mapping relationship when the data path side consumes tokens. quantity The conversion to the token management side requires consumption. The quantity.