Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2271379rdb; Thu, 21 Sep 2023 13:35:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsAk+6Czp2BOS/sCL0N5VLKooNUfLVJSFOHV84f2aHReh3w29P8Vi4Vt/H7ayzb/JfWIAE X-Received: by 2002:a05:6a00:c95:b0:690:28d0:b7b3 with SMTP id a21-20020a056a000c9500b0069028d0b7b3mr7609565pfv.13.1695328534451; Thu, 21 Sep 2023 13:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695328534; cv=none; d=google.com; s=arc-20160816; b=ZA1zn1jDuSWs0qordqRVQlCxq1domMcG4NxpN95a3erCFOP/Md3g4MfySxL/BHW3eF WbUI5MBAFADZZ8eLG9PxfoPlEMgA2Ru+uArlSGIfkcbr/XnkehssCHmqPafvWsRUla5c k3YBYKc8KYCTaQMKpjyxHe69YdatA5irt/aXZRf4bdCDOQ4Xv1/k4ZnLIjlnAiLFnmZ0 9Dkt6ZXaQDps51nEHBx6HXxy4TD8QCrdEpXs9uZ2TL9gBtN3FXuarnTAqB/DY3cb8dEf vvMSC/w+QTStJoYLF8mmb1SSyKlhT5NglqCeU64n+OhHq+CdxMrmLxMCag59RFYuq8ej tQVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=PZJCsdLzutgfF2WmT4E/VmrTiPqUKFREB2gVIRmp/cw=; fh=teHwLjm6Bv6TT84DAiOw1HevCBR9+MpGQ9+q6jMBfPU=; b=BN5eQGEoflRSY7tOo9ZoVmKlIE9sgNRK3xoocC6pi17RjJTl/dCOhYmFHaz0mSFtHM 5vx4V/dRw2rTYxridgNzHb3UeN/lQN4L2ZGCis3AOcMonEQ4AAYTbW/H/+B7+536TaTt jTiMNEEceVNyUOyUUtT2OeyWgxHl5+jI+lVfAAYAHeyIOlM8cN+Tyql4s/PlxRZB3hB8 pfA82cCxpjJiN7mfLMh69HzP3KmDj6S83akS6k85wjDr7uKB+omRa//OhfH+7sGkSTRJ fnnLqSCqk6Tr26m9t0j4c+VNTF5Hs46Vfwe+h3HHZHBsrkWftK7z1dQ5zuLbb6rsc3I6 RvXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hbuInmYv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id 69-20020a630048000000b00578a02ee39fsi2141210pga.334.2023.09.21.13.35.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 13:35:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hbuInmYv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 02EEA80B2875; Thu, 21 Sep 2023 11:52:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230411AbjIUSwe (ORCPT + 99 others); Thu, 21 Sep 2023 14:52:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230350AbjIUSwW (ORCPT ); Thu, 21 Sep 2023 14:52:22 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A54C900D4 for ; Thu, 21 Sep 2023 10:46:21 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4053c6f0e50so624155e9.1 for ; Thu, 21 Sep 2023 10:46:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695318380; x=1695923180; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=PZJCsdLzutgfF2WmT4E/VmrTiPqUKFREB2gVIRmp/cw=; b=hbuInmYvZLer3b+p50wSq4DjG7wPmoiouANwdKo/9FzLzyHOOWT/xlmFyIcemKw5g6 pN/5gkj9vZAW+8qsAv+zmlvImqBMwxKpJAKeOdnmcxGnPxzW2nuPAmRP1Qqm7YEoziN8 FOV/Qpc5l7hXBLClMF15r9+qZ8pLnp7SacuQaSkA9U8pJOvFtJQAzuZHTIgEXiDNoQde nMdIa8cHwH3fpnIHjSc70MiaEmGgdLnyxbeDVkYj/unoW0wF4nYh7o729HKpiYQAiGQ1 PxfgL+zv4s7sujGJmMZVTrBFuJ6cdf1c7PVPwLfl7jXyDcZnKIxivDX3WShVgpS5KTTs P9Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318380; x=1695923180; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PZJCsdLzutgfF2WmT4E/VmrTiPqUKFREB2gVIRmp/cw=; b=XexFxTrRB9U6awsL/YhILPsRdpYCpekc6yJPP7lXXMNNpX7lOetDFLr4ixCXQsSynH way7FlyFAgWp1r3X/z50zcNQDZlHVXcWTdj/+ZSAkxzuA+5NLFLlCWZT4KCxPwwud0zq 47FEPy+WVC+ECLEUye4MtzCYAn9InZiC7BZvhelS5Hjw8zk5M8dLZrpZflMjvxyo0BJK aaM7a7jtvaSBNGnWBCSAG2eHcZPEwjlKBzBioblsis9kFJN+gwL0GlUSYMjx7+a5bKll 4xSRSLZ5lOP7suJhVK7WfQfm8/RP6Zx4Lv6VbHXNR/RKSpTtIqZYBVhvcbp8m58m1PrE 3UFQ== X-Gm-Message-State: AOJu0YyqJHrBUWA8VSxXcFJrm7VBx0fT4JxpB5nS4RJeGUo1v8iEfuln YNaD9tDdmBXeV2nqDSzDU1ScnKHUyKs= X-Received: by 2002:adf:9dc5:0:b0:321:9979:99ef with SMTP id q5-20020adf9dc5000000b00321997999efmr1071103wre.48.1695279813023; Thu, 21 Sep 2023 00:03:33 -0700 (PDT) Received: from gmail.com (1F2EF265.nat.pool.telekom.hu. [31.46.242.101]) by smtp.gmail.com with ESMTPSA id s16-20020a5d5110000000b0031aca6cc69csm885389wrt.2.2023.09.21.00.03.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 00:03:28 -0700 (PDT) Sender: Ingo Molnar Date: Thu, 21 Sep 2023 09:03:26 +0200 From: Ingo Molnar To: Yi Sun Cc: dave.hansen@intel.com, linux-kernel@vger.kernel.org, x86@kernel.org, sohil.mehta@intel.com, ak@linux.intel.com, ilpo.jarvinen@linux.intel.com, heng.su@intel.com, tony.luck@intel.com, yi.sun@linux.intel.com, yu.c.chen@intel.com Subject: Re: [PATCH v7 1/3] x86/fpu: Measure the Latency of XSAVE and XRSTOR Message-ID: References: <20230921062900.864679-1-yi.sun@intel.com> <20230921062900.864679-2-yi.sun@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230921062900.864679-2-yi.sun@intel.com> X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 11:52:40 -0700 (PDT) * Yi Sun wrote: > @@ -113,7 +116,7 @@ static inline u64 xfeatures_mask_independent(void) > * original instruction which gets replaced. We need to use it here as the > * address of the instruction where we might get an exception at. > */ > -#define XSTATE_XSAVE(st, lmask, hmask, err) \ > +#define __XSTATE_XSAVE(st, lmask, hmask, err) \ > asm volatile(ALTERNATIVE_3(XSAVE, \ > XSAVEOPT, X86_FEATURE_XSAVEOPT, \ > XSAVEC, X86_FEATURE_XSAVEC, \ > @@ -130,7 +133,7 @@ static inline u64 xfeatures_mask_independent(void) > * Use XRSTORS to restore context if it is enabled. XRSTORS supports compact > * XSAVE area format. > */ > -#define XSTATE_XRESTORE(st, lmask, hmask) \ > +#define __XSTATE_XRESTORE(st, lmask, hmask) \ > asm volatile(ALTERNATIVE(XRSTOR, \ > XRSTORS, X86_FEATURE_XSAVES) \ > "\n" \ > @@ -140,6 +143,35 @@ static inline u64 xfeatures_mask_independent(void) > : "D" (st), "m" (*st), "a" (lmask), "d" (hmask) \ > : "memory") > > +#if defined(CONFIG_X86_DEBUG_FPU) > +#define XSTATE_XSAVE(fps, lmask, hmask, err) \ > + do { \ > + struct fpstate *f = fps; \ > + u64 tc = -1; \ > + if (tracepoint_enabled(x86_fpu_latency_xsave)) \ > + tc = trace_clock(); \ > + __XSTATE_XSAVE(&f->regs.xsave, lmask, hmask, err); \ > + if (tracepoint_enabled(x86_fpu_latency_xsave)) \ > + trace_x86_fpu_latency_xsave(f, trace_clock() - tc);\ > + } while (0) > + > +#define XSTATE_XRESTORE(fps, lmask, hmask) \ > + do { \ > + struct fpstate *f = fps; \ > + u64 tc = -1; \ > + if (tracepoint_enabled(x86_fpu_latency_xrstor)) \ > + tc = trace_clock(); \ > + __XSTATE_XRESTORE(&f->regs.xsave, lmask, hmask); \ > + if (tracepoint_enabled(x86_fpu_latency_xrstor)) \ > + trace_x86_fpu_latency_xrstor(f, trace_clock() - tc);\ This v7 version does not adequately address the review feedback I gave for v6: it adds tracing overhead to potential hot paths, and putting it behind CONFIG_X86_DEBUG_FPU is not a solution either: it's default-y, so de-facto enabled on all major distros... It seems unnecessarily complex: why does it have to measure latency directly? Tracepoints *by default* come with event timestamps. A latency measurement tool should be able to subtract two timestamps to extract the latency between two tracepoints... In fact, function tracing is enabled on all major Linux distros: kepler:~/tip> grep FUNCTION_TRACER /boot/config-6.2.0-33-generic CONFIG_HAVE_FUNCTION_TRACER=y CONFIG_FUNCTION_TRACER=y Why not just enable function tracing for the affected FPU context switching functions? The relevant functions are already standalone in a typical kernel: xsave: # ffffffff8103cfe0 T save_fpregs_to_fpstate xrstor: # ffffffff8103d160 T restore_fpregs_from_fpstate xrstor_supervisor: # ffffffff8103dc50 T fpu__clear_user_states ... and FPU context switching overhead dominates the cost of these functions. Thanks, Ingo