🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #5380

Re: Micro Timing Critical sections HELP!

#5380
From: Anthony Thyssen
Date: Sat, 22 Sep 1990 02:20
187 lines
8251 bytes
   Thanks to All who replied to my list of questions - I now present
The testing code I am using to do a Timing of a empty loop of
C code. It compiles under lattice 5.4 without options (DONOT use the
-O (optimizer) option as that  removes the empty loop and then the
start timer assign (poke).  Using OFF_DISPLAY in the start timer macro
worked to stop the large variance in the timings due to the vidio DMA's
(It does however cause the screen to flash but I expected that) 

   Note the timed sections DONOT do any I/O or waits - The only system call
made is to allocate/deallocate memory. The code I am timing is
data structure routines for my honors project. (Skiplists, Red Black Trees,
Binary Trees, Prioity Queues, ....).

   The Timing still varies but not to a large extent.
Eg in the timing of the empty 10000 time loop varied over the range
                          40096 - 40104
This seems however to depend on the amout of disk activity due to the
loading of the command - but I am not positive. I'll have to do some
tests from ram to be sure.

   Here is the code for my timing routines. and a test program.
This is released for comment only. Donot put on BBS's or hand out.
After the code is finialized I'll release it to Comp.sources.amiga
for general distrubution.
  I'll also release the Data Structures Code sometime but not soon.

  Anthony Thyssen - (Dragon Computing!)         thyssen@batserver.cs.uq.oz.au
-------------------------------------------------------------------------------
     `One afternoon we were running the Khronal Dungeon, and we opened
   a door and found ourselves looking out into the living room where we
   were playing.  One of the characters shot the Game Master with a
   crossbow bolt, and the whole dungeon dissappeared!'   -- "Dream Park"
-------------------------------------------------------------------------------

================= CODE STARTS HERE (3 files) ===============

::::::::::::::
amiga_timer.c
::::::::::::::
/********************************************************************\
**                             _________________________________    **
**   A n t h o n y            |________    __    __    _________|   **
**                                     |  |o_|  |o_|  |             **
**           T h y s s e n           __|   __    __   |__           **
**                                __|   __|  |  |  |__   |__        **
**  `` Dragon Computing! ''    __|   __|     |  |     |__   |__     **
**                            |_____|        |__|        |_____|    **
**                                                                  **
\********************************************************************/
/*
**   This is the timing C subroutines for the amiga computer.
** Note that the start and stop timer is a macro in the header
** file to speed the timing overhead.
**           This is an EXAMPLE only - Not a final release
*/
#include "amiga_timer.h"

static UBYTE CIACRAsave, CIACRBsave;
void *ciab_resource;

void
Open_Timer()
{  /* save info on current timer setup */
  ciab_resource = OpenResource(CIABNAME);
  CIACRAsave = ciab.ciacra;
  CIACRBsave = ciab.ciacrb;
  ciab.ciaicr = 0xff &~CIAICRF_TA &~CIAICRF_TB; /* disable timer interupts */
}

void
TimerPrepare()
{ /* prepare the timer to be started */
  ciab.ciacra=(CIACRAsave&(CIACRAF_TODIN|CIACRAF_SPMODE)) | CIACRBF_IN_PHI2;
  ciab.ciacrb=(CIACRBsave & CIACRBF_ALARM) | CIACRBF_IN_TA | CIACRBF_START;
  ciab.ciatalo = ciab.ciatahi =
  ciab.ciatblo = ciab.ciatbhi = (UBYTE)0xff; /* start at value -1 */
}

ULONG
TimerRead()
{
  register ULONG ticks;
  ticks =              ciab.ciatbhi;
  ticks = (ticks<<8) | ciab.ciatblo;
  ticks = (ticks<<8) | ciab.ciatahi;
  ticks = (ticks<<8) | ciab.ciatalo;
  ticks = ~ticks;          /* negate and -1 */
  return( ticks );    /* time = ticks/clock_rate (.709MHz) */
}

void
Close_Timer()
{
  ciab.ciacra = CIACRAsave;
  ciab.ciacrb = CIACRBsave;
  ciab.ciaicr = (UBYTE)0xff;
}

::::::::::::::
amiga_timer.h
::::::::::::::
/********************************************************************\
**                             _________________________________    **
**   A n t h o n y            |________    __    __    _________|   **
**                                     |  |o_|  |o_|  |             **
**           T h y s s e n           __|   __    __   |__           **
**                                __|   __|  |  |  |__   |__        **
**  `` Dragon Computing! ''    __|   __|     |  |     |__   |__     **
**                            |_____|        |__|        |_____|    **
**                                                                  **
\********************************************************************/
/*
**    Header file to define the code for timeing sections of C code
** on the amiga.  It includes macros for starting and stopping and
** restarting the timer.
**           This is an EXAMPLE only - Not a final release
*/
#include <exec/types.h>          /* general types */
#include <hardware/cia.h>        /* cia stuff */
#include <resources/cia.h>
#include <hardware/custom.h>     /* stuff for ON/OFF DISPLAY */
#include <hardware/dmabits.h>
#include <graphics/gfxmacros.h>
#include <proto/exec.h>          /* do library calls direct */

extern struct CIA    __far ciab;       /* structure for CIA-B chip */
extern struct Custom __far custom;     /* DMA chip - ON/OFF_DISPLAY */

extern void  Open_Timer();    /* initialize timers */
extern ULONG TimerRead();     /* read timers */
extern void  Close_Timer();   /* return timers to system */

/* start timing - Multitasking Disabled */
#define TimerStart() \
  { TimerPrepare(); OFF_DISPLAY; Disable(); ciab.ciacra |= CIACRAF_START; }

/* restart timing - continue the timing from where it left off */
#define TimerRestart() \
  { OFF_DISPLAY; Disable(); ciab.ciacra |= CIACRAF_START; }

/* Stop timer - restore Multitasking */
#define TimerStop() \
  { ciab.ciacra &= ~CIACRAF_START; Enable(); ON_DISPLAY; }


/* The following is to prepare the timer as part of TimerStart macro */
extern void  TimerPrepare();  /* get timer ready to start */

::::::::::::::
timertest.c
::::::::::::::
/*********************************************************************\
**                               ________________________________    **
**    A n t h o n y             |________    __    __    ________|   **
**                                       |  |o_|  |o_|  |            **
**            T h y s s e n            __|   __    __   |__          **
**                                  __|   __|  |  |  |__   |__       **
**   `` Dragon Computing ! ''    __|   __|     |  |     |__   |__    **
**                              |_____|        |__|        |_____|   **
**                                                                   **
\*********************************************************************/
/*
**   Test the timer routines on the amiga
**           This is an EXAMPLE only - Not a final release
*/
#include <stdio.h>
#include "amiga_timer.h"

char input[100];

main()
{
  register int i;
  printf("Timing...\n"); fflush(stdout);
  Open_Timer();                                /* initialize the timer */
  TimerStart();                                /* start timing */
    for(i=0; i<10000; i++);

  TimerStop();                                 /* stop timing */
  printf("Stopped -> %lu \n", TimerRead() ); /* read timer */
  fflush(stdout);
  Close_Timer();                               /* return timer */
  return(0);
}

/*================ END OF CODE ================*/
Technical Details
Message-ID: <4969@uqcspe.cs.uq.oz.au>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!brolga!uqcspe!batserver.cs.uq.oz.au!thyssen
References: <4934@uqcspe.cs.uq.oz.au> <1687@shodha.enet.dec.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!brolga!uqcspe!batserver.cs.uq.oz.au!thyssen
From: thyssen@batserver.cs.uq.oz.au (Anthony Thyssen)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Micro Timing Critical sections HELP!
Message-ID: <4969@uqcspe.cs.uq.oz.au>
Date: 22 Sep 90 02:20:04 GMT
References: <4934@uqcspe.cs.uq.oz.au> <1687@shodha.enet.dec.com>
Sender: news@uqcspe.cs.uq.oz.au
Reply-To: thyssen@batserver.cs.uq.oz.au
Lines: 187