Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2594494imj; Mon, 11 Feb 2019 05:36:42 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib9IdyBFV/r7P9vXUUKILRYWbxjVxu08M/e759C/S4TFgvPobbgwRX65NKL8CiwCErxmnLn X-Received: by 2002:a17:902:8e8a:: with SMTP id bg10mr37330432plb.192.1549892202888; Mon, 11 Feb 2019 05:36:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549892202; cv=none; d=google.com; s=arc-20160816; b=m5Tz1nVXCxi2vPLuLnOsoobIICF92atoZZExSNsglQhSLzaJdELD1PMpjJ5Y8olup9 RfS/1sKjdV9+Yv74IXDg/wJbmnqPLyJOEROY91E8fPLr1WdMs5fJYh5wtAFojI6dxYcH 4BhOVjLRAhSRLa0Mobsa21GGHPP1W/5cvohvOQ9xDPVSCM9XiHVbhOi9K9CY3Oltw1li lAL+/zW+fr/3YflAbu2XNNIa76P6RK7m7KNmtuey8N9RJq3uX1HFz+LczqQi/b4Z5iv/ mNliKfi4M8HnmqYdcLrpYEWXP0HyqX23CSw80jKV/b6B4lpSOumGC53A6L07UcKoJAb1 QQ4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=2daRsJTIpcqysONSORjifswiBfAKxFbnIgDVUoRL3ts=; b=yL61t7X6iulFE747Nury0UjRI7SktXBrAUg4EPgkFomk/5LytNY5ZWW5vrsXZrAYTN IOg/En+NOwWIIajTExv6GFFCZrGnigOw2vwkl7TKDzlB4DMB35D9+2CsHu6uiYqFPpkS dvasPm7Ww2A+j17mcaWzoSoO6t4Is8sIu2J0hQBgftkML1Ro9WPU2moWgTLvJc3Vj02U A1on1DK9ljQPf5Wc93zr2C196bxKQwApe2fa0MPibeUTEtANP463oTsLepp8Y0foAiUd 8krB6r2mrNrp1WRgsqp16a7wr5kSx7ZP8D//0A/JsVbOSTgYwgi+/pB/vwd73podLj1k SvdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c8si9382748pgl.507.2019.02.11.05.36.25; Mon, 11 Feb 2019 05:36:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727931AbfBKNef (ORCPT + 99 others); Mon, 11 Feb 2019 08:34:35 -0500 Received: from terminus.zytor.com ([198.137.202.136]:38829 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727182AbfBKNef (ORCPT ); Mon, 11 Feb 2019 08:34:35 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x1BDYACB3552753 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 11 Feb 2019 05:34:11 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x1BDYA9r3552750; Mon, 11 Feb 2019 05:34:10 -0800 Date: Mon, 11 Feb 2019 05:34:10 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Aubrey Li Message-ID: Cc: oleg@redhat.com, peterz@infradead.org, torvalds@linux-foundation.org, hpa@zytor.com, dave.hansen@intel.com, tim.c.chen@linux.intel.com, luto@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, mingo@kernel.org, dave.hansen@linux.intel.com, fenghua.yu@intel.com, aubrey.li@intel.com, aubrey.li@linux.intel.com, arjan@linux.intel.com, bp@alien8.de Reply-To: luto@kernel.org, tglx@linutronix.de, peterz@infradead.org, oleg@redhat.com, hpa@zytor.com, torvalds@linux-foundation.org, dave.hansen@intel.com, tim.c.chen@linux.intel.com, bp@alien8.de, linux-kernel@vger.kernel.org, mingo@kernel.org, dave.hansen@linux.intel.com, fenghua.yu@intel.com, aubrey.li@intel.com, aubrey.li@linux.intel.com, arjan@linux.intel.com In-Reply-To: <20190117183822.31333-1-aubrey.li@intel.com> References: <20190117183822.31333-1-aubrey.li@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/fpu] x86/fpu: Track AVX-512 usage of tasks Git-Commit-ID: 2f7726f955572e587d5f50fbe9b2deed5334bd90 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 2f7726f955572e587d5f50fbe9b2deed5334bd90 Gitweb: https://git.kernel.org/tip/2f7726f955572e587d5f50fbe9b2deed5334bd90 Author: Aubrey Li AuthorDate: Fri, 18 Jan 2019 02:38:20 +0800 Committer: Ingo Molnar CommitDate: Mon, 11 Feb 2019 14:28:56 +0100 x86/fpu: Track AVX-512 usage of tasks User space tools which do automated task placement need information about AVX-512 usage of tasks, because AVX-512 usage could cause core turbo frequency drop and impact the running task on the sibling CPU. The XSAVE hardware structure has bits that indicate when valid state is present in registers unique to AVX-512 use. Use these bits to indicate when AVX-512 has been in use and add per-task AVX-512 state timestamp tracking to context switch. Well-written AVX-512 applications are expected to clear the AVX-512 state when not actively using AVX-512 registers, so the tracking mechanism is imprecise and can theoretically miss AVX-512 usage during context switch. But it has been measured to be precise enough to be useful under real-world workloads like tensorflow and linpack. If higher precision is required, suggest user space tools to use the PMU-based mechanisms in combination. Signed-off-by: Aubrey Li Reviewed-by: Thomas Gleixner Cc: Andy Lutomirski Cc: Arjan van de Ven Cc: Borislav Petkov Cc: Dave Hansen Cc: Dave Hansen Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Tim Chen Cc: aubrey.li@intel.com Link: http://lkml.kernel.org/r/20190117183822.31333-1-aubrey.li@intel.com Signed-off-by: Ingo Molnar --- arch/x86/include/asm/fpu/internal.h | 7 +++++++ arch/x86/include/asm/fpu/types.h | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h index 5d536e3dcc6d..fb04a3ded7dd 100644 --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -376,6 +376,13 @@ static inline int copy_fpregs_to_fpstate(struct fpu *fpu) { if (likely(use_xsave())) { copy_xregs_to_kernel(&fpu->state.xsave); + + /* + * AVX512 state is tracked here because its use is + * known to slow the max clock speed of the core. + */ + if (fpu->state.xsave.header.xfeatures & XFEATURE_MASK_AVX512) + fpu->avx512_timestamp = jiffies; return 1; } diff --git a/arch/x86/include/asm/fpu/types.h b/arch/x86/include/asm/fpu/types.h index 202c53918ecf..2e32e178e064 100644 --- a/arch/x86/include/asm/fpu/types.h +++ b/arch/x86/include/asm/fpu/types.h @@ -302,6 +302,13 @@ struct fpu { */ unsigned char initialized; + /* + * @avx512_timestamp: + * + * Records the timestamp of AVX512 use during last context switch. + */ + unsigned long avx512_timestamp; + /* * @state: *