aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2018-04-15 10:41:26 +0200
committerKarel Kočí <cynerd@email.cz>2018-04-15 10:41:26 +0200
commit25e85c6eed3c9457568de2d64ebfb32b1edfa0d0 (patch)
treed834962254d1a513bffea6edaa63ec6bbf698ee5
parent69aaf6837c9a1da2fea8961159d574023f0c7a6d (diff)
downloadqtmips-25e85c6eed3c9457568de2d64ebfb32b1edfa0d0.tar.gz
qtmips-25e85c6eed3c9457568de2d64ebfb32b1edfa0d0.tar.bz2
qtmips-25e85c6eed3c9457568de2d64ebfb32b1edfa0d0.zip
Show cache statistics in Memory block in coreview
-rw-r--r--qtmips_gui/coreview/memory.cpp30
-rw-r--r--qtmips_gui/coreview/memory.h7
-rw-r--r--qtmips_machine/cache.cpp5
-rw-r--r--qtmips_machine/cache.h4
4 files changed, 39 insertions, 7 deletions
diff --git a/qtmips_gui/coreview/memory.cpp b/qtmips_gui/coreview/memory.cpp
index f4ba058..41e7ee9 100644
--- a/qtmips_gui/coreview/memory.cpp
+++ b/qtmips_gui/coreview/memory.cpp
@@ -6,20 +6,30 @@ using namespace coreview;
//////////////////////
#define WIDTH 60
#define HEIGHT 80
-#define CACHE_HEIGHT 50
+#define CACHE_HEIGHT 47
#define PENW 1
//////////////////////
-Memory::Memory(machine::QtMipsMachine *machine) : QGraphicsObject(nullptr), name("Memory", this), type(this) {
+Memory::Memory(const machine::Cache *cch) : QGraphicsObject(nullptr), name("Memory", this), type(this), cache_t("Cache", this), cache_hit_t("Hit: 0", this), cache_miss_t("Miss: 0", this) {
cache = false;
QFont font;
font.setPointSize(7);
name.setFont(font);
type.setFont(font);
+ cache_t.setFont(font);
+ cache_hit_t.setFont(font);
+ cache_miss_t.setFont(font);
- const QRectF &name_box = name.boundingRect();
- name.setPos(WIDTH/2 - name_box.width()/2, HEIGHT - (HEIGHT - CACHE_HEIGHT)/2);
+ name.setPos(WIDTH/2 - name.boundingRect().width()/2, HEIGHT - (HEIGHT - CACHE_HEIGHT)/2);
+ const QRectF &cache_t_b = cache_t.boundingRect();
+ cache_t.setPos(WIDTH/2 - cache_t_b.width()/2, 1);
+ const QRectF &cache_hit_b = cache_hit_t.boundingRect();
+ cache_hit_t.setPos(WIDTH/2 - cache_hit_b.width()/2, cache_t_b.height() + 2);
+ cache_miss_t.setPos(WIDTH/2 - cache_miss_t.boundingRect().width()/2, cache_t_b.height() + cache_hit_b.height() + 3);
+
+ connect(cch, SIGNAL(hit_update(uint)), this, SLOT(cache_hit_update(uint)));
+ connect(cch, SIGNAL(miss_update(uint)), this, SLOT(cache_miss_update(uint)));
setPos(x(), y()); // set connector's position
}
@@ -34,6 +44,14 @@ void Memory::paint(QPainter *painter, const QStyleOptionGraphicsItem *option __a
painter->drawLine(0, CACHE_HEIGHT, WIDTH, CACHE_HEIGHT);
}
+void Memory::cache_hit_update(unsigned val) {
+ cache_hit_t.setText("Hit: " + QString::number(val));
+}
+
+void Memory::cache_miss_update(unsigned val) {
+ cache_miss_t.setText("Miss: " + QString::number(val));
+}
+
void Memory::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
QGraphicsObject::mouseDoubleClickEvent(event);
@@ -49,7 +67,7 @@ void Memory::set_type(const QString &text) {
type.setPos(WIDTH/2 - box.width()/2, HEIGHT - (HEIGHT - CACHE_HEIGHT)/2 - box.height());
}
-ProgramMemory::ProgramMemory(machine::QtMipsMachine *machine) : Memory(machine) {
+ProgramMemory::ProgramMemory(machine::QtMipsMachine *machine) : Memory(machine->cache_program()) {
cache = machine->config().cache_program().enabled();
set_type("Program");
@@ -77,7 +95,7 @@ const Connector *ProgramMemory::connector_instruction() const {
return con_inst;
}
-DataMemory::DataMemory(machine::QtMipsMachine *machine) : Memory(machine) {
+DataMemory::DataMemory(machine::QtMipsMachine *machine) : Memory(machine->cache_data()) {
cache = machine->config().cache_data().enabled();
set_type("Data");
diff --git a/qtmips_gui/coreview/memory.h b/qtmips_gui/coreview/memory.h
index 177dc6d..57158a6 100644
--- a/qtmips_gui/coreview/memory.h
+++ b/qtmips_gui/coreview/memory.h
@@ -13,7 +13,7 @@ namespace coreview {
class Memory : public QGraphicsObject {
Q_OBJECT
public:
- Memory(machine::QtMipsMachine *machine);
+ Memory(const machine::Cache *cache);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
@@ -22,6 +22,10 @@ signals:
void open_mem();
void open_cache();
+private slots:
+ void cache_hit_update(unsigned);
+ void cache_miss_update(unsigned);
+
protected:
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
@@ -31,6 +35,7 @@ protected:
private:
QGraphicsSimpleTextItem name, type;
+ QGraphicsSimpleTextItem cache_t, cache_hit_t, cache_miss_t;
};
class ProgramMemory : public Memory {
diff --git a/qtmips_machine/cache.cpp b/qtmips_machine/cache.cpp
index d699cd6..d8c1fff 100644
--- a/qtmips_machine/cache.cpp
+++ b/qtmips_machine/cache.cpp
@@ -93,6 +93,9 @@ void Cache::reset() {
// Zero hit and miss rate
hitc = 0;
missc = 0;
+ // Trigger signals
+ emit hit_update(hitc);
+ emit miss_update(missc);
}
const MachineConfigCache &Cache::config() const {
@@ -153,8 +156,10 @@ void Cache::access(std::uint32_t address, std::uint32_t **data, bool read) const
// Update statistics and otherwise read from memory
if (cd.valid) {
hitc++;
+ emit hit_update(hitc);
} else {
missc++;
+ emit miss_update(missc);
for (unsigned i = 0; i < cnf.blocks(); i++)
cd.data[i] = mem->rword(base_address(tag, row) + (4*i));
}
diff --git a/qtmips_machine/cache.h b/qtmips_machine/cache.h
index 1882c6c..8321bbf 100644
--- a/qtmips_machine/cache.h
+++ b/qtmips_machine/cache.h
@@ -27,6 +27,10 @@ public:
const MachineConfigCache &config() const;
// TODO getters for cells
+signals:
+ void hit_update(unsigned) const;
+ void miss_update(unsigned) const;
+
private:
MachineConfigCache cnf;
Memory *mem;