From c067cbf6ad220e06de0cec352a193bc474f9540f Mon Sep 17 00:00:00 2001
From: fche
Date: Mon, 22 Oct 2001 19:48:44 +0000
Subject: [PATCH] * function ++, cleanup
2001-10-22 Frank Ch. Eigler
* cache.cxx (flush_all): New function. Associate with "flush-all" pin.
* cacheutil.cxx (find_any_dirty): New functions.
* cache.h, cacheutil.h: Relevant changes.
Warning cleanups throughout.
* hw-cache.xml (flush-all): Document new pin.
* hw-cache-txt: Regenerated.
---
sid/component/cache/ChangeLog | 9 ++++++++
sid/component/cache/cache.cxx | 43 ++++++++++++++++++++++++++-------------
sid/component/cache/cache.h | 5 ++++-
sid/component/cache/cacheutil.cxx | 27 +++++++++++++++++++++++-
sid/component/cache/cacheutil.h | 18 ++++++++++++----
sid/component/cache/hw-cache.txt | 6 +++++-
sid/component/cache/hw-cache.xml | 4 +++-
sid/component/cache/log2.h | 8 ++++----
8 files changed, 94 insertions(+), 26 deletions(-)
diff --git a/sid/component/cache/ChangeLog b/sid/component/cache/ChangeLog
index 1cc083cf13..39bd039947 100644
--- a/sid/component/cache/ChangeLog
+++ b/sid/component/cache/ChangeLog
@@ -1,3 +1,12 @@
+2001-10-22 Frank Ch. Eigler
+
+ * cache.cxx (flush_all): New function. Associate with "flush-all" pin.
+ * cacheutil.cxx (find_any_dirty): New functions.
+ * cache.h, cacheutil.h: Relevant changes.
+ Warning cleanups throughout.
+ * hw-cache.xml (flush-all): Document new pin.
+ * hw-cache-txt: Regenerated.
+
2001-09-27 Frank Ch. Eigler
* cache.cxx (emit_report): Remove extra blank line.
diff --git a/sid/component/cache/cache.cxx b/sid/component/cache/cache.cxx
index 2785ff5d8e..fdc45b7b15 100644
--- a/sid/component/cache/cache.cxx
+++ b/sid/component/cache/cache.cxx
@@ -48,7 +48,11 @@ cache_component::cache_component (unsigned assocy,
unsigned cache_sz,
unsigned line_sz,
cache_replacement_algorithm& replacer)
- :report_pin (this, &cache_component::emit_report),
+ :acache (cache_sz, line_sz, assocy, replacer),
+ upstream (*this),
+ downstream (0),
+ report_pin (this, &cache_component::emit_report),
+ flush_all_pin (this, &cache_component::flush_all_lines),
flush_pin (this, &cache_component::flush_line),
invalidate_all_pin (this, &cache_component::invalidate_all_lines),
invalidate_pin (this, &cache_component::invalidate_line),
@@ -57,14 +61,13 @@ cache_component::cache_component (unsigned assocy,
unlock_pin (this, &cache_component::unlock_line),
write_allocate_p (false),
write_through_p (false),
- downstream (0),
- upstream (*this),
collect_p (true),
+ report_heading ("cache profile report"),
line_size (line_sz),
cache_size (cache_sz),
assoc (assocy),
- report_heading ("cache profile report"),
- acache (cache_sz, line_sz, assocy, replacer)
+ hit_latency (0),
+ miss_latency (0)
{
memset (&stats, 0, sizeof (stats));
@@ -72,6 +75,7 @@ cache_component::cache_component (unsigned assocy,
add_accessor ("downstream", &downstream);
add_pin ("report!", &report_pin);
+ add_pin ("flush-all", &flush_all_pin);
add_pin ("flush", &flush_pin);
add_pin ("invalidate-all", &invalidate_all_pin);
add_pin ("invalidate", &invalidate_pin);
@@ -347,12 +351,23 @@ cache_component::write_line (cache_line& line)
}
void
+cache_component::flush_all_lines (host_int_4)
+{
+ while (true)
+ {
+ cache_line* line = acache.find_any_dirty ();
+ if (line == 0) break;
+ (void) write_line (*line);
+ }
+}
+
+void
cache_component::flush_line (host_int_4 addr)
{
bool hit;
cache_line& line = acache.find (acache.addr_to_tag (addr), hit);
if (hit && line.dirty_p ())
- bus::status st = write_line (line);
+ (void) write_line (line);
}
void
@@ -374,7 +389,7 @@ void
cache_component::prefetch_line (host_int_4 addr)
{
sid::big_int_1 dummy;
- bus::status st = read_any (addr, dummy);
+ (void) read_any (addr, dummy);
}
void
@@ -535,11 +550,11 @@ cache_replacement_fifo::replace (cache_set& cset, cache_line& old_line, cache_li
void
cache_replacement_lru::replace (cache_set& cset, cache_line& old_line, cache_line new_line)
{
- int oldest;
+ unsigned oldest = 0;
int index = -1;
lru.resize (cset.num_lines ());
- for (unsigned i = 0, oldest = 0; i < cset.num_lines (); i++)
+ for (unsigned i = 0; i < cset.num_lines (); i++)
{
cache_line& line = cset.get_line (i);
if (!line.valid_p ())
@@ -640,9 +655,9 @@ CacheListTypes ()
types.push_back ("hw-cache-basic");
- for (int i = 0; i < (sizeof (assocs) / sizeof (string)); i++)
- for (int j = 0; j < (sizeof (cache_sizes) / sizeof (string)); j++)
- for (int k = 0; k < (sizeof (line_sizes) / sizeof (string)); k++)
+ for (unsigned i = 0; i < (sizeof (assocs) / sizeof (string)); i++)
+ for (unsigned j = 0; j < (sizeof (cache_sizes) / sizeof (string)); j++)
+ for (unsigned k = 0; k < (sizeof (line_sizes) / sizeof (string)); k++)
{
if (assocs[i] == "direct")
{
@@ -652,7 +667,7 @@ CacheListTypes ()
types.push_back (type);
}
else
- for (int m = 0;
+ for (unsigned m = 0;
m < (sizeof (replacement_algorithms) / sizeof (string)); m++)
{
type = string ("hw-cache-");
@@ -669,7 +684,7 @@ CacheListTypes ()
static component*
CacheCreate (const string& typeName)
{
- int i;
+ unsigned i;
bool match;
if (typeName == "hw-cache-basic")
diff --git a/sid/component/cache/cache.h b/sid/component/cache/cache.h
index f14f9924be..efbf3164ff 100644
--- a/sid/component/cache/cache.h
+++ b/sid/component/cache/cache.h
@@ -77,7 +77,7 @@ public:
void update (cache_set& cset, cache_line& selected);
private:
- vector lru;
+ vector lru;
};
// Random replacement algorithm
@@ -125,6 +125,9 @@ private:
callback_pin report_pin;
void emit_report (host_int_4 ignore);
+ callback_pin flush_all_pin;
+ void flush_all_lines (host_int_4 ignore);
+
callback_pin flush_pin;
void flush_line (host_int_4 addr);
diff --git a/sid/component/cache/cacheutil.cxx b/sid/component/cache/cacheutil.cxx
index ec6a1fbf7b..0d17c4a563 100644
--- a/sid/component/cache/cacheutil.cxx
+++ b/sid/component/cache/cacheutil.cxx
@@ -209,6 +209,19 @@ cache_set::find (const cache_tag& tag, bool& hit)
return dummy;
}
+
+cache_line*
+cache_set::find_any_dirty ()
+{
+ for (iterator_t it = lines.begin (); it != lines.end (); it++)
+ {
+ cache_line* i = * it;
+ if (i->dirty_p ()) return i;
+ }
+
+ return 0;
+}
+
void
cache_set::invalidate ()
{
@@ -306,7 +319,19 @@ cache::find (cache_tag tag, bool& hit)
return sets[index]->find (tag, hit);
}
-int
+cache_line*
+cache::find_any_dirty ()
+{
+ for (unsigned i = 0; i < this->num_sets(); i++)
+ {
+ cache_line* foo = sets[i]->find_any_dirty ();
+ if (foo) return foo;
+ }
+ return 0;
+}
+
+
+unsigned
cache::num_sets ()
{
return sets.size ();
diff --git a/sid/component/cache/cacheutil.h b/sid/component/cache/cacheutil.h
index 759019337a..575fa9f206 100644
--- a/sid/component/cache/cacheutil.h
+++ b/sid/component/cache/cacheutil.h
@@ -32,7 +32,7 @@ public:
cache_line (unsigned line_size, cache_tag tag, std::vector intial_data);
cache_line (const cache_line&);
cache_line& operator= (const cache_line&);
- ~cache_line ();
+ virtual ~cache_line ();
// Get the line's tag.
cache_tag tag () const;
@@ -100,6 +100,8 @@ class cache_set;
class cache_replacement_algorithm
{
public:
+ virtual ~cache_replacement_algorithm () {}
+
// Place new_line in a cache slot. Point old_line to the existing line.
// Return true if successful, false otherwise.
virtual void replace (cache_set& cset, cache_line& old_line, cache_line new_line) = 0;
@@ -117,13 +119,17 @@ class cache_set
public:
cache_set (unsigned line_size, unsigned nlines,
cache_replacement_algorithm& alg);
- ~cache_set ();
+ virtual ~cache_set ();
// Try to find a line in the cache with a matching tag.
// If found, set "hit" to true and return a ref to the line.
// Otherwise, set "hit" to false.
virtual cache_line& find (const cache_tag& tag, bool& hit);
+ // Find any dirty cache line. If found, set hit to true and return it.
+ // Otherwise, set hit to false.
+ virtual cache_line* find_any_dirty ();
+
// Invalidate the entire set.
void invalidate ();
@@ -171,7 +177,7 @@ class cache
public:
cache (unsigned cache_size, unsigned line_size,
unsigned assoc, cache_replacement_algorithm& replacer);
- ~cache ();
+ virtual ~cache ();
// Calculate a tag.
cache_tag addr_to_tag (const sid::host_int_4& addr) const;
@@ -183,6 +189,10 @@ public:
// Otherwise, set hit to false.
cache_line& find (cache_tag tag, bool& hit);
+ // Find any dirty cache line. If found, set hit to true and return it.
+ // Otherwise, set hit to false.
+ cache_line* find_any_dirty ();
+
// Remove a line from the cache.
void expunge (cache_line& line);
@@ -198,7 +208,7 @@ public:
void invalidate ();
// The number of sets in the cache.
- int num_sets ();
+ unsigned num_sets ();
// Dump the entire cache's state.
void dump () const;
diff --git a/sid/component/cache/hw-cache.txt b/sid/component/cache/hw-cache.txt
index 2537b0ef8a..c54dd00827 100644
--- a/sid/component/cache/hw-cache.txt
+++ b/sid/component/cache/hw-cache.txt
@@ -116,7 +116,9 @@ Functionality:
| | on a line that is present and |
| | dirty, it will be flushed to |
| | memory and marked as not |
- | | dirty. |
+ | | dirty. The entire cache can |
+ | | be flushed by driving |
+ | | flush-all. |
|-----------------+-------------------------------|
| invalidating | Lines in the cache that |
| | contain accurate contents are |
@@ -234,6 +236,8 @@ Component Reference:
|flush |in |32-bit |flushing |
| | |address | |
|--------------+---------+-----------+------------|
+ |flush-all |in |any |flushing |
+ |--------------+---------+-----------+------------|
|invalidate |in |32-bit |invalidating|
| | |address | |
|--------------+---------+-----------+------------|
diff --git a/sid/component/cache/hw-cache.xml b/sid/component/cache/hw-cache.xml
index b6fc76ff88..d4c5fa6ac7 100644
--- a/sid/component/cache/hw-cache.xml
+++ b/sid/component/cache/hw-cache.xml
@@ -13,6 +13,7 @@
+
@@ -146,7 +147,8 @@
a line to memory. For this purpose, the component provides
flush which can be driven with an address. If the
address falls on a line that is present and dirty, it will be
- flushed to memory and marked as not dirty.
+ flushed to memory and marked as not dirty. The entire cache
+ can be flushed by driving flush-all.
diff --git a/sid/component/cache/log2.h b/sid/component/cache/log2.h
index 74c7a994df..1b485e74ac 100644
--- a/sid/component/cache/log2.h
+++ b/sid/component/cache/log2.h
@@ -12,10 +12,10 @@
template
bool power_of_two_p (const V& v1)
{
- int count = 0;
+ unsigned count = 0;
V v2(1);
- for (int i = 0; i < 8 * sizeof (V); i++)
+ for (unsigned i = 0; i < 8 * sizeof (V); i++)
if (v1 & (v2 << i))
count++;
@@ -26,12 +26,12 @@ bool power_of_two_p (const V& v1)
// Compute log2 (V).
template
-int log2 (const V& v1)
+unsigned log2 (const V& v1)
{
assert (power_of_two_p (v1));
V v2(1);
- for (int i = 0; i < 8 * sizeof (V); i++)
+ for (unsigned i = 0; i < 8 * sizeof (V); i++)
if (v1 & (v2 << i))
return i;
}
--
2.11.0