1 /****************************************************************************
2 * Copyright (C) 2014-2015 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 ****************************************************************************/
27 #include "common/os.h"
28 #include "common/rdtsc_buckets.h"
36 APIDrawWakeAllThreads
,
62 FECullZeroAreaAndBackface
,
65 FEProcessInvalidateTiles
,
85 BESingleSampleBackend
,
98 void rdtscInit(int threadId
);
99 void rdtscStart(uint32_t bucketId
);
100 void rdtscStop(uint32_t bucketId
, uint32_t count
, uint64_t drawId
);
101 void rdtscEvent(uint32_t bucketId
, uint32_t count1
, uint32_t count2
);
102 void rdtscEndFrame();
104 #ifdef KNOB_ENABLE_RDTSC
105 #define RDTSC_RESET() rdtscReset()
106 #define RDTSC_INIT(threadId) rdtscInit(threadId)
107 #define RDTSC_START(bucket) rdtscStart(bucket)
108 #define RDTSC_STOP(bucket, count, draw) rdtscStop(bucket, count, draw)
109 #define RDTSC_EVENT(bucket, count1, count2) rdtscEvent(bucket, count1, count2)
110 #define RDTSC_ENDFRAME() rdtscEndFrame()
112 #define RDTSC_RESET()
113 #define RDTSC_INIT(threadId)
114 #define RDTSC_START(bucket)
115 #define RDTSC_STOP(bucket, count, draw)
116 #define RDTSC_EVENT(bucket, count1, count2)
117 #define RDTSC_ENDFRAME()
120 extern std::vector
<uint32_t> gBucketMap
;
121 extern BucketManager gBucketMgr
;
122 extern BUCKET_DESC gCoreBuckets
[];
123 extern uint32_t gCurrentFrame
;
124 extern bool gBucketsInitialized
;
126 INLINE
void rdtscReset()
129 gBucketMgr
.ClearThreads();
132 INLINE
void rdtscInit(int threadId
)
134 // register all the buckets once
135 if (!gBucketsInitialized
&& (threadId
== 0))
137 gBucketMap
.resize(NumBuckets
);
138 for (uint32_t i
= 0; i
< NumBuckets
; ++i
)
140 gBucketMap
[i
] = gBucketMgr
.RegisterBucket(gCoreBuckets
[i
]);
142 gBucketsInitialized
= true;
145 std::string name
= threadId
== 0 ? "API" : "WORKER";
146 gBucketMgr
.RegisterThread(name
);
149 INLINE
void rdtscStart(uint32_t bucketId
)
151 uint32_t id
= gBucketMap
[bucketId
];
152 gBucketMgr
.StartBucket(id
);
155 INLINE
void rdtscStop(uint32_t bucketId
, uint32_t count
, uint64_t drawId
)
157 uint32_t id
= gBucketMap
[bucketId
];
158 gBucketMgr
.StopBucket(id
);
161 INLINE
void rdtscEvent(uint32_t bucketId
, uint32_t count1
, uint32_t count2
)
163 uint32_t id
= gBucketMap
[bucketId
];
164 gBucketMgr
.AddEvent(id
, count1
);
167 INLINE
void rdtscEndFrame()
171 if (gCurrentFrame
== KNOB_BUCKETS_START_FRAME
&& KNOB_BUCKETS_START_FRAME
< KNOB_BUCKETS_END_FRAME
)
173 gBucketMgr
.StartCapture();
176 if (gCurrentFrame
== KNOB_BUCKETS_END_FRAME
&& KNOB_BUCKETS_START_FRAME
< KNOB_BUCKETS_END_FRAME
)
178 gBucketMgr
.StopCapture();
179 gBucketMgr
.PrintReport("rdtsc.txt");