Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2392803ioo; Sat, 28 May 2022 12:12:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoTVRwF94pueheV/wyI7n1zlWDsfw7ROKMt6DfeOANxQ1ZL0V4aLeSkB0KRUX7FDXHI5NW X-Received: by 2002:a63:90c9:0:b0:3f9:dd57:7cf3 with SMTP id a192-20020a6390c9000000b003f9dd577cf3mr32377014pge.382.1653765163982; Sat, 28 May 2022 12:12:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653765163; cv=none; d=google.com; s=arc-20160816; b=jGv9OHYgwM+Fn5hZmZUfzVwkBa1WrFoAVlxpwTM0GqtFIZdk8r2+KzNL50lasTQ7n/ 6rtGaJeJMztageRdLvq8bkU/nM6fOwEXtjDibh1QOO4PeIiGIq88vhgiCJ9b0pxZ04gb 8EykUmWrfbRzUqbYrpynEhGa+54i/nMKXtWunpLDk8DzJD9FzL8TIFHQ4Lpn4huslyNU 9ZUDQScX9uOLAx0yfrL/xGl7dVDL02H2W2q4sz05YbUIQ5Wj7ajxsCcQv5dCHiIPaSox Qqt5+MMRG4+ONet8RYW3KxMO/wAyWb8lqPPP5Lm1u2YIuoA0DxNenZ+gU2aekCUdqIBa p46w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=+nhRSW0HB0IrL3AsaUbgyELmuQlg7AADB3tpFmkYZW4=; b=FliN/2SGBZQcrKuglcqDYgMH6RbzLcpJ00PsQf9u7tSasMaYxW6ipd2VgVOHW02liw N0jHNmipVzxfwuijfKydn3UJ73SXio9r0yBUHHc4QOplY1zKX6+AUtybPqwCn52/71Gf qN/FDObWvf/8hqbXnScgnwHvVa8O3o0co2YU0zFdRwpVZ7ommDK6deJfyCK5Vu7dqnGf chByv4AUWqhzxVbHSXxS8iKtB9cVXjO+xIgetl8kZQVgxTzSvXsYSNC22jP2Qr14JE4f YErMjOEM+6wCakLXE8idzRu8fVIyjXJ4wGaoFRhBxyM+p/zvhLvc4mAGLHjGUCwpdjvU JjrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ODsEChw4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q5-20020a170902f78500b001586fb0260asi9788170pln.218.2022.05.28.12.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 12:12:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ODsEChw4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0396042EEA; Sat, 28 May 2022 11:48:53 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354098AbiE0QAY (ORCPT + 99 others); Fri, 27 May 2022 12:00:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349598AbiE0P6A (ORCPT ); Fri, 27 May 2022 11:58:00 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEB5A2870A for ; Fri, 27 May 2022 08:57:58 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id p5-20020a1c2905000000b003970dd5404dso2985292wmp.0 for ; Fri, 27 May 2022 08:57:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+nhRSW0HB0IrL3AsaUbgyELmuQlg7AADB3tpFmkYZW4=; b=ODsEChw49WJ2jXA7phOq9UZH0sa+uGOmARNU0dKT8ELNxeavTeP0ERYA525+wh7RW7 9p0HVYaFdK9NPOtwfoYX/3YxuBlVrTS/PvOIFREHdr6i3F0FZXNsx0jO1emEFXlOq8jk UzaGW0oM2FSWqXu3ovPYxFW396ckgz81nYoroROMlRcdxD5HFF4bvmOf1FwwjwwS9E5M 9OWKi+EmtrlVAGJDI4ujDWdfiaOGYNygBvMJh+7eICZSsg2874r1YcHaLvmgsnell5CV XhDsg+s/QhI5QzdQAgcnyrDgPgAhweQ+452ZY+E8TlGN2qWg3aPW1kMEF3SuGryy6ig8 Mrkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+nhRSW0HB0IrL3AsaUbgyELmuQlg7AADB3tpFmkYZW4=; b=m3BS89FUvVxzbTR+o4QS6u0fj18piQq8deYKMbpHu1NukMimRvFgfZIIxX/3vGwv9G bo6JB3jwic7V0jU7PU+iVczoHjluibHhYdAklJczAjja4VrPQF5W8ogBRLSxuC+xLyXe f4+E0iTIz5N0eIYFrWBSgSnXRnpYL4XFR7xOoeRw/MoaGLFL+ZBibasPzXoR2er4Jz8w +/BLs7OFRhTXw/3WsXDitVi9M9GXhTkTGk1nzW/OT9vehgXjBuIr4/dKjmWXDRQjbfbo eg7SKUJnu/Hm71keAOyf2Orue77yuVgnH+tNmycXPBlw3wHYZ4QqVvx12LpJKwFjOQOC dn1A== X-Gm-Message-State: AOAM531HiOALWJ9KvMTUghJqhyQH4uCZyxXC7eAmSn1Nib0WyxH9Ei4q RUtM7lXgxsiEmnurv7twyaIkfxJjFkiIOwqvOdyJOQ== X-Received: by 2002:a05:600c:2305:b0:397:44a4:d3cb with SMTP id 5-20020a05600c230500b0039744a4d3cbmr7538356wmo.115.1653667077089; Fri, 27 May 2022 08:57:57 -0700 (PDT) MIME-Version: 1.0 References: <20220527040407.4193232-1-irogers@google.com> <76dce5d3-6c69-e403-c4d9-f882967a4467@linux.intel.com> In-Reply-To: <76dce5d3-6c69-e403-c4d9-f882967a4467@linux.intel.com> From: Ian Rogers Date: Fri, 27 May 2022 08:57:43 -0700 Message-ID: Subject: Re: [PATCH v2] perf metrics: Add literal for system TSC frequency To: Andi Kleen Cc: Peter Zijlstra , perry.taylor@intel.com, caleb.biggers@intel.com, kshipra.bopardikar@intel.com, Kan Liang , Zhengjun Xing , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Maxime Coquelin , Alexandre Torgue , James Clark , John Garry , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Stephane Eranian , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 On Fri, May 27, 2022 at 7:54 AM Andi Kleen wrote: > > > On 5/27/2022 2:49 AM, Peter Zijlstra wrote: > > On Thu, May 26, 2022 at 09:04:07PM -0700, Ian Rogers wrote: > >> Such a literal is useful to calculate things like the average frequency > >> [1]. The TSC frequency isn't exposed by sysfs although some experimental > >> drivers look to add it [2]. This change computes the value using the > >> frequency in /proc/cpuinfo which is accurate at least on Intel > >> processors. > > It would be better to use CPUID if available which is far more accurate. > Also I believe newer Intel CPUs drop the frequency in the brand string. But on v1 you also said it was broken for certain architectures. The point of the tests and warnings is to identify this case. > BTW it also has the problem that if perf script is run on some other > system to compute metrics it won't work. Yep. We don't yet support recording then reporting metrics on a different system. There would be a bunch to do to support this. > > > > This all seems bonghits inspired... and perf actually does expose the > > tsc frequency. What do you think is in perf_event_mmap_page::time_* ? > > > That's not really available to perf stat, which is the primary metrics user. So we have 3 approaches: 1) read /proc/cpuinfo: pros: easy in comparison to other approaches. cons: will break in the future, will need a cross system strategy 2) use cpuid: pros: can be made to work across systems cons: not available for all Intel architectures 3) mmap: pros: more stable API than cpuinfo vendor string. cons: could end up with new events purely to gather a TSC frequency and associated complexity around permissions, etc. I feel we can bike shed and go between the 3 approaches almost endlessly. I'd rather get something in and iterate. How the approach breaks can motivate the next steps and the tests added here will capture when it does break, not just when a metric is first used. I mentioned this on V1 and requested feedback, this is just implementing what I said I'd do to V1. Thanks, Ian > -Andi > > >