随笔-处理器微架构-测量最大IPC(流水线宽度)
固定cpu频率
随笔-处理器微架构-固定cpu频率 - LiYanbin - 博客园
max_ipc_test.sh
#!/bin/bash
[[ -z "$1" || -z "$2" ]] && {
echo "usage: $0 [cpuid] [nop_count]"
exit
}
cpuid=$1
nop_count=$2
echo 'void main() { do {__asm__ (' > nop.c
for ((i = 1; i <= $nop_count; i++)); do
echo '"nop\n\t"' >> nop.c;
done
echo ');} while(1);}' >> nop.c
gcc -O0 nop.c -o nop
echo $?
[[ $? -ne 0 ]] && exit -1
set -x
[ -f ./nop ] && {
perf stat -C $cpuid --timeout 2000 taskset -c $cpuid ./nop
}
set +x
rm nop.c
rm nop
$ sudo bash max_ipc_test.sh 7 4
...
12,290,206,450 instructions # 3.97 insn per cycle
...
当nop_count较小,可能因为while(1)
分支指令达不到max ipc,可以增加nop_count来弱化while(1)
分支指令
本文来自博客园,作者:LiYanbin,转载请注明原文链接:https://www.cnblogs.com/stellar-liyanbin/p/18414475