寄托天下
查看: 1709|回复: 5
打印 上一主题 下一主题

再问一个CS Practice Book上的第20题 [复制链接]

Rank: 4

声望
0
寄托币
1521
注册时间
2005-1-12
精华
1
帖子
4
跳转到指定楼层
楼主
发表于 2005-11-1 14:39:45 |只看该作者 |倒序浏览
Array A contains 256 elements of 4 bytes each. Its first element is stored at physical address 4,096.
Array B contains 512 elements of 4 bytes each. Its first element is stored at physical address 8,192.
Assume that only arrays A and B can be cached in an initially empty, physically addressed, physically tagged,direct-mapped, 2K-byte cache with an 8-byte block size. The following loop is then executed.

for (i = 0; i < 256; i++)
    A[i] = A[i] + B[2*i];

20. During the execution of the loop, how many bytes will be written to memory if the cache has a write-through policy?

(A) 0 (B) 256 (C) 1,024 (D) 2,048 (E) 4,096

答案是C

为什么不是D?
当采用write-through时,每执行一次A[i] = A[i] + B[2*i],cache的对应块就该写入内存。这条语句要执行256次,就要写265 × 8 = 2048字节的数据到内存,所以该选D
选C的原因可能是:每次write-through的时候,只写块中改变了的4个字节,所以是C。但是,根据cache的定义,cache的读写操作都是以块为单位的,因此我感觉C不对。
GRE作文互动论坛 -> GRE考试综合论坛 -> TOEFL考试讨论专版  -> GRE_SUB -> 美国留学 -> VISA 美国签证 -> 行前准备::飞跃同期声 -> 异乡岁月※海外申请
0 0

使用道具 举报

Rank: 2

声望
0
寄托币
73
注册时间
2005-6-26
精华
0
帖子
0
沙发
发表于 2005-11-1 21:10:13 |只看该作者
cache的定义,cache的读写操作都是以块为单位的, yes, it's right.

But I think when you do a write -through back to memory, there is some dirty bit associated with each byte location, so if it's not changed, it won't write back to memory.

Otherwise, it will be very inefficient, say if each cache block has 8 bytes, and only one byte is changed, you have to repalce the whole 8 bytes.

But you have your point.

It's just my two cents.

Good luck on Saturday.

使用道具 举报

Rank: 4

声望
0
寄托币
1521
注册时间
2005-1-12
精华
1
帖子
4
板凳
发表于 2005-11-1 21:53:56 |只看该作者
CPU一次就可以写cache的一个块到内存(块的大小是由cache和内存间数据通路的宽度所决定的),所以写一个字节和写一个块的开销是一样的。这样,dirty bit就只需要以块为单位来设置。

"Good luck on Saturday",别吓我,我记得是12号考,还有10来天吧,呵呵!
GRE作文互动论坛 -> GRE考试综合论坛 -> TOEFL考试讨论专版  -> GRE_SUB -> 美国留学 -> VISA 美国签证 -> 行前准备::飞跃同期声 -> 异乡岁月※海外申请

使用道具 举报

Rank: 2

声望
0
寄托币
73
注册时间
2005-6-26
精华
0
帖子
0
地板
发表于 2005-11-2 05:15:18 |只看该作者

What do we need "byte offset" in cache addressing?

Can you find some reference for this :

块的大小是由cache和内存间数据通路的宽度所决定的,所以写一个字节和写一个块的开销是一样的.

I think we use bigger block size because  the spatial locality. One memory is accessed, and it's likely its close memory location will also be accessed.

Also, check out the memory address structure to access the cache :
1> Tag 2> Index 3> Byte Offset.

The byte offset is used to address this issue exactly, we really don't need to write the whole block back.

I will take the test in States, and in December. And I appreciate your reply to my questions on testmagic forum, if you are the AutoSea there.

使用道具 举报

Rank: 4

声望
0
寄托币
1521
注册时间
2005-1-12
精华
1
帖子
4
5
发表于 2005-11-2 11:25:18 |只看该作者
U R  Welcome!我也在Testmagic上。
那句话是我上课的时候听老师说的,似乎西电的系统结构书上也有提及,主要是从cache读写的高效方面来考虑的。locality当然是要考虑的,呵呵
“Computer Systems a programmer's perspective"书上也提到是写回一个cache块。
GRE作文互动论坛 -> GRE考试综合论坛 -> TOEFL考试讨论专版  -> GRE_SUB -> 美国留学 -> VISA 美国签证 -> 行前准备::飞跃同期声 -> 异乡岁月※海外申请

使用道具 举报

Rank: 1

声望
0
寄托币
27
注册时间
2005-10-24
精华
0
帖子
0
6
发表于 2005-11-4 19:30:39 |只看该作者
我也选C
256*4
write-through 方式是每次仅将修改的内容更新cache和主存,而不是将一块重新写入内存。
本来这种方式就增加了bus的流量,如果还将整块更新bus压力就更大了!
这样想简直把designer看扁了:)

请参考《计算机系统结构》第2 版,汤志忠,清华大学出版社 P196:
写直法(即write-through)是指将CPU在执行写操作时,必须把数据同时写入Cache和主存。这样,在Cache的块表中就不需要“修改位”。...

(这样是不可能把整块写回去的)

使用道具 举报

RE: 再问一个CS Practice Book上的第20题 [修改]

问答
Offer
投票
面经
最新
精华
转发
转发该帖子
再问一个CS Practice Book上的第20题
https://bbs.gter.net/thread-357221-1-1.html
复制链接
发送
回顶部