Token adding quantity configuration method and device, storage medium and electronic equipment
By configuring parameters in the register, the number of single token additions is flexibly calculated based on the clock frequency and shaping rate, which solves the problem of customizing the number of token additions for different chip designs and improves reusability and inheritance.
Patent Information
- Application Number
- CN202410766451.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-13
- Publication Date
- 2024-10-11
AI Technical Summary
Different chip designs need to customize the number of tokens added at a time according to the clock frequency and shaping rate range, resulting in poor reusability and inheritance.
By determining the clock frequency, shaping rate and minimum adding period of the target chip, calculate and configure the parameters in the register to flexibly configure the number of single token additions and avoid modifying the token bucket implementation plan due to changes in clock frequency.
It improves the reusability and inheritance of the token addition quantity configuration, simplifies the chip design and verification process, and adapts to the needs of various clock frequencies.
Smart Images

Figure CN118764437A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the computer field, and specifically, to a method and device for configuring the number of token additions, a storage medium, and an electronic device. Background Art
[0002] The Token Bucket algorithm is the most commonly used algorithm in traffic shaping and rate limiting. It can control the rate of data transmission, that is, limit the traffic.
[0003] In this algorithm, a fixed token bucket will add tokens at a constant rate. At the same time, the requester can obtain tokens from the token bucket, but each time the requester obtains a token, the requester must consume a certain amount of tokens. If there are not enough tokens in the token bucket, the requester cannot obtain tokens, thereby limiting the access rate of the requester. A token can represent a data packet or a byte. If it represents a data packet, then the token bucket ultimately implements pps shaping. If it represents a byte, then the token bucket ultimately implements bps shaping.
[0004] Specifically, the token bucket algorithm can be divided into two parts: token generation and token consumption.
[0005] Among them, the two important parameters for token generation are bucket depth and the number of tokens added at a time. The method of periodically adding tokens is the key to chip design and implementation. The strategy of adding tokens directly determines the accuracy of the token bucket and the effect of speed limit.
[0006] In the common implementation scheme of the general token bucket algorithm, the number of tokens added at a time is affected by the clock frequency and the configuration rate. Different chip designs need to customize the number of tokens added at a time according to the clock frequency and the speed limit range. Therefore, the reusability and inheritance are very poor, which not only brings a lot of workload to the chip design, but also greatly increases the complexity of verification.
[0007] Regarding the related technologies, different chip designs need to customize the number of tokens added at a time according to the range of clock frequency and shaping rate. Therefore, there is a problem of poor reusability and inheritance, and no effective solution has been proposed yet.
[0008] Therefore, it is necessary to improve the related technology to overcome the above-mentioned defects in the related technology. Summary of the invention
[0009] The embodiments of the present application provide a method and device for configuring the number of tokens to be added, a storage medium, and an electronic device, so as to at least solve the problem in the related art that different chip designs need to customize the solution for the number of tokens to be added at a time according to the range of clock frequency and shaping rate, and thus the reusability and inheritance are very poor.
[0010] According to one embodiment of the present application, a method for configuring the number of tokens added is provided, including: determining a clock frequency, a shaping rate, and a minimum addition period of a target chip, wherein the minimum addition period is used to indicate a minimum period for adding tokens to a token bucket of the target chip; determining a single number of tokens added according to the clock frequency, the shaping rate, and the minimum addition period; determining a value of a first parameter and a value of a second parameter according to the number of tokens added, wherein a first functional relationship exists between the number of tokens added and the first parameter and the second parameter; configuring the value of the first parameter and the value of the second parameter in a register to configure the number of tokens added.
[0011] In an exemplary embodiment, the number of tokens added at a single time is determined based on the clock frequency, the shaping rate and the minimum addition period, including: determining a target addition period based on the minimum addition period; determining a first product of the target addition period and the shaping speed, and determining a first quotient of the first product and the clock frequency; and determining the number of tokens added based on the first quotient.
[0012] In an exemplary embodiment, determining the value of a first parameter and the value of a second parameter based on the number of tokens added includes: determining a second quotient value between the number of tokens added and a target value, and determining a first size relationship between the second quotient value and a preset value; when the first size relationship indicates that the second quotient value is greater than or equal to the preset value, determining a third quotient value between the second quotient value and the target value, and determining a second size relationship between the third quotient value and the preset value; when the first size relationship indicates that the second quotient value is less than the preset value, determining whether the second quotient value is a value of the target type; when the second quotient value is a value of the target type, determining a fourth quotient value between the second quotient value and the target value, and determining whether the fourth quotient value is a value of the target type; when the second quotient value is not a value of the target type, determining the second quotient value to be the value of the first parameter; determining a fifth quotient value between the number of tokens added and the value of the first parameter; and determining the second parameter based on the fifth quotient value and the target value.
[0013] In an exemplary embodiment, after determining the value of the first parameter and the value of the second parameter according to the number of tokens added, the method further includes: determining the bucket depth of the token bucket and the multiple of the number of tokens added; determining the value of the third parameter and the value of the fourth parameter according to the multiple, the value of the first parameter and the value of the second parameter, wherein the bucket depth has a second functional relationship with the third parameter and the fourth parameter; configuring the value of the third parameter and the value of the fourth parameter in a register to configure the bucket depth of the token bucket.
[0014] In an exemplary embodiment, after configuring the value of the first parameter and the value of the second parameter in a register, the method further includes: determining the number of nodes in a single layer of a scheduler corresponding to the token bucket, wherein the scheduler is a scheduler of the target chip; determining a time period for adding tokens to the token bucket corresponding to each node based on the number of nodes and the minimum addition period; and adding the number of tokens to be added to the token bucket of each node based on the time period corresponding to each node.
[0015] In an exemplary embodiment, after adding the tokens of the token addition quantity to the token bucket of each node according to the time period corresponding to each node, the method further includes: determining the first total number of tokens of the token bucket corresponding to each node according to the token addition quantity and the remaining number of tokens of the token bucket corresponding to each node; determining whether the first total number of tokens is greater than the bucket depth of the token bucket corresponding to each node; if the first total number of tokens is greater than the bucket depth of the token bucket corresponding to each node, writing the value corresponding to the bucket depth into the target field in the memory corresponding to each node, wherein the target field is used to indicate the number of tokens in the token bucket corresponding to each node; if the first total number of tokens is less than or equal to the bucket depth of the token bucket corresponding to each node, writing the value corresponding to the first total number of tokens into the target field in the memory corresponding to each node.
[0016] In an exemplary embodiment, after configuring the value of the first parameter and the value of the second parameter in the register, the method further includes: upon receiving a chip processing message, obtaining a target number of tokens in the token bucket of the target node; upon obtaining the target number of tokens, determining whether there is a target operation to read and write the memory of the target node; in the absence of a target operation to read and write the memory of the target node, determining the second total number of tokens in the token bucket corresponding to the target node based on the target number and the remaining number of tokens in the token bucket corresponding to the target node; and writing the value corresponding to the second total number of tokens into the target field in the memory corresponding to the target node.
[0017] According to another embodiment of the present application, a device for configuring the number of tokens added is provided, including: a first determination module, used to determine the clock frequency, shaping rate and minimum addition period of a target chip, wherein the minimum addition period is used to indicate the minimum period for adding tokens to the token bucket of the target chip; a second determination module, used to determine the number of tokens added at a single time according to the clock frequency, shaping rate and minimum addition period; a third determination module, used to determine the value of a first parameter and the value of a second parameter according to the number of tokens added, wherein the number of tokens added has a first functional relationship with the first parameter and the second parameter; a configuration module, used to configure the value of the first parameter and the value of the second parameter in a register to configure the number of tokens added.
[0018] According to another embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when run.
[0019] According to another embodiment of the present application, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0020] According to another embodiment of the present application, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0021] Through the system in the present application, the clock frequency, shaping rate and minimum adding period of the target chip are determined, wherein the minimum adding period is used to indicate the minimum period for adding tokens to the token bucket of the target chip; the number of tokens added at a time is determined according to the clock frequency, shaping rate and minimum adding period; the value of the first parameter and the value of the second parameter are determined according to the number of tokens added, wherein the number of tokens added has a first functional relationship with the first parameter and the second parameter; the value of the first parameter and the value of the second parameter are configured in the register to configure the number of tokens added. In the embodiment of the present application, the number of tokens added at a time can be flexibly configured by flexibly configuring the values of the first parameter and the second parameter in the register, thereby achieving flexible configuration of the number of tokens added at a time. Therefore, the problem in the related art that different chip designs need to customize the number of tokens added at a time according to the range of clock frequency and shaping rate, and thus the problem of poor reusability and inheritance can be solved. The present application determines the clock frequency, shaping rate and minimum adding period according to the clock frequency, shaping rate and minimum adding period, and configures the value of the first parameter and the value of the second parameter in the register to configure the number of tokens to be added. The implementation scheme of the token bucket will not be modified due to the change of the clock frequency. Only the parameters in the register need to be adjusted, which greatly improves the reusability of this scheme. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The exemplary embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0023] Figure 1 It is a schematic diagram of the working principle of the token bucket in the related technology;
[0024] Figure 2 It is a hardware structure block diagram of a computer device of a method for configuring the number of token additions in an embodiment of the present application;
[0025] Figure 3 is a flowchart of a method for configuring the number of tokens added according to an embodiment of the present application;
[0026] Figure 4 It is a schematic diagram of adding tokens according to an embodiment of the present application;
[0027] Figure 5 is a flow chart of a token adding and deducting method according to an embodiment of the present application;
[0028] Figure 6 It is a schematic diagram of a method for calculating parameters of a token bucket according to an embodiment of the present application;
[0029] Figure 7is a flowchart of a method for calculating parameters of a token bucket according to an embodiment of the present application;
[0030] Figure 8 It is a structural block diagram of a device for configuring the number of tokens to be added according to an embodiment of the present application. DETAILED DESCRIPTION
[0031] The embodiments of the present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0032] It should be noted that the terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0033] In order to better understand the embodiments of the present application, the related technologies are described as follows:
[0034] The token bucket algorithm can be divided into two parts: token generation and token consumption. The working principle of the token bucket is as follows: Figure 1 shown.
[0035] Among them, token generation means: the token bucket generates tokens at a fixed rate (which can be understood as the token bucket being filled with water), and increases the number of tokens in the bucket, not exceeding the capacity of the bucket, which is the so-called bucket depth; if the number of tokens already in the bucket plus the number of generated tokens exceeds the capacity of the bucket, the number of tokens is overflowed; this fixed rate is the configuration rate of the token bucket, that is, the rate at which the token bucket needs to be limited.
[0036] Token consumption means: when a request comes, first check the number of tokens in the token bucket; if the number of tokens is greater than or equal to the number of tokens required for the request, issue a token and deduct the corresponding number of tokens from the token; if the number of tokens is less than the number of tokens required for the request, reject the request. Generally, for the sake of simplicity, as long as there are tokens in the token bucket, the required number of tokens will be deducted. After deduction, the remaining number in the token bucket is a negative number. Therefore, the standard for judging whether the token bucket can pass is to judge the sign bit of the remaining tokens.
[0037] The advantages of the token bucket algorithm include: it can limit traffic smoothly without sudden traffic limiting; it can be used in combination with other algorithms to increase network stability, etc.
[0038] The advantage of the token bucket current limiting algorithm is that it allows burst traffic, that is, the system allows some requests to take multiple tokens from the token bucket in a short period of time, so that burst traffic can be processed. The premise of allowing bursts is that the bucket depth is large and a large number of tokens are cached in the token bucket.
[0039] The disadvantage is that if the bucket capacity is large, the system will respond slowly; if the bucket capacity is small, it will not be able to handle burst traffic.
[0040] The token bucket algorithm is one of the more common current limiting algorithms, with the following characteristics:
[0041] 1. All requests need to obtain a valid token before they can be processed;
[0042] 2. According to the current limit size, set a certain rate to add tokens to the bucket;
[0043] 3. The bucket sets a maximum limit for placing tokens. When the bucket is full, newly added tokens are discarded or rejected, or overflow;
[0044] 4. After the request arrives, you must first obtain the token in the token bucket. Only with the token can you perform other business logic. After processing the business logic, the token will be deducted directly.
[0045] In this embodiment, a method for configuring the number of tokens to be added is provided. The method embodiment provided in the embodiment of the present application can be executed in a system for configuring the number of tokens to be added. The system for configuring the number of tokens to be added can be a computer device or a similar computing device. Taking running on a computer device as an example, Figure 2 1 is a hardware structure block diagram of a computer device for configuring the number of token additions in an embodiment of the present application. Figure 2 As shown, the computer device may include one or more ( Figure 2 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the above-mentioned computer device may also include a transmission device 106 and an input and output device 108 for communication functions. It can be understood by those skilled in the art that Figure 2 The structure shown is only for illustration and does not limit the structure of the above-mentioned computer device. Figure 2 More or fewer components as shown, or with Figure 2 Different configurations shown.
[0046] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the configuration method of the number of token additions in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0047] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer device. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0048] In this embodiment, a method for configuring the number of tokens to be added is provided. Figure 3 is a flowchart of a method for configuring the number of tokens added according to an embodiment of the present application, such as Figure 3 As shown, the process includes the following steps:
[0049] Step S302, determining the clock frequency, shaping rate and minimum adding cycle of the target chip, wherein the minimum adding cycle is used to indicate the minimum cycle for adding tokens to the token bucket of the target chip;
[0050] Step S304, determining the number of tokens added at a time according to the clock frequency, shaping rate and minimum adding period;
[0051] Step S306, determining a value of a first parameter and a value of a second parameter according to the number of tokens added, wherein a first functional relationship exists between the number of tokens added and the first parameter and the second parameter;
[0052] The first functional relationship can be expressed as: a=ir_b*2 ir_u , where a is the number of tokens added, ir_b is the first parameter, and ir_u is the second parameter.
[0053] Step S308, configuring the value of the first parameter and the value of the second parameter in the register to configure the number of tokens to be added.
[0054] Through the above steps, the clock frequency, shaping rate and minimum adding period of the target chip are determined, wherein the minimum adding period is used to indicate the minimum period for adding tokens to the token bucket of the target chip; the number of tokens added at a time is determined according to the clock frequency, shaping rate and minimum adding period; the value of the first parameter and the value of the second parameter are determined according to the number of tokens added, wherein the number of tokens added has a first functional relationship with the first parameter and the second parameter; the value of the first parameter and the value of the second parameter are configured in the register to configure the number of tokens added. In an embodiment of the present application, the number of tokens added at a time can be flexibly configured by flexibly configuring the values of the first parameter and the second parameter in the register, thereby achieving flexible configuration of the number of tokens added at a time. Therefore, the problem in the related art that different chip designs need to be customized according to the range of clock frequency and shaping rate to give a solution for the number of tokens added at a time, and thus the problem of poor reusability and inheritance can be solved. The present application determines the clock frequency, shaping rate and minimum adding period according to the clock frequency, shaping rate and minimum adding period, and configures the value of the first parameter and the value of the second parameter in the register to configure the number of tokens to be added. The implementation scheme of the token bucket will not be modified due to the change of the clock frequency. Only the parameters in the register need to be adjusted, which greatly improves the reusability of this scheme.
[0055] Optionally, the number of tokens to be added at a single time is determined based on the clock frequency, the shaping rate and the minimum addition period, including: determining a target addition period based on the minimum addition period; determining a first product of the target addition period and the shaping speed, and determining a first quotient of the first product and the clock frequency; and determining the number of tokens to be added based on the first quotient.
[0056] It should be noted that the target addition period can be a target multiple of the minimum addition period, that is, the target addition period is determined according to the actual situation and the minimum addition period, wherein the target addition period = tick*2 ir_s , where tick is the minimum addition period and ir_s is an unsigned integer.
[0057] In the embodiment of the present application, a method for determining the number of tokens added at a time is provided, specifically:
[0058] Among them, a is the number of tokens added at a time, shaping_rate is the shaping rate, clk_frequency is the clock frequency, tick*2 ir_s is the target clock period.
[0059] Through the embodiments of the present application, the number of single token additions corresponding to the current shaping rate and clock frequency can be quickly determined.
[0060] Optionally, the above step S306 can also be implemented in the following manner: determining a second quotient of the number of tokens added and the target value, and determining a first size relationship between the second quotient and a preset value; when the first size relationship indicates that the second quotient is greater than or equal to the preset value, determining the second quotient and the target number 1600=ir_b*2 ir_u value, and determine a second size relationship between the third quotient value and the preset value; in the case where the first size relationship indicates that the second quotient value is less than the preset value, determine whether the second quotient value is a value of the target type; in the case where the second quotient value is a value of the target type, determine a fourth quotient value of the second quotient value and the target value, and determine whether the fourth quotient value is a value of the target type; in the case where the second quotient value is not a value of the target type, determine the second quotient value to be the value of the first parameter; determine a fifth quotient value of the number of tokens added and the value of the first parameter; determine the second parameter based on the fifth quotient value and the target value.
[0061] It should be noted that the above target value can be understood as 2, the value of the above target type can be understood as an even number, and the value of the non-target type can be understood as an odd number.
[0062] In an embodiment of the present application, the number of tokens added is cyclically divided by the target value so that the obtained quotient is less than the preset value; when the quotient is less than the preset threshold, it is also necessary to determine whether the obtained quotient is an even number. When the obtained quotient is an even number, continue to cyclically divide by the target value until the final quotient is an odd number.
[0063] It should be noted that, when the second quotient obtained after the number of tokens added is divided by the target value has a decimal part, it is necessary to round the second quotient down to determine the third size relationship between the second quotient after rounding down and the preset value; when the first size relationship indicates that the second quotient is less than the preset value, determine whether the second quotient after rounding down is a value of the target type; when the second quotient after rounding down is not a value of the target type, determine that the second quotient after rounding down is the value of the first parameter.
[0064] The value of the second parameter mentioned above can be understood as the number of times the number of token additions is cyclically divided by the target value to obtain the value of the first parameter.
[0065] For example, assume that the chip design has a tick of 128, a clk_frequency of 1 GHz, and a shaping_rate of 100 Gbps. According to the above formula, 1600 = ir_b*2 ir-u
[0066] In the default case of ir_s=0, try to add tokens evenly. We use 1600 / 2=800, 800 / 2=400, 400 / 2=200...50 / 2=25, that is, 1600 divided by 6 times 2 equals 25, so the formula is:
[0067] 1600=25*2^6, then ir_b=25, ir_u=6, that is, the first parameter is 25 and the second parameter is 6.
[0068] Through the embodiments of the present application, the values of the first parameter and the second parameter are determined in a calculable manner. When the values of the second parameter and the second parameter are determined, the first parameter and the second parameter are configured to achieve the configuration of the number of tokens added at a single time. That is, the parameterized solution is adaptable to chip designs of various clock frequencies, and at most the bit width of the parameters needs to be adjusted according to different requirements. This greatly simplifies the logical implementation process of the previous token bucket algorithm, simplifies the verification process, and accelerates the convergence speed of the shaper verification.
[0069] Optionally, after determining the value of the first parameter and the value of the second parameter according to the number of tokens added, it includes: determining the bucket depth of the token bucket and the multiple of the number of tokens added; determining the value of the third parameter and the value of the fourth parameter according to the multiple, the value of the first parameter and the value of the second parameter, wherein there is a second functional relationship between the bucket depth and the third parameter and the fourth parameter; configuring the value of the third parameter and the value of the fourth parameter in a register to configure the bucket depth of the token bucket.
[0070] It should be noted that the second functional relationship can be expressed as: bucket depth bs = bs_b*2 bs_s , where bs_b is the third parameter and bs_s is the fourth parameter.
[0071] Optionally, the bucket depth of the token bucket is also an important parameter for implementing the token algorithm. Therefore, after configuring the number of tokens to be added, the bucket depth of the token bucket needs to be calculated and then configured. Generally, the bucket depth value that needs to be configured is greater than the number of tokens added at a time. The purpose of this constraint is to prevent the number of tokens added at a time from being greater than the bucket depth, which causes token overflow. This results in the loss of tokens that should have been cached, and the macro speed limit effect is that the actual traffic is less than the configured rate.
[0072] Assuming that the number of tokens added at a time is 1600, the minimum bucket depth can be set equal to the number of tokens added at a time, that is, bs_b = 25, bs_s = 6. The bucket depth can also be set to twice the number of tokens added at a time, that is, bs_b = 50, bs_s = 6 or bs_b = 25, bs_s = 7.
[0073] It should be noted that the above two bucket depth configurations can only meet the minimum requirements. If you want the token bucket to have a certain ability to resist sudden events, the bucket depth needs to be configured larger, such as 10 times the number of tokens added at a time.
[0074] Through the embodiments of the present application, when determining the number of tokens to be added in a single time, the third parameter and the fourth parameter can be determined based on the algorithm formula, and when the third parameter and the fourth parameter are configured in the register, the configuration of the bucket depth of the token bucket is completed. The parameterized token bucket implementation scheme will not modify the token bucket implementation scheme due to changes in the clock frequency, which greatly improves the reusability of this scheme.
[0075] Optionally, after configuring the value of the first parameter and the value of the second parameter in the register, it also includes: determining the number of nodes in a single layer of the scheduler corresponding to the token bucket, wherein the scheduler is the scheduler of the target chip; determining the time period for adding tokens to the token bucket corresponding to each node according to the number of nodes and the minimum addition period; and adding the token addition quantity of tokens to the token bucket of each node according to the time period corresponding to each node.
[0076] It should be noted that general token buckets are used on schedulers and are multi-level (such as HQoS-based schedulers). Each level of the scheduler has multiple nodes, so the minimum addition cycle is determined by the number of scheduling nodes in a single level and the timing of adding and deducting tokens at a single node. In general, token buckets in schedulers are implemented using random access memory (RAM). The performance of adding and deducting tokens needs to be considered. Token addition of all nodes at this level needs to be completed within one tick cycle, and token deduction time slots that meet the performance are reserved.
[0077] After determining the minimum adding period, determine the time period for adding tokens to the token bucket corresponding to each node according to the minimum adding period and the number of nodes; and add the tokens of the token adding number to the token bucket of each node according to the time period corresponding to each node. Through the embodiment of the present application, tokens can be added to the token buckets of multiple nodes in each level of the scheduler in an orderly and accurate manner, avoiding the problem of missing adding tokens to the token bucket of a certain node.
[0078] Optionally, after adding the number of tokens added to the token bucket of each node according to the time period corresponding to each node, the method further includes: determining the first total number of tokens of the token bucket corresponding to each node according to the number of tokens added and the remaining number of tokens in the token bucket corresponding to each node; determining whether the first total number of tokens is greater than the bucket depth of the token bucket corresponding to each node; if the first total number of tokens is greater than the bucket depth of the token bucket corresponding to each node, writing the value corresponding to the bucket depth into the target field in the memory corresponding to each node, wherein the target field is used to indicate the number of tokens in the token bucket corresponding to each node; if the first total number of tokens is less than or equal to the bucket depth of the token bucket corresponding to each node, writing the value corresponding to the first total number of tokens into the target field in the memory corresponding to each node.
[0079] It should be noted that when adding tokens to each node, the number of tokens of the node stored in RAM needs to be updated. The specific method is as follows: the result read out from RAM plus the number of tokens added is compared with the bucket depth. If it is greater than the bucket depth, the bucket depth will be written to RAM. If it is less than the bucket depth, the result will be written to RAM.
[0080] Optionally, after configuring the value of the first parameter and the value of the second parameter in the register, it also includes: when a chip processing message is received, obtaining a target number of tokens in the token bucket of the target node; when the target number of tokens is obtained, determining whether there is a target operation to read and write the memory of the target node; when there is no target operation to read and write the memory of the target node, determining the total number of second tokens in the token bucket corresponding to the target node based on the target number and the remaining number of tokens in the token bucket corresponding to the target node; and writing the value corresponding to the second total number of tokens into the target field in the memory corresponding to the target node.
[0081] In reality, there may be conflicts in read and write operations. In the event of a conflict in read and write operations, it is determined based on a preset periodic loop whether there is a target operation to read and write the memory of the target node, until it is determined that there is no target operation to read and write the memory of the target node, and then the total number of second tokens in the token bucket corresponding to the target node is determined based on the target number and the remaining number of tokens in the token bucket corresponding to the target node; the value corresponding to the second total number of tokens is written into the target field in the memory corresponding to the target node.
[0082] Obviously, the above-described embodiments are only a part of the embodiments of the present application, not all of the embodiments. In order to better understand the configuration method of the above-mentioned token addition quantity, the above-mentioned process is described below in conjunction with the embodiments, but it is not intended to limit the technical solution of the embodiments of the present application, specifically:
[0083] In the embodiment of the present application, a parameterized token bucket implementation algorithm is provided, which does not need to be redesigned according to the change of frequency, and the frequency is also a variable in the algorithm formula. This formula has a total of seven parameters, namely bs_b, bs_s, ir_b, ir_s, ir_u, tick and clock frequency clk_frequency, among which tick and clk_frequency are basically determined after the project specifications are determined. Therefore, there are a total of 5 configurable parameters, and the formula is as follows:
[0084] Shaping rate
[0085] Bucket depth
[0086] The shaping_rate formula can be simplified to:
[0087] where ir_b*2 ir_u Indicates the number of tokens added at a time, tick*2 ir_s Indicates the period for adding tokens, tick is the minimum period for adding tokens.
[0088] When the chip design is determined, the tick value is fixed, and the bit widths of ir_b, ir_u, ir_s, bs_b, and bs_s are determined according to the range of the integer. The above five parameters are all unsigned integers, and the minimum value is 0. In the above formula, the unit of clk_frequency is Hz, and ir_b*2 ir_u-ir_s The unit of is byte, and the unit of shaping_rate is bps.
[0089] For the token bucket algorithm, there are many ways to add tokens to achieve a fixed speed limit. You can choose to add many tokens per second to achieve the configured speed limit, or you can evenly distribute the tokens that need to be added per second into a smaller adding cycle. Comparing the two adding methods, from a micro perspective, it is obvious that the speed limit effect of the second method is more uniform. From a macro perspective, the second method has less jitter.
[0090] Combined with the period of adding tokens, it is tick*2 ir_s, that is to say, the larger ir_s is, the longer the adding cycle is, and the more tokens are added at a time. Generally, ir_s is set to 0, the purpose is to make the adding cycle shorter and the fewer tokens are added at a time, so the formula of shaping_rate can be further simplified as:
[0091]
[0092] Of course, ir_s may not be 0, for example, ir_s=1, which is equivalent to the period of adding tokens becoming twice that of ir_s=0. Assuming tick=128, the period of adding tokens becomes 256 clock cycles.
[0093] There is another situation where ir_s>ir_u. This situation is equivalent to ir_u-ir_s being a negative number. This situation is often used in some very small rate configurations.
[0094] For details of adding solutions, please refer to Figure 4 ,like Figure 4 As shown in the figure, general token buckets are used on schedulers and are multi-level, that is, the so-called HQoS-based scheduler. Each level of the scheduler has multiple nodes, so the tick is determined by the number of scheduling nodes in a single level and the timing of adding and deducting tokens in a single node. In general, token buckets in schedulers are implemented using RAM, and the performance of adding and deducting tokens needs to be considered. Token addition of all nodes in the level needs to be completed within one tick cycle, and token deduction time slots that meet the performance are reserved.
[0095] The specific token addition and deduction process is as follows Figure 5 As shown, the specific steps are as follows:
[0096] Step S501: Power on the token bucket;
[0097] Step S502: Initiate a read-modify-and-add-token operation on the RAM storing the token every tick cycle;
[0098] Step S503: responding to the read-modify-write operation;
[0099] Step S504: read out the token value corresponding to the token bucket, the result obtained by adding the token value and the number of added tokens (ir_b*2^ir_s) or subtracting tokens (-pkt_len); if the result is less than the bucket depth (bs_b*2^bs_s), the result is directly written back to the RAM, otherwise the bucket depth is written back to the RAM;
[0100] Step S505: when receiving the chip processing message, determine whether the token bucket has a token. If so, execute step S506; otherwise, wait until there is a token before processing.
[0101] Step S506: initiate a read-modify-reduction token operation on the RAM storing the token;
[0102] Step S507: Determine whether there is a conflict with the operation of adding a token. If there is a conflict, execute step S507 again based on a preset period, otherwise execute steps S503 and S504.
[0103] For example, if ir_s = 0, tick = 128, ir_b = 10, and ir_u = 5, then the number of tokens added at a time is 320 bytes, and the adding cycle is 128 clock cycles. Assuming the frequency is 1GHz, the speed limit under this configuration can be calculated to be 20Gbps. Figure 6 shown.
[0104] The present application also provides a method for calculating parameters of a token bucket. Figure 7 is a flow chart of a method for calculating parameters of a token bucket according to an embodiment of the present application, such as Figure 7 As shown, including:
[0105] according to Move all known variables to the left side of the formula, and then the right side of the formula is in the form of the variable multiplied by the power of 2. Then you can divide the constant on the left side of the simplified formula by 2 continuously until the result is a number between 0 and 128. Then ir_b is equal to the final result of the division, and ir_u is the number of divisions by 2.
[0106] Assume that the chip design tick is 128, clk_frequency is 1GHz, and shaping_rate is 100Gbps; substituting the known conditions into the above formula, we can get:
[0107] 1600 = ir_b * 2^(ir_u);
[0108] When ir_s=0, try to add tokens evenly, using 1600 / 2=800, 800 / 2=400, 400 / 2=200...50 / 2=25, that is, 1600 divided by 6 times 2 equals 25, so the formula is:
[0109] 1600=25*2^6; therefore, ir_b=25, ir_u=6.
[0110] For the configuration of bucket depth, the bucket depth value that needs to be configured is generally larger than the number of tokens added at a single time. The purpose of this constraint is to prevent the number of tokens added at a single time from being larger than the bucket depth, which will cause token overflow and result in loss of tokens that should have been cached. The macro speed limit effect is that the actual traffic is less than the configured rate.
[0111] From the above calculation results, it can be concluded that the number of tokens added at a time is 1600, so the minimum bucket depth can be set equal to the number of tokens added at a time, that is, bs_b = 25, bs_s = 6. The bucket depth can also be set to twice the number of tokens added at a time, that is, bs_b = 50, bs_s = 6 or bs_b = 25, bs_s = 7.
[0112] It should be noted that the above two bucket depth configurations can only meet the minimum requirements. If you want the token bucket to have a certain ability to resist sudden changes, the bucket depth needs to be configured larger, such as 10 times the number of tokens added at a time.
[0113] Through the embodiment of the present application, the parameterized token bucket implementation scheme will not be modified due to the change of the clock frequency, which greatly improves the reusability of this scheme. In different chip designs, we only need to adjust the bit width of the parameter and the size of the tick value according to the scope of shaping and current limiting, the number of network topology nodes, and the cost of implementation. The algorithm can greatly simplify the complexity of the token bucket algorithm used for shaping and speed limiting, and improves reusability, and does not need to be redesigned between projects.
[0114] In the present embodiment, a configuration device for adding the number of tokens is also provided, and the device is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.
[0115] Figure 8 is a structural block diagram of a device for configuring the number of token additions according to an embodiment of the present application, such as Figure 8 As shown, the device comprises:
[0116] A first determination module 82, used to determine a clock frequency, a shaping rate and a minimum adding cycle of a target chip, wherein the minimum adding cycle is used to indicate a minimum cycle for adding tokens to a token bucket of the target chip;
[0117] A second determination module 84, configured to determine the number of tokens to be added at a time according to the clock frequency, shaping rate and minimum adding period;
[0118] A third determination module 86, configured to determine a value of a first parameter and a value of a second parameter according to the number of tokens added, wherein a first functional relationship exists between the number of tokens added and the first parameter and the second parameter;
[0119] The configuration module 88 is used to configure the value of the first parameter and the value of the second parameter in the register to configure the number of tokens added.
[0120] Through the above-mentioned device, the clock frequency, shaping rate and minimum adding period of the target chip are determined, wherein the minimum adding period is used to indicate the minimum period for adding tokens to the token bucket of the target chip; the number of tokens added at a time is determined according to the clock frequency, shaping rate and minimum adding period; the value of the first parameter and the value of the second parameter are determined according to the number of tokens added, wherein the number of tokens added has a first functional relationship with the first parameter and the second parameter; the value of the first parameter and the value of the second parameter are configured in the register to configure the number of tokens added. In an embodiment of the present application, the number of tokens added at a time can be flexibly configured by flexibly configuring the values of the first parameter and the second parameter in the register, thereby achieving flexible configuration of the number of tokens added at a time. Therefore, the problem in the related art that different chip designs need to customize the number of tokens added at a time according to the range of clock frequency and shaping rate, and thus the problem of poor reusability and inheritance can be solved. The present application determines the clock frequency, shaping rate and minimum adding period according to the clock frequency, shaping rate and minimum adding period, and configures the value of the first parameter and the value of the second parameter in the register to configure the number of tokens to be added. The implementation scheme of the token bucket will not be modified due to the change of the clock frequency. Only the parameters in the register need to be adjusted, which greatly improves the reusability of this scheme.
[0121] In an exemplary embodiment, the second determination module 84 is used to determine the target addition period based on the minimum addition period; determine the first product of the target addition period and the shaping speed, and determine the first quotient of the first product and the clock frequency; and determine the token addition quantity based on the first quotient.
[0122] In an exemplary embodiment, the third determination module 86 is used to determine a second quotient of the number of tokens added and the target value, and to determine a first size relationship between the second quotient and a preset value; when the first size relationship indicates that the second quotient is greater than or equal to the preset value, determine a third quotient of the second quotient and the target value, and to determine a second size relationship between the third quotient and the preset value; when the first size relationship indicates that the second quotient is less than the preset value, determine whether the second quotient is a value of the target type; when the second quotient is a value of the target type, determine a fourth quotient of the second quotient and the target value, and determine whether the fourth quotient is a value of the target type; when the second quotient is not a value of the target type, determine the second quotient to be the value of the first parameter; determine a fifth quotient of the number of tokens added and the value of the first parameter; and determine the second parameter based on the fifth quotient and the target value.
[0123] In an exemplary embodiment, the third determination module 86 is used to determine the multiple of the bucket depth of the token bucket and the number of tokens added; determine the value of the third parameter and the value of the fourth parameter according to the multiple, the value of the first parameter and the value of the second parameter, wherein the bucket depth has a second functional relationship with the third parameter and the fourth parameter;
[0124] The configuration module 88 is used to configure the value of the third parameter and the value of the fourth parameter in the register to configure the bucket depth of the token bucket.
[0125] In an exemplary embodiment, the first determination module 82 is used to determine the number of nodes in a single layer of a scheduler corresponding to the token bucket, wherein the scheduler is a scheduler of the target chip; determine a time period for adding tokens to the token bucket corresponding to each node according to the number of nodes and the minimum addition period;
[0126] The above-mentioned device also includes: an adding module, which is used to add tokens of the token addition quantity to the token bucket of each node according to the time period corresponding to each node.
[0127] In an exemplary embodiment, the above-mentioned device also includes: a read-write module, which is used to determine the first total number of tokens of the token bucket corresponding to each node based on the number of tokens added and the remaining number of tokens in the token bucket corresponding to each node; determine whether the first total number of tokens is greater than the bucket depth of the token bucket corresponding to each node; when the first total number of tokens is greater than the bucket depth of the token bucket corresponding to each node, write the value corresponding to the bucket depth in the target field in the memory corresponding to each node, wherein the target field is used to indicate the number of tokens in the token bucket corresponding to each node; when the first total number of tokens is less than or equal to the bucket depth of the token bucket corresponding to each node, write the value corresponding to the first total number of tokens in the target field in the memory corresponding to each node.
[0128] In an exemplary embodiment, a read-write module is used to obtain a target number of tokens in a token bucket of a target node upon receiving a chip processing message; when the target number of tokens is obtained, determine whether there is a target operation to read or write the memory of the target node; when there is no target operation to read or write the memory of the target node, determine the second total number of tokens in the token bucket corresponding to the target node based on the target number and the remaining number of tokens in the token bucket corresponding to the target node; and write a numerical value corresponding to the second total number of tokens into a target field in the memory corresponding to the target node.
[0129] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0130] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:
[0131] S1, determining a clock frequency, shaping rate, and minimum adding cycle of a target chip, wherein the minimum adding cycle is used to indicate a minimum cycle for adding tokens to a token bucket of the target chip;
[0132] S2, determining the number of tokens added at a time according to the clock frequency, shaping rate and minimum adding period;
[0133] S3, determining a value of a first parameter and a value of a second parameter according to the number of tokens added, wherein a first functional relationship exists between the number of tokens added and the first parameter and the second parameter;
[0134] S4, configuring the value of the first parameter and the value of the second parameter in a register to configure the number of tokens to be added.
[0135] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0136] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0137] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0138] S1, determining a clock frequency, shaping rate, and minimum adding cycle of a target chip, wherein the minimum adding cycle is used to indicate a minimum cycle for adding tokens to a token bucket of the target chip;
[0139] S2, determining the number of tokens added at a time according to the clock frequency, shaping rate and minimum adding period;
[0140] S3, determining a value of a first parameter and a value of a second parameter according to the number of tokens added, wherein a first functional relationship exists between the number of tokens added and the first parameter and the second parameter;
[0141] S4, configuring the value of the first parameter and the value of the second parameter in a register to configure the number of tokens to be added.
[0142] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0143] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any one of the above method embodiments are implemented.
[0144] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0145] S1, determining a clock frequency, shaping rate, and minimum adding cycle of a target chip, wherein the minimum adding cycle is used to indicate a minimum cycle for adding tokens to a token bucket of the target chip;
[0146] S2, determining the number of tokens added at a time according to the clock frequency, shaping rate and minimum adding period;
[0147] S3, determining a value of a first parameter and a value of a second parameter according to the number of tokens added, wherein a first functional relationship exists between the number of tokens added and the first parameter and the second parameter;
[0148] S4, configuring the value of the first parameter and the value of the second parameter in a register to configure the number of tokens to be added.
[0149] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0150] The embodiments of the present application also provide a computer program, which includes computer instructions, which are stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the steps in any one of the above method embodiments.
[0151] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0152] Obviously, those skilled in the art should understand that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
[0153] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principles of the present application shall be included in the protection scope of the present application.
Claims
1. A method for configuring the number of token additions, characterized in that: include: Determine a clock frequency, shaping rate, and minimum adding cycle of a target chip, wherein the minimum adding cycle is used to indicate a minimum cycle for adding tokens to a token bucket of the target chip; Determine the number of tokens added at a single time according to the clock frequency, shaping rate and minimum adding period; Determine a value of a first parameter and a value of a second parameter according to the number of tokens added, wherein a first functional relationship exists between the number of tokens added and the first parameter and the second parameter; The value of the first parameter and the value of the second parameter are configured in a register to configure the number of tokens added.
2. The method according to claim 1, characterized in that The number of tokens added at a time is determined according to the clock frequency, shaping rate and minimum adding period, including: Determine a target addition period according to the minimum addition period; determining a first product of the target addition period and the shaping speed, and determining a first quotient of the first product and the clock frequency; The token addition quantity is determined according to the first quotient value.
3. The method according to claim 1, characterized in that Determining the value of the first parameter and the value of the second parameter according to the number of tokens added includes: Determine a second quotient of the number of tokens added and the target value, and determine a first magnitude relationship between the second quotient and a preset value; When the first magnitude relationship indicates that the second quotient is greater than or equal to the preset value, determining a third quotient of the second quotient and the target value, and determining a second magnitude relationship between the third quotient and the preset value; In a case where the first magnitude relationship indicates that the second quotient value is less than the preset value, determining whether the second quotient value is a value of a target type; In a case where the second quotient value is a numerical value of the target type, determining a fourth quotient value of the second quotient value and the target numerical value, and determining whether the fourth quotient value is a numerical value of the target type; If the second quotient value is not a value of the target type, determining the second quotient value to be a value of the first parameter; determining a fifth quotient of the number of tokens added and the value of the first parameter; The second parameter is determined according to the fifth quotient value and the target value.
4. The method according to claim 1, characterized in that: After determining the value of the first parameter and the value of the second parameter according to the number of tokens added, the method further includes: Determine a multiple of the bucket depth of the token bucket and the number of tokens added; Determining a value of a third parameter and a value of a fourth parameter according to the multiple, a value of the first parameter, and a value of the second parameter, wherein a second functional relationship exists between the bucket depth and the third parameter and the fourth parameter; The value of the third parameter and the value of the fourth parameter are configured in the register to configure the bucket depth of the token bucket.
5. The method according to claim 1, characterized in that After configuring the value of the first parameter and the value of the second parameter in the register, the method further includes: Determine the number of nodes of a single layer of the scheduler corresponding to the token bucket, wherein the scheduler is the scheduler of the target chip; Determine a time period for adding tokens to a token bucket corresponding to each node according to the number of nodes and the minimum adding period; Add the token addition quantity of tokens to the token bucket of each node according to the time period corresponding to each node.
6. The method according to claim 5, characterized in that After adding the token addition quantity of tokens to the token bucket of each node according to the time period corresponding to each node, the method further includes: Determine the total number of first tokens in the token bucket corresponding to each node according to the number of tokens added and the remaining number of tokens in the token bucket corresponding to each node; Determine whether the total number of the first tokens is greater than the bucket depth of the token bucket corresponding to each node; In the case where the total number of the first tokens is greater than the bucket depth of the token bucket corresponding to each node, a value corresponding to the bucket depth is written into a target field in the memory corresponding to each node, wherein the target field is used to indicate the number of tokens in the token bucket corresponding to each node; When the first total number of tokens is less than or equal to the bucket depth of the token bucket corresponding to each node, a value corresponding to the first total number of tokens is written into the target field in the memory corresponding to each node.
7. The method according to claim 1, characterized in that After configuring the value of the first parameter and the value of the second parameter in the register, the method further includes: When receiving the chip processing message, obtain the target number of tokens from the token bucket of the target node; When the target number of tokens is obtained, determining whether there is a target operation to read and write the memory of the target node; In the absence of a target operation of reading and writing the memory of the target node, determining the total number of second tokens of the token bucket corresponding to the target node according to the target number and the remaining number of tokens of the token bucket corresponding to the target node; A value corresponding to the total number of the second tokens is written into the target field in the memory corresponding to the target node.
8. A device for configuring the number of token additions, characterized in that: include: A first determination module is used to determine a clock frequency, a shaping rate and a minimum adding cycle of a target chip, wherein the minimum adding cycle is used to indicate a minimum cycle for adding tokens to a token bucket of the target chip; A second determination module, used to determine the number of tokens added at a single time according to the clock frequency, shaping rate and minimum adding cycle; A third determination module, configured to determine a value of a first parameter and a value of a second parameter according to the number of tokens added, wherein a first functional relationship exists between the number of tokens added and the first parameter and the second parameter; A configuration module is used to configure the value of the first parameter and the value of the second parameter in a register to configure the number of tokens added.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program implements the steps of the method according to any one of claims 1 to 7 when executed by a processor.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Message forwarding method and device
CN120512403A
