intel/l3: Don't assert on gen12 (use gen11 config temporarily)
[mesa.git] / src / intel / common / gen_l3_config.c
1 /*
2 * Copyright (c) 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <stdlib.h>
25 #include <math.h>
26
27 #include "util/macros.h"
28 #include "main/macros.h"
29
30 #include "gen_l3_config.h"
31
32 /**
33 * IVB/HSW validated L3 configurations. The first entry will be used as
34 * default by gen7_restore_default_l3_config(), otherwise the ordering is
35 * unimportant.
36 */
37 static const struct gen_l3_config ivb_l3_configs[] = {
38 /* SLM URB ALL DC RO IS C T */
39 {{ 0, 32, 0, 0, 32, 0, 0, 0 }},
40 {{ 0, 32, 0, 16, 16, 0, 0, 0 }},
41 {{ 0, 32, 0, 4, 0, 8, 4, 16 }},
42 {{ 0, 28, 0, 8, 0, 8, 4, 16 }},
43 {{ 0, 28, 0, 16, 0, 8, 4, 8 }},
44 {{ 0, 28, 0, 8, 0, 16, 4, 8 }},
45 {{ 0, 28, 0, 0, 0, 16, 4, 16 }},
46 {{ 0, 32, 0, 0, 0, 16, 0, 16 }},
47 {{ 0, 28, 0, 4, 32, 0, 0, 0 }},
48 {{ 16, 16, 0, 16, 16, 0, 0, 0 }},
49 {{ 16, 16, 0, 8, 0, 8, 8, 8 }},
50 {{ 16, 16, 0, 4, 0, 8, 4, 16 }},
51 {{ 16, 16, 0, 4, 0, 16, 4, 8 }},
52 {{ 16, 16, 0, 0, 32, 0, 0, 0 }},
53 {{ 0 }}
54 };
55
56 /**
57 * VLV validated L3 configurations. \sa ivb_l3_configs.
58 */
59 static const struct gen_l3_config vlv_l3_configs[] = {
60 /* SLM URB ALL DC RO IS C T */
61 {{ 0, 64, 0, 0, 32, 0, 0, 0 }},
62 {{ 0, 80, 0, 0, 16, 0, 0, 0 }},
63 {{ 0, 80, 0, 8, 8, 0, 0, 0 }},
64 {{ 0, 64, 0, 16, 16, 0, 0, 0 }},
65 {{ 0, 60, 0, 4, 32, 0, 0, 0 }},
66 {{ 32, 32, 0, 16, 16, 0, 0, 0 }},
67 {{ 32, 40, 0, 8, 16, 0, 0, 0 }},
68 {{ 32, 40, 0, 16, 8, 0, 0, 0 }},
69 {{ 0 }}
70 };
71
72 /**
73 * BDW validated L3 configurations. \sa ivb_l3_configs.
74 */
75 static const struct gen_l3_config bdw_l3_configs[] = {
76 /* SLM URB ALL DC RO IS C T */
77 {{ 0, 48, 48, 0, 0, 0, 0, 0 }},
78 {{ 0, 48, 0, 16, 32, 0, 0, 0 }},
79 {{ 0, 32, 0, 16, 48, 0, 0, 0 }},
80 {{ 0, 32, 0, 0, 64, 0, 0, 0 }},
81 {{ 0, 32, 64, 0, 0, 0, 0, 0 }},
82 {{ 24, 16, 48, 0, 0, 0, 0, 0 }},
83 {{ 24, 16, 0, 16, 32, 0, 0, 0 }},
84 {{ 24, 16, 0, 32, 16, 0, 0, 0 }},
85 {{ 0 }}
86 };
87
88 /**
89 * CHV/SKL validated L3 configurations. \sa ivb_l3_configs.
90 */
91 static const struct gen_l3_config chv_l3_configs[] = {
92 /* SLM URB ALL DC RO IS C T */
93 {{ 0, 48, 48, 0, 0, 0, 0, 0 }},
94 {{ 0, 48, 0, 16, 32, 0, 0, 0 }},
95 {{ 0, 32, 0, 16, 48, 0, 0, 0 }},
96 {{ 0, 32, 0, 0, 64, 0, 0, 0 }},
97 {{ 0, 32, 64, 0, 0, 0, 0, 0 }},
98 {{ 32, 16, 48, 0, 0, 0, 0, 0 }},
99 {{ 32, 16, 0, 16, 32, 0, 0, 0 }},
100 {{ 32, 16, 0, 32, 16, 0, 0, 0 }},
101 {{ 0 }}
102 };
103
104 /**
105 * BXT 2x6 validated L3 configurations. \sa ivb_l3_configs.
106 */
107 static const struct gen_l3_config bxt_2x6_l3_configs[] = {
108 /* SLM URB ALL DC RO IS C T */
109 {{ 0, 32, 48, 0, 0, 0, 0, 0 }},
110 {{ 0, 32, 0, 8, 40, 0, 0, 0 }},
111 {{ 0, 32, 0, 32, 16, 0, 0, 0 }},
112 {{ 16, 16, 48, 0, 0, 0, 0, 0 }},
113 {{ 16, 16, 0, 40, 8, 0, 0, 0 }},
114 {{ 16, 16, 0, 16, 32, 0, 0, 0 }},
115 {{ 0 }}
116 };
117
118 /**
119 * CNL validated L3 configurations. \sa ivb_l3_configs.
120 */
121 static const struct gen_l3_config cnl_l3_configs[] = {
122 /* SLM URB ALL DC RO IS C T */
123 {{ 0, 64, 64, 0, 0, 0, 0, 0 }},
124 {{ 0, 64, 0, 16, 48, 0, 0, 0 }},
125 {{ 0, 48, 0, 16, 64, 0, 0, 0 }},
126 {{ 0, 32, 0, 0, 96, 0, 0, 0 }},
127 {{ 0, 32, 96, 0, 0, 0, 0, 0 }},
128 {{ 0, 32, 0, 16, 80, 0, 0, 0 }},
129 {{ 32, 16, 80, 0, 0, 0, 0, 0 }},
130 {{ 32, 16, 0, 64, 16, 0, 0, 0 }},
131 {{ 32, 0, 96, 0, 0, 0, 0, 0 }},
132 {{ 0 }}
133 };
134
135 /**
136 * ICL validated L3 configurations. \sa icl_l3_configs.
137 * Zeroth entry in below table has been commented out intentionally
138 * due to known issues with this configuration. Many other entries
139 * suggested by h/w specification aren't added here because they
140 * do under allocation of L3 cache with below partitioning.
141 */
142 static const struct gen_l3_config icl_l3_configs[] = {
143 /* SLM URB ALL DC RO IS C T */
144 /*{{ 0, 16, 80, 0, 0, 0, 0, 0 }},*/
145 {{ 0, 32, 64, 0, 0, 0, 0, 0 }},
146 {{ 0 }}
147 };
148
149
150 /**
151 * Return a zero-terminated array of validated L3 configurations for the
152 * specified device.
153 */
154 static const struct gen_l3_config *
155 get_l3_configs(const struct gen_device_info *devinfo)
156 {
157 switch (devinfo->gen) {
158 case 7:
159 return (devinfo->is_baytrail ? vlv_l3_configs : ivb_l3_configs);
160
161 case 8:
162 return (devinfo->is_cherryview ? chv_l3_configs : bdw_l3_configs);
163
164 case 9:
165 if (devinfo->l3_banks == 1)
166 return bxt_2x6_l3_configs;
167 return chv_l3_configs;
168
169 case 10:
170 return cnl_l3_configs;
171
172 case 11:
173 case 12:
174 return icl_l3_configs;
175
176 default:
177 unreachable("Not implemented");
178 }
179 }
180
181 /**
182 * L1-normalize a vector of L3 partition weights.
183 */
184 static struct gen_l3_weights
185 norm_l3_weights(struct gen_l3_weights w)
186 {
187 float sz = 0;
188
189 for (unsigned i = 0; i < GEN_NUM_L3P; i++)
190 sz += w.w[i];
191
192 for (unsigned i = 0; i < GEN_NUM_L3P; i++)
193 w.w[i] /= sz;
194
195 return w;
196 }
197
198 /**
199 * Get the relative partition weights of the specified L3 configuration.
200 */
201 struct gen_l3_weights
202 gen_get_l3_config_weights(const struct gen_l3_config *cfg)
203 {
204 if (cfg) {
205 struct gen_l3_weights w;
206
207 for (unsigned i = 0; i < GEN_NUM_L3P; i++)
208 w.w[i] = cfg->n[i];
209
210 return norm_l3_weights(w);
211 } else {
212 const struct gen_l3_weights w = { { 0 } };
213 return w;
214 }
215 }
216
217 /**
218 * Distance between two L3 configurations represented as vectors of weights.
219 * Usually just the L1 metric except when the two configurations are
220 * considered incompatible in which case the distance will be infinite. Note
221 * that the compatibility condition is asymmetric -- They will be considered
222 * incompatible whenever the reference configuration \p w0 requires SLM, DC,
223 * or URB but \p w1 doesn't provide it.
224 */
225 float
226 gen_diff_l3_weights(struct gen_l3_weights w0, struct gen_l3_weights w1)
227 {
228 if ((w0.w[GEN_L3P_SLM] && !w1.w[GEN_L3P_SLM]) ||
229 (w0.w[GEN_L3P_DC] && !w1.w[GEN_L3P_DC] && !w1.w[GEN_L3P_ALL]) ||
230 (w0.w[GEN_L3P_URB] && !w1.w[GEN_L3P_URB])) {
231 return HUGE_VALF;
232
233 } else {
234 float dw = 0;
235
236 for (unsigned i = 0; i < GEN_NUM_L3P; i++)
237 dw += fabs(w0.w[i] - w1.w[i]);
238
239 return dw;
240 }
241 }
242
243 /**
244 * Return a reasonable default L3 configuration for the specified device based
245 * on whether SLM and DC are required. In the non-SLM non-DC case the result
246 * is intended to approximately resemble the hardware defaults.
247 */
248 struct gen_l3_weights
249 gen_get_default_l3_weights(const struct gen_device_info *devinfo,
250 bool needs_dc, bool needs_slm)
251 {
252 struct gen_l3_weights w = {{ 0 }};
253
254 w.w[GEN_L3P_SLM] = devinfo->gen < 11 && needs_slm;
255 w.w[GEN_L3P_URB] = 1.0;
256
257 if (devinfo->gen >= 8) {
258 w.w[GEN_L3P_ALL] = 1.0;
259 } else {
260 w.w[GEN_L3P_DC] = needs_dc ? 0.1 : 0;
261 w.w[GEN_L3P_RO] = devinfo->is_baytrail ? 0.5 : 1.0;
262 }
263
264 return norm_l3_weights(w);
265 }
266
267 /**
268 * Get the default L3 configuration
269 */
270 const struct gen_l3_config *
271 gen_get_default_l3_config(const struct gen_device_info *devinfo)
272 {
273 /* For efficiency assume that the first entry of the array matches the
274 * default configuration.
275 */
276 const struct gen_l3_config *const cfg = get_l3_configs(devinfo);
277 assert(cfg == gen_get_l3_config(devinfo,
278 gen_get_default_l3_weights(devinfo, false, false)));
279 return cfg;
280 }
281
282 /**
283 * Return the closest validated L3 configuration for the specified device and
284 * weight vector.
285 */
286 const struct gen_l3_config *
287 gen_get_l3_config(const struct gen_device_info *devinfo,
288 struct gen_l3_weights w0)
289 {
290 const struct gen_l3_config *const cfgs = get_l3_configs(devinfo);
291 const struct gen_l3_config *cfg_best = NULL;
292 float dw_best = HUGE_VALF;
293
294 for (const struct gen_l3_config *cfg = cfgs; cfg->n[GEN_L3P_URB]; cfg++) {
295 const float dw = gen_diff_l3_weights(w0, gen_get_l3_config_weights(cfg));
296
297 if (dw < dw_best) {
298 cfg_best = cfg;
299 dw_best = dw;
300 }
301 }
302
303 return cfg_best;
304 }
305
306 /**
307 * Return the size of an L3 way in KB.
308 */
309 static unsigned
310 get_l3_way_size(const struct gen_device_info *devinfo)
311 {
312 const unsigned way_size_per_bank =
313 (devinfo->gen >= 9 && devinfo->l3_banks == 1) || devinfo->gen == 11 ?
314 4 : 2;
315
316 assert(devinfo->l3_banks);
317 return way_size_per_bank * devinfo->l3_banks;
318 }
319
320 /**
321 * Return the unit brw_context::urb::size is expressed in, in KB. \sa
322 * gen_device_info::urb::size.
323 */
324 static unsigned
325 get_urb_size_scale(const struct gen_device_info *devinfo)
326 {
327 return (devinfo->gen >= 8 ? devinfo->num_slices : 1);
328 }
329
330 unsigned
331 gen_get_l3_config_urb_size(const struct gen_device_info *devinfo,
332 const struct gen_l3_config *cfg)
333 {
334 /* From the SKL "L3 Allocation and Programming" documentation:
335 *
336 * "URB is limited to 1008KB due to programming restrictions. This is not
337 * a restriction of the L3 implementation, but of the FF and other clients.
338 * Therefore, in a GT4 implementation it is possible for the programmed
339 * allocation of the L3 data array to provide 3*384KB=1152KB for URB, but
340 * only 1008KB of this will be used."
341 */
342 const unsigned max = (devinfo->gen == 9 ? 1008 : ~0);
343 return MIN2(max, cfg->n[GEN_L3P_URB] * get_l3_way_size(devinfo)) /
344 get_urb_size_scale(devinfo);
345 }
346
347 /**
348 * Print out the specified L3 configuration.
349 */
350 void
351 gen_dump_l3_config(const struct gen_l3_config *cfg, FILE *fp)
352 {
353 fprintf(stderr, "SLM=%d URB=%d ALL=%d DC=%d RO=%d IS=%d C=%d T=%d\n",
354 cfg->n[GEN_L3P_SLM], cfg->n[GEN_L3P_URB], cfg->n[GEN_L3P_ALL],
355 cfg->n[GEN_L3P_DC], cfg->n[GEN_L3P_RO],
356 cfg->n[GEN_L3P_IS], cfg->n[GEN_L3P_C], cfg->n[GEN_L3P_T]);
357 }