From: Yao Qi <yao@codesourcery.com>
To: Doug Evans <dje@google.com>
Cc: gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 05/10] Invalidate or shrink dcache when setting is changed.
Date: Mon, 18 Nov 2013 14:31:00 -0000 [thread overview]
Message-ID: <528A1F67.1090400@codesourcery.com> (raw)
In-Reply-To: <CADPb22R2Di9SVVPeftvXrYjrt+sCkemTeoyJj3r=2Nm-QWRoHA@mail.gmail.com>
On 11/18/2013 04:34 AM, Doug Evans wrote:
> It feels simpler if this were:
>
> if (target_dcache_init_p ())
> dcache_check_resize (target_dcache);
> return target_dcache;
>
> There may be a better name than dcache_check_resize, one may want to
> call it for situations other than resizings, but here target-dcache.c
> is using 3 API routines from dcache.c to achieve what is essentially
> one operation: check if the cache needs to be reconfigured and update
> if so.
How about "dcache_update_config"?
>
>> >@@ -54,7 +62,14 @@ target_dcache_get (void)
>> > DCACHE *
>> > target_dcache_get_or_init (void)
>> > {
>> >- if (!target_dcache_init_p ())
>> >+ if (target_dcache_init_p ())
>> >+ {
>> >+ if (dcache_invalidate_p (target_dcache))
>> >+ dcache_invalidate (target_dcache);
>> >+
>> >+ dcache_shrink (target_dcache);
>> >+ }
>> >+ else
>> > target_dcache = dcache_init ();
>> >
>> > return target_dcache;
> I think it would be better to remove the duplication and have:
>
> if (target_dcache_init_p ())
> return target_dcache_get ();
Fixed.
--
Yao (é½å°§)
gdb:
2013-11-18 Yao Qi <yao@codesourcery.com>
* dcache.c (dcache_evict): New function.
(dcache_shrink): New function.
(dcache_update_config): New function.
(dcache_alloc): Call dcache_evict.
(set_dcache_size): Remove call target_dcache_invalidate.
(set_dcache_line_size): Likewise.
* dcache.h (dcache_update_config): Declare.
* target-dcache.c (target_dcache_get): Invalidate and shrink
cache if necessary.
(target_dcache_get_or_init): Likewise.
gdb/doc:
2013-11-18 Yao Qi <yao@codesourcery.com>
* gdb.texinfo (Caching Target Data): Update document of
commands 'set dcache size' and 'set dcache line-size'.
---
gdb/dcache.c | 53 ++++++++++++++++++++++++++++++++++++++++++--------
gdb/dcache.h | 2 +
gdb/doc/gdb.texinfo | 7 ++++-
gdb/target-dcache.c | 7 +++++-
4 files changed, 57 insertions(+), 12 deletions(-)
diff --git a/gdb/dcache.c b/gdb/dcache.c
index 5b32629..4474be4 100644
--- a/gdb/dcache.c
+++ b/gdb/dcache.c
@@ -243,6 +243,49 @@ invalidate_block (struct dcache_block *block, void *param)
append_block (&dcache->freelist, block);
}
+/* Evict the cache line decided by the eviction algorithm. Return the
+ evicted cache line. */
+
+static struct dcache_block *
+dcache_evict (DCACHE *dcache)
+{
+ /* Evict the least recently allocated line. */
+ struct dcache_block *db = dcache->oldest;
+
+ remove_block (&dcache->oldest, db);
+ splay_tree_remove (dcache->tree, (splay_tree_key) db->addr);
+
+ return db;
+}
+
+/* Shrink DCACHE if it is over-sized. */
+
+static void
+dcache_shrink (DCACHE *dcache)
+{
+ while (dcache->size > dcache_size)
+ {
+ struct dcache_block *db = dcache_evict (dcache);
+
+ free_block (db, NULL);
+ dcache->size--;
+ }
+}
+
+/* Update the configuration, such as line-size, of DCACHE if
+ necessary. */
+
+void
+dcache_update_config (DCACHE *dcache)
+{
+ /* DCACHE must be invalidated if its line-size is different from the
+ global setting. */
+ if (dcache->line_size != dcache_line_size)
+ dcache_invalidate (dcache);
+
+ dcache_shrink (dcache);
+}
+
/* Free all the data cache blocks, thus discarding all cached data. */
void
@@ -359,13 +402,7 @@ dcache_alloc (DCACHE *dcache, CORE_ADDR addr)
struct dcache_block *db;
if (dcache->size >= dcache_size)
- {
- /* Evict the least recently allocated line. */
- db = dcache->oldest;
- remove_block (&dcache->oldest, db);
-
- splay_tree_remove (dcache->tree, (splay_tree_key) db->addr);
- }
+ db = dcache_evict (dcache);
else
{
db = dcache->freelist;
@@ -669,7 +706,6 @@ set_dcache_size (char *args, int from_tty,
dcache_size = DCACHE_DEFAULT_SIZE;
error (_("Dcache size must be greater than 0."));
}
- target_dcache_invalidate ();
}
static void
@@ -683,7 +719,6 @@ set_dcache_line_size (char *args, int from_tty,
dcache_line_size = DCACHE_DEFAULT_LINE_SIZE;
error (_("Invalid dcache line size: %u (must be power of 2)."), d);
}
- target_dcache_invalidate ();
}
static void
diff --git a/gdb/dcache.h b/gdb/dcache.h
index 720a887..d2fcd6a 100644
--- a/gdb/dcache.h
+++ b/gdb/dcache.h
@@ -40,4 +40,6 @@ int dcache_xfer_memory (struct target_ops *ops, DCACHE *cache, CORE_ADDR mem,
void dcache_update (DCACHE *dcache, CORE_ADDR memaddr, gdb_byte *myaddr,
int len);
+void dcache_update_config (DCACHE *dcache);
+
#endif /* DCACHE_H */
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 8377ca8..16ae0c8 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -10878,13 +10878,16 @@ printed in hex.
@item set dcache size @var{size}
@cindex dcache size
@kindex set dcache size
-Set maximum number of entries in dcache (dcache depth above).
+Set maximum number of entries in dcache (dcache depth above). When
+the dcache is being used, if its size is greater than this setting, it
+is shrunk.
@item set dcache line-size @var{line-size}
@cindex dcache line-size
@kindex set dcache line-size
Set number of bytes each dcache entry caches (dcache width above).
-Must be a power of 2.
+Must be a power of 2. When the dcache is being used, if its width is
+different from this setting, it is invalidated.
@item show dcache size
@kindex show dcache size
diff --git a/gdb/target-dcache.c b/gdb/target-dcache.c
index bf04679..6bd576d 100644
--- a/gdb/target-dcache.c
+++ b/gdb/target-dcache.c
@@ -45,6 +45,9 @@ target_dcache_invalidate (void)
DCACHE *
target_dcache_get (void)
{
+ if (target_dcache_init_p ())
+ dcache_update_config (target_dcache);
+
return target_dcache;
}
@@ -54,7 +57,9 @@ target_dcache_get (void)
DCACHE *
target_dcache_get_or_init (void)
{
- if (!target_dcache_init_p ())
+ if (target_dcache_init_p ())
+ return target_dcache_get ();
+ else
target_dcache = dcache_init ();
return target_dcache;
--
1.7.7.6
next prev parent reply other threads:[~2013-11-18 14:12 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-03 5:57 [PATCH 00/10 V2] Cache code access for disassemble Yao Qi
2013-11-03 5:56 ` [PATCH 08/10] Don't invalidate dcache when option stack-cache is changed Yao Qi
2013-11-17 22:02 ` Doug Evans
2013-11-18 14:12 ` Yao Qi
2013-11-18 15:51 ` Pedro Alves
2013-11-19 6:43 ` Yao Qi
2013-11-19 12:14 ` Pedro Alves
2013-11-19 14:06 ` Yao Qi
2013-11-03 5:56 ` [PATCH 09/10] set/show code-cache Yao Qi
2013-11-03 16:58 ` Eli Zaretskii
2013-11-18 8:23 ` Doug Evans
2013-11-03 5:56 ` [PATCH 03/10] Move target-dcache out of target.c Yao Qi
2013-11-17 20:15 ` Doug Evans
2013-11-18 15:53 ` Pedro Alves
2013-11-03 5:56 ` [PATCH 01/10] Remove last_cache Yao Qi
2013-11-17 19:52 ` Doug Evans
2013-11-03 5:56 ` [PATCH 07/10] Associate target_dcache to address_space Yao Qi
2013-11-03 16:48 ` Eli Zaretskii
2013-11-17 21:22 ` Doug Evans
2013-11-20 7:54 ` Yao Qi
2013-11-20 13:23 ` Yao Qi
2013-11-03 5:56 ` [PATCH 02/10] Don't update target_dcache if it is not initialized Yao Qi
2013-11-17 20:09 ` Doug Evans
2013-11-03 5:56 ` [PATCH 05/10] Invalidate or shrink dcache when setting is changed Yao Qi
2013-11-03 16:50 ` Eli Zaretskii
2013-11-17 20:55 ` Doug Evans
2013-11-18 14:31 ` Yao Qi [this message]
2013-11-18 15:59 ` Pedro Alves
2013-11-19 6:16 ` Yao Qi
2013-11-19 11:52 ` Pedro Alves
2013-11-19 13:12 ` Yao Qi
2013-11-03 5:57 ` [PATCH 06/10] Add REGISTRY for struct address_space Yao Qi
2013-11-17 21:09 ` Doug Evans
2013-11-20 4:46 ` Yao Qi
2013-11-03 5:57 ` [PATCH 04/10] Don't stress 'remote' in "Data Caching" in doc Yao Qi
2013-11-03 16:55 ` Eli Zaretskii
2013-11-06 7:56 ` Yao Qi
2013-11-06 10:28 ` Eli Zaretskii
2013-11-17 20:34 ` Doug Evans
2013-11-17 21:44 ` Eli Zaretskii
2013-11-20 2:41 ` Doug Evans
2013-11-20 4:01 ` Eli Zaretskii
2013-11-22 1:17 ` Doug Evans
2013-11-20 3:58 ` Yao Qi
2013-11-11 9:38 ` [PATCH 00/10 V2] Cache code access for disassemble Yao Qi
2013-11-17 17:03 ` Yao Qi
2013-11-18 8:39 ` [PATCH 10/10] Use target_read_code in disassemble Yao Qi
2013-11-18 17:12 ` Doug Evans
2013-11-20 4:46 ` [PATCH 00/10 V2] Cache code access for disassemble Yao Qi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=528A1F67.1090400@codesourcery.com \
--to=yao@codesourcery.com \
--cc=dje@google.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox