这几天一直在参加IBM的面试,应该不是统一的校招,是组内招聘,一直没有写这个面经,是因为我感觉不是一篇面经可以总结的,我一直觉得IBM的笔试我就应该挂了,因为除了语言基础和数据结构方面我写的还行,网络和操作系统 还有linux的我完全都忘了或者不会。 我现在在这立一个字据,我真的要开始学linux了,我觉得不会linux,不深入了解他,就像不会编程一样痛苦,我要是感觉还不能掌握linux,我就不结婚了。然后一面是一个和两个女的面试的,一大一小,但是感觉懂得挺多的,他们问的基础一点,在最后解决吧。先从痛苦的二面开始回忆,简直一个被吊打的过程,可以看出面试官是多么厉害,以至于我当时都扛不住了,旁边的那个姐姐都快笑了虐的我。。后来听别人说他是他们的技术大亨,总觉得和这种人在一起工作是一种享受,就像上次阿里一面和二面的那做技术的。在这里我又不得不吐槽一下阿里的三面,视频面试,听不清啊听不清,反复问了好几次。而且问的是我最应付的项目,要写的都写出来了,但是还是给我没通过。扯远了,还是回到今天痛苦的回忆上吧。
面试开始,我先自我介绍,说了我的项目,说完之后,大亨话题一转,你是哪个实验室的,我说高性能,那他说你说下超标量计算机的概念以及和普通计算机的不同。我去。。。这么专业,超标量。。。我不知道啊。。当我吞吞吐吐瞎侃的时候,他已经没有兴趣听了。
下面我给出超标量计算机的一些概念:
超标量是通过内置多条流水线来同时执行多个处理器,以实现一个周期内处理多条指令,其实质是以空间换取时间。思想:多条流水线并行工作,提高指令集并行度。硬件要求多套独立译码电路。多条独立流水线,控制器。
之后,他看我做的项目是多核的,他说多核情况下怎么保证cahce一致性问题,咋说呢,好几次都被问到,我一直就没有和别人讲清楚过,因为我们真的不用在乎caceh一致性,然后我就说我们做的这个没有数据共享,就跟GPU一样不会产生cache一致性问题,然后他说,cache一致性是体系结构中,最基本的概念,你讲一讲大致的模型吧,我在那纠结了半天也没有说出来真的是忘了,我说我记得cache的替换策略,什么的。他就没有逼问我了,下面来总结一下cache的一些基本知识吧。
Every cache line is marked with one of the four following states (coded in two additional bits):
-
Modified
- The cache line is present only in the current cache, and is dirty - it has been modified from the value in main memory. The cache is required to write the data back to main memory at some time in the future, before permitting any other read of the (no longer valid) main memory state. The write-back changes the line to the Shared state. Exclusive
- The cache line is present only in the current cache, but is clean - it matches main memory. It may be changed to the Shared state at any time, in response to a read request. Alternatively, it may be changed to the Modified state when writing to it. Shared
- Indicates that this cache line may be stored in other caches of the machine and is clean - it matches the main memory. The line may be discarded (changed to the Invalid state) at any time. Invalid
- Indicates that this cache line is invalid (unused).
- 读请求的条件( except Invalid )
写请求的条件(Modified or Exclusive)
A write may only be performed if the cache line is in the Modified or Exclusive state. If it is in the Shared state, all other cached copies must be invalidated first. This is typically done by a broadcast operation known as Request For Ownership (RFO).
丢弃(non-Modified)
A cache may discard a non-Modified line (i.e. Shared or Exclusive) at any time, changing to the Invalid state. A Modified line must be written back first.
监听(Modified)
A cache that holds a line in the Modified state must snoop (intercept) all attempted reads (from all of the other caches in the system) of the corresponding main memory location and insert the data that it holds. This is typically done by forcing the read to back off (i.e. retry later), then writing the data to main memory and changing the cache line to the Shared state.
监听(Shared)
A cache that holds a line in the Shared state must listen for invalidate or request-for-ownership broadcasts from other caches, and discard the line (by moving it into Invalid state) on a match.
监听(Exclusive )
A cache that holds a line in the Exclusive state must also snoop all read transactions from all other caches, and move the line to Shared state on a match.
A Read For Ownership (RFO) is an operation in cache coherency protocols that combines a read and an invalidate broadcast. The operation is issued by a processor trying to write into a cache line that is in the shared (S) or invalid (I) states of the MESI protocol. The operation causes all other cache to set the state of such a line to I. A read for ownership transaction is a read operation with intent to write to that memory address. Therefore, this operation is exclusive. It brings data to the cache and invalidates all other processor caches which hold this memory line.
关于这个状态转换的http://blog.youkuaiyun.com/muxiqingyang/article/details/6615199这篇文章讲的很不错,我就不复制了。
从结构的角度来看,多处理器系统可以分为共享存储系统,和消息传递系统两类。在消息传递的系统中,每个处理器是单独编制的,二值共享存储系统中,所有的存储器是统一编址的。常见的存储一致性模型包括
严格一致性,顺序一致性处理器一致性 弱一致性 释放一致性等
严格一致性:
任何对一个内存位置X的读操作,将返回最最近的一次对该内存位置的写操作所写入的值。如果我们有很多处理器,没有缓存,通过一条总线来访问内存,那么就我们得到(或者符合)了“严格一致性内存模型”。这里最关键的是精确地序列化所有对内存的访问。
顺序一致性:
对于满足顺序一致性的多处理器的任一执行,总可以找到同意程序在单机多进程环境下的一个执行与之对应,使得二者结果相等。任何一次执行结果都相同,就像所有处理器的操作按照某个顺序执行,各个微处理器的操作按照其程序指定的顺序进行。
处理器一致性:
在任何取数操作load允许被执行前,所有在同一处理器中先于这一LOAD的取数操作都已经完成,在任一存数操作STORE允许被执行之前,所有在同意处理器中限于这一STROE的访存擦走哦都已经完成。
弱一致性:
就是同步操作和普通访存操作区分开来,程序员必须用硬件可识别的同步操作把对可写共享单元的访问保护起来,以保证多个处理器对可写共享单元的访问时互斥的。弱一致性对访存事件发生的次序做如下限制:同步操作执行满足顺序一致性条件 在任一普通访存操作被允许之前,所有在同一处理器中先于这一访存操作的同步操作必须都已经完成。在任一同步操作被允许执行之前,所有在同一处理器中限于这一同步操作的普通访存操作都已经完成。
弱一致性:
是对弱一致性的改进,它吧同步操作进一步分成获取操作acquire和释放操作release acquire用于获取对某些共享存储单元的独占性访问权,而release则用于释放这些访问控制权。释放一致性模型对访存事件发生的次序作如下限制:同步操作的执行满足顺序一致性条件; 在任意普通访存操作被允许之前,所有同意处理器中先于这一访存操作的acquire操作都已经完成,在任意release操作被允许之前,所有在同一处理器中先于这个release的普通访存操作都已经完成。
什么是cache一致性协议
cache一致性协议是吧某个处理器新写的值传播给其他的处理器一确保所有的处理器都看到一致的共享存储内容的一种机制。cache一致性协议都是为了实现某种存储一致性模型而设计的,存储一致性模型对cache一致性协议提出了一致性要求,即cache一致性协议应该实现什么样的一致性。例如在释放一致性中,一个处理器对共享变量写新值时,其他处理器只有等到该处理器释放锁之后才能看到;而在顺序一致性中,一个处理器的值会立刻传播给所有的处理器