From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2693 invoked by alias); 18 Nov 2013 14:12:06 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 2671 invoked by uid 89); 18 Nov 2013 14:12:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=3.1 required=5.0 tests=AWL,BAYES_50,GARBLED_BODY,RDNS_NONE,URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from Unknown (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 18 Nov 2013 14:10:33 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1ViPWq-0001En-QK from Yao_Qi@mentor.com ; Mon, 18 Nov 2013 06:10:16 -0800 Received: from SVR-ORW-FEM-04.mgc.mentorg.com ([147.34.97.41]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Mon, 18 Nov 2013 06:10:16 -0800 Received: from qiyao.dyndns.org (147.34.91.1) by svr-orw-fem-04.mgc.mentorg.com (147.34.97.41) with Microsoft SMTP Server id 14.2.247.3; Mon, 18 Nov 2013 06:10:14 -0800 Message-ID: <528A1F67.1090400@codesourcery.com> Date: Mon, 18 Nov 2013 14:31:00 -0000 From: Yao Qi User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Doug Evans CC: gdb-patches Subject: Re: [PATCH 05/10] Invalidate or shrink dcache when setting is changed. References: <1383458049-20893-1-git-send-email-yao@codesourcery.com> <1383458049-20893-6-git-send-email-yao@codesourcery.com> In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2013-11/txt/msg00465.txt.bz2 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 * 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 * 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