Path: blob/21.2-virgl/src/intel/common/intel_l3_config.c
4547 views
/*1* Copyright (c) 2015 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include <stdlib.h>24#include <math.h>2526#include "util/macros.h"27#include "main/macros.h"2829#include "intel_l3_config.h"3031struct intel_l3_list {32const struct intel_l3_config *configs;33int length;34};3536#define DECLARE_L3_LIST(hw) \37struct intel_l3_list hw##_l3_list = \38{ .configs = hw##_l3_configs, .length = ARRAY_SIZE(hw##_l3_configs) }3940/**41* IVB/HSW validated L3 configurations. The first entry will be used as42* default by gfx7_restore_default_l3_config(), otherwise the ordering is43* unimportant.44*/45static 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 }},61};62DECLARE_L3_LIST(ivb);6364/**65* VLV validated L3 configurations. \sa ivb_l3_configs.66*/67static 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 }},77};78DECLARE_L3_LIST(vlv);7980/**81* BDW validated L3 configurations. \sa ivb_l3_configs.82*/83static 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 }},93};94DECLARE_L3_LIST(bdw);9596/**97* CHV/SKL validated L3 configurations. \sa ivb_l3_configs.98*/99static 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 }},109};110DECLARE_L3_LIST(chv);111112/**113* BXT 2x6 validated L3 configurations. \sa ivb_l3_configs.114*/115static 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 }},123};124DECLARE_L3_LIST(bxt_2x6);125126/**127* ICL validated L3 configurations. \sa icl_l3_configs.128* Zeroth entry in below table has been commented out intentionally129* due to known issues with this configuration. Many other entries130* suggested by h/w specification aren't added here because they131* do under allocation of L3 cache with below partitioning.132*/133static 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 }},137};138DECLARE_L3_LIST(icl);139140/**141* TGL validated L3 configurations. \sa tgl_l3_configs.142*/143static 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 }},147};148DECLARE_L3_LIST(tgl);149150/**151* DG1 validated L3 configurations. \sa dg1_l3_configs.152*/153static const struct intel_l3_config dg1_l3_configs[] = {154/* No configurations. L3FullWayAllocationEnable is always set. */155};156DECLARE_L3_LIST(dg1);157158/**159* Return a zero-terminated array of validated L3 configurations for the160* specified device.161*/162static const struct intel_l3_list *163get_l3_list(const struct intel_device_info *devinfo)164{165switch (devinfo->ver) {166case 7:167return (devinfo->is_baytrail ? &vlv_l3_list : &ivb_l3_list);168169case 8:170return (devinfo->is_cherryview ? &chv_l3_list : &bdw_l3_list);171172case 9:173if (devinfo->l3_banks == 1)174return &bxt_2x6_l3_list;175return &chv_l3_list;176177case 11:178return &icl_l3_list;179180case 12:181if (devinfo->is_dg1)182return &dg1_l3_list;183else184return &tgl_l3_list;185186default:187unreachable("Not implemented");188}189}190191/**192* L1-normalize a vector of L3 partition weights.193*/194static struct intel_l3_weights195norm_l3_weights(struct intel_l3_weights w)196{197float sz = 0;198199for (unsigned i = 0; i < INTEL_NUM_L3P; i++)200sz += w.w[i];201202for (unsigned i = 0; i < INTEL_NUM_L3P; i++)203w.w[i] /= sz;204205return w;206}207208/**209* Get the relative partition weights of the specified L3 configuration.210*/211struct intel_l3_weights212intel_get_l3_config_weights(const struct intel_l3_config *cfg)213{214if (cfg) {215struct intel_l3_weights w;216217for (unsigned i = 0; i < INTEL_NUM_L3P; i++)218w.w[i] = cfg->n[i];219220return norm_l3_weights(w);221} else {222const struct intel_l3_weights w = { { 0 } };223return w;224}225}226227/**228* Distance between two L3 configurations represented as vectors of weights.229* Usually just the L1 metric except when the two configurations are230* considered incompatible in which case the distance will be infinite. Note231* that the compatibility condition is asymmetric -- They will be considered232* incompatible whenever the reference configuration \p w0 requires SLM, DC,233* or URB but \p w1 doesn't provide it.234*/235float236intel_diff_l3_weights(struct intel_l3_weights w0, struct intel_l3_weights w1)237{238if ((w0.w[INTEL_L3P_SLM] && !w1.w[INTEL_L3P_SLM]) ||239(w0.w[INTEL_L3P_DC] && !w1.w[INTEL_L3P_DC] && !w1.w[INTEL_L3P_ALL]) ||240(w0.w[INTEL_L3P_URB] && !w1.w[INTEL_L3P_URB])) {241return HUGE_VALF;242243} else {244float dw = 0;245246for (unsigned i = 0; i < INTEL_NUM_L3P; i++)247dw += fabsf(w0.w[i] - w1.w[i]);248249return dw;250}251}252253/**254* Return a reasonable default L3 configuration for the specified device based255* on whether SLM and DC are required. In the non-SLM non-DC case the result256* is intended to approximately resemble the hardware defaults.257*/258struct intel_l3_weights259intel_get_default_l3_weights(const struct intel_device_info *devinfo,260bool needs_dc, bool needs_slm)261{262struct intel_l3_weights w = {{ 0 }};263264w.w[INTEL_L3P_SLM] = devinfo->ver < 11 && needs_slm;265w.w[INTEL_L3P_URB] = 1.0;266267if (devinfo->ver >= 8) {268w.w[INTEL_L3P_ALL] = 1.0;269} else {270w.w[INTEL_L3P_DC] = needs_dc ? 0.1 : 0;271w.w[INTEL_L3P_RO] = devinfo->is_baytrail ? 0.5 : 1.0;272}273274return norm_l3_weights(w);275}276277/**278* Get the default L3 configuration279*/280const struct intel_l3_config *281intel_get_default_l3_config(const struct intel_device_info *devinfo)282{283/* For efficiency assume that the first entry of the array matches the284* default configuration.285*/286const struct intel_l3_list *const list = get_l3_list(devinfo);287assert(list->length > 0 || devinfo->ver >= 12);288if (list->length > 0) {289const struct intel_l3_config *const cfg = &list->configs[0];290assert(cfg == intel_get_l3_config(devinfo,291intel_get_default_l3_weights(devinfo, false, false)));292return cfg;293} else {294return NULL;295}296}297298/**299* Return the closest validated L3 configuration for the specified device and300* weight vector.301*/302const struct intel_l3_config *303intel_get_l3_config(const struct intel_device_info *devinfo,304struct intel_l3_weights w0)305{306const struct intel_l3_list *const list = get_l3_list(devinfo);307const struct intel_l3_config *const cfgs = list->configs;308const struct intel_l3_config *cfg_best = NULL;309float dw_best = HUGE_VALF;310311for (int i = 0; i < list->length; i++) {312const struct intel_l3_config *cfg = &cfgs[i];313const float dw = intel_diff_l3_weights(w0, intel_get_l3_config_weights(cfg));314315if (dw < dw_best) {316cfg_best = cfg;317dw_best = dw;318}319}320321assert(cfg_best || devinfo->ver >= 12);322return cfg_best;323}324325/**326* Return the size of an L3 way in KB.327*/328static unsigned329get_l3_way_size(const struct intel_device_info *devinfo)330{331const unsigned way_size_per_bank =332(devinfo->ver >= 9 && devinfo->l3_banks == 1) || devinfo->ver >= 11 ?3334 : 2;334335assert(devinfo->l3_banks);336return way_size_per_bank * devinfo->l3_banks;337}338339/**340* Return the unit brw_context::urb::size is expressed in, in KB. \sa341* intel_device_info::urb::size.342*/343static unsigned344get_urb_size_scale(const struct intel_device_info *devinfo)345{346return (devinfo->ver >= 8 ? devinfo->num_slices : 1);347}348349unsigned350intel_get_l3_config_urb_size(const struct intel_device_info *devinfo,351const struct intel_l3_config *cfg)352{353/* We don't have to program the URB size in DG1, it's a fixed value. */354if (devinfo->is_dg1)355return devinfo->urb.size;356357/* From the SKL "L3 Allocation and Programming" documentation:358*359* "URB is limited to 1008KB due to programming restrictions. This is not360* a restriction of the L3 implementation, but of the FF and other clients.361* Therefore, in a GT4 implementation it is possible for the programmed362* allocation of the L3 data array to provide 3*384KB=1152KB for URB, but363* only 1008KB of this will be used."364*/365const unsigned max = (devinfo->ver == 9 ? 1008 : ~0);366return MIN2(max, cfg->n[INTEL_L3P_URB] * get_l3_way_size(devinfo)) /367get_urb_size_scale(devinfo);368}369370/**371* Print out the specified L3 configuration.372*/373void374intel_dump_l3_config(const struct intel_l3_config *cfg, FILE *fp)375{376fprintf(stderr, "SLM=%d URB=%d ALL=%d DC=%d RO=%d IS=%d C=%d T=%d\n",377cfg->n[INTEL_L3P_SLM], cfg->n[INTEL_L3P_URB], cfg->n[INTEL_L3P_ALL],378cfg->n[INTEL_L3P_DC], cfg->n[INTEL_L3P_RO],379cfg->n[INTEL_L3P_IS], cfg->n[INTEL_L3P_C], cfg->n[INTEL_L3P_T]);380}381382383