aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/generic/files/crypto/ocf/kirkwood/mvHal/mv_hal/cpu/mvCpuL2Cntrs.c
blob: 033386224ffde52a463522ebc3f277113af5df97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "mvOs.h"
#include "mvCpuL2Cntrs.h"



MV_CPU_L2_CNTRS_ENTRY   mvCpuL2CntrsTbl[MV_CPU_L2_CNTRS_NUM];

MV_CPU_L2_CNTRS_EVENT*  mvCpuL2CntrsEventTbl[128];

void mvCpuL2CntrsReset(void)
{
    MV_U32 reg = 0;
   
    MV_ASM ("mcr p15, 6, %0, c15, c13, 0" : : "r" (reg));
    MV_ASM ("mcr p15, 6, %0, c15, c13, 1" : : "r" (reg));
    MV_ASM ("mcr p15, 6, %0, c15, c13, 2" : : "r" (reg));
    MV_ASM ("mcr p15, 6, %0, c15, c13, 3" : : "r" (reg));
}
               
static void mvCpuL2CntrConfig(int counter, int op)
{
    MV_U32 reg =  (1 << op) | 0x1; /*enable*/

    switch(counter)
    {
        case 0:
         MV_ASM ("mcr p15, 6, %0, c15, c12, 0" : : "r" (reg));
         return;

        case 1:
         MV_ASM ("mcr p15, 6, %0, c15, c12, 1" : : "r" (reg));
         return;

        default:
            mvOsPrintf("mvCpuL2CntrConfig: bad counter number (%d)\n", counter);
    }
    return;
}

void mvCpuL2CntrsEventClear(MV_CPU_L2_CNTRS_EVENT* pEvent)
{
    int i;

    for(i=0; i<MV_CPU_L2_CNTRS_NUM; i++)
    {
        pEvent->counters_sum[i] = 0;
    }
    pEvent->num_of_measurements = 0;
}

                                                                                                              
MV_CPU_L2_CNTRS_EVENT* mvCpuL2CntrsEventCreate(char* name, MV_U32 print_threshold)
{
    int                     i;
    MV_CPU_L2_CNTRS_EVENT*  event = mvOsMalloc(sizeof(MV_CPU_L2_CNTRS_EVENT));

    if(event)
    {
        strncpy(event->name, name, sizeof(event->name));
        event->num_of_measurements = 0;
        event->avg_sample_count = print_threshold;
        for(i=0; i<MV_CPU_L2_CNTRS_NUM; i++)
        {
            event->counters_before[i] = 0;
            event->counters_after[i] = 0;
            event->counters_sum[i] = 0;
        }
    }
    return event;
}

void    mvCpuL2CntrsEventDelete(MV_CPU_L2_CNTRS_EVENT* event)
{
    if(event != NULL)
        mvOsFree(event);
}

                                                                                     
MV_STATUS   mvCpuL2CntrsProgram(int counter, MV_CPU_L2_CNTRS_OPS op, 
                                 char* name, MV_U32 overhead)
{
    strncpy(mvCpuL2CntrsTbl[counter].name, name, sizeof(mvCpuL2CntrsTbl[counter].name));
    mvCpuL2CntrsTbl[counter].operation = op;
    mvCpuL2CntrsTbl[counter].opIdx = op;
    mvCpuL2CntrsTbl[counter].overhead = overhead;
    mvCpuL2CntrConfig(counter, op);
    mvOsPrintf("CPU L2 Counter %d: operation=%d, overhead=%d\n",
                        counter, op, overhead);
    return MV_OK;
}

void    mvCpuL2CntrsShow(MV_CPU_L2_CNTRS_EVENT* pEvent)
{
    int     i;
    MV_U64  counters_avg;

    if(pEvent->num_of_measurements < pEvent->avg_sample_count) 
        return;

    mvOsPrintf("%16s: ", pEvent->name);
    for(i=0; i<MV_CPU_L2_CNTRS_NUM; i++)
    {
        counters_avg = mvOsDivMod64(pEvent->counters_sum[i], 
                                    pEvent->num_of_measurements, NULL);

        if(counters_avg >= mvCpuL2CntrsTbl[i].overhead)
            counters_avg -= mvCpuL2CntrsTbl[i].overhead;
        else
            counters_avg = 0;

        mvOsPrintf("%s=%5llu, ", mvCpuL2CntrsTbl[i].name, counters_avg);
    }
    mvOsPrintf("\n");
    mvCpuL2CntrsEventClear(pEvent);
    mvCpuL2CntrsReset();
}

void    mvCpuL2CntrsStatus(void)
{
    int i;

    for(i=0; i<MV_CPU_L2_CNTRS_NUM; i++)
    {
        mvOsPrintf("#%d: %s, overhead=%d\n", 
            i, mvCpuL2CntrsTbl[i].name, mvCpuL2CntrsTbl[i].overhead);
    }
}