# US 2014/0157287 A1 · Optimized Context Switching for Long-Running Processes

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

- Number: US 2014/0157287 A1
- Document ID: US20140157287A1
- Status: Published application
- Kind: A1
- Application number: 13/691,066
- Filed: 2012-11-30
- Published: 2014-06-05
- Earliest claimed: 2012-11-30
- Assignees: Advanced Micro Devices, Inc.
- Applicants: Advanced Micro Devices, Inc
- Inventors: Lee W. HOWES; Benedict R. GASTER; Michael MANTOR
- Web page: https://patentgrep.com/patent/US20140157287A1

## CPC

- G06F 9/461: {Saving or restoring of program or task context}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Methods, systems, and computer readable storage media embodiments allow for low overhead context switching of threads. In embodiments, applications, such as, but not limited to, iterative data-parallel applications, substantially reduce the overhead of context switching by adding a user or higher-level program configurability of a state to be saved upon preempting of a executing thread. These methods, systems, and computer readable storage media include aspects of running a group of threads on a processor, saving state information by respective threads in the group in response to a signal from a scheduler, and pre-empting running of the group after the saving of the state information.

## Claims

### Claim 1

A method, comprising:
running a group of threads on a processor;
saving state information by respective threads in the group in response to a signal from a scheduler; and
pre-empting the running of the group after the saving.

### Claim 2 (depends on 1)

The method of claim 1, wherein the saving the state information comprises:
selectively saving elements from a context of the respective threads.

### Claim 3 (depends on 1)

The method of claim 1, wherein the saving the state information comprises:
detecting the signal from the scheduler;
calling a user-specified code block by each of the respective threads in response to the detected signal, wherein the code block is configured to save the state information.

### Claim 4 (depends on 3)

The method of claim 3, wherein the saving the state information further comprises:
determining a point at which to yield the running by the respective threads; and
calling the code block at the determined point.

### Claim 5 (depends on 4)

The method of claim 4, wherein the determining the point comprises:
determining the point in order to reduce an amount of the state information to be saved.

### Claim 6 (depends on 5)

The method of claim 5, wherein the determining the point in order to reduce an amount of the state information to be saved is performed by a compiler.

### Claim 7 (depends on 5)

The method of claim 5, wherein the determining the point in order to reduce an amount of the state information to be saved is performed dynamically at runtime.

### Claim 8 (depends on 1)

The method of claim 1, wherein the saving state information comprises:
detecting the signal from the scheduler;
calling a compiler-generated code block by each of the respective threads in response to the detected signal, wherein the code block is configured to save the state information.

### Claim 9 (depends on 1)

The method of claim 1, further comprising:
resuming the pre-empted group; and
restoring the selectively saved state information by respective threads from the resumed group.

### Claim 10 (depends on 8)

The method of claim 8, wherein the restoring comprises:
reading the selectively saved state information;
determining a resume point based upon the read selectively saved state information; and
continuing running from the determined resume point.

### Claim 11 (depends on 1)

The method of claim 1, further comprising:
determining by the scheduler to perform a context switch;
setting, by the scheduler in response to the determining, the signal in order to yield the running threads; and
starting another group of threads on the processor.

### Claim 12 (depends on 11)

The method of claim 11, wherein the setting comprises:
selectively setting the signal for iterative applications.

### Claim 13

A system, comprising:
a processor;
a group of threads executing on the processor; and
a context switching module that, in response to being executed by the processor, is configured to cause the processor to:
save state information by respective threads in the group in response to a signal from a scheduler; and
pre-empt the running of the group after the saving.

### Claim 14 (depends on 13)

The system of claim 13, wherein the context switching module is configured to farther cause the processor to:
selectively save elements from a context of the respective threads.

### Claim 15 (depends on 13)

The system of claim 13, wherein the context switching module is configured to further cause the processor to:
detect the signal from the scheduler;
call a user-specified code block by each of the respective threads in response to the detected signal, wherein the code block is configured to save the state information.

### Claim 16 (depends on 13)

The system of claim 13, further comprising:
a resume module that, in response to being executed by the processor, is configured to cause the processor to:
resume the pre-empted group on the processor; and
restore the selectively saved state information by respective threads from the resumed group.

### Claim 17 (depends on 16)

The system of claim 16, wherein the resume module is configured to further cause the processor to:
read the selectively saved state information by the respective threads;
determine a resume point based upon the read selectively saved state information; and
continue execution of the respective threads from the determined resume point.

### Claim 18

A computer readable storage medium having instructions, the instructions when executed by a processor, causes the processor to execute a method comprising:
running a group of threads on a processor;
saving state information by respective threads in the group in response to a signal from a scheduler; and
pre-empting the running of the group after the saving.

### Claim 19 (depends on 18)

The computer readable storage of claim 18, wherein the saving individual state comprises:
selectively saving elements from a context of each of the respective threads.

### Claim 20 (depends on 18)

The computer readable storage of claim 18, wherein the method further comprises:
resuming the pre-empted group on the processor; and
restoring the selectively saved individual state information by respective threads from the resumed group.
