最近程序需要支持CGSL系统运行,测试中发现相同操作系统的两台机器,编译机运行正常,测试机coredump。core信息汇总如下,可以看出是由于测试机不支持编译后的指令导致的问题:

Program terminated with signal 4, Illegal instruction.

   0x00007fad269ac973 <+435>:   add    $0x4,%rdx
0x00007fad269ac977 <+439>: lea -0x1010101(%rcx),%eax
=> 0x00007fad269ac97d <+445>: andn %eax,%ecx,%eax
0x00007fad269ac982 <+450>: and $0x80808080,%eax 0x00007f26c8b37e87 <+181>: lea 0x28(%rax),%rsi
0x00007f26c8b37e8b <+185>: mov -0x38(%rbp),%rax
=> 0x00007f26c8b37e8f <+189>: vmovdqa -0x60(%rbp),%xmm0
0x00007f26c8b37e94 <+194>: vmovdqu %xmm0,0x10(%rsp)
0x00007f26c8b37e9a <+200>: movl $0x0,0x8(%rsp) 0x00007f2f5d5c282e <+216>: js 0x7f2f5d5c2837
=> 0x00007f2f5d5c2830 <+218>: vcvtsi2ss %rax,%xmm0,%xmm0
0x00007f2f5d5c2835 <+223>: jmp 0x7f2f5d5c284c
0x00007f2f5d5c2837 <+225>: mov %rax,%rdx

两台机器操作系统完全一致,内核和gcc版本如下:

[CGSLv5]# uname -a
Linux CGSLv5-2965 3.10.0-693.21.1.el7.x86_64 #1 SMP Fri Mar 30 15:43:35 CST 2018 x86_64 x86_64 x86_64 GNU/Linux
[CGSLv5]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-ZTEOS-linux/4.8.5/lto-wrapper
Target: x86_64-ZTEOS-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-ZTEOS-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-ZTEOS-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-ZTEOS-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
[CGSLv5]#

  

通过<<Intel® 64 and IA-32 Architectures Software Developer’s Manual>>查询汇编指令andn/vmovdqa/vcvtsi2ss归属的指令集, 可以看到这三个指令分别归属与BMI1/AVX

查询编译机和测试机的CPU信息和flags如下,确认测试机不支持BMI1/AVX/AVX2(也可以参考Intel对E5-2680和E5260的介绍):

编译机器:
[compiler@CGSLV5]# cat /proc/cpuinfo | grep "model name" | uniq -c
56 model name : Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts 测试机器:
[compiler@CGSLV5]# cat /proc/cpuinfo | grep "model name" | uniq -c
16 model name : Intel(R) Xeon(R) CPU E5620 @ 2.40GHz flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 popcnt aes lahf_lm epb tpr_shadow vnmi flexpriority ept vpid dtherm arat

针对指令集的问题,GCC可以通过设置编译选项-march/-mtune来处理,具体参考<<Intel 386 and AMD x86-64 Options>>,截取一部分如下:

-march=cpu-type
Generate instructions for the machine type cpu-type. In contrast to -mtune=cpu-type, which merely tunes the generated code for the specified cpu-type, -march=cpu-type allows GCC to generate code that may not run at all on processors other than the one indicated. Specifying -march=cpu-type implies -mtune=cpu-type. The choices for cpu-type are:
‘native’
This selects the CPU to generate code for at compilation time by determining the processor type of the compiling machine. Using -march=native enables all instruction subsets supported by the local machine (hence the result might not run on different machines). Using -mtune=native produces code optimized for the local machine under the constraints of the selected instruction set.
‘core2’
Intel Core CPU with -bit extensions, MMX, SSE, SSE2, SSE3 and SSSE3 instruction set support.
‘corei7’
Intel Core i7 CPU with -bit extensions, MMX, SSE, SSE2, SSE3, SSSE3, SSE4. and SSE4. instruction set support.
‘corei7-avx’
Intel Core i7 CPU with -bit extensions, MMX, SSE, SSE2, SSE3, SSSE3, SSE4., SSE4., AVX, AES and PCLMUL instruction set support.
‘core-avx2’
Intel Core CPU with -bit extensions, MOVBE, MMX, SSE, SSE2, SSE3, SSSE3, SSE4., SSE4., AVX, AVX2, AES, PCLMUL, FSGSBASE, RDRND, FMA, BMI, BMI2 and F16C instruction set support.

一般来说编译时设置了-march=native,才会出现本地机器指令集都支持,但很有可能导致编译后的程序不能在其它机器上运行的结果。查询编译选项发现-march=native,删除后通过objdump反汇编编译后程序确认不再生成BMI/AVX指令,测试机器验证运行正常。

修改前:
[CGSLv5]# objdump -d libTest.so | grep vcvtsi2ss
: c4 e1 fa 2a c0 vcvtsi2ss %rax,%xmm0,%xmm0
: c4 e1 fa 2a c2 vcvtsi2ss %rdx,%xmm0,%xmm0
640a6: c4 e1 fa 2a c0 vcvtsi2ss %rax,%xmm0,%xmm0
640b9: c4 e1 fa 2a c1 vcvtsi2ss %rcx,%xmm0,%xmm0
640d3: c4 e1 f2 2a ca vcvtsi2ss %rdx,%xmm1,%xmm1
640e6: c4 e1 f2 2a c8 vcvtsi2ss %rax,%xmm1,%xmm1
: c4 e1 f2 2a ce vcvtsi2ss %rsi,%xmm1,%xmm1
: c4 e1 f2 2a cf vcvtsi2ss %rdi,%xmm1,%xmm1
: c4 e1 f2 2a ce vcvtsi2ss %rsi,%xmm1,%xmm1
: c4 e1 f2 2a cf vcvtsi2ss %rdi,%xmm1,%xmm1
641a2: c4 e1 fa 2a c0 vcvtsi2ss %rax,%xmm0,%xmm0
641b5: c4 e1 fa 2a c2 vcvtsi2ss %rdx,%xmm0,%xmm0
[CGSLv5]# 修改后:
[CGSLv5]# objdump -d libTest.so | grep vcvtsi2ss
[CGSLv5]#

当然,也可以直接指定选项-march的值,像我的机器查询出来有以下几种cpu-type,可以通过指定 -march=corei7 来屏蔽BMI/AVX/AVX2指令集:

[localhost]# gcc -c -Q -march=native --help=target  | grep -E "avx|arch"
-march= core-avx2
-mavx [enabled]
-mavx2 [enabled]
-mavx256-split-unaligned-load [disabled]
-mavx256-split-unaligned-store [disabled]
-mprefer-avx128 [disabled]
-msse2avx [disabled] -march= corei7
-mavx [disabled]
-mavx2 [disabled]
-mavx256-split-unaligned-load [disabled]
-mavx256-split-unaligned-store [disabled]
-mprefer-avx128 [disabled]
-msse2avx [disabled] -march= corei7-avx
-mavx [enabled]
-mavx2 [disabled]
-mavx256-split-unaligned-load [disabled]
-mavx256-split-unaligned-store [disabled]
-mprefer-avx128 [disabled]
-msse2avx [disabled]
-mtune= corei7-avx

几个问题:

. 如果GCC编译选项没有设置-march, 那么默认这个选项是什么?
. 理论来讲,设置-march=native可以使用本机器支持的全部指令集,从而得到更优的性能,但降低了程序对不同机器的兼容性;不设置-march=native或设置为其它选项虽然理论上降低了程序性能,但程序兼容性大大增加;如何取舍?
3. docker是Build once,run anywhere, 那对于这种情况, 同一个docker程序镜像可以在这两台机器上运行吗?

可以参考的网址:

Intel® Xeon® Processor E5620(Intel® SSE4.):
https://ark.intel.com/products/47925/Intel-Xeon-Processor-E5620-12M-Cache-2-40-GHz-5-86-GT-s-Intel-QPI- Intel® Xeon® Processor E5-(Intel® AVX):
https://ark.intel.com/products/64583/Intel-Xeon-Processor-E5-2680-20M-Cache-2-70-GHz-8-00-GT-s-Intel-QPI- gcc-online-docs:
https://gcc.gnu.org/onlinedocs/ i386-x86--option of gcc4.8.5:
https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/Option-Summary.html#Option-Summary
https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/i386-and-x86-64-Options.html#i386-and-x86-64-Options avx(Advanced Vector Extensions):
https://software.intel.com/zh-cn/articles/introduction-to-intel-advanced-vector-extensions
https://software.intel.com/en-us/blogs/2015/01/15/vector-programming-sse42-to-avx2-conversion-examples
https://software.intel.com/en-us/articles/introduction-to-intel-advanced-vector-extensions Intel® and IA- Architectures Software Developer’s Manual:
https://software.intel.com/en-us/articles/intel-sdm x86/amd64 fast online instruction reference from Intel Architectures Software Developer’s Manual:
http://www.felixcloutier.com/x86/

CPU指令集不同导致的core分析的更多相关文章

  1. 一个符号冲突导致的core分析

    问题描述: 修改跟踪程序(Trace)支持IPV6时,发现程序启动后正常,但是客户端一旦下发查询条件进行跟踪,Trace程序就直接coredump! (gdb) bt # 0x00007f7dab9e ...

  2. CPU指令集

    cpu作为一台电脑中的核心,它的作用是无法替代的.而cpu本身只是在块硅晶片上所集成的超大规模的集成电路,集成的晶体管数量可达到上亿个,是由非常先进复杂的制造工艺制造出来的,拥有相当高的科技含量. C ...

  3. php-cgi占用太多cpu资源而导致服务器响应过慢

    服务器环境:redhat linux 5.5 , nginx ,  phpfastcgi 在此环境下,一般php-cgi运行是非常稳定的,但也遇到过php-cgi占用太多cpu资源而导致服务器响应过慢 ...

  4. 【转】STM32擦除内部FLASH时间过长导致IWDG复位分析

    @20119-01-29 [小记] STM32擦除内部FLASH时间过长导致IWDG复位分析

  5. 关于display:inline-block布局导致错位问题分析

    移动端设计稿需求是这样的,如下图: 未知的几个头像从左至右并行居中排列. 一般可能直接使用float,但是设计图要求头像排列始终是居中的,于是想到要让它们成为行内元素,然后可使用的方法有flex bo ...

  6. 编译TensorFlow CPU指令集优化版

    编译TensorFlow CPU指令集优化版 如题,CPU指令集优化版,说的是针对某种特定的CPU型号进行过优化的版本.通常官方给的版本是没有针对特定CPU进行过优化的,有网友称,优化过的版本相比优化 ...

  7. CPU 指令集(Instruction Set Architecture, ISA)

    本文摘自网络 概念 指令集是存储在CPU内部,对CPU运算进行指导和优化的硬程序,用来引导CPU进行加减运算和控制计算机操作系统的一系列指令集合.拥有这些指令集,CPU就可以更高效地运行.系统所下达的 ...

  8. HMS Core 分析服务 6.4.1版本上线啦,快来看看更新了哪些内容。

    更新概览 支持转化事件回传至华为应用市场商业推广,便捷归因,实时调优. 卸载分析模型支持用户卸载前事件和路径分析,深度剖析卸载根因. 实时漏斗体验开放,灵活定位异常流失. 详情介绍 更新一:全面开放深 ...

  9. 如何科学衡量广告投放效果?HMS Core分析服务助您科学归因

    日益多元化的广告形式以及投放成本的不断攀升,让广告主们更加关注每一次广告投放带来的实际价值. 然而,广告主一般仅能从平台获得展示.点击.下载等前端效果字段,实际的用户注册.激活等后端深度转化指标并无法 ...

随机推荐

  1. IOError: [Errno 22] invalid mode ('rb') or filename: 'F:\netData1.mat'

    这种错误的出现是在使用built-in函数file()或者open()的时候.或者是因为文件的打开模式不对,或者是文件名有问题.前者的话只需要注意文件是否可读或者可写就可以了.后者则是与文件路径相关的 ...

  2. js获取对象所有的keys

    Js中获取对象的所有key值   假如现在有一个对象 var obj = { A:2 ,B:"Ray" ,C:true ,D:function(){} } 如果想遍历对象obj中的 ...

  3. bootstarp v3 学习简记

    1.快速设置浮动通过这两个class让页面元素左右浮动. !important被用来避免某些问题. <div class="pull-left">...</div ...

  4. Python2.x 和 3.x 的区别

    Python有两个版本,2.x 和 3.x ,两个版本不兼容,3.x 不不考虑对2.x代码的向后兼容. 在3.x中,一些语法,内建函数和对象的行为都有所调整. 大部分的python库都支持 pytho ...

  5. C#继承的多态性

    C#继承的多态性 当一个类A派生出新类B时,这个基类A在新类B中可以表现为不同的类型:用作它自己的类型.基类型,或者在实现接口时用作接口类型,我们将这种情况称为多态性. C#中的每种类型都是多态性的, ...

  6. 初尝微信小程序2-基本框架

    基本框架: .wxml :页面骨架 .wxss :页面样式 .js :页面逻辑    描述一些行为 .json :页面配置 创建一个小程序之后,app.js,app.json,app.wxss是必须的 ...

  7. angular2中一种换肤实现方案

    思路:整体思路是准备多套不同主题的css样式.在anguar项目启动时,首先加载的index.html中先引入一套默认的样式.当我们页面有动作时再切换css.  可以通过url传参触发,也可以通过bu ...

  8. LNMP+HAProxy+Keepalived负载均衡 - 基础服务准备

    日志服务 修改日志服务配置并重启日志服务: ``` vim /etc/rsyslog.conf ``` 编辑系统日志配置,指定包含的配置文件路径和规则: ``` $IncludeConfig /etc ...

  9. 【Mysql】给mysql配置远程登录

    grant all privileges on 库名.表名 to '用户名'@'IP地址' identified by '密码' with grant option; flush privileges ...

  10. python--随笔一

    1.format函数--根据关键字和位置选择性插入数据 In [11]: '{mingzi}jintian{dongzuo}'.format(mingzi='duzi',dongzuo='i love ...