p37: Introduce atomic spinlocks for multiprocessor concurrency#358
Open
2023cs50578 wants to merge 5 commits intocodenet:p31-umallocfrom
Open
p37: Introduce atomic spinlocks for multiprocessor concurrency#3582023cs50578 wants to merge 5 commits intocodenet:p31-umallocfrom
2023cs50578 wants to merge 5 commits intocodenet:p31-umallocfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
This branch initiates the transition from a uniprocessor architecture to Symmetric Multiprocessing (SMP). It introduces the core mutual exclusion primitives (
spinlocks) required to protect shared kernel data structures from race conditions once multiple CPU cores are booted.Core Changes
x86.h: Ensured the atomic hardware instructionxchg(exchange) is available for read-modify-write operations, leveraging the CPU's hardware-level locking.spinlock.h: Defined thestruct spinlockto track lock state (locked) and diagnostic data (holdingcpu).spinlock.c: Implemented the core lock lifecycle functions:initlock: Initializes lock state.acquire: Uses the atomicxchginstruction in a tight loop to spin until the lock is available. Includes__sync_synchronize()barriers to prevent compiler/hardware instruction reordering and wraps the logic inpushcli()to prevent deadlocks from interrupt handlers.release: Uses an atomicmovlto clear the lock state and issues memory barriers to ensure critical section stores are visible before the lock is released.holding: Diagnostic utility to verify ownership.defs.h: Added the respective prototypes for the spinlock API.Next Steps
With the atomic primitives in place, subsequent branches can begin retrofitting global kernel structures (e.g., the physical memory allocator
kmem, the process tableptable) with these locks in preparation for booting the Application Processors (APs).