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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
|
/*
* Performance Profiling routines
*
* $Id: romeperf.c,v 1.1 2009/11/06 12:26:48 victoryman Exp $
*
* Copyright (c) 2009 Realtek Semiconductor Corp.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include "8192cd_cfg.h"
#ifdef PERF_DUMP
#include "romeperf.h"
//#include <asm/rtl865x/rtl_glue.h>
#define KERNEL_SYSeALLS
#include <asm/unistd.h>
#include <asm/processor.h>
#include <asm/uaccess.h>
#include <asm/rlxregs.h>
#ifdef CONFIG_WIRELESS_LAN_MODULE
#define __IRAM
#else
#define __IRAM __attribute__ ((section(".iram-gen")))
#endif
#define rtlglue_malloc(size) kmalloc(size, 0x1f0)
#define rtlglue_free(p) kfree(p)
#define rtlglue_printf panic_printk
enum CP3_COUNTER
{
CP3CNT_CYCLES = 0,
CP3CNT_NEW_INST_FECTH,
CP3CNT_NEW_INST_FETCH_CACHE_MISS,
CP3CNT_NEW_INST_MISS_BUSY_CYCLE,
CP3CNT_DATA_STORE_INST,
CP3CNT_DATA_LOAD_INST,
CP3CNT_DATA_LOAD_OR_STORE_INST,
CP3CNT_EXACT_RETIRED_INST,
CP3CNT_RETIRED_INST_FOR_PIPE_A,
CP3CNT_RETIRED_INST_FOR_PIPE_B,
CP3CNT_DATA_LOAD_OR_STORE_CACHE_MISS,
CP3CNT_DATA_LOAD_OR_STORE_MISS_BUSY_CYCLE,
CP3CNT_RESERVED12,
CP3CNT_RESERVED13,
CP3CNT_RESERVED14,
CP3CNT_RESERVED15,
};
/* Local variables */
static uint64 tempVariable64;
static uint32 tempVariable32;
static uint64 currCnt[4];
/* Global variables */
#ifdef CONFIG_WIRELESS_LAN_MODULE
static uint64 cnt1, cnt2;
static rtl8651_romeperf_stat_t romePerfStat[ROMEPERF_INDEX_MAX];
static uint32 rtl8651_romeperf_inited = 0;
static uint32 rtl8651_romeperf_enable = TRUE;
#else
uint64 cnt1, cnt2;
rtl8651_romeperf_stat_t romePerfStat[ROMEPERF_INDEX_MAX];
uint32 rtl8651_romeperf_inited = 0;
uint32 rtl8651_romeperf_enable = TRUE;
#endif
__IRAM void CP3_COUNTER0_INIT( void )
{
__asm__ __volatile__ \
(" ;\
mfc0 $8, $12 ;\
la $9, 0x80000000 ;\
or $8, $9 ;\
mtc0 $8, $12 ;\
");
}
__IRAM uint32 CP3_COUNTER0_IS_INITED( void )
{
__asm__ __volatile__ \
(" ;\
mfc0 $8, $12 ;\
la $9, tempVariable32;\
sw $8, 0($9) ;\
");
return tempVariable32;
}
__IRAM void CP3_COUNTER0_START( void )
{
#if 1 /* Inst */
tempVariable32 = /* Counter0 */((0x10|CP3CNT_CYCLES)<< 0) |
/* Counter1 */((0x10|CP3CNT_NEW_INST_FECTH)<< 8) |
/* Counter2 */((0x10|CP3CNT_NEW_INST_FETCH_CACHE_MISS)<<16) |
/* Counter3 */((0x10|CP3CNT_NEW_INST_MISS_BUSY_CYCLE)<<24);
#elif 1 /* Data (LOAD+STORE) */
tempVariable32 = /* Counter0 */((0x10|CP3CNT_CYCLES)<< 0) |
/* Counter1 */((0x10|CP3CNT_DATA_LOAD_OR_STORE_INST)<< 8) |
/* Counter2 */((0x10|CP3CNT_DATA_LOAD_OR_STORE_CACHE_MISS)<<16) |
/* Counter3 */((0x10|CP3CNT_DATA_LOAD_OR_STORE_MISS_BUSY_CYCLE)<<24);
#elif 1 /* Data (STORE) */
tempVariable32 = /* Counter0 */((0x10|CP3CNT_DATA_LOAD_INST)<< 0) |
/* Counter1 */((0x10|CP3CNT_DATA_STORE_INST)<< 8) |
/* Counter2 */((0x10|CP3CNT_DATA_LOAD_OR_STORE_CACHE_MISS)<<16) |
/* Counter3 */((0x10|CP3CNT_DATA_LOAD_OR_STORE_MISS_BUSY_CYCLE)<<24);
#else
#error
#endif
__asm__ __volatile__ \
(" ;\
la $8, tempVariable32 ;\
lw $8, 0($8) ;\
ctc3 $8, $0 ;\
");
}
__IRAM void CP3_COUNTER0_STOP( void )
{
__asm__ __volatile__ \
(" ;\
ctc3 $0, $0 ;\
");
}
__IRAM uint64 CP3_COUNTER0_GET( void )
{
__asm__ __volatile__ \
(" ;\
la $8, tempVariable64;\
mfc3 $9, $9 ;\
sw $9, 0($8) ;\
mfc3 $9, $8 ;\
sw $9, 4($8) ;\
");
return tempVariable64;
}
__IRAM void CP3_COUNTER0_GET_ALL( void )
{
__asm__ __volatile__ \
(" ;\
la $4, currCnt ;\
mfc3 $9, $9 ;\
sw $9, 0x00($4) ;\
mfc3 $9, $8 ;\
sw $9, 0x04($4) ;\
mfc3 $9, $11 ;\
sw $9, 0x08($4) ;\
mfc3 $9, $10 ;\
sw $9, 0x0C($4) ;\
mfc3 $9, $13 ;\
sw $9, 0x10($4) ;\
mfc3 $9, $12 ;\
sw $9, 0x14($4) ;\
mfc3 $9, $15 ;\
sw $9, 0x18($4) ;\
mfc3 $9, $14 ;\
sw $9, 0x1C($4) ;\
");
}
int32 rtl8651_romeperfInit()
{
CP3_COUNTER0_INIT();
CP3_COUNTER0_START();
rtl8651_romeperf_inited = TRUE;
rtl8651_romeperf_enable = TRUE;
memset( &romePerfStat, 0, sizeof( romePerfStat ) );
romePerfStat[ROMEPERF_INDEX_NAPT_ADD].desc = "NAPT add_all";
romePerfStat[ROMEPERF_INDEX_NAPT_ADD_1].desc = "NAPT add_checkIntIP";
romePerfStat[ROMEPERF_INDEX_NAPT_ADD_2].desc = "NAPT add_localServer";
romePerfStat[ROMEPERF_INDEX_NAPT_ADD_3].desc = "NAPT add_checkExtIp";
romePerfStat[ROMEPERF_INDEX_NAPT_ADD_4].desc = "NAPT add_dupCheck1";
romePerfStat[ROMEPERF_INDEX_NAPT_ADD_5].desc = "NAPT add_dupCheck2";
romePerfStat[ROMEPERF_INDEX_NAPT_ADD_6].desc = "NAPT add_bPortReused";
romePerfStat[ROMEPERF_INDEX_NAPT_ADD_7].desc = "NAPT add_routeCache";
romePerfStat[ROMEPERF_INDEX_NAPT_ADD_8].desc = "NAPT add_tooManyConn";
romePerfStat[ROMEPERF_INDEX_NAPT_ADD_9].desc = "NAPT add_initConn";
romePerfStat[ROMEPERF_INDEX_NAPT_ADD_10].desc = "NAPT add_decisionFlo";
romePerfStat[ROMEPERF_INDEX_NAPT_ADD_11].desc = "NAPT add_ambiguous";
romePerfStat[ROMEPERF_INDEX_NAPT_DEL].desc = "NAPT del";
romePerfStat[ROMEPERF_INDEX_NAPT_FIND_OUTBOUND].desc = "NATP outbound";
romePerfStat[ROMEPERF_INDEX_NAPT_FIND_INBOUND].desc = "NAPT inbound";
romePerfStat[ROMEPERF_INDEX_NAPT_UPDATE].desc = "NAPT update";
romePerfStat[ROMEPERF_INDEX_UNTIL_RXTHREAD].desc = "IntDispatch-RxThread";
romePerfStat[ROMEPERF_INDEX_RECVLOOP].desc = "RecvLoop-FwdInput";
romePerfStat[ROMEPERF_INDEX_FWDENG_INPUT].desc = "FwdEng_Input()";
romePerfStat[ROMEPERF_INDEX_BEFORE_CRYPTO_ENCAP].desc = "FwdInput-Crypto(En)";
romePerfStat[ROMEPERF_INDEX_ENCAP].desc = "IPSEC Encap";
romePerfStat[ROMEPERF_INDEX_ENCAP_CRYPTO_ENGINE].desc = "Encap Crypto";
romePerfStat[ROMEPERF_INDEX_ENCAP_AUTH_ENGINE].desc = "Encap Authtication";
romePerfStat[ROMEPERF_INDEX_BEFORE_CRYPTO_DECAP].desc = "FwdInput-Crypto(De)";
romePerfStat[ROMEPERF_INDEX_DECAP].desc = "IPSEC Decap";
romePerfStat[ROMEPERF_INDEX_DECAP_CRYPTO_ENGINE].desc = "Decap Crypto";
romePerfStat[ROMEPERF_INDEX_DECAP_AUTH_ENGINE].desc = "Decap Authtication";
romePerfStat[ROMEPERF_INDEX_FASTPATH].desc = "Fast Path";
romePerfStat[ROMEPERF_INDEX_SLOWPATH].desc = "Slow Path";
romePerfStat[ROMEPERF_INDEX_FWDENG_SEND].desc = "FwdEngSend()";
romePerfStat[ROMEPERF_INDEX_UNTIL_ACLDB].desc = "FwdInput() Until ACLDB";
romePerfStat[ROMEPERF_INDEX_GET_MTU_AND_SOURCE_MAC].desc = "L3Route_MTU_srcMAC";
romePerfStat[ROMEPERF_INDEX_PPTPL2TP_1].desc = "L3Route_PPTPL2TP_1";
romePerfStat[ROMEPERF_INDEX_PPPOE_ARP_CACHE].desc = "L3Route_PPPoE_ArpCache";
romePerfStat[ROMEPERF_INDEX_PPTPL2TP_SEND].desc = "L3Route_PptpL2tpSend()";
romePerfStat[ROMEPERF_INDEX_FRAG].desc = "L3Route_Fragment";
romePerfStat[ROMEPERF_INDEX_EGRESS_ACL].desc = "FwdSend_EgressACL";
romePerfStat[ROMEPERF_INDEX_PPTPL2TP_ENCAP].desc = "FwdSend_PPTP/L2TP_Encap";
romePerfStat[ROMEPERF_INDEX_FROM_PS].desc = "FwdSend_FromPS";
romePerfStat[ROMEPERF_INDEX_EXTDEV_SEND].desc = "FwdSend_ExtDevSend()";
romePerfStat[ROMEPERF_INDEX_FRAG_2ND_HALF].desc = "FwdSend_Frag_2ndHalf()";
romePerfStat[ROMEPERF_INDEX_TXPKTPOST].desc = "rtl8651_txPktPostProcessing()";
romePerfStat[ROMEPERF_INDEX_MBUFPAD].desc = "mBuf_padding()";
romePerfStat[ROMEPERF_INDEX_TXALIGN].desc = "_swNic_txAlign";
romePerfStat[ROMEPERF_INDEX_ISRTXRECYCLE].desc = "_swNic_isrTxRecycle";
romePerfStat[ROMEPERF_INDEX_16].desc = "FwdEng_temp_16";
romePerfStat[ROMEPERF_INDEX_17].desc = "FwdEng_temp_17";
romePerfStat[ROMEPERF_INDEX_18].desc = "FwdEng_temp_18";
romePerfStat[ROMEPERF_INDEX_19].desc = "FwdEng_temp_19";
romePerfStat[ROMEPERF_INDEX_20].desc = "FwdEng_temp_20";
romePerfStat[ROMEPERF_INDEX_21].desc = "FwdEng_temp_21";
romePerfStat[ROMEPERF_INDEX_22].desc = "FwdEng_temp_22";
romePerfStat[ROMEPERF_INDEX_23].desc = "FwdEng_temp_23";
romePerfStat[ROMEPERF_INDEX_24].desc = "FwdEng_temp_24";
romePerfStat[ROMEPERF_INDEX_25].desc = "FwdEng_temp_25";
romePerfStat[ROMEPERF_INDEX_FLUSHDCACHE].desc = "rtlglue_flushDCache";
romePerfStat[ROMEPERF_INDEX_IRAM_1].desc = "IRAM Cached within IRAM";
romePerfStat[ROMEPERF_INDEX_IRAM_2].desc = "IRAM Uncached within IRAM";
romePerfStat[ROMEPERF_INDEX_IRAM_3].desc = "test ICACHE (1024*100)";
romePerfStat[ROMEPERF_INDEX_IRAM_4].desc = "test Uncached (1024*10)";
romePerfStat[ROMEPERF_INDEX_DRAM_1].desc = "DRAM Cached within DRAM";
romePerfStat[ROMEPERF_INDEX_DRAM_2].desc = "DRAM Uncached within DRAM";
romePerfStat[ROMEPERF_INDEX_DRAM_3].desc = "test DCACHE (1024*100)";
romePerfStat[ROMEPERF_INDEX_DRAM_4].desc = "test Uncached (1024*10)";
romePerfStat[ROMEPERF_INDEX_BMP].desc = "KMP Algorithm";
romePerfStat[ROMEPERF_INDEX_MDCMDIO].desc = "MDCMDIO PHY Register ACCESS";
return SUCCESS;
}
int32 rtl8651_romeperfReset()
{
rtl8651_romeperfInit();
return SUCCESS;
}
#if 0/* old fashion function, for reference only. */
int32 rtl8651_romeperfStart()
{
if ( rtl8651_romeperf_inited == FALSE ) rtl8651_romeperfInit();
START_AND_GET_CP3_COUNTER0( cnt1 );
return SUCCESS;
}
int32 rtl8651_romeperfStop( uint64 *pDiff )
{
if ( rtl8651_romeperf_inited == FALSE ) rtl8651_romeperfInit();
STOP_AND_GET_CP3_COUNTER0( cnt2 );
*pDiff = cnt2 - cnt1;
return SUCCESS;
}
#endif
int32 rtl8651_romeperfGet( uint64 *pGet )
{
if ( rtl8651_romeperf_inited == FALSE ) return FAILED;
/* Louis patch: someone will disable CP3 in somewhere. */
CP3_COUNTER0_INIT();
CP3_COUNTER0_STOP();
*pGet = CP3_COUNTER0_GET();
CP3_COUNTER0_START();
return SUCCESS;
}
int32 rtl8651_romeperfPause( void )
{
if ( rtl8651_romeperf_inited == FALSE ) return FAILED;
rtl8651_romeperf_enable = FALSE;
/* Louis patch: someone will disable CP3 in somewhere. */
CP3_COUNTER0_INIT();
CP3_COUNTER0_STOP();
return SUCCESS;
}
int32 rtl8651_romeperfResume( void )
{
if ( rtl8651_romeperf_inited == FALSE ) return FAILED;
rtl8651_romeperf_enable = TRUE;
/* Louis patch: someone will disable CP3 in somewhere. */
CP3_COUNTER0_INIT();
CP3_COUNTER0_START();
return SUCCESS;
}
__IRAM int32 rtl8651_romeperfEnterPoint( uint32 index )
{
if ( rtl8651_romeperf_inited == FALSE ||
rtl8651_romeperf_enable == FALSE ) return FAILED;
if ( index >= (sizeof(romePerfStat)/sizeof(rtl8651_romeperf_stat_t)) )
return FAILED;
/* Louis patch: someone will disable CP3 in somewhere. */
CP3_COUNTER0_INIT();
CP3_COUNTER0_STOP();
CP3_COUNTER0_GET_ALL();
romePerfStat[index].tempCycle[0] = currCnt[0];
romePerfStat[index].tempCycle[1] = currCnt[1];
romePerfStat[index].tempCycle[2] = currCnt[2];
romePerfStat[index].tempCycle[3] = currCnt[3];
romePerfStat[index].hasTempCycle = TRUE;
CP3_COUNTER0_START();
return SUCCESS;
}
__IRAM int32 rtl8651_romeperfExitPoint( uint32 index )
{
if ( rtl8651_romeperf_inited == FALSE ||
rtl8651_romeperf_enable == FALSE ) return FAILED;
if ( index >= (sizeof(romePerfStat)/sizeof(rtl8651_romeperf_stat_t)) )
return FAILED;
if ( romePerfStat[index].hasTempCycle == FALSE )
return FAILED;
/* Louis patch: someone will disable CP3 in somewhere. */
CP3_COUNTER0_INIT();
CP3_COUNTER0_STOP();
CP3_COUNTER0_GET_ALL();
romePerfStat[index].accCycle[0] += currCnt[0]-romePerfStat[index].tempCycle[0];
romePerfStat[index].accCycle[1] += currCnt[1]-romePerfStat[index].tempCycle[1];
romePerfStat[index].accCycle[2] += currCnt[2]-romePerfStat[index].tempCycle[2];
romePerfStat[index].accCycle[3] += currCnt[3]-romePerfStat[index].tempCycle[3];
romePerfStat[index].hasTempCycle = FALSE;
romePerfStat[index].executedNum++;
CP3_COUNTER0_START();
return SUCCESS;
}
int32 rtl8651_romeperfDump( int start, int end )
{
#if 0
int i;
rtlglue_printf( "index %30s %12s %8s %10s\n", "description", "accCycle", "totalNum", "Average" );
for( i = start; i <= end; i++ )
{
if ( romePerfStat[i].executedNum == 0 )
{
rtlglue_printf( "[%3d] %30s %12s %8s %10s\n", i, romePerfStat[i].desc, "--", "--", "--" );
}
else
{
int j;
rtlglue_printf( "[%3d] %30s ",
i, romePerfStat[i].desc );
for( j =0; j < sizeof(romePerfStat[i].accCycle)/sizeof(romePerfStat[i].accCycle[0]);
j++ )
{
uint32 *pAccCycle = (uint32*)&romePerfStat[i].accCycle[j];
uint32 avrgCycle = /* Hi-word */ (pAccCycle[0]*(0xffffffff/romePerfStat[i].executedNum)) +
/* Low-word */(pAccCycle[1]/romePerfStat[i].executedNum);
rtlglue_printf( "%12llu %8u %10u\n",
romePerfStat[i].accCycle[j],
romePerfStat[i].executedNum,
avrgCycle
);
rtlglue_printf( " %3s %30s ", "", "" );
}
rtlglue_printf( "\r" );
}
}
return SUCCESS;
#else
int i;
rtl8651_romeperf_stat_t* statSnapShot = rtlglue_malloc(sizeof(rtl8651_romeperf_stat_t) * (end - start + 1) );
if( statSnapShot == NULL )
{
rtlglue_printf("statSnapShot mem alloc failed\n");
return FAILED;
}
rtlglue_printf( "index %30s %12s %8s %10s\n", "description", "accCycle", "totalNum", "Average" );
for( i = start; i <= end; i++ )
{
int j;
for( j =0; j < sizeof(romePerfStat[i].accCycle)/sizeof(romePerfStat[i].accCycle[0]); j++ )
{
statSnapShot[i].accCycle[j] = romePerfStat[i].accCycle[j];
statSnapShot[i].tempCycle[j] = romePerfStat[i].tempCycle[j];
}
statSnapShot[i].executedNum = romePerfStat[i].executedNum;
statSnapShot[i].hasTempCycle = romePerfStat[i].hasTempCycle;
}
for( i = start; i <= end; i++ )
{
if ( statSnapShot[i].executedNum == 0 )
{
rtlglue_printf( "[%3d] %30s %12s %8s %10s\n", i, romePerfStat[i].desc, "--", "--", "--" );
}
else
{
int j;
rtlglue_printf( "[%3d] %30s ", i, romePerfStat[i].desc );
for( j =0; j < sizeof(statSnapShot[i].accCycle)/sizeof(statSnapShot[i].accCycle[0]); j++ )
{
uint32 *pAccCycle = (uint32*)&statSnapShot[i].accCycle[j];
uint32 avrgCycle = /* Hi-word */ (pAccCycle[0]*(0xffffffff/statSnapShot[i].executedNum)) +
/* Low-word */(pAccCycle[1]/statSnapShot[i].executedNum);
rtlglue_printf( "%12llu %8u %10u\n",
statSnapShot[i].accCycle[j],
statSnapShot[i].executedNum,
avrgCycle );
rtlglue_printf( " %3s %30s ", "", "" );
}
rtlglue_printf( "\r" );
}
}
rtlglue_free(statSnapShot);
return SUCCESS;
#endif
}
#endif // PERF_DUMP
|