feat: implement Multilevel Queue (MLQ) scheduling algorithm
- Added MLQ scheduling logic in multilevel.ts, including queue selection, preemption rules, and quantum expiration checks. - Updated SchedulerConfig to include mlqQueues for MLQ configuration. - Created default MLQ queue definitions for use in presets and process store. - Modified process store to auto-increment process IDs. - Enhanced tests for MLQ scheduling, covering selection, preemption, quantum expiration, and integration scenarios. - Updated existing presets to support MLQ and adjusted process definitions to include auto-incremented IDs.
This commit is contained in:
1 parent
64bbc4ca27
commit
9c552e53fa
12 files changed
+550
-67
No files matched your search
@@ -1,11 +1,17 @@
|
||||
import { create } from "zustand";
|
||||
import { persist } from "zustand/middleware";
|
||||
import type { Process, SchedulerConfig } from "@core/types";
|
||||
import type { MlqQueueDef, Process, SchedulerConfig } from "@core/types";
|
||||
|
||||
// ============================================================
|
||||
// Defaults
|
||||
// ============================================================
|
||||
|
||||
const DEFAULT_MLQ_QUEUES: MlqQueueDef[] = [
|
||||
{ priorityMin: 1, priorityMax: 3, algorithm: "RR", quantum: 2 },
|
||||
{ priorityMin: 4, priorityMax: 7, algorithm: "PRIORITY_NP", quantum: 2 },
|
||||
{ priorityMin: 8, priorityMax: 10, algorithm: "FCFS", quantum: 2 },
|
||||
];
|
||||
|
||||
const DEFAULT_CONFIG: SchedulerConfig = {
|
||||
algorithm: "FCFS",
|
||||
quantum: 2,
|
||||
@@ -13,6 +19,7 @@ const DEFAULT_CONFIG: SchedulerConfig = {
|
||||
isPreemptive: false,
|
||||
agingEnabled: false,
|
||||
agingInterval: 5,
|
||||
mlqQueues: DEFAULT_MLQ_QUEUES,
|
||||
};
|
||||
|
||||
// ============================================================
|
||||
@@ -22,6 +29,7 @@ const DEFAULT_CONFIG: SchedulerConfig = {
|
||||
interface ProcessStore {
|
||||
processes: Process[];
|
||||
config: SchedulerConfig;
|
||||
_nextPid: number;
|
||||
|
||||
addProcess: (p: Process) => void;
|
||||
updateProcess: (id: string, updates: Partial<Process>) => void;
|
||||
@@ -36,9 +44,13 @@ export const useProcessStore = create<ProcessStore>()(
|
||||
(set) => ({
|
||||
processes: [],
|
||||
config: DEFAULT_CONFIG,
|
||||
_nextPid: 1,
|
||||
|
||||
addProcess: (p) =>
|
||||
set((s) => ({ processes: [...s.processes, p] })),
|
||||
set((s) => ({
|
||||
processes: [...s.processes, { ...p, pid: s._nextPid }],
|
||||
_nextPid: s._nextPid + 1,
|
||||
})),
|
||||
|
||||
updateProcess: (id, updates) =>
|
||||
set((s) => ({
|
||||
@@ -50,12 +62,17 @@ export const useProcessStore = create<ProcessStore>()(
|
||||
removeProcess: (id) =>
|
||||
set((s) => ({ processes: s.processes.filter((p) => p.id !== id) })),
|
||||
|
||||
clearProcesses: () => set({ processes: [] }),
|
||||
clearProcesses: () => set({ processes: [], _nextPid: 1 }),
|
||||
|
||||
setConfig: (updates) =>
|
||||
set((s) => ({ config: { ...s.config, ...updates } })),
|
||||
|
||||
loadPreset: (processes, config) => set({ processes, config }),
|
||||
loadPreset: (processes, config) =>
|
||||
set({
|
||||
processes,
|
||||
config,
|
||||
_nextPid: processes.reduce((max, p) => Math.max(max, p.pid ?? 0), 0) + 1,
|
||||
}),
|
||||
}),
|
||||
{ name: "pss:session" },
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user