Skip to content

Commit 7f9daaf

Browse files
ChangSeokBaehansendc
authored andcommitted
Documentation/x86: Add the AMX enabling example
Explain steps to enable the dynamic feature with a code example. Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Bagas Sanjaya <bagasdotme@gmail.com> Reviewed-by: Tony Luck <tony.luck@intel.com> Link: https://lore.kernel.org/all/20230121001900.14900-4-chang.seok.bae%40intel.com
1 parent a03c376 commit 7f9daaf

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

Documentation/x86/xstate.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,61 @@ the handler allocates a larger xstate buffer for the task so the large
8080
state can be context switched. In the unlikely cases that the allocation
8181
fails, the kernel sends SIGSEGV.
8282

83+
AMX TILE_DATA enabling example
84+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
85+
86+
Below is the example of how userspace applications enable
87+
TILE_DATA dynamically:
88+
89+
1. The application first needs to query the kernel for AMX
90+
support::
91+
92+
#include <asm/prctl.h>
93+
#include <sys/syscall.h>
94+
#include <stdio.h>
95+
#include <unistd.h>
96+
97+
#ifndef ARCH_GET_XCOMP_SUPP
98+
#define ARCH_GET_XCOMP_SUPP 0x1021
99+
#endif
100+
101+
#ifndef ARCH_XCOMP_TILECFG
102+
#define ARCH_XCOMP_TILECFG 17
103+
#endif
104+
105+
#ifndef ARCH_XCOMP_TILEDATA
106+
#define ARCH_XCOMP_TILEDATA 18
107+
#endif
108+
109+
#define MASK_XCOMP_TILE ((1 << ARCH_XCOMP_TILECFG) | \
110+
(1 << ARCH_XCOMP_TILEDATA))
111+
112+
unsigned long features;
113+
long rc;
114+
115+
...
116+
117+
rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features);
118+
119+
if (!rc && (features & MASK_XCOMP_TILE) == MASK_XCOMP_TILE)
120+
printf("AMX is available.\n");
121+
122+
2. After that, determining support for AMX, an application must
123+
explicitly ask permission to use it::
124+
125+
#ifndef ARCH_REQ_XCOMP_PERM
126+
#define ARCH_REQ_XCOMP_PERM 0x1023
127+
#endif
128+
129+
...
130+
131+
rc = syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_PERM, ARCH_XCOMP_TILEDATA);
132+
133+
if (!rc)
134+
printf("AMX is ready for use.\n");
135+
136+
Note this example does not include the sigaltstack preparation.
137+
83138
Dynamic features in signal frames
84139
---------------------------------
85140

0 commit comments

Comments
 (0)