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++
12748 Discussions

problem with performance counter core

Altera_Forum
Honored Contributor II
1,028 Views

Hi everyone, I am a new to nios. I've been trying to get this code to work on the cyclone 2 development board that I have. I just don't know what is wrong. I cannot get any valid result from the performance counter core of altera. any suggestion is very helpful. 

 

 

# include "alt_types.h"# include <stdio.h> /* This ert_main.c example uses printf/fflush */# include <unistd.h># include <altera_avalon_performance_counter.h> /*Use to measure code performance*/ # include "varipitch.h" /* Model&#39;s header file */# include "rtwtypes.h" /* MathWorks types */# define RATE0 1# define RATE1 2 

 

extern const float GNC_input_table[33343][21]; 

 

static RT_MODEL_varipitch varipitch_M_; 

static RT_MODEL_varipitch *varipitch_M = &varipitch_M_;/* Real-time model */ 

static BlockIO_varipitch varipitch_B; /* Observable signals */ 

static D_Work_varipitch varipitch_DWork;/* Observable states */ 

static real32_T varipitch_U_Xe[3]; 

 

/* Root inport: &#39;<Root>/Xe&#39; */ 

static real32_T varipitch_U_Ve[3]; 

 

/* Root inport: &#39;<Root>/Ve&#39; */ 

static real32_T varipitch_U_p; 

 

/* Root inport: &#39;<Root>/p&#39; */ 

static real32_T varipitch_U_dpdt; 

 

/* Root inport: &#39;<Root>/dpdt&#39; */ 

static real32_T varipitch_U_Q6; 

 

/* Root inport: &#39;<Root>/Q6&#39; */ 

static real32_T varipitch_U_Cdsin6; 

 

/* Root inport: &#39;<Root>/Cdsin6&#39; */ 

static real32_T varipitch_U_Cmas6; 

 

/* Root inport: &#39;<Root>/Cmas6&#39; */ 

static real32_T varipitch_U_Vb[3]; 

 

/* Root inport: &#39;<Root>/Vb&#39; */ 

static real32_T varipitch_U_mass_single; 

 

/* Root inport: &#39;<Root>/mass&#39; */ 

static real32_T varipitch_U_ix_single; 

 

/* Root inport: &#39;<Root>/ix&#39; */ 

static real32_T varipitch_U_iy_single; 

 

/* Root inport: &#39;<Root>/iy&#39; */ 

static real32_T varipitch_U_cg_single; 

 

/* Root inport: &#39;<Root>/cg&#39; */ 

static real32_T varipitch_U_winds_single[2]; 

 

/* Root inport: &#39;<Root>/winds&#39; */ 

static real32_T varipitch_U_clock_single; 

 

/* Root inport: &#39;<Root>/clock&#39; */ 

static real32_T varipitch_Y_Mode; 

 

/* Root outport: &#39;<Root>/Mode&#39; */ 

static real32_T varipitch_Y_CMDP; 

 

/* Root outport: &#39;<Root>/CMDP&#39; */ 

static boolean_T OverrunFlags[2] = { 0, 0 }; 

 

DEFINITION OF MYFUNCTION1{} 

DEFINITION OF MYFUNCTION2{ 

PERF_BEGIN(PERFORMANCE_COUNTER_0_BASE, RATE1);  

do something 

PERF_END(PERFORMANCE_COUNTER_0_BASE, RATE1); 

 

 

 

 

int perf_print_my_formatted_report (void* perf_base, alt_u32 clock_freq_hertz) 

 

double total_usec; 

alt_u64 total_clocks; 

alt_u64 section_clocks; 

int section_num = 1; 

 

const char* separator = "+---------------+-----+------------+---------------+-----------+\n"; 

const char* column_header = "| Section | % | Time (usec)| Time (clocks)|Occurrences|\n"; 

 

 

total_clocks = perf_get_total_time (perf_base); 

total_usec = ((double)total_clocks) / clock_freq_hertz *1000000; 

 

// Print the total at the top: 

printf ("--Performance Counter Report--\nTotal Time: %lld microseconds ",(alt_u64)total_usec); 

printf ("(%llu clock-cycles)\n\n", total_clocks); 

printf ("%s",separator); 

printf ("%s",column_header); 

printf ("%s",separator); 

 

for (section_num = 1; section_num <= 2; section_num++) 

section_clocks = perf_get_section_time (perf_base, section_num); 

 

if (section_num == 1){ 

printf ("|rate0 ");} 

else { 

printf ("|rate1 ");} 

printf ("|%5lld",(section_clocks * 100) / total_clocks); // % 

printf ("|%12lld",(section_clocks*1000000) / clock_freq_hertz); // time (us) 

printf ("|%15lld",section_clocks); // time (clocks) 

printf ("|%11u", (unsigned int) perf_get_num_starts (perf_base, section_num)); // occurrences 

printf ("|\n"); 

printf ("%s",separator); 

 

 

return 0; 

/* The example "main" function illustrates what is required by your 

* application code to initialize, execute, and terminate the generated code. 

* Attaching rt_OneStep to a real-time clock is target specific. This example 

* illustates how you do this relative to initializing the model. 

*/ 

int main(int_T argc, const char_T *argv[]) 

/* Initialize model */ 

PERF_RESET(PERFORMANCE_COUNTER_0_BASE); 

int_T count = 0;  

FILE *model_out; 

CALL MYFUNCTION1; 

 

/* Attach rt_OneStep to a timer or interrupt service routine with 

* period 0.0002 seconds (the model&#39;s base sample time) here. The 

* call syntax for rt_OneStep is 

* rt_OneStep(varipitch_M); 

*/ 

printf("Warning: The simulation will run forever. " 

"Generated ERT main won&#39;t simulate model step behavior. " 

"To change this behavior select the &#39;MAT-file logging&#39; option.\n"); 

fflush(NULL); 

PERF_START_MEASURING(PERFORMANCE_COUNTER_0_BASE); 

while(count < 1){ 

CALL MYFUNCTION2 

PERF_BEGIN(PERFORMANCE_COUNTER_0_BASE, RATE0);  

count++; 

PERF_END(PERFORMANCE_COUNTER_0_BASE, RATE0); 

PERF_STOP_MEASURING(PERFORMANCE_COUNTER_0_BASE); 

perf_print_my_formatted_report((void*)PERFORMANCE_COUNTER_0_BASE, ALT_CPU_FREQ); 

 

 

output capture from screen: 

 

 

nios2-terminal: Warning: The JTAG cable you are using is not supported for Nios 

nios2-terminal: II systems. You may experience intermittent JTAG communication 

nios2-terminal: failures with this cable. Please use a USB Blaster revision B 

nios2-terminal: cable or another supported cable. Please refer to the file 

nios2-terminal: errata.txt included in the Nios II development kit documents 

nios2-terminal: directory for more information. 

 

nios2-terminal: connected to hardware target using JTAG UART on cable 

nios2-terminal: "USB-Blaster [USB-0]", device 1, instance 0 

nios2-terminal: (Use the IDE stop button or Ctrl-C to terminate) 

 

Warning: The simulation will run forever. Generated ERT main won&#39;t simulate mode 

l step behavior. To change this behavior select the &#39;MAT-file logging&#39; option. 

I am loading 

--Performance Counter Report-- 

Total Time: 217020518514230016 microseconds (18446744073709551615 clock-cycles) 

 

+---------------+-----+------------+---------------+-----------+ 

| Section | % | Time (usec)| Time (clocks)|Occurrences| 

+---------------+-----+------------+---------------+-----------+ 

|rate0 | 0|217020518514| -1| 4294967295| 

+---------------+-----+------------+---------------+-----------+ 

|rate1 | 0|217020518514| -1| 4294967295| 

+---------------+-----+------------+---------------+-----------+ 

 

 

I generated the C code from matlab embedded real time workshop so that&#39;s why there are funky type like char_T, int_T, real32_T. Those are just regulare char, int, double but typedef in rtwtypes.h.
0 Kudos
0 Replies
Reply