target-dcache.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* Copyright (C) 1992-2022 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. #include "cli/cli-cmds.h"
  18. /* The target dcache is kept per-address-space. This key lets us
  19. associate the cache with the address space. */
  20. static const struct address_space_key<DCACHE, dcache_deleter>
  21. target_dcache_aspace_key;
  22. /* Target dcache is initialized or not. */
  23. int
  24. target_dcache_init_p (void)
  25. {
  26. DCACHE *dcache
  27. = target_dcache_aspace_key.get (current_program_space->aspace);
  28. return (dcache != NULL);
  29. }
  30. /* Invalidate the target dcache. */
  31. void
  32. target_dcache_invalidate (void)
  33. {
  34. DCACHE *dcache
  35. = target_dcache_aspace_key.get (current_program_space->aspace);
  36. if (dcache != NULL)
  37. dcache_invalidate (dcache);
  38. }
  39. /* Return the target dcache. Return NULL if target dcache is not
  40. initialized yet. */
  41. DCACHE *
  42. target_dcache_get (void)
  43. {
  44. return target_dcache_aspace_key.get (current_program_space->aspace);
  45. }
  46. /* Return the target dcache. If it is not initialized yet, initialize
  47. it. */
  48. DCACHE *
  49. target_dcache_get_or_init (void)
  50. {
  51. DCACHE *dcache
  52. = target_dcache_aspace_key.get (current_program_space->aspace);
  53. if (dcache == NULL)
  54. {
  55. dcache = dcache_init ();
  56. target_dcache_aspace_key.set (current_program_space->aspace, dcache);
  57. }
  58. return dcache;
  59. }
  60. /* The option sets this. */
  61. static bool stack_cache_enabled_1 = true;
  62. /* And set_stack_cache updates this.
  63. The reason for the separation is so that we don't flush the cache for
  64. on->on transitions. */
  65. static int stack_cache_enabled = 1;
  66. /* This is called *after* the stack-cache has been set.
  67. Flush the cache for off->on and on->off transitions.
  68. There's no real need to flush the cache for on->off transitions,
  69. except cleanliness. */
  70. static void
  71. set_stack_cache (const char *args, int from_tty, struct cmd_list_element *c)
  72. {
  73. if (stack_cache_enabled != stack_cache_enabled_1)
  74. target_dcache_invalidate ();
  75. stack_cache_enabled = stack_cache_enabled_1;
  76. }
  77. static void
  78. show_stack_cache (struct ui_file *file, int from_tty,
  79. struct cmd_list_element *c, const char *value)
  80. {
  81. gdb_printf (file, _("Cache use for stack accesses is %s.\n"), value);
  82. }
  83. /* Return true if "stack cache" is enabled, otherwise, return false. */
  84. int
  85. stack_cache_enabled_p (void)
  86. {
  87. return stack_cache_enabled;
  88. }
  89. /* The option sets this. */
  90. static bool code_cache_enabled_1 = true;
  91. /* And set_code_cache updates this.
  92. The reason for the separation is so that we don't flush the cache for
  93. on->on transitions. */
  94. static int code_cache_enabled = 1;
  95. /* This is called *after* the code-cache has been set.
  96. Flush the cache for off->on and on->off transitions.
  97. There's no real need to flush the cache for on->off transitions,
  98. except cleanliness. */
  99. static void
  100. set_code_cache (const char *args, int from_tty, struct cmd_list_element *c)
  101. {
  102. if (code_cache_enabled != code_cache_enabled_1)
  103. target_dcache_invalidate ();
  104. code_cache_enabled = code_cache_enabled_1;
  105. }
  106. /* Show option "code-cache". */
  107. static void
  108. show_code_cache (struct ui_file *file, int from_tty,
  109. struct cmd_list_element *c, const char *value)
  110. {
  111. gdb_printf (file, _("Cache use for code accesses is %s.\n"), value);
  112. }
  113. /* Return true if "code cache" is enabled, otherwise, return false. */
  114. int
  115. code_cache_enabled_p (void)
  116. {
  117. return code_cache_enabled;
  118. }
  119. /* Implement the 'maint flush dcache' command. */
  120. static void
  121. maint_flush_dcache_command (const char *command, int from_tty)
  122. {
  123. target_dcache_invalidate ();
  124. if (from_tty)
  125. gdb_printf (_("The dcache was flushed.\n"));
  126. }
  127. void _initialize_target_dcache ();
  128. void
  129. _initialize_target_dcache ()
  130. {
  131. add_setshow_boolean_cmd ("stack-cache", class_support,
  132. &stack_cache_enabled_1, _("\
  133. Set cache use for stack access."), _("\
  134. Show cache use for stack access."), _("\
  135. When on, use the target memory cache for all stack access, regardless of any\n\
  136. configured memory regions. This improves remote performance significantly.\n\
  137. By default, caching for stack access is on."),
  138. set_stack_cache,
  139. show_stack_cache,
  140. &setlist, &showlist);
  141. add_setshow_boolean_cmd ("code-cache", class_support,
  142. &code_cache_enabled_1, _("\
  143. Set cache use for code segment access."), _("\
  144. Show cache use for code segment access."), _("\
  145. When on, use the target memory cache for all code segment accesses,\n\
  146. regardless of any configured memory regions. This improves remote\n\
  147. performance significantly. By default, caching for code segment\n\
  148. access is on."),
  149. set_code_cache,
  150. show_code_cache,
  151. &setlist, &showlist);
  152. add_cmd ("dcache", class_maintenance, maint_flush_dcache_command,
  153. _("\
  154. Force gdb to flush its target memory data cache.\n\
  155. \n\
  156. The dcache caches all target memory accesses where possible, this\n\
  157. includes the stack-cache and the code-cache."),
  158. &maintenanceflushlist);
  159. }