📄 cpu.m
字号:
%--------------------------------------------------------------------------
clc;
clear;
%--------------------------------------------------------------------------
GlobalCycle=0;
EndTime=500; %========>
DiskTime=5;
Ts=1;
NProcess=3;
Qlen=NProcess;
TB=[200;10;10];
QReady=[1 0;
2 0;
3 0]; % 1 col is the process name;2 col is the Tb
QReady(:,2)=TB;
QReady_WaitTime=zeros(NProcess,1);
QReady_History=zeros(2*NProcess+3,EndTime);
QDisk=zeros(NProcess,2); % 1 col is the process name;2 col is the endtime
QDisk(:,2)=EndTime+100; % initial the endtime to the EndTime
%--------------------------------------------------------------------------
while GlobalCycle<EndTime
curP=0; %make sure not store the old state, 0 mean the cpu is idle
% disp('------before check and SJF at Time %d ---',GlobalCycle);
% QDisk
% QReady
[QDisk,QReady]=CheckDiskQueue_FCFSorSJF(QDisk,QReady,Qlen,GlobalCycle,TB,EndTime); %......
if sum(QReady(:,1))==0 % check before pick up
fprintf('CPU idle at T=%d....\n',GlobalCycle);
QReady_History(:,GlobalCycle+1)=-1;% Idle state
GlobalCycle=GlobalCycle+1;
continue;
end
%--------------------we know there are processes in the ReadQueue------------------
% disp('----before SJF');
[curP,QReady]=SJF(QReady,Qlen); %pick up a process=====>>
% disp('----after');
QReady_History(:,GlobalCycle+1)=[QReady(:,1);0;QDisk(:,1);0;curP];% the current state
GlobalCycle=GlobalCycle+TB(curP); %TB is GOOD for debug....
GlobalCycle=GlobalCycle+Ts;
value=GlobalCycle+DiskTime;
[QDisk,pos]=InQueue2(curP,value,QDisk,Qlen,'D'); %put into the DiskQueue
end
OutputResult(QReady_History,EndTime,NProcess);
Analysis(QReady_History,TB,1,Qlen);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -