All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] x86/fpu: Remove opmask state from avx512_timestamp check
@ 2021-09-20  5:39 Noah Goldstein
  2021-09-27 18:02 ` Noah Goldstein
                   ` (6 more replies)
  0 siblings, 7 replies; 31+ messages in thread
From: Noah Goldstein @ 2021-09-20  5:39 UTC (permalink / raw)
  Cc: goldstein.w.n, tglx, mingo, bp, x86, hpa, luto, linux-kernel

This commit creates a new mask, XFEATURE_MASK_ZMM, to test against
xfeatures for conditionally updating the axx512_timestamp.

Based on the comments, the avx512 state is meant to track when the
state would cause frequencey throttling. The opmasks (k0-k7) do not
cause frequency throttling, so they don't make sense to include.

The current implementation, as well as the old, still does have a
false positive on ymm16-ymm31 and xmm16-31 because
XFEATURE_MASK_Hi16_ZMM includes them.

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
---
Issue is reproducible with the following code on x86_64:

```
	.global	_start
	.text
_start:
	korq	%k0, %k0, %k0

loop:
	jmp	loop


	movl	$60, %eax
	xorl	%edi, %edi
	syscall
```

Pretending run as executable named "foo":

$> cat /proc/$(pidof foo)/arch_status


This should yield -1 as no frequency changing AVX512 instructions
where used but instead tracks the process.

Note there still is a false positive with ymm16-ymm31 and xmm16-xmm31
but since there is no state to distinguish between there use and
zmm16-31 that seems inevitable.

    
 arch/x86/include/asm/fpu/types.h | 2 ++
 arch/x86/kernel/fpu/core.c       | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/fpu/types.h b/arch/x86/include/asm/fpu/types.h
index f5a38a5f3ae1..a4816fa7d541 100644
--- a/arch/x86/include/asm/fpu/types.h
+++ b/arch/x86/include/asm/fpu/types.h
@@ -141,6 +141,8 @@ enum xfeature {
 #define XFEATURE_MASK_AVX512		(XFEATURE_MASK_OPMASK \
 					 | XFEATURE_MASK_ZMM_Hi256 \
 					 | XFEATURE_MASK_Hi16_ZMM)
+#define XFEATURE_MASK_ZMM		(XFEATURE_MASK_ZMM_Hi256 \
+					 | XFEATURE_MASK_Hi16_ZMM)
 
 #define FIRST_EXTENDED_XFEATURE	XFEATURE_YMM
 
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 7ada7bd03a32..342620a2e8ef 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -104,8 +104,10 @@ void save_fpregs_to_fpstate(struct fpu *fpu)
 		/*
 		 * AVX512 state is tracked here because its use is
 		 * known to slow the max clock speed of the core.
+		 * Note: This has a false positive on Hi16 ymm and
+		 * xmm registers.
 		 */
-		if (fpu->state.xsave.header.xfeatures & XFEATURE_MASK_AVX512)
+		if (fpu->state.xsave.header.xfeatures & XFEATURE_MASK_ZMM)
 			fpu->avx512_timestamp = jiffies;
 		return;
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2021-11-17 18:29 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-20  5:39 [PATCH v1] x86/fpu: Remove opmask state from avx512_timestamp check Noah Goldstein
2021-09-27 18:02 ` Noah Goldstein
2021-10-13 22:36   ` Noah Goldstein
2021-10-14  8:28     ` Borislav Petkov
2021-10-14 15:49       ` Noah Goldstein
2021-10-15 14:40         ` Borislav Petkov
2021-10-15 15:25         ` Dave Hansen
2021-10-15 17:30           ` Noah Goldstein
2021-10-15 20:47 ` [PATCH v2 1/2] x86/fpu: Add helper function for tracking AVX512 status Noah Goldstein
2021-10-26 23:15   ` Noah Goldstein
2021-10-15 20:47 ` [PATCH v2 2/2] x86/xstate: Make AVX512 status tracking more accurate Noah Goldstein
2021-10-27 11:07   ` Borislav Petkov
2021-10-27 16:28     ` Noah Goldstein
2021-10-27 16:58       ` Borislav Petkov
2021-10-27 17:18         ` Noah Goldstein
2021-10-27 16:26 ` [PATCH v3 1/2] x86/fpu: Add helper function for tracking AVX512 status Noah Goldstein
2021-10-27 16:26   ` [PATCH v3 2/2] x86/xstate: Make AVX512 status tracking more accurate Noah Goldstein
2021-10-27 17:11     ` Borislav Petkov
2021-10-27 17:37       ` Noah Goldstein
2021-10-27 17:45         ` Borislav Petkov
2021-10-27 18:21           ` Noah Goldstein
2021-11-03 20:22             ` Noah Goldstein
2021-11-03 20:48               ` Borislav Petkov
2021-11-03 20:56                 ` Noah Goldstein
2021-10-27 17:17 ` [PATCH v4 1/2] x86/fpu: Add helper function for tracking AVX512 status Noah Goldstein
2021-10-27 17:17   ` [PATCH v4 2/2] x86/xstate: Make AVX512 status tracking more accurate Noah Goldstein
2021-10-27 18:21 ` [PATCH v5 1/2] x86/fpu: Add helper function for tracking AVX512 status Noah Goldstein
2021-10-27 18:21   ` [PATCH v5 2/2] x86/xstate: Make AVX512 status tracking more accurate Noah Goldstein
2021-11-16 16:21     ` [PATCH] x86/fpu: Correct AVX512 state tracking Borislav Petkov
2021-11-16 16:49       ` Noah Goldstein
2021-11-17 18:29 ` [tip: x86/fpu] " tip-bot2 for Noah Goldstein

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.