Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp442870imu; Wed, 19 Dec 2018 22:44:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/VxEaAQi2Scz8d7wZHWwhSxAJvA/zUD9KWwdNKKXO4lHUU9I9+ixAMpk5oteHB7P4P59uxO X-Received: by 2002:a17:902:7e44:: with SMTP id a4mr23187018pln.338.1545288244919; Wed, 19 Dec 2018 22:44:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545288244; cv=none; d=google.com; s=arc-20160816; b=zF6R+tCJRe4ZC/iPPpWfvihfKHDl6Raxs3VfBNmeZX7aotxraVrzWJhnf9mPq4kKg8 R7/hl6Mv6bg77nD6+wFd/QGHppWbgkUjMMClfGfxfy0kbzBPVzRnwv9s2WRHQkRsdBps S0d780N4fAj11lCdpjoKspOAwAzLOzeOOQ4nT4/wFI32VxltAh4bBpi/tH2v8ig+5I8z FX8KibDe+065YW5uaezlTr+DQYi20TAFgJE0zRMTRLs9ieN9pykj8CdwYCaiTKRE2BIA 3wl8tT2j8fmuEl2OlF3RRs6cAqg3eS+qAOreb8DJDTT3KqsngD0Bn9LejLAtR5CVY4WP O6vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=5XHqf/McE4x9yyQAqWQJ38q3J0J1OqkMchNAFbl2vwc=; b=cH3usJ8SOCkIQ+enksEQT1E8UFDOlZAqi4OcWI+1p/u9dxCHaoHSwN5ZreUpUx/ypA 5uk4Q5IDRNSRngpamvoCKZUOmmALyOrFDhpm0BmxOvVkF9XbwAQlNCbInweAZYePmsQ8 1ab97c2T/tHlwyoO5dUXGdtqHILERtBl/jbOGJIsG7EJ0SeM7/OQr95rg2mt7HTsHKIv IyNS0niSTaY49AApbHZ53gwG0WGT6aJZoAxHMmDIaiauqQVefP7Z85rMI7gRmw79ZAme JB4w8AA8DzzRvrUn1GO0wSL8X2ol/bxSBtXNXAVEkahEMpns32NSxR7ZP0E2oowDC2Uv i3jg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b5si18320825pfg.121.2018.12.19.22.43.49; Wed, 19 Dec 2018 22:44:04 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725780AbeLTFDt (ORCPT + 99 others); Thu, 20 Dec 2018 00:03:49 -0500 Received: from mga01.intel.com ([192.55.52.88]:39452 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbeLTFDr (ORCPT ); Thu, 20 Dec 2018 00:03:47 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Dec 2018 21:03:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,375,1539673200"; d="scan'208";a="119756263" Received: from aubrey-skl.sh.intel.com ([10.239.53.9]) by orsmga002.jf.intel.com with ESMTP; 19 Dec 2018 21:03:44 -0800 From: Aubrey Li To: tglx@linutronix.de, mingo@redhat.com, peterz@infradead.org, hpa@zytor.com Cc: ak@linux.intel.com, tim.c.chen@linux.intel.com, dave.hansen@intel.com, arjan@linux.intel.com, aubrey.li@intel.com, linux-kernel@vger.kernel.org, Aubrey Li Subject: [PATCH v7 1/3] x86/fpu: track AVX-512 usage of tasks Date: Thu, 20 Dec 2018 05:45:22 +0800 Message-Id: <20181219214524.3986-1-aubrey.li@intel.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Peter Zijlstra Cc: Andi Kleen Cc: Tim Chen Cc: Dave Hansen Cc: Arjan van de Ven --- 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 a38bf5a1e37a..e30c5b414b2c 100644 --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -411,6 +411,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: * -- 2.17.1