Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3343225imu; Mon, 17 Dec 2018 18:31:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/XeZuARMgPfOjSWnFe5J/hzA7UvbmQJ7KBtKnsjWsUrCkf27Y7CciAS/OOJLL9EwwQwhb0R X-Received: by 2002:a63:f1f:: with SMTP id e31mr14128008pgl.274.1545100297154; Mon, 17 Dec 2018 18:31:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545100297; cv=none; d=google.com; s=arc-20160816; b=bPr2wK5ER3cAGgWKoHbiAoka3LKEVkKBjuQPfocqHaeEXBcQKS1LQQVYRb+Jzj42ix fuv126Rcsnsh9GQzoASAGu+k3nz2NRqR9veZxpqubN2Ck5Yufg/oDw4KZIxfzpBIscwy 166qBhW4pEhGAUmmzW9Nwu0QXdKZjDVLsYijtZSBI9d6Qbg7m/KSUXJmtA4ceaJaY/T/ y6AUlNnWWfFtC7F94d32+PYfiPOx23inPHLh0vlPZY2OJvBPDxBPN9p7CjkdMCh9N1ol 3OR1aXnyrVRcCev79h+CY50FvAO6JAZi96UfM6ZL16b3CRaXUecvmRMSyzQ0X1rkGDQ1 TQpw== 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=miByt4UBtujLZ6gakMhRKo706aoBxPu/AGSy/L6iA4Y=; b=Hqg82YfRGkhnpxU+A1Zr0kruOAD9O09zu601A3xlINNvgzjj7IPi68iF2IxeZShfCc kWhJezLX0/pCHzWuJOLuSs/yn2w+2iyLrwPRt+Ngow3QRnewt114lu1U/5NGeBVZFsY0 FlF6pe2IuW7r9nTOX3w1NxV95N2QjYs8w+QCqAqhrcBz4/QsQqzAbfxzYMLqoQPbsFKQ DFRxaTfXfsT23GT0Z+BZFVQsf0EkyDZ5gZABOU3ioSk+aPIG7yWps/rn07WA7qzbHL/+ QL+Bjtbza4GPnYA562uv/mLfgs57kxD3auwD56rhZL6rN/WPFyG70XMsBDB8gL6aE7MB 8LOw== 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 f186si12385909pfb.67.2018.12.17.18.31.21; Mon, 17 Dec 2018 18:31:37 -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 S1726449AbeLRCa2 (ORCPT + 99 others); Mon, 17 Dec 2018 21:30:28 -0500 Received: from mga17.intel.com ([192.55.52.151]:35298 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726276AbeLRCa1 (ORCPT ); Mon, 17 Dec 2018 21:30:27 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Dec 2018 18:30:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,367,1539673200"; d="scan'208";a="101465112" Received: from aubrey-skl.sh.intel.com ([10.239.53.9]) by orsmga006.jf.intel.com with ESMTP; 17 Dec 2018 18:30:25 -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: [RESEND PATCH v5 1/3] x86/fpu: track AVX-512 usage of tasks Date: Tue, 18 Dec 2018 03:12:07 +0800 Message-Id: <20181217191209.6494-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..8778ac172255 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_64; return 1; } diff --git a/arch/x86/include/asm/fpu/types.h b/arch/x86/include/asm/fpu/types.h index 202c53918ecf..81393dabdb46 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. + */ + u64 avx512_timestamp; + /* * @state: * -- 2.17.1