Vanderson Martins do Rosario
2014-Sep-17 20:35 UTC
[LLVMdev] Measure execution time of each basic block
Jon, I need to create a database of basics blocks and their execution time. The only thing I'm concerned is if a block A is more expensive than a block B. Do you think that even with the overhead I would be able to get the A > B information? Like: overhead + time(A) > overhead + time(B) => A > B. If so, I'm not too much concerned about the accuracy. Not sure if I was clear, Thanks again Vanderson M. Rosario 2014-09-17 17:26 GMT-03:00 Jonathan Roelofs <jonathan at codesourcery.com>:> I think if you do this, you're quickly going to realize that there's quite > a lot of overhead in getting the time stamps needed to record basic block > duration, so you're not going to get accurate results except for really big > basic blocks. > > > Cheers, > > Jon > > > On 9/17/14 1:53 PM, Vanderson Martins do Rosario wrote: > >> Guys, >> >> Someone have any idea how could I measure the execution time of each LLVM >> basic >> block of a program? >> >> I tried to use some profiling tools like gcov and perf, but as far as I >> know >> they can only give me the frequency that each basic block is executed. >> >> I was thinking about writing a pass to add PAPI instructions in each LLVM >> basic >> block. Do you think is a good idea? >> >> Thanks >> >> Vanderson M. Rosario >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> > -- > Jon Roelofs > jonathan at codesourcery.com > CodeSourcery / Mentor Embedded >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140917/5e1218d4/attachment.html>
Jonathan Roelofs
2014-Sep-17 20:46 UTC
[LLVMdev] Measure execution time of each basic block
On 9/17/14 2:35 PM, Vanderson Martins do Rosario wrote:> Jon, > I need to create a database of basics blocks and their execution time. The only > thing I'm concerned is if a block A is more expensive than a block B. > Do you think that even with the overhead I would be able to get the A > B > information? > Like: overhead + time(A) > overhead + time(B) => A > B. > If so, I'm not too much concerned about the accuracy. >Depends on your platform. Different counters have different resolutions, anywhere from miliseconds to 10's of cycles, and the overhead can have a bit of variability too, which means that 'overhead + time(A) > overhead + time(B) => A > B' is not necessarily true. When overhead >> time(A) (or B), then you're not going to get a meaningful measurement. Cheers, Jon> Not sure if I was clear, > > Thanks again > > Vanderson M. Rosario > > 2014-09-17 17:26 GMT-03:00 Jonathan Roelofs <jonathan at codesourcery.com > <mailto:jonathan at codesourcery.com>>: > > I think if you do this, you're quickly going to realize that there's quite a > lot of overhead in getting the time stamps needed to record basic block > duration, so you're not going to get accurate results except for really big > basic blocks. > > > Cheers, > > Jon > > > On 9/17/14 1:53 PM, Vanderson Martins do Rosario wrote: > > Guys, > > Someone have any idea how could I measure the execution time of each > LLVM basic > block of a program? > > I tried to use some profiling tools like gcov and perf, but as far as I know > they can only give me the frequency that each basic block is executed. > > I was thinking about writing a pass to add PAPI instructions in each > LLVM basic > block. Do you think is a good idea? > > Thanks > > Vanderson M. Rosario > > > _________________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu> http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/__mailman/listinfo/llvmdev > <http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev> > > > -- > Jon Roelofs > jonathan at codesourcery.com <mailto:jonathan at codesourcery.com> > CodeSourcery / Mentor Embedded > >-- Jon Roelofs jonathan at codesourcery.com CodeSourcery / Mentor Embedded
If you are on X86, you can use the rdtsc/rdtscp llvm intrinsics - http://permalink.gmane.org/gmane.comp.compilers.llvm.cvs/185208 with RDTSCP you can double fence your basic block so you can be sure that the OOO scheduling does not schedule instructions that you don't intend to measure, however note that there is a huge overhead as a result of this. RDTSC has a much lower overhead since it only reads your TSC reg but if you are measuring a small basic block it won't be accurate. thanks, sathvik On Wed, Sep 17, 2014 at 1:35 PM, Vanderson Martins do Rosario < vandersonmr2 at gmail.com> wrote:> Jon, > I need to create a database of basics blocks and their execution time. The > only thing I'm concerned is if a block A is more expensive than a block B. > Do you think that even with the overhead I would be able to get the A > B > information? > Like: overhead + time(A) > overhead + time(B) => A > B. > If so, I'm not too much concerned about the accuracy. > > Not sure if I was clear, > > Thanks again > > Vanderson M. Rosario > > 2014-09-17 17:26 GMT-03:00 Jonathan Roelofs <jonathan at codesourcery.com>: > >> I think if you do this, you're quickly going to realize that there's >> quite a lot of overhead in getting the time stamps needed to record basic >> block duration, so you're not going to get accurate results except for >> really big basic blocks. >> >> >> Cheers, >> >> Jon >> >> >> On 9/17/14 1:53 PM, Vanderson Martins do Rosario wrote: >> >>> Guys, >>> >>> Someone have any idea how could I measure the execution time of each >>> LLVM basic >>> block of a program? >>> >>> I tried to use some profiling tools like gcov and perf, but as far as I >>> know >>> they can only give me the frequency that each basic block is executed. >>> >>> I was thinking about writing a pass to add PAPI instructions in each >>> LLVM basic >>> block. Do you think is a good idea? >>> >>> Thanks >>> >>> Vanderson M. Rosario >>> >>> >>> _______________________________________________ >>> LLVM Developers mailing list >>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >>> >>> >> -- >> Jon Roelofs >> jonathan at codesourcery.com >> CodeSourcery / Mentor Embedded >> > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140917/118bd47f/attachment.html>
rdtsc is pretty good but keep in mind that the tsc register is not kept consistent across cores. In general, it is consistent across cores on one cpu socket but not across sockets. But I’ve seen cases where there is a huge difference across cores on the same cpu socket. (this was because of bios settings used during the boot cycle.) If you can lock your thread(s) on specific cores, you can avoid these issues. -bean On Sep 17, 2014, at 1:50 PM, sathvik <sathvikl at gmail.com> wrote:> If you are on X86, you can use the rdtsc/rdtscp llvm intrinsics - > http://permalink.gmane.org/gmane.comp.compilers.llvm.cvs/185208 > > with RDTSCP you can double fence your basic block so you can be sure that the OOO scheduling does not schedule instructions that you don't intend to measure, however note that there is a huge overhead as a result of this. > RDTSC has a much lower overhead since it only reads your TSC reg but if you are measuring a small basic block it won't be accurate. > > thanks, > sathvik > > > On Wed, Sep 17, 2014 at 1:35 PM, Vanderson Martins do Rosario <vandersonmr2 at gmail.com> wrote: > Jon, > I need to create a database of basics blocks and their execution time. The only thing I'm concerned is if a block A is more expensive than a block B. > Do you think that even with the overhead I would be able to get the A > B information? > Like: overhead + time(A) > overhead + time(B) => A > B. > If so, I'm not too much concerned about the accuracy. > > Not sure if I was clear, > > Thanks again > > Vanderson M. Rosario > > 2014-09-17 17:26 GMT-03:00 Jonathan Roelofs <jonathan at codesourcery.com>: > I think if you do this, you're quickly going to realize that there's quite a lot of overhead in getting the time stamps needed to record basic block duration, so you're not going to get accurate results except for really big basic blocks. > > > Cheers, > > Jon > > > On 9/17/14 1:53 PM, Vanderson Martins do Rosario wrote: > Guys, > > Someone have any idea how could I measure the execution time of each LLVM basic > block of a program? > > I tried to use some profiling tools like gcov and perf, but as far as I know > they can only give me the frequency that each basic block is executed. > > I was thinking about writing a pass to add PAPI instructions in each LLVM basic > block. Do you think is a good idea? > > Thanks > > Vanderson M. Rosario > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > -- > Jon Roelofs > jonathan at codesourcery.com > CodeSourcery / Mentor Embedded > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140917/06155338/attachment.html>