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

📄 analysis_rr.m

📁 3个CPU调度算法的simulation. 分别是Short Job First,High Return Ration Next, Round Robin. 模拟得到R,U,S等重要指标。
💻 M
字号:
function Analysis_RR(History,TB,cpubP,TQ,Qlen)
%here the GlobalCycle is not the same as that in the CPU()


UseTimeForP=zeros(1,Qlen);
RoundForP=zeros(1,Qlen);

CycleStart=input('CycleStart:');
CycleEnd=input('CycleEnd:');
GlobalCycle=CycleEnd-CycleStart;


i=CycleStart+1;           %QRedeady_History start from 1
j=CycleEnd;              %this is end of the next round, do not use CycleEnd+1
UserTime=0;
CPUBoundTime=0;
IdleTime=0;

for k=i:j                %calculate how many times the p running on the CPU.
    curP=History(19,k);           %Need to change is the number of process change!!!(*****)
    
    if (curP>0)                   %  if 0, one p is picked up, cound the pickingup time of each p!!
        
        UseTimeForP(curP)=UseTimeForP(curP)+History(20,k); %accumulate each p's user time!!!(*****)
    end
    
    if curP==-1    %Idle
        IdleTime=IdleTime+1;
    end
end


%Find the User Time and CPU Bound Time
for i=1:Qlen
   UserTime=UserTime+UseTimeForP(i);  %  
end
CPUBoundTime=UseTimeForP(cpubP);

%Find the rounds
for i=1:Qlen
   RoundForP(i)=UseTimeForP(i)/TB(i);  %Could be float??! 
   fprintf('P%d runs %d times\n',i,RoundForP(i));  %******************************
end

%print out
disp('==========================================================')
fprintf('User Time=%d\n',UserTime);
fprintf('GlobalCycle=%d\n\n',GlobalCycle);
fprintf('CPUBoundTime=%d\n',CPUBoundTime);
fprintf('Idle Time=%d\n\n',IdleTime);

cnt=0;
sum=0;
for i=1:Qlen
   if i~=cpubP
        if  RoundForP(i)~=0
           fprintf('R%d=%.2f\n',i,GlobalCycle/RoundForP(i));
           
           cnt=cnt+1;
           sum=sum+GlobalCycle/RoundForP(i);
        else
           fprintf('R%d starving\n',i);
       end
   end
end
fprintf('Average R=%.2f\n',sum/cnt);

fprintf('U=%.2f%%\n',(UserTime/GlobalCycle)*100);
fprintf('S=%.2f\n',GlobalCycle/CPUBoundTime);


%print out

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -