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

📄 analysis.m

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

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

CountP=zeros(1,Qlen);

%Find the User Time and CPU Bound Time
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
    curP=History(19,k);              %Need to change is the number of process change!!!*****
    if (curP>0)  %if 0,sikp idle
        UserTime=UserTime+TB(curP);
        CountP(curP)=CountP(curP)+1;  %count the show up times
        
        if (curP==cpubP)
            CPUBoundTime=CPUBoundTime+TB(curP);
        end
    end
    
    if curP==-1    %Idle
        IdleTime=IdleTime+1;
    end
end

%Find the User Time and CPU Bound Time and the Rounds!!
for i=1:Qlen
   fprintf('P%d runs %d times\n',i,CountP(i));
end



%print out
disp('==========================================================')
for i=1:Qlen
   if i~=cpubP
       if CountP(i)~=0
          fprintf('R%d=%f\n',i,GlobalCycle/CountP(i));
       else
          fprintf('R%d starving\n',i);
       end
   end
end

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

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




⌨️ 快捷键说明

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