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

📄 analysis_rr.asv

📁 3个CPU调度算法的simulation. 分别是Short Job First,High Return Ration Next, Round Robin. 模拟得到R,U,S等重要指标。
💻 ASV
字号:
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(9,k);
    if (curP>0)                   %  if 0, one p is picked up, cound the pickingup time of each p!!
        UseTimeForP(curP)=UseTimeForP(curP)+History(10,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('CPUBoundTime=%d\n',CPUBoundTime);
fprintf('GlobalCycle=%d\n',GlobalCycle);
fprintf('Idle=%d\n',IdleTime);

for i=1:Qlen
   if i~=cpubP
        fprintf('R%d=%f\n',i,GlobalCycle/RoundForP(i));
   end
end

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


%print out

⌨️ 快捷键说明

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