2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #include "mvCpuL2Cntrs.h"
22 MV_CPU_L2_CNTRS_ENTRY mvCpuL2CntrsTbl[MV_CPU_L2_CNTRS_NUM];
24 MV_CPU_L2_CNTRS_EVENT* mvCpuL2CntrsEventTbl[128];
26 void mvCpuL2CntrsReset(void)
30 MV_ASM ("mcr p15, 6, %0, c15, c13, 0" : : "r" (reg));
31 MV_ASM ("mcr p15, 6, %0, c15, c13, 1" : : "r" (reg));
32 MV_ASM ("mcr p15, 6, %0, c15, c13, 2" : : "r" (reg));
33 MV_ASM ("mcr p15, 6, %0, c15, c13, 3" : : "r" (reg));
36 static void mvCpuL2CntrConfig(int counter, int op)
38 MV_U32 reg = (1 << op) | 0x1; /*enable*/
43 MV_ASM ("mcr p15, 6, %0, c15, c12, 0" : : "r" (reg));
47 MV_ASM ("mcr p15, 6, %0, c15, c12, 1" : : "r" (reg));
51 mvOsPrintf("mvCpuL2CntrConfig: bad counter number (%d)\n", counter);
56 void mvCpuL2CntrsEventClear(MV_CPU_L2_CNTRS_EVENT* pEvent)
60 for(i=0; i<MV_CPU_L2_CNTRS_NUM; i++)
62 pEvent->counters_sum[i] = 0;
64 pEvent->num_of_measurements = 0;
68 MV_CPU_L2_CNTRS_EVENT* mvCpuL2CntrsEventCreate(char* name, MV_U32 print_threshold)
71 MV_CPU_L2_CNTRS_EVENT* event = mvOsMalloc(sizeof(MV_CPU_L2_CNTRS_EVENT));
75 strncpy(event->name, name, sizeof(event->name));
76 event->num_of_measurements = 0;
77 event->avg_sample_count = print_threshold;
78 for(i=0; i<MV_CPU_L2_CNTRS_NUM; i++)
80 event->counters_before[i] = 0;
81 event->counters_after[i] = 0;
82 event->counters_sum[i] = 0;
88 void mvCpuL2CntrsEventDelete(MV_CPU_L2_CNTRS_EVENT* event)
95 MV_STATUS mvCpuL2CntrsProgram(int counter, MV_CPU_L2_CNTRS_OPS op,
96 char* name, MV_U32 overhead)
98 strncpy(mvCpuL2CntrsTbl[counter].name, name, sizeof(mvCpuL2CntrsTbl[counter].name));
99 mvCpuL2CntrsTbl[counter].operation = op;
100 mvCpuL2CntrsTbl[counter].opIdx = op;
101 mvCpuL2CntrsTbl[counter].overhead = overhead;
102 mvCpuL2CntrConfig(counter, op);
103 mvOsPrintf("CPU L2 Counter %d: operation=%d, overhead=%d\n",
104 counter, op, overhead);
108 void mvCpuL2CntrsShow(MV_CPU_L2_CNTRS_EVENT* pEvent)
113 if(pEvent->num_of_measurements < pEvent->avg_sample_count)
116 mvOsPrintf("%16s: ", pEvent->name);
117 for(i=0; i<MV_CPU_L2_CNTRS_NUM; i++)
119 counters_avg = mvOsDivMod64(pEvent->counters_sum[i],
120 pEvent->num_of_measurements, NULL);
122 if(counters_avg >= mvCpuL2CntrsTbl[i].overhead)
123 counters_avg -= mvCpuL2CntrsTbl[i].overhead;
127 mvOsPrintf("%s=%5llu, ", mvCpuL2CntrsTbl[i].name, counters_avg);
130 mvCpuL2CntrsEventClear(pEvent);
134 void mvCpuL2CntrsStatus(void)
138 for(i=0; i<MV_CPU_L2_CNTRS_NUM; i++)
140 mvOsPrintf("#%d: %s, overhead=%d\n",
141 i, mvCpuL2CntrsTbl[i].name, mvCpuL2CntrsTbl[i].overhead);