[ECOS] naive doubts regarding magic nos. in show_ticks_in_us implementations

sandeep shimple0@yahoo.com
Mon Sep 27 14:58:00 GMT 2004


hi,

i find certain pieces of code in eCos kernel/tests, bit confusing. i am 
embedding my doubts (marked with ###) in the code snippets from various files below.


packages/net/bsd_tcpip/current/src/ecos/support.c
-------------------------------------------------

// Display a number of ticks as microseconds
// Note: for improved calculation significance, values are kept in ticks*1000
static long rtc_resolution[] = CYGNUM_KERNEL_COUNTERS_RTC_RESOLUTION;
static long ns_per_system_clock;

static void show_ticks_in_us(cyg_uint32 ticks)
{
     long long ns;
     ns_per_system_clock = 1000000/rtc_resolution[1];

### as much as i have understood from discussion on list and available
### documentation, rtc_resolution indicates no. of nanoseconds per kernel tick.
### that means 10^7 nanoseconds/tick can be represented by either of the
### combinations of numerator/denominator -
### ( 10^9 / 10^2 ) , (10^8 / 10) , (10^7 / 1)
### is there anything, i am missing here?

### the magic no. 10^6 is used to compute no. of microseconds per tick??
### the computation of ns_per_system_clock seems to be assuming first
### combination of numerator/denominator.

     ns = (ns_per_system_clock * ((long long)ticks * 1000)) /
         CYGNUM_KERNEL_COUNTERS_RTC_PERIOD;

### why multiplication by 1000 in above computation?? while computation for
### similar aim, don't do this in other places as evident from the code snippets
### below.

     ns += 5;  // for rounding to .01us
     diag_printf("%7d.%02d", (int)(ns/1000), (int)((ns%1000)/10));

### in other similar functions below, the format specifier is "%5d.%02d". i
### guess "%7d.%02d" is put here, because of previous multiplication by 1000.
### will %5d -> %7d take care of the number generated due to above mentioned
### multiplication? shouldn't it be kept as %8d ?

}

packages/kernel/current/tests/tm_basic.cxx
packages/compat/posix/current/tests/tm_basic.cxx
------------------------------------------------

static long rtc_resolution[] = CYGNUM_KERNEL_COUNTERS_RTC_RESOLUTION;
static long ns_per_system_clock;

// Display a number of ticks as microseconds
// Note: for improved calculation significance, values are kept in ticks*1000
void show_ticks_in_us(cyg_uint32 ticks)
{
     long long ns;
     ns = (ns_per_system_clock * (long long)ticks) / 
CYGNUM_KERNEL_COUNTERS_RTC_PERIOD;
     ns += 5;  // for rounding to .01us
     diag_printf("%5d.%02d", (int)(ns/1000), (int)((ns%1000)/10));
}

static void _run_all_tests(CYG_ADDRESS id)
{
.......
     ns_per_system_clock = 1000000/rtc_resolution[1];

### same doubt as in previous case

.......


packages/services/gfx/mw/current/src/ecos/ecos_init.c
-----------------------------------------------------

// Display a number of ticks as microseconds
// Note: for improved calculation significance, values are kept in ticks*1000
static void show_ns(long long ns)
{
diag_printf("%5d.%02d", (int)(ns/1000), (int)((ns%1000)/10));
}

static long rtc_resolution[] = CYGNUM_KERNEL_COUNTERS_RTC_RESOLUTION;
static long ns_per_system_clock;

static long long ns_time(void)
{
     cyg_uint32 off;
     long long ns, clocks;

     ns_per_system_clock = 1000000/rtc_resolution[1];

### same doubt as in previous case

     HAL_CLOCK_READ(&off);
     ns = (ns_per_system_clock * (long long)off) / 
CYGNUM_KERNEL_COUNTERS_RTC_PERIOD;
     ns += 5;  // for rounding to .01us
     clocks = (cyg_current_time() * 10000000) + ns;

### though eCos allows configurable kernel tick, but isn't above computation
### assuming 10 milliseconds tick???

     return clocks;
}


static void test_file_io(void)
{
     long long start_time, end_time;
...........
     start_time = ns_time();
...........
     end_time = ns_time();
     diag_printf("'fgets': %d bytes in ", len); show_ns(end_time-start_time); 
diag_printf("ns\n");
...........
}


packages/devs/eth/mcf52xx/mcf5272/current/src/if_mcf5272.c
----------------------------------------------------------

/* Start a alarm that  will trigger  every second.   This alarm  will */
/* periodically update the recevie and transmit statistics. */
..............
cyg_alarm_initialize(((MCF5272_fec_priv_data_t*)sc->driver_private)->alarm_h,
                      cyg_current_time()+
                      (1*SEC_IN_NS)/CYGNUM_KERNEL_COUNTERS_RTC_PERIOD,
                      (1*SEC_IN_NS)/CYGNUM_KERNEL_COUNTERS_RTC_PERIOD);

### SEC_IN_NS = 10^9 ; I am not able to understand this computation in
### cyg_alarm_initialize call. SEC_IN_NS is in time units, while PERIOD is in
### h/w clock cycles?

-- 
regards
sandeep
--------------------------------------------------------------------------
A psychiatrist is a person who will give you expensive answers that
your wife will give you for free.
--------------------------------------------------------------------------


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss



More information about the Ecos-discuss mailing list