blob: b4881f846a5ca922d21b8a6a9ede4ba8c78f8b0f [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2019 Dortmund University of Applied Sciences and Arts.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors: Junhyung Ki - initial API and implementation
*
*******************************************************************************/
package org.eclipse.app4mc.gsoc_rta.ui;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.stream.Collectors;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.eclipse.app4mc.amalthea.model.Amalthea;
import org.eclipse.app4mc.amalthea.model.AmaltheaServices;
import org.eclipse.app4mc.amalthea.model.EventChain;
import org.eclipse.app4mc.amalthea.model.Label;
import org.eclipse.app4mc.amalthea.model.ProcessingUnit;
import org.eclipse.app4mc.amalthea.model.PuType;
import org.eclipse.app4mc.amalthea.model.Task;
import org.eclipse.app4mc.amalthea.model.Time;
import org.eclipse.app4mc.amalthea.model.TimeUnit;
import org.eclipse.app4mc.amalthea.model.io.AmaltheaLoader;
import org.eclipse.app4mc.amalthea.model.util.FactoryUtil;
import org.eclipse.app4mc.amalthea.model.util.RuntimeUtil.TimeType;
import org.eclipse.app4mc.gsoc_rta.*;
import org.eclipse.app4mc.gsoc_rta.SharedConsts.ComParadigm;
import org.eclipse.emf.common.util.EList;
import javax.swing.SwingConstants;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
* Date: August 21-2019
* @author Junhyung Ki
* @version 1.0
* The purpose of this class is to provide users a better visual and increase usability of Response Time Analysis.
*/
@SuppressWarnings("serial")
public class APP4RTA extends JFrame {
private static JComboBox<String> ecComboBox = new JComboBox<String>();
private CPURta cpurta = new CPURta();
private E2ELatency e2e = new E2ELatency();
private Amalthea currentModel = null;
private java.util.List<ProcessingUnit> currentPUList = null;
private int[] currentIA = null;
private EList<Task> allTaskList = null;
private EList<EventChain> currentECList = null;
private EventChain currentEC = null;
private java.util.List<Task> currentTaskChain = null;
private File currentFile = null;
private HashMap<Integer, java.util.List<Task>> puTaskListHM;
private JFrame frame;
private int selectedECIndex = -1;
private boolean schedulability_flag = false;
private ComParadigm currentParadigm = null;
JFileChooser fileChooser;
JTextField selectedModelLbl;
private JLabel jl0, jl1, jl2, jl3, jl4, jl5, jl6, jl7, jl8, jl9, jl10,
jl11, jl12, jl13, jl14, jl15, jl16, jl17, jl18, jl19;
private JTextField tf0, tf1, tf2, tf3, tf4, tf5, tf6, tf7, tf8, tf9,
tf10, tf11, tf12, tf13, tf14, tf15, tf16, tf17, tf18, tf19;
private JLabel[] jLabelArray = {
jl0, jl1, jl2, jl3, jl4, jl5, jl6, jl7, jl8, jl9, jl10,
jl11, jl12, jl13, jl14, jl15, jl16, jl17, jl18, jl19
};
private JTextField[] jTextFieldArray= {
tf0, tf1, tf2, tf3, tf4, tf5, tf6, tf7, tf8, tf9,
tf10, tf11, tf12, tf13, tf14, tf15, tf16, tf17, tf18, tf19
};
private JLabel jl_0, jl_1, jl_2, jl_3, jl_4, jl_5, jl_6, jl_7;
private JLabel jl_a, jl_b, jl_c, jl_d, jl_e, jl_f, jl_g, jl_h;
private List l0, l1, l2, l3, l4, l5, l6, l7;
private List rtL0, rtL1, rtL2, rtL3, rtL4, rtL5, rtL6, rtL7;
private JLabel[] puLabelArray = {
jl_0, jl_1, jl_2, jl_3, jl_4, jl_5, jl_6, jl_7
};
private JLabel[] rtListLabelArray = {
jl_a, jl_b, jl_c, jl_d, jl_e, jl_f, jl_g, jl_h
};
private List[] puListArray = {
l0, l1, l2, l3, l4, l5, l6, l7
};
private List[] rtListArray = {
rtL0, rtL1, rtL2, rtL3, rtL4, rtL5, rtL6, rtL7
};
private JLabel ecL0, ecL1, ecL2, ecL3, ecL4, ecL5, ecL6,
ecL7, ecL8, ecL9, ecL10, ecL11, ecL12, ecL13;
private JTextField jtf0, jtf1, jtf2, jtf3, jtf4, jtf5, jtf6,
jtf7, jtf8, jtf9, jtf10, jtf11, jtf12, jtf13;
private JLabel[] ecLabelArray = {
ecL0, ecL1, ecL2, ecL3, ecL4, ecL5, ecL6,
ecL7, ecL8, ecL9, ecL10, ecL11, ecL12, ecL13
};
private JTextField[] ecJTPArray = {
jtf0, jtf1, jtf2, jtf3, jtf4, jtf5, jtf6,
jtf7, jtf8, jtf9, jtf10, jtf11, jtf12, jtf13
};
private List list, list_1, list_2;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
org.apache.log4j.BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.ERROR);
final APP4RTA window = new APP4RTA();
window.frame.setVisible(true);
window.frame.setTitle("APP4RTA");
}
});
}
public APP4RTA() {
initialize();
}
private void initialize() {
frame = new JFrame();
frame.getContentPane().setFont(new Font("Sitka Small", Font.PLAIN, 13));
frame.setBounds(0, 31, 1200, 1027);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JLabel lblSelectTheModel = new JLabel("Amalthea Model");
lblSelectTheModel.setFont(new Font("Stencil BT", Font.PLAIN, 13));
lblSelectTheModel.setBounds(10, 13, 120, 22);
frame.getContentPane().add(lblSelectTheModel);
JLabel lblTaskName = new JLabel("Task Name");
lblTaskName.setForeground(new Color(139, 0, 0));
lblTaskName.setFont(new Font("Sitka Heading", Font.BOLD, 12));
lblTaskName.setHorizontalAlignment(SwingConstants.CENTER);
lblTaskName.setBounds(15, 43, 70, 16);
frame.getContentPane().add(lblTaskName);
JLabel lblPuNum = new JLabel("PU Num");
lblPuNum.setForeground(new Color(0, 0, 255));
lblPuNum.setHorizontalAlignment(SwingConstants.CENTER);
lblPuNum.setFont(new Font("Sitka Heading", Font.BOLD, 12));
lblPuNum.setBounds(92, 43, 70, 16);
frame.getContentPane().add(lblPuNum);
JButton btnDefualtIa = new JButton("Defualt IA");
btnDefualtIa.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (cpurta.getModel() == null) {
JOptionPane.showMessageDialog(frame, "ERROR: A model is not loaded.");
return ;
} else if (cpurta.getTRT() == null) {
JOptionPane.showMessageDialog(frame, "ERROR: TRT HashMap is not loaded.");
return ;
} else if (cpurta.getPUl().size() == 0) {
JOptionPane.showMessageDialog(frame, "ERROR: Processing Unit List is not loaded.");
return ;
}
final int[] defaultIA = SharedConsts.defaultIAMapping;
if (cpurta.getModel().getSwModel().getTasks().size() == defaultIA.length) {
for (int i = 0; i < defaultIA.length; i++) {
jTextFieldArray[i].setText("" + defaultIA[i]);
}
return ;
}
JOptionPane.showMessageDialog(frame, "ERROR: The length of the default integer array does not match with\n"
+ "the number of tasks in the target model.");
}
});
JButton btnEnterIA = new JButton("Enter IA");
btnEnterIA.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
currentIA = new int[cpurta.getModel().getSwModel().getTasks().size()];
for (int i = 0; i < allTaskList.size(); i++) {
if (jTextFieldArray[i].getText().length() == 0) {
JOptionPane.showMessageDialog(frame, "ERROR: Fill the rest of the array!");
return ;
} else if (jTextFieldArray[i].getText().charAt(0) < 48 || jTextFieldArray[i].getText().charAt(0) > 54) {
JOptionPane.showMessageDialog(frame, "ERROR: Wrong array value!");
return ;
} else if (i >= 0 && i <= 9 && Integer.parseInt(jTextFieldArray[i].getText()) == 6) {
JOptionPane.showMessageDialog(frame, "ERROR: CPU Tasks should not be mapped to GPU! \n\n"
+ "Please assign different IA value for " + "(" + allTaskList.get(i).getName() + ")");
return ;
} else if (i == jTextFieldArray.length-1 && Integer.parseInt(jTextFieldArray[i].getText()) != 6) {
JOptionPane.showMessageDialog(frame, "ERROR: 'Detection' task can not be mapped to CPU!");
return ;
}
currentIA[i] = Integer.parseInt(jTextFieldArray[i].getText());
}
cpurta.setIA(currentIA);
cpurta.setContention(currentIA, currentModel);
puTaskListHM = cpurta.be_getPUTaskListHashMap(currentModel);
for (int i = 0; i < puTaskListHM.size(); i++) {
if (puListArray[i].getItemCount() == 0) {
for (int j = 0; j < puTaskListHM.get(i).size(); j++) {
puListArray[i].add((puTaskListHM.get(i).get(j)).getName());
}
}
}
}
});
JRadioButton rdbtnSynchronous = new JRadioButton("Synchronous");
rdbtnSynchronous.setForeground(new Color(139, 0, 0));
rdbtnSynchronous.setFont(new Font("Sitka Heading", Font.BOLD, 13));
JRadioButton rdbtnAsynchronous = new JRadioButton("Asynchronous");
rdbtnAsynchronous.setForeground(new Color(0, 0, 255));
rdbtnAsynchronous.setFont(new Font("Sitka Heading", Font.BOLD, 13));
ButtonGroup offloadingMode = new ButtonGroup();
offloadingMode.add(rdbtnSynchronous);
offloadingMode.add(rdbtnAsynchronous);
JRadioButton rdbtnWorstCase = new JRadioButton("Worst-Case");
rdbtnWorstCase.setFont(new Font("Sitka Heading", Font.BOLD, 13));
rdbtnWorstCase.setForeground(Color.DARK_GRAY);
JRadioButton rdbtnAverageCase = new JRadioButton("Average-Case");
rdbtnAverageCase.setFont(new Font("Sitka Heading", Font.BOLD, 13));
rdbtnAverageCase.setForeground(Color.DARK_GRAY);
JRadioButton rdbtnBestCase = new JRadioButton("Best-Case");
rdbtnBestCase.setFont(new Font("Sitka Heading", Font.BOLD, 13));
rdbtnBestCase.setForeground(Color.DARK_GRAY);
ButtonGroup executionMode = new ButtonGroup();
executionMode.add(rdbtnWorstCase);
executionMode.add(rdbtnAverageCase);
executionMode.add(rdbtnBestCase);
JLabel lblSchedulability = new JLabel("Schedulability");
JTextField schedulability = new JTextField();
schedulability.setHorizontalAlignment(SwingConstants.RIGHT);
schedulability.setEditable(false);
JLabel lblMemAccCost = new JLabel("Cumulated Memory-Access Cost");
JTextField memAccCost = new JTextField();
memAccCost.setHorizontalAlignment(SwingConstants.RIGHT);
memAccCost.setEditable(false);
JLabel lblCumulContention = new JLabel("Cumulated Contention");
JTextField cumulContention = new JTextField();
cumulContention.setHorizontalAlignment(SwingConstants.RIGHT);
cumulContention.setEditable(false);
JLabel lblComputation = new JLabel("Computation");
JTextField computation = new JTextField();
computation.setHorizontalAlignment(SwingConstants.RIGHT);
computation.setEditable(false);
JLabel lblResponseTimeSum = new JLabel("Response Time Sum");
JTextField rtSum = new JTextField();
rtSum.setHorizontalAlignment(SwingConstants.RIGHT);
rtSum.setEditable(false);
JButton btnCalculate = new JButton("Calculate");
btnCalculate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
for (int i = 0; i < allTaskList.size(); i++) {
if (jTextFieldArray[i].getText().length() == 0) {
JOptionPane.showMessageDialog(frame, "ERROR: Fill the array first!");
return ;
}
}
if (rdbtnSynchronous.isSelected()) {
SharedConsts.synchronousOffloading = true;
} else if (rdbtnAsynchronous.isSelected()) {
SharedConsts.synchronousOffloading = false;
} else {
JOptionPane.showMessageDialog(frame, "ERROR: You should choose an offloading mode! (Sync / Async)");
return ;
}
if (rdbtnWorstCase.isSelected()) {
SharedConsts.timeType = TimeType.WCET;
} else if (rdbtnAverageCase.isSelected()) {
SharedConsts.timeType = TimeType.ACET;
} else if (rdbtnBestCase.isSelected()) {
SharedConsts.timeType = TimeType.BCET;
} else {
JOptionPane.showMessageDialog(frame, "ERROR: You should choose an execution case! (Worst Case / Average Case / Best Case)");
return ;
}
if (currentIA == null || puTaskListHM.size() == 0) {
JOptionPane.showMessageDialog(frame, "ERROR: Click the 'Enter IA' button.");
return ;
}
schedulability_flag = true;
Time pRtSum = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
for (int i = 0; i < puTaskListHM.size(); i++) {
final ProcessingUnit pu = cpurta.getPUl().get(i);
final java.util.List<Task> thisPUTaskList = puTaskListHM.get(i);
Time thisRT = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
if (rtListArray[i].getItemCount() == 0) {
if (pu.getDefinition().getPuType().equals(PuType.CPU)) {
for (Task t : thisPUTaskList) {
thisRT = cpurta.preciseTestCPURT(t, thisPUTaskList, SharedConsts.timeType, pu);
final Time thisPeriod = CommonUtils.getStimInTime(t);
final BigInteger period = AmaltheaServices.convertToPicoSeconds(thisPeriod);
if (AmaltheaServices.convertToPicoSeconds(thisRT).compareTo(period) > 0) {
rtListArray[i].add("Non Scheduleable! => MAX Value");
schedulability_flag = false;
} else if (AmaltheaServices.convertToPicoSeconds(thisRT).equals(BigInteger.ZERO)) {
rtListArray[i].add("0 ps (GPU Task on CPU)");
} else {
rtListArray[i].add(thisRT.toString());
}
pRtSum = pRtSum.add(thisRT);
}
} else {
for (Task t : thisPUTaskList) {
thisRT = cpurta.getTRT().get(t);
rtListArray[i].add(thisRT.toString());
pRtSum = pRtSum.add(thisRT);
}
}
}
}
if (schedulability_flag) {
schedulability.setText("Scheduleable! :)");
memAccCost.setText("" + cpurta.getCumulatedMemAccCosts());
cumulContention.setText("" + cpurta.getCumulatedContention());
computation.setText("" + (pRtSum.subtract(cpurta.getCumulatedMemAccCosts())).subtract(cpurta.getCumulatedContention()));
rtSum.setText(pRtSum.toString());
} else {
schedulability.setText("Non Scheduleable! :(");
memAccCost.setText("Not Available.");
cumulContention.setText("Not Available.");
computation.setText("Not Available.");
rtSum.setText("Not Available.");
}
}
});
JButton btnReset = new JButton("Reset");
btnReset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
currentIA = null;
cpurta.setIA(currentIA);
cpurta.setContention(currentIA, currentModel);
/* latency time initializing */
cpurta.initCumulatedMemAccCosts();
cpurta.initCumulatedContention();
for (int i = 0; i < allTaskList.size(); i++) {
jTextFieldArray[i].setText("");
}
for (int i = 0; i < currentPUList.size(); i++) {
puListArray[i].removeAll();
}
for (int i = 0; i < currentPUList.size(); i++) {
rtListArray[i].removeAll();
}
offloadingMode.setSelected(null, false);
executionMode.setSelected(null, false);
schedulability.setText(null);
memAccCost.setText(null);
cumulContention.setText(null);
computation.setText(null);
rtSum.setText(null);
currentIA = null;
puTaskListHM = null;
frame.revalidate();
frame.repaint();
}
});
selectedModelLbl = new JTextField();
selectedModelLbl.setEditable(false);
selectedModelLbl.setBounds(142, 13, 206, 22);
frame.getContentPane().add(selectedModelLbl);
selectedModelLbl.setColumns(10);
JButton amaltheaSchBtn = new JButton("Search Amalthea");
amaltheaSchBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final String userDirLocation = System.getProperty("user.dir");
File userDir = new File(userDirLocation);
fileChooser = new JFileChooser(userDir);
fileChooser.setAcceptAllFileFilterUsed(false);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Amalthea models", "amxmi");
fileChooser.addChoosableFileFilter(filter);
fileChooser.setDialogTitle("Open File");
int result = fileChooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
final Amalthea loadedModel = AmaltheaLoader.loadFromFile(fileChooser.getSelectedFile());
if (loadedModel.getVersion().compareTo("0.9.4") != 0) {
JOptionPane.showMessageDialog(frame, "Error: This model should be migrated to the version 0.9.4");
return ;
}
/* Something was selected before */
if (currentFile != null) {
/* The selected file is equal to the previous file => Do nothing */
if (fileChooser.getSelectedFile().equals(currentFile)) {
JOptionPane.showMessageDialog(frame, "Same Model");
return ;
}
/* If the selected file is different to the previous one => Remove and Do Normal. */
else {
schedulability.setText(null);
memAccCost.setText(null);
cumulContention.setText(null);
computation.setText(null);
rtSum.setText(null);
for (int i = 0; i < allTaskList.size(); i++) {
frame.remove(jLabelArray[i]);
frame.remove(jTextFieldArray[i]);
}
frame.remove(btnDefualtIa);
frame.remove(btnEnterIA);
frame.remove(rdbtnSynchronous);
frame.remove(rdbtnAsynchronous);
frame.remove(rdbtnWorstCase);
frame.remove(rdbtnAverageCase);
frame.remove(rdbtnBestCase);
frame.remove(btnCalculate);
frame.remove(btnReset);
frame.remove(lblSchedulability);
frame.remove(schedulability);
frame.remove(lblMemAccCost);
frame.remove(memAccCost);
frame.remove(lblCumulContention);
frame.remove(cumulContention);
frame.remove(lblComputation);
frame.remove(computation);
frame.remove(lblResponseTimeSum);
frame.remove(rtSum);
for (int i = 0; i < currentPUList.size(); i++) {
frame.remove(puLabelArray[i]);
frame.remove(rtListLabelArray[i]);
frame.remove(puListArray[i]);
frame.remove(rtListArray[i]);
}
frame.remove(ecComboBox);
}
}
/* Something was not selected before => Do normal */
currentFile = fileChooser.getSelectedFile();
selectedModelLbl.setText(currentFile.getName());
currentModel = loadedModel;
currentPUList = CommonUtils.getPUs(currentModel);
cpurta.setModel(currentModel);
cpurta.setTRT(cpurta.getDefaultTRT(currentModel));
cpurta.setPUl(currentPUList);
allTaskList = currentModel.getSwModel().getTasks();
if (allTaskList.size() > 20) {
JOptionPane.showMessageDialog(frame, "ERROR: The selected model has " + allTaskList.size() + " Tasks. (Limit: 20)\n"
+ "Please choose a different model.");
return ;
} else if (currentPUList.size() > 8) {
JOptionPane.showMessageDialog(frame, "ERROR: The selected model has " + currentPUList.size() + " Processing Units. (Limit: 8)\n"
+ "Please choose a different model.");
return ;
}
/* Task Indices */
for (int i = 0; i < allTaskList.size(); i++) {
jLabelArray[i] = new JLabel(allTaskList.get(i).getName());
jLabelArray[i].setBounds(12, (60+(i*24)), 97, 16);
frame.getContentPane().add(jLabelArray[i]);
jTextFieldArray[i] = new JTextField();
jTextFieldArray[i].setColumns(10);
jTextFieldArray[i].setBounds(118, (60+(i*24)), 22, 22);
frame.getContentPane().add(jTextFieldArray[i]);
}
/* DefaultIA Button */
btnDefualtIa.setBounds(155, 60, 97, 25);
frame.getContentPane().add(btnDefualtIa);
/* EnterIA Button */
btnEnterIA.setBounds(155, 90, 97, 25);
frame.getContentPane().add(btnEnterIA);
/* Sync Radio Button */
rdbtnSynchronous.setBounds(152, 125, 126, 25);
frame.getContentPane().add(rdbtnSynchronous);
/* Async Radio Button */
rdbtnAsynchronous.setBounds(152, 145, 126, 25);
frame.getContentPane().add(rdbtnAsynchronous);
/* WorstCase Radio Button */
rdbtnWorstCase.setBounds(152, 175, 107, 25);
frame.getContentPane().add(rdbtnWorstCase);
/* AverageCase Radio Button */
rdbtnAverageCase.setBounds(152, 195, 107, 25);
frame.getContentPane().add(rdbtnAverageCase);
/* BestCase Radio Button */
rdbtnBestCase.setBounds(152, 215, 107, 25);
frame.getContentPane().add(rdbtnBestCase);
/* Calculate Button */
btnCalculate.setBounds(155, 252, 97, 25);
frame.getContentPane().add(btnCalculate);
/* Reset Button */
btnReset.setBounds(155, 282, 97, 25);
frame.getContentPane().add(btnReset);
/* Schedulability Label & TextField */
lblSchedulability.setBounds(157, 323, 200, 16);
frame.getContentPane().add(lblSchedulability);
schedulability.setBounds(155, 343, 200, 22);
frame.getContentPane().add(schedulability);
/* MemAccCost Label & TextField */
lblMemAccCost.setBounds(157, 368, 200, 16);
frame.getContentPane().add(lblMemAccCost);
memAccCost.setBounds(155, 388, 200, 22);
frame.getContentPane().add(memAccCost);
/* CumulContention Label & TextField */
lblCumulContention.setBounds(157, 413, 200, 16);
frame.getContentPane().add(lblCumulContention);
cumulContention.setBounds(155, 433, 200, 22);
frame.getContentPane().add(cumulContention);
/* Computation */
lblComputation.setBounds(157, 458, 200, 16);
frame.getContentPane().add(lblComputation);
computation.setBounds(155, 478, 200, 22);
frame.getContentPane().add(computation);
/* ResponseTime Sum Label & TextField */
lblResponseTimeSum.setBounds(157, 503, 200, 16);
frame.getContentPane().add(lblResponseTimeSum);
rtSum.setBounds(155, 523, 200, 22);
frame.getContentPane().add(rtSum);
/* PU & RT Lists */
for (int i = 0; i < currentPUList.size(); i++) {
puLabelArray[i] = new JLabel(i +": " + currentPUList.get(i).getDefinition().getName());
rtListLabelArray[i] = new JLabel("Response Time");
puListArray[i] = new List();
rtListArray[i] = new List();
if (i >= 0 && i < 4) {
puLabelArray[i].setBounds((387+(i*200)), 50, 87, 22);
rtListLabelArray[i].setBounds((474+(i*200)), 50, 88, 22);
puListArray[i].setBounds((385+(i*200)), 75, 87, 145);
rtListArray[i].setBounds((475+(i*200)), 75, 87, 145);
} else if (i >= 4) {
puLabelArray[i].setBounds((387+((i-4)*200)), 225, 87, 22);
rtListLabelArray[i].setBounds((474+((i-4)*200)), 225, 88, 22);
puListArray[i].setBounds((385+((i-4)*200)), 250, 87, 145);
rtListArray[i].setBounds((475+((i-4)*200)), 250, 87, 145);
}
frame.getContentPane().add(puLabelArray[i]);
frame.getContentPane().add(rtListLabelArray[i]);
frame.getContentPane().add(puListArray[i]);
frame.getContentPane().add(rtListArray[i]);
}
/* E2ELatency Part */
currentECList = currentModel.getConstraintsModel().getEventChains();
if (currentECList.size() != 0) {
final String[] ecComboArray = new String[currentECList.size()];
for (int i = 0; i < currentECList.size(); i++) {
ecComboArray[i] = currentECList.get(i).getName();
}
ecComboBox = new JComboBox<String>(ecComboArray);
ecComboBox.setBounds(150, 570, 206, 22);
frame.getContentPane().add(ecComboBox);
ecComboBox.setSelectedItem(null);
} else {
JOptionPane.showMessageDialog(frame, "WARNING: The selected model has no Event-Chain.\n"
+ "End to End EventChain Latency Calculation is impossible with this model.");
// TODO: Something needs to be done here to prevent E2ELatency calculation.
}
frame.revalidate();
frame.repaint();
}
}
});
amaltheaSchBtn.setBounds(348, 12, 133, 24);
frame.getContentPane().add(amaltheaSchBtn);
JLabel lblEventChainModel = new JLabel("EVENT CHAIN MODEL");
lblEventChainModel.setFont(new Font("Stencil BT", Font.PLAIN, 13));
lblEventChainModel.setBounds(10, 570, 136, 22);
frame.getContentPane().add(lblEventChainModel);
JRadioButton rdbtnDirect = new JRadioButton("Direct");
rdbtnDirect.setForeground(new Color(139, 0, 0));
rdbtnDirect.setFont(new Font("Sitka Heading", Font.BOLD, 13));
rdbtnDirect.setBounds(530, 569, 70, 25);
frame.getContentPane().add(rdbtnDirect);
JRadioButton rdbtnImplicit = new JRadioButton("Implicit");
rdbtnImplicit.setForeground(new Color(0, 0, 255));
rdbtnImplicit.setFont(new Font("Sitka Heading", Font.BOLD, 13));
rdbtnImplicit.setBounds(596, 569, 79, 25);
frame.getContentPane().add(rdbtnImplicit);
ButtonGroup paradigmMode = new ButtonGroup();
paradigmMode.add(rdbtnDirect);
paradigmMode.add(rdbtnImplicit);
JLabel lblNewLabel = new JLabel("Direct & Implicit Communication Paradigm");
lblNewLabel.setFont(new Font("Sitka Text", Font.BOLD | Font.ITALIC, 13));
lblNewLabel.setBounds(10, 605, 293, 16);
frame.getContentPane().add(lblNewLabel);
JLabel lblWorstcaseReaction = new JLabel("WC Reaction");
lblWorstcaseReaction.setHorizontalAlignment(SwingConstants.CENTER);
lblWorstcaseReaction.setFont(new Font("Sitka Small", Font.PLAIN, 13));
lblWorstcaseReaction.setBounds(10, 627, 90, 16);
frame.getContentPane().add(lblWorstcaseReaction);
JTextField txtField0 = new JTextField();
txtField0.setHorizontalAlignment(SwingConstants.RIGHT);
txtField0.setBounds(103, 625, 200, 22);
txtField0.setEditable(false);
frame.getContentPane().add(txtField0);
JLabel lblBestcaseReaction = new JLabel("BC Reaction");
lblBestcaseReaction.setFont(new Font("Sitka Small", Font.PLAIN, 13));
lblBestcaseReaction.setHorizontalAlignment(SwingConstants.CENTER);
lblBestcaseReaction.setBounds(10, 656, 90, 16);
frame.getContentPane().add(lblBestcaseReaction);
JTextField txtField1 = new JTextField();
txtField1.setHorizontalAlignment(SwingConstants.RIGHT);
txtField1.setBounds(103, 654, 200, 22);
txtField1.setEditable(false);
frame.getContentPane().add(txtField1);
JLabel lblLetCommunicationParadigm = new JLabel("LET Communication Paradigm");
lblLetCommunicationParadigm.setFont(new Font("Sitka Text", Font.BOLD | Font.ITALIC, 13));
lblLetCommunicationParadigm.setBounds(10, 688, 193, 16);
frame.getContentPane().add(lblLetCommunicationParadigm);
JLabel lblWcReaction = new JLabel("WC Reaction");
lblWcReaction.setHorizontalAlignment(SwingConstants.CENTER);
lblWcReaction.setFont(new Font("Sitka Small", Font.PLAIN, 13));
lblWcReaction.setBounds(10, 710, 90, 16);
frame.getContentPane().add(lblWcReaction);
JTextField txtField2 = new JTextField();
txtField2.setHorizontalAlignment(SwingConstants.RIGHT);
txtField2.setBounds(103, 708, 200, 22);
txtField2.setEditable(false);
frame.getContentPane().add(txtField2);
JLabel lblBcReaction = new JLabel("BC Reaction");
lblBcReaction.setFont(new Font("Sitka Small", Font.PLAIN, 13));
lblBcReaction.setHorizontalAlignment(SwingConstants.CENTER);
lblBcReaction.setBounds(10, 739, 90, 16);
frame.getContentPane().add(lblBcReaction);
JTextField txtField3 = new JTextField();
txtField3.setHorizontalAlignment(SwingConstants.RIGHT);
txtField3.setBounds(103, 737, 200, 22);
txtField3.setEditable(false);
frame.getContentPane().add(txtField3);
JLabel lblTaskChain = new JLabel("Task Chain Age (Direct & Implicit)");
lblTaskChain.setFont(new Font("Sitka Text", Font.BOLD | Font.ITALIC, 13));
lblTaskChain.setBounds(338, 605, 222, 16);
frame.getContentPane().add(lblTaskChain);
JLabel lblWcAge = new JLabel("WC Age");
lblWcAge.setHorizontalAlignment(SwingConstants.CENTER);
lblWcAge.setFont(new Font("Sitka Small", Font.PLAIN, 13));
lblWcAge.setBounds(350, 627, 58, 16);
frame.getContentPane().add(lblWcAge);
JTextField txtField4 = new JTextField();
txtField4.setHorizontalAlignment(SwingConstants.RIGHT);
txtField4.setBounds(413, 625, 200, 22);
txtField4.setEditable(false);
frame.getContentPane().add(txtField4);
JLabel lblBcAge = new JLabel("BC Age");
lblBcAge.setHorizontalAlignment(SwingConstants.CENTER);
lblBcAge.setFont(new Font("Sitka Small", Font.PLAIN, 13));
lblBcAge.setBounds(350, 656, 58, 16);
frame.getContentPane().add(lblBcAge);
JTextField txtField5 = new JTextField();
txtField5.setHorizontalAlignment(SwingConstants.RIGHT);
txtField5.setBounds(413, 654, 200, 22);
txtField5.setEditable(false);
frame.getContentPane().add(txtField5);
JLabel lblEarlyReaction = new JLabel("Early Reaction (Direct & Implicit)");
lblEarlyReaction.setFont(new Font("Sitka Text", Font.BOLD | Font.ITALIC, 13));
lblEarlyReaction.setBounds(338, 688, 232, 16);
frame.getContentPane().add(lblEarlyReaction);
JLabel lblWcErct = new JLabel("WC E-Rct");
lblWcErct.setHorizontalAlignment(SwingConstants.CENTER);
lblWcErct.setFont(new Font("Sitka Small", Font.PLAIN, 13));
lblWcErct.setBounds(338, 710, 70, 16);
frame.getContentPane().add(lblWcErct);
JTextField txtField6 = new JTextField();
txtField6.setHorizontalAlignment(SwingConstants.RIGHT);
txtField6.setBounds(413, 708, 200, 22);
txtField6.setEditable(false);
frame.getContentPane().add(txtField6);
JLabel lblBcErct = new JLabel("BC E-Rct");
lblBcErct.setHorizontalAlignment(SwingConstants.CENTER);
lblBcErct.setFont(new Font("Sitka Small", Font.PLAIN, 13));
lblBcErct.setBounds(338, 739, 70, 16);
frame.getContentPane().add(lblBcErct);
JTextField txtField7 = new JTextField();
txtField7.setHorizontalAlignment(SwingConstants.RIGHT);
txtField7.setBounds(413, 737, 200, 22);
txtField7.setEditable(false);
frame.getContentPane().add(txtField7);
JLabel lblDataAge = new JLabel("Data Age");
lblDataAge.setFont(new Font("Sitka Text", Font.BOLD | Font.ITALIC, 13));
lblDataAge.setBounds(10, 771, 58, 16);
frame.getContentPane().add(lblDataAge);
JLabel lblContainedLabels = new JLabel("Contained Labels");
lblContainedLabels.setFont(new Font("Sitka Small", Font.PLAIN, 13));
lblContainedLabels.setBounds(10, 791, 136, 16);
frame.getContentPane().add(lblContainedLabels);
list = new List();
list.setBounds(10, 810, 155, 160);
frame.getContentPane().add(list);
JLabel lblWorstcaseAge = new JLabel("Worst-case Age");
lblWorstcaseAge.setFont(new Font("Sitka Small", Font.PLAIN, 13));
lblWorstcaseAge.setBounds(177, 791, 136, 16);
frame.getContentPane().add(lblWorstcaseAge);
list_1 = new List();
list_1.setBounds(177, 810, 155, 160);
frame.getContentPane().add(list_1);
JLabel lblBestcaseAge = new JLabel("Best-case Age");
lblBestcaseAge.setFont(new Font("Sitka Small", Font.PLAIN, 13));
lblBestcaseAge.setBounds(344, 791, 136, 16);
frame.getContentPane().add(lblBestcaseAge);
list_2 = new List();
list_2.setBounds(344, 810, 155, 160);
frame.getContentPane().add(list_2);
JButton ecSelect = new JButton("Calculate");
ecSelect.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (currentModel == null) {
JOptionPane.showMessageDialog(frame, "ERROR: Select an AMALTHEA model first.");
return ;
} else if (currentECList == null) {
JOptionPane.showMessageDialog(frame, "ERROR: Event-Chain List is empty somehow.");
return ;
} else if (ecComboBox.getSelectedItem() == null) {
JOptionPane.showMessageDialog(frame, "ERROR: Select an Event-Chain.");
return ;
} else if (puTaskListHM == null) {
JOptionPane.showMessageDialog(frame, "ERROR: IA(Integer Array) has not been assigned.");
return ;
} else if (offloadingMode.getSelection() == null) {
JOptionPane.showMessageDialog(frame, "ERROR: Choose an offloading mode. (Sync / Async)");
return ;
} else if (schedulability_flag == false) {
String offMode = null;
if (SharedConsts.synchronousOffloading == true) {
offMode = "Sync";
} else if (SharedConsts.synchronousOffloading == false) {
offMode = "Aync";
}
String tType = null;
if (SharedConsts.timeType.equals(TimeType.WCET)) {
tType = "WC";
} else if (SharedConsts.timeType.equals(TimeType.ACET)) {
tType = "AC";
} else if (SharedConsts.timeType.equals(TimeType.BCET)) {
tType = "BC";
}
String iaFeedback = "";
for (int i = 0; i < currentIA.length; i++) {
if (i == currentIA.length - 1) {
iaFeedback = iaFeedback + currentIA[i];
} else {
iaFeedback = iaFeedback + currentIA[i] + ", ";
}
}
JOptionPane.showMessageDialog(frame, "ERROR: The entered IA value is not schedulable with the current configuration.\n\n"
+ "Current Integer Arrary: { " + iaFeedback + " }\n\n"
+ "Current Configuration: Offloading Mode(" + offMode + "), ExecutionCase(" + tType + ")");
return ;
} else if (paradigmMode.getSelection() == null) {
JOptionPane.showMessageDialog(frame, "ERROR: Choose a communication paradigm. (Direct / Implicit)");
return ;
}
final int thisIndex = ecComboBox.getSelectedIndex();
/* Something was selected before */
if (selectedECIndex != -1) {
/* If the selected Event-Chain is the same as before => Do Nothing */
if (selectedECIndex == thisIndex) {
if (currentParadigm != null) {
ComParadigm changedParadigm = null;
if (rdbtnDirect.isSelected()) {
changedParadigm = ComParadigm.DIRECT;
} else if (rdbtnImplicit.isSelected()) {
changedParadigm = ComParadigm.IMPLICIT;
}
if (currentParadigm.equals(changedParadigm)) {
JOptionPane.showMessageDialog(frame, "Same Paradigm & Same Event-Chain.");
return ;
}
for (int i = 0; i < currentTaskChain.size(); i++) {
frame.remove(ecLabelArray[i]);
frame.remove(ecJTPArray[i]);
}
}
}
/* If the selected Event-Chain is different to the previous one => Remove and Do Normal. */
else if (selectedECIndex != thisIndex) {
for (int i = 0; i < currentTaskChain.size(); i++) {
frame.remove(ecLabelArray[i]);
frame.remove(ecJTPArray[i]);
}
selectedECIndex = thisIndex;
}
}
selectedECIndex = thisIndex;
currentEC = currentECList.get(thisIndex);
currentTaskChain = e2e.getECTaskList(currentEC);
if (currentTaskChain.size() == 0 ) {
JOptionPane.showMessageDialog(frame, "ERROR: The selected Event-Chain has no chain-element.");
txtField0.setText("Not Available.");
txtField1.setText("Not Available.");
txtField2.setText("Not Available.");
txtField3.setText("Not Available.");
txtField4.setText("Not Available.");
txtField5.setText("Not Available.");
txtField6.setText("Not Available.");
txtField7.setText("Not Available.");
list.removeAll();
list.add("Not Available.");
list_1.removeAll();
list_1.add("Not Available.");
list_2.removeAll();
list_2.add("Not Available.");
return ;
}
else if (currentTaskChain.size() > 14) {
JOptionPane.showMessageDialog(frame, "ERROR: The selected Event-Chain has more than " + currentTaskChain.size() + " elements. (Limit: 14)\n");
txtField0.setText("Not Available.");
txtField1.setText("Not Available.");
txtField2.setText("Not Available.");
txtField3.setText("Not Available.");
txtField4.setText("Not Available.");
txtField5.setText("Not Available.");
txtField6.setText("Not Available.");
txtField7.setText("Not Available.");
list.removeAll();
list.add("Not Available.");
list_1.removeAll();
list_1.add("Not Available.");
list_2.removeAll();
list_2.add("Not Available.");
return ;
}
for (int i = 0; i < currentTaskChain.size(); i++) {
final Task task = currentTaskChain.get(i);
for (int j = 0; j < puTaskListHM.size(); j++) {
java.util.List<Task> puTaskList = puTaskListHM.get(j);
if (puTaskList.stream().filter(s -> s.equals(task)).collect(Collectors.toList()).size() != 0) {
final ProcessingUnit pu = currentPUList.get(j);
ecLabelArray[i] = new JLabel((i+1) + ": " + pu.getName() + " (" + pu.getDefinition().getName() + ")");
ecJTPArray[i] = new JTextField();
ecJTPArray[i].setText(task.getName());
ecJTPArray[i].setEditable(false);
if (i < 7) {
ecLabelArray[i].setBounds(750, (604+(50*i)), 187, 16);
ecJTPArray[i].setBounds(750, (624+(50*i)), 187, 22);
} else {
ecLabelArray[i].setBounds(950, (604+(50*(i-7))), 187, 16);
ecJTPArray[i].setBounds(950, (624+(50*(i-7))), 187, 22);
}
frame.getContentPane().add(ecLabelArray[i]);
frame.getContentPane().add(ecJTPArray[i]);
break;
}
}
}
/* Calculation Part */
if (currentModel == null) {
JOptionPane.showMessageDialog(frame, "ERROR: Select an AMALTHEA model first.");
return ;
} else if (ecComboBox.getSelectedItem() == null) {
JOptionPane.showMessageDialog(frame, "ERROR: Select an Event-Chain.");
return ;
} else if (currentIA == null) {
JOptionPane.showMessageDialog(frame, "ERROR: IA(Integer Array) has not been entered.");
return ;
}
if (list.getItemCount() > 0) {
list.removeAll();
list_1.removeAll();
list_2.removeAll();
}
/* Sometimes the same task can not be schedulable in the implicit communication due to the LocalCopy cost time */
Time rctWC = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
Time rctBC = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
Time ageWC = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
Time ageBC = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
Time eRctWC = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
Time eRctBC = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
/* PARADIGM */
if (rdbtnDirect.isSelected()) {
currentParadigm = ComParadigm.DIRECT;
rctWC = e2e.getTCReactionWC(currentEC, currentParadigm, cpurta);
rctBC = e2e.getTCReactionBC(currentEC, currentParadigm, cpurta);
ageWC = e2e.getTaskChainAge(currentEC, TimeType.WCET, currentParadigm, cpurta);
ageBC = e2e.getTaskChainAge(currentEC, TimeType.BCET, currentParadigm, cpurta);
eRctWC = e2e.getEarlyReaction(currentEC, TimeType.WCET, currentParadigm, cpurta);
eRctBC = e2e.getEarlyReaction(currentEC, TimeType.BCET, currentParadigm, cpurta);
} else if (rdbtnImplicit.isSelected()) {
currentParadigm = ComParadigm.IMPLICIT;
rctWC = e2e.getTCReactionWC(currentEC, currentParadigm, cpurta);
rctBC = e2e.getTCReactionBC(currentEC, currentParadigm, cpurta);
ageWC = e2e.getTaskChainAge(currentEC, TimeType.WCET, currentParadigm, cpurta);
ageBC = e2e.getTaskChainAge(currentEC, TimeType.BCET, currentParadigm, cpurta);
eRctWC = e2e.getEarlyReaction(currentEC, TimeType.WCET, currentParadigm, cpurta);
eRctBC = e2e.getEarlyReaction(currentEC, TimeType.BCET, currentParadigm, cpurta);
}
if (rctWC.getValue().equals(BigInteger.ZERO)) {
txtField0.setText("Not Schedulable (LocalCopy Cost)");
} else {
txtField0.setText("" + rctWC);
}
if (rctBC.getValue().equals(BigInteger.ZERO)) {
txtField1.setText("Not Schedulable (LocalCopy Cost)");
} else {
txtField1.setText("" + rctBC);
}
txtField2.setText("" + e2e.getLetReactionWC(currentEC, cpurta));
txtField3.setText("" + e2e.getLetReactionBC(currentEC, cpurta));
txtField4.setText("" + ageWC);
txtField5.setText("" + ageBC);
if (eRctWC.getValue().equals(BigInteger.ZERO)) {
txtField6.setText("Not Schedulable (LocalCopy Cost)");
} else {
txtField6.setText("" + eRctWC);
}
if (eRctBC.getValue().equals(BigInteger.ZERO)) {
txtField7.setText("Not Schedulable (LocalCopy Cost)");
} else {
txtField7.setText("" + eRctBC);
}
final EList<Label> labelList = currentModel.getSwModel().getLabels();
for (int i = 0; i < labelList.size(); i++) {
Time datAgeLatWC = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
Time datAgeLatBC = FactoryUtil.createTime(BigInteger.ZERO, TimeUnit.PS);
datAgeLatWC = e2e.getDataAge(labelList.get(i), currentEC, TimeType.WCET, currentParadigm, cpurta);
datAgeLatBC = e2e.getDataAge(labelList.get(i), currentEC, TimeType.BCET, currentParadigm, cpurta);
if (datAgeLatWC != null && datAgeLatBC != null) {
list.add(labelList.get(i).getName());
list_1.add(datAgeLatWC + "");
list_2.add(datAgeLatBC + "");
}
}
frame.revalidate();
frame.repaint();
}
});
ecSelect.setBounds(356, 569, 90, 25);
frame.getContentPane().add(ecSelect);
JButton btnNewButton_1 = new JButton("Reset");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < currentTaskChain.size(); i++) {
ecLabelArray[i].setText(null);
frame.remove(ecLabelArray[i]);
ecJTPArray[i].setText(null);
frame.remove(ecJTPArray[i]);
}
selectedECIndex = -1;
currentParadigm = null;
txtField0.setText("");
txtField1.setText("");
txtField2.setText("");
txtField3.setText("");
txtField4.setText("");
txtField5.setText("");
txtField6.setText("");
txtField7.setText("");
paradigmMode.setSelected(null, false);
list.removeAll();
list_1.removeAll();
list_2.removeAll();
frame.revalidate();
frame.repaint();
}
});
btnNewButton_1.setBounds(445, 569, 70, 25);
frame.getContentPane().add(btnNewButton_1);
JLabel lblTaskChain_1 = new JLabel("Task Chain >");
lblTaskChain_1.setFont(new Font("Segoe UI Emoji", Font.BOLD, 13));
lblTaskChain_1.setBounds(646, 605, 90, 16);
frame.getContentPane().add(lblTaskChain_1);
JLabel lblApprta = new JLabel("APP4RTA");
lblApprta.setForeground(Color.DARK_GRAY);
lblApprta.setFont(new Font("Snap ITC", Font.ITALIC, 20));
lblApprta.setBounds(1050, 1, 120, 34);
frame.getContentPane().add(lblApprta);
}
}