1 / 9

Memory 笔记

2008.4.28. Memory 笔记. Memory.h 结构. 先定义了两个宏 #define MEM_PTAB_SIZE (32*1024) ‏ #define MEM_LOG_PTAB_SIZE 15 页表大小 32k (个入口),页大小 8k 定义了一个结构 mem_pte_t struct mem_pte_t { struct mem_pte_t *next; /* next translation in this bucket */ md_addr_t tag; /* virtual page number tag */

fedora
Download Presentation

Memory 笔记

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2008.4.28 Memory笔记

  2. Memory.h结构 • 先定义了两个宏 • #define MEM_PTAB_SIZE (32*1024)‏ • #define MEM_LOG_PTAB_SIZE 15 • 页表大小32k(个入口),页大小8k • 定义了一个结构mem_pte_t • struct mem_pte_t { • struct mem_pte_t *next; /* next translation in this bucket */ • md_addr_t tag; /* virtual page number tag */ • byte_t *page; /* page pointer */ • }; • 表示页表的一项 • Md_addr_t为32bit unsigned int • Byte_t为8bit unsigned char

  3. Memory.h结构 • 定义了一个结构mem_t • struct mem_t { • /* memory object state */ • char *name; /* name of this memory space */ • struct mem_pte_t *ptab[MEM_PTAB_SIZE];/* inverted page table */ • /* memory object stats */ • counter_t page_count; /* total number of pages allocated */ • counter_t ptab_misses; /* total first level page tbl misses */ • counter_t ptab_accesses; /* total page table accesses */ • }; • 其中counter_t为64bit signed long long

  4. Memory.h结构 • 定义了一个枚举类型表示内存的读写操作 • 读:目标机(被模拟的程序)到本地机(模拟器) • 写:本地机到目标机 • 定义了一个内存访问的函数类型mem_access_fn • typedef enum md_fault_type • (*mem_access_fn)(struct mem_t *mem, /* memory space to access */ • enum mem_cmd cmd, /* Read or Write */ • md_addr_t addr, /* target memory address to access */ • void *p, /* where to copy to/from */ • int nbytes); /* transfer length in bytes */ • 返回值为枚举类型md_fault_type

  5. 内存模型 • 在各处理器中初始化(sim-fast,sim-outorder等) • 先调用mem_create()创建一张页表,该页表即为mem_t类型,有自己的名字,32k个入口地址,以及一些用于最后统计输出的变量 • 再调用mem_init()将所有入口地址置为NULL

  6. 内存模型 • 内存的分配采用页式 • 先分配4096个连续的byte(这是simple scalar中的默认页大小),然后新分配页表中的一项,让该项的page指针指向新页的地址,随后在页表中将该项插入到对应的入口链表中的第一个(局部性原理,新分配的页最有可能用到)

  7. 内存模型

  8. 内存模型 • 似乎将页指针数组当成TLB使用 • 定义的内存操作:read,write • Read:将模拟器申请的页中的数据读到给定的主存指针的地址中 • Write:将主存指针地址中的数据存到内存的虚地址对应的页 • 两个操作均以byte为单位

  9. Memory.c • mem_dump()中的len是否有问题?应该如何计算? • 定义的函数指针mem_fn有何用处?是否是为了方便用户能够添加自己定义的内存操作函数? • 其他用到mem_fn()的函数的作用?

More Related