Looking for breakthrough ideas for innovation challenges? Try Patsnap Eureka!

Implementation method of spin lock as multi-core CPU accessing resources

A technology for accessing resources and implementing methods, which is applied to the implementation of multi-core CPU spin locks and can solve problems such as bus occupancy and overhead.

Active Publication Date: 2017-11-17
北京智盟信通科技有限公司
View PDF7 Cites 6 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

The atomic operation of locking the bus usually brings additional bus occupation overhead, so there is still room for further improvement of these two spinlocks

Method used

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more

Image

Smart Image Click on the blue labels to locate them in the text.
Viewing Examples
Smart Image
  • Implementation method of spin lock as multi-core CPU accessing resources
  • Implementation method of spin lock as multi-core CPU accessing resources
  • Implementation method of spin lock as multi-core CPU accessing resources

Examples

Experimental program
Comparison scheme
Effect test

Embodiment 1

[0075] For any n-core CPU system, its CPU number is 0~n-1, then any number such as the kth (0≤k≤n-1) CPU, the specific implementation process of obtaining resource access rights is as follows image 3 shown.

[0076] Before the kth CPU accesses the resource, initialize the resource lock and assign an initial value, such as figure 2 As shown, pLock is assigned a value of NULL, that is, the memory content is NULL, indicating that the current resource is not occupied. pNext is assigned a value of &Lock_g, that is, the next lock address of the resource lock is itself. Therefore, the initialized resource lock forms a one-way self-circulating list, such as figure 2 shown.

[0077] The kth CPU locks and unlocks when accessing resources.

[0078] Compared with the prior art, the method according to this embodiment allocates a resource lock for each shared resource, and each resource lock forms a one-way self-circular linked list when the right to use the shared resource is not oc...

Embodiment 2

[0080] In this embodiment, a specific implementation scheme of locking and unlocking in Example 1 is given. During the locking and unlocking process of this method, the CPU does not need to retain its own spin lock when using resources, specifically as Figure 4 shown.

[0081] S101: Set the first unit of the spin lock of the kth CPU to be non-empty, and set the second unit to be empty.

[0082] Wherein, the spin lock is formed in the running stack.

[0083] In programmatic operation, this can be achieved as follows:

[0084] When the CPU obtains access rights to shared resources, it first declares. Declare the type variable me of the spin lock LOCK, and assign the initial value to the spin lock, [pLock]=&me, [pNext]=NULL.

[0085] S103 The k-th CPU puts the spin lock at the end of the current queue for resource acquisition, and simultaneously acquires the last lock ID of the queue before the above-mentioned spin lock is placed in the queue, that is, the ID of the previous...

Embodiment 3

[0120] The above process of unlocking and unlocking does not provide an interface for trying to access resources. The method further includes a method of trying to obtain resource usage rights, that is, when resources are occupied, the CPU does not need to wait for resource locks to be acquired, and can perform other operations. The corresponding operation method is performed only when it is determined that the resource usage permission has been obtained.

[0121] When trying to access, the atomic operation of the bus hardware lock mode can be used, and the operation flow is shown in Figure 5:

[0122] Assuming that the kth CPU is trying to obtain access to resources, that is, the initialization return value pRet=&Lock_g, the step goes to S201.

[0123] S201 locks the resource access queue of the CPU before the kth CPU acquires the access resource, and the CPUs not in the queue can access the resource only when the queue lock is unlocked.

[0124] In programmatic operation, t...

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to View More

PUM

No PUM Login to View More

Abstract

The invention discloses an implementation method of spin lock as multi-core CPU accessing resources. The method comprises following steps: resource to be accessed is provided with a resource lock and a spin lock is generated for self use when any CPU accesses resources; inner structures of the resource lock and the spin lock comprise a first memory unit and a second memory unit, wherein the first memory unit is used for identifying lock label and the second memory unit is used for saving a next lock address; before any CPU accesses resources, the first memory unit of the resource lock is set as null, and the second memory unit is set as resource lock itself so that the resource lock forms a self-loop linked list by itself; locking and unlocking are performed when any CPU accesses resources. The implementation method of the spin lock provides a resource lock for each shared resource; when the shared resource use right is not occupied, each resource lock forms a one-way circulation linked list. The adoption of the self-loop linked list mechanism reduces complexity of program design and the use efficiency of system shared resource is increased.

Description

technical field [0001] The invention relates to the field of computers, and more specifically, to a method for realizing a multi-core CPU spin lock. Background technique [0002] Because the multi-core CPU runs in parallel, in order to ensure the safe access of a program (or process) to a certain resource and maintain data consistency, such parallel running programs generally need to use the lock mechanism at the bottom layer for synchronization, so as to ensure The consistency of the shared resource data during the running of the program, otherwise, it is easy to cause system errors due to data inconsistency, resulting in serious consequences. In a single-core CPU, since there is only one task running at each moment, and in a multi-core CPU system, multiple threads are truly executed in parallel, so the synchronization method in a single-core system cannot be simply applied to a multi-core processor system In this process, it is necessary to design a fast and efficient dat...

Claims

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to View More

Application Information

Patent Timeline
no application Login to View More
IPC IPC(8): G06F9/50G06F9/52
CPCG06F9/5038G06F9/52
Inventor 吕锦柏崔萍
Owner 北京智盟信通科技有限公司
Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Patsnap Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Patsnap Eureka Blog
Learn More
PatSnap group products