1 | /** @file
|
---|
2 | SMM MP perf-logging implementation
|
---|
3 |
|
---|
4 | Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
|
---|
5 |
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #include "PiSmmCpuDxeSmm.h"
|
---|
11 |
|
---|
12 | #define SMM_MP_PERF_PROCEDURE_NAME(procedure) # procedure
|
---|
13 | GLOBAL_REMOVE_IF_UNREFERENCED
|
---|
14 | CHAR8 *gSmmMpPerfProcedureName[] = {
|
---|
15 | SMM_MP_PERF_PROCEDURE_LIST (SMM_MP_PERF_PROCEDURE_NAME)
|
---|
16 | };
|
---|
17 | //
|
---|
18 | // Each element holds the performance data for one processor.
|
---|
19 | //
|
---|
20 | GLOBAL_REMOVE_IF_UNREFERENCED
|
---|
21 | SMM_PERF_AP_PROCEDURE_PERFORMANCE *mSmmMpProcedurePerformance = NULL;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | Initialize the perf-logging feature for APs.
|
---|
25 |
|
---|
26 | @param NumberofCpus Number of processors in the platform.
|
---|
27 | **/
|
---|
28 | VOID
|
---|
29 | InitializeMpPerf (
|
---|
30 | UINTN NumberofCpus
|
---|
31 | )
|
---|
32 | {
|
---|
33 | mSmmMpProcedurePerformance = AllocateZeroPool (NumberofCpus * sizeof (*mSmmMpProcedurePerformance));
|
---|
34 | ASSERT (mSmmMpProcedurePerformance != NULL);
|
---|
35 | }
|
---|
36 |
|
---|
37 | /**
|
---|
38 | Migrate MP performance data to standardized performance database.
|
---|
39 |
|
---|
40 | @param NumberofCpus Number of processors in the platform.
|
---|
41 | @param BspIndex The index of the BSP.
|
---|
42 | **/
|
---|
43 | VOID
|
---|
44 | MigrateMpPerf (
|
---|
45 | UINTN NumberofCpus,
|
---|
46 | UINTN BspIndex
|
---|
47 | )
|
---|
48 | {
|
---|
49 | UINTN CpuIndex;
|
---|
50 | UINTN MpProcecureId;
|
---|
51 |
|
---|
52 | for (CpuIndex = 0; CpuIndex < NumberofCpus; CpuIndex++) {
|
---|
53 | if ((CpuIndex != BspIndex) && !FeaturePcdGet (PcdSmmApPerfLogEnable)) {
|
---|
54 | //
|
---|
55 | // Skip migrating AP performance data if AP perf-logging is disabled.
|
---|
56 | //
|
---|
57 | continue;
|
---|
58 | }
|
---|
59 |
|
---|
60 | for (MpProcecureId = 0; MpProcecureId < SMM_MP_PERF_PROCEDURE_ID (SmmMpProcedureMax); MpProcecureId++) {
|
---|
61 | if (mSmmMpProcedurePerformance[CpuIndex].Begin[MpProcecureId] != 0) {
|
---|
62 | PERF_START (NULL, gSmmMpPerfProcedureName[MpProcecureId], NULL, mSmmMpProcedurePerformance[CpuIndex].Begin[MpProcecureId]);
|
---|
63 | PERF_END (NULL, gSmmMpPerfProcedureName[MpProcecureId], NULL, mSmmMpProcedurePerformance[CpuIndex].End[MpProcecureId]);
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | ZeroMem (mSmmMpProcedurePerformance, NumberofCpus * sizeof (*mSmmMpProcedurePerformance));
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | Save the performance counter value before running the MP procedure.
|
---|
73 |
|
---|
74 | @param CpuIndex The index of the CPU.
|
---|
75 | @param MpProcedureId The ID of the MP procedure.
|
---|
76 | **/
|
---|
77 | VOID
|
---|
78 | MpPerfBegin (
|
---|
79 | IN UINTN CpuIndex,
|
---|
80 | IN UINTN MpProcedureId
|
---|
81 | )
|
---|
82 | {
|
---|
83 | mSmmMpProcedurePerformance[CpuIndex].Begin[MpProcedureId] = GetPerformanceCounter ();
|
---|
84 | }
|
---|
85 |
|
---|
86 | /**
|
---|
87 | Save the performance counter value after running the MP procedure.
|
---|
88 |
|
---|
89 | @param CpuIndex The index of the CPU.
|
---|
90 | @param MpProcedureId The ID of the MP procedure.
|
---|
91 | **/
|
---|
92 | VOID
|
---|
93 | MpPerfEnd (
|
---|
94 | IN UINTN CpuIndex,
|
---|
95 | IN UINTN MpProcedureId
|
---|
96 | )
|
---|
97 | {
|
---|
98 | mSmmMpProcedurePerformance[CpuIndex].End[MpProcedureId] = GetPerformanceCounter ();
|
---|
99 | }
|
---|