set/show code-cache
authorYao Qi <yao@codesourcery.com>
Fri, 1 Nov 2013 04:26:10 +0000 (12:26 +0800)
committerYao Qi <yao@codesourcery.com>
Sun, 24 Nov 2013 06:56:49 +0000 (14:56 +0800)
Similar to stack cache, in this patch, we add
TARGET_OBJECT_CODE_MEMORY to read code from target and add a new
option "set code-cache on|off" to optimize code accesses by
using the target memory cache.

In V4:
 - Remove "without affecting correctness" from NEWS and doc.
 - Replace "ON" with "on" in doc.
 - "access" -> "accesses".

In V3:
 - Rename functions and variables.
 - Update command help, doc and NEWS entry.
 - Invalidate cache on option transitions, to align with
   the behaviour of "stack-cache".  Since cache invalidation is
   transparent to users, users don't know option "stack-cache"
   transitions cause code cache invalidation.

V2 was reviewed by Doug.  There are some changes in V3, so I post it
here.

gdb:

2013-11-24  Yao Qi  <yao@codesourcery.com>

* NEWS: Add note on new "set code-cache" option.
* target-dcache.c (code_cache_enabled_1): New variable.
(code_cache_enabled): New variable.
(show_code_cache, set_code_cache): New function.
(code_cache_enabled_p): New function.
(_initialize_target_dcache): Register command.
* target-dcache.h (code_cache_enabled_p): Declare.
* target.c (memory_xfer_partial_1):Handle
TARGET_OBJECT_CODE_MEMORY and code_cache_enabled.
(target_read_code): New function.
* target.h (enum target_object) <TARGET_OBJECT_CODE_MEMORY>:
New.
(target_read_code): Declare.

gdb/doc:

2013-11-24  Yao Qi  <yao@codesourcery.com>

* gdb.texinfo (Caching Remote Data): Document new
"set/show stack-cache" option.

gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/target-dcache.c
gdb/target-dcache.h
gdb/target.c
gdb/target.h

index 869c8606f79ae64bdab3f71b410f7574e231579c..b91eb51f9b0e3d0e04b6afa5ce103040648a10e7 100644 (file)
@@ -1,3 +1,19 @@
+2013-11-24  Yao Qi  <yao@codesourcery.com>
+
+       * NEWS: Add note on new "set code-cache" option.
+       * target-dcache.c (code_cache_enabled_1): New variable.
+       (code_cache_enabled): New variable.
+       (show_code_cache, set_code_cache): New function.
+       (code_cache_enabled_p): New function.
+       (_initialize_target_dcache): Register command.
+       * target-dcache.h (code_cache_enabled_p): Declare.
+       * target.c (memory_xfer_partial_1):Handle
+       TARGET_OBJECT_CODE_MEMORY and code_cache_enabled.
+       (target_read_code): New function.
+       * target.h (enum target_object) <TARGET_OBJECT_CODE_MEMORY>:
+       New.
+       (target_read_code): Declare.
+
 2013-11-24  Yao Qi  <yao@codesourcery.com>
 
        * target-dcache.c (stack_cache_enabled_p_1): Rename to ...
index 9fc3638ff0c1e539135936626d0555a7fb12c99d..5110b273f52bfc6407d6af5ccacc9471790ce7b7 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -117,6 +117,11 @@ show startup-with-shell
   Specifies whether Unix child processes are started via a shell or
   directly.
 
+set code-cache
+show code-cache
+  Use the target memory cache for accesses to the code segment.  This
+  improves performance of remote debugging (particularly disassembly).
+
 * You can now use a literal value 'unlimited' for options that
   interpret 0 or -1 as meaning "unlimited".  E.g., "set
   trace-buffer-size unlimited" is now an alias for "set
index 7ec3f615b7b32602d811d5d8e63e87b94d72cade..141d47f4ee90643f4203ad2db53301b5982b6aee 100644 (file)
@@ -1,3 +1,8 @@
+2013-11-24  Yao Qi  <yao@codesourcery.com>
+
+       * gdb.texinfo (Caching Remote Data): Document new
+       "set/show stack-cache" option.
+
 2013-11-24  Yao Qi  <yao@codesourcery.com>
 
        * gdb.texinfo (Caching Target Data): Replace "ON" with "on".
index 830a156a0f530ccf8c93806e9d9f0922224f0847..004c3761bfa219bae6d6904a97042c885246b2cb 100644 (file)
@@ -10842,7 +10842,8 @@ Therefore, by default, @value{GDBN} only caches data
 known to be on the stack@footnote{In non-stop mode, it is moderately
 rare for a running thread to modify the stack of a stopped thread
 in a way that would interfere with a backtrace, and caching of
-stack reads provides a significant speed up of remote backtraces.}.
+stack reads provides a significant speed up of remote backtraces.} or
+in the code segment.
 Other regions of memory can be explicitly marked as
 cacheable; @pxref{Memory Region Attributes}.
 
@@ -10867,6 +10868,18 @@ caching.  By default, this option is @code{on}.
 @item show stack-cache
 Show the current state of data caching for memory accesses.
 
+@kindex set code-cache
+@item set code-cache on
+@itemx set code-cache off
+Enable or disable caching of code segment accesses.  When @code{on},
+use caching.  By default, this option is @code{on}.  This improves
+performance of disassembly in remote debugging.
+
+@kindex show code-cache
+@item show code-cache
+Show the current state of target memory cache for code segment
+accesses.
+
 @kindex info dcache
 @item info dcache @r{[}line@r{]}
 Print the information about the performance of data cache of the
index 6b7986a4124eb6e27dd94a2353f1c2455e6c3989..7f68ddc8620f97f1b8b2cc572be29ba49a4f3ea9 100644 (file)
@@ -124,6 +124,46 @@ stack_cache_enabled_p (void)
   return stack_cache_enabled;
 }
 
+/* The option sets this.  */
+
+static int code_cache_enabled_1 = 1;
+
+/* And set_code_cache updates this.
+   The reason for the separation is so that we don't flush the cache for
+   on->on transitions.  */
+static int code_cache_enabled = 1;
+
+/* This is called *after* the code-cache has been set.
+   Flush the cache for off->on and on->off transitions.
+   There's no real need to flush the cache for on->off transitions,
+   except cleanliness.  */
+
+static void
+set_code_cache (char *args, int from_tty, struct cmd_list_element *c)
+{
+  if (code_cache_enabled != code_cache_enabled_1)
+    target_dcache_invalidate ();
+
+  code_cache_enabled = code_cache_enabled_1;
+}
+
+/* Show option "code-cache".  */
+
+static void
+show_code_cache (struct ui_file *file, int from_tty,
+                struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Cache use for code accesses is %s.\n"), value);
+}
+
+/* Return true if "code cache" is enabled, otherwise, return false.  */
+
+int
+code_cache_enabled_p (void)
+{
+  return code_cache_enabled;
+}
+
 /* -Wmissing-prototypes */
 extern initialize_file_ftype _initialize_target_dcache;
 
@@ -141,6 +181,18 @@ By default, caching for stack access is on."),
                           show_stack_cache,
                           &setlist, &showlist);
 
+  add_setshow_boolean_cmd ("code-cache", class_support,
+                          &code_cache_enabled_1, _("\
+Set cache use for code segment access."), _("\
+Show cache use for code segment access."), _("\
+When on, use the target memory cache for all code segment accesses,\n\
+regardless of any configured memory regions.  This improves remote\n\
+performance significantly.  By default, caching for code segment\n\
+access is on."),
+                          set_code_cache,
+                          show_code_cache,
+                          &setlist, &showlist);
+
   target_dcache_aspace_key
     = register_address_space_data_with_cleanup (NULL,
                                                target_dcache_cleanup);
index 3200dd9621b0442d16fb5b23627f4f97419b9539..59e0b3d788b457dfd5fdc3164174d2f3abfc190c 100644 (file)
@@ -30,4 +30,6 @@ extern int target_dcache_init_p (void);
 
 extern int stack_cache_enabled_p (void);
 
+extern int code_cache_enabled_p (void);
+
 #endif /* TARGET_DCACHE_H */
index f402a18752ae7a27086bd1c94c2be34e2093217c..cc6194b3ba7b182a3499076b3d61d6a9c01e34f8 100644 (file)
@@ -1547,7 +1547,8 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
         the collected memory range fails.  */
       && get_traceframe_number () == -1
       && (region->attrib.cache
-         || (stack_cache_enabled_p () && object == TARGET_OBJECT_STACK_MEMORY)))
+         || (stack_cache_enabled_p () && object == TARGET_OBJECT_STACK_MEMORY)
+         || (code_cache_enabled_p () && object == TARGET_OBJECT_CODE_MEMORY)))
     {
       DCACHE *dcache = target_dcache_get_or_init ();
 
@@ -1600,8 +1601,8 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
       && writebuf != NULL
       && target_dcache_init_p ()
       && !region->attrib.cache
-      && stack_cache_enabled_p ()
-      && object != TARGET_OBJECT_STACK_MEMORY)
+      && ((stack_cache_enabled_p () && object != TARGET_OBJECT_STACK_MEMORY)
+         || (code_cache_enabled_p () && object != TARGET_OBJECT_CODE_MEMORY)))
     {
       DCACHE *dcache = target_dcache_get ();
 
@@ -1697,7 +1698,8 @@ target_xfer_partial (struct target_ops *ops,
   /* If this is a memory transfer, let the memory-specific code
      have a look at it instead.  Memory transfers are more
      complicated.  */
-  if (object == TARGET_OBJECT_MEMORY || object == TARGET_OBJECT_STACK_MEMORY)
+  if (object == TARGET_OBJECT_MEMORY || object == TARGET_OBJECT_STACK_MEMORY
+      || object == TARGET_OBJECT_CODE_MEMORY)
     retval = memory_xfer_partial (ops, object, readbuf,
                                  writebuf, offset, len);
   else
@@ -1799,6 +1801,19 @@ target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
     return TARGET_XFER_E_IO;
 }
 
+/* Like target_read_memory, but specify explicitly that this is a read from
+   the target's code.  This may trigger different cache behavior.  */
+
+int
+target_read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
+{
+  if (target_read (current_target.beneath, TARGET_OBJECT_CODE_MEMORY, NULL,
+                  myaddr, memaddr, len) == len)
+    return 0;
+  else
+    return TARGET_XFER_E_IO;
+}
+
 /* Write LEN bytes from MYADDR to target memory at address MEMADDR.
    Returns either 0 for success or a target_xfer_error value if any
    error occurs.  If an error occurs, no guarantee is made about how
index 646907a0e69f1491aebf4c5fabc8345c7c4f61a6..890171da14a748fc817d3646f3ad0dead99e4976 100644 (file)
@@ -145,6 +145,9 @@ enum target_object
      if it is not in a region marked as such, since it is known to be
      "normal" RAM.  */
   TARGET_OBJECT_STACK_MEMORY,
+  /* Memory known to be part of the target code.   This is cached even
+     if it is not in a region marked as such.  */
+  TARGET_OBJECT_CODE_MEMORY,
   /* Kernel Unwind Table.  See "ia64-tdep.c".  */
   TARGET_OBJECT_UNWIND_TABLE,
   /* Transfer auxilliary vector.  */
@@ -1050,6 +1053,8 @@ extern int target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr,
 
 extern int target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len);
 
+extern int target_read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len);
+
 extern int target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr,
                                ssize_t len);
 
This page took 0.094954 seconds and 4 git commands to generate.