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=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 EADE4C433E9 for ; Fri, 12 Mar 2021 14:35:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C721764FDC for ; Fri, 12 Mar 2021 14:35:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230386AbhCLOfP (ORCPT ); Fri, 12 Mar 2021 09:35:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:34756 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229959AbhCLOey (ORCPT ); Fri, 12 Mar 2021 09:34:54 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C3EF664F23 for ; Fri, 12 Mar 2021 14:34:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615559694; bh=L+vIlV/agm+Y36Vfdw7/F5SkJZPDHB3Vs6EXYx4Bj2k=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=jZ1X2NRhsDUW1GlhHciFxm6eAqpOL45+qNK9KcUxiae0eqdasrc43PlcZ4KhNjggh 45ZXI8tNC2an3Q35h9th6SeTdZMAc2oINIraEZwHWUosyuto8eMPoknkwUv5NcNqpd pkiOdNGyLOd2b9HWC6X+tvV3MiF4TZAjSvFFP8POHg+47osOxALpcKNIj8sLwhn859 ScnzukpPKaEnD/ssu4K7SmZCYqHeiNChBVzk9G040aHA/RMsVJ4e5YRxI5BizLdqfL z2l9zMTovHl/Bj0D99N9YmsEhEtHdr9mBhhCR6Hu9PdodOuud25EHDVx412bFs7V/P +8kr68uSrF+1w== Received: by mail-ej1-f46.google.com with SMTP id k16so232102ejx.1 for ; Fri, 12 Mar 2021 06:34:53 -0800 (PST) X-Gm-Message-State: AOAM531BqphWOzborXSewPzrLRyt4BWeDTI3hehPCQBvzufvW6nMdmp7 kdjTt1u69SBFe24M+65bGf80uxAsco0OOLCHiw== X-Google-Smtp-Source: ABdhPJydJdts2afhRCK8ep/AJsnZcQOl4g9AawP6BZ9hsjbVGEH1Y5VtSm8XHshzur+pzfZ8W+Saf5Ne3S8gRAYKol4= X-Received: by 2002:a17:906:1d44:: with SMTP id o4mr8252548ejh.130.1615559692308; Fri, 12 Mar 2021 06:34:52 -0800 (PST) MIME-Version: 1.0 References: <20210311000837.3630499-1-robh@kernel.org> <20210311000837.3630499-5-robh@kernel.org> In-Reply-To: From: Rob Herring Date: Fri, 12 Mar 2021 07:34:39 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v6 04/10] libperf: Add evsel mmap support To: Jiri Olsa Cc: Will Deacon , Catalin Marinas , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Ian Rogers , Alexander Shishkin , Honnappa Nagarahalli , Zachary.Leaf@arm.com, Raphael Gault , Jonathan Cameron , Namhyung Kim , Itaru Kitayama , linux-arm-kernel , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 12, 2021 at 6:59 AM Jiri Olsa wrote: > > On Wed, Mar 10, 2021 at 05:08:31PM -0700, Rob Herring wrote: > > SNIP > > > + > > static int > > sys_perf_event_open(struct perf_event_attr *attr, > > pid_t pid, int cpu, int group_fd, > > @@ -137,6 +147,8 @@ void perf_evsel__free_fd(struct perf_evsel *evsel) > > { > > xyarray__delete(evsel->fd); > > evsel->fd = NULL; > > + xyarray__delete(evsel->mmap); > > + evsel->mmap = NULL; > > } > > > > void perf_evsel__close(struct perf_evsel *evsel) > > @@ -156,6 +168,45 @@ void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu) > > perf_evsel__close_fd_cpu(evsel, cpu); > > } > > > > +int perf_evsel__mmap(struct perf_evsel *evsel, int pages) > > +{ > > + int ret, cpu, thread; > > + struct perf_mmap_param mp = { > > + .prot = PROT_READ | PROT_WRITE, > > + .mask = (pages * page_size) - 1, > > + }; > > I don't mind using evsel->fd for dimensions below, > but we need to check in here that it's defined, > that perf_evsel__open was called Right, so I'll add this here: if (evsel->fd == NULL) return -EINVAL; Note that struct evsel has dimensions in it, but they are only set in the evlist code. I couldn't tell if that was by design or mistake. BTW, I just noticed perf_evsel__open is leaking memory on most of its error paths. > > jirka > > > + > > + if (evsel->mmap == NULL && > > + perf_evsel__alloc_mmap(evsel, xyarray__max_x(evsel->fd), xyarray__max_y(evsel->fd)) < 0) > > + return -ENOMEM; > > + > > + for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++) { > > + for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) { > > + int fd = FD(evsel, cpu, thread); > > + struct perf_mmap *map = MMAP(evsel, cpu, thread); > > + > > + if (fd < 0) > > + continue; > > + > > + perf_mmap__init(map, NULL, false, NULL); > > + > > + ret = perf_mmap__mmap(map, &mp, fd, cpu); > > + if (ret) > > + return -1; > > + } > > + } > > + > > + return 0; > > +} > > + > > SNIP > 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=-9.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 802D6C433DB for ; Fri, 12 Mar 2021 14:36:23 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 E13A964F23 for ; Fri, 12 Mar 2021 14:36:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E13A964F23 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=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc: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=1njwBhZ9Jx1qyPrXVqim5xuOJkyNjIqAQ7NOY/OHvDM=; b=MuxwPQDdnK9F1hEh5KyiAY+gY nZcLO3wQ/j5jwZS+vjNi0Yrxe37Nx3GV19pM98m1lP0/JmfiT6xFPpcG6RHRu58IKcjfB+JVyBnXu WbUG7wqc/dSNI0tTC8vfyTrgtdwIc4+Uh79siTzb1nQJYppCFEBC4ZXZ4pXymiuuoeKl2lMa7no74 NXEGJbvS+F6skoXozq4AaCbD3/Jkl5c32hXstK3COqqHdeeaSoWl5FNfoIJ1FCgupQe8xg8s+oZyi 349YLhoTO8qNIcSXGFmwoVM0ab1KtjoLF5TzCZFTt3zohB8+y2kiisn5XTwrqXbIzZilc9AldIqrm sQ6xy+2Ew==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lKisW-00BfF9-6X; Fri, 12 Mar 2021 14:35:00 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lKisR-00BfEQ-FF for linux-arm-kernel@lists.infradead.org; Fri, 12 Mar 2021 14:34:57 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id B69C564FDC for ; Fri, 12 Mar 2021 14:34:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615559694; bh=L+vIlV/agm+Y36Vfdw7/F5SkJZPDHB3Vs6EXYx4Bj2k=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=jZ1X2NRhsDUW1GlhHciFxm6eAqpOL45+qNK9KcUxiae0eqdasrc43PlcZ4KhNjggh 45ZXI8tNC2an3Q35h9th6SeTdZMAc2oINIraEZwHWUosyuto8eMPoknkwUv5NcNqpd pkiOdNGyLOd2b9HWC6X+tvV3MiF4TZAjSvFFP8POHg+47osOxALpcKNIj8sLwhn859 ScnzukpPKaEnD/ssu4K7SmZCYqHeiNChBVzk9G040aHA/RMsVJ4e5YRxI5BizLdqfL z2l9zMTovHl/Bj0D99N9YmsEhEtHdr9mBhhCR6Hu9PdodOuud25EHDVx412bFs7V/P +8kr68uSrF+1w== Received: by mail-ej1-f52.google.com with SMTP id bm21so53753822ejb.4 for ; Fri, 12 Mar 2021 06:34:53 -0800 (PST) X-Gm-Message-State: AOAM531bXTAcabBXDai+NeDrJcf4GQmoBnmfH1QxweMqToCTlK3IsOib cxOwcvgrulR9u+y/Dn2ZQ/k7kput/2sPC8A3iw== X-Google-Smtp-Source: ABdhPJydJdts2afhRCK8ep/AJsnZcQOl4g9AawP6BZ9hsjbVGEH1Y5VtSm8XHshzur+pzfZ8W+Saf5Ne3S8gRAYKol4= X-Received: by 2002:a17:906:1d44:: with SMTP id o4mr8252548ejh.130.1615559692308; Fri, 12 Mar 2021 06:34:52 -0800 (PST) MIME-Version: 1.0 References: <20210311000837.3630499-1-robh@kernel.org> <20210311000837.3630499-5-robh@kernel.org> In-Reply-To: From: Rob Herring Date: Fri, 12 Mar 2021 07:34:39 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v6 04/10] libperf: Add evsel mmap support To: Jiri Olsa Cc: Will Deacon , Catalin Marinas , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Ian Rogers , Alexander Shishkin , Honnappa Nagarahalli , Zachary.Leaf@arm.com, Raphael Gault , Jonathan Cameron , Namhyung Kim , Itaru Kitayama , linux-arm-kernel , "linux-kernel@vger.kernel.org" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210312_143455_904403_43113545 X-CRM114-Status: GOOD ( 19.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 Fri, Mar 12, 2021 at 6:59 AM Jiri Olsa wrote: > > On Wed, Mar 10, 2021 at 05:08:31PM -0700, Rob Herring wrote: > > SNIP > > > + > > static int > > sys_perf_event_open(struct perf_event_attr *attr, > > pid_t pid, int cpu, int group_fd, > > @@ -137,6 +147,8 @@ void perf_evsel__free_fd(struct perf_evsel *evsel) > > { > > xyarray__delete(evsel->fd); > > evsel->fd = NULL; > > + xyarray__delete(evsel->mmap); > > + evsel->mmap = NULL; > > } > > > > void perf_evsel__close(struct perf_evsel *evsel) > > @@ -156,6 +168,45 @@ void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu) > > perf_evsel__close_fd_cpu(evsel, cpu); > > } > > > > +int perf_evsel__mmap(struct perf_evsel *evsel, int pages) > > +{ > > + int ret, cpu, thread; > > + struct perf_mmap_param mp = { > > + .prot = PROT_READ | PROT_WRITE, > > + .mask = (pages * page_size) - 1, > > + }; > > I don't mind using evsel->fd for dimensions below, > but we need to check in here that it's defined, > that perf_evsel__open was called Right, so I'll add this here: if (evsel->fd == NULL) return -EINVAL; Note that struct evsel has dimensions in it, but they are only set in the evlist code. I couldn't tell if that was by design or mistake. BTW, I just noticed perf_evsel__open is leaking memory on most of its error paths. > > jirka > > > + > > + if (evsel->mmap == NULL && > > + perf_evsel__alloc_mmap(evsel, xyarray__max_x(evsel->fd), xyarray__max_y(evsel->fd)) < 0) > > + return -ENOMEM; > > + > > + for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++) { > > + for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) { > > + int fd = FD(evsel, cpu, thread); > > + struct perf_mmap *map = MMAP(evsel, cpu, thread); > > + > > + if (fd < 0) > > + continue; > > + > > + perf_mmap__init(map, NULL, false, NULL); > > + > > + ret = perf_mmap__mmap(map, &mp, fd, cpu); > > + if (ret) > > + return -1; > > + } > > + } > > + > > + return 0; > > +} > > + > > SNIP > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel