# US 2021/0240547 A1 · Method, apparatus, and electronic device for improving cpu performance

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2021/0240547 A1
- Document ID: US20210240547A1
- Status: Published application
- Kind: A1
- Application number: 17/234,313
- Filed: 2021-04-19
- Published: 2021-08-05
- Earliest claimed: 2019-01-16
- Assignees: Advanced New Technologies Co., Ltd.
- Applicants: Advanced New Technologies Co., Ltd.
- Inventors: Ling Ma; Changhua He
- Web page: https://patentgrep.com/patent/US20210240547A1

## CPC

- G06F 9/526: {Mutual exclusion algorithms}
- G06F 9/3851: {from multiple instruction streams, e.g. multistreaming}
- G06F 9/50: Allocation of resources, e.g. of the central processing unit [CPU]
- G06F 9/5022: {Mechanisms to release resources}
- G06F 9/5027: {the resource being a machine, e.g. CPUs, Servers, Terminals}
- G06F 9/5044: {considering hardware capabilities}
- G06F 9/52: Program synchronisation; Mutual exclusion, e.g. by means of semaphores
- G06F 13/36: for access to common bus or bus system
- G06F 16/176: Support for shared access to files; File sharing support
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Implementations of this specification provide a method, an apparatus, and an electronic device for improving performance of a central processing unit (CPU) comprising a plurality of CPU dies. The method includes the following: enabling threads in each CPU die of the CPU to compete for a mutex of a respective CPU die; identifying the plurality of threads that have obtained the mutexes; enabling the plurality of threads that have obtained the mutexes to compete for a spin lock of the CPU; identifying, from the plurality of threads, a target thread that has obtained the spin lock; executing a critical section corresponding to the target thread that has obtained the spin lock; and releasing the mutex and the spin lock that are obtained by the target thread.

## Claims

### Claim at position 1

-20. (canceled)

### Claim 21

A computer-implemented method comprising:
at each of a plurality of CPU components of a CPU: enabling threads awaiting execution on the CPU component to compete for a respective mutex of the CPU component, wherein each CPU component is operable to execute one thread at any given time;
identifying a plurality of threads that have each obtained the respective mutex;
enabling the plurality of threads that have each obtained the respective mutex of a CPU component to compete for a spin lock of the CPU;
identifying, from the plurality of threads, a target thread holding a mutex of a CPU component that has also obtained the spin lock of the CPU; and
executing, at the CPU, a critical section corresponding to the target thread that has obtained the spin lock while remaining threads that have not obtained the respective mutexes are sleeping.

### Claim 22 (depends on 21)

The method according to claim 21, further comprising releasing the mutex of the CPU component and the spin lock of the CPU that are obtained by the target thread only after execution of the critical section corresponding to the target thread is completed.

### Claim 23 (depends on 22)

The method according to claim 22, wherein the releasing the mutex of the CPU component and the spin lock of the CPU that are obtained by the target thread comprises:
first releasing the spin lock of the CPU obtained by the target thread, and then releasing the mutex of the CPU component obtained by the target thread.

### Claim 24 (depends on 23)

The method according to claim 23, further comprising:
enabling one or more threads that have not obtained the spin lock to continuously detect whether the spin lock of the CPU is released.

### Claim 25 (depends on 24)

The method according to claim 24, further comprising:
in response to detecting that the spin lock is released, re-competing, by the one or more threads that have not obtained the spin lock, for the spin lock of the CPU.

### Claim 26 (depends on 21)

The method according to claim 21, wherein the remaining threads that have not obtained the respective mutexes and that are sleeping do not compete for any of the respective mutexes of the CPU components or the spin lock of the CPU.

### Claim 27 (depends on 22)

The method according to claim 22, wherein after the releasing the mutex of the CPU component obtained by the target thread, the method further comprises:
waking up any sleeping thread on the CPU component the mutex of which has been released; and
enabling the sleeping thread to re-compete for the mutex of the CPU component.

### Claim 28 (depends on 21)

The method according to claim 21, wherein the mutex of the CPU component is located in a private cache of the CPU.

### Claim 29 (depends on 21)

The method according to claim 21, wherein the mutex comprises a corresponding mutual exclusion lock.

### Claim 30 (depends on 21)

The method according to claim 21, wherein executing the critical section corresponding to the target thread that has obtained the spin lock of the CPU comprises executing the critical section in an uninterrupted manner on the CPU until completion.

### Claim 31 (depends on 21)

The method according to claim 21, wherein the CPU component that is operable to execute one thread at any given time comprises a CPU core of the CPU.

### Claim 32

A computer-implemented system, comprising:
one or more computers; and
one or more computer memory devices interoperably coupled with the one or more computers and having tangible, non-transitory, machine-readable media storing one or more instructions that, when executed by the one or more computers, perform operations comprising:
at each of a plurality of CPU components of a CPU: enabling threads awaiting execution on the CPU component to compete for a respective mutex of the CPU component, wherein each CPU component is operable to execute one thread at any given time;
identifying a plurality of threads that have each obtained the respective mutex;
enabling the plurality of threads that have each obtained the respective mutex of a CPU component to compete for a spin lock of the CPU;
identifying, from the plurality of threads, a target thread holding a mutex of a CPU component that has also obtained the spin lock of the CPU; and
executing, at the CPU, a critical section corresponding to the target thread that has obtained the spin lock while remaining threads that have not obtained the respective mutexes are sleeping.

### Claim 33 (depends on 32)

The system according to claim 32, wherein the operations further comprise releasing the mutex of the CPU component and the spin lock of the CPU that are obtained by the target thread only after execution of the critical section corresponding to the target thread is completed.

### Claim 34 (depends on 33)

The system according to claim 33, wherein the releasing the mutex of the CPU component and the spin lock of the CPU that are obtained by the target thread comprises:
first releasing the spin lock of the CPU obtained by the target thread, and then releasing the mutex of the CPU component obtained by the target thread.

### Claim 35 (depends on 34)

The system according to claim 34, wherein the operations further comprise:
enabling one or more threads that have not obtained the spin lock to continuously detect whether the spin lock of the CPU is released.

### Claim 36 (depends on 35)

The system according to claim 35, wherein the operations further comprise:
in response to detecting that the spin lock is released, re-competing, by the one or more threads that have not obtained the spin lock, for the spin lock of the CPU.

### Claim 37 (depends on 32)

The system according to claim 32, wherein the remaining threads that have not obtained the respective mutexes and that are sleeping do not compete for any of the respective mutexes of the CPU components or the spin lock of the CPU.

### Claim 38 (depends on 33)

The system according to claim 33, wherein after the releasing the mutex of the CPU component obtained by the target thread, the operations further comprise:
waking up any sleeping thread on the CPU component the mutex of which has been released; and
enabling the sleeping thread to re-compete for the mutex of the CPU component.

### Claim 39 (depends on 32)

The system according to claim 32, wherein the mutex of the CPU component is located in a private cache of the CPU.

### Claim 40

A non-transitory, computer-readable medium storing one or more instructions executable by a computer system to perform operations comprising:
at each of a plurality of CPU components of a CPU: enabling threads awaiting execution on the CPU component to compete for a respective mutex of the CPU component, wherein each CPU component is operable to execute one thread at any given time;
identifying a plurality of threads that have each obtained the respective mutex;
enabling the plurality of threads that have each obtained the respective mutex of a CPU component to compete for a spin lock of the CPU;
identifying, from the plurality of threads, a target thread holding a mutex of a CPU component that has also obtained the spin lock of the CPU; and
executing, at the CPU, a critical section corresponding to the target thread that has obtained the spin lock while remaining threads that have not obtained the respective mutexes are sleeping.
