简体   繁体   English

如何根据开销计算缓存块大小?

[英]How to calculate cache block size from its overhead?

I've being looking for this for a lot of time now (over 3 days) without luck.我现在(超过 3 天)一直在寻找这个,但没有运气。 Maybe one of you guys can tell me how can I solve it.也许你们中的一个人可以告诉我我该如何解决它。

Consider you have a computer with a 16-bit size address and a byte addressable memory.假设您有一台具有 16 位大小的地址和字节可寻址存储器的计算机。 The cache is 2-way set-associative mapped, write-back policy and a perfect LRU replacement strategy.缓存是 2 路组关联映射、回写策略和完美的 LRU 替换策略。 Cache has an overhead of 4352 bits.缓存有 4352 位的开销。 What's the size of the block?块的大小是多少?

Very few resources talk about overhead and the ones I've found only relate it to total cache size.很少有资源谈论开销,而我发现的资源只与总缓存大小相关。 The problem is I only know how to calculate cache size with #blocks or at least with the fields of the address properly defined (which I have not being able to do for this problem since I can't calculate the size of the tag.).问题是我只知道如何使用#blocks 或至少使用正确定义的地址字段来计算缓存大小(我无法解决这个问题,因为我无法计算标签的大小。) .

Any help would be appreciated.任何帮助,将不胜感激。

So, here's how I read this question:所以,这就是我阅读这个问题的方式:

Overhead bits are the bits that don't count toward the actual data that is being cached.开销位是不计入正在缓存的实际数据的位。 They are bits that track maintenance state of the cache, and help the cache implement hits, write back, and eviction policy.它们是跟踪缓存维护状态的位,并帮助缓存实现命中、回写和驱逐策略。 To some way of looking at it, if one byte is being cached (8 bits) how many non-data bits are in the cache to help manage that (or at least for all the actual data bits how many non-data/overhead bits are there).以某种方式看待它,如果一个字节被缓存(8位),缓存中有多少非数据位来帮助管理它(或至少对于所有实际数据位,有多少非数据/开销位在那儿)。

This is mathematical, so I hope I haven't made an error, but even if I have maybe you can see your way through the reasoning.这是数学,所以我希望我没有犯错误,但即使我有,也许你可以通过推理看到你的方式。

Let's derive some additional information:让我们得出一些额外的信息:

A write-back policy means the cache needs to store "dirty" information for each data block: dirty is 1-bit: yes, dirty -or- no, clean.回写策略意味着缓存需要为每个数据块存储“脏”信息:脏是 1 位:是,脏 - 或 - 否,干净。

For 2-way set associative cache, a "perfect" LRU algorithm is also 1 bit (yes: first block -or- no: second block) but this 1 bit costs per index position (ie per line) — not per block as there are two blocks per index.对于 2-way set associative cache,一个“完美”的 LRU 算法也是 1 位(是:第一个块 - 或 - 否:第二个块),但是这个 1 位成本每个索引位置(即每行) - 不是每个块每个索引是两个块。

What we don't know is if there is a valid bit, which would also be per data block, but most caches I see in coursework have the valid bits, so we might assume they have it.我们不知道是否有一个有效位,这也是每个数据块,但我在课程作业中看到的大多数缓存都有有效位,所以我们可能会假设它们有它。

And lastly, there's the tag bits where tag bits are: however many bits are leftover in the address space bits after accounting for index bits and block offset bits.最后,还有标记位所在的标记位:但是在考虑了索引位和块偏移位之后,地址空间位中剩余的许多位。

So, a formula for overhead might be:因此,开销的公式可能是:

overhead in bits = index positions * (1 x LRU bit + block overhead bits)位开销 = 索引位置 * (1 x LRU 位 + 块开销位)

where block overhead bits = 2 [ways] * (1 x Dirty bit + 1 x Valid bit + tag bits)其中块开销位 = 2 [方式] * (1 x 脏位 + 1 x 有效位 + 标记位)

We also know that tag bits = address space bits - index bits - block bits我们也知道标签位=地址空间位-索引位-块位

So, we have:所以,我们有:

  • 4352 [overhead in bits] = index positions * (1 + 2 * (2 + tag bits)) 4352 [位开销] = 索引位置 * (1 + 2 * (2 + 标签位))

    -and- -和-

  • tag bits = address space bits - index bits - block offset bits标签位 = 地址空间位 - 索引位 - 块偏移位

    -and- -和-

  • index positions = 2 index bits索引位置 = 2 个索引位

    -and- -和-

  • We also know that the number of tag, index, and block offset bits has to be an integer (no fractions of bits).我们还知道标签、索引和块偏移位的数量必须是整数(没有位的分数)。

So, we can begin to reduce those two formulas by substituting:因此,我们可以通过代入来减少这两个公式:

4352 = index positions * (1 + 2 * (2 + address space bits - index bits - block bits) 4352 = 索引位置 * (1 + 2 * (2 + 地址空间位 - 索引位 - 块位)

by reduction also then:然后通过减少:

4352 = 2 index bits * (1 + 2 * (2 + 16 - index bits - block bits) 4352 = 2 个索引位* (1 + 2 * (2 + 16 - 索引位 - 块位)

Solving for block bits we have:解决我们有的块位:

-((4352/2 index bits - 1)/2 - 18 + index bits) = block bits -((4352/2索引位- 1)/2 - 18 + 索引位) = 块位

I don't know how to solve this directly mathematically, given the constraint that the variables must be integers, so, instead of solving directly, simply try/search different values:考虑到变量必须是整数的约束,我不知道如何直接在数学上解决这个问题,因此,与其直接求解,不如简单地尝试/搜索不同的值:

If index bits is 7 then by this formula, block bits is fractional, so that doesn't work.如果索引位是 7,那么通过这个公式,块位是小数,所以这不起作用。

If index bits is 9 then by this formula, block bits is fractional, so that doesn't work.如果索引位是 9,那么通过这个公式,块位是小数,所以这不起作用。

No other values between 0 and 16 result in an integer number of bits, except: 0 到 16 之间的其他值不会产生整数位数,除了:

If index bits is 8 then by this formula, block bits is 2, so:如果索引位是 8,那么通过这个公式,块位是 2,所以:

16 = tag bits + 8 + 2, meaning tag bits is 6, index bits is 8, and block offset is 2. 16 = tag bits + 8 + 2,表示tag bits为6,index bits为8,block offset为2。

Since block offset is 2 then block size is 2 2 .由于块偏移量为2 ,因此块大小为 2 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM