英特尔® 事务同步扩展新指令 (TSX-NI) 与英特尔 TSX 有何不同?
Is Intel® Transactional Synchronization Extensions New Instruction (TSX-NI) difference from Intel TSX?
我在 Intel 的页面上找到
https://ark.intel.com/products/97123/Intel-Core-i5-7500-Processor-6M-Cache-up-to-3_80-GHz
该处理器支持 TSX-NI 技术,但我在 google 上找不到任何相关信息。是不是和Intel TSX一样。如果有区别,那我怎么用呢
抱歉我的英语不好! :)
这似乎只是一种营销点缀。
我在互联网上、英特尔手册和英特尔 ISA 扩展手册中都没有找到对 "TSX-NI" 的引用。
引用英特尔 [1]
Intel Transactional Synchronization Extensions (Intel TSX) comes in two flavours: HLE and RTM.
由于它们的实现,这两个方面是分离的(其中一个可以与另一个分开支持)并且只有 RTM 引入了新指令。
所以他们可能指的是 RTM。
我相信首先引入了 HLE,并且应该有支持 HLE 但不支持 RTM 的处理器(相反,虽然可能,但似乎不可信)。
所以,也许,这只是市场营销的正确说法:"This CPU supports our latest TSX features!"。
作为参考,我在假设"TSX-NI"指的是"TSX RTM".
的前提下写了Intel TSX的两部分简介
可以在 Intel 手册 1 - 第 15 章.
上找到完整的参考资料
HLE
HLE(硬件锁省略)部分向后兼容。
我们仍然可以用 CPUID.07H.EBX.HLE[bit 4] 来测试它的可用性,但是它是通过改变前缀的语义来实现的 repne
/ repe
获取说明。
此功能包含两个 "new" 前缀:xacquire
和 xrelease
。
CPU 现在能够进入事务状态,其中每次读取都添加到事务的 read-set,每次写入都添加到 write -set 的事务并且不执行到内存中。
粒度是缓存行的大小。
如果一个线程从另一个线程的读取集读取,或者写入另一个线程的读取集或写入集,则事务将中止。
CPU 恢复事务开始时的体系结构状态,并以非事务方式重新执行指令。
如果事务成功完成,所有写入的内存都将以原子方式提交。
事务由 xacquire
和 xrelease
分隔。
它们可以嵌套,但有深度限制(超过该深度事务中止)和可以省略的不同锁的数量(超过 CPU 不会省略新锁但不会中止交易)。
当嵌套事务中止时,CPU 重新开始执行 最外层的 事务。
xacquire
(操作码F2
,与repne
相同)用在获取锁(即写入锁)的指令前面,标志着一笔交易。
此读取 未 添加到写入集(或者不会发生并发,因为每个线程都写入锁,这将立即中止任何后续事务)。
它被添加到读取集中。
xrelease
(操作码F3
)用在释放锁的指令前,标志着事务的结束。
xrelease
必须使用与 xacquire
相同的锁来与之配对并完成交易。
xacquire
只能与这些指令的 lock
d 版本一起使用:ADD, ADC, AND, BTC, BTR, BTS, CMPXCHG, CMPXCHG8B, DEC, INC, NEG, NOT, OR, SBB, SUB, XOR, XADD, XCHG
.
xrelease
使用相同的指令加上 MOV mem, reg
和 MOV mem, imm
没有 lock
前缀。
如果存在 HLE(或 RTM),则新指令 xtest
可用,它设置 ZF 是处理器 not 在交易中。
RTM
RTM(受限事务内存)不向后兼容。
可以用CPUID.07H.EBX.RTM[bit 11]进行测试。
它引入了三个新指令:xbegin
、xend
和 xabort
。
它们只是已经指定的、通用的、事务执行能力的一个新接口。
xbegin
必须提供指向回退代码路径的指针作为相对偏移量。
每当事务提交失败时执行此代码。
在这种情况下 eax
包含中止的原因。
xend
结束事务并指示 CPU 提交它。
xabort
允许程序员使用自定义错误代码显式中止事务。
英特尔不保证处理器成功提交事务的能力。
虽然 HLE 有一组非常具体的条件,但 RTM 是一种 "best effort" 类型的功能 - 因此需要回退代码。
RTM 比 HLE 更底层,它允许程序员使用事务内存,无论是否使用锁。
混合 HLE 和 RTM
引用英特尔:
The behaviour when HLE and RTM are nested together—HLE
inside RTM or RTM inside HLE—is implementation specific. However, in all cases, the
implementation will maintain HLE and RTM semantics. An implementation may
choose to ignore HLE hints when used inside RTM regions, and may cause a transactional abort when RTM instructions are used inside HLE regions. In the latter case,
the transition from transactional to non-transactional execution occurs seamlessly
since the processor will re-execute the HLE region without actually doing elision, and
then execute the RTM instructions.
TSX-NI 是对先前指令集 (HLE) 的扩展 (RTM)。
来自英特尔页面
Hardware Lock Elision (HLE)
HLE is a legacy-compatible instruction set extension (comprising the
XACQUIRE and XRELEASE prefixes) to specify transactional regions. HLE
is for programmers who prefer the backward compatibility of the
conventional mutual-exclusion programming model and would like to run
HLE-enabled software on legacy hardware, but would like to take
advantage of new lock elision capabilities on hardware with HLE
support.
Restricted Transactional Memory (RTM)
RTM is a new instruction set interface (comprising the XBEGIN, XEND,
and XABORT instructions) for programmers to define transactional
regions in a more flexible manner than that possible with HLE.
RTM is for programmers who prefer a flexible interface to the
transactional execution hardware.
所以新的集合包括:
XACQUIRE Prefix hint to the beginning of an HLE transaction region
XRELEASE Prefix hint to the end of an HLE transaction region
XBEGIN Transaction begin of an RTM transaction region
XEND Transaction end of an RTM transaction region
XABORT Abort an RTM transaction execution
XTEST Test if executing in a transactional region
我在 Intel 的页面上找到
https://ark.intel.com/products/97123/Intel-Core-i5-7500-Processor-6M-Cache-up-to-3_80-GHz
该处理器支持 TSX-NI 技术,但我在 google 上找不到任何相关信息。是不是和Intel TSX一样。如果有区别,那我怎么用呢
抱歉我的英语不好! :)
这似乎只是一种营销点缀。
我在互联网上、英特尔手册和英特尔 ISA 扩展手册中都没有找到对 "TSX-NI" 的引用。
引用英特尔 [1]
Intel Transactional Synchronization Extensions (Intel TSX) comes in two flavours: HLE and RTM.
由于它们的实现,这两个方面是分离的(其中一个可以与另一个分开支持)并且只有 RTM 引入了新指令。
所以他们可能指的是 RTM。
我相信首先引入了 HLE,并且应该有支持 HLE 但不支持 RTM 的处理器(相反,虽然可能,但似乎不可信)。
所以,也许,这只是市场营销的正确说法:"This CPU supports our latest TSX features!"。
作为参考,我在假设"TSX-NI"指的是"TSX RTM".
的前提下写了Intel TSX的两部分简介
可以在 Intel 手册 1 - 第 15 章.
HLE
HLE(硬件锁省略)部分向后兼容。
我们仍然可以用 CPUID.07H.EBX.HLE[bit 4] 来测试它的可用性,但是它是通过改变前缀的语义来实现的 repne
/ repe
获取说明。
此功能包含两个 "new" 前缀:xacquire
和 xrelease
。
CPU 现在能够进入事务状态,其中每次读取都添加到事务的 read-set,每次写入都添加到 write -set 的事务并且不执行到内存中。
粒度是缓存行的大小。
如果一个线程从另一个线程的读取集读取,或者写入另一个线程的读取集或写入集,则事务将中止。
CPU 恢复事务开始时的体系结构状态,并以非事务方式重新执行指令。
如果事务成功完成,所有写入的内存都将以原子方式提交。
事务由 xacquire
和 xrelease
分隔。
它们可以嵌套,但有深度限制(超过该深度事务中止)和可以省略的不同锁的数量(超过 CPU 不会省略新锁但不会中止交易)。
当嵌套事务中止时,CPU 重新开始执行 最外层的 事务。
xacquire
(操作码F2
,与repne
相同)用在获取锁(即写入锁)的指令前面,标志着一笔交易。
此读取 未 添加到写入集(或者不会发生并发,因为每个线程都写入锁,这将立即中止任何后续事务)。
它被添加到读取集中。
xrelease
(操作码F3
)用在释放锁的指令前,标志着事务的结束。
xrelease
必须使用与 xacquire
相同的锁来与之配对并完成交易。
xacquire
只能与这些指令的 lock
d 版本一起使用:ADD, ADC, AND, BTC, BTR, BTS, CMPXCHG, CMPXCHG8B, DEC, INC, NEG, NOT, OR, SBB, SUB, XOR, XADD, XCHG
.
xrelease
使用相同的指令加上 MOV mem, reg
和 MOV mem, imm
没有 lock
前缀。
如果存在 HLE(或 RTM),则新指令 xtest
可用,它设置 ZF 是处理器 not 在交易中。
RTM
RTM(受限事务内存)不向后兼容。
可以用CPUID.07H.EBX.RTM[bit 11]进行测试。
它引入了三个新指令:xbegin
、xend
和 xabort
。
它们只是已经指定的、通用的、事务执行能力的一个新接口。
xbegin
必须提供指向回退代码路径的指针作为相对偏移量。
每当事务提交失败时执行此代码。
在这种情况下 eax
包含中止的原因。
xend
结束事务并指示 CPU 提交它。
xabort
允许程序员使用自定义错误代码显式中止事务。
英特尔不保证处理器成功提交事务的能力。
虽然 HLE 有一组非常具体的条件,但 RTM 是一种 "best effort" 类型的功能 - 因此需要回退代码。
RTM 比 HLE 更底层,它允许程序员使用事务内存,无论是否使用锁。
混合 HLE 和 RTM
引用英特尔:
The behaviour when HLE and RTM are nested together—HLE inside RTM or RTM inside HLE—is implementation specific. However, in all cases, the implementation will maintain HLE and RTM semantics. An implementation may choose to ignore HLE hints when used inside RTM regions, and may cause a transactional abort when RTM instructions are used inside HLE regions. In the latter case, the transition from transactional to non-transactional execution occurs seamlessly since the processor will re-execute the HLE region without actually doing elision, and then execute the RTM instructions.
TSX-NI 是对先前指令集 (HLE) 的扩展 (RTM)。
来自英特尔页面
Hardware Lock Elision (HLE)
HLE is a legacy-compatible instruction set extension (comprising the XACQUIRE and XRELEASE prefixes) to specify transactional regions. HLE is for programmers who prefer the backward compatibility of the conventional mutual-exclusion programming model and would like to run HLE-enabled software on legacy hardware, but would like to take advantage of new lock elision capabilities on hardware with HLE support.
Restricted Transactional Memory (RTM)
RTM is a new instruction set interface (comprising the XBEGIN, XEND, and XABORT instructions) for programmers to define transactional regions in a more flexible manner than that possible with HLE.
RTM is for programmers who prefer a flexible interface to the transactional execution hardware.
所以新的集合包括:
XACQUIRE Prefix hint to the beginning of an HLE transaction region
XRELEASE Prefix hint to the end of an HLE transaction region
XBEGIN Transaction begin of an RTM transaction region
XEND Transaction end of an RTM transaction region
XABORT Abort an RTM transaction execution
XTEST Test if executing in a transactional region