目录
正在加载目录…
正在阅读专栏 程序员应该知道的内存专栏 第 9 篇 · 共 9 篇 · 100%

内存性能实验:基准程序、OProfile 与 DRAM

发布于 2026-09-15 23:11 · 最后编辑于 2026-09-21 18:14 · 版本 v3 · 字数 10,187 · 预计阅读 21 分钟 👁 18 次阅读

程序员应该知道的内存:附录与参考文献

本文是系列第 9 篇,整理原文中的 benchmark、branch prediction 调试代码、Cache line sharing 测试、oprofile 使用提示、内存类型说明和参考资料。

TL;DR

  • 附录用途:把第 6、7 篇中的实验思路落实为可运行的 C 代码和 profiling 命令。
  • 代码原则:代码保留原样,中文只翻译说明;运行前应根据当前 CPU、编译器和 Linux 版本调整平台相关部分。
  • 测量原则:benchmark 只能说明特定输入和特定机器上的行为;它不是所有 workload 的普遍结论。
  • 版本提醒:原文使用 OProfile、Core 2 事件和旧式 GCC intrinsic,现代环境可用 perf 等工具替代,但实验意图仍然相同。

目录

章节说明
9 Examples and Benchmark Programs附录实验程序
10 Some OProfile TipsOProfile 采样和分析
11 Memory Typesregistered 与 ECC DRAM
小结原文参考文献入口

9 Examples and Benchmark Programs

9.1 Matrix Multiplication

下面是第 6.2.1 节矩阵乘法 benchmark 的完整程序。代码使用 Intel intrinsic;SM 表示 blocking 的边长,三个矩阵显式按 64-byte 对齐。循环顺序和 block 化让数据在 Cache 中得到复用。

c
#include <stdlib.h>
#include <stdio.h>
#include <emmintrin.h>
#define N 1000
double res[N][N] __attribute__ ((aligned (64)));
double mul1[N][N] __attribute__ ((aligned (64)));
double mul2[N][N] __attribute__ ((aligned (64)));
#define SM (CLS / sizeof (double))

int
main (void)
{
  // ... Initialize mul1 and mul2
  int i, i2, j, j2, k, k2;
  double *restrict rres;
  double *restrict rmul1;
  double *restrict rmul2;
  for (i = 0; i < N; i += SM)
    for (j = 0; j < N; j += SM)
      for (k = 0; k < N; k += SM)
        for (i2 = 0, rres = &res[i][j], rmul1 = &mul1[i][k]; i2 < SM;
             ++i2, rres += N, rmul1 += N)
          {
            _mm_prefetch (&rmul1[8], _MM_HINT_NTA);
            for (k2 = 0, rmul2 = &mul2[k][j]; k2 < SM; ++k2, rmul2 += N)
              {
                __m128d m1d = _mm_load_sd (&rmul1[k2]);
                m1d = _mm_unpacklo_pd (m1d, m1d);
                for (j2 = 0; j2 < SM; j2 += 2)
                  {
                    __m128d m2 = _mm_load_pd (&rmul2[j2]);
                    __m128d r2 = _mm_load_pd (&rres[j2]);
                    _mm_store_pd (&rres[j2],
                                  _mm_add_pd (_mm_mul_pd (m2, m1d), r2));
                  }
              }
          }
  // ... use res matrix
  return 0;
}

与第 6.2.1 节最终版本相比,主要变化是把 rmul1[k2] 的加载移出最内层循环,因为需要把同一个值复制到 vector 的两个元素中;_mm_unpacklo_pd() 完成复制。三个数组显式对齐,是为了让预期处于同一 Cache line 的值确实位于同一 line 中。

9.2 Debug Branch Prediction

如果程序使用 likely 和 unlikely,可以在 debug mode 中统计预测正确和错误的次数。下面的宏利用 GNU assembler/linker 创建额外 section,并为每一个调用点保存计数、行号和文件名。

c
#ifndef DEBUGPRED
# define unlikely(expr) __builtin_expect (!!(expr), 0)
# define likely(expr) __builtin_expect (!!(expr), 1)
#else
/* debug 版本:记录每个预测点的 correct/incorrect 次数 */
# define unlikely(expr) debugpred__ ((expr), 0)
# define likely(expr) debugpred__ ((expr), 1)
#endif

真实原文中的 debugpred__ 使用 inline assembly 把计数写入 predict_data,把调用位置写入 predict_line 和 predict_file;程序退出时遍历这些 section 并打印预测结果。该 debug 数据会增加空间和 DSO relocation 成本,不应编译进 production binary。

原文给出的 GNU x86-64 实现如下;它在每个预测调用点分别保存 correct/incorrect counter、source line 和 source file:

c
#ifndef DEBUGPRED
# define unlikely(expr) __builtin_expect (!!(expr), 0)
# define likely(expr) __builtin_expect (!!(expr), 1)
#else
asm (".section predict_data, \"aw\"; .previous\n"
     ".section predict_line, \"a\"; .previous\n"
     ".section predict_file, \"a\"; .previous");
# ifdef __x86_64__
#  define debugpred__(e, E) \
  ({ long int _e = !!(e); \
     asm volatile (".pushsection predict_data\n" \
                   "..predictcnt%=: .quad 0; .quad 0\n" \
                   ".section predict_line; .quad %c1\n" \
                   ".section predict_file; .quad %c2; .popsection\n" \
                   "addq $1,..predictcnt%=(,%0,8)" \
                   : : "r" (_e == E), "i" (__LINE__), "i" (__FILE__)); \
    __builtin_expect (_e, E); \
  })
# elif defined __i386__
#  define debugpred__(e, E) \
  ({ long int _e = !!(e); \
     asm volatile (".pushsection predict_data\n" \
                   "..predictcnt%=: .long 0; .long 0\n" \
                   ".section predict_line; .long %c1\n" \
                   ".section predict_file; .long %c2; .popsection\n" \
                   "incl ..predictcnt%=(,%0,4)" \
                   : : "r" (_e == E), "i" (__LINE__), "i" (__FILE__)); \
    __builtin_expect (_e, E); \
  })
# else
#  error "debugpred__ definition missing"
# endif
# define unlikely(expt) debugpred__ ((expr), 0)
# define likely(expr) debugpred__ ((expr), 1)
#endif

predict_data、predict_line 和 predict_file 是 ELF section。%= 为每个调用点生成唯一的局部符号;GNU linker 会为每个 section 提供 __start_<name> 与 __stop_<name>,程序可以据此遍历所有记录:

c
extern long int __start_predict_data;
extern long int __stop_predict_data;
extern long int __start_predict_line;
extern const char *__start_predict_file;

static void
__attribute__ ((destructor))
predprint(void)
{
  long int *s = &__start_predict_data;
  long int *e = &__stop_predict_data;
  long int *sl = &__start_predict_line;
  const char **sf = &__start_predict_file;
  while (s < e) {
    printf("%s:%ld: incorrect=%ld, correct=%ld%s\n", *sf, *sl,
           s[0], s[1], s[0] > s[1] ? "   <==== WARNING" : "");
    ++sl;
    ++sf;
    s += 2;
  }
}

每个预测点在 predict_data 中占两个 word,在另外两个 section 中各占一个 word;因此三个指针可以同步递增。这里没有使用 atomic operation,因为 debug 统计允许极少量竞争,绝对精确度不值得为所有更新付出 atomic 成本。该机制会为 executable 和每个 DSO 分别生成数据;DSO 中的 file pointer 还会带来 relocation 成本,所以只能用于 debug 或测试 binary。

9.3 Measure Cache Line Sharing Overhead

该实验比较多个线程把变量放在同一 Cache line 与不同 Cache line 时的开销。测试程序为每个线程分配独立 counter,并通过 disp 控制 counter 之间的距离;disp = 0 时多个线程共享同一地址,disp != 0 时可以把它们分开。实验的关键不是代码本身,而是观察 false sharing 和 atomic update 对吞吐量的影响。

c
#define N (atomic ? 10000000 : 500000000)

static void *
tf (void *arg)
{
  long *p = arg;
  if (atomic)
    for (int n = 0; n < N; ++n)
      __sync_add_and_fetch (p, 1);
  else
    for (int n = 0; n < N; ++n) {
      *p += 1;
      asm volatile ("" : : "m" (*p));
    }
  return NULL;
}

测试程序还会把线程绑定到不同 CPU,并在结束时检查计数结果。非 atomic 循环中的空 inline asm 用来阻止编译器把递增操作移出循环;它本身不产生实际机器代码。

原文完整的测试程序如下:

c
#include <error.h>
#include <pthread.h>
#include <stdlib.h>

#define N (atomic ? 10000000 : 500000000)

static int atomic;
static unsigned nthreads;
static unsigned disp;
static long **reads;
static pthread_barrier_t b;

static void *
tf(void *arg)
{
  long *p = arg;

  if (atomic)
    for (int n = 0; n < N; ++n)
      __sync_add_and_fetch(p, 1);
  else
    for (int n = 0; n < N; ++n)
      {
        *p += 1;
        asm volatile("" : : "m" (*p));
      }

  return NULL;
}

int
main(int argc, char *argv[])
{
  if (argc < 2)
    disp = 0;
  else
    disp = atol(argv[1]);

  if (argc < 3)
    nthreads = 2;
  else
    nthreads = atol(argv[2]) ?: 1;

  if (argc < 4)
    atomic = 1;
  else
    atomic = atol(argv[3]);

  pthread_barrier_init(&b, NULL, nthreads);

  void *p;
  posix_memalign(&p, 64, (nthreads * disp ?: 1) * sizeof(long));
  long *mem = p;

  pthread_t th[nthreads];
  pthread_attr_t a;
  pthread_attr_init(&a);
  cpu_set_t c;
  for (unsigned i = 1; i < nthreads; ++i)
    {
      CPU_ZERO(&c);
      CPU_SET(i, &c);
      pthread_attr_setaffinity_np(&a, sizeof(c), &c);
      mem[i * disp] = 0;
      pthread_create(&th[i], &a, tf, &mem[i * disp]);
    }

  CPU_ZERO(&c);
  CPU_SET(0, &c);
  pthread_setaffinity_np(pthread_self(), sizeof(c), &c);
  mem[0] = 0;
  tf(&mem[0]);

  if ((disp == 0 && mem[0] != nthreads * N)
      || (disp != 0 && mem[0] != N))
    error(1, 0, "mem[0] wrong: %ld instead of %d",
          mem[0], disp == 0 ? nthreads * N : N);

  for (unsigned i = 1; i < nthreads; ++i)
    {
      pthread_join(th[i], NULL);
      if (disp != 0 && mem[i * disp] != N)
        error(1, 0, "mem[%u] wrong: %ld instead of %d",
              i, mem[i * disp], N);
    }

  return 0;
}

运行参数中的 disp 控制不同 thread 的 counter 之间相隔多少个 long。disp=0 时所有 thread 更新同一个 location;使用非零值时可以把 counter 分开,若每个 counter 之间至少相隔一个 Cache line,就能观察 false sharing 的差异。atomic=1 使用 compiler 提供的 atomic add,atomic=0 则测量普通 increment;后者的 inline asm 只是告诉 compiler 每次循环都必须消费 *p,防止优化器删除或合并 increment。

程序把第 1 个 thread 绑定到 CPU 0,其余 thread 绑定到 CPU 1、2、3……,因此测试结果不会被 scheduler 频繁迁移所掩盖。这个例子假定这些 logical CPU 编号存在;更通用的实现可以先通过 libNUMA 查询可用 CPU,但原文特意保持 benchmark 不依赖该 library。

10 Some OProfile Tips

10.1 OProfile 基础

OProfile 分为 collection 和 analysis 两阶段。collection 由 kernel 使用 CPU performance counter 完成,通常需要权限;analysis 阶段用 opreport 生成报告,用 opannotate 显示事件落在哪条 instruction 或 source line。

bash
opcontrol --event CPU_CLK_UNHALTED:30000:0:1:1
opcontrol --start
./cachebench
opcontrol --stop
opreport
opannotate --source

上面的命令只是一个最小示例。OProfile 的 collection 阶段由 kernel 完成,因为 performance counter 需要访问 CPU 的 MSR;analysis 阶段则在 user level 读取结果。每个 processor 都有自己的 counter 和 event 集合,某些 event 只能与特定 event 组合使用,因此必须先查阅目标 processor 的 architecture manual,不能把 Core 2 的 event 名称直接套用到其他 CPU。

--event 参数中的 30000 是 overrun number:counter 每累计这么多个 event,CPU 才中断一次并记录当前 instruction address。值太低会让系统大部分时间都在收集 profile,甚至无法正常运行;值太高则会降低分辨率,使真正的 hot spot 得不到代表性 sample。OProfile 是 statistical profiler,记录的是概率样本,而不是每次事件;x86 和 PowerPC 在某些情况下还能记录 backtrace,但 instruction pointer 也可能因为 out-of-order execution 而不精确。

针对独立 benchmark,通常可以选择尽可能低的 overrun number;如果被测程序与其他 process 交互、具有 realtime requirement,或者需要长时间分析整个系统,则必须选择更高的值。可以用下面的命令查询目标处理器支持的 event:

bash
opcontrol --list-events

opcontrol --start 开始采样,--stop 停止;数据先在 kernel 中累积,再批量交给 user-level daemon,必要时可用 opcontrol --dump 强制刷新。不同 profiling run 的数据可以累加,也可以在下一次运行前清空。opreport 生成按文件、DSO 或 thread 汇总的报告;opannotate 把 event 映射到 instruction 和 source line。

OProfile 的 collection 与 analysis 不必在同一台 machine 上完成。user-level 部分会按 file、DSO 甚至 thread 拆分数据,oparchive 可以把结果打包后搬到另一台机器分析。需要注意,运行期间通常需要 root 权限,但被测程序本身不必以 root 身份运行。

10.2 实际输出形态

一个典型的最小 session 是:

bash
opcontrol -i cachebench
opcontrol -e INST_RETIRED:6000:0:0:1 --start
./cachebench
opcontrol --dump
opcontrol --stop
opreport
opannotate --source

opreport 会显示 processor 型号、event、unit mask、overrun 和 sample 总数;例如 INST_RETIRED:6000 的报告可以表明某个 binary 收到了多少 retired-instruction sample。opannotate --source 则把 sample 分配到 source line。由于 processor 会 out-of-order 执行,样本可能分布在同一 loop 的相邻几行,而不一定准确落在真正触发 event 的那一条 instruction 上;对统计 profiling 而言,通常只要热点呈现出稳定趋势即可。

10.3 开始 profiling

例如,统计 INST_RETIRED 可以说明哪些 instruction 执行得最多,而统计 CPU cycle 则说明时间花在哪里(其中也包含 Cache miss 的影响)。单个 address 上只有一次 sample 没有实际意义,必须重复运行确认。对复杂程序,更有价值的通常不是绝对 sample 数,而是两个 event 的 ratio:例如 branch misprediction 除以函数调用次数,或 ITLB miss 除以 retired instruction 数。绝对值只说明总量,ratio 才更接近代码质量或某条路径的效率。

Cache 相关的 ratio 也应结合 baseline 解读:L1I_MISSES / INST_RETIRED 高,可能表示 execution flow 难以预测或 code 太大;ITLB_MISS_RETIRED / INST_RETIRED 高,可能表示 code 分布在太多 page;L1D_REPL / INST_RETIRED 高,可能表示 data locality 不佳。不同 workload 的正常值不同,任何 ratio 都不能脱离工作集与访问模式单独判断。

对 Core 2,原文列出的更细粒度指标还包括:instruction-fetch stall(CYCLES_L1I_MEM_STALLED / CPU_CLK_UNHALTED.CORE)、L2 instruction miss、store-order block、因资源不足而阻塞的 L1d load、L2 demand miss、useful NTA prefetch rate 和 late NTA prefetch rate。它们分别帮助判断 instruction/ITLB、store queue、并发 L1d access、hardware/software prefetch 是否有效。比如 L2 demand miss rate 明显大于零,说明发生 miss 的 load 根本没有被 hardware prefetch 覆盖;late prefetch rate 高,则说明软件发出 prefetch 太晚。

计算 ratio 时,两个 event 最好在同一次 profiling run 中同时采集,并先把各自的 counter 乘以对应 overrun number,再进行除法。ratio 可以在整个 program、单个 executable/DSO 或 function 层面计算,但观察范围越窄,统计误差越大。一个函数的绝对 branch-miss 数很高,可能只是因为它被调用了很多次;branch miss / call 才更能反映这段 code 的质量。任何 ratio 都必须与同类 workload 的 baseline 比较。

11 Memory Types

registered(也称 buffered)DRAM 在 memory controller 与 DRAM chips 之间增加 buffer。buffer 降低了 controller 直接驱动大量芯片的电气负担,使 server 能安装更多 DIMM,但会增加 latency、成本和功耗。unregistered module 的连接更简单,通常适合 DIMM 数量较少的 commodity system。

lwn memory 09 cpumemory.51

图 11.1:unregistered DRAM module

lwn memory 09 cpumemory.52

图 11.2:registered DRAM module

ECC DRAM 通过额外的校验信息识别错误,并在一定范围内自动纠正。DRAM cell 中的电荷非常微小,宇宙射线、alpha decay 等自然因素都可能造成 bit flip;内存容量越大,出现错误的概率越高。对不能容忍错误的 server,ECC 是可靠性与容量成本之间的必要选择。

更准确地说,ECC memory 并不是由 DRAM module 自己完成 error checking;真正计算 ECC 的是 memory controller。DRAM module 只是提供额外的 storage,并把 non-data bit 与真正的数据一起传输。写入时,memory controller 在把 data 和 ECC 送上 memory bus 之前计算校验值;读取时重新计算 ECC,并与 module 返回的 ECC 比较。两者一致就说明数据正常;不一致时,controller 尝试纠正错误,无法纠正则记录错误,并可能停止机器。

DRAM 通常使用 Hamming code。SEC(Single Error Correction)可以识别并纠正一个 flipped bit;再增加一个 parity bit 后,可以实现 SEC/DED(Single Error Correction/Double Error Detection)。数据 bit 数为 W、ECC bit 数为 E 时,基本关系是:

E = ⌈log₂(W + E + 1)⌉

Data bits WSEC 的 ECC bits ESEC overheadSEC/DED 的 ECC bits ESEC/DED overhead
4375.0%4100.0%
8450.0%562.5%
16531.3%637.5%
32618.8%721.9%
64710.9%812.5%

对 W=64 而言,SEC/DED 需要 8 个 ECC bit,开销已经足够低,而且 64 与 8 都是 8 的倍数;多数 module 上每个 RAM chip 产生 8 bit,因此这是自然的选择。

Hamming code 可以用 W=4、E=3 的例子说明。编码后的 word 中,位置为 2 的幂的 bit 用作 parity bit;P1 检查每隔一个 bit 的组合,P2 检查编码位置 3、6、7 上的数据,P4 以类似方式计算。也可以使用矩阵表达:构造 G=[I|A],其中 I 是 identity matrix、A 是 parity generation matrix;将四维数据向量 d 与 G 相乘即可得到七维编码向量 r。解码时构造 H=[Aᵀ|I],计算 H·r;结果为全零向量表示数据正确,否则结果按二进制解释后就是发生 flipped bit 的位置。

原文用图展示这些矩阵的构造关系:G 把 data vector 编码为 code word,H 用于计算 syndrome;S 与 S' 分别表示无错误和出现错误时的 syndrome。矩阵形式说明了为什么 syndrome 可以直接指出错误 bit 的位置,而不需要逐个猜测错误发生在哪里。

lwn memory 09 g matrix

图 11.3:Hamming generation matrix G

lwn memory 09 h matrix

图:parity-check matrix H

lwn memory 09 s matrix

图:无错误时的 syndrome S

lwn memory 09 sprime matrix

图:发生错误时的 syndrome S'

ECC 并不能无限纠错;错误概率取决于 memory capacity 与工作时间。server motherboard 往往会定期主动读取全部 memory,并把经过 ECC 校正的数据写回。只要在一次完整扫描期间发生两个错误的概率仍然可以接受,SEC/DED 就是合理方案。

为什么 ECC DRAM 不是所有系统的默认配置?原因与 registered DRAM 类似:额外的 RAM chip 增加成本,ECC 计算增加 latency,unregistered、non-ECC memory 可以明显更快。也因此实际 server 中通常同时看到 registered 和 ECC,而不是 registered、non-ECC 的组合。另一种方案是把数据冗余分布到多个 DRAM module 上,有些厂商把它称为“memory RAID”;但额外的 memory bus traffic 可能抵消普通 module 在访问时间上的优势。

12 libNUMA 简介

程序员需要知道如何调度 thread、如何分配 memory,才能在 NUMA machine 上获得更好性能;但当时系统能够提供的信息很难获取。现有的 NUMA support library(RHEL/Fedora 中 numactl package 的 libnuma)并不能充分满足这些需求。因此作者提出了一个新的 library,试图统一提供 NUMA 所需的功能。由于它也处理 memory hierarchy 和 Cache hierarchy,这个 library 对几乎所有 multi-thread、多-core machine 都有用,而不只限于 NUMA。

需要注意的是,这个 library 在原文写作时尚未完成、未经 review,也没有广泛发布,interface 可能发生重大变化;它依赖 /sys filesystem 导出的信息,如果 /sys 未挂载,许多函数会失败或提供不准确的信息,在 chroot jail 中尤其需要留意。

原文提出的 library interface 还包括:NUMA_cpu_system_count()/NUMA_cpu_system_mask() 获取系统 CPU 数和 mask,NUMA_cpu_self_count()/NUMA_cpu_self_mask() 获取当前 thread 可运行的 CPU,NUMA_cpu_self_current_idx() 获取当前 CPU;NUMA_cpu_to_memnode() 与 NUMA_memnode_to_cpu() 在 CPU 集合和 memory node 集合之间转换;NUMA_mem_get_node_idx() 与 NUMA_mem_get_node_mask() 查询已分配地址所在的 node。当前 CPU 和当前 memory node 的结果在函数返回时可能已经过时,只能作为 scheduling hint。

memnode_set_t 类似 cpu_set_t,但表示 memory node 集合。memory node 的数量不一定等于 CPU 数量:一个 node 可以对应多个 CPU,也可能存在没有 CPU 的 memory node。因此动态分配 bit set 时,应使用 NUMA_memnode_system_count(),不能假定 CPU 数量就是 memory node 数量。

memnode_set_t 的操作形式与 cpu_set_t 类似,但所有 MEMNODE_* macro 都需要显式传入 set size:

c
typedef memnode_set_t;
#define MEMNODE_ZERO_S(size, set)
#define MEMNODE_SET_S(node, size, set)
#define MEMNODE_CLR_S(node, size, set)
#define MEMNODE_ISSET_S(node, size, set)
#define MEMNODE_COUNT_S(size, set)
#define MEMNODE_ALLOC_SIZE(count)
#define MEMNODE_ALLOC(count)
#define MEMNODE_FREE(set)

memory node 数量可能随 system topology 或 hot-plug 变化,因此动态 bit set 应根据 NUMA_memnode_system_count() 分配,而不能用 CPU 数量推导。

例如,要为给定 CPU 找到同一 CPU 上的其他 hyper-thread,可以先用 CPU_SET 构造只包含该 CPU 的 mask,再调用 NUMA_cpu_level_mask(..., 1),最后清除原 CPU 对应的 bit。若要找到同一 processor 上的其他 core,则使用 level 2,并从结果中减去原 CPU 的 hyper-thread。获得这些 mask 后,程序可以把 helper thread 绑定到合适的 CPU;如果没有明确理由,最好保留更多选择,让 OS 参与最终调度。

对应的完整代码可以写成:

c
cpu_set_t cur;
CPU_ZERO(&cur);
CPU_SET(cpunr, &cur);

cpu_set_t hyperths;
NUMA_cpu_level_mask(sizeof(hyperths), &hyperths,
                    sizeof(cur), &cur, 1);
CPU_CLR(cpunr, &hyperths);

level=1 返回给定 CPU 的 hyper-thread 集合。若希望找到同一 processor 上的其他 core,而不是同一 core 的 hyper-thread,则还要查询 level=2,再从结果中去掉 hyperths:

c
cpu_set_t coreths;
int nhts = NUMA_cpu_level_mask(sizeof(hyperths), &hyperths,
                               sizeof(cur), &cur, 1);
int ncs = NUMA_cpu_level_mask(sizeof(coreths), &coreths,
                              sizeof(cur), &cur, 2);
CPU_XOR(&coreths, &coreths, &hyperths);
ncs -= nhts;

得到的 mask 可以用于设置另一个 thread 的 affinity;若没有明确的 placement 要求,最好把选择权交给 OS。原文也提醒,示例省略了 error handling,以及 CPU 数量超过 cpu_set_t 容量时的动态 set 处理。

参考文献

  • [amdccnuma] Advanced Micro Devices,《Performance guidelines for AMD Athlon 64 and AMD Opteron ccNUMA multiprocessor systems》,2006。
  • [arstechtwo] Jon “Hannibal” Stokes,《Ars Technica RAM Guide, Part II: Asynchronous and Synchronous DRAM》,2004。
  • [continuous] Jennifer M. Anderson 等,《Continuous profiling: Where have all the cycles gone》,1997。
  • [dcas] Simon Doherty 等,《DCAS is not a Silver Bullet for Nonblocking Algorithm Design》,2004。
  • [ddrtwo] M. Dowler,《Introduction to DDR-2: The DDR Memory Replacement》,2004。
  • [directcacheaccess] Ram Huggahalli、Ravi Iyer、Scott Tetrick,《Direct Cache Access for High Bandwidth Network I/O》,2005。
  • [dwarves] Arnaldo Carvalho de Melo,《The 7 dwarves: debugging information beyond gdb》,2007。
  • [futexes] Ulrich Drepper,《Futexes Are Tricky》,2005。
  • [goldberg] David Goldberg,《What Every Computer Scientist Should Know About Floating-Point Arithmetic》,1991。
  • [highperfdram] Vinodh Cuppu 等,《High-Performance DRAMs in Workstation Environments》,2001。
  • [htimpact] William Margo、Paul Petersen、Sanjiv Shah,《Hyper-Threading Technology: Impact on Compute-Intensive Workloads》,2002。
  • [intelopt] Intel Corporation,《Intel 64 and IA-32 Architectures Optimization Reference Manual》,2007。
  • [lockfree] Dominique Fober 等,《Lock-Free Techniques for Concurrent Access to Shared Objects》,2002。
  • [micronddr] Micron Technology,《Double Data Rate (DDR) SDRAM MT46V》,2003。
  • [mytls] Ulrich Drepper,《ELF Handling For Thread-Local Storage》,2003。
  • [nonselsec] Ulrich Drepper,《Security Enhancements in Red Hat Enterprise Linux》,2004。
  • [oooreorder] Caolán McNamara,《Controlling symbol ordering》,2007。
  • [sramwiki] Wikipedia,《Static random-access memory》,2006。
  • [transactmem] Maurice Herlihy、J. Eliot B. Moss,《Transactional memory: Architectural support for lock-free data structures》,1993。
  • [vectorops] Joe Gebis、David Patterson,《Embracing and Extending 20th-Century Instruction Set Architectures》,2007。

小结

附录中的程序把前文的抽象原则落到实验:矩阵 block 化、Cache line sharing、branch prediction 和 performance counter 都可以被测量。运行这些代码时,应把编译器、CPU 型号、线程数、CPU affinity 和内存布局记录下来,才能正确解释结果。

参考资料

← 返回列表
← 上一篇 内存未来技术:事务内存、延迟隐藏与向量化 查看专栏目录 → 程序员应该知道的内存专栏

评论 (0)

暂无评论,来留下第一条吧。
登录 或 注册 后才能发表评论