Commit 244735d
prctl: Introduce PR_{SET,GET}_MEM_MODEL
On some architectures, it is possible to query and/or change the CPU
memory model. This allows userspace to switch to a stricter memory model
for performance reasons, such as when emulating code for another
architecture where that model is the default.
Introduce two prctls to allow userspace to query and set the memory
model for a thread. Two models are initially defined:
- PR_SET_MEM_MODEL_DEFAULT requests the default memory model for the
architecture.
- PR_SET_MEM_MODEL_TSO requests the x86 TSO memory model.
PR_SET_MEM_MODEL is allowed to set a stricter memory model than
requested if available, in which case it will return successfully. If
the requested memory model cannot be fulfilled, it will return an error.
The memory model that was actually set can be queried by a subsequent
call to PR_GET_MEM_MODEL.
Examples:
- On a CPU with not support for a memory model at least as strong as
TSO, PR_SET_MEM_MODEL(PR_SET_MEM_MODEL_TSO) fails.
- On a CPU with runtime-configurable TSO support, PR_SET_MEM_MODEL can
toggle the memory model between DEFAULT and TSO at will.
- On a CPU where the only memory model is at least as strict as TSO,
PR_GET_MEM_MODEL will return PR_SET_MEM_MODEL_DEFAULT, and
PR_SET_MEM_MODEL(PR_SET_MEM_MODEL_TSO) will return success but leave
the memory model at PR_SET_MEM_MODEL_DEFAULT. This implies that the
default is in fact at least as strict as TSO.
Signed-off-by: Hector Martin <marcan@marcan.st>
Reviewed-by: Neal Gompa <neal@gompa.dev>1 parent 7d0a66e commit 244735d
3 files changed
Lines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
9 | 14 | | |
10 | 15 | | |
11 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
2515 | 2516 | | |
2516 | 2517 | | |
2517 | 2518 | | |
| 2519 | + | |
| 2520 | + | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
2518 | 2529 | | |
2519 | 2530 | | |
2520 | 2531 | | |
| |||
2528 | 2539 | | |
2529 | 2540 | | |
2530 | 2541 | | |
| 2542 | + | |
| 2543 | + | |
| 2544 | + | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
2531 | 2552 | | |
2532 | 2553 | | |
2533 | 2554 | | |
| |||
0 commit comments