A message processing method and device

By processing token bucket addition and application operations in parallel without locks in multi-core processors, the problem of mutual exclusion of token bucket locks in multi-core network equipment that affects packet speed limit is solved, and the forwarding performance of multi-core processors is improved.

CN116016356BActive Publication Date: 2024-10-11MAIPU COMM TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111162501.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-30
Publication Date
2024-10-11
Estimated Expiration
2041-09-30

AI Technical Summary

Technical Problem

In multi-core network equipment, the token bucket serves as a locking mutual exclusion protection for critical resources, which affects packet rate-limiting forwarding performance and makes it impossible to achieve lock-free concurrency.

Method used

Using a multi-core processor, select one core Core0 to calculate the incremental value of the token bucket and accumulate it to the added statistical value. The other cores Corei perform message coloring and processing based on the remaining token values ​​to avoid locking and mutual exclusion operations and achieve lock-free parallelism. deal with.

Benefits of technology

Through lock-free parallel processing, tokens in each verification token bucket can be added and applied for without interference, which improves the packet forwarding performance when the token bucket is rate-limited, thereby improving the overall forwarding performance of multi-core processors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116016356B_ABST
    Figure CN116016356B_ABST
Patent Text Reader

Abstract

The present invention discloses a message processing method and device, which relates to the field of data communication. The method comprises: selecting a core Core0 of a multi-core processor to calculate a first token increment value of a token bucket according to a preset time period, and accumulating the first token increment value to a token addition statistic value; when any core Core0 is used ... i When there are messages to be forwarded, the core i Calculate the remaining token value of the current token bucket; according to the remaining token value, the core Core i Color the message, process the message according to the coloring result, and then Core i According to the actual forwarding volume of the message checked by this core, the application statistics of the token checked by this core are accumulated. The adoption of this application can ensure that multiple cores can add and apply for tokens in parallel without locks, avoiding the locking and mutual exclusion processing when multiple cores access the token bucket, and can greatly improve the message forwarding performance when the token bucket is speed-limited.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data communication, and in particular to a message processing method and device. Background Art

[0002] When transmitting messages in the network, in order to prevent network congestion, it is necessary to limit the messages flowing out of the network so that the messages are sent out at a relatively uniform speed. The token bucket algorithm implements this function, which can control the number of messages sent to the network and allow the sending of burst messages.

[0003] When sending a message to the network, the tokens in the token bucket need to be consumed. The number of tokens consumed varies for messages of different sizes, so when a message needs to be sent, the token required to send the message will be obtained from the token bucket.

[0004] In a multi-core network device, when a message needs to be processed at a limited speed, the token bucket, as a critical resource, needs to be protected by mutual exclusion. That is, when a core has a message to send, it will obtain a token from the token bucket. At this time, other cores are not allowed to obtain tokens from the token bucket, resulting in the inability of multi-core processing in parallel. And every time a message needs to be sent, it needs to obtain a token from the token bucket, and the token bucket will be protected by mutual exclusion; therefore, when there are multiple messages to be sent, multiple locks will be locked and mutually excluded, resulting in a high frequency of locks and mutual exclusion. This is bound to affect the concurrency of multi-core network devices and ultimately affect the performance of speed limiting. Therefore, how to use a lock-free concurrent method to implement message speed limiting for token buckets in multi-core network devices has become an urgent problem to be solved. Summary of the invention

[0005] In order to solve the above problems, the present invention provides a message processing method, which solves the performance problem of message speed-limited forwarding affected by locking and mutual exclusion of token buckets in multi-core network devices.

[0006] In a first aspect, the present invention provides a message processing method, which is implemented by a device having a multi-core processor, and includes the following steps:

[0007] A core Core0 of the multi-core processor is selected to calculate the first token increment value of the token bucket according to a preset time period, and accumulate the first token increment value to the token addition statistic value; when any core Core i When there are messages to be forwarded, the core i Calculate the remaining token value of the current token bucket; according to the remaining token value, the core Core i Color the message, process the message according to the coloring result, and then Core iAccording to the actual forwarding volume of the message checked by this core, the application statistics of the tokens checked by this core are accumulated; wherein, 0≤i≤N, N is the total number of cores of the multi-core processor, and the remaining token value is equal to the added statistics value minus the sum of the application statistics of all cores of the multi-core processor.

[0008] The selecting of a core Core0 of the multi-core processor to calculate a first token increment value of the token bucket according to a preset time period and accumulating the first token increment value to the token addition statistic value includes:

[0009] When the token bucket is in single-speed single-bucket mode, core Core0 calculates the first token increment value of the token bucket according to a preset time period, and accumulates the first token increment value to the added statistical value until the token bucket is full; or, when the token bucket is in single-speed dual-bucket mode, core Core0 calculates the first token increment value of the token bucket according to a preset time period, and the first token increment value is used first to repay the debt of bucket C tokens, and then to repay the debt of bucket E tokens. If bucket C and bucket E have no token load, the remaining first token increment value is first accumulated to the added statistical value of bucket C until bucket C is full, and then accumulated to the added statistical value of bucket E until bucket E is full.

[0010] According to the remaining token value, the core Core i Color the message, process the message according to the coloring result, and then Core i According to the actual forwarding volume of the message checked, the application statistics of the token checked are accumulated, including:

[0011] When the token bucket is in single-rate single-bucket mode, if the remaining token value is greater than zero, the core Core i Mark the message green, forward it, and then core i According to the actual forwarding amount of the message by this core, the application statistics of this core are accumulated; if the remaining token value is less than or equal to zero, the core Core i Mark the message in red and discard or queue the message for processing. At this time, the core maintains the application statistics unchanged; or, when the token bucket is in single-speed dual-bucket mode, if the remaining token value of bucket C is greater than zero, the core Core i Mark the message green, forward it, and then core i According to the actual forwarding volume of the message by this core, the application statistics of the core C bucket are accumulated; otherwise, if the sum of the remaining token value of the C bucket and the remaining token value of the E bucket is greater than zero, the core Core iMark the message in yellow, forward it, and then Core i According to the actual forwarding volume of the message by this core, the application statistics of the E bucket of this core are accumulated; otherwise, the core Core i Mark the message in red and discard it or queue it for processing. i The application statistics for buckets C and E remain unchanged.

[0012] The remaining token value is equal to the added statistical value minus the sum of the application statistical values ​​of all cores of the multi-core processor, including: when the token bucket is in single-speed dual-bucket mode, the remaining token value of the current C bucket is equal to the added statistical value of the C bucket minus the sum of the application statistical values ​​of the C bucket of all cores of the multi-core processor, and the remaining token value of the current E bucket is equal to the added statistical value of the E bucket minus the sum of the application statistical values ​​of the E bucket of all cores of the multi-core processor.

[0013] In a possible implementation, the method further includes: when the token bucket is full for a plurality of consecutive time periods, the core Core0 stops accumulating the added statistical value and records the current system timestamp, and waits for any core Core i When there is a message to be forwarded, a wake-up signal is sent to core Core0. After receiving the wake-up signal, core Core0 calculates the second token increment value according to the time interval between the latest system timestamp and the current system timestamp, and accumulates the second token increment value to the added statistical value.

[0014] In a second aspect, the present invention provides a message processing device, including a token adding core Core0 and a token applying core Core i , the device comprises:

[0015] The token adding core Core0 is used to calculate the first token increment value of the token bucket according to a preset time period, and accumulate the first token increment value to the token adding statistical value;

[0016] Token Application Core i , when the core has a message to be forwarded, calculate the remaining token value of the current token bucket; color the message according to the remaining token value, process the message according to the coloring result, and then accumulate the application statistics of the token by the core according to the actual forwarding amount of the message by the core; wherein 0≤i≤N, N is the total number of cores of the multi-core processor, and the remaining token value is equal to the added statistical value minus the sum of the application statistics of all cores of the multi-core processor.

[0017] Among them, the token adding core Core0 is specifically used for: when the token bucket is in single-speed single-bucket mode, calculating the first token increment value of the token bucket according to a preset time period, and accumulating the first token increment value to the adding statistic value until the token bucket is full; or, when the token bucket is in single-speed dual-bucket mode, calculating the first token increment value of the token bucket according to a preset time period, the first token increment value is used first to repay the debt of the C bucket token, and then to repay the debt of the E bucket token. If neither the C bucket nor the E bucket has a token load, the remaining first token increment value is first accumulated to the adding statistic value of the C bucket until the C bucket is full, and then accumulated to the adding statistic value of the E bucket until the E bucket is full.

[0018] The token application core i Specifically used for: when the token bucket is in single-speed single-bucket mode, if the remaining token value is greater than zero, the message is marked as green, and the message is forwarded, and then the application statistics of this core are accumulated according to the actual forwarding amount of the message by this core; if the remaining token value is less than or equal to zero, the message is marked as red, and the message is discarded or queued for processing, and the application statistics of this core remain unchanged; or, when the token bucket is in single-speed dual-bucket mode, if the remaining token value of bucket C is greater than zero, the message is marked as green If the message is marked yellow, it is forwarded, and then the application statistics of bucket C of the core are accumulated according to the actual forwarding volume of the message by the core; otherwise, if the sum of the remaining token value of bucket C and the remaining token value of bucket E is greater than zero, the message is marked yellow, and the message is forwarded, and then the application statistics of bucket E of the core are accumulated according to the actual forwarding volume of the message by the core; otherwise, the message is marked red, and the message is discarded or queued for processing. At this time, the application statistics of bucket C and bucket E of the core remain unchanged.

[0019] In one possible implementation, the token application core i Specifically used for: when the token bucket is in single-speed dual-bucket mode, the remaining token value of the current C bucket is equal to the added statistical value of the C bucket minus the sum of the application statistical values ​​of the C buckets of all cores of the multi-core processor, and the remaining token value of the current E bucket is equal to the added statistical value of the E bucket minus the sum of the application statistical values ​​of the E buckets of all cores of the multi-core processor.

[0020] In a possible implementation, the token adding core Core0 is further used to: when the token bucket is full for a plurality of consecutive time periods, suspend the accumulation of the adding statistics and record the current system timestamp, and wait for any token application core Core0 to receive a token request. iAfter the wake-up signal is sent, the second token increment value is calculated according to the time interval between the latest system timestamp and the current system timestamp, and the second token increment value is accumulated to the added statistical value; the token application core Core i Specifically, it is also used for: sending a wake-up signal to the token adding core Core0 when the core has a message to be forwarded.

[0021] To sum up, the present invention uses multi-core lock-free parallel processing, so that each core can add and apply for tokens in the token bucket without interfering with each other, avoiding the locking and mutual exclusion processing when multiple cores access the token bucket, and can greatly improve the message forwarding performance when the token bucket is speed-limited, thereby improving the overall forwarding performance of the multi-core processor. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.

[0023] Figure 1 A flow chart of a message processing method provided by an embodiment of the present invention is shown;

[0024] Figure 2 is based on Figure 1 A flow chart of a method for adding statistical values ​​to cumulative tokens shown in the illustrated embodiment;

[0025] Figure 3 is based on Figure 1 The illustrated embodiment shows a flow chart of another method for adding statistical values ​​to cumulative tokens;

[0026] Figure 4 is based on Figure 3 A flowchart of a method for paying off a C-bucket token liability as shown in the illustrated embodiment;

[0027] Figure 5 is based on Figure 3 A flow chart of a method for paying off an E-bucket token liability as shown in the illustrated embodiment;

[0028] Figure 6 is based on Figure 3 A flow chart of a method for accumulating remaining tokens to add statistical values ​​to buckets C and E, as shown in the illustrated embodiment;

[0029] Figure 7 A schematic diagram of a message processing device provided by an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0030] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. The following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present invention.

[0031] The following describes the embodiments in detail.

[0032] Embodiment 1

[0033] The embodiment of the present invention provides a message processing method, which is applied to the token bucket in single-rate single-bucket mode. Assuming that the added statistic value of the marking token is InC, marking any core Core i The remaining token value of the current token bucket is calculated as Tc i , mark any core Core i The application statistics value of the token is OutC i , the token increment value is Δa, where 0≤i≤N, and N is the total number of cores in the multi-core processor. The processing flow chart is as follows Figure 1 As shown, the following steps are included:

[0034] Step S101 , selecting a core Core0 of a multi-core processor to calculate a first token increment value of a token bucket according to a preset time period, and accumulating the first token increment value to a token addition statistic value.

[0035] As an embodiment of the present invention, the processing flow of this step is as follows: Figure 2 As shown, the following steps are included:

[0036] Step S101a, core Core0 calculates Tc0 according to a preset time period T.

[0037] It should be noted that Tc0 is equal to InC minus OutC of all cores of the multi-core processor. m The sum is:

[0038]

[0039] Among them, OutC of any core m It can be saved in global variables or shared memory. In the initial state, InC is equal to CBS (Committed Burst Size), and OutC of each core is equal to CBS (Committed Burst Size). mEqual to 0, Tc0 is equal to CBS, that is, in the initial state, the token bucket is in a full state.

[0040] Step S101b, determine whether the token bucket is in a non-full state or a debt state. If so, execute step S101c.

[0041] Among them, when Tc0 < CBS, it means that the token bucket is in a non-full state or a debt state, and step S101c needs to be executed; otherwise, if Tc0 = CBS, it means that the token bucket is in a full state, and the processing of this cycle ends.

[0042] Step S101c, Core0 calculates the first token increment value T * CIR (Committed Information Rate) of the token bucket according to the preset time period T, and sets Δa = T * CIR.

[0043] Step S101d, determine whether the token bucket will not overflow after adding Δa tokens. If it will not overflow, execute step S101e; otherwise, if it will overflow, execute step S101f.

[0044] In this step, when Tc0 + Δa ≤ CBS, it means that the token bucket will not overflow after adding Δa tokens, and step S101e needs to be executed. Otherwise, when Tc0 + Δa > CBS, it means that the token bucket is in an overflow state after adding Δa tokens, and step S101f needs to be executed.

[0045] Step S101e, Core0 accumulates Δa tokens to InC.

[0046] That is, set InC = InC + Δa, and end the processing of this cycle.

[0047] Step S101f, Core0 fills the token bucket to a full state and discards the overflowed tokens.

[0048] That is, set InC = InC + CBS - Tc0, and end the processing of this cycle.

[0049] Optionally, as another embodiment of the method of the present invention, Core0 determines that if the token bucket is in a full state for multiple consecutive time periods T, that is, when Tc0 is equal to CBS for K consecutive time periods T, Core0 pauses accumulating InC and records the current system timestamp T0. Wait for any core i When there is a message to be forwarded, send a wake-up signal to Core0. After receiving the wake-up signal, Core0 calculates the second token increment value as (T1 - T0) * CIR according to the time interval between the latest system timestamp T1 and the current system timestamp T0, sets Δa = (T1 - T0) * CIR, and accumulates Δa to InC. The accumulation method is the same as Figure 2 The processing flow in is similar and will not be repeated here, where K is an integer greater than 0.

[0050] Step S102: When any core Core i When there are messages to be forwarded, the core i Calculate the remaining token value of the current token bucket; based on the remaining token value, the core i Color the message, process it according to the coloring result, and then Core i According to the actual forwarding volume of this verification message, the application statistics of this verification token are accumulated; where 0≤i≤N, N is the total number of cores of the multi-core processor, and the remaining token value is equal to the added statistics minus the sum of the application statistics of all cores of the multi-core processor.

[0051] In this step, when any core Core i When there are messages to be forwarded, the core i Calculate Tc i ,Right now:

[0052]

[0053] If Tc i >0, indicating that there are remaining tokens in the token bucket. i Mark the message green and forward it. Assume that the message size is S bytes. i According to the actual forwarding volume S of the message by this core, the OutC of this core is accumulated. i , that is, set OutC i =OutC i +S; if Tc i ≤0, indicating that there are no remaining tokens in the token bucket. i The message is marked in red and discarded or queued for processing. i About OutC i Remain unchanged.

[0054] It should be noted that when any core i When there are packets to be forwarded, each core calculates Tc i The value of Tc i , InC and OutC i All use lock-free concurrency for reading, writing and computing to ensure that the cores do not interfere with each other.

[0055] The embodiment of the present invention uses multi-core lock-free parallel processing, so that each core can add and apply for tokens in the token bucket without interfering with each other, avoiding locking and mutual exclusion processing when multiple cores access the token bucket, and can greatly improve the message forwarding performance when the token bucket is speed-limited, thereby improving the overall forwarding performance of the multi-core processor.

[0056] Embodiment 2

[0057] The embodiment of the present invention provides a message processing method, which is applied to the token bucket in single-rate dual-bucket mode. i The remaining token value of the current C bucket is calculated as Tc i , the remaining token value of the current E bucket is Te i ; Mark the added statistic value of bucket C as InC, and the added statistic value of bucket E as InE; Mark any core Core i The application statistics value of bucket C is OutC i , the application statistics value of bucket E is OutE i ; The token increment value of the token bucket is Δa, where 0≤i≤N, and N is the total number of cores in the multi-core processor. The processing flow is still the same as Figure 1 As shown, the following steps are included:

[0058] Step S101 , selecting a core Core0 of a multi-core processor to calculate a first token increment value of a token bucket according to a preset time period, and accumulating the first token increment value to a token addition statistic value.

[0059] As a preferred embodiment of the present invention, the core Core0 first calculates Tc0 and Te0 according to a preset time period T, that is,

[0060]

[0061]

[0062] Among them, OutC of any core m and OutE m It can be saved in global variables or shared memory. In the initial state, InC is equal to CBS, InE is equal to EBS (Excess Burst Size), and OutC of each core is equal to CBS. m and OutE m Both are equal to 0, Tc0 is equal to CBS, and Te0 is equal to EBS. That is, in the initial state, the tokens in buckets C and E are both full.

[0063] If Tc0=CBS and Te0=EBS, it means that the tokens in buckets C and E are both full, and the processing of this cycle ends.

[0064] Otherwise, when Tc0≠CBS or Te0≠EBS, the processing flow is as follows: Figure 3 As shown, it includes the following steps:

[0065] Step S211 , the core Core0 calculates the first token increment value T*CIR of the token bucket according to a preset time period T, and sets Δa=T*CIR.

[0066] Step S212, Δa is first used to pay off the debt of bucket C tokens.

[0067] Step S213, Δa is first used to pay off the debt of the E bucket token.

[0068] Step S214, if neither bucket C nor bucket E has a token debt, the remaining tokens in Δa are first accumulated to the added statistic value InC of bucket C until bucket C is full, and then accumulated to the added statistic value InE of bucket E until bucket E is full.

[0069] It should be noted that if Figure 4 As shown, step S212 may include the following steps:

[0070] Step S212a, determine whether bucket C is in a debt state, if so, execute step S212b.

[0071] Among them, when Tc0<0, it means that bucket C is in a debt state, and step S212b needs to be executed; otherwise, when Tc0≥0, step S213 needs to be executed to continue to determine whether bucket E is in a debt state.

[0072] Step S212b, determine whether there is any surplus after Δa tokens are used to repay the debt of bucket C. If there is no surplus, execute step S212c; otherwise, if there is a surplus, execute step S212d.

[0073] In this step, since bucket C is in a debt state, Δa should be used to repay the load of bucket C first. Core0 determines that if Tc0+Δa≤0, it means that after all Δa tokens are used to repay the debt of bucket C, bucket C is still in a debt state or the debt of bucket C is just cleared to 0, and step S212c needs to be executed at this time; otherwise, if Tc0+Δa>0, it means that there is some remaining after Δa tokens are used to repay the debt of bucket C, and step S212d needs to be executed at this time.

[0074] Step S212c, accumulating Δa to InC.

[0075] That is, InC=InC+Δa is set, and the processing of this cycle is ended.

[0076] Step S212d, pay off the debt of bucket C and update Δa.

[0077] That is, set InC = InC - Tc0; Δa = Δa + Tc0; Tc0 = 0. Then continue to step S213.

[0078] In addition, if Figure 5 As shown, step S213 may include the following steps:

[0079] Step S213a, determine whether bucket E is in a debt state, if so, execute step S213b.

[0080] Among them, when Te0<0, it means that bucket E is in a debt state, and step S213b needs to be executed; otherwise, when Te0≥0, step S214 needs to be executed to continue accumulating tokens in buckets C and E.

[0081] Step S213b, determine whether there is any surplus after Δa tokens are used to repay the E bucket debt. If there is no surplus, execute step S213c; otherwise, if there is a surplus, execute step S213d.

[0082] In this step, since bucket E is in a debt state, Δa should be used to repay the load of bucket E first. When Te0+Δa≤0, it means that after all Δa tokens are used to repay the debt of bucket E, bucket E is still in a debt state or the debt of bucket E is just cleared to 0, and step S213c needs to be executed at this time; otherwise, when Te0+Δa>0, it means that there is still some remaining after Δa tokens are used to repay the debt of bucket E, and step S213d needs to be executed at this time.

[0083] Step S213c, accumulating Δa to InE.

[0084] That is, InE=InE+Δa is set, and the processing of this cycle is ended.

[0085] Step S213d, pay off the E bucket debt and update Δa.

[0086] That is, it is set that InE=InE-Te0; Δa=Δa+Te0; Te0=0. Then, the step S214 is continued.

[0087] It should be noted that if Figure 6 As shown, step S214 may include the following steps:

[0088] Step S214a, determining whether Δa is in an overflow state after being accumulated to InC of bucket C, if so, executing step S214b; otherwise, executing step S214f.

[0089] In this step, when Tc0+Δa>CBS, it means that after Δa is accumulated to InC of C bucket, C bucket is in overflow state. It means that there are some tokens left after Δa tokens are added to C bucket, which is full. In this case, step S214b needs to be executed; otherwise, when Tc0+Δa≤CBS, it means that after Δa is accumulated to InC of C bucket, C bucket is still not full or C bucket has just reached full state. In this case, step S214f needs to be executed.

[0090] Step S214b, Δa is accumulated until bucket C is full and Δa is updated.

[0091] That is, it is set that InC=InC+CBS-Tc0; Δa=Δa-CBS+Tc0.

[0092] Step S214c, determining whether it is an overflow state after Δa is accumulated to InE of bucket E, if it is an overflow state, executing step S214d; otherwise, it is not an overflow state, executing step S214e.

[0093] In this step, when Te0+Δa>EBS, it means that after Δa is accumulated to InE of E bucket, E bucket is in overflow state. It means that there are some tokens left after Δa tokens are added to E bucket, which is full. In this case, step S214d needs to be executed; otherwise, when Te0+Δa≤EBS, it means that after Δa is accumulated to InE of E bucket, E bucket is still not full or E bucket has just reached full state. In this case, step S214e needs to be executed.

[0094] Step S214d: accumulate Δa until bucket E is full and discard the overflowing tokens.

[0095] That is, InE=InE+EBS-Te0 is set, and then the processing of this cycle is ended.

[0096] Step S214e, Δa is accumulated into bucket E.

[0097] That is, InE=InE+Δa is set, and then the processing of this cycle is ended.

[0098] Step S214f, accumulate Δa into bucket C.

[0099] That is, InC=InC+Δa is set, and then the processing of this cycle is terminated.

[0100] Optionally, as another embodiment of the method of the present invention, core Core0 determines that if Tc0 is equal to CBS and Te0 is equal to EBS in multiple consecutive time periods T, that is, when bucket C and bucket E are both full in K time periods T, core Core0 suspends accumulating InC and InE, and records the current system timestamp T0, and waits for any core Core iWhen there is a message to be forwarded, a wake-up signal is sent to Core 0. After receiving the wake-up signal, Core 0 calculates the second token increment value as (T1-T0)*CIR according to the time interval between the latest system timestamp T1 and the current system timestamp T0, sets Δa equal to (T1-T0)*CIR and accumulates Δa to InC. The accumulation method is the same as Figure 3 The processing flow is similar to that in , which will not be repeated here, where K is an integer greater than 0.

[0101] Step S102: When any core Core i When there are messages to be forwarded, the core i Calculate the remaining token value of the current token bucket; based on the remaining token value, the core i Color the message, process it according to the coloring result, and then Core i According to the actual forwarding volume of this verification message, the application statistics of this verification token are accumulated; where 0≤i≤N, N is the total number of cores of the multi-core processor, and the remaining token value is equal to the added statistics minus the sum of the application statistics of all cores of the multi-core processor.

[0102] In this step, when any core Core i When there are messages to be forwarded, the core i Calculate Tc i and Te i ,Right now:

[0103]

[0104]

[0105] If Tc i >0, indicating that there are remaining tokens in bucket C. i Mark the message green and forward it. Assume that the message size is S bytes, Core i According to the actual forwarding volume S of the message by this core, the OutC of this core is accumulated. i , that is, set OutC i =OutC i +S. If Tc i +Te i >0, indicating that there are still tokens left after combining the remaining tokens in buckets C and E. i Mark the message yellow, forward it, and then i According to the actual forwarding volume S of the message by this core, the OutE of this core is accumulated. i , that is, set OutE i =OutEi +S. Otherwise if Tc i <0 and Tc i +Te i ≤0, Core i The message is marked in red and discarded or queued for processing. i OutC i and OutE i All remain unchanged.

[0106] It should be noted that when any core i When there are packets to be forwarded, each core calculates Tc i and Te i The value of Tc i 、Te i 、InC、InE、OutC i 、OutE i All use lock-free concurrency for reading, writing and computing to ensure that the cores do not interfere with each other.

[0107] The embodiment of the present invention uses multi-core lock-free parallel processing, so that each core can add and apply for tokens in buckets C and E without interfering with each other, avoiding locking and mutual exclusion processing when multiple cores access token buckets, and can greatly improve the message forwarding performance when the token bucket is speed-limited, thereby improving the overall forwarding performance of the multi-core processor.

[0108] Embodiment 3

[0109] The embodiment of the present invention provides a message processing device 701, including a token adding core Core0 and a token applying core Core i , its schematic diagram is as follows Figure 7 As shown, including:

[0110] The token adding core Core0 is used to calculate the first token increment value of the token bucket according to a preset time period, and accumulate the first token increment value to the token adding statistical value;

[0111] Token Application Core i , when the core has a message to be forwarded, calculate the remaining token value of the current token bucket; color the message according to the remaining token value, process the message according to the coloring result, and then accumulate the application statistics of the token by the core according to the actual forwarding volume of the message; where 0≤i≤N, N is the total number of cores of the multi-core processor, and the remaining token value is equal to the sum of the application statistics of all cores of the multi-core processor minus the added statistics.

[0112] Among them, the token adding core Core0 is specifically used for: when the token bucket is in single-speed single-bucket mode, calculating the first token increment value of the token bucket according to a preset time period, and accumulating the first token increment value to the adding statistic value until the token bucket is full; or, when the token bucket is in single-speed dual-bucket mode, calculating the first token increment value of the token bucket according to a preset time period, the first token increment value is used first to repay the debt of the C bucket token, and then to repay the debt of the E bucket token. If neither the C bucket nor the E bucket has a token load, the remaining first token increment value is first accumulated to the adding statistic value of the C bucket until the C bucket is full, and then accumulated to the adding statistic value of the E bucket until the E bucket is full.

[0113] Token Application Core i Specifically used for: when the token bucket is in single-speed single-bucket mode, if the remaining token value is greater than zero, the message is marked as green and the message is forwarded, and then the application statistics of the core are accumulated according to the actual forwarding volume of the message of this core; if the remaining token value is less than or equal to zero, the message is marked as red, and the message is discarded or queued for processing, and the application statistics of the core remain unchanged; or, when the token bucket is in single-speed dual-bucket mode, if the remaining token value of bucket C is greater than zero, the message is marked as green, and the message is forwarded, and then the application statistics of bucket C of the core are accumulated according to the actual forwarding volume of the message of this core; otherwise, if the sum of the remaining token value of bucket C and the remaining token value of bucket E is greater than zero, the message is marked as yellow, and the message is forwarded, and then the application statistics of bucket E of the core are accumulated according to the actual forwarding volume of the message of this core; otherwise, the message is marked as red, and the message is discarded or queued for processing, and the application statistics of bucket C and bucket E of the core remain unchanged.

[0114] Among them, the token application core i Specifically used for: when the token bucket is in single-speed dual-bucket mode, the current remaining token value of bucket C is equal to the addition statistic value of bucket C minus the sum of the application statistic values ​​of bucket C of all cores of the multi-core processor, and the current remaining token value of bucket E is equal to the addition statistic value of bucket E minus the sum of the application statistic values ​​of bucket E of all cores of the multi-core processor.

[0115] It should be noted that the core Core0 can be used as the token adding core Core0 and the token applying core Core0 at the same time.

[0116] As a preferred embodiment of the present invention, the token adding core Core0 is also used to: when the token bucket is full for multiple consecutive time periods, suspend the accumulation of token adding statistics and record the current system timestamp, and wait for any token application core Core0 to receive the token application. iAfter the wake-up signal is sent, the second token increment value is calculated according to the time interval between the latest system timestamp and the current system timestamp, and the second token increment value is accumulated to the token addition statistics. i Specifically, it is also used to send a wake-up signal to the token-added core Core0 when the core has a message to be forwarded.

[0117] The embodiment of the present invention uses multi-core lock-free parallel processing, so that each core can add and apply for tokens in the token bucket without interfering with each other, avoiding locking and mutual exclusion processing when multiple cores access the token bucket, and can greatly improve the message forwarding performance when the token bucket is speed-limited, thereby improving the overall forwarding performance of the multi-core processor.

[0118] Each part of this specification is described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment.

[0119] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. A message processing method, the method is implemented by a device having a multi-core processor, It is characterized in that The method comprises: Select a core of a multi-core processor 0 Used to calculate the first token increment value of the token bucket according to a preset time period, and accumulate the first token increment value to the token addition statistic value; when any core Core i When there are messages to be forwarded, the core i Calculate the remaining token value of the current token bucket; according to the remaining token value, the core Core i Color the message, process the message according to the coloring result, and then Core i According to the actual forwarding volume of the message checked by this core, the application statistics of the tokens checked by this core are accumulated; wherein, 0≤i≤N, N is the total number of cores of the multi-core processor, and the remaining token value is equal to the added statistics value minus the sum of the application statistics of all cores of the multi-core processor.

2. The method according to claim 1, It is characterized in that Selecting a core of a multi-core processor 0 The method is used to calculate a first token increment value of a token bucket according to a preset time period, and accumulate the first token increment value to a token addition statistic value, including: When the token bucket is in single-rate single-bucket mode, the core Core 0 Calculating a first token increment value of the token bucket according to a preset time period, and accumulating the first token increment value to the added statistical value until the token bucket is full; or, When the token bucket is in single-speed dual-bucket mode, the core Core 0 The first token increment value of the token bucket is calculated according to a preset time period. The first token increment value is used first to repay the debt of the C bucket token, and then to repay the debt of the E bucket token. If both the C bucket and the E bucket have no token load, the remaining first token increment value is first accumulated to the added statistical value of the C bucket until the C bucket is full, and then accumulated to the added statistical value of the E bucket until the E bucket is full.

3. The method according to claim 2, It is characterized in that According to the remaining token value, the core Core i Color the message, process the message according to the coloring result, and then Core i According to the actual forwarding volume of the message checked, the application statistics of the token checked are accumulated, including: When the token bucket is in single-rate single-bucket mode, if the remaining token value is greater than zero, the core Core i Mark the message green, forward it, and then core i According to the actual forwarding amount of the message by this core, the application statistics of this core are accumulated; if the remaining token value is less than or equal to zero, the core Core i Mark the message in red and discard it or put it into a queue for processing, at which time the core maintains the application statistics unchanged; or, When the token bucket is in single-rate dual-bucket mode, if the remaining token value of bucket C is greater than zero, the core Core i Mark the message green, forward it, and then core i According to the actual forwarding volume of the message by this core, the application statistics of the core C bucket are accumulated; otherwise, if the sum of the remaining token value of the C bucket and the remaining token value of the E bucket is greater than zero, the core Core i Mark the message in yellow, forward it, and then Core i According to the actual forwarding volume of the message by this core, the application statistics of the E bucket of this core are accumulated; otherwise, the core Core i The message is marked in red and discarded or queued for processing. i The application statistics for buckets C and E remain unchanged.

4. The method according to claim 3, It is characterized in that The remaining token value is equal to the added statistical value minus the sum of the application statistical values ​​of all cores of the multi-core processor, including: When the token bucket is in single-speed dual-bucket mode, the remaining token value of the current C bucket is equal to the added statistical value of the C bucket minus the sum of the application statistical values ​​of the C buckets of all cores of the multi-core processor, and the remaining token value of the current E bucket is equal to the added statistical value of the E bucket minus the sum of the application statistical values ​​of the E buckets of all cores of the multi-core processor.

5. The method according to any one of claims 1 to 4, It is characterized in that The method further comprises: When the token bucket is full for a plurality of consecutive time periods, the core 0 Pause the accumulation of the added statistics and record the current system timestamp, and wait for any core Core i When there is a message to be forwarded, send it to the core 0 Send a wake-up signal, Core 0 After receiving the wake-up signal, a second token increment value is calculated according to the time interval between the latest system timestamp and the current system timestamp, and the second token increment value is accumulated to the added statistical value.

6. A message processing device, which is applied to a device with a multi-core processor, and includes a token adding core Core 0 and token application core i , It is characterized in that The device comprises: Token Add Core 0 , used to calculate the first token increment value of the token bucket according to a preset time period, and accumulate the first token increment value to the token addition statistic value; Token Application Core i , when the core has a message to be forwarded, calculate the remaining token value of the current token bucket; color the message according to the remaining token value, process the message according to the coloring result, and then accumulate the application statistics of the token by the core according to the actual forwarding amount of the message by the core; wherein 0≤i≤N, N is the total number of cores of the multi-core processor, and the remaining token value is equal to the added statistical value minus the sum of the application statistics of all cores of the multi-core processor.

7. The device according to claim 6, It is characterized in that The token adds a core 0 Specifically used for: When the token bucket is in single-rate single-bucket mode, a first token increment value of the token bucket is calculated according to a preset time period, and the first token increment value is accumulated to the added statistical value until the token bucket is full; or, When the token bucket is in single-speed dual-bucket mode, the first token increment value of the token bucket is calculated according to a preset time period, and the first token increment value is used first to repay the debt of the C bucket token, and then to repay the debt of the E bucket token. If both the C bucket and the E bucket have no token load, the remaining first token increment value is first accumulated to the added statistical value of the C bucket until the C bucket is full, and then accumulated to the added statistical value of the E bucket until the E bucket is full.

8. The device according to claim 7, It is characterized in that The token application core i Specifically used for: When the token bucket is in single-speed single-bucket mode, if the remaining token value is greater than zero, the message is marked as green and the message is forwarded, and then the application statistics of the core are accumulated according to the actual forwarding amount of the message by the core; if the remaining token value is less than or equal to zero, the message is marked as red, and the message is discarded or queued for processing, and the application statistics of the core remain unchanged; or, When the token bucket is in single-speed dual-bucket mode, if the remaining token value of bucket C is greater than zero, the message is marked as green and forwarded, and then the application statistics of bucket C of this core are accumulated according to the actual forwarding volume of the message by this core; otherwise, if the sum of the remaining token value of bucket C and the remaining token value of bucket E is greater than zero, the message is marked as yellow, and the message is forwarded, and then the application statistics of bucket E of this core are accumulated according to the actual forwarding volume of the message by this core; otherwise, the message is marked as red, and the message is discarded or queued for processing, at which time the application statistics of bucket C and bucket E of this core remain unchanged.

9. The device as claimed in claim 8, It is characterized in that The token application core i Specifically used for: When the token bucket is in single-speed dual-bucket mode, the remaining token value of the current C bucket is equal to the added statistical value of the C bucket minus the sum of the application statistical values ​​of the C buckets of all cores of the multi-core processor, and the remaining token value of the current E bucket is equal to the added statistical value of the E bucket minus the sum of the application statistical values ​​of the E buckets of all cores of the multi-core processor.

10. The device according to any one of claims 6 to 9, It is characterized in that The token adds a core 0 Specifically, it is also used to: when the token bucket is full for multiple consecutive time periods, suspend the accumulation of the added statistical value and record the current system timestamp, and wait for any token application core Core to be received i After the wake-up signal is sent, a second token increment value is calculated according to the time interval between the latest system timestamp and the current system timestamp, and the second token increment value is accumulated to the added statistical value; The token application core i Specifically, it is also used to add a core Core to the token when the core has a message to be forwarded. 0 Send a wake-up signal.