当前位置:文档之家› 计算机体系结构实验-单功能流水线调度机构模拟

计算机体系结构实验-单功能流水线调度机构模拟

断流等。只有连续提供同类任务才能充分发挥流水线的效率。在流水线的每一个流水线
段中都要设置一个流水锁存器。流水线需要有“装入时间”和“排空时间”。只有流水线完
全充满时,整个流水线的效率才能得到充分发挥。
四、关键代码
//构筑主窗体大小颜色:
publicvoidlauchFrame() {
this.setLayout(null);
}
class InputActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(jtf2.getText().equals("")) {
Object[] options = { "OK" };
CENTRAL SOUTH UNIVERSITY
计算机体系结构实验报告
题目单功能流水线调度机构模拟
一、实验目的
结合数据结构的相关知识,编写流水线调度模拟程序。
二、实验环境
Eclipse IDE for Java Developers(Version: Kepler Release)
Win7
三、实验内容
jlabel1.setBounds(50, 50, 110, 20);
//jlabel2.setBounds(230, 50, 90, 20);
jta1.setBounds(50, 100, 500, 150);
jtf2.setBounds(170, 50, 70, 20);
//jtf3.setBounds(330, 50, 90, 20);
new Painting(150, 400, 450, 400, Color.red, "", false).draw(g);
new Painting(200, 300, 200, 430, Color.red, "", false).draw(g);
if(timeslice != null && Integer.parseInt(timeslice) <= 8) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public void paint(Graphics g) {
new Painting(50, 280, 500, 180, Color.orange, "", true).draw(g);
newPainting(250, 360, 25, 20, Color.gray, "EA2",true).draw(g);
newPainting(250, 340, 25, 20, Color.gray, "MA1",true).draw(g);
}
这个程序运行的流水线的模拟,依靠的是Java对于界面的编写,流水线的时空图并不是由程序得出,而是由预先设计好的时空图通过编程输出为图像。比如这个当输入为3时,时空图中有6块,每块用new Painting输出。
五、运行截图及源代码
输入为空的时候:
输入超出规定范围的时候:
输入正常的范围,比如t=8的时候的流水线时空图:
源代码:
package waterline;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
jb_input.setBounds(450, 50, 60, 20);
//run.setBounds(450, 260, 100, 20);
this.add(jlabel1);
//this.add(jlabel2);
this.add(jta1);
this.add(jtf2);
//this.add(jtf3);
程序通过模拟单功能流水线调度过程,掌握流水线技术,学会计算流水线的吞吐率、
加速比、效率。
1流水线的表示法有三种:
连接图、时空图、预约表。对于线性流水线,主要考虑前二种。
2流水线的主要特点:
在流水线的每一个功能部件的后面都要有一个缓冲器,称为锁存器、闸门寄存器等,
它的作用是保存本流水段的执行结果。各流水段的时间应尽量相等,否则回引起阻塞、
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.color = color;
this.s = s;
this.f void draw(Graphics g) {
Color c = g.getColor();
newPainting(225, 380, 25, 20, Color.gray, "ED2",true).draw(g);
newPainting(250, 380, 25, 20, Color.gray, "ED3",true).draw(g);
newPainting(225, 360, 25, 20, Color.gray, "EA1",true).draw(g);
this.setBounds(100, 100, 600, 500);
this.setBackground(Color.cyan);
this.setVisible(true);
//当输入为3时,显示的是此时的流水线
if(Integer.parseInt(timeslice) == 3) {
newPainting(200, 380, 25, 20, Color.gray, "ED1",true).draw(g);
}
}
class Painting {
int x, y, width, height;
Color color;
String s;
Boolean flag;
public Painting(int x, int y,int width, int height, Color color, String s, Boolean flag) {
new Painting(225, 380, 25, 20, Color.gray, "ED2", true).draw(g);
new Painting(225, 360, 25, 20, Color.gray, "EA1", true).draw(g);
}
if(Integer.parseInt(timeslice) == 3) {
}
g.setColor(Color.red);
g.drawString(s, x+2, y+15);
g.setColor(c);
}
}
private class PaintThread implements Runnable {
public void run() {
while(true) {
repaint();
JOptionPane.showOptionDialog(null, "你的输入存在“”,请按提示输入!", "警告",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
}
timeslice = jtf2.getText();
jta1.append("Here, we display all the content in the pipline:\n");
jta1.append("Please input a time slice:\n");
//jta1.append(" " + NL[0] + " " + NL[1] + " " + NL[2]);
public void lauchFrame() {
this.setLayout(null);
this.setBounds(100, 100, 600, 500);
this.setBackground(Color.cyan);
this.setVisible(true);
jlabel1 = new Label("请输入时间t:");
if(Integer.parseInt(timeslice) == 1) {
new Painting(200, 380, 25, 20, Color.gray, "ED1", true).draw(g);
}
if(Integer.parseInt(timeslice) == 2) {
new Painting(200, 380, 25, 20, Color.gray, "ED1", true).draw(g);
jb_input.addActionListener(new RunActionListener());
jta1.addKeyListener(new TextAreaThread());
g = this.getGraphics();
new Thread(new PaintThread()).start();
jta1.append("---------------------Deno the pipline for float point add.---------------------\n");
相关主题