Message ID | 20220616212210.3182-2-chang.seok.bae@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Documentation/x86: Update the dynamic XSTATE doc | expand |
> + 1. **Check the feature availability**. AMX_TILE is enumerated in CPUID > + leaf 7, sub-leaf 0, bit 24 of EDX. If available, ``/proc/cpuinfo`` > + shows ``amx_tile`` in the flag entry of the CPUs. Given that, the > + kernel may have set XSTATE component 18 in the XCR0 register. But a > + user needs to ensure the kernel support via the ARCH_GET_XCOMP_SUPP > + option:: Why did you bother mentioning the XCR0 and CPUID specifics? We don't want applications doing that, right? > + #include <asm/prctl.h> > + #include <sys/syscall.h> > + #include <stdio.h> > + #include <unistd.h> ^ Just from the appearance here there looks to be some spaces vs. tabs inconsistency. > + #define ARCH_GET_XCOMP_SUPP 0x1021 > + > + #define XFEATURE_XTILECFG 17 > + #define XFEATURE_XTILEDATA 18 > + #define XFEATURE_MASK_XTILE ((1 << XFEATURE_XTILECFG) | (1 << XFEATURE_XFILEDATA)) > + > + unsigned long features; > + long rc; > + > + ... > + > + rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features); > + > + if (!rc && features & XFEATURE_MASK_XTILE == XFEATURE_MASK_XTILE) > + printf("AMX is available.\n"); > + > + 2. **Request permission**. Now it is found that the kernel supports the > + feature. But the permission is not automatically given. A user needs > + to explicitly request it via the ARCH_REQ_XCOMP_PERM option:: That phrasing is a bit awkward. How about: After determining support for AMX, an application must explicitly ask permission to use it: ... > + #define ARCH_REQ_XCOMP_PERM 0x1023 > + > + ... > + > + rc = syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_PERM, XFEATURE_XTILEDATA); > + > + if (!rc) > + printf("AMX is ready for use.\n"); > + > +Note this example does not include the sigaltstack preparation. > + > Dynamic features in signal frames > --------------------------------- >
On 6/16/2022 3:45 PM, Dave Hansen wrote: >> + 1. **Check the feature availability**. AMX_TILE is enumerated in CPUID >> + leaf 7, sub-leaf 0, bit 24 of EDX. If available, ``/proc/cpuinfo`` >> + shows ``amx_tile`` in the flag entry of the CPUs. Given that, the >> + kernel may have set XSTATE component 18 in the XCR0 register. But a >> + user needs to ensure the kernel support via the ARCH_GET_XCOMP_SUPP >> + option:: > > Why did you bother mentioning the XCR0 and CPUID specifics? We don't > want applications doing that, right? Without checking them, this arch_prctl(2) option can be tried. Then it will return either EINVAL or the feature bit off if unavailable. Yes, that's all wanted instead of that old way. So maybe something like this here: An application first needs to determine the feature support: > >> + #include <asm/prctl.h> >> + #include <sys/syscall.h> >> + #include <stdio.h> >> + #include <unistd.h> > > ^ Just from the appearance here there looks to be some spaces vs. tabs > inconsistency. Sorry, a tab instead of spaces was added later to fix a compile error. <snip> >> + 2. **Request permission**. Now it is found that the kernel supports the >> + feature. But the permission is not automatically given. A user needs >> + to explicitly request it via the ARCH_REQ_XCOMP_PERM option:: > > That phrasing is a bit awkward. How about: > > After determining support for AMX, an application must > explicitly ask permission to use it: > ... Yeah, looks to be concise. Thanks! Chang
On Thu, Jun 16, 2022 at 02:22:09PM -0700, Chang S. Bae wrote: > + 1. **Check the feature availability**. AMX_TILE is enumerated in CPUID > + leaf 7, sub-leaf 0, bit 24 of EDX. If available, ``/proc/cpuinfo`` > + shows ``amx_tile`` in the flag entry of the CPUs. Given that, the > + kernel may have set XSTATE component 18 in the XCR0 register. But a > + user needs to ensure the kernel support via the ARCH_GET_XCOMP_SUPP > + option:: > + > + #include <asm/prctl.h> > + #include <sys/syscall.h> > + #include <stdio.h> > + #include <unistd.h> > + > + #define ARCH_GET_XCOMP_SUPP 0x1021 > + > + #define XFEATURE_XTILECFG 17 > + #define XFEATURE_XTILEDATA 18 > + #define XFEATURE_MASK_XTILE ((1 << XFEATURE_XTILECFG) | (1 << XFEATURE_XFILEDATA)) > + > + unsigned long features; > + long rc; > + > + ... > + > + rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features); > + > + if (!rc && features & XFEATURE_MASK_XTILE == XFEATURE_MASK_XTILE) > + printf("AMX is available.\n"); > + nit: stdio include line isn't aligned with the rest of code. Otherwise LGTM (no new warnings). Reviewed-by: Bagas Sanjaya <bagasdotme@gmail.com>
diff --git a/Documentation/x86/xstate.rst b/Documentation/x86/xstate.rst index 5cec7fb558d6..9597e6caa30e 100644 --- a/Documentation/x86/xstate.rst +++ b/Documentation/x86/xstate.rst @@ -64,6 +64,54 @@ the handler allocates a larger xstate buffer for the task so the large state can be context switched. In the unlikely cases that the allocation fails, the kernel sends SIGSEGV. +AMX TILE_DATA enabling example +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The following steps dynamically enable TILE_DATA: + + 1. **Check the feature availability**. AMX_TILE is enumerated in CPUID + leaf 7, sub-leaf 0, bit 24 of EDX. If available, ``/proc/cpuinfo`` + shows ``amx_tile`` in the flag entry of the CPUs. Given that, the + kernel may have set XSTATE component 18 in the XCR0 register. But a + user needs to ensure the kernel support via the ARCH_GET_XCOMP_SUPP + option:: + + #include <asm/prctl.h> + #include <sys/syscall.h> + #include <stdio.h> + #include <unistd.h> + + #define ARCH_GET_XCOMP_SUPP 0x1021 + + #define XFEATURE_XTILECFG 17 + #define XFEATURE_XTILEDATA 18 + #define XFEATURE_MASK_XTILE ((1 << XFEATURE_XTILECFG) | (1 << XFEATURE_XFILEDATA)) + + unsigned long features; + long rc; + + ... + + rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features); + + if (!rc && features & XFEATURE_MASK_XTILE == XFEATURE_MASK_XTILE) + printf("AMX is available.\n"); + + 2. **Request permission**. Now it is found that the kernel supports the + feature. But the permission is not automatically given. A user needs + to explicitly request it via the ARCH_REQ_XCOMP_PERM option:: + + #define ARCH_REQ_XCOMP_PERM 0x1023 + + ... + + rc = syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_PERM, XFEATURE_XTILEDATA); + + if (!rc) + printf("AMX is ready for use.\n"); + +Note this example does not include the sigaltstack preparation. + Dynamic features in signal frames ---------------------------------