xref: /aosp_15_r20/external/gmmlib/Source/GmmLib/ULT/GmmCachePolicyULT.cpp (revision 35ffd701415c9e32e53136d61a677a8d0a8fc4a5)
1 /*==============================================================================
2 Copyright(c) 2017 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 shall be included
12 in all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
21 ============================================================================*/
22 
23 #include "GmmCachePolicyULT.h"
24 
25 using namespace std;
26 
27 /////////////////////////////////////////////////////////////////////////////////////
28 /// Sets up common environment for Cache Policy fixture tests. this is called once per
29 /// test case before executing all tests under resource fixture test case.
30 /// It also calls SetupTestCase from CommonULT to initialize global context and others.
31 ///
32 /////////////////////////////////////////////////////////////////////////////////////
SetUpTestCase()33 void CTestCachePolicy::SetUpTestCase()
34 {
35     GfxPlatform.eProductFamily    = IGFX_BROADWELL;
36     GfxPlatform.eRenderCoreFamily = IGFX_GEN8_CORE;
37     AllocateAdapterInfo();
38 
39     pGfxAdapterInfo->SystemInfo.L3CacheSizeInKb                         = 768;
40     pGfxAdapterInfo->SystemInfo.LLCCacheSizeInKb                        = 2 * 1024;  //2 MB
41     pGfxAdapterInfo->SystemInfo.EdramSizeInKb                           = 64 * 1024; //64 MB
42     const_cast<SKU_FEATURE_TABLE &>(pGfxAdapterInfo->SkuTable).FtrEDram = 1;
43 
44     CommonULT::SetUpTestCase();
45 
46     printf("%s\n", __FUNCTION__);
47 }
48 
49 /////////////////////////////////////////////////////////////////////////////////////
50 /// cleans up once all the tests finish execution.  It also calls TearDownTestCase
51 /// from CommonULT to destroy global context and others.
52 ///
53 /////////////////////////////////////////////////////////////////////////////////////
TearDownTestCase()54 void CTestCachePolicy::TearDownTestCase()
55 {
56     printf("%s\n", __FUNCTION__);
57 
58     CommonULT::TearDownTestCase();
59 }
60 
CheckL3CachePolicy()61 void CTestCachePolicy::CheckL3CachePolicy()
62 {
63     const uint32_t TargetCache_L3_LLC_ELLC = 0x3;
64 
65     // Check Usage MOCS index against MOCS settings
66     for(uint32_t Usage = GMM_RESOURCE_USAGE_UNKNOWN; Usage < GMM_RESOURCE_USAGE_MAX; Usage++)
67     {
68         GMM_CACHE_POLICY_ELEMENT    ClientRequest = pGmmULTClientContext->GetCachePolicyElement((GMM_RESOURCE_USAGE_TYPE)Usage);
69         MEMORY_OBJECT_CONTROL_STATE Mocs          = ClientRequest.MemoryObjectOverride;
70 
71         // Not check WT/WB/UC since that doesn't really matter for L3
72         if(ClientRequest.L3)
73         {
74             EXPECT_EQ(TargetCache_L3_LLC_ELLC, Mocs.Gen8.TargetCache) << "Usage# " << Usage << ": Incorrect L3 target cache setting";
75         }
76     }
77 }
78 
79 
TEST_F(CTestCachePolicy,TestL3CachePolicy)80 TEST_F(CTestCachePolicy, TestL3CachePolicy)
81 {
82     CheckL3CachePolicy();
83 }
84 
85 
CheckLlcEdramCachePolicy()86 void CTestCachePolicy::CheckLlcEdramCachePolicy()
87 {
88     const uint32_t TargetCache_ELLC        = 0;
89     const uint32_t TargetCache_LLC         = 1;
90     const uint32_t TargetCache_LLC_ELLC    = 2;
91     const uint32_t TargetCache_L3_LLC_ELLC = 2;
92 
93     const uint32_t CC_UNCACHED  = 0x1;
94     const uint32_t CC_CACHED_WT = 0x2;
95     const uint32_t CC_CACHED_WB = 0x3;
96 
97     // Check Usage MOCS index against MOCS settings
98     for(uint32_t Usage = GMM_RESOURCE_USAGE_UNKNOWN; Usage < GMM_RESOURCE_USAGE_MAX; Usage++)
99     {
100         GMM_CACHE_POLICY_ELEMENT    ClientRequest = pGmmULTClientContext->GetCachePolicyElement((GMM_RESOURCE_USAGE_TYPE)Usage);
101         MEMORY_OBJECT_CONTROL_STATE Mocs          = ClientRequest.MemoryObjectOverride;
102 
103         // Check for age
104         EXPECT_EQ(ClientRequest.AGE, Mocs.Gen8.Age) << "Usage# " << Usage << ": Incorrect AGE settings";
105 
106         if(ClientRequest.L3)
107         {
108             continue;
109         }
110 
111         if(!ClientRequest.LLC && !ClientRequest.ELLC) // Uncached
112         {
113             EXPECT_EQ(CC_UNCACHED, Mocs.Gen8.CacheControl) << "Usage# " << Usage << ": Incorrect cache control setting";
114         }
115         else
116         {
117             if(ClientRequest.WT) // Write-through
118             {
119                 EXPECT_EQ(CC_CACHED_WT, Mocs.Gen8.CacheControl) << "Usage# " << Usage << ": Incorrect cache control setting";
120             }
121             else // Write-back
122             {
123                 EXPECT_EQ(CC_CACHED_WB, Mocs.Gen8.CacheControl) << "Usage# " << Usage << ": Incorrect cache control setting";
124             }
125 
126             if(ClientRequest.LLC && !ClientRequest.ELLC) // LLC only
127             {
128                 EXPECT_EQ(TargetCache_LLC, Mocs.Gen8.TargetCache) << "Usage# " << Usage << ": Incorrect target cache setting";
129             }
130             else if(!ClientRequest.LLC && ClientRequest.ELLC) // eLLC only
131             {
132                 EXPECT_EQ(TargetCache_ELLC, Mocs.Gen8.TargetCache) << "Usage# " << Usage << ": Incorrect target cache setting";
133             }
134             else if(ClientRequest.LLC && ClientRequest.ELLC)
135             {
136                 EXPECT_EQ(TargetCache_LLC_ELLC, Mocs.Gen8.TargetCache) << "Usage# " << Usage << ": Incorrect target cache setting";
137             }
138         }
139     }
140 }
141 
TEST_F(CTestCachePolicy,TestLlcEdramCachePolicy)142 TEST_F(CTestCachePolicy, TestLlcEdramCachePolicy)
143 {
144     CheckLlcEdramCachePolicy();
145 }
146