# US 2025/0165280 A1 · System and method for mitigating the effects of preemption in multitasking systems

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

- Number: US 2025/0165280 A1
- Document ID: US20250165280A1
- Status: Published application
- Kind: A1
- Application number: 18/515,007
- Filed: 2023-11-20
- Published: 2025-05-22
- Earliest claimed: 2023-11-20
- Inventors: Eric Allen Grant
- Web page: https://patentgrep.com/patent/US20250165280A1

## CPC

- G06F 9/4812: {by interrupt, e.g. masked}
- G06F 9/485: {Task life-cycle, e.g. stopping, restarting, resuming execution (G06F9/4881 takes precedence)}
- G06F 9/526: {Mutual exclusion algorithms}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A system and method for avoiding problems associated with locks and preemption. After interrupting a rollback section of user code, the kernel causes a roll back” to the first instruction in the section. After the interrupt, when control is returned to the interrupted user-level thread, execution resumes at the beginning of the rollback section, not the point where the interrupt occurred. After interrupting a rollforward section of the present invention, the kernel causes execution to “roll forward” through the section to the last instruction. That is, the kernel essentially suppresses interrupts within a rollforward section, delaying the servicing of any interrupt until the section completes. Spinlocks employing the techniques of the present invention have none of the disadvantages of traditional locks: they formally fit the definition of “lock-free” code.

## Claims

### Claim 1

A process for handling interrupts in a kernel, the process comprising the acts of:
beginning execution of a designated section of code;
recognizing an interrupt occurred during the execution of the designated section of code, wherein the interrupt stops execution of the designated section of code;
postponing any action that would normally be performed to process the interrupt; and
restarting execution of the designated section of code at the point where execution was previously interrupted.

### Claim 2 (depends on 1)

The process according to claim 1, further comprising:
after the execution of the final instruction in the designated section of code, the kernel executing an interrupt handler that would normally process the postponed interrupt.

### Claim 3 (depends on 1)

The process according to claim 1, wherein the time between the beginning of the execution of the designated section of code and the end of the execution of the designated section of code is bounded.

### Claim 4 (depends on 1)

The process according to claim 1, wherein the designated section of code is provided by the kernel.

### Claim 5 (depends on 4)

The process according to claim 4, wherein the designated section of code is provided by the kernel in a common area of memory.

### Claim 6 (depends on 5)

The process according to claim 5, wherein a user application executes the designated section of code in the common area of memory.

### Claim 7 (depends on 1)

The process according to claim 1, wherein the designated section of code is denoted a rollforward section of code, the process further comprising:
prior to beginning the rollforward section of code, beginning execution of a rollback section of code;
recognizing an interrupt occurred during the rollback section of code, wherein the interrupt stops execution of the rollback section of code;
executing an interrupt handler to process the interrupt;
restarting execution of the interrupted rollback section of code at the beginning of the rollback section of code.

### Claim 8 (depends on 7)

The process according to claim 7, further comprising:
executing the rollback section of code and the rollforward section of code contiguously.

### Claim 9 (depends on 2)

The process according to claim 2, wherein the interrupt is a hardware interrupt.

### Claim 10

A process for handling interrupts in a kernel, the process comprising the acts of:
recognizing an interrupt has occurred;
determining if the interrupt occurred during the execution of one of a plurality of designated routines;
if the interrupt did not occur during the execution of one of a plurality of designated routines, executing normal interrupt handling;
determining if the interrupt occurred during the execution of the plurality of designated routines denoted as a rollforward routine;
if the interrupt occurred during the execution of the rollforward routine:
masking the interrupt;
resuming the interrupted rollforward routine;
completing execution of the interrupted rollforward routine; and
executing the normal interrupt handling;

### Claim 11 (depends on 10)

The process according to claim 10, further comprising:
determining if the interrupt occurred during the execution of another one of the plurality of designated routines denoted as a rollback routine;
if the interrupt occurred during the execution of the rollback routine:
setting an address to which the kernel returns;
executing the normal interrupt handling; and
after the normal interrupt handling is completed, returning execution to the previously set address.

### Claim 12 (depends on 11)

The process according to claim 11, wherein the set address is the beginning of the rollback routine.

### Claim 13 (depends on 11)

The process according to claim 11, further comprising:
determining that the interrupt occurred on a boundary between the rollback and rollforward routines;
determining if a modification to a shared data structure by the rollback routine was successful;
if the modification was successful, continuing the process as if the interrupt occurred during the rollforward routine; and
if the modification was not successful, continuing the process as if the interrupt occurred during the rollback routine.

### Claim 14 (depends on 13)

The process according to claim 13, wherein the act of determining if the modification to the shared data structure was successful further comprises examining a status register.

### Claim 15 (depends on 11)

The process according to claim 11, further comprising:
determining if the interrupt is a non-maskable interrupt;
if the interrupt is a non-maskable interrupt:
setting a flag to indicate that the non-maskable interrupt must be handled later;
resuming execution of the interrupted routine;
passing control to a non-maskable interrupt handler after completion of the execution of the interrupted routine; and
processing the interrupt by the non-maskable interrupt handler before any other action is taken by the kernel.

### Claim 16 (depends on 10)

The process according to claim 10, further comprising:
determining if the interrupt is caused by a fault;
following the determination that the fault caused interrupt occurred during the execution of the rollforward routine:
determining if special handling of the fault caused interrupt is required;
if it is determined that special handling is required:
setting a flag to indicate that the fault caused interrupt must be handled later;
resuming execution of the interrupted rollforward routine;
completing execution of the interrupted rollforward routine; and
executing the normal interrupt handling;
if it is determined that special handling is not required:
determining if the fault occurred in the rollforward routine that had been previously resumed;
if the fault occurred in the rollforward routine that had been previously resumed:
executing the handling of the previously masked interrupt that had been postponed; and
reporting a fatal exception;
if the fault occurred in the rollforward routine that had not been previously resumed:
immediately reporting a fatal exception.

### Claim 17 (depends on 11)

The process according to claim 11, further comprising:
determining if the interrupt is caused by a fault;
following the determination that the fault caused interrupt occurred during the execution of the rollback routine:
determining if special handling of the fault caused interrupt is required;
if it is determined that special handling is required:
setting a flag to suppress any exceptions caused by the fault;
setting an address to which the kernel returns; and
executing the normal interrupt handling.

### Claim 18 (depends on 10)

The process according to claim 10, further comprising:
determining if a value in a specified register is an unlikely value; and
if the value is not an unlikely value, executing a normal interrupt handling.

### Claim 19 (depends on 1)

The process according to claim 1, wherein a plurality of concurrent threads are executing, and the designated section of code is denoted a rollforward section of code, the process further comprising acts for creating, acquiring, using, and releasing a spinlock comprising:
within a single thread:
allocating an Anderson array-based spinlock having N elements, where N is a power of 2 not less than a maximum number of processors in the system;
initializing an index to 0, a value of a lock field of a first element to ‘locked’, and values of lock fields of all other elements to ‘unlocked’;
within any of the plurality of concurrently executing threads:
executing, immediately preceding the rollforward section of code, an atomic fetch-and-increment operation that increments the index;
reading, within the rollforward section of code, the value of the lock field of element (i % N), where i is the index returned by such operation;
repeating the reading act until such value is ‘unlocked’ whereby the spinlock is acquired;
resetting the lock field of element (i % N) to ‘locked’;
executing, within the rollforward section of code, a critical section protected by the acquired spinlock by a process comprising:
reading zero or more values written to the element by the previous holder of the spinlock;
reading from or writing to shared memory; and
writing zero or more values to element ((i+1) % N); and
releasing, within the rollforward section, the acquired spinlock by setting the value of the lock field of element ((i+1) % N) to ‘unlocked’.

### Claim 20 (depends on 19)

The process according to claim 19 further comprising:
initializing the value of the first element to N, and the values of all other elements to their respective indices 1 to N−1;
repeating the reading act until the value is i;
omitting the resetting the value of element (i % N); and
releasing the acquired spinlock by setting the value of element ((i+1) % N) to (i+1+N).

### Claim 21

A process for handling VM exits in a hardware-assisted virtualization environment, the process in a hypervisor comprising the acts of:
beginning execution of a designated section of code by a VM thread;
recognizing a VM exit occurred during the execution of the designated section of code, wherein the VM exit stops execution of the designated section of code;
postponing any action that would normally be performed to process the VM exit;
restarting execution of the designated section of code at the point where execution was previously interrupted.

### Claim 22

A system for handling interrupts in a multicore processing environment comprising:
a plurality of cores, each of the plurality of cores executing within a virtual address space comprising a user space and a kernel space;
the user space comprising code and data;
the kernel space comprising at least one interrupt handler and at least one designated routine; wherein the at least one designated routine is called for execution by the code in the user space;
the interrupt handlers:
recognizing an interrupt occurred during the execution of the at least one designated routine, wherein execution of the designated routine is interrupted and execution resumes at the at least one handler;
postponing any action that would normally be performed to process the interrupt;
resuming execution of the designated routine at the point where execution was previously interrupted; and
ensuring that in the absence of a synchronous fault, the execution continues uninterrupted until the end of the designated routine.

### Claim 23 (depends on 22)

The system according to claim 22, wherein plurality of processors are executing virtual machine threads and the kernel is a hypervisor overseeing execution of those threads.

### Claim 24 (depends on 22)

The system according to claim 22 wherein the kernel includes regular interrupt handlers and special interrupt handlers and further wherein the special interrupt handlers induce a non-maskable handler, a page fault handler and a debug handler.

### Claim 25 (depends on 22)

The system according to claim 22 wherein the virtual address space of the kernel space is common between all of the plurality of cores.
