相关疑难解决方法(0)

内存屏障是否确保缓存一致性已完成?

假设我有两个线程来操纵全局变量x.每个线程(或我认为的每个核心)都有一个缓存副本x.

现在说Thread A执行以下说明:

set x to 5
some other instruction
Run Code Online (Sandbox Code Playgroud)

现在set x to 5执行时,缓存的值x将设置为5,这将导致缓存一致性协议使用新值来操作和更新其他核心的缓存x.

现在我的问题是:什么时候x实际设置5Thread A缓存中,其他内核的缓存在some other instruction执行之前是否会更新?或者应该使用内存屏障来确保?:

set x to 5
memory barrier
some other instruction
Run Code Online (Sandbox Code Playgroud)

注意:假设指令是按顺序执行的,也假设set x to 5执行时,5会立即放入线程A的缓存中(因此指令不会放在队列中或稍后要执行的内容).

x86 assembly operating-system memory-barriers cpu-cache

16
推荐指数
2
解决办法
1513
查看次数

CPU缓存如何影响C程序的性能

我试图更多地了解 CPU 缓存如何影响性能。作为一个简单的测试,我将矩阵第一列的值与不同数量的总列数相加。

// compiled with: gcc -Wall -Wextra -Ofast -march=native cache.c
// tested with: for n in {1..100}; do ./a.out $n; done | tee out.csv
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

double sum_column(uint64_t ni, uint64_t nj, double const data[ni][nj])
{
    double sum = 0.0;
    for (uint64_t i = 0; i < ni; ++i) {
        sum += data[i][0];
    }
    return sum;
}

int compare(void const* _a, void const* _b)
{
    double const a = *((double*)_a);
    double …
Run Code Online (Sandbox Code Playgroud)

c performance cpu-cache

16
推荐指数
1
解决办法
1144
查看次数

intel core i7处理器使用哪种缓存映射技术?

我已经了解了不同的缓存映射技术,如直接映射,关联映射和集合关联映射技术,还学习了权衡.但我很好奇现在在intel core i7或AMD处理器中使用了什么.以及这些技术是如何演变的.还有哪些事情需要改进?

x86 amd intel cpu-architecture cpu-cache

8
推荐指数
1
解决办法
2255
查看次数