从内存加载寄存器时是否可以“中止"而不是触发页面错误? [英] Is it possible to “abort” when loading a register from memory rather the triggering a page fault?

查看:17
本文介绍了从内存加载寄存器时是否可以“中止"而不是触发页面错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑最小化页面行走"大图时出现故障(和 TLB 故障)'

'如何知道一个指针是否在物理内存中,否则会触发 Page Fault?' 是一个从另一面看问题的相关问题,但没有解决方案.

'How to know whether a pointer is in physical memory or it will trigger a Page Fault?' is a related question looking at the problem from the other side, but does not have a solution.

我希望能够将一些数据从内存加载到寄存器中,但如果内存当前已被分页,则加载会中止而不是出现页面错误.我需要代码在 Windows 和 Linux 上的用户空间中工作,而无需任何非标准权限.

I wish to be able to load some data from memory into a register, but have the load abort rather than getting a page fault, if the memory is currently paged out. I need the code to work in user space on both Windows and Linux without needing any none standard permission.

(理想情况下,我也想在 TLB 错误时中止.)

(Ideally, I would also like to abort on a TLB fault.)

推荐答案

TXT-NI 功能的 RTM(受限事务内存)部分允许抑制异常:

The RTM (Restricted Transactional Memory) part of the TXT-NI feature allows to suppress exceptions:

事务区域中必须暴露给软件的任何故障或陷阱都将被抑制.事务性执行将中止并且执行将转换为非事务性执行,就好像错误或陷阱从未发生过发生了.
[...]
同步异常事件(#DE、#OF、#NP、#SS、#GP、#BR、#UD、#AC、#XM、#PF、#NM、#TS、#MF、#DB、#BP/INT3) 发生在事务执行期间可能会导致执行不提交事务,和需要非事务性执行.这些事件被抑制,就好像它们从未发生过一样.

Any fault or trap in a transactional region that must be exposed to software will be suppressed. Transactional execution will abort and execution will transition to a non-transactional execution, as if the fault or trap had never occurred.
[...]
Synchronous exception events (#DE, #OF, #NP, #SS, #GP, #BR, #UD, #AC, #XM, #PF, #NM, #TS, #MF, #DB, #BP/INT3) that occur during transactional execution may cause an execution not to commit transactionally, and require a non-transactional execution. These events are suppressed as if they had never occurred.

我从未使用过 RTM,但它应该是这样的:

I've never used RTM but it should work something like this:

xbegin fallback

  ; Don't fault here

xend

; Somewhere else
fallback:
  ; Retry non-transactionally

请注意,事务可能因多种原因中止,请参阅英特尔手册卷 1 的第 16.8.3.2 章.另请注意,RTM 并非无处不在.

Note that a transaction can be aborted for many reasons, see chapter 16.8.3.2 of the Intel manual volume 1. Also note that RTM is not ubiquitous.

除了 RTM 之外,我想不出另一种方法来抑制负载,因为它必须返回一个值或最终发出中止条件的信号(这与 #PF 相同).

Besides RTM I cannot think of another way to suppress a load since it must return a value or eventually signal an abort condition (which would be the same as a #PF).

这篇关于从内存加载寄存器时是否可以“中止"而不是触发页面错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆