一个中央处理器可带若干个终端。终端每隔一定时间(均值为25秒的指数分布)向CPU传送一个任务,服务时间服从均值为0.8秒的指数分布。
该计算机系统用轮转法选择下一进程。
1 CPU为每一个任务分配的服务时间最大为:
q=0.1秒。
2 若进程的剩余服务时间s<=q,CPU用s+t时间
处理该进程(t=0.015秒,切换时间)。
3 若s>q,CPU用q+t完成该任务的处理
和切换后,该任务排到队尾,剩余服
务时间减少q。CPU为下一进程服务。
4 重复上述步骤直到某任务结果返回终
端,经过一定间隔时间下一任务再传
出。
5 模拟处理完1000个任务的情形。在响
应时间低于30秒的前提下,求CPU可
带最大终端数和CPU的利用率。
事件:n个到达,1个离开
思路:
1.到达事件:记录到达时间,服务时间,所属终端,该终端的下一个到达时间无穷。
若CPU不忙,则占用CPU,CPU状态设忙,安排占用CPU.
2.安排占用CPU:若本次可以完成处理,则安排离开系统的时间,所需的剩余服务时间为0;若还得继续处理,则安排离开CPU时间,计算所需的剩余服务时间。
3.离开CPU事件:若已经处理完成,计算响应时间,安排下一个的到达,若系统为空,则设备只闲,下次离开CPU不发生,若不空,则安排队首占用CPU。
若没服务完成,若系统只有自己,安排自己占用CPU,若系统还有其他人,安排队首占用CPU,自己排到队尾。
java程序1:事件数组版本:
到达事件:
public void arrive(int terminalNo){
this.currentTime=events[terminalNo];
this.numberOfTaskInSystem++;
Task tmp=new Task();
tmp.setArriveTime(events[terminalNo]);
tmp.setServiceTime(this.GenerateExpRandom(theta2));
tmp.setTerminalNo(terminalNo);
queue.add(tmp);
System.out.println("at "+this.currentTime+"----terminal["+tmp.getTerminalNo()+"] arrived...");
events[terminalNo]=this.INFINITE;
if(statusBusy==false){
this.statusBusy=true;
this.task=this.queue.getFirst();
this.occupyCPU();
}
}
占用CPU:
public void occupyCPU(){
//this.task=queue.getFirst();
if(task.getServiceTime()<=this.cycleTime){
events[TerminalSize+1]=task.getServiceTime()+this.currentTime;
task.setServiceTime(0.0);
}else{
events[TerminalSize+1]=this.cycleTime+this.currentTime;
task.setServiceTime(task.getServiceTime()-this.cycleTime);
}
}
离开CPU:
public void depart(){
this.currentTime=events[TerminalSize+1];
if(task.getServiceTime()==0){
// 可以离开系统,计算停留时间
this.stayingTime+=this.currentTime-task.getArriveTime();
this.finishNumer++;
//安排此终端下次到达时间
events[task.getTerminalNo()]=this.currentTime+this.GenerateExpRandom(theta1);
this.numberOfTaskInSystem--;
queue.removeFirst();
System.out.println("at "+this.currentTime+"----terminal["+task.getTerminalNo()+"] depart cpu...");
if(this.numberOfTaskInSystem==0){
this.statusBusy=false;
events[TerminalSize+1]=this.INFINITE;
}else{
this.task=queue.getFirst();
this.occupyCPU();
}
}else{
if(this.numberOfTaskInSystem==1){
this.occupyCPU();
}else{
Task tmp=queue.getFirst();
queue.removeFirst();
queue.addLast(tmp);
this.task=queue.getFirst();
this.occupyCPU();
}
}
}
链表版本:
到达CPU:
public void arrive(Event e){
this.currentTime=e.getTime();
this.numberOfTaskInSystem++;
Task tmp=new Task();
tmp.setArriveTime(e.getTime());
tmp.setServiceTime(this.GenerateExpRandom(theta2));
tmp.setTerminalNo(e.getTerminalNo());
queue.add(tmp);
System.out.println("at "+this.currentTime+"----terminal["+tmp.getTerminalNo()+"] arrived...");
if(statusBusy==false){
this.statusBusy=true;
this.task=this.queue.getFirst();
this.occupyCPU();
}
}
占用CPU:
public void occupyCPU(){
//this.task=queue.getFirst();
Event e=new Event();
e.setEventType(Event.departType);
e.setTerminalNo(task.getTerminalNo());
if(task.getServiceTime()<=this.cycleTime){
e.setTime(task.getServiceTime()+this.currentTime);
task.setServiceTime(0.0);
}else{
e.setTime(this.cycleTime+this.currentTime);
task.setServiceTime(task.getServiceTime()-this.cycleTime);
}
eventList.add(e);
}
离开CPU:
public void depart(Event e){
this.currentTime=e.getTime();
if(task.getServiceTime()==0){
// 可以离开系统,计算停留时间
this.stayingTime+=this.currentTime-task.getArriveTime();
this.finishNumer++;
//安排此终端下次到达时间
//System.out.println("测试两个地方的终端号:"+(e.getTerminalNo()==task.getTerminalNo()));
Event e1=new Event();
e1.setEventType(Event.arriveType);
e1.setTerminalNo(e.getTerminalNo());
e1.setTime(this.currentTime+this.GenerateExpRandom(theta1));
eventList.add(e1);
this.numberOfTaskInSystem--;
queue.removeFirst();
System.out.println("at "+this.currentTime+"----terminal["+task.getTerminalNo()+"] depart cpu...");
if(this.numberOfTaskInSystem==0){
this.statusBusy=false;
}else{
this.task=queue.getFirst();
this.occupyCPU();
}
}else{
if(this.numberOfTaskInSystem==1){
this.occupyCPU();
}else{
Task tmp=queue.getFirst();
queue.removeFirst();
queue.addLast(tmp);
this.task=queue.getFirst();
this.occupyCPU();
}
}
}
分享到:
相关推荐
重写覆盖原模型中使用的 cpu_nms.pyx, 解决碰到的 ModuleNotFoundError: No module named 'utils.nms.cpu_nms' 报错
CPU与简单模型机设计实验.pdf
湖南大学数电综合设计——模型机,文件内含模型机的全部模块代码(ALU、IN控制单元、OUT控制单元、PC、RAM、寄存器、寄存器组、控制器、选择器、移位逻辑、指令译码器),及综合报告
西门子S7-300 315 CPU_iso三维模型图zip,西门子S7-300 315 CPU_iso三维模型图
西门子PLC;S7-1200;CPU-1215C-3D模型.STEP ;及PLC尺寸大小
(1) 选定CPU中所使用的产要器件; (2) 根据指令系统、选用的器件和设计指标,设计指令流的数据通路; (3) 根据指令系统、选用的器件和设计指标,设计数据流的数据通路。 计算机的工作过程,实质上是不同的数据流在...
计算机组成原理实验说明书_CPU与简单模型机设计实验_西安唐都.pdf
java 锁 内存模型, 对于想了解cpu锁,内存模型的同学是很不错的资料
ChatGLM-6B 清华大学实现的一个开源的、支持中英双语、支持图像理解的对话语言模型.本文档详细介绍了再Windows系统下如何使用现有的资源部署运行ChatGLM-6B模型。
简易CPU模型设计verilog.pdf
使用onnxRt CPU 部署tensorflow模型 需要使用tensorflow simple_save将模型保存为带参数的pb模型,再转化为onnx模型进行部署。训练:TensorFlow1.13.1 cuda 10.0 cudnn7.6.5 部署:cuda10.2 tensorRT8.0.1.6 cudnn...
西门子S7-400 417 CPU_iso三维模型图zip,西门子S7-400 417 CPU_iso三维模型图
计算机组成原理(CPU模型),有需要的可以看一看。。。。
CPU与简单模型机设计实验中的关键问题分析.docxCPU与简单模型机设计实验中的关键问题分析.docxCPU与简单模型机设计实验中的关键问题分析.docxCPU与简单模型机设计实验中的关键问题分析.docxCPU与简单模型机设计实验...
verilog实现的机器字长16位的单周期处理器设计,单周期CPU模型机的设计与实现。十几条指令,带文档和接口,设计流程的说明,非常详细。自己写的。有扩展需求还可以私信我
模型机设计讲义,对CPU设计有详细讲解。模型机设计讲义,对CPU设计有详细讲解。
CPU模型的组成及其数据通路.pptx
2.使用Verilog HDL 在Max Plus2上实现CPU模型的仿真。 二、设计目标 1.设计可以实现基本的指令运算指令、数据传输指令、输入输出指令、转移指令。 2.实现乘法。(借鉴网上资料) 三、CPU结构 1.CPU结构图(见图...