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
,
93 WorkerWaitForThreadEvent
,
99 void rdtscInit(int threadId
);
100 void rdtscStart(uint32_t bucketId
);
101 void rdtscStop(uint32_t bucketId
, uint32_t count
, uint64_t drawId
);
102 void rdtscEvent(uint32_t bucketId
, uint32_t count1
, uint32_t count2
);
103 void rdtscEndFrame();
105 #ifdef KNOB_ENABLE_RDTSC
106 #define RDTSC_RESET() rdtscReset()
107 #define RDTSC_INIT(threadId) rdtscInit(threadId)
108 #define RDTSC_START(bucket) rdtscStart(bucket)
109 #define RDTSC_STOP(bucket, count, draw) rdtscStop(bucket, count, draw)
110 #define RDTSC_EVENT(bucket, count1, count2) rdtscEvent(bucket, count1, count2)
111 #define RDTSC_ENDFRAME() rdtscEndFrame()
113 #define RDTSC_RESET()
114 #define RDTSC_INIT(threadId)
115 #define RDTSC_START(bucket)
116 #define RDTSC_STOP(bucket, count, draw)
117 #define RDTSC_EVENT(bucket, count1, count2)
118 #define RDTSC_ENDFRAME()
121 extern std::vector
<uint32_t> gBucketMap
;
122 extern BucketManager gBucketMgr
;
123 extern BUCKET_DESC gCoreBuckets
[];
124 extern uint32_t gCurrentFrame
;
125 extern bool gBucketsInitialized
;
127 INLINE
void rdtscReset()
130 gBucketMgr
.ClearThreads();
133 INLINE
void rdtscInit(int threadId
)
135 // register all the buckets once
136 if (!gBucketsInitialized
&& (threadId
== 0))
138 gBucketMap
.resize(NumBuckets
);
139 for (uint32_t i
= 0; i
< NumBuckets
; ++i
)
141 gBucketMap
[i
] = gBucketMgr
.RegisterBucket(gCoreBuckets
[i
]);
143 gBucketsInitialized
= true;
146 std::string name
= threadId
== 0 ? "API" : "WORKER";
147 gBucketMgr
.RegisterThread(name
);
150 INLINE
void rdtscStart(uint32_t bucketId
)
152 uint32_t id
= gBucketMap
[bucketId
];
153 gBucketMgr
.StartBucket(id
);
156 INLINE
void rdtscStop(uint32_t bucketId
, uint32_t count
, uint64_t drawId
)
158 uint32_t id
= gBucketMap
[bucketId
];
159 gBucketMgr
.StopBucket(id
);
162 INLINE
void rdtscEvent(uint32_t bucketId
, uint32_t count1
, uint32_t count2
)
164 uint32_t id
= gBucketMap
[bucketId
];
165 gBucketMgr
.AddEvent(id
, count1
);
168 INLINE
void rdtscEndFrame()
172 if (gCurrentFrame
== KNOB_BUCKETS_START_FRAME
&& KNOB_BUCKETS_START_FRAME
< KNOB_BUCKETS_END_FRAME
)
174 gBucketMgr
.StartCapture();
177 if (gCurrentFrame
== KNOB_BUCKETS_END_FRAME
&& KNOB_BUCKETS_START_FRAME
< KNOB_BUCKETS_END_FRAME
)
179 gBucketMgr
.StopCapture();
180 gBucketMgr
.PrintReport("rdtsc.txt");