Debugging & Embedded Linux Runtime Environments
by Rajesh Mishra

Listing One

static int bfin_profiler_proc_output (char *buf)
{
    char *p;
    unsigned long data;
    unsigned long long total_cycles;
    spin_lock_irq(&bfin_profiler_lock);
    data = bfin_profiler_data;
    spin_unlock_irq(&bfin_profiler_lock);

    p = buf;

    p += sprintf(p,
          "jiffies\t: %05d\n"
          "bad ret from fork\t: %d\n"
          "read count\t: %02d\n"
          "\ttotal_wait_cycles\t: %02d\n"
          "\tave_wait_cycles\t: %02d\n"
          "\tmin_wait_cycles\t: %02d\n"
          "\tmax_wait_cycles\t: %02d\n",
          (int)data, (int)bad_ret_from_fork, (int)total_read_count,
          (int)total_wait_cycles,
          total_read_count ? (int)(total_wait_cycles/total_read_count) : -1,
          (int)min_wait_cycles,
          (int)max_wait_cycles);

    p += sprintf (p, "CPU profiler\t: %s\n", 
                               (bfin_profiler_cpu_profile ? "on" : "off"));
    if (bfin_profiler_cpu_profile)
      asm("R0=cycles; R1=cycles2; P0.H=bfin_profiler_end_timestamp; 
    P0.L=bfin_profiler_end_timestamp; 
    [P0++]=R1; [P0++]=R0;":::"P0","R0","R1");
    total_cycles = bfin_profiler_end_timestamp - 
                                   bfin_profiler_start_timestamp;
    p += sprintf (p, 
           "\tstate:\t%s\n"
           "\t(%08X:%08X) -> (%08X:%08X)\t= (%08X:%08X) cycles\n"
           "\tidle time\t: (%08X:%08X) cycles\n"
           "\tkernel time\t: (%08X:%08X) cycles\n"
           "\tuser time\t: (%08X:%08X) cycles\n",
    (bfin_profiler_state >= 0 && bfin_profiler_state < 4) ? 
           bfin_profiler_state_str[bfin_profiler_state] : "unknown",
           *(unsigned long *)&bfin_profiler_start_timestamp,
           *((unsigned long *)&bfin_profiler_start_timestamp+1),
           *(unsigned long *)&bfin_profiler_end_timestamp,
           *((unsigned long *)&bfin_profiler_end_timestamp+1),
           *(unsigned long *)&total_cycles,
           *((unsigned long *)&total_cycles+1),
           *(unsigned long *)&bfin_profiler_idle_time, //
     (bfin_profiler_idle_time/total_cycles),
           *((unsigned long *)&bfin_profiler_idle_time+1), // 
     (bfin_profiler_idle_time/total_cycles), 
           *(unsigned long *)&bfin_profiler_kernel_time, // 
     (bfin_profiler_kernel_time/total_cycles),
           *((unsigned long *)&bfin_profiler_kernel_time+1), // 
     (bfin_profiler_kernel_time/total_cycles),
           *(unsigned long *)&bfin_profiler_user_time,
           *((unsigned long *)&bfin_profiler_user_time+1)); 

#ifdef CONFIG_BLACKFIN_PROFILER_TIMER
    p += sprintf (p,
          "timer: %d events\n"
          "\tlast time\t:  (%08X:%08X) cycles\n"
          "\ttotal time\t: (%08X:%08X) cycles\n",
          bfin_profiler_timer_count,
          bfin_profiler_timer_time,
          bfin_profiler_total_timer_time);
#endif

#ifdef CONFIG_BLACKFIN_PROFILER_SCHEDULER
    p += sprintf (p,
          "scheduler: %d events\n"
          "\tlast time\t:  (%08X:%08X) cycles\n"
          "\ttotal time\t: (%08X:%08X) cycles\n",
          bfin_profiler_scheduler_count,
          bfin_profiler_scheduler_time,
          bfin_profiler_total_scheduler_time);
#endif

#ifdef CONFIG_BLACKFIN_PROFILER_TELEM
    p += sprintf (p,
      "telemetry: %d events\n"
      "\tenable\t:  %d\n"
      "\t\t: (%08X:%08X) cycles\n",
      bfin_profiler_telem_num_entries,
      bfin_profiler_telem,
      bfin_profiler_telem_buffer[bfin_profiler_telem_num_entries-1].ulCycles2,
      bfin_profiler_telem_buffer[bfin_profiler_telem_num_entries-1].ulCycles);
#endif

#ifdef CONFIG_BLACKFIN_GDB_APPL_DEBUGGING
    p = bfin_debug_appl_proc_output (p);
#endif

    return  p - buf;
}
static int bfin_profiler_read_proc(char *page, char **start, off_t off,
                         int count, int *eof, void *data)
{
        int len = bfin_profiler_proc_output (page);
        if (len <= off+count) *eof = 1;
        *start = page + off;
        len -= off;
        if (len>count) len = count;
        if (len<0) len = 0;
        return len;
}


Listing Two

read count      : 00
   total_wait_cycles       : 00
   ave_wait_cycles : -1
   min_wait_cycles : 2147483647
   max_wait_cycles : 00
CPU profiler    : off
   state:  disabled
   (00000000:00000000) -> (00000000:00000000) = (00000000:00000000D8) cycles
   idle time       : (00000000:00000000) cycles
   kernel time     : (00000000:00000000) cycles
   user time       : (00000000:00000000) cycles
timer: 0 events
   last time       :  (00000000:00000000) cycles
   total time      : (00000000:00000000) cycles
scheduler: 0 events
   last time       :  (00000000:00000000) cycles
   total time      : (00000000:00000000) cycles
telemetry: 0 events
   enable  :  0
           : (00000000:00000000) cycles
appl count: 8
   0: name=/bin/init text=04C40044 data=04C44708 (current=04b5bcc0 pid=1)
   1: name=/bin/busybox text=04D00044 data=04D52B48 (current=07e6acc0 pid=34)
   2: name=/bin/busybox text=07100044 data=07152B48 (current=04f4dcc0 pid=29)
   3: name=/bin/busybox text=07000044 data=07052B48 (current=04f4d680 pid=27)
   4: name=/bin/portmap text=04F80044 data=04F8BFC8 (current=07e6a360 pid=32)
   5: name=/bin/busybox text=07200044 data=07252B48 (current=04f4d360 pid=30)
   6: name=/bin/inetd text=04FB0044 data=04FB5128 (current=04f4d9a0 pid=37)
   7: NULL entry





3


