You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Intel TSX异常:xbegin指令始终返回0,事务无法提交的问题排查

RTM事务始终中止的问题排查

我正在编写包含RTM事务区域的程序,已通过cpuid指令确认机器支持HLE和RTM,但xbegin指令的rax寄存器始终返回0,表明事务已中止。为此编写了仅包含xbegin和xend指令的简单示例程序:

int main() {
    asm volatile(".byte 0xc7, 0xf8, 0x03, 0x00, 0x00, 0x00" ::"r"(-1ul)); // xbegin machine code
    asm volatile(".byte 0x0f, 0x01, 0xd5"); // xend machine code
    return 0;
}

对应的汇编代码如下:

00000000000005fa <main>:
 5fa:   48 c7 c0 ff ff ff ff    mov    $0xffffffffffffffff,%rax
 601:   c7 f8 03 00 00 00       xbeginq 60a <main+0x10>
 607:   0f 01 d5                xend   
 60a:   b8 00 00 00 00          mov    $0x0,%eax
 60f:   c3                      retq   

我将xbegin的回退地址设为xend的下一条指令,确保事务无论是否中止都能正常执行。随后使用perf工具分析执行情况,发现事务因HLE-unfriendly instructions中止,对此原因感到困惑。

Perf分析结果

事务启动统计

$ sudo perf stat -e rtm_retired.start ./demo     

 Performance counter stats for './demo':
                              
                 1      rtm_retired.start

       0.000614539 seconds time elapsed                                               
                                                                                                 
       0.000634000 seconds user
       0.000000000 seconds sys 

事务提交统计

$ sudo perf stat -e rtm_retired.commit ./demo                                                                                        

 Performance counter stats for './demo':                                                                                                                                       

                 0      rtm_retired.commit                                                                                                                                    

       0.000657118 seconds time elapsed                                                                                                                                       

       0.000616000 seconds user         
       0.000000000 seconds sys

事务中止原因统计

$ sudo perf stat -e rtm_retired.aborted_unfriendly ./demo

 Performance counter stats for './demo':

                 1      rtm_retired.aborted_unfriendly                                   

       0.000617362 seconds time elapsed

       0.000609000 seconds user
       0.000000000 seconds sys

机器配置

CPU: Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
microcode: 0xf0
OS: Linux 5.4.0-150-generic, Ubuntu 18.04.1

更新结论:查阅Intel官方文档得知,Intel已通过微码更新禁用TSX,并新增CPUID位标识该变更。经检查我的处理器已设置该位,因此RTM区域无法成功执行。


内容的提问来源于stack exchange,提问作者Kayroger

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 14:22:01