2
* Copyright (c) 2015 Intel Corporation
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:
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
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
27
#include "util/macros.h"
29
#include "intel_l3_config.h"
31
struct intel_l3_list {
32
const struct intel_l3_config *configs;
36
#define DECLARE_L3_LIST(hw) \
37
struct intel_l3_list hw##_l3_list = \
38
{ .configs = hw##_l3_configs, .length = ARRAY_SIZE(hw##_l3_configs) }
41
* IVB/HSW validated L3 configurations. The first entry will be used as
42
* default by gfx7_restore_default_l3_config(), otherwise the ordering is
45
static const struct intel_l3_config ivb_l3_configs[] = {
46
/* SLM URB ALL DC RO IS C T */
47
{{ 0, 32, 0, 0, 32, 0, 0, 0 }},
48
{{ 0, 32, 0, 16, 16, 0, 0, 0 }},
49
{{ 0, 32, 0, 4, 0, 8, 4, 16 }},
50
{{ 0, 28, 0, 8, 0, 8, 4, 16 }},
51
{{ 0, 28, 0, 16, 0, 8, 4, 8 }},
52
{{ 0, 28, 0, 8, 0, 16, 4, 8 }},
53
{{ 0, 28, 0, 0, 0, 16, 4, 16 }},
54
{{ 0, 32, 0, 0, 0, 16, 0, 16 }},
55
{{ 0, 28, 0, 4, 32, 0, 0, 0 }},
56
{{ 16, 16, 0, 16, 16, 0, 0, 0 }},
57
{{ 16, 16, 0, 8, 0, 8, 8, 8 }},
58
{{ 16, 16, 0, 4, 0, 8, 4, 16 }},
59
{{ 16, 16, 0, 4, 0, 16, 4, 8 }},
60
{{ 16, 16, 0, 0, 32, 0, 0, 0 }},
65
* VLV validated L3 configurations. \sa ivb_l3_configs.
67
static const struct intel_l3_config vlv_l3_configs[] = {
68
/* SLM URB ALL DC RO IS C T */
69
{{ 0, 64, 0, 0, 32, 0, 0, 0 }},
70
{{ 0, 80, 0, 0, 16, 0, 0, 0 }},
71
{{ 0, 80, 0, 8, 8, 0, 0, 0 }},
72
{{ 0, 64, 0, 16, 16, 0, 0, 0 }},
73
{{ 0, 60, 0, 4, 32, 0, 0, 0 }},
74
{{ 32, 32, 0, 16, 16, 0, 0, 0 }},
75
{{ 32, 40, 0, 8, 16, 0, 0, 0 }},
76
{{ 32, 40, 0, 16, 8, 0, 0, 0 }},
81
* BDW validated L3 configurations. \sa ivb_l3_configs.
83
static const struct intel_l3_config bdw_l3_configs[] = {
84
/* SLM URB ALL DC RO IS C T */
85
{{ 0, 48, 48, 0, 0, 0, 0, 0 }},
86
{{ 0, 48, 0, 16, 32, 0, 0, 0 }},
87
{{ 0, 32, 0, 16, 48, 0, 0, 0 }},
88
{{ 0, 32, 0, 0, 64, 0, 0, 0 }},
89
{{ 0, 32, 64, 0, 0, 0, 0, 0 }},
90
{{ 24, 16, 48, 0, 0, 0, 0, 0 }},
91
{{ 24, 16, 0, 16, 32, 0, 0, 0 }},
92
{{ 24, 16, 0, 32, 16, 0, 0, 0 }},
97
* CHV/SKL validated L3 configurations. \sa ivb_l3_configs.
99
static const struct intel_l3_config chv_l3_configs[] = {
100
/* SLM URB ALL DC RO IS C T */
101
{{ 0, 48, 48, 0, 0, 0, 0, 0 }},
102
{{ 0, 48, 0, 16, 32, 0, 0, 0 }},
103
{{ 0, 32, 0, 16, 48, 0, 0, 0 }},
104
{{ 0, 32, 0, 0, 64, 0, 0, 0 }},
105
{{ 0, 32, 64, 0, 0, 0, 0, 0 }},
106
{{ 32, 16, 48, 0, 0, 0, 0, 0 }},
107
{{ 32, 16, 0, 16, 32, 0, 0, 0 }},
108
{{ 32, 16, 0, 32, 16, 0, 0, 0 }},
110
DECLARE_L3_LIST(chv);
113
* BXT 2x6 validated L3 configurations. \sa ivb_l3_configs.
115
static const struct intel_l3_config bxt_2x6_l3_configs[] = {
116
/* SLM URB ALL DC RO IS C T */
117
{{ 0, 32, 48, 0, 0, 0, 0, 0 }},
118
{{ 0, 32, 0, 8, 40, 0, 0, 0 }},
119
{{ 0, 32, 0, 32, 16, 0, 0, 0 }},
120
{{ 16, 16, 48, 0, 0, 0, 0, 0 }},
121
{{ 16, 16, 0, 40, 8, 0, 0, 0 }},
122
{{ 16, 16, 0, 16, 32, 0, 0, 0 }},
124
DECLARE_L3_LIST(bxt_2x6);
127
* ICL validated L3 configurations. \sa icl_l3_configs.
128
* Zeroth entry in below table has been commented out intentionally
129
* due to known issues with this configuration. Many other entries
130
* suggested by h/w specification aren't added here because they
131
* do under allocation of L3 cache with below partitioning.
133
static const struct intel_l3_config icl_l3_configs[] = {
134
/* SLM URB ALL DC RO IS C T */
135
/*{{ 0, 16, 80, 0, 0, 0, 0, 0 }},*/
136
{{ 0, 32, 64, 0, 0, 0, 0, 0 }},
138
DECLARE_L3_LIST(icl);
141
* TGL validated L3 configurations. \sa tgl_l3_configs.
143
static const struct intel_l3_config tgl_l3_configs[] = {
144
/* SLM URB ALL DC RO IS C T */
145
{{ 0, 32, 88, 0, 0, 0, 0, 0 }},
146
{{ 0, 16, 104, 0, 0, 0, 0, 0 }},
148
DECLARE_L3_LIST(tgl);
151
* Empty L3 configurations. \sa empty_l3_configs.
153
static const struct intel_l3_config empty_l3_configs[] = {
154
/* No configurations. L3FullWayAllocationEnable is always set. */
156
DECLARE_L3_LIST(empty);
159
* Return a zero-terminated array of validated L3 configurations for the
162
static const struct intel_l3_list *
163
get_l3_list(const struct intel_device_info *devinfo)
165
switch (devinfo->ver) {
167
return (devinfo->platform == INTEL_PLATFORM_BYT ? &vlv_l3_list : &ivb_l3_list);
170
return (devinfo->platform == INTEL_PLATFORM_CHV ? &chv_l3_list : &bdw_l3_list);
173
if (devinfo->l3_banks == 1)
174
return &bxt_2x6_l3_list;
181
if (devinfo->platform == INTEL_PLATFORM_DG1 ||
182
intel_device_info_is_dg2(devinfo))
183
return &empty_l3_list;
188
unreachable("Not implemented");
193
* L1-normalize a vector of L3 partition weights.
195
static struct intel_l3_weights
196
norm_l3_weights(struct intel_l3_weights w)
200
for (unsigned i = 0; i < INTEL_NUM_L3P; i++)
203
for (unsigned i = 0; i < INTEL_NUM_L3P; i++)
210
* Get the relative partition weights of the specified L3 configuration.
212
struct intel_l3_weights
213
intel_get_l3_config_weights(const struct intel_l3_config *cfg)
216
struct intel_l3_weights w;
218
for (unsigned i = 0; i < INTEL_NUM_L3P; i++)
221
return norm_l3_weights(w);
223
const struct intel_l3_weights w = { { 0 } };
229
* Distance between two L3 configurations represented as vectors of weights.
230
* Usually just the L1 metric except when the two configurations are
231
* considered incompatible in which case the distance will be infinite. Note
232
* that the compatibility condition is asymmetric -- They will be considered
233
* incompatible whenever the reference configuration \p w0 requires SLM, DC,
234
* or URB but \p w1 doesn't provide it.
237
intel_diff_l3_weights(struct intel_l3_weights w0, struct intel_l3_weights w1)
239
if ((w0.w[INTEL_L3P_SLM] && !w1.w[INTEL_L3P_SLM]) ||
240
(w0.w[INTEL_L3P_DC] && !w1.w[INTEL_L3P_DC] && !w1.w[INTEL_L3P_ALL]) ||
241
(w0.w[INTEL_L3P_URB] && !w1.w[INTEL_L3P_URB])) {
247
for (unsigned i = 0; i < INTEL_NUM_L3P; i++)
248
dw += fabsf(w0.w[i] - w1.w[i]);
255
* Return a reasonable default L3 configuration for the specified device based
256
* on whether SLM and DC are required. In the non-SLM non-DC case the result
257
* is intended to approximately resemble the hardware defaults.
259
struct intel_l3_weights
260
intel_get_default_l3_weights(const struct intel_device_info *devinfo,
261
bool needs_dc, bool needs_slm)
263
struct intel_l3_weights w = {{ 0 }};
265
w.w[INTEL_L3P_SLM] = devinfo->ver < 11 && needs_slm;
266
w.w[INTEL_L3P_URB] = 1.0;
268
if (devinfo->ver >= 8) {
269
w.w[INTEL_L3P_ALL] = 1.0;
271
w.w[INTEL_L3P_DC] = needs_dc ? 0.1 : 0;
272
w.w[INTEL_L3P_RO] = devinfo->platform == INTEL_PLATFORM_BYT ? 0.5 : 1.0;
275
return norm_l3_weights(w);
279
* Get the default L3 configuration
281
const struct intel_l3_config *
282
intel_get_default_l3_config(const struct intel_device_info *devinfo)
284
/* For efficiency assume that the first entry of the array matches the
285
* default configuration.
287
const struct intel_l3_list *const list = get_l3_list(devinfo);
288
assert(list->length > 0 || devinfo->ver >= 12);
289
if (list->length > 0) {
290
const struct intel_l3_config *const cfg = &list->configs[0];
291
assert(cfg == intel_get_l3_config(devinfo,
292
intel_get_default_l3_weights(devinfo, false, false)));
300
* Return the closest validated L3 configuration for the specified device and
303
const struct intel_l3_config *
304
intel_get_l3_config(const struct intel_device_info *devinfo,
305
struct intel_l3_weights w0)
307
const struct intel_l3_list *const list = get_l3_list(devinfo);
308
const struct intel_l3_config *const cfgs = list->configs;
309
const struct intel_l3_config *cfg_best = NULL;
310
float dw_best = HUGE_VALF;
312
for (int i = 0; i < list->length; i++) {
313
const struct intel_l3_config *cfg = &cfgs[i];
314
const float dw = intel_diff_l3_weights(w0, intel_get_l3_config_weights(cfg));
322
assert(cfg_best || devinfo->ver >= 12);
327
* Return the size of an L3 way in KB.
330
get_l3_way_size(const struct intel_device_info *devinfo)
332
const unsigned way_size_per_bank =
333
(devinfo->ver >= 9 && devinfo->l3_banks == 1) || devinfo->ver >= 11 ?
336
assert(devinfo->l3_banks);
337
return way_size_per_bank * devinfo->l3_banks;
341
* Return the unit brw_context::urb::size is expressed in, in KB. \sa
342
* intel_device_info::urb::size.
345
get_urb_size_scale(const struct intel_device_info *devinfo)
347
return (devinfo->ver >= 8 ? devinfo->num_slices : 1);
351
intel_get_l3_config_urb_size(const struct intel_device_info *devinfo,
352
const struct intel_l3_config *cfg)
354
/* We don't have to program the URB size for some platforms. It's a fixed
358
ASSERTED const struct intel_l3_list *const list = get_l3_list(devinfo);
359
assert(list->length == 0);
360
return devinfo->urb.size;
363
/* From the SKL "L3 Allocation and Programming" documentation:
365
* "URB is limited to 1008KB due to programming restrictions. This is not
366
* a restriction of the L3 implementation, but of the FF and other clients.
367
* Therefore, in a GT4 implementation it is possible for the programmed
368
* allocation of the L3 data array to provide 3*384KB=1152KB for URB, but
369
* only 1008KB of this will be used."
371
const unsigned max = (devinfo->ver == 9 ? 1008 : ~0);
372
return MIN2(max, cfg->n[INTEL_L3P_URB] * get_l3_way_size(devinfo)) /
373
get_urb_size_scale(devinfo);
377
* Print out the specified L3 configuration.
380
intel_dump_l3_config(const struct intel_l3_config *cfg, FILE *fp)
382
fprintf(stderr, "SLM=%d URB=%d ALL=%d DC=%d RO=%d IS=%d C=%d T=%d\n",
383
cfg->n[INTEL_L3P_SLM], cfg->n[INTEL_L3P_URB], cfg->n[INTEL_L3P_ALL],
384
cfg->n[INTEL_L3P_DC], cfg->n[INTEL_L3P_RO],
385
cfg->n[INTEL_L3P_IS], cfg->n[INTEL_L3P_C], cfg->n[INTEL_L3P_T]);