With the enhancement of processing performance requirements of network devices, multi-core processors have been widely used. Generally, critical resources may be set in a processing system, in which the critical resources are resources that allow only one process to be accessed at a time, i.e., the resources are exclusively accessed by multiple cores. A spinlock may be set when software is designed to prevent the multiple cores from accessing the same critical resource simultaneously.
For simplicity and illustrative purposes, the present disclosure is described by referring mainly to example(s) thereof. In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present disclosure. It will be readily apparent however, that the present disclosure may be practiced without limitation to these specific details. In other instances, some methods and structures have not been described in detail so as not to unnecessarily obscure the present disclosure. As used throughout the present disclosure, the term “includes” means includes but not limited to, the term “including” means including but not limited to. The term “based on” means based at least in part on. In addition, the terms “a” and “an” are intended to denote at least one of a particular element.
Referring first to
As shown in
In contrast, in a conventional spinlock architecture, an independent first-level (L1) cache is set on each core of a multi-core processor and all of the cores share a second-level (L2) cache and a memory. In this conventional spinlock architecture, images of globally-shared memory variables are stored in the memory, the L2 cache, and each L1 cache. In addition, when a core operates the spinlock, the memory variables in the L1 cache may be updated, resulting in the memory variables stored in the L1 caches of other cores to become invalid. If the other cores operate the spinlock, the other cores read the memory variables from the L2 cache or the memory. If the memory variables in the L1 cache are invalid, the access speed for obtaining the spinlock by accessing the memory and the L2 cache may be about fifty dock cycles to about one hundred and fifty dock cycles.
Referring now to
The obtaining module 201 may read a value of a spinlock cache variable from a cache 110, write the value of the spinlock cache variable into a register, and determine whether the value of the spinlock cache variable is an initial value.
The updating module 202 may update the value of the spinlock memory variable in the register if the value of the spinlock cache variable is the initial value.
The determination module 203 may determine whether the spinlock cache variable is accessed by a core after the value of the spinlock cache variable is written into the register, inform the obtaining module 201 to read the value of the spinlock cache variable from the cache 110, and write the value of the spinlock cache variable into the register if the spinlock cache variable is accessed by a core 114a and write the value of the spinlock cache variable updated by the updating module 202 into the cache if the spinlock cache variable is not accessed by a core 114a.
According to an example of the present disclosure, an access speed of the cache 110 may be larger than that of the L2 cache 120.
According to an example of the present disclosure, the cache 110 may be shared by multiple cores 114a-114d.
According to an example of the present disclosure, if the value of the spinlock cache variable is not the initial value, the obtaining module 201 may further read the value of the spinlock cache variable from the cache 110, write the value of the spinlock cache variable into the register, and determine whether the newly-read value of the spinlock cache variable is the initial value.
According to an example of the present disclosure, the access speed of the cache 110 may be larger than or equal to that of the Li cache 112.
According to an example of the present disclosure, the device 200 may further include a restoring module 204 to set the value of the spinlock cache variable in the register as the initial value after critical resources are accessed and write the initial value into the cache 110.
According to an example, the modules 201-204 may be software modules, e.g., sets of machine readable instructions, stored in a hardware memory device. In another example, the modules 201-204 may be hardware modules on a hardware device. In a further example, the modules 201-204 may include a combination of software and hardware modules.
Referring to
In block 301, a value of a spinlock cache variable may be read from a cache 110. In block 302, the value of the spinlock cache variable may be written into a register. In block 303, a determination may be made as to whether the value of the spinlock cache variable is an initial value. If the value of the spinlock cache variable is the initial value, block 304 may be performed. If the value of the spinlock cache variable is not the initial value, the value of the spinlock cache variable may be read from the cache 110 again and the newly-read value of the spinlock cache variable may be written into the register, as indicated in blocks 301 and 302.
According to an example, the value of the spinlock cache variable may also be called the value of a key of the spinlock in the cache 110.
In a multi-core processing system, the critical resources may be protected by the spinlock. If a core intends to access the critical resources, a spinlock resource may be obtained first. Whether the core has obtained the spinlock resource may be determined according to the value of the spinlock cache variable. Each time an operation is performed on the spinlock, the value of the spinlock cache value may be updated. Initially, the initial value may be set for the value of the spinlock cache variable. For instance, the initial value of the spinlock cache variable may be set as zero, which denotes that the spinlock resource may not be occupied. If the spinlock resource is occupied, the value of the spinlock cache variable may be updated as one.
According to an example, referring to
The obtaining module 201 may execute blocks 301-303. That is, the obtaining module 201 may write the value of the spinlock cache variable into the register and perform the determination at block 303. If the value of the spinlock cache variable is the initial value, the spinlock resource may not be occupied and subsequent blocks may be performed. If the value of the spinlock cache variable is not the initial value, the spinlock resource may be occupied and an operation may be performed after other cores release the spinlock resource. The obtaining module 201 may cyclically read the value of the spinlock cache variable (block 301) and perform the determination (block 303), until the spinlock resource is not occupied.
In block 304, the value of the spinlock cache variable in the register may be updated. For instance, the updating module 202 may perform block 304. The value of the spinlock cache variable in the register may be updated as another value. For instance, the initial value, e.g., zero, of the spinlock cache variable may be updated as one.
In block 305, a determination may be made as to whether the spinlock cache variable is accessed by a core after the value of the spinlock cache variable is written into the register. If the spinlock cache variable is accessed by a core, blocks 301-303 may be performed. If the spinlock cache variable is no accessed by a core, block 306 may be performed.
Block 305 may be performed by the determination module 203. If the value of the spinlock cache variable read in block 301 is the initial value, the spinlock may be obtained and the critical resource may be accessed. If the value of the spinlock cache variable is accessed by another core after the value of the spinlock cache variable is accessed by the core and before the value of the spinlock cache variable is updated, both of the cores may determine that the spinlock resource may have been obtained and the critical resources may be accessed, resulting in access conflict.
According to an example of the present disclosure, a determination may be made as to whether the value of the spinlock cache variable may be accessed by another core after the value of the spinlock cache variable is written into the register before the value of the spinlock cache variable in the cache may be modified. The determination as to whether the value of the spinlock cache variable may be accessed by another core may be obtained from a CPU bus. If the value of the spinlock cache variable is accessed by another core, the operation for obtaining the spinlock resource may have failed and block 301 may be re-performed to obtain the spinlock resource again. If the value of the spinlock cache variable is not accessed by another core, the operation for obtaining the spinlock resource may be considered as being successful. The updated value of the spinlock cache variable in the register may be written into the cache to inform other cores that the spinlock resource may be occupied and that the critical resources may be accessed.
In block 306, the updated value of the spinlock cache variable in the register may be written into the cache.
The method may further include setting of the value of the spinlock cache variable in the cache as the initial value. A restoring module 204 may perform the setting of the value of the spinlock cache variable in the cache as the initial value. After the critical resources are accessed, the spinlock resource may be released so that other cores may access the spinlock resource. After the critical resources are accessed, the value of the spinlock cache variable in the register may be set as the initial value and the initial value may be written into the cache.
According to an example of the present disclosure, the spinlock resource may be obtained via the following operations.
Referring to
The processor 402 may include an obtaining module 410, configured to obtain a value of a spinlock cache variable from the cache 405 via the packet forwarding chip 403, write the value of the spinlock cache variable into the register 404 via the packet forwarding chip 403, and determine whether the value of spinlock cache variable is an initial value. The processor 402 may further include an updating module 412, configured to update the value of the spinlock cache variable in the register 404 if the value of the spinlock cache variable is the initial value. The processor 402 may further store a determination module 414, configured to determine whether the spinlock cache variable is accessed by a core after the value of the spinlock cache variable is written into the register 404. The obtaining module 410 may be further configured to read the value of the spinlock cache variable from the cache 405 and write the value of the spinlock cache variable into the register 404 via the packet forwarding chip 403 if the spinlock cache variable is accessed and write the updated value of the spinlock cache variable into the cache 405 via the packet forwarding chip 403 if the spinlock cache variable is not accessed by a core.
An access speed of the cache 405 may be larger than an access speed of an L2 cache 120.
According to an example, the cache 405 may be shared by multiple cores, such as cores 114a-114d.
According to an example, if the value of the spinlock cache variable is not the initial value, the obtaining module 410 may be further configured to read the value of the spinlock cache variable from the cache 405 via the packet forwarding chip 403 again, write the value of the spinlock cache variable into the register 404 via the packet forwarding chip 403, and determine whether the newly-read value of the spinlock cache variable is the initial value.
According to an example, the access speed of the cache 405 may be larger than or equal to the access speed of an L1 cache 112.
According to an example, the processor 402 may further include a restoring module 416, which also be machine readable instructions. The restoring instruction 416 may be configured to set the value of the spinlock cache variable in the register 404 as the initial value after critical resources are accessed and store the initial value in the cache 405 via the packet forwarding chip 403.
According to an example, the obtaining module 410, updating module 412, determination module 414 and restoring module 416 may be implemented by logic circuits inside the processor 402 as shown for example in
In various examples, a module or unit may be implemented mechanically or electronically. For example, a hardware module may include dedicated circuitry or logic that is permanently configured (e.g., as a special-purpose processor, such as a field programmable gate array (FPGA) or an application-specific integrated circuit (ASIC)) to perform certain operations. A hardware module may also include programmable logic or circuitry (e.g., as encompassed within a general-purpose processor or other programmable processor) that is temporarily configured by software to perform certain operations. It will be appreciated that the decision to implement a hardware module mechanically, in dedicated and permanently configured circuitry, or in temporarily configured circuitry (e.g., configured by software) may be driven by cost and time considerations.
It can be seen from the above description that according to examples of the present disclosure, the cache for storing the value of the spinlock cache variable may be set. Therefore, each core in the multi-core processor may obtain the spinlock resource of the critical resources. Therefore, the operating efficiency of the spinlock may be enhanced and the processing efficiency of the packet forwarding may also be enhanced. Since the multi-core processor may be used on a device having high processing performance requirements, the access efficiency of the critical resources and performance of the device may be enhanced through implementation of the present disclosure.
What has been described and illustrated herein are examples of the disclosure along with some variations. The terms, descriptions and figures used herein are set forth by way of illustration only and are not meant as limitations. Many variations are possible within the scope of the disclosure, which is intended to be defined by the following claims—and their equivalents—in which all terms are meant in their broadest reasonable sense unless otherwise indicated.
Number | Date | Country | Kind |
---|---|---|---|
201310189093.2 | May 2013 | CN | national |
Filing Document | Filing Date | Country | Kind |
---|---|---|---|
PCT/CN2014/074695 | 4/3/2014 | WO | 00 |