false_sharing.h 2.34 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. 
 *
 */

/*********************************************************************
 * false_sharing.h
 *
 * Track the false sharing in the caches... enabled by a run-time
 * option. 
 * 
 * $Author: blythe $
 * $Date: 2002/05/29 01:09:09 $
 *********************************************************************/

#ifndef _FALSE_SHARING_H
#define _FALSE_SHARING_H

#include "machine_params.h"

#ifdef TRACK_FALSE_SHARING
#define FALSE_SHARING_ACCESS(_cpu, _fshE, _pA) {\
   if (falseSharing) { \
    (_fshE->accessedWords |= falseSharingMaskEntries[M_FROM_CPU(_cpu)]\
                              [_pA&falseSharingMask]); \
  } \
}

#define FALSE_SHARING_MODIFY(_cpu,_pA) \
       if (falseSharing) { FalseSharingModify(_cpu,_pA);}

#else
#define FALSE_SHARING_ACCESS(_cpu, _fshE, _pA) 
#define FALSE_SHARING_MODIFY(_cpu,_pA) 
#endif
/************************************************************************
 * False vs. True Sharing data structures. These are accessed directy by
 * some time-critical macros.
 ************************************************************************/

typedef uint FalseSharingBV;    /* 32 bits. Cluster words if cache line >128 */

typedef struct FalseSharingEntry {
   FalseSharingBV  accessedWords;   /* bitvector modified on every access */
   int categ;                    /* Type of last miss --> used to classify */
   int valid;
   VA PC;                           
   VA vAddr;
   PA pAddr;
   int stall;
   struct StatRecordSnapshot *snap;
} FalseSharingEntry;

extern void FalseSharingEarlyInit(void);
extern void FalseSharingLateInit(void);

extern void FalseSharingEvict(int cpuNum, PA pAddr, int way, int type);
extern void FalseSharingDefine(int cpuNum, PA pAddr, int way, VA pc, VA vAddr,int stall);
extern void FalseSharingDefineOffset(int cpuNum,PA pAddr,int way, int off);
extern void FalseSharingModify(int cpuNum, PA pAddr);
extern FalseSharingEntry *SCacheLineToFalseSharing(int cpuNum, PA pAddr, 
                                                   int way);

extern void FalseSharingCleanup(void);
extern FalseSharingBV *falseSharingMaskEntries[MAX_MACHINES];
extern uint falseSharingMask;
extern bool falseSharing;

#endif /* _FALSE_SHARING_H */