Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12621 Discussions

NIOS software execution time using performance counter

Honored Contributor II

I want to calculate my NIOS software execution time. My application need approx 3min(180 sec) to complete execution.(measured with a stopwatch) 

I am using performance counter. As per its specs, it returns a 64 bit value. I am using DE2 board with 50MHz crystal. 


So as per my expectation, the counter should return (180*50,000,000) at the end, but its returning something in the range (40*50,000,000). 


What could be the reason?? My expected value completely comes under the 64 bit return value, so no case of re-loop. 

I am using: 


int main() 





// Code Logic 




unsigned long long time; 

time = (unsigned long long)perf_get_section_time(performance_counter_0_base, 1); 

printf("\n\nTotal cycles consumed in FIR calculation = %llu cycles\n", time); 


Please suggest.. 

Is their any other way to calculate exact real time??
0 Kudos
2 Replies
Honored Contributor II

Your problem sounds a little bit like your 64-bit value is being truncated to 32-bits due to a software bug; without exact expected/actual values it's hard to say. 

Your problem could also be something like the wrong clock supplied to the performance counter block. 


As far as other time measurements go, you can use alt_nticks() for coarse, and a 64-bit Interval Timer for fine granularity; but the performance counter block you are already using works well, I just think you have some bug which is not obvious from your snippet.
0 Kudos
Honored Contributor II

Hi ted, 


After a hard time finding the bug, i designed my own IP block in verilog to count the clocks. Now it has perfect 64 bit resolution. 

Thanks for your suggestions.
0 Kudos