GDB (xrefs)

/tmp/gdb-8.1/gdb/target-dcache.c
Go to the documentation of this file.
1 /* Copyright (C) 1992-2018 Free Software Foundation, Inc.
2
3 This file is part of GDB.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18 #include "defs.h"
19 #include "target-dcache.h"
20 #include "gdbcmd.h"
21 #include "progspace.h"
22
23 /* The target dcache is kept per-address-space. This key lets us
24 associate the cache with the address space. */
25
26 static const struct address_space_data *target_dcache_aspace_key;
27
28 /* Clean up dcache, represented by ARG, which is associated with
29 ASPACE. */
30
31 static void
32 target_dcache_cleanup (struct address_space *aspace, void *arg)
33 {
34 dcache_free ((DCACHE *) arg);
35 }
36
37 /* Target dcache is initialized or not. */
38
39 int
40 target_dcache_init_p (void)
41 {
42 DCACHE *dcache
43 = (DCACHE *) address_space_data (current_program_space->aspace,
44 target_dcache_aspace_key);
45
46 return (dcache != NULL);
47 }
48
49 /* Invalidate the target dcache. */
50
51 void
52 target_dcache_invalidate (void)
53 {
54 DCACHE *dcache
55 = (DCACHE *) address_space_data (current_program_space->aspace,
56 target_dcache_aspace_key);
57
58 if (dcache != NULL)
59 dcache_invalidate (dcache);
60 }
61
62 /* Return the target dcache. Return NULL if target dcache is not
63 initialized yet. */
64
65 DCACHE *
66 target_dcache_get (void)
67 {
68 DCACHE *dcache
69 = (DCACHE *) address_space_data (current_program_space->aspace,
70 target_dcache_aspace_key);
71
72 return dcache;
73 }
74
75 /* Return the target dcache. If it is not initialized yet, initialize
76 it. */
77
78 DCACHE *
79 target_dcache_get_or_init (void)
80 {
81 DCACHE *dcache
82 = (DCACHE *) address_space_data (current_program_space->aspace,
83 target_dcache_aspace_key);
84
85 if (dcache == NULL)
86 {
87 dcache = dcache_init ();
88 set_address_space_data (current_program_space->aspace,
89 target_dcache_aspace_key, dcache);
90 }
91
92 return dcache;
93 }
94
95 /* The option sets this. */
96 static int stack_cache_enabled_1 = 1;
97 /* And set_stack_cache updates this.
98 The reason for the separation is so that we don't flush the cache for
99 on->on transitions. */
100 static int stack_cache_enabled = 1;
101
102 /* This is called *after* the stack-cache has been set.
103 Flush the cache for off->on and on->off transitions.
104 There's no real need to flush the cache for on->off transitions,
105 except cleanliness. */
106
107 static void
108 set_stack_cache (const char *args, int from_tty, struct cmd_list_element *c)
109 {
110 if (stack_cache_enabled != stack_cache_enabled_1)
111 target_dcache_invalidate ();
112
113 stack_cache_enabled = stack_cache_enabled_1;
114 }
115
116 static void
117 show_stack_cache (struct ui_file *file, int from_tty,
118 struct cmd_list_element *c, const char *value)
119 {
120 fprintf_filtered (file, _("Cache use for stack accesses is %s.\n"), value);
121 }
122
123 /* Return true if "stack cache" is enabled, otherwise, return false. */
124
125 int
126 stack_cache_enabled_p (void)
127 {
128 return stack_cache_enabled;
129 }
130
131 /* The option sets this. */
132
133 static int code_cache_enabled_1 = 1;
134
135 /* And set_code_cache updates this.
136 The reason for the separation is so that we don't flush the cache for
137 on->on transitions. */
138 static int code_cache_enabled = 1;
139
140 /* This is called *after* the code-cache has been set.
141 Flush the cache for off->on and on->off transitions.
142 There's no real need to flush the cache for on->off transitions,
143 except cleanliness. */
144
145 static void
146 set_code_cache (const char *args, int from_tty, struct cmd_list_element *c)
147 {
148 if (code_cache_enabled != code_cache_enabled_1)
149 target_dcache_invalidate ();
150
151 code_cache_enabled = code_cache_enabled_1;
152 }
153
154 /* Show option "code-cache". */
155
156 static void
157 show_code_cache (struct ui_file *file, int from_tty,
158 struct cmd_list_element *c, const char *value)
159 {
160 fprintf_filtered (file, _("Cache use for code accesses is %s.\n"), value);
161 }
162
163 /* Return true if "code cache" is enabled, otherwise, return false. */
164
165 int
166 code_cache_enabled_p (void)
167 {
168 return code_cache_enabled;
169 }
170
171 void
172 _initialize_target_dcache (void)
173 {
174 add_setshow_boolean_cmd ("stack-cache", class_support,
175 &stack_cache_enabled_1, _("\
176 Set cache use for stack access."), _("\
177 Show cache use for stack access."), _("\
178 When on, use the target memory cache for all stack access, regardless of any\n\
179 configured memory regions. This improves remote performance significantly.\n\
180 By default, caching for stack access is on."),
181 set_stack_cache,
182 show_stack_cache,
183 &setlist, &showlist);
184
185 add_setshow_boolean_cmd ("code-cache", class_support,
186 &code_cache_enabled_1, _("\
187 Set cache use for code segment access."), _("\
188 Show cache use for code segment access."), _("\
189 When on, use the target memory cache for all code segment accesses,\n\
190 regardless of any configured memory regions. This improves remote\n\
191 performance significantly. By default, caching for code segment\n\
192 access is on."),
193 set_code_cache,
194 show_code_cache,
195 &setlist, &showlist);
196
197 target_dcache_aspace_key
198 = register_address_space_data_with_cleanup (NULL,
199 target_dcache_cleanup);
200 }
stack_cache_enabled_1
static int stack_cache_enabled_1
Definition: target-dcache.c:96
dcache_init
DCACHE * dcache_init(void)
Definition: dcache.c:442
program_space::aspace
struct address_space * aspace
Definition: progspace.h:166
target-dcache.h
class_support
Definition: command.h:42
cmd_list_element
Definition: cli-decode.h:46
dcache_free
void dcache_free(DCACHE *dcache)
Definition: dcache.c:219
progspace.h
code_cache_enabled_1
static int code_cache_enabled_1
Definition: target-dcache.c:133
target_dcache_get_or_init
DCACHE * target_dcache_get_or_init(void)
Definition: target-dcache.c:79
_
#define _(String)
Definition: gdb_locale.h:35
ui_file
Definition: ui-file.h:26
defs.h
stack_cache_enabled
static int stack_cache_enabled
Definition: target-dcache.c:100
code_cache_enabled
static int code_cache_enabled
Definition: target-dcache.c:138
show_code_cache
static void show_code_cache(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: target-dcache.c:157
setlist
struct cmd_list_element * setlist
Definition: cli-cmds.c:111
target_dcache_invalidate
void target_dcache_invalidate(void)
Definition: target-dcache.c:52
dcache_struct
Definition: dcache.c:103
fprintf_filtered
void fprintf_filtered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2008
target_dcache_init_p
int target_dcache_init_p(void)
Definition: target-dcache.c:40
showlist
struct cmd_list_element * showlist
Definition: cli-cmds.c:119
value
Definition: value.c:169
target_dcache_cleanup
static void target_dcache_cleanup(struct address_space *aspace, void *arg)
Definition: target-dcache.c:32
dcache_invalidate
void dcache_invalidate(DCACHE *dcache)
Definition: dcache.c:244
_initialize_target_dcache
void _initialize_target_dcache(void)
Definition: target-dcache.c:172
set_stack_cache
static void set_stack_cache(const char *args, int from_tty, struct cmd_list_element *c)
Definition: target-dcache.c:108
address_space
Definition: progspace.h:216
add_setshow_boolean_cmd
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_const_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition: cli-decode.c:569
current_program_space
struct program_space * current_program_space
Definition: progspace.c:35
target_dcache_aspace_key
static const struct address_space_data * target_dcache_aspace_key
Definition: target-dcache.c:26
code_cache_enabled_p
int code_cache_enabled_p(void)
Definition: target-dcache.c:166
show_stack_cache
static void show_stack_cache(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition: target-dcache.c:117
stack_cache_enabled_p
int stack_cache_enabled_p(void)
Definition: target-dcache.c:126
gdbcmd.h
target_dcache_get
DCACHE * target_dcache_get(void)
Definition: target-dcache.c:66
set_code_cache
static void set_code_cache(const char *args, int from_tty, struct cmd_list_element *c)
Definition: target-dcache.c:146