⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpu.asv

📁 3个CPU调度算法的simulation. 分别是Short Job First,High Return Ration Next, Round Robin. 模拟得到R,U,S等重要指标。
💻 ASV
字号:
%--------------------------------------------------------------------------
clc;
clear;
%--------------------------------------------------------------------------

QReady=[1 0 0 0;
        2 0 0 0;
        3 0 0 0];                  % 1 col is the process name;2 col is the bust time; 3 col is the waiting time; 4 col for the temperally store waitingTime/TB....
QReady(:,2)=TB;
QReady(:,3)=GlobalCycle;                  %  for the first time.                

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
-------------------
GlobalCycle=0;
EndTime=1000;                                                       %========>
DiskTime=4; %4 or 11

Ts=1;

NProcess=7;
Qlen=NProcess;
TB=[3;5;3;5;3;5;105];

cpubP=7;                      %who is the CPU-bound process

QReady=[1 0 0 0;
        2 0 0 0;
        3 0 0 0;
        4 0 0 0;
        5 0 0 0;
        6 0 0 0;
        7 0 0 0]; %  % 1 col is the process name;2 col is the bust time; %3 col is the waiting time; 4 col for the temperally store waitingTime/TB....
QReady(:,2)=TB;

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 when the cpu is idle.  could cause TB(0)......
%   fprintf('------before check and HRRN-Time now is:%d--',GlobalCycle);
%   QDisk
%   QReady
  [QDisk,QReady]=CheckDiskQueue_HRRN(QDisk,QReady,Qlen,GlobalCycle,TB,EndTime); %......
  
  
  if sum(QReady(:,1))==0  % check before pick up, 0 mean the cpu is idle
      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 HRRN');
  [curP,QReady]=HRRN(QReady,Qlen,GlobalCycle);                                     %pick up a process=====>>
%   disp('----after HRRN');
  QReady_History(:,GlobalCycle+1)=[QReady(:,1);0;QDisk(:,1);0;curP]; % the current state,remember GlobalCycle+1....
  
    
   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 + -