/*
    System.c, Copyright  (c) by Lukas Ruf
    Swiss Federal Institute of Technology,
    Computer Engineering and Networks Laboratory.
 
    TOPSY -- A Teachable Operating System.
             Implementation of a tiny and simple
             micro kernel for teaching purposes.
 
    For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
    This software is provided under the terms of the GNU General Public Licence.
 
    A full copy of the GNU GPL is provided in the file COPYING found in the 
    development root of Topsy.
 */
/*
	
    File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/Topsy/System.c,v $
    Author(s):             Lukas Ruf
    Affiliation:           ETH Zuerich, TIK
    Version:               $Revision: 3048 $
    Creation Date:         
    Last Date of Change:   $Date: 2007-07-20 18:11:54 +0200 (Fre, 20 Jul 2007) $ by: $Author: sryffel $
*/
/* System Functionalities: Statistical Material Collecting
  
   Provides function calls to access the data concerning numbers of scheduled,
   clock cycles consumed, overall functionality etc.
*/
#include "System.h"

//#define WITH_STATISTICS   YES

#ifdef WITH_STATISTICS /* only used if statistics are on */
/* mSysInterrupted: Numbers of handled interrupts that occured */
static unsigned long mSysInterrupted       = 0;
static unsigned long mSysNestedInterrupted = 0;
/* mSysRestored   : Numbers of to be handled mSysRestored */
static unsigned long mSysRestored    = 0;
/* mSysScheduled  : Number of Scheduled function calls */
static unsigned long mSysScheduled  = 0;


static unsigned long mcompactCalled  = 0;
static unsigned long mfindFreeCalled = 0;
static unsigned long mhmAllocCalled  = 0;
static unsigned long mhmAllocFailed  = 0;
static unsigned long mhmFreeCalled   = 0;
static unsigned long mhmFreeFailed   = 0;
static unsigned long mhmInitCalled   = 0;
static unsigned long msplitCalled    = 0;
static unsigned long mTmThreadsNow   = 0;
static unsigned long mTmThreadsAll   = 0;

static unsigned long mIpcMsgSent     = 0;
#endif

void SysInterrupted(void)
{
#ifdef WITH_STATISTICS
  mSysInterrupted++;
#endif
}

void SysNestedInterrupted(int nestedIrq, int interruptedIrq)
{
#ifdef WITH_STATISTICS
  mSysNestedInterrupted++;
#endif
}

void SysRestored(void)
{
#ifdef WITH_STATISTICS
  mSysRestored++;
#endif
}

void SysScheduled(void)
{
#ifdef WITH_STATISTICS
  mSysScheduled++;
#endif
}

void SysThreadScheduled(unsigned long long *pInc)
{
#ifdef WITH_STATISTICS
  (*pInc)++;
#endif
}

unsigned long SysGetInterrupted(void)
{
#ifdef WITH_STATISTICS
  return mSysInterrupted;
#else

  return 0;
#endif
}

unsigned long SysGetRestored(void)
{
#ifdef WITH_STATISTICS
  return mSysRestored;
#else

  return 0;
#endif
}

unsigned long SysGetScheduled(void)
{
#ifdef WITH_STATISTICS
  return mSysScheduled;
#else

  return 0;
#endif
}

void compactCalled(void)
{
#ifdef WITH_STATISTICS
  mcompactCalled++;
#endif
}
void findFreeCalled(void)
{
#ifdef WITH_STATISTICS
  mfindFreeCalled++;
#endif
}
void hmAllocCalled(void)
{
#ifdef WITH_STATISTICS
  mhmAllocCalled++;
#endif
}
void hmAllocFailed(void)
{
#ifdef WITH_STATISTICS
  mhmAllocFailed++;
#endif
}
void hmFreeCalled(void)
{
#ifdef WITH_STATISTICS
  mhmFreeCalled++;
#endif
}
void hmFreeFailed(void)
{
#ifdef WITH_STATISTICS
  mhmFreeFailed++;
#endif
}
void hmInitCalled(void)
{
#ifdef WITH_STATISTICS
  mhmInitCalled++;
#endif
}
void splitCalled(void)
{
#ifdef WITH_STATISTICS
  msplitCalled++;
#endif
}

unsigned long GetcompactCalled(void)
{
#ifdef WITH_STATISTICS
  return mcompactCalled;
#else

  return 0;
#endif
}
unsigned long GetfindFreeCalled(void)
{
#ifdef WITH_STATISTICS
  return mfindFreeCalled;
#else

  return 0;
#endif
}
unsigned long GethmAllocCalled(void)
{
#ifdef WITH_STATISTICS
  return mhmAllocCalled;
#else

  return 0;
#endif
}
unsigned long GethmAllocFailed(void)
{
#ifdef WITH_STATISTICS
  return mhmAllocFailed;
#else

  return 0;
#endif
}
unsigned long GethmFreeCalled(void)
{
#ifdef WITH_STATISTICS
  return mhmFreeCalled;
#else

  return 0;
#endif
}
unsigned long GethmFreeFailed(void)
{
#ifdef WITH_STATISTICS
  return mhmFreeFailed;
#else

  return 0;
#endif
}
unsigned long GethmInitCalled(void)
{
#ifdef WITH_STATISTICS
  return mhmInitCalled;
#else

  return 0;
#endif
}
unsigned long GetsplitCalled(void)
{
#ifdef WITH_STATISTICS
  return msplitCalled;
#else

  return 0;
#endif
}

void tmNewThread(void)
{
#ifdef WITH_STATISTICS
  mTmThreadsNow++;
  mTmThreadsAll++;
#endif
}

void tmDestroyThread(void)
{
#ifdef WITH_STATISTICS
  mTmThreadsNow--;
#endif
}

void ipcMsgSent(void)
{
#ifdef WITH_STATISTICS
  mIpcMsgSent++;
#endif
}

