From patchwork Mon Feb 13 19:07:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liang, Kan" X-Patchwork-Id: 56487 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2529127wrn; Mon, 13 Feb 2023 11:25:05 -0800 (PST) X-Google-Smtp-Source: AK7set8SR9LXiAxFppK1+RcduStnkV5kToRgM9qLZONTYWixf/h7Kg87XdUWNAgfFpkuqoCWr4nv X-Received: by 2002:a17:90a:19d2:b0:233:457f:e71c with SMTP id 18-20020a17090a19d200b00233457fe71cmr16191113pjj.38.1676316304925; Mon, 13 Feb 2023 11:25:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676316304; cv=none; d=google.com; s=arc-20160816; b=bl0OTK+zRAYNm7E58iWqAnDjBULInn2E4FzAhdlbokjmaY933Hy2k1AH4XMQDLit6J gjEJ8yaQzUHjHvNsuuZbvX3ubhYnA1sD5w3YQlxJ6Ct4IuVysV/pDysClwdq91Hv1UPc BQ5+Txzffb1nfE2/xlP3mdoC2t5d1ACEijoCDlu5QqKGJdmAXlxglqBj/Pby+/jikEMV DcKhD4y20usONkdP6lmS4x8YysRc8cpQudoSjyRODn1wIJAEeSc2uwI9pjiIsw/dMtUs G1Qc4KNQaLpRIxo/LPlsfs0YVktArJnvdkpZucbELVxp7JzNCM4dJ25UyXGnilEBbT+/ AmmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PaYKFWqHShaFq4ksvbV1pRFRktB1WYbs7ybV7XV8SLc=; b=Xju8sNhHAwJM8/ywXHgAY0kFXqoCcJMTyydyq3h+nklg8OnMN3nyRjuiGbBJdaRTpX X5mjEyQfsE9I70Wgd4NCOK1V/pS2MbMC8WogaTtShyYoUAPe4H/OB9PRfOaLWNCblXvg 6QJKKk6Dc7GrjzeLGlKbd3VXmNRAlAGjbKbr6uiuV4GHSNBceFXf9p0YZrdKtpIqguWj nGMbZHlcWcy+Mjkp+2uEzpfNZ12JUrbefu48GY3CRBwGxn+qIMFyf8RWuUaSSEI0CqHP kfyavSxUEwnilYz+XH474b/HvJvfvhteDoswY420vmTBHMMS5v6EpQcDLU0XnbnwHYKO DBYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=U9RvRuLY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iq9-20020a17090afb4900b00233f147ef63si3996737pjb.40.2023.02.13.11.24.52; Mon, 13 Feb 2023 11:25:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=U9RvRuLY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229818AbjBMTIC (ORCPT + 99 others); Mon, 13 Feb 2023 14:08:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229560AbjBMTH7 (ORCPT ); Mon, 13 Feb 2023 14:07:59 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE21FBB9C for ; Mon, 13 Feb 2023 11:07:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676315277; x=1707851277; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nthHD7ORD3zn2LmHh/lLY5cOKkIBSk15uJqRpUpGiOc=; b=U9RvRuLY9cvI44iibSx2NrKWux7oU5di7PofNUO+4kj0Yh0QNlaLvH6V q/nTnE7+Upz+4CB9ADJWNi/rOVK6xkTj3gRHyHkG5k4zLWbP2cpysPzLs mYY9cI6nxGGvFTcoacLNmFHfGzsIazk5GVg5VlCqhqfUi5RZjfuPB4zjN G5Y0RC4xucxVYyRIcTnK0eN4Akdmd7tGJK1CjWu/FqNyyE0iMQqOE1Gmc IbLHc2PSYZ8Tl0vrrlD+H+r3xBb0KolHc3O8hxW3E+tAFukKqViU2p4H4 mTZIXCwtSfFXit11r9yvYHdd7ovArQU7Te4W9R4X8dDC3V41lU36PgZG5 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="333108679" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="333108679" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 11:07:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="668901912" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="668901912" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2023 11:07:57 -0800 From: kan.liang@linux.intel.com To: tglx@linutronix.de, jstultz@google.com, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: sboyd@kernel.org, eranian@google.com, namhyung@kernel.org, ak@linux.intel.com, adrian.hunter@intel.com, Kan Liang Subject: [RFC PATCH V2 1/9] timekeeping: Expose the conversion information of monotonic raw Date: Mon, 13 Feb 2023 11:07:46 -0800 Message-Id: <20230213190754.1836051-2-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230213190754.1836051-1-kan.liang@linux.intel.com> References: <20230213190754.1836051-1-kan.liang@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757745046255193685?= X-GMAIL-MSGID: =?utf-8?q?1757745046255193685?= From: Kan Liang The conversion information of monotonic raw is not affected by NTP/PTP correction. The perf tool can utilize the information to correctly calculate the monotonic raw via a TSC in each PEBS record in the post-processing stage. The current conversion information is hidden in the internal struct tk_read_base. Add a new external struct ktime_conv to store and share the conversion information with other subsystems. Add a new interface ktime_get_fast_mono_raw_conv() to expose the conversion information of monotonic raw. The function probably be invoked in a NMI. Use NMI safe tk_fast_raw to retrieve the conversion information. Signed-off-by: Kan Liang --- include/linux/timekeeping.h | 18 ++++++++++++++++++ kernel/time/timekeeping.c | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index fe1e467ba046..94ba02e7eb13 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -253,6 +253,21 @@ struct system_time_snapshot { u8 cs_was_changed_seq; }; +/** + * struct ktime_conv - Timestamp conversion information + * @mult: Multiplier for scaled math conversion + * @shift: Shift value for scaled math conversion + * @xtime_nsec: Shifted (fractional) nano seconds offset for readout + * @base: (nanoseconds) base time for readout + */ +struct ktime_conv { + u64 cycle_last; + u32 mult; + u32 shift; + u64 xtime_nsec; + u64 base; +}; + /** * struct system_device_crosststamp - system/device cross-timestamp * (synchronized capture) @@ -297,6 +312,9 @@ extern void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot); /* NMI safe mono/boot/realtime timestamps */ extern void ktime_get_fast_timestamps(struct ktime_timestamps *snap); +/* NMI safe mono raw conv information */ +extern void ktime_get_fast_mono_raw_conv(struct ktime_conv *conv); + /* * Persistent clock related interfaces */ diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 5579ead449f2..a202b7a0a249 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -505,6 +505,30 @@ u64 notrace ktime_get_raw_fast_ns(void) } EXPORT_SYMBOL_GPL(ktime_get_raw_fast_ns); +/** + * ktime_get_fast_mono_raw_conv - NMI safe access to get the conversion + * information of clock monotonic raw + * + * The conversion information is not affected by NTP/PTP correction. + */ +void ktime_get_fast_mono_raw_conv(struct ktime_conv *conv) +{ + struct tk_fast *tkf = &tk_fast_raw; + struct tk_read_base *tkr; + unsigned int seq; + + do { + seq = raw_read_seqcount_latch(&tkf->seq); + tkr = tkf->base + (seq & 0x01); + conv->cycle_last = tkr->cycle_last; + conv->mult = tkr->mult; + conv->shift = tkr->shift; + conv->xtime_nsec = tkr->xtime_nsec; + conv->base = tkr->base; + } while (read_seqcount_latch_retry(&tkf->seq, seq)); +} +EXPORT_SYMBOL_GPL(ktime_get_fast_mono_raw_conv); + /** * ktime_get_boot_fast_ns - NMI safe and fast access to boot clock. * From patchwork Mon Feb 13 19:07:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liang, Kan" X-Patchwork-Id: 56481 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2523221wrn; Mon, 13 Feb 2023 11:12:27 -0800 (PST) X-Google-Smtp-Source: AK7set9QtjajTwIEtamXpFyjX3w1VMT+eBqmTl+zHobsXAL2qZ77zgdkHY9ykXx7X74UHSCQU2iz X-Received: by 2002:a17:906:774f:b0:8aa:c105:f0bf with SMTP id o15-20020a170906774f00b008aac105f0bfmr7202ejn.17.1676315547342; Mon, 13 Feb 2023 11:12:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676315547; cv=none; d=google.com; s=arc-20160816; b=ojwQY5Oo08TUNEc4yA/vGJhDpRMJPh2vmQQ5qXMOH9olMXQuCk11DUeiqXcpQiFP2P 1Xqt4EBLk0OVrW70B97DBNew16MUl6RjRykwi1dncwdJQGkQQjJwjhembfkzrw2ZTVBD wtEX6+aOODma/he34IxxceC18v6mRudkPyILxsjhh1W4ts9nEebCldFa2LPe/sYXRHi0 h8/b+o988WNqCt/LSZJbTQyqJtGoZcZBai28QQ+FYSBeV21fpl+ELGpPxQqyjEUouKP3 q0CYgLV+vcNb6jE1dBr0tiMkWoa7Hk2y5X2I8baUN2jxd9K92giIUAbP2c+PMfu9CFbp X86w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HS4NCgKo7FQixOuCxx6mZmkkPy4TpbN1VGgOt1VEqHE=; b=tfY8I/isCY8wRSy8kdEceUSwKX0+DY7eXuJ6jbDr94O5BDlKtI10LG4Atw2FXoSVtl UCEmqDXREQ1TRlnhXhvceG/6soQRn6IbKj+ktxLvWLbNaBnMNPY+1RIzQB0f6ozw2aCt uUU/s08+HEao3vXHCvec1+jkl6k6Scw/QZ9Kp+cGcvfZdbisiPbd92NG405bCH23SemB Plxoh3XYH290EaEjxP09EZu6UkQrbLzrFE/hQl8RpJY3yB4CKQ6lyg17hX8USHrk5FLg qeNFFogGXwZ+8+PhNv9+E7GEc345KOY3q3Pf2wTHRfC2Xw+LawNouXHslJLk2QxC13aJ zM1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g2KxmUMV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kb3-20020a170907924300b008988a44b121si13924649ejb.180.2023.02.13.11.12.04; Mon, 13 Feb 2023 11:12:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=g2KxmUMV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229767AbjBMTIE (ORCPT + 99 others); Mon, 13 Feb 2023 14:08:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229668AbjBMTH7 (ORCPT ); Mon, 13 Feb 2023 14:07:59 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14940CA1A for ; Mon, 13 Feb 2023 11:07:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676315279; x=1707851279; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9lgoINWxU1sPPhF4j2mJcGx7Hoa3TJdaZRev5+44tes=; b=g2KxmUMVoIAHC1Crf3KbXVJOTw+tVN+7qO9huGhP9xjmfV1EuHY2esDs pTb5e5iKbXCiYdu4t29T65YaqNAdPf1l/YqGS0jhDMWB2/kRwOwOtMxAe sCLOFLlqTaRHSvuM+u+isJPB9xKuqVMVWEI0HFATCuXFTGIY9A+TeqRTi FYQvy2GxzNhq4y92D0GJWpUK0QP2FGTwfiLmJLie0lk+nCT+2SNQAaSEM uqC71kQ2y/A2qxb1lz/2jFIOjKtXJFEqtoU8Op510wiDc/76AluopGltm eHltr98S0PkhS7ON50ZI1GDrSyZr7Lsv2KAmEXbXP/qHCoIa/jOpiecFK g==; X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="333108696" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="333108696" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 11:07:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="668901920" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="668901920" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2023 11:07:58 -0800 From: kan.liang@linux.intel.com To: tglx@linutronix.de, jstultz@google.com, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: sboyd@kernel.org, eranian@google.com, namhyung@kernel.org, ak@linux.intel.com, adrian.hunter@intel.com, Kan Liang Subject: [RFC PATCH V2 2/9] perf: Extend ABI to support post-processing monotonic raw conversion Date: Mon, 13 Feb 2023 11:07:47 -0800 Message-Id: <20230213190754.1836051-3-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230213190754.1836051-1-kan.liang@linux.intel.com> References: <20230213190754.1836051-1-kan.liang@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757744251658099453?= X-GMAIL-MSGID: =?utf-8?q?1757744251658099453?= From: Kan Liang The monotonic raw clock is not affected by NTP/PTP correction. The calculation of the monotonic raw clock can be done in the post-processing, which can reduce the kernel overhead. Add hw_time in the struct perf_event_attr to tell the kernel dump the raw HW time to user space. The perf tool will calculate the HW time in post-processing. Currently, only supports the monotonic raw conversion. Only dump the raw HW time with PERF_RECORD_SAMPLE, because the accurate HW time can only be provided in a sample by HW. For other type of records, the user requested clock should be returned as usual. Nothing is changed. Add perf_event_mmap_page::cap_user_time_mono_raw ABI to dump the conversion information. The cap_user_time_mono_raw also indicates whether the monotonic raw conversion information is available. If yes, the clock monotonic raw can be calculated as mono_raw = base + ((cyc - last) * mult + nsec) >> shift Signed-off-by: Kan Liang --- include/uapi/linux/perf_event.h | 21 ++++++++++++++++++--- kernel/events/core.c | 7 +++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h index ccb7f5dad59b..9d56fe027f6c 100644 --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -455,7 +455,8 @@ struct perf_event_attr { inherit_thread : 1, /* children only inherit if cloned with CLONE_THREAD */ remove_on_exec : 1, /* event is removed from task on exec */ sigtrap : 1, /* send synchronous SIGTRAP on event */ - __reserved_1 : 26; + hw_time : 1, /* generate raw HW time for samples */ + __reserved_1 : 25; union { __u32 wakeup_events; /* wakeup every n events */ @@ -615,7 +616,8 @@ struct perf_event_mmap_page { cap_user_time : 1, /* The time_{shift,mult,offset} fields are used */ cap_user_time_zero : 1, /* The time_zero field is used */ cap_user_time_short : 1, /* the time_{cycle,mask} fields are used */ - cap_____res : 58; + cap_user_time_mono_raw : 1, /* The time_mono_* fields are used */ + cap_____res : 57; }; }; @@ -692,11 +694,24 @@ struct perf_event_mmap_page { __u64 time_cycles; __u64 time_mask; + /* + * If cap_user_time_mono_raw, the monotonic raw clock can be calculated + * from the hardware clock (e.g. TSC) 'cyc'. + * + * mono_raw = base + ((cyc - last) * mult + nsec) >> shift + * + */ + __u64 time_mono_last; + __u32 time_mono_mult; + __u32 time_mono_shift; + __u64 time_mono_nsec; + __u64 time_mono_base; + /* * Hole for extension of the self monitor capabilities */ - __u8 __reserved[116*8]; /* align to 1k. */ + __u8 __reserved[112*8]; /* align to 1k. */ /* * Control data for the mmap() data buffer. diff --git a/kernel/events/core.c b/kernel/events/core.c index 380476a934e8..f062cce2dafc 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -12135,6 +12135,13 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr, if (attr->sigtrap && !attr->remove_on_exec) return -EINVAL; + if (attr->use_clockid) { + /* + * Only support post-processing for the monotonic raw clock + */ + if (attr->hw_time && (attr->clockid != CLOCK_MONOTONIC_RAW)) + return -EINVAL; + } out: return ret; From patchwork Mon Feb 13 19:07:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liang, Kan" X-Patchwork-Id: 56492 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2532494wrn; Mon, 13 Feb 2023 11:32:08 -0800 (PST) X-Google-Smtp-Source: AK7set+L+Iyza2ZiPUxaGgpEFnqrHqcuxqtVVeV8mI70oG8+on9UisTHDmw37M9GjO0nUmR8SWbj X-Received: by 2002:a17:906:3654:b0:87f:546d:7cb4 with SMTP id r20-20020a170906365400b0087f546d7cb4mr14848ejb.64.1676316728054; Mon, 13 Feb 2023 11:32:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676316728; cv=none; d=google.com; s=arc-20160816; b=JO+9GvYzKKQYDk85cNqIm5smLRm0HYUnPCFZMSa7IvfthD8tjh1hO6l4OF1gGdTX9G sDeE2heihqDE3JCt4OtYQGaQMK5hsmyagnreczmQI6AZOrt6fmdEoemHZCQoTHHVmf6K WLTR9rGe3TcKDt6zxwH0BFIlP51bN42B5D74LE9dJs4xlf1W6dmGeNI7XYxd7baPlfTP JCTDIXnoYLwUIBMjvlaQxquZyOK9FuymCcsQot4gKvAmiD65uJTDytcE7gQfje1qGyf6 V9mN/8rcxH+wb/qxvlVn4tVf5p4O0yghI+sVgJEUnYfFhNVSvk9zzc1As8gdwpqJpAc+ L0zA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5vaoRm8zr9quVwlGG6a10UuSMEjR6U3xnG70V43SpK0=; b=l4OvynOvU0kSQZe5Lo7cbe0nRvOtYktn1JbZerMM2V7VhkQD/c2H0fmIUIRqODkdJq 3j4q0bUQtr7e0iDyuZgsaZtjYQgi91LqQraN/2XbHPTVdBRZIPfek0oAhEW8HF8Q2Jbg ux5+Sv8aIbbHPqflpta0vu0kz/GoeRja92Vmgh5G37qrUj+aFyiFBj+br+l29BAlsFko WLAERV7HFPdTvLxBAFPLEb/kg9JYIkwazsoTTX1Pq4Ly91InAHko9nMdDVGQhuv1rmxK FcqfxcJmZ9iJJAGip8ePRJcQhnHyyJ0flT3vTA4fkDPwjofnphB+Xm5Bkjd8SK74q/Mj ybQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=T7nwOSAw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wj23-20020a170907051700b008b1278ab9ccsi528709ejb.849.2023.02.13.11.31.44; Mon, 13 Feb 2023 11:32:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=T7nwOSAw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230135AbjBMTIN (ORCPT + 99 others); Mon, 13 Feb 2023 14:08:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230038AbjBMTIG (ORCPT ); Mon, 13 Feb 2023 14:08:06 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B181D20D13 for ; Mon, 13 Feb 2023 11:08:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676315284; x=1707851284; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c/ssmWV2rsADLLuYj8FPgrlgffTVyCWr1wk53uQoQzs=; b=T7nwOSAwKCm6JusTwbhnPqd2EAQXqjU3LA+xw2/vs8ASzYfLxmNhPTQb lVsorpwn3Ac+bnX/yd/6WtD6W3ZC2Ot+05YRfswS1Y3iL+K0SQE/ojlSC 038hyGVhIL6uQenesZsCvAR9lLruB9ba3EsVBR9Lnx5DIurWkOxBWrXeZ iIUsHr2hMdTiv/bFvABItsYGlaBIfqbB6mJeg3FwncTMlzUjLuPFM6ISM g//ZvxULY43xCZ05HhV333q1R3dpXMaXzb4bKpJUScmVK+N7J6AZ8awT/ +0OSoIrfTGotUXD5ZMsucvDg/dk65CZJStv38M+euJgSIwHaik9N5suMI A==; X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="333108728" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="333108728" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 11:08:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="668901940" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="668901940" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2023 11:08:03 -0800 From: kan.liang@linux.intel.com To: tglx@linutronix.de, jstultz@google.com, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: sboyd@kernel.org, eranian@google.com, namhyung@kernel.org, ak@linux.intel.com, adrian.hunter@intel.com, Kan Liang , Ravi Bangoria Subject: [RFC PATCH V2 3/9] perf/x86: Factor out x86_pmu_sample_preload() Date: Mon, 13 Feb 2023 11:07:48 -0800 Message-Id: <20230213190754.1836051-4-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230213190754.1836051-1-kan.liang@linux.intel.com> References: <20230213190754.1836051-1-kan.liang@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757745489490128540?= X-GMAIL-MSGID: =?utf-8?q?1757745489490128540?= From: Kan Liang Some common sample data are preloaded on X86 platforms before the sample output. For example, the branch stack information. Factor out a generic x86_pmu_sample_preload(). It will also be used later to preload the common HW time, TSC. Signed-off-by: Kan Liang Cc: Ravi Bangoria --- arch/x86/events/amd/core.c | 3 +-- arch/x86/events/core.c | 5 +---- arch/x86/events/intel/core.c | 3 +-- arch/x86/events/intel/ds.c | 3 +-- arch/x86/events/perf_event.h | 8 ++++++++ 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c index 8c45b198b62f..af7b3977efa8 100644 --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -928,8 +928,7 @@ static int amd_pmu_v2_handle_irq(struct pt_regs *regs) if (!x86_perf_event_set_period(event)) continue; - if (has_branch_stack(event)) - perf_sample_save_brstack(&data, event, &cpuc->lbr_stack); + x86_pmu_sample_preload(&data, event, cpuc); if (perf_event_overflow(event, &data, regs)) x86_pmu_stop(event, 0); diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 85a63a41c471..b19ac54ebeea 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -1703,10 +1703,7 @@ int x86_pmu_handle_irq(struct pt_regs *regs) perf_sample_data_init(&data, 0, event->hw.last_period); - if (has_branch_stack(event)) { - data.br_stack = &cpuc->lbr_stack; - data.sample_flags |= PERF_SAMPLE_BRANCH_STACK; - } + x86_pmu_sample_preload(&data, event, cpuc); if (perf_event_overflow(event, &data, regs)) x86_pmu_stop(event, 0); diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 14f0a746257d..d9be5701e60a 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -3036,8 +3036,7 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status) perf_sample_data_init(&data, 0, event->hw.last_period); - if (has_branch_stack(event)) - perf_sample_save_brstack(&data, event, &cpuc->lbr_stack); + x86_pmu_sample_preload(&data, event, cpuc); if (perf_event_overflow(event, &data, regs)) x86_pmu_stop(event, 0); diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c index 7980e92dec64..2f59573ed463 100644 --- a/arch/x86/events/intel/ds.c +++ b/arch/x86/events/intel/ds.c @@ -1742,8 +1742,7 @@ static void setup_pebs_fixed_sample_data(struct perf_event *event, if (x86_pmu.intel_cap.pebs_format >= 3) setup_pebs_time(event, data, pebs->tsc); - if (has_branch_stack(event)) - perf_sample_save_brstack(data, event, &cpuc->lbr_stack); + x86_pmu_sample_preload(data, event, cpuc); } static void adaptive_pebs_save_regs(struct pt_regs *regs, diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h index d6de4487348c..ae6ec58fde14 100644 --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -1185,6 +1185,14 @@ int x86_pmu_handle_irq(struct pt_regs *regs); void x86_pmu_show_pmu_cap(int num_counters, int num_counters_fixed, u64 intel_ctrl); +static inline void x86_pmu_sample_preload(struct perf_sample_data *data, + struct perf_event *event, + struct cpu_hw_events *cpuc) +{ + if (has_branch_stack(event)) + perf_sample_save_brstack(data, event, &cpuc->lbr_stack); +} + extern struct event_constraint emptyconstraint; extern struct event_constraint unconstrained; From patchwork Mon Feb 13 19:07:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liang, Kan" X-Patchwork-Id: 56494 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2532645wrn; Mon, 13 Feb 2023 11:32:24 -0800 (PST) X-Google-Smtp-Source: AK7set/9sb2HeHE3M8OmhxC6UfeoC6t2a6X9HHbpCpqcwEQJi01gNnX3A8qTHtw/oF+/tiPuPV0f X-Received: by 2002:a17:907:9490:b0:889:58bd:86f1 with SMTP id dm16-20020a170907949000b0088958bd86f1mr90006ejc.14.1676316744732; Mon, 13 Feb 2023 11:32:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676316744; cv=none; d=google.com; s=arc-20160816; b=oz8gfre0wrMaIGd8CVxHGAOTCLKA0ClhPjl8yJiQTQz3lITlu7Bzpd0bVEEdnutv/E fh6wobyW8BonX0PQStFFMQ1N+5CyzGRa2OkcSg6gZh8ZuGHt4gC+mGXSdJWCcajWMgCL UpVhrp1n+TibxoakFh/z3Eb011a9a8tdevrscxuX7lzNJdlRZjJLB7nI+Or23U1K1bAp MkHsh81YpWbpn3yXifYD6Ba7Fa4XlKVZsqPSt8yjxyUX6uQH22i4FuPnxauuIPSlMnKZ ptd+gmhvhaF/+/3YdX/agL4ewkIXWgQjJQmQm29XkauOifZFh6hjCkmc7rS5cybzEbPw smxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ewN9uvwiqeyb3SbxrjPiheq8K9KVjnhmIdMgHQ37Xh4=; b=svZNQ5rQQQ0OCYGzwkcXEk/yMPF9SqGQpKnokEzzmrekFQo1Oq3oH5w7e8/RLAfGYd 32hIE7XeOyqEA7NQvwBTkGmBZtxCnXzUDITQb0w0JcZIkA/45m1uzDr4lsCFOXxvdH2b N3rjXiSTqFF3JHV3mYs/4sewpof86OQOnNY68nLKMPLFQzdSriIDC3y8P2INe9iC9Vzq JLSXCxDglxt2TfKFqCI8Owtc+rJ873DXOQx1CIU4Yk0gopqe4Iq1Ut72mVsWsIQpXdtv 0mhLZDCwiY/nQQdEn5raQ6CQLU8vPtq6/sqlH+ZDHREu0oK1Zcf8Jwck8P9Zb5FgMtiF 9c+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=W61ZLQ1L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wi4-20020a170906fd4400b008b12a3a6f7esi62883ejb.147.2023.02.13.11.32.01; Mon, 13 Feb 2023 11:32:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=W61ZLQ1L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230121AbjBMTIQ (ORCPT + 99 others); Mon, 13 Feb 2023 14:08:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230199AbjBMTIK (ORCPT ); Mon, 13 Feb 2023 14:08:10 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D5D6113FF for ; Mon, 13 Feb 2023 11:08:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676315286; x=1707851286; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fxFiGFPky9M3poyi0730g1j+bTkHg+8oo/QfUKfpmfE=; b=W61ZLQ1LWzYrf4I3Ba/hdnO/+e9BkSaup7utoAXJIJU52KCsx9gCAB9H dM3ZN01qyZlYBnphcOM4KVRtaYHxINvdbig+XAYZ1U4SfRx2CUfENSWGv 22b1oirDuuqVze+bOapS2lEWZ0vpFBcIcASP3pElXzIkMkC1ksbWmxa28 TxabMpRJ6qhkQyooyeGjESIMauXyHfcyMQsKjxWrWr7SMFDyULL62vEEz lGfKOnlfoV31/Hd3qFNJ8K4PVbuPOTswYtAgqaOw+42rKDpW2aBPrlsS7 Afn8uBZYi7XQBICX/ao/aRdXQpacfuiADIDlcF0YrW5oa5Zsllon723lK A==; X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="333108738" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="333108738" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 11:08:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="668901943" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="668901943" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2023 11:08:05 -0800 From: kan.liang@linux.intel.com To: tglx@linutronix.de, jstultz@google.com, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: sboyd@kernel.org, eranian@google.com, namhyung@kernel.org, ak@linux.intel.com, adrian.hunter@intel.com, Kan Liang , Ravi Bangoria Subject: [RFC PATCH V2 4/9] perf/x86: Enable post-processing monotonic raw conversion Date: Mon, 13 Feb 2023 11:07:49 -0800 Message-Id: <20230213190754.1836051-5-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230213190754.1836051-1-kan.liang@linux.intel.com> References: <20230213190754.1836051-1-kan.liang@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757745506969502780?= X-GMAIL-MSGID: =?utf-8?q?1757745506969502780?= From: Kan Liang The raw HW time is from TSC on X86. Preload the HW time for each sample, once the hw_time is set with the monotonic raw clock by the new perf tool. Also, dump the conversion information into mmap_page. For the legacy perf tool which doesn't know the hw_time, nothing is changed. Move the x86_pmu_sample_preload() before setup_pebs_time() to utilize the TSC from a PEBS record. Signed-off-by: Kan Liang Cc: Ravi Bangoria --- arch/x86/events/core.c | 10 ++++++++++ arch/x86/events/intel/ds.c | 14 +++++++++++--- arch/x86/events/perf_event.h | 12 ++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index b19ac54ebeea..7c1dfb8c763d 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2740,6 +2740,16 @@ void arch_perf_update_userpage(struct perf_event *event, if (!event->attr.use_clockid) { userpg->cap_user_time_zero = 1; userpg->time_zero = offset; + } else if (perf_event_hw_time(event)) { + struct ktime_conv mono; + + userpg->cap_user_time_mono_raw = 1; + ktime_get_fast_mono_raw_conv(&mono); + userpg->time_mono_last = mono.cycle_last; + userpg->time_mono_mult = mono.mult; + userpg->time_mono_shift = mono.shift; + userpg->time_mono_nsec = mono.xtime_nsec; + userpg->time_mono_base = mono.base; } cyc2ns_read_end(); diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c index 2f59573ed463..10d4b63c891f 100644 --- a/arch/x86/events/intel/ds.c +++ b/arch/x86/events/intel/ds.c @@ -1574,6 +1574,12 @@ static void setup_pebs_time(struct perf_event *event, struct perf_sample_data *data, u64 tsc) { + u64 time = tsc; + + /* Perf tool does the conversion. No conversion here. */ + if (perf_event_hw_time(event)) + goto done; + /* Converting to a user-defined clock is not supported yet. */ if (event->attr.use_clockid != 0) return; @@ -1588,7 +1594,9 @@ static void setup_pebs_time(struct perf_event *event, if (!using_native_sched_clock() || !sched_clock_stable()) return; - data->time = native_sched_clock_from_tsc(tsc) + __sched_clock_offset; + time = native_sched_clock_from_tsc(tsc) + __sched_clock_offset; +done: + data->time = time; data->sample_flags |= PERF_SAMPLE_TIME; } @@ -1733,6 +1741,8 @@ static void setup_pebs_fixed_sample_data(struct perf_event *event, } } + x86_pmu_sample_preload(data, event, cpuc); + /* * v3 supplies an accurate time stamp, so we use that * for the time stamp. @@ -1741,8 +1751,6 @@ static void setup_pebs_fixed_sample_data(struct perf_event *event, */ if (x86_pmu.intel_cap.pebs_format >= 3) setup_pebs_time(event, data, pebs->tsc); - - x86_pmu_sample_preload(data, event, cpuc); } static void adaptive_pebs_save_regs(struct pt_regs *regs, diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h index ae6ec58fde14..0486ee6a7605 100644 --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -1185,12 +1185,24 @@ int x86_pmu_handle_irq(struct pt_regs *regs); void x86_pmu_show_pmu_cap(int num_counters, int num_counters_fixed, u64 intel_ctrl); +static inline bool perf_event_hw_time(struct perf_event *event) +{ + return (event->attr.hw_time && + event->attr.use_clockid && + (event->attr.clockid == CLOCK_MONOTONIC_RAW)); +} + static inline void x86_pmu_sample_preload(struct perf_sample_data *data, struct perf_event *event, struct cpu_hw_events *cpuc) { if (has_branch_stack(event)) perf_sample_save_brstack(data, event, &cpuc->lbr_stack); + + if (perf_event_hw_time(event)) { + data->time = rdtsc(); + data->sample_flags |= PERF_SAMPLE_TIME; + } } extern struct event_constraint emptyconstraint; From patchwork Mon Feb 13 19:07:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liang, Kan" X-Patchwork-Id: 56483 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2524895wrn; Mon, 13 Feb 2023 11:15:46 -0800 (PST) X-Google-Smtp-Source: AK7set91OMoe1vqLSm/dI/gSVIJjd6lw4uPw0O+Jb1jZ8YEFreJhthQaSbLKoiKnm6xhDCUvnLoB X-Received: by 2002:adf:ce01:0:b0:2c4:840:c86d with SMTP id p1-20020adfce01000000b002c40840c86dmr14620151wrn.44.1676315746255; Mon, 13 Feb 2023 11:15:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676315746; cv=none; d=google.com; s=arc-20160816; b=CaHZ3/aqEVkP/nJOmyxUBRe2UVt4XxumgLQHanXMHFHxplEJJjAykN495fk9qYWezO 3357ujzcP/36JkrdWCkLRWXI3hrX5Q8+qvQ0E6rWcvSsUOLVgVqyEld2je8LtW9pKd0T GR1PQqnrSRCW1ML1jkRS1w3XwqnI+rEssoePIuyjrJMu+Ia7JmRjIBYG+CRcRCuSQJoC gPkJLn77Z4PiWxMAC6PFAp3i6ZO+ILFTl1vG77DEQc+iDCra3+rhJFESYBqs0Dh11RDI 4sX77W8Ly/W4C215qs/9MlcP559uJjaeAAq5ZdR/wkhQcelS8VZRYVgbHFGkBErDh+Z5 OaeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oz5Mrairh3yNBAhONHw4gDOsj8eYXXkRDnEtROaaWb4=; b=FnrhngAuWhOPTmBmgwiQQVcIF360zJfmNHvEj6rawPhL445Vg4k/N9bz8k1pQutBZg Qw8z1HxJSd5LeobbgiAoSlsZF0KFp1pM9U2iiZ8nDPcx1c3hMXAeKQUHMbnDDsmz7e+9 AIcYtS0FykXJgbwkcDDVrBQ8Y3nM/bvuatLWiDD8dTCuewEF+/jQ75u3YH9f92cinad1 PHTpFtI2/0/ANUz7cs6VL6dKdiX2DHhzc+kUQIufQ6qDy9cAj8rOt61Q8CgT+khjhQxl PAiwjdu2GE6pzNxwF6p15UxwtLsnBT5U8FOxaf+XJ6nwc0GNmu1cDK8Z3ADvj3vYvE3l 2n8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aKK74wCE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i17-20020a5d5231000000b002be1d4675fdsi12590249wra.124.2023.02.13.11.15.14; Mon, 13 Feb 2023 11:15:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=aKK74wCE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230480AbjBMTIS (ORCPT + 99 others); Mon, 13 Feb 2023 14:08:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230074AbjBMTIL (ORCPT ); Mon, 13 Feb 2023 14:08:11 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E39B76E80 for ; Mon, 13 Feb 2023 11:08:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676315286; x=1707851286; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X9aN6C+r13kwLYq+5iI5APWDkP47jg3B6kqADSWKNhM=; b=aKK74wCEIiSvFaYQeCUtkXBYhpexCr3jy2ES9NUgOznOWSeZEM7dAIQK 6An1x/xqeBVAVNv6QDXvC8A/L80kIpdCyd1jWNJ2Iu/ixsK415AkdwK1q d48BoRfQ5lnBnXGsGw4yhO8SY58O0S86zQt2/H8isprCnOjbkn6HtEQ+H AVLGYvPcwkHE0B8mitvNKxbK0frWC7B+Z4E/ihTm9r12oOT5ifxvrwjdr TNjcAa5DrLnBVKry+612yl39bdMcx3cIwgjDv53HBhCXZ3WQNnNx1ln/v Wi2Gp54cKHOuq+pcrongR2C5OBeo56mi3fuDD2yF34O3SBLaY5s9vDjKN w==; X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="333108757" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="333108757" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 11:08:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="668901950" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="668901950" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2023 11:08:06 -0800 From: kan.liang@linux.intel.com To: tglx@linutronix.de, jstultz@google.com, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: sboyd@kernel.org, eranian@google.com, namhyung@kernel.org, ak@linux.intel.com, adrian.hunter@intel.com, Kan Liang Subject: [RFC PATCH V2 5/9] perf/x86/intel: Enable large PEBS for monotonic raw Date: Mon, 13 Feb 2023 11:07:50 -0800 Message-Id: <20230213190754.1836051-6-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230213190754.1836051-1-kan.liang@linux.intel.com> References: <20230213190754.1836051-1-kan.liang@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757744459605424720?= X-GMAIL-MSGID: =?utf-8?q?1757744459605424720?= From: Kan Liang The monotonic raw clock is not affected by NTP/PTP correction. The monotonic raw clock can be calculated from the TSC of each PEBS record by the same conversion information. Signed-off-by: Kan Liang --- arch/x86/events/intel/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index d9be5701e60a..eac389e1f44c 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -3776,7 +3776,8 @@ static unsigned long intel_pmu_large_pebs_flags(struct perf_event *event) { unsigned long flags = x86_pmu.large_pebs_flags; - if (event->attr.use_clockid) + if (event->attr.use_clockid && + !((x86_pmu.intel_cap.pebs_format >= 3) && perf_event_hw_time(event))) flags &= ~PERF_SAMPLE_TIME; if (!event->attr.exclude_kernel) flags &= ~PERF_SAMPLE_REGS_USER; From patchwork Mon Feb 13 19:07:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liang, Kan" X-Patchwork-Id: 56485 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2527722wrn; Mon, 13 Feb 2023 11:21:56 -0800 (PST) X-Google-Smtp-Source: AK7set82YURJy0cHgQcx5qdmiCPmTCWUAo1zNgjW9xcy/92Q+2N5GqVhD2MAGdPe+MsWzDpemRxZ X-Received: by 2002:a17:902:f2cd:b0:19a:96f0:b0f with SMTP id h13-20020a170902f2cd00b0019a96f00b0fmr4916575plc.28.1676316116528; Mon, 13 Feb 2023 11:21:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676316116; cv=none; d=google.com; s=arc-20160816; b=qQ32buK/aDesPlRnHWSbTR+3Mfzw47VkEvwaYC2xPQ7S0xfYOd4vtbVAiYyWFLayrN JbpgsqrqXmXrsjoKYbBTfHAp/P7vW9pJhrsFv71UEeCoUUnyV3FoKfEldGHrbuPnF1gq RI0tO7rDlnPEiNXUsg+lehNJQKvrYeZJJ0MdH/+I8kRI3Kf2k1rq07F6JaLVmBsBc8pq CpYIdbQNZc1YkApnyg726WovulD5uxkAUqWXEmhW+oYztcgkYc0vzi4i547JHtU28akf ghTYQeKUpj3vTHJGAv2kLl6z1KMkluwc2Ib2dRMZnGCnpMX2yQAgyDoNiP73JE7Djs5Q H06A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0XSQr4vFXIkiQji+oykr0KEjDMCU6klh9i6WPPXXCuw=; b=xlkcFuIJy+mKuUGw7lMC1phgXpv6hNN06d3n1ULhVNMV7ENq15E3ttbMfxNBGke8hi j5ex7IEr60tYbdWFNr6cjF0Bv/X8UJ2yzDEEeIw/76A1vic8p8PI/1/zEJsHDyfx89jE c4ob2/T6QyTl/eoQYJWmn6GZXVl+0Z31UIyDfgFVF/0GVDWEz4FeuVSIBMlDvvIBim5D gRcLQI2n5EmdmGOWfiAwk61HU6dm+QyBxOpolWBdEYAlQzYYigAQJ/V0akMv1UrmWGc6 DSSPLy+PkNISAWg/LNi7BZYXgpARzKKM7Bnny2CZfmYCFtTCXJYwEn+k45moA4eRujQ2 MiHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BBHEk5HP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k8-20020a170902c40800b001926b288ae9si6301427plk.82.2023.02.13.11.21.44; Mon, 13 Feb 2023 11:21:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BBHEk5HP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231124AbjBMTIZ (ORCPT + 99 others); Mon, 13 Feb 2023 14:08:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230292AbjBMTIL (ORCPT ); Mon, 13 Feb 2023 14:08:11 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EB6C21A19 for ; Mon, 13 Feb 2023 11:08:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676315288; x=1707851288; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ew5LHI5pCmCiUBMVzv2I8reY5qJGqW8V/hL9T+aryPM=; b=BBHEk5HPSfq9c+Jm60Gw/Ydm8f+79enTtISNBSd06JVpinuHb76jKCHo UPRQyFK8SgT0dx/ftqXrun8CVXP3Y1NLv78GP6/G2LoLQNJpuKYDfQut8 bl4mC2XW09kR/sMVLrh/0zt951Gd5bh2S35MWTjZ6x4Mknp7Jp+5lO488 Eig/p0xUMwbZ9c4DsSAIDMKcg4gr4eHtLucB7jlO0ZNyCSvWdmjUKZY2k 7FzvN/GBjyhRwLDAKHLIMTyYO9lilwQMK3Rzhd5DT64fLDmZ0wPvuzkBD oKJTpEU+muyIEOsVb/NIV2WrWt8roRcox/ofsU64xFg/LrzR+vmUhOImz Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="333108766" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="333108766" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 11:08:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="668901955" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="668901955" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2023 11:08:07 -0800 From: kan.liang@linux.intel.com To: tglx@linutronix.de, jstultz@google.com, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: sboyd@kernel.org, eranian@google.com, namhyung@kernel.org, ak@linux.intel.com, adrian.hunter@intel.com, Kan Liang Subject: [RFC PATCH V2 6/9] tools headers UAPI: Sync linux/perf_event.h with the kernel sources Date: Mon, 13 Feb 2023 11:07:51 -0800 Message-Id: <20230213190754.1836051-7-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230213190754.1836051-1-kan.liang@linux.intel.com> References: <20230213190754.1836051-1-kan.liang@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757744848544020009?= X-GMAIL-MSGID: =?utf-8?q?1757744848544020009?= From: Kan Liang The kernel ABI has been extended to support tool based monotonic raw conversion. This thus partially addresses this perf build warning: Warning: Kernel ABI header at 'tools/include/uapi/linux/perf_event.h' differs from latest version at 'include/uapi/linux/perf_event.h' diff -u tools/include/uapi/linux/perf_event.h include/uapi/linux/perf_event.h Signed-off-by: Kan Liang --- tools/include/uapi/linux/perf_event.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h index ccb7f5dad59b..9d56fe027f6c 100644 --- a/tools/include/uapi/linux/perf_event.h +++ b/tools/include/uapi/linux/perf_event.h @@ -455,7 +455,8 @@ struct perf_event_attr { inherit_thread : 1, /* children only inherit if cloned with CLONE_THREAD */ remove_on_exec : 1, /* event is removed from task on exec */ sigtrap : 1, /* send synchronous SIGTRAP on event */ - __reserved_1 : 26; + hw_time : 1, /* generate raw HW time for samples */ + __reserved_1 : 25; union { __u32 wakeup_events; /* wakeup every n events */ @@ -615,7 +616,8 @@ struct perf_event_mmap_page { cap_user_time : 1, /* The time_{shift,mult,offset} fields are used */ cap_user_time_zero : 1, /* The time_zero field is used */ cap_user_time_short : 1, /* the time_{cycle,mask} fields are used */ - cap_____res : 58; + cap_user_time_mono_raw : 1, /* The time_mono_* fields are used */ + cap_____res : 57; }; }; @@ -692,11 +694,24 @@ struct perf_event_mmap_page { __u64 time_cycles; __u64 time_mask; + /* + * If cap_user_time_mono_raw, the monotonic raw clock can be calculated + * from the hardware clock (e.g. TSC) 'cyc'. + * + * mono_raw = base + ((cyc - last) * mult + nsec) >> shift + * + */ + __u64 time_mono_last; + __u32 time_mono_mult; + __u32 time_mono_shift; + __u64 time_mono_nsec; + __u64 time_mono_base; + /* * Hole for extension of the self monitor capabilities */ - __u8 __reserved[116*8]; /* align to 1k. */ + __u8 __reserved[112*8]; /* align to 1k. */ /* * Control data for the mmap() data buffer. From patchwork Mon Feb 13 19:07:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liang, Kan" X-Patchwork-Id: 56486 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2528401wrn; Mon, 13 Feb 2023 11:23:34 -0800 (PST) X-Google-Smtp-Source: AK7set/WdWmhPaezv5CoSnxMT6r0Jw9v1GBbOddxs2mn5m5ahfwiNRTcfTFPJmRXi17cQkiDVzQN X-Received: by 2002:a17:902:f20c:b0:19a:93fc:c4d0 with SMTP id m12-20020a170902f20c00b0019a93fcc4d0mr29888plc.12.1676316214576; Mon, 13 Feb 2023 11:23:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676316214; cv=none; d=google.com; s=arc-20160816; b=gD4Ph6l+JJ/hLYyySzgOzjILR37UGMCAsb31NUXnxu5L1adqH0+AeWmGoYy8iT4NWB NI+u/rXc931NVRPYwY4h//flkbxqCx9FLoKLNI+19LnpifzGZTd2QpjX7xT5Vvcm0TNX KXvHoPjJbdK/AvPqhK0Q3vgpqyJ7RlJwxlvfpr4RPH5KdjEKk1W0VZ3WHqmQz7re7rWI W+C9PV/ZZBaBHyr7OPTaqzwRvdfX79FZDDPyto0DdEjROrgvflK5VHTvfFdaZF6WiPly 9jbBiQEcfpW+VBFJZfdjGdSng8IxFVcK+OzQSOKSIlq/gBla2NvAK2SxRVAj6cVJt73g L9+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=U9Q+FR6zsAU//0JAAtcScHU8RKWzIscn6K+nKiXzfoI=; b=vmUs8Baqj85HI6g6IAsJ88TP71O9z18BHg0m+kFYx2xbvsH2683UGFOxLUKJLkH6Zo qYSFRlLvV7SpJRZAw4ab/qYV3K3P6jIL2ulaoNTmXw5D0mcUKquXQAbjMVp6svfAeK7q M5EuG0p6aur8zUvKZZzByzLhqAq2z8CmdMnE8h3yttDM6wzTjCfBGemHEPDNWtU5h04D 5M4S+D0u0fia/UsbpoyEaudBqho1NjjgJV3XMFLlBbmKnvzkV418jLJ+PYyfLFMeVor5 pUI/H0lAakvzjRZJBzTqOsCOdp9VE1zV04fsPS9NHaCg/+2r7stGj1jpfZ6JegT2QjYM i6pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PIESye95; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w3-20020a170902904300b001993f9bdc13si9036357plz.494.2023.02.13.11.23.21; Mon, 13 Feb 2023 11:23:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PIESye95; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230292AbjBMTI2 (ORCPT + 99 others); Mon, 13 Feb 2023 14:08:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230378AbjBMTIO (ORCPT ); Mon, 13 Feb 2023 14:08:14 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42FE712F26 for ; Mon, 13 Feb 2023 11:08:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676315289; x=1707851289; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MsZexMlSjxnKR+I1ycQ9RqJ26PCvPIyRW1Mj53H7MC4=; b=PIESye95aYFhcKpERBIKzGflt8OP70tCxvDAgmPOq7yseNcaxR5/AK1s qjtlvwRZiU5hBGSXaOwgANi/9Z6WqBXXrVZ67dxvlPsFD1oneMjOFPJrS gK5l5cOdvQi9wOGGLK1lbAPX20UBGXEKFaxo2z1Ny8S2RUnGrfro3ugAp TP7bC3mSOc4cLs7lcefGviVBAumyQYFocp1eXCmAdvKA8k36JorvZ0GDX 0pvPA1hS5nCTdeH+UdlKFqKriW5XLGD3qE/7gsnPEiUVQC9nQc4qemA35 ZlYRyFuFMFbDR4tUfLbcfRiLJOCrg6ItdpoAwi8sIj2rxscfuKFDsPIz1 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="333108781" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="333108781" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 11:08:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="668901959" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="668901959" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2023 11:08:08 -0800 From: kan.liang@linux.intel.com To: tglx@linutronix.de, jstultz@google.com, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: sboyd@kernel.org, eranian@google.com, namhyung@kernel.org, ak@linux.intel.com, adrian.hunter@intel.com, Kan Liang Subject: [RFC PATCH V2 7/9] perf session: Support the monotonic raw clock conversion information Date: Mon, 13 Feb 2023 11:07:52 -0800 Message-Id: <20230213190754.1836051-8-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230213190754.1836051-1-kan.liang@linux.intel.com> References: <20230213190754.1836051-1-kan.liang@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757744950789001572?= X-GMAIL-MSGID: =?utf-8?q?1757744950789001572?= From: Kan Liang The monotonic raw clock conversion information can be retrieved from the perf_event_mmap_page::cap_user_time_mono_raw ABI. Store the information in the struct perf_record_time_conv for later usage. Dump the information in TIME_CONV event as well. Signed-off-by: Kan Liang --- tools/lib/perf/include/perf/event.h | 8 +++++++- tools/perf/util/session.c | 8 ++++++++ tools/perf/util/tsc.c | 22 +++++++++++++++++++++- tools/perf/util/tsc.h | 6 ++++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/perf/event.h index ad47d7b31046..20187a3d84c8 100644 --- a/tools/lib/perf/include/perf/event.h +++ b/tools/lib/perf/include/perf/event.h @@ -422,9 +422,15 @@ struct perf_record_time_conv { __u64 time_zero; __u64 time_cycles; __u64 time_mask; + __u64 time_mono_last; + __u32 time_mono_mult; + __u32 time_mono_shift; + __u64 time_mono_nsec; + __u64 time_mono_base; __u8 cap_user_time_zero; __u8 cap_user_time_short; - __u8 reserved[6]; /* For alignment */ + __u8 cap_user_time_mono_raw; + __u8 reserved[5]; /* For alignment */ }; struct perf_record_header_feature { diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 7c021c6cedb9..189149a7012f 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -995,6 +995,14 @@ static void perf_event__time_conv_swap(union perf_event *event, event->time_conv.time_cycles = bswap_64(event->time_conv.time_cycles); event->time_conv.time_mask = bswap_64(event->time_conv.time_mask); } + + if (event_contains(event->time_conv, time_mono_last)) { + event->time_conv.time_mono_last = bswap_64(event->time_conv.time_mono_last); + event->time_conv.time_mono_mult = bswap_32(event->time_conv.time_mono_mult); + event->time_conv.time_mono_shift = bswap_32(event->time_conv.time_mono_shift); + event->time_conv.time_mono_nsec = bswap_64(event->time_conv.time_mono_nsec); + event->time_conv.time_mono_base = bswap_64(event->time_conv.time_mono_base); + } } typedef void (*perf_event__swap_op)(union perf_event *event, diff --git a/tools/perf/util/tsc.c b/tools/perf/util/tsc.c index f19791d46e99..0b59c0f815f9 100644 --- a/tools/perf/util/tsc.c +++ b/tools/perf/util/tsc.c @@ -54,8 +54,14 @@ int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc, tc->time_zero = pc->time_zero; tc->time_cycles = pc->time_cycles; tc->time_mask = pc->time_mask; + tc->time_mono_last = pc->time_mono_last; + tc->time_mono_mult = pc->time_mono_mult; + tc->time_mono_shift = pc->time_mono_shift; + tc->time_mono_nsec = pc->time_mono_nsec; + tc->time_mono_base = pc->time_mono_base; tc->cap_user_time_zero = pc->cap_user_time_zero; tc->cap_user_time_short = pc->cap_user_time_short; + tc->cap_user_time_mono_raw = pc->cap_user_time_mono_raw; rmb(); if (pc->lock == seq && !(seq & 1)) break; @@ -65,7 +71,7 @@ int perf_read_tsc_conversion(const struct perf_event_mmap_page *pc, } } - if (!tc->cap_user_time_zero) + if (!tc->cap_user_time_zero && !tc->cap_user_time_mono_raw) return -EOPNOTSUPP; return 0; @@ -102,8 +108,14 @@ int perf_event__synth_time_conv(const struct perf_event_mmap_page *pc, event.time_conv.time_zero = tc.time_zero; event.time_conv.time_cycles = tc.time_cycles; event.time_conv.time_mask = tc.time_mask; + event.time_conv.time_mono_last = tc.time_mono_last; + event.time_conv.time_mono_mult = tc.time_mono_mult; + event.time_conv.time_mono_shift = tc.time_mono_shift; + event.time_conv.time_mono_nsec = tc.time_mono_nsec; + event.time_conv.time_mono_base = tc.time_mono_base; event.time_conv.cap_user_time_zero = tc.cap_user_time_zero; event.time_conv.cap_user_time_short = tc.cap_user_time_short; + event.time_conv.cap_user_time_mono_raw = tc.cap_user_time_mono_raw; return process(tool, &event, NULL, machine); } @@ -138,5 +150,13 @@ size_t perf_event__fprintf_time_conv(union perf_event *event, FILE *fp) tc->cap_user_time_short); } + ret += fprintf(fp, "... Cap Time Monotonic Raw %" PRId32 "\n", + tc->cap_user_time_mono_raw); + ret += fprintf(fp, "... Time Last %" PRI_lu64 "\n", tc->time_mono_last); + ret += fprintf(fp, "... Time Multiplier %" PRId32 "\n", tc->time_mono_mult); + ret += fprintf(fp, "... Time Shift %" PRId32 "\n", tc->time_mono_shift); + ret += fprintf(fp, "... Time Nsec %" PRI_lu64 "\n", tc->time_mono_nsec); + ret += fprintf(fp, "... Time Base %" PRI_lu64 "\n", tc->time_mono_base); + return ret; } diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h index 88fd1c4c1cb8..6bacc450a14d 100644 --- a/tools/perf/util/tsc.h +++ b/tools/perf/util/tsc.h @@ -12,9 +12,15 @@ struct perf_tsc_conversion { u64 time_zero; u64 time_cycles; u64 time_mask; + u64 time_mono_last; + u32 time_mono_mult; + u32 time_mono_shift; + u64 time_mono_nsec; + u64 time_mono_base; bool cap_user_time_zero; bool cap_user_time_short; + bool cap_user_time_mono_raw; }; struct perf_event_mmap_page; From patchwork Mon Feb 13 19:07:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liang, Kan" X-Patchwork-Id: 56498 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2536447wrn; Mon, 13 Feb 2023 11:40:42 -0800 (PST) X-Google-Smtp-Source: AK7set9eDu78YXqh6q/aylnKV9zQG/j/NqxrJ0JMlfpqnV6jMraNtoyh4amIwOSsvkyVBg8Sw8ZJ X-Received: by 2002:a17:906:738e:b0:8b0:23a6:c491 with SMTP id f14-20020a170906738e00b008b023a6c491mr82141ejl.31.1676317242589; Mon, 13 Feb 2023 11:40:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676317242; cv=none; d=google.com; s=arc-20160816; b=drlT89U+Z9Q7c7lyc9f1E/4cbcqtWvktxkVKuFRnJuTa7QLec2jf8A9Cwn72ueRbze wsMnYuxm1gqMIxcw6J4U6WSVSj/re9/QSztv98/+rhAp8rERoehw3NbAmGAU/igtyiCy ZBQDLHsaxV5QSSJ1cEE9F5+oYvRJTYjN5PfhZs+U+jpBUq/YB9nq0eQmxE9xGW/9S2VZ PeEwHM/YefF4fJyVyvd+zpSUter+hMTTD2llvfcRR4HzPLZH4+exMtu+0vTW7Ng0m76z z1jO1Rm6Hri+Qiqu26oedXHtJ64xJIRt5cE1sACzoxgYDtzZLM7gX1ONrj13eTueBFOh 3HlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UDAbQQe335SB7l5sUPHQlO4m6Bo847ihLkXpIBy5EWk=; b=efbPDCB2KMRIiMalslTqKNZMWMd+uZ2/ZzfvHVNacisiBTZ1jCtB717jHc2n3Nj3i8 er9dw4ByT7VhK1VBGp5rsbPanxy+CRZ9RhlM86Hx9G5G/pRsv8mnoWjVWN6v8s5aAaFU 0e/Kyzg4GxBgjNZ2B1DFK6WV4qARbA3rcPE3dF/wS2w5gZSyPyGz+qLkmPXobkxnGHyd Y34bmQIA86/AZN63hcBOkQQRAqEDhYcPwpc/Q2dEbRcvKcWqZnv8BEF0bJBQkpNggxFU M7nJvlI7CofSDz9Me4SXVUXXNfxZm/Y0bTWcMz5x5UFYmau68brLJjsiYxDJckSHHzQv oggw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Gv/AwFIH"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e16-20020a056402105000b004aac89c74a9si14325581edu.630.2023.02.13.11.40.19; Mon, 13 Feb 2023 11:40:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Gv/AwFIH"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231137AbjBMTIa (ORCPT + 99 others); Mon, 13 Feb 2023 14:08:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230204AbjBMTIO (ORCPT ); Mon, 13 Feb 2023 14:08:14 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D571E1F4B1 for ; Mon, 13 Feb 2023 11:08:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676315289; x=1707851289; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k5xM53xjvbGCGQ5zJv4ziyGbnCGQidPVN7fJrmFsYRQ=; b=Gv/AwFIHrWB4+sz2xTHKInbBzV/TdVGB96JkIrA8a4vhStKe37ij6obV hM38cWxF9XloULEZ6Dtu7jzQ2kxbWL7O0dJgRTjQ4EPephIcdWK6xiLTI qSDxPEBjPKYBqvQO2Y3/lebIjEycGwlA0uJnEe7ACkNngDmjjcTGcWhof ggyhsb1SQj8yW8JP8XtHq4f6rnWQChVdn6YWd8DLHhAXiizR3u2vDz4/X YCxaY+En220UTC34iFnVsF9aWfkjd2mRFJ7wWC2Np6/9rcFCJ04PiBVOW DvcBsaZlCZAv7FX9e8/U5osZ7xuB4X0c1ZMKQX0HlxhiY8epj86XGhQBh Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="333108787" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="333108787" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 11:08:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="668901963" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="668901963" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2023 11:08:09 -0800 From: kan.liang@linux.intel.com To: tglx@linutronix.de, jstultz@google.com, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: sboyd@kernel.org, eranian@google.com, namhyung@kernel.org, ak@linux.intel.com, adrian.hunter@intel.com, Kan Liang Subject: [RFC PATCH V2 8/9] perf evsel, tsc: Support the monotonic raw clock conversion Date: Mon, 13 Feb 2023 11:07:53 -0800 Message-Id: <20230213190754.1836051-9-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230213190754.1836051-1-kan.liang@linux.intel.com> References: <20230213190754.1836051-1-kan.liang@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757746028984817262?= X-GMAIL-MSGID: =?utf-8?q?1757746028984817262?= From: Kan Liang The cap_user_time_mono_raw indicates that the kernel relies on the perf tool to convert the HW time to the monotonic raw clock. Add tsc_to_monotonic_raw() to do the conversion. The conversion information is stored in the session, which cannot be read in evsel parsing. Add a pointor in the evlist to point to the conversion information. Signed-off-by: Kan Liang --- tools/perf/util/evlist.h | 1 + tools/perf/util/evsel.c | 17 +++++++++++++++-- tools/perf/util/evsel.h | 7 +++++++ tools/perf/util/session.c | 1 + tools/perf/util/tsc.c | 12 ++++++++++++ tools/perf/util/tsc.h | 2 ++ 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 01fa9d592c5a..d860dc94009c 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -82,6 +82,7 @@ struct evlist { int pos; /* index at evlist core object to check signals */ } ctl_fd; struct event_enable_timer *eet; + struct perf_record_time_conv *time_conv; }; struct evsel_str_handler { diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 999dd1700502..5e27ac2b9f9b 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -50,6 +50,7 @@ #include "off_cpu.h" #include "../perf-sys.h" #include "util/parse-branch-options.h" +#include "tsc.h" #include #include #include @@ -2349,6 +2350,18 @@ u64 evsel__bitfield_swap_branch_flags(u64 value) return new_val; } +static u64 perf_evsel_parse_time(struct evsel *evsel, u64 time) +{ + /* + * The HW time can only be generated by HW events. + */ + if ((evsel->core.attr.clockid == CLOCK_MONOTONIC_RAW) && + evsel->evlist->time_conv && evsel__is_hw_event(evsel)) + return tsc_to_monotonic_raw(evsel->evlist->time_conv, time); + + return time; +} + int evsel__parse_sample(struct evsel *evsel, union perf_event *event, struct perf_sample *data) { @@ -2411,7 +2424,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, } if (type & PERF_SAMPLE_TIME) { - data->time = *array; + data->time = perf_evsel_parse_time(evsel, *array); array++; } @@ -2734,7 +2747,7 @@ int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event, array++; if (type & PERF_SAMPLE_TIME) - *timestamp = *array; + *timestamp = perf_evsel_parse_time(evsel, *array); return 0; } diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index d572be41b960..d1ef67852bda 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -269,6 +269,13 @@ static inline bool evsel__is_bpf(struct evsel *evsel) return evsel->bpf_counter_ops != NULL; } +static inline bool evsel__is_hw_event(struct evsel *evsel) +{ + return (evsel->core.attr.type == PERF_TYPE_HARDWARE) || + (evsel->core.attr.type == PERF_TYPE_HW_CACHE) || + (evsel->core.attr.type == PERF_TYPE_RAW); +} + #define EVSEL__MAX_ALIASES 8 extern const char *const evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX][EVSEL__MAX_ALIASES]; diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 189149a7012f..d80d0c4e46da 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1725,6 +1725,7 @@ static s64 perf_session__process_user_event(struct perf_session *session, return tool->stat_round(session, event); case PERF_RECORD_TIME_CONV: session->time_conv = event->time_conv; + session->evlist->time_conv = &session->time_conv; return tool->time_conv(session, event); case PERF_RECORD_HEADER_FEATURE: return tool->feature(session, event); diff --git a/tools/perf/util/tsc.c b/tools/perf/util/tsc.c index 0b59c0f815f9..5264f9d54be4 100644 --- a/tools/perf/util/tsc.c +++ b/tools/perf/util/tsc.c @@ -160,3 +160,15 @@ size_t perf_event__fprintf_time_conv(union perf_event *event, FILE *fp) return ret; } + +u64 tsc_to_monotonic_raw(struct perf_record_time_conv *tc, u64 cyc) +{ + u64 delta; + + if (!tc->cap_user_time_mono_raw) + return cyc; + + delta = (cyc - tc->time_mono_last) * tc->time_mono_mult + tc->time_mono_nsec; + delta >>= tc->time_mono_shift; + return tc->time_mono_base + delta; +} diff --git a/tools/perf/util/tsc.h b/tools/perf/util/tsc.h index 6bacc450a14d..2611d3de94b1 100644 --- a/tools/perf/util/tsc.h +++ b/tools/perf/util/tsc.h @@ -35,4 +35,6 @@ double arch_get_tsc_freq(void); size_t perf_event__fprintf_time_conv(union perf_event *event, FILE *fp); +u64 tsc_to_monotonic_raw(struct perf_record_time_conv *tc, u64 cyc); + #endif // __PERF_TSC_H From patchwork Mon Feb 13 19:07:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liang, Kan" X-Patchwork-Id: 56488 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2529744wrn; Mon, 13 Feb 2023 11:26:20 -0800 (PST) X-Google-Smtp-Source: AK7set9atUHQ1S13ltCh2EuHvp/t2wGqjxqrkw+ryeLPrNKrpUB8ko7c9x7x0iteJzQ/JfBNS6R/ X-Received: by 2002:a05:6a20:69a7:b0:c2:addd:b508 with SMTP id t39-20020a056a2069a700b000c2adddb508mr15466122pzk.2.1676316380095; Mon, 13 Feb 2023 11:26:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676316380; cv=none; d=google.com; s=arc-20160816; b=rK3uYqxUnhjrs/OFdKXAyGfJKNzc2JWMcIEa1JpIZsvk/g6kcjkNcPcm09xq735H4q Nx0+qk2+adC5XF0EJr2uIsDt7FUvGnxXhQlp068TObMLGggY9scnB3h/0q50gBDrkqFL KlGssfRmLeZb9D/Qqtpl4lyfhi1DtgsecXfoseCUg3DAzPyHmV/NoJFLg5zxEBD06r0L 2SErPaw4Zu+5agBvRqq0B63Z6aO8oLnIutkFQn3ZZagxSmL8TPxIJZLDSLGJ8zFn/T2y ztFTjKc2LbvlsNNWZhIIHCsQtXVbgcNfuvTIex1TL9Mtt0A3/Q5Je4U+HfOorqLsr7Bv C+9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HJE2cGRjVQSVwu9qF66SHemk8Zq4QziC/So3LYZ/SR8=; b=Qkc6jSKcPeT5BGSyDpSHYeBeGmDzY9ZtJLrq1POyqFpRhBTQ/1Udxl/nTIONmX5TvU lBHAF0V9E0fsQhFruUYP+RwDrec852B/7c3sz+41mK7HnN/OFN7Hs6gsIrScYl4ioEFS qsXF8qM9y7ibjXHuOyrU7sP/NH27jKBUouGma4MzRnDjjfS7qpSXas+RRsIIp9anyq0c nBXi/OYN2aVrevDyPf0KjdVbYYp+lB1XoUw0oCJQMk7xkMYVttLybfezwzeexROceIHC 0jR0pLYM6tU+a57gRmrnt1fgM7EEB0W1xz13UaT0lcV2lYD4oJ23G83c49S2gVNovIIr S40g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fA4BsrQs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 82-20020a630255000000b004b353c89e27si7250139pgc.429.2023.02.13.11.26.07; Mon, 13 Feb 2023 11:26:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fA4BsrQs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230426AbjBMTId (ORCPT + 99 others); Mon, 13 Feb 2023 14:08:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230061AbjBMTIP (ORCPT ); Mon, 13 Feb 2023 14:08:15 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C18C813DE7 for ; Mon, 13 Feb 2023 11:08:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676315290; x=1707851290; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9vCwYtZX3hPfCSqvh+1wJUJFKXzNXPAQY4vmXXsWFxE=; b=fA4BsrQsZKY3Fo5eKyqf1I5EgTKh84RKa8Hw7J4t2d/eko5Y5C0rQLm3 8wMnbrTYdMclBXp65YZ6E6BYkdyt4MC7TF+eC6qyupiaSFj2edpc65kFu 8xbDNg0pyEEl566abfdhZrdVXgKP2+EcOCtUW5qrne2Ep86R4ZMcn3Xb2 M6E5nkpYzTkMqy/Dy8+OV5511AlA+QxUAaiGMRxMw8zbsyI10YKPiA4dI 6e1j9wyZcg+Pz1Qb6c54rEF20OiiClDzMWJkxFBiVXH+THDF0hNugwQha 37dZdtfqXqppDGU+lGb0a88ey75jUK/WUMOb1LhaGAon1QGym3ngT2EkX g==; X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="333108803" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="333108803" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 11:08:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="668901968" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="668901968" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga002.jf.intel.com with ESMTP; 13 Feb 2023 11:08:10 -0800 From: kan.liang@linux.intel.com To: tglx@linutronix.de, jstultz@google.com, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: sboyd@kernel.org, eranian@google.com, namhyung@kernel.org, ak@linux.intel.com, adrian.hunter@intel.com, Kan Liang Subject: [RFC PATCH V2 9/9] perf evsel: Enable post-processing monotonic raw conversion by default Date: Mon, 13 Feb 2023 11:07:54 -0800 Message-Id: <20230213190754.1836051-10-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230213190754.1836051-1-kan.liang@linux.intel.com> References: <20230213190754.1836051-1-kan.liang@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757745124442995846?= X-GMAIL-MSGID: =?utf-8?q?1757745124442995846?= From: Kan Liang The HW time is more accurate than the time recorded in the NMI handler. Set the hw_time by default for the monotonic raw clock, and convert the HW time to the monotonic raw clock in perf tool. For the legacy kernel which doesn't support the attr, nothing is changed. The monotonic raw clock is still from the time recorded in the NMI handler. Print the hw_time in perf_event_attr__fprintf Signed-off-by: Kan Liang --- tools/perf/util/evsel.c | 11 ++++++++++- tools/perf/util/evsel.h | 1 + tools/perf/util/perf_event_attr_fprintf.c | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 5e27ac2b9f9b..d182c12fd291 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1349,6 +1349,8 @@ void evsel__config(struct evsel *evsel, struct record_opts *opts, if (opts->use_clockid) { attr->use_clockid = 1; attr->clockid = opts->clockid; + if (opts->clockid == CLOCK_MONOTONIC_RAW) + attr->hw_time = 1; } if (evsel->precise_max) @@ -1853,6 +1855,8 @@ static int __evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus, static void evsel__disable_missing_features(struct evsel *evsel) { + if (perf_missing_features.hw_time) + evsel->core.attr.hw_time = 0; if (perf_missing_features.read_lost) evsel->core.attr.read_format &= ~PERF_FORMAT_LOST; if (perf_missing_features.weight_struct) { @@ -1906,7 +1910,12 @@ bool evsel__detect_missing_features(struct evsel *evsel) * Must probe features in the order they were added to the * perf_event_attr interface. */ - if (!perf_missing_features.read_lost && + if (!perf_missing_features.hw_time && + evsel->core.attr.hw_time) { + perf_missing_features.hw_time = true; + pr_debug2("switching off hw_time support\n"); + return true; + } else if (!perf_missing_features.read_lost && (evsel->core.attr.read_format & PERF_FORMAT_LOST)) { perf_missing_features.read_lost = true; pr_debug2("switching off PERF_FORMAT_LOST support\n"); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index d1ef67852bda..c1d6fd40ea39 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -189,6 +189,7 @@ struct perf_missing_features { bool code_page_size; bool weight_struct; bool read_lost; + bool hw_time; }; extern struct perf_missing_features perf_missing_features; diff --git a/tools/perf/util/perf_event_attr_fprintf.c b/tools/perf/util/perf_event_attr_fprintf.c index 7e5e7b30510d..7b3669430b87 100644 --- a/tools/perf/util/perf_event_attr_fprintf.c +++ b/tools/perf/util/perf_event_attr_fprintf.c @@ -154,6 +154,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, PRINT_ATTRf(sample_max_stack, p_unsigned); PRINT_ATTRf(aux_sample_size, p_unsigned); PRINT_ATTRf(sig_data, p_unsigned); + PRINT_ATTRf(hw_time, p_unsigned); return ret; }