Commit Title: Implement Priority-Based Scheduling in Scheduler
Commit Body:
-
Add
priorityField:- Introduced a new
int priority;field in thestruct procwithinproc.hto store the priority of each process.
- Introduced a new
-
Initialize Process Priority:
- Updated the
procinit()function inproc.cto set a default priority (p->priority = 10;) for each process during initialization.
- Updated the
-
Modify Scheduler for Priority Scheduling:
- Enhanced the
scheduler()function inproc.cto implement priority-based scheduling. - Traverses the process table to identify the runnable process with the highest priority.
- Ensures that the highest priority process is selected for execution by comparing the
priorityfields.
- Enhanced the
-
Improve Lock Management:
- Adjusted lock acquisition and release logic to prevent deadlocks and ensure proper synchronization.
- Ensured that locks on previously selected highest priority processes are released before selecting a new one.
- Added comments to clarify the rationale behind lock handling during the scheduling process.
-
Ensure System Stability:
- Verified that the scheduler correctly handles cases where no runnable processes are available by entering a low-power state (
wfi) without holding any locks. - Maintained consistency in
c->procto accurately reflect the currently running process.
- Verified that the scheduler correctly handles cases where no runnable processes are available by entering a low-power state (
Summary: This commit enhances the process scheduler by introducing a priority-based scheduling algorithm. By adding a priority field to each process and modifying the scheduler to select the highest priority runnable process, the system can achieve better responsiveness and resource management. Additionally, improvements in lock management ensure that the scheduler operates reliably without introducing concurrency issues.