From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C978C433E7 for ; Fri, 16 Oct 2020 21:39:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D89DA218AC for ; Fri, 16 Oct 2020 21:39:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602884369; bh=MXBdSxOof0HQgxlxhMM7NHOelApiLzd1XB6m/omkx3o=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=Zh1dQg3JRb9iIB2KjYMSTf/R3/IJSWFLW6tolBVQfAjXc4s9Fz4IEZd/B1cGoefGF Mli1dlrgeMdgdj1G556+nI+HXxGFXYWK8GHuCXL+4HaNsHY1me0tSXhzjg4DGiU9mK uRq4jcd1RbElJzLKaXj3q7EBH8Up1d2B0Vp5gZh4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727080AbgJPVj2 (ORCPT ); Fri, 16 Oct 2020 17:39:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:52922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726074AbgJPVj2 (ORCPT ); Fri, 16 Oct 2020 17:39:28 -0400 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BFA7E22200 for ; Fri, 16 Oct 2020 21:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602884367; bh=MXBdSxOof0HQgxlxhMM7NHOelApiLzd1XB6m/omkx3o=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Sg5U6uSIUn26qEyi+A1WsrKqK4cTDdVI13HGIIwUNKS/+7rC/twf7EULp823G3yGA ddMHL/2X8d812wJye+cxh9+7Sgn8j7eZGF8IBvoPWmth8qtSozm7iC3/eRxGcpkSAZ k/ahLTd/tYg8uvIqoDrEh/hw7s9ACCrf4HA82DTU= Received: by mail-ot1-f46.google.com with SMTP id t15so3910011otk.0 for ; Fri, 16 Oct 2020 14:39:27 -0700 (PDT) X-Gm-Message-State: AOAM533hTbuJXuzAueajEpvEX50wQmZMMf7VbFe8VoMT7lrbNjNzE/yf ttdWJaOqeD9GyAaP8AnwsZKJGB3iHWInAZfvtg== X-Google-Smtp-Source: ABdhPJw+/zfaiQhjnKkx4JHL224P8sFLZNr0dl0+zpvRXoOwaHad7Wi3At2ecz3YFqjGo/JCv+IeSWuMrQ8anaO33KI= X-Received: by 2002:a9d:1c90:: with SMTP id l16mr4240754ota.192.1602884366849; Fri, 16 Oct 2020 14:39:26 -0700 (PDT) MIME-Version: 1.0 References: <20201001140116.651970-1-robh@kernel.org> <20201001140116.651970-5-robh@kernel.org> <20201014110527.GA1349644@krava> In-Reply-To: <20201014110527.GA1349644@krava> From: Rob Herring Date: Fri, 16 Oct 2020 16:39:15 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 4/9] libperf: Add libperf_evsel__mmap() To: Jiri Olsa Cc: Will Deacon , Catalin Marinas , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , linux-arm-kernel , "linux-kernel@vger.kernel.org" , Alexander Shishkin , Namhyung Kim , Raphael Gault , Mark Rutland , Jonathan Cameron , Ian Rogers , Honnappa Nagarahalli , Itaru Kitayama Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 14, 2020 at 6:05 AM Jiri Olsa wrote: > > On Thu, Oct 01, 2020 at 09:01:11AM -0500, Rob Herring wrote: > > SNIP > > > > > +void *perf_evsel__mmap(struct perf_evsel *evsel, int pages) > > +{ > > + int ret; > > + struct perf_mmap *map; > > + struct perf_mmap_param mp = { > > + .prot = PROT_READ | PROT_WRITE, > > + }; > > + > > + if (FD(evsel, 0, 0) < 0) > > + return NULL; > > + > > + mp.mask = (pages * page_size) - 1; > > + > > + map = zalloc(sizeof(*map)); > > + if (!map) > > + return NULL; > > + > > + perf_mmap__init(map, NULL, false, NULL); > > + > > + ret = perf_mmap__mmap(map, &mp, FD(evsel, 0, 0), 0); > > hum, so you map event for FD(0,0) but later in perf_evsel__read > you allow to read any cpu/thread combination ending up reading > data from FD(0,0) map: > > int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread, > struct perf_counts_values *count) > { > size_t size = perf_evsel__read_size(evsel); > > memset(count, 0, sizeof(*count)); > > if (FD(evsel, cpu, thread) < 0) > return -EINVAL; > > if (evsel->mmap && !perf_mmap__read_self(evsel->mmap, count)) > return 0; > > > I think we should either check cpu == 0, thread == 0, or make it > general and store perf_evsel::mmap in xyarray as we do for fds The mmapped read will actually fail and then we fallback here. My main concern though is adding more overhead on a feature that's meant to be low overhead (granted, it's not much). Maybe we could add checks on the mmap that we've opened the event with pid == 0 and cpu == -1 (so only 1 FD)? Rob From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FB15C433E7 for ; Fri, 16 Oct 2020 21:41:05 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C9C48214DB for ; Fri, 16 Oct 2020 21:41:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZdpZVh6Q"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="Sg5U6uSI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C9C48214DB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=XWLO3/xgcu7PJLqmOMm+aUY8wIzHuYYZmDnhKfTMJ6w=; b=ZdpZVh6Qb3UwDVj5McVUzhiT1 HRl5ontAleFQwi4WvE3gVdqDG6HE7CQIOnJF9lGAglA0O8videdAH6IUq6ekuBh/Nit+IxZst0ENj ZZqUM3k6PexC7GeG8KyGulejBvxh/mP3NJQH7LdlbuI9M8h4/ml+dEO3ah2jSgti+/L5br7sp1ldf aTE7nRUulIO1VgSyrBN5guylsiUIx2izNG0UDFE22ZveHro6sey39z/ChmCG0zwah0IXltW6EEatM afzCwgJwO4s651sGQwYwb1MjcIa8FFUofxK4EdZcZjUX1SBnMjzURL8QQK1+r6/3pgURWuU0YYEq5 9azeRDTug==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kTXRk-0001fx-3N; Fri, 16 Oct 2020 21:39:32 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kTXRh-0001ez-2h for linux-arm-kernel@lists.infradead.org; Fri, 16 Oct 2020 21:39:30 +0000 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A59A8214DB for ; Fri, 16 Oct 2020 21:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602884367; bh=MXBdSxOof0HQgxlxhMM7NHOelApiLzd1XB6m/omkx3o=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Sg5U6uSIUn26qEyi+A1WsrKqK4cTDdVI13HGIIwUNKS/+7rC/twf7EULp823G3yGA ddMHL/2X8d812wJye+cxh9+7Sgn8j7eZGF8IBvoPWmth8qtSozm7iC3/eRxGcpkSAZ k/ahLTd/tYg8uvIqoDrEh/hw7s9ACCrf4HA82DTU= Received: by mail-ot1-f53.google.com with SMTP id 32so3908445otm.3 for ; Fri, 16 Oct 2020 14:39:27 -0700 (PDT) X-Gm-Message-State: AOAM532XdU+nGvGQGYPu+Vha19wXnHcLhHq+aW121AtRgqb9pp8PbfD5 oEMABhHE6guPR9teL/8lKZ5V+nKPKWaWdkwC8g== X-Google-Smtp-Source: ABdhPJw+/zfaiQhjnKkx4JHL224P8sFLZNr0dl0+zpvRXoOwaHad7Wi3At2ecz3YFqjGo/JCv+IeSWuMrQ8anaO33KI= X-Received: by 2002:a9d:1c90:: with SMTP id l16mr4240754ota.192.1602884366849; Fri, 16 Oct 2020 14:39:26 -0700 (PDT) MIME-Version: 1.0 References: <20201001140116.651970-1-robh@kernel.org> <20201001140116.651970-5-robh@kernel.org> <20201014110527.GA1349644@krava> In-Reply-To: <20201014110527.GA1349644@krava> From: Rob Herring Date: Fri, 16 Oct 2020 16:39:15 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 4/9] libperf: Add libperf_evsel__mmap() To: Jiri Olsa X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201016_173929_704542_45CDE874 X-CRM114-Status: GOOD ( 19.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ian Rogers , Peter Zijlstra , Catalin Marinas , "linux-kernel@vger.kernel.org" , Arnaldo Carvalho de Melo , Alexander Shishkin , Raphael Gault , Ingo Molnar , Honnappa Nagarahalli , Jonathan Cameron , Namhyung Kim , Itaru Kitayama , Will Deacon , linux-arm-kernel Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Oct 14, 2020 at 6:05 AM Jiri Olsa wrote: > > On Thu, Oct 01, 2020 at 09:01:11AM -0500, Rob Herring wrote: > > SNIP > > > > > +void *perf_evsel__mmap(struct perf_evsel *evsel, int pages) > > +{ > > + int ret; > > + struct perf_mmap *map; > > + struct perf_mmap_param mp = { > > + .prot = PROT_READ | PROT_WRITE, > > + }; > > + > > + if (FD(evsel, 0, 0) < 0) > > + return NULL; > > + > > + mp.mask = (pages * page_size) - 1; > > + > > + map = zalloc(sizeof(*map)); > > + if (!map) > > + return NULL; > > + > > + perf_mmap__init(map, NULL, false, NULL); > > + > > + ret = perf_mmap__mmap(map, &mp, FD(evsel, 0, 0), 0); > > hum, so you map event for FD(0,0) but later in perf_evsel__read > you allow to read any cpu/thread combination ending up reading > data from FD(0,0) map: > > int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread, > struct perf_counts_values *count) > { > size_t size = perf_evsel__read_size(evsel); > > memset(count, 0, sizeof(*count)); > > if (FD(evsel, cpu, thread) < 0) > return -EINVAL; > > if (evsel->mmap && !perf_mmap__read_self(evsel->mmap, count)) > return 0; > > > I think we should either check cpu == 0, thread == 0, or make it > general and store perf_evsel::mmap in xyarray as we do for fds The mmapped read will actually fail and then we fallback here. My main concern though is adding more overhead on a feature that's meant to be low overhead (granted, it's not much). Maybe we could add checks on the mmap that we've opened the event with pid == 0 and cpu == -1 (so only 1 FD)? Rob _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel