关于Vtune测量branch misprediction的问题

haojn 2008-04-08 04:55:49
作归并排序的时候想测量一下分支预测失败对归并时性能的影响,于是在vtune中增加branch misprediction performance impact。测量后,该数值居然为0,但理论上讲因为热点部分的分支都是数据相关的,分支预测不可能有这么高。

另外,我特地写了个绝对是数据相关的分支程序:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

#define N 10000000

int aa[N];

int main( void )
{
int i;
srand( (unsigned)time( NULL ) );
for (i=0;i<N;i++){
int a,b;
a=rand();
b=rand();
if (a>b){
aa[i]=a;
}
else{
aa[i]=b;
}
}
}
因为都是随机数据,我认为分支预测错误率在if语句块50%左右才对,但测量的结果branch misprediction performance impact只有0.77%

是vtune哪里设置错了么?如何才能正确地观察到分支预测错误率?

谢谢!
...全文
509 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
jcven 2008-05-14
  • 打赏
  • 举报
回复
ding
beblue 2008-05-12
  • 打赏
  • 举报
回复
我顶一个
intel_iclifort 2008-04-11
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 haojn 的回复:]
谢谢!Software Developer's Manuals我也看过,里面关于架构的介绍同样很少。我希望的是一些更为学术的数据,类似于Computer Architecture,A Quantitative Approach中关于NetBurst的内容
[/Quote]

这几个帖子已经介绍的比较详细了

Intel Core 微架构全面解析: http://www.ocer.net/article/a_show.php?id=3675

Intel Core 微架构 vs. AMD K8 微架构 http://www.ocer.net/article/a_show.php?id=3954

Intel Core vs. AMD K8 : CPU架构分析 http://www.highdiy.com/html/cpu/eva/223.shtml

Intel Core架构再解析 http://www.highdiy.com/html/cpu/eva/279.shtml
intel_iclifort 2008-04-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 haojn 的回复:]
谢谢!基本上明白了

有没有对于Core 2微架构详细的技术资料呢?Optimization Reference Manual中的介绍太笼统了

[/Quote]

很多问题在 Intel® 64 and IA-32 Architectures Software Developer's Manuals 中有介绍, 看看Volume 1: Basic Architecture和Volume 3A: System Programming Guide, 这里下载PDF文档: http://www.intel.com/products/processor/manuals/index.htm


haojn 2008-04-10
  • 打赏
  • 举报
回复
谢谢!Software Developer's Manuals我也看过,里面关于架构的介绍同样很少。我希望的是一些更为学术的数据,类似于Computer Architecture,A Quantitative Approach中关于NetBurst的内容
haojn 2008-04-09
  • 打赏
  • 举报
回复
谢谢!基本上明白了

有没有对于Core 2微架构详细的技术资料呢?Optimization Reference Manual中的介绍太笼统了

有几个新问题,关于Core 2架构:
1、Cache有没有分sub-block?
2、目前的分支预测用的是什么算法?
3、L1 Cache的一致性协议用的是写无效么?在Quad中,L2的一致性是通过北桥来实现的?协议是什么?
haojn 2008-04-09
  • 打赏
  • 举报
回复
谢谢!

目前是calibration based on selected properties
这个calibration主要的作用是什么呢?

RESOURCE_STALLS.BR_MISS_CLEAR的sample after是2299,有什么含意么?


程序改为:
int a;

int aa[N];
int bb[N];

int b;

int main( void )
{
int i;
srand( (unsigned)time( NULL ) );
for (i=0;i<N;i++){
a=rand();
b=rand();
if (a>b){
aa[i]=a;
}
else{
bb[i]=b;
}
}
}
这样源和目的操作数都不在同一cache line,如果分支预测错误应该有更大的排空周期,但测得的结果还是只有0.1%
intel_zhenyuwang 2008-04-09
  • 打赏
  • 举报
回复
首先,样本为零的问题-主要是“事件”发生的次数不够,可用VTune的"Calibration"设置去调节"Sample After" Value,或手工改。

if (a>b){
aa[i]=a;
// 实体不够,二个分支都在相同的Cache line.
}
else{
aa[i]=b;
}

intel_zhenyuwang 2008-04-09
  • 打赏
  • 举报
回复
"calibration" 是VTune帮助你测量多少次事件发生后产生一个中断,收集一个样本。

RESOURCE_STALLS.BR_MISS_CLEAR的sample after是2299, 即是- 分支误测一起的阻塞发生2299次后收集一个样本.

设置"Sample After" of RESOURCE_STALLS.BR_MISS_CLEAR = 2000
设置"Sample After" of BR_INST_RETIRED.MISPRED = 2000

Process RESOURCE_STALLS.BR_MISS_CLEAR samples BR_INST_RETIRED.MISPRED samples Branch Misprediction Performance Impact

SimpleTest.exe 525 2588 0.07%

可见,分支误测确实发生,但影响不大。

把你的程序改为:
int a;

int aa[N];
int bb[N];

int foo(int);
int _tmain(int argc, _TCHAR* argv[])
{
int i;

srand( (unsigned)time( NULL ) );

for (i=0;i <N;i++){
a=rand();
b=rand();
if (a>b){
aa[i]=a;
foo(a);
}
else{
bb[i]=b;
}
}

return 0;
}

int foo(int a)
{
return (++a);
}

结果RESOURCE_STALLS.BR_MISS_CLEAR Samples 加倍了, 但 Branch Misprediction Performance Impact 影响不明显。
Process RESOURCE_STALLS.BR_MISS_CLEAR samples BR_INST_RETIRED.MISPRED samples Branch Misprediction Performance Impact

SimpleTest.exe 1014 3380 0.10%

为何?主要是Intel 架构有很多branch target buffer...你的程序不够复杂,试试switch_case加多跳转。



haojn 2008-04-08
  • 打赏
  • 举报
回复
我现在还没做并行呢

单线程的用23.35秒,N=2^27,全随机数据(MKL,标准VSL_BRNG_MCG31,UNIFORM,初始种子12345),Q6600@2.4G

parallel_sort我这里用6.85秒,其实就是多线程的qsort
denghui0815 2008-04-08
  • 打赏
  • 举报
回复
haojn 你做的归并 能否超越TBB的parallel_sort?

567

社区成员

发帖
与我相关
我的任务
社区描述
英特尔® 边缘计算,聚焦于边缘计算、AI、IoT等领域,为开发者提供丰富的开发资源、创新技术、解决方案与行业活动。
社区管理员
  • 英特尔技术社区
  • shere_lin
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧