1 /*---------------------------------------------------------------------------*
2 Project: OS Library
3 File: OSSync.h
4
5 Copyright (C) Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 *---------------------------------------------------------------------------*/
14
15 #ifndef __OSPERFORMANCE_MONITOR_H__
16 #define __OSPERFORMANCE_MONITOR_H__
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 #define PM_MASK_MMCR0 (1 << 0)
23 #define PM_MASK_MMCR1 (1 << 1)
24 #define PM_MASK_PMC1 (1 << 2)
25 #define PM_MASK_PMC2 (1 << 3)
26 #define PM_MASK_PMC3 (1 << 4)
27 #define PM_MASK_PMC4 (1 << 5)
28 #define PM_MASK_CONTROL (PM_MASK_MMCR0 | PM_MASK_MMCR1)
29 #define PM_MASK_COUNTER (PM_MASK_PMC1 | PM_MASK_PMC2 | PM_MASK_PMC3 | PM_MASK_PMC4)
30 #define PM_MASK_ALL ( PM_MASK_MMCR0 | PM_MASK_MMCR1 | PM_MASK_PMC1 | PM_MASK_PMC2 | PM_MASK_PMC3 | PM_MASK_PMC4)
31
32 #define PM_UPMC1 937
33 #define PM_UPMC2 938
34
35 #define PM_MMCR0_PMC1_SHIFT 6
36 #define PM_MMCR0_PMC2_SHIFT 0
37
38 #define PM_PMC1_ENCODING_CYCLES (1 << PM_MMCR0_PMC1_SHIFT)
39 #define PM_PMC2_ENCODING_INSTRUCTIONS (2 << PM_MMCR0_PMC2_SHIFT)
40
41 void OSSetPerformanceMonitor(u32 pm_mask, u32 mmcr0, u32 mmcr1, u32 pmc1, u32 pmc2, u32 pmc3, u32 pmc4);
42
43 #define PMStartCycleAndInstructionCount() \
44 OSSetPerformanceMonitor(PM_MASK_MMCR0|PM_MASK_PMC1|PM_MASK_PMC2,\
45 PM_PMC1_ENCODING_CYCLES|PM_PMC2_ENCODING_INSTRUCTIONS,\
46 0, 0, 0, 0, 0);
47
48 #define PMStopCycleAndInstructionCount() \
49 OSSetPerformanceMonitor(PM_MASK_MMCR0, 0, 0, 0, 0, 0, 0);
50
51 #define PMResetCycleAndInstructionCount() \
52 OSSetPerformanceMonitor(PM_MASK_PMC1|PM_MASK_PMC2, 0, 0, 0, 0, 0, 0);
53
54 #if 0
55 inline void PMStartCycleAndInstructionCount()
56 {
57 OSSetPerformanceMonitor(PM_MASK_MMCR0|PM_MASK_PMC1|PM_MASK_PMC2,
58 PM_PMC1_ENCODING_CYCLES|PM_PMC2_ENCODING_INSTRUCTIONS,
59 0, 0, 0, 0, 0);
60 }
61
62 inline void PMStopCycleAndInstructionCount()
63 {
64 OSSetPerformanceMonitor(PM_MASK_MMCR0, 0, 0, 0, 0, 0, 0);
65 }
66
67 inline void PMResetCycleAndInstructionCount()
68 {
69 OSSetPerformanceMonitor(PM_MASK_PMC1|PM_MASK_PMC2, 0, 0, 0, 0, 0, 0);
70 }
71 #endif
72
PMGetCycleCount()73 static inline u32 PMGetCycleCount()
74 {
75 return __MFSPR(PM_UPMC1);
76 }
77
PMGetInstructionCount()78 static inline u32 PMGetInstructionCount()
79 {
80 return __MFSPR(PM_UPMC2);
81 }
82
83 #ifdef __cplusplus
84 }
85 #endif
86
87 #endif // __OSPERFORMANCE_MONITOR_H__
88
89