⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cache.h

📁 用C语言来实现虚拟cache的操作
💻 H
字号:
#if !defined (CACHE_H)
#define CACHE_H

#include "misc.h"



#define CACHE_IDX(cp,addr) (((addr)>>cp->log2_block_size) & (cp->nsets-1))
#define CACHE_TAG(cp,addr) ((addr) >> (cp->log2_block_size + cp->log2_nsets))


/* cache replacement policy */
enum cache_policy 
{
  LRU,          /* replace least recently used block */
  Random,       /* replace a random block */
  FIFO          /* replace the oldest block in the set */
};


typedef struct cache_block_s
{
   boolean		valid;		/* valid bit			*/
   unsigned		tag;		/* comment needed?		*/
   int			time;		/* For LRU: time of last access	*/
					/* FIFO: time brought to cache 	*/
   struct cache_block_s	*next;		/* next block in whatever list	*/
   void			*hook;		/* can hook up anything here	*/
} cache_block_t;


typedef struct cache_set_s
{
   cache_block_t        *block;		/* Array of cache blocks	*/
} cache_set_t;


typedef struct cache_s
{
   char				*name;
   int					nsets;		/* Number of sets		*/
   int					log2_nsets;	/* log base 2 of nsets		*/
   int					assoc;		/* degree of associativity	*/
   int					log2_block_size; /* log base 2 of block size	*/
   enum	cache_policy	policy;		/* cache replacement policy	*/
   cache_set_t			*set;		/* array of cache sets		*/
   struct cache_s		*victim;  				/*pointer to a victim cache*/
} cache_t;
   

extern char *cache_policy(cache_t *);
extern  enum cache_policy cache_char2policy(char);
void cache_print_config(cache_t *);
void cache_print_stats(cache_t *, double, double, double, double);
void cache_dump(cache_t *);
extern cache_t *cache_create(char *, int, int, int, enum cache_policy);
 
cache_block_t *cache_locate(cache_t *, unsigned);
cache_block_t *cache_get_repl_block(cache_t *, unsigned);
void cache_update_time(cache_t *, cache_block_t *, int);

void cache_sim(cache_t *, FILE *input);
#endif // CACHE_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -