From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by sourceware.org (Postfix) with ESMTPS id 41558385703C for ; Tue, 25 Jul 2023 13:30:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 41558385703C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690291835; x=1721827835; h=from:to:subject:date:message-id:references:in-reply-to: mime-version:content-transfer-encoding; bh=8QAV90pNyzGnwXAXKxtXQcC30SAyMNAPHKT9WnOjhyk=; b=gu6XQSMymHvuooXmz1Ww7OaeHSzP0C6v5hDxvrr/MG+Ei0dJk9JeLVRY 3H6g5Cn6E+0s12sbBF3nYlPYCDCnQF9nEAzD9jf65Tyr14AAZQkseobc8 snG0pRy2oK2VM7cQRV+Lg0DD1ROtyTUOzqLVRAvQX53M70U9U4nM6ORbp ETW6QjVQ4UhlSdTNgXe1QjuqBR2UDjiwPVEpJTAY2WAk+0/OhHhFNQZtE dSBtU4J5WUqikyHRXtI4tVDs00jxiOs9zEOG8H0/y78gFrimuPnn9olZI 6Hb//GCADtt3NdIwRl9+kI3yvxm5Ebzc+lxs+yjpQllE3YcqEvL9QiKsU Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="352619963" X-IronPort-AV: E=Sophos;i="6.01,230,1684825200"; d="scan'208";a="352619963" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 06:30:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="755758665" X-IronPort-AV: E=Sophos;i="6.01,230,1684825200"; d="scan'208";a="755758665" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by orsmga008.jf.intel.com with ESMTP; 25 Jul 2023 06:30:07 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 25 Jul 2023 06:30:06 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 25 Jul 2023 06:30:06 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Tue, 25 Jul 2023 06:30:06 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.103) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.27; Tue, 25 Jul 2023 06:30:05 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m/XPnS0cxHCQ8icaYOkQdbT0PnHUtlhjOIUsn7+uQdx+KZkWAYbhkyaHZYMR3oCgvMCE2YFlbdPYkAseoMY5wxW854IQGD6OHslrj4F8pLRz5BZnthZjWF9+qYc9Tlb1d+lUu6iBFgYMsgTafq6UX6HeYOYY44L3m9DatIMp5jPwX7Tg5031lbOGRbx7ln/3wU1VJatJSaF62fc4fzqPC57u8r8WbGtjFQDNzNKi95kyo19x9zlnIHAXl99DxQGuc3mCaaIB+W/zaIPjLZGNEobPXsFlFiIHSI/PgTgpLS5IR3NsGavrtTbJjcY1OSqILLJZZAko0oZ//t5dLD6M6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0ku13RLkEJgevvUqBzVbI3+kK2jdxksj0i3olPwEmyY=; b=kE+EKRKmhNZEkGnLzGMP5R9sQaGoMofwD2UiXck/TP65TXY35WKsuORplLUZOHjh8fk3pSGoT8572HDg3NSHPDs7pkH3Y0yGx8+mJOqwt5FxzuVlR+AZ133Rs5vXT8tW53trAv+dLjB/c/d9VZlxc3y0XoROxw3X6dpe6qMxRccG31uW9SA9j+rcT/vyGwub4zv+kV+zYerxpe7BKltWnZyROpKDmcgRuccKyTf0teMoQKzO3PbUigzpoXVbBwCr+BjoqnbzSLn+zijHNWhjXN+LQBpGQbBSqORc9Rvcz3ocNc8FMSfn9q48gl5F1+opTo6Y8j17tXPCvptap4PIvQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from DM8PR11MB5749.namprd11.prod.outlook.com (2603:10b6:8:10::15) by MN2PR11MB4517.namprd11.prod.outlook.com (2603:10b6:208:24e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Tue, 25 Jul 2023 13:30:03 +0000 Received: from DM8PR11MB5749.namprd11.prod.outlook.com ([fe80::dcf7:d957:e9dc:2c64]) by DM8PR11MB5749.namprd11.prod.outlook.com ([fe80::dcf7:d957:e9dc:2c64%5]) with mapi id 15.20.6609.032; Tue, 25 Jul 2023 13:30:03 +0000 From: "Metzger, Markus T" To: "Willgerodt, Felix" , "gdb-patches@sourceware.org" , "simark@simark.ca" Subject: RE: [PATCH v10 08/10] btrace, linux: Enable ptwrite packets. Thread-Topic: [PATCH v10 08/10] btrace, linux: Enable ptwrite packets. Thread-Index: AQHZuW8DsqYZzh8nFkGDdV0pFhD7yq/KVj8Q Date: Tue, 25 Jul 2023 13:30:03 +0000 Message-ID: References: <20230718115637.3531-1-felix.willgerodt@intel.com> <20230718115637.3531-9-felix.willgerodt@intel.com> In-Reply-To: <20230718115637.3531-9-felix.willgerodt@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM8PR11MB5749:EE_|MN2PR11MB4517:EE_ x-ms-office365-filtering-correlation-id: 45330e6c-2bff-4c61-f835-08db8d134106 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 3tVEwcjpZp+3lbKN1/9DKzQ3lCwqMAzem0Jc96qZUVy2UudI/WqHvdeGLP6qDti95aWF0AqH+u6BxAO3AXEESVVnxReycJ9LbX/Qrdg+YhkE2cHSs1qZA/+Drp7Y9OLmO4Mb6Caj+xSrYTLjj6vxYK53gMZKL71WaJe8bL1mE/hkjnUEmWX4dhRX9AmQeRCJRUtK0YHdyqbKSpNW248ZEj27Cm+AvZGdeoE/pxPGgvTsAX950/mxoKoVazamaKHut8UrJRpR/RsFCpZlRFTTPBnhPFfiHJfTLGO7AOkUIuy1qpQMsS19Alj/eys2vGgLnhBlAOw6LNqCaKhniSOosatrq0K4l7xsBvqHyq4yAcAqc/go6nbTzgZWhyTom/4kuRTXR/t8j/Jnq2O8Og23k0xe+Muty7JJGqGdAvMj9bq3cVlDh+Lq7suG5taEa8G7Aty23M/7y8gmzypVfZXBquboxjkamwyQ9VxV5Dq4A56fICKLzqyEFDhdUGer9abcR5KXfQKJ5ihB2toeUyIw0BIkqxCi/UAiT7mgTS5Z2eOn5+1zWPMqc4NP+8q9adFFP+3toJwv0eW0N7tWOTrd9Q3/M1LDMUx2XrY2yd0rKbxo/DSnBzgoAdI3erWAMsKW x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM8PR11MB5749.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(346002)(136003)(366004)(376002)(396003)(451199021)(8676002)(8936002)(52536014)(5660300002)(41300700001)(316002)(2906002)(66946007)(66446008)(64756008)(76116006)(66476007)(66556008)(9686003)(7696005)(26005)(71200400001)(478600001)(186003)(110136005)(6506007)(82960400001)(86362001)(55016003)(83380400001)(38100700002)(38070700005)(33656002)(122000001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?V02mVZD3A1G+MqI3w3Cv1BB9DrEsR9h26tsMaVnJ2MpQkLjrAuwZ7l8akcXY?= =?us-ascii?Q?/FnSuvcYgSOUi6sxukXoRK0ROe+fhot1/2noDTc/Q58ww0phJp/XGBohNGpp?= =?us-ascii?Q?AP0swm1yIER5to8xeKng8awBBFvmyF608MhaNKsAopcHvgkbYAA2WdZ39L/w?= =?us-ascii?Q?HFxtafC8AAgHOT+mNRu4uupqHpyoGXypniYm5BgXX2NRMPDVwtouK+pkHYjV?= =?us-ascii?Q?yUaY6X6XAR4GbKium+RPQdgiJOiMPJ/mEU6Lz48OCYDEt0uQBLJ0/csUYW4p?= =?us-ascii?Q?TNxHx//ema4wrtPoU49Q0y+CPnBGTlOOC3dtNzegvlNyN4FYlUP+IsfrLpiu?= =?us-ascii?Q?PbLEB3oFV83apdy5fhnC3tH2Z9z6DFhWbhXKr3mxvLs/YWD2IRjZ59zGNeK2?= =?us-ascii?Q?OW92nh7NdxYzyX25O2GQDOscMu98sDyCogMh8537JnfFSksR8szhOEkNO68P?= =?us-ascii?Q?IfVex5bjOjMzVKHlbyF7Tyly9NF4DIWebXNx/NXtABMuppu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fu1BK9rVFE9ePPap5Wd7x9HSGmQH/T7zv7ShGETTzVN?= =?us-ascii?Q?9m5B/20Zl8PkoXDqmX8aNPsiQ4geGc3mhCy0CwtVbH0YPJWghHfhtuhhgveC?= =?us-ascii?Q?WAAlaocXPN4Q/C8NgkoJ82gcg7VtenR5P/vvJOjg9zJ+Q8AcnMlXx2HS2wJB?= =?us-ascii?Q?F3IkeKwnuAMsBw3P598wl+HzRRRn1FPs2Lef22Xpyp7BNpMLIG4D4s7pPhwf?= =?us-ascii?Q?LA=3D=3D?= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM8PR11MB5749.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45330e6c-2bff-4c61-f835-08db8d134106 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Jul 2023 13:30:03.7317 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: MZjst9u56xRlfvm1mQrS5KNyey6QIIOmr3WSnzth7NJ971mX3N6JsC/pVAvHB6D4gnEno8AJilwNkocUha40yUXR0AGovq7052+tZOoLCuc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB4517 X-OriginatorOrg: intel.com Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hello Felix, >+/* Read config bits. */ >+ >+static bool >+linux_read_pt_config_bit (const std::string &feature, uint64_t *config_bi= t) This isn't really necessary since the bit resembles the enable bit in the c= ontrol MSR. It also doesn't hurt so I'm OK with the change. >+{ >+ std::string filename >+ =3D "/sys/bus/event_source/devices/intel_pt/format/" + feature; >+ gdb_file_up file =3D gdb_fopen_cloexec (filename.c_str (), "r"); >+ >+ if (file.get () =3D=3D nullptr || config_bit =3D=3D nullptr) >+ return false; We could check CONFIG_BIT before opening the file. >+ >+ int found =3D fscanf (file.get (), "config:%lu", config_bit); The format string doesn't match the type. We should use SCNu64. >+ if (found !=3D 1) >+ { >+ warning (_("Failed to determine config bit from %s."), >+ filename.c_str ()); The issue is that the file didn't contain the expected content. This will probably need some changes in GDB to fix. Could we print the actual content and what we expected? >+/* Check whether the linux target supports Intel Processor Trace PTWRITE.= */ >+ >+static bool >+linux_supports_ptwrite (uint64_t *config_bit) >+{ >+ static const char filename[] >+ =3D "/sys/bus/event_source/devices/intel_pt/caps/ptwrite"; >+ gdb_file_up file =3D gdb_fopen_cloexec (filename, "r"); >+ >+ if (file.get () =3D=3D nullptr) >+ return false; >+ >+ int status, found =3D fscanf (file.get (), "%d", &status); >+ >+ if (found !=3D 1) >+ { >+ warning (_("Failed to determine ptwrite support from %s."), filenam= e); >+ return false; >+ } >+ >+ if (!linux_read_pt_config_bit ("ptw", config_bit)) We should check STATUS before. If caps indicates that ptwrite isn't available, I'm not sure format will contain the bit position for enabling it. >+ uint64_t config_bit; >+ if (conf->ptwrite && linux_supports_ptwrite (&config_bit)) >+ { >+ pt->attr.config |=3D 1 << config_bit; >+ tinfo->conf.pt.ptwrite =3D conf->ptwrite; >+ } >+ > errno =3D 0; > scoped_fd fd (syscall (SYS_perf_event_open, &pt->attr, pid, -1, -1, 0)); > if (fd.get () < 0) >diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c >index c93b3d7c8de..ad3160d42c5 100644 >--- a/gdb/record-btrace.c >+++ b/gdb/record-btrace.c >@@ -3295,4 +3295,9 @@ to see the actual buffer size."), NULL, >show_record_pt_buffer_size_value, > > record_btrace_conf.bts.size =3D 64 * 1024; > record_btrace_conf.pt.size =3D 16 * 1024; >+#if (LIBIPT_VERSION >=3D 0x200) >+ record_btrace_conf.pt.ptwrite =3D true; >+#else >+ record_btrace_conf.pt.ptwrite =3D false; >+#endif Is there a way to get an error when attempting to install a custom ptwrite filter when either GDB (via libipt) or the kernel does not support PTWRITE? Regards, Markus. Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva = Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928