cpu_stats.h 4.15 KB
/*
 * Copyright (C) 1996-1998 by the Board of Trustees
 *    of Leland Stanford Junior University.
 * 
 * This file is part of the SimOS distribution. 
 * See LICENSE file for terms of the license. 
 *
 */

/****************************************************************
 * stats.h
 *
 * Definitions and macros for the general cpu statistics collection. 
 * The goal is for this to hook up to visualization engines easily.
 *
 * Author: $author$
 * Date: $date$
 ****************************************************************/

#ifndef CPU_STATS_H
#define CPU_STATS_H

#include "simtypes.h"

/* Exported functions */
extern void InitCPUStats(void);
extern void ResetCPUStats(void);
extern void PrintPeriodicCPUStats(void);
extern void PrintAllCPUStats(void);

#define SPIN_LOOP_INST         35
#define STAT_INTERVAL          (1024*1024*4)

#define MAX_SYSCALL             181
#define MAX_UTLB_CAUSE          4
#define MAX_CAUSE               75

#ifdef NO_STATS
# define STATS_INC(_cpu, _var, _count) 
# define STATS_SET(_cpu, _var, _value) 
# define STATS_VALUE(_cpu, _var)        0
# define STATS_ADD_INTERVAL(_cpu, _var, _startVar) 
#else
#define STATS_INC(_cpu, _var, _count) cpuStats[(_cpu)]._var += _count;
#define STATS_SET(_cpu, _var, _value) cpuStats[(_cpu)]._var = _value;
#define STATS_VALUE(_cpu, _var)       (cpuStats[(_cpu)]._var)
#define STATS_ADD_INTERVAL(_cpu, _var, _startVar) \
{ if (cpuStats[(_cpu)]._startVar) { \
     cpuStats[(_cpu)]._var += (CPUVec.CycleCount(_cpu) - STATS_VALUE(_cpu, _startVar)); \
     cpuStats[(_cpu)]._startVar = 0; \
     } \
}
#endif

typedef struct CPUStats {
   /* Stats */
   SimCounter iReads;
   SimCounter dReads;
   SimCounter dWrites;
  
   SimTime stallStart;
   SimCounter stallTime;

   SimCounter numInstructions;   /* Number of instruction executed */
   SimTime nextInstrSample;   /* When to sample the PC next */

   SimTime syncOpStallStart;  /* Start time of sync op */
   SimTime syncOpStallTime;   /* Total time spent waiting for the sync op */

   SimTime syncStallStart;  
   SimTime syncStallTime;   

   SimTime prefMHTStallStart;
   SimTime writeMHTStallStart;

   SimTime libcWaitStart;
   SimTime libcWaitTime;

   SimTime haltedTime;        /* Just in SOLO - time before CREATE */

   uint numSyscalls;
   uint numFaults;
   uint numInterrupts;

   SimCounter numBdoorInsts;
   SimCounter numFPOps;
   SimCounter syscallCount[MAX_SYSCALL];
   SimCounter causeCount[MAX_CAUSE];
   SimCounter utlbCount[MAX_UTLB_CAUSE];

   SimCounter syncOps;

   struct { 
      SimCounter lls;	    /* Number of LL */
      SimCounter llNonZero;   /* Number of LL returned non zero */
      SimCounter llStallTime; /* LL stall time*/
      SimCounter scs;	    /* Number of SC */
      SimCounter scFailed;    /* Number failed SC */
      SimCounter scStallTime; /* Stall time on sc in cycles*/
      SimCounter llscConflictSuccess; 
      SimCounter syncs;	    /* Number of SYNCs */
      SimCounter syncStallTime; /* Time stalled on SYNCs */
      SimCounter locks;	      /* Number of Locks */
      SimCounter lockStallTime; /* Time stalled on locks */
      SimCounter barriers;      /* Number of barriers */
      SimCounter barrierStallTime; /* Time stalled on barriers */
      SimCounter waitForCount;  /* Number of WAIT_FOR_END calls */
      SimCounter waitForStallTime; /* Time stalled in WAIT_FOR_END */
   } syncStats;

   struct {
      SimCounter prefs;       /* Number of prefetches */
      SimCounter prefXs;      /* Number of prefetch exclusives */
      SimCounter prefTLBMisses;
      SimCounter prefXTLBMisses;
      SimCounter prefL1Hits;
      SimCounter prefXL1Hits;
      SimCounter prefL2Hits;
      SimCounter prefXL2Hits;
      SimCounter prefStalls;
      SimCounter prefXStalls;
      SimCounter prefMerges;
      SimCounter prefXMerges;
      SimCounter prefFails;
      SimCounter prefXFails;
      SimCounter prefMHTStall;
      SimCounter prefXMHTStall;
      SimCounter prefMHTStallTime;
      SimCounter prefXMHTStallTime;
      SimCounter prefUpgrades;
      SimCounter prefXUpgrades;
   } prefStats;

   struct {
      SimCounter writeMHTStall;
      SimCounter writeMHTStallTime;
   } writeBufferStats;
} CPUStats;

extern CPUStats *cpuStats;

#endif