gdb/target-dcache.c - gdb

Global variables defined

Functions defined

Source code

  1. /* Copyright (C) 1992-2015 Free Software Foundation, Inc.

  2.    This file is part of GDB.

  3.    This program is free software; you can redistribute it and/or modify
  4.    it under the terms of the GNU General Public License as published by
  5.    the Free Software Foundation; either version 3 of the License, or
  6.    (at your option) any later version.

  7.    This program is distributed in the hope that it will be useful,
  8.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.    GNU General Public License for more details.

  11.    You should have received a copy of the GNU General Public License
  12.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  13. #include "defs.h"
  14. #include "target-dcache.h"
  15. #include "gdbcmd.h"
  16. #include "progspace.h"

  17. /* The target dcache is kept per-address-space.  This key lets us
  18.    associate the cache with the address space.  */

  19. static const struct address_space_data *target_dcache_aspace_key;

  20. /* Clean up dcache, represented by ARG, which is associated with
  21.    ASPACE.  */

  22. static void
  23. target_dcache_cleanup (struct address_space *aspace, void *arg)
  24. {
  25.   dcache_free (arg);
  26. }

  27. /* Target dcache is initialized or not.  */

  28. int
  29. target_dcache_init_p (void)
  30. {
  31.   DCACHE *dcache = address_space_data (current_program_space->aspace,
  32.                                        target_dcache_aspace_key);

  33.   return (dcache != NULL);
  34. }

  35. /* Invalidate the target dcache.  */

  36. void
  37. target_dcache_invalidate (void)
  38. {
  39.   DCACHE *dcache = address_space_data (current_program_space->aspace,
  40.                                        target_dcache_aspace_key);

  41.   if (dcache != NULL)
  42.     dcache_invalidate (dcache);
  43. }

  44. /* Return the target dcache.  Return NULL if target dcache is not
  45.    initialized yet.  */

  46. DCACHE *
  47. target_dcache_get (void)
  48. {
  49.   DCACHE *dcache = address_space_data (current_program_space->aspace,
  50.                                        target_dcache_aspace_key);

  51.   return dcache;
  52. }

  53. /* Return the target dcache.  If it is not initialized yet, initialize
  54.    it.  */

  55. DCACHE *
  56. target_dcache_get_or_init (void)
  57. {
  58.   DCACHE *dcache = address_space_data (current_program_space->aspace,
  59.                                        target_dcache_aspace_key);

  60.   if (dcache == NULL)
  61.     {
  62.       dcache = dcache_init ();
  63.       set_address_space_data (current_program_space->aspace,
  64.                               target_dcache_aspace_key, dcache);
  65.     }

  66.   return dcache;
  67. }

  68. /* The option sets this.  */
  69. static int stack_cache_enabled_1 = 1;
  70. /* And set_stack_cache updates this.
  71.    The reason for the separation is so that we don't flush the cache for
  72.    on->on transitions.  */
  73. static int stack_cache_enabled = 1;

  74. /* This is called *after* the stack-cache has been set.
  75.    Flush the cache for off->on and on->off transitions.
  76.    There's no real need to flush the cache for on->off transitions,
  77.    except cleanliness.  */

  78. static void
  79. set_stack_cache (char *args, int from_tty, struct cmd_list_element *c)
  80. {
  81.   if (stack_cache_enabled != stack_cache_enabled_1)
  82.     target_dcache_invalidate ();

  83.   stack_cache_enabled = stack_cache_enabled_1;
  84. }

  85. static void
  86. show_stack_cache (struct ui_file *file, int from_tty,
  87.                   struct cmd_list_element *c, const char *value)
  88. {
  89.   fprintf_filtered (file, _("Cache use for stack accesses is %s.\n"), value);
  90. }

  91. /* Return true if "stack cache" is enabled, otherwise, return false.  */

  92. int
  93. stack_cache_enabled_p (void)
  94. {
  95.   return stack_cache_enabled;
  96. }

  97. /* The option sets this.  */

  98. static int code_cache_enabled_1 = 1;

  99. /* And set_code_cache updates this.
  100.    The reason for the separation is so that we don't flush the cache for
  101.    on->on transitions.  */
  102. static int code_cache_enabled = 1;

  103. /* This is called *after* the code-cache has been set.
  104.    Flush the cache for off->on and on->off transitions.
  105.    There's no real need to flush the cache for on->off transitions,
  106.    except cleanliness.  */

  107. static void
  108. set_code_cache (char *args, int from_tty, struct cmd_list_element *c)
  109. {
  110.   if (code_cache_enabled != code_cache_enabled_1)
  111.     target_dcache_invalidate ();

  112.   code_cache_enabled = code_cache_enabled_1;
  113. }

  114. /* Show option "code-cache".  */

  115. static void
  116. show_code_cache (struct ui_file *file, int from_tty,
  117.                  struct cmd_list_element *c, const char *value)
  118. {
  119.   fprintf_filtered (file, _("Cache use for code accesses is %s.\n"), value);
  120. }

  121. /* Return true if "code cache" is enabled, otherwise, return false.  */

  122. int
  123. code_cache_enabled_p (void)
  124. {
  125.   return code_cache_enabled;
  126. }

  127. /* -Wmissing-prototypes */
  128. extern initialize_file_ftype _initialize_target_dcache;

  129. void
  130. _initialize_target_dcache (void)
  131. {
  132.   add_setshow_boolean_cmd ("stack-cache", class_support,
  133.                            &stack_cache_enabled_1, _("\
  134. Set cache use for stack access."), _("\
  135. Show cache use for stack access."), _("\
  136. When on, use the target memory cache for all stack access, regardless of any\n\
  137. configured memory regions.  This improves remote performance significantly.\n\
  138. By default, caching for stack access is on."),
  139.                            set_stack_cache,
  140.                            show_stack_cache,
  141.                            &setlist, &showlist);

  142.   add_setshow_boolean_cmd ("code-cache", class_support,
  143.                            &code_cache_enabled_1, _("\
  144. Set cache use for code segment access."), _("\
  145. Show cache use for code segment access."), _("\
  146. When on, use the target memory cache for all code segment accesses,\n\
  147. regardless of any configured memory regions.  This improves remote\n\
  148. performance significantly.  By default, caching for code segment\n\
  149. access is on."),
  150.                            set_code_cache,
  151.                            show_code_cache,
  152.                            &setlist, &showlist);

  153.   target_dcache_aspace_key
  154.     = register_address_space_data_with_cleanup (NULL,
  155.                                                 target_dcache_cleanup);
  156. }