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=-2.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,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 EF9D4C433FE for ; Tue, 7 Sep 2021 20:50:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB31460EE6 for ; Tue, 7 Sep 2021 20:50:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346682AbhIGUv1 (ORCPT ); Tue, 7 Sep 2021 16:51:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbhIGUv0 (ORCPT ); Tue, 7 Sep 2021 16:51:26 -0400 Received: from mail-yb1-xb2d.google.com (mail-yb1-xb2d.google.com [IPv6:2607:f8b0:4864:20::b2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51D0CC061575; Tue, 7 Sep 2021 13:50:19 -0700 (PDT) Received: by mail-yb1-xb2d.google.com with SMTP id z18so1094664ybg.8; Tue, 07 Sep 2021 13:50:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=c67uG96v7m5oK6v4jgMgyYQ8vaVF+ha9XkRfekq/788=; b=pMAobo9YyVRUKw/e0lSeOrV7MzoP1qHoxGq8kRvC9THZX5iSxB3qteUbxw0PjY7KW+ laobPerUdQAc0Yl3Du7F9AggiSAbM9c0JmZmQ1xewS1u4dTZsWeQ/79dLQ7oHxufFCFI /J1ItRGJnN5/XY9zEhttI6t+nPQCILUYm5JzQVCHebKPRgZSVl95KfKJK6vxR2zAIC9B 61YK2JMJpDrH5/G05Xyps4NnRbfG9RRS3LZaCrABOQhNYtPXNOa9UYg6ucFiKcr5I1/q pIeKOVklz3UTov7xILClILhf37fsJiz4a5g6vgiiy5iNy/2RYDQEVyEYhjUlT/2yb5yW xgkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=c67uG96v7m5oK6v4jgMgyYQ8vaVF+ha9XkRfekq/788=; b=XxiRnMWQdUcFDZENBjjgkxOFFjJtnC3Y56Yo124ZDR3bKmuY1i+IFHsgz8IvkbiEVg HQmKXAHIxy9sjJyrtc+WWpQcEeoax+PKwU/dqU83KHquNYlNoo4npV+IKaxLiOCsHfYR dPXdrykhVfcMQtwoMSKPnSw93n01laAsdTpR7YVHzY+3Z79e2VfcsFRqmcLJZO6wynSF dF7gCfI19bJw7PQZg5NmOI4menuv1pbfi0SuX68z333Y87F9B9vpTnnBWkNl3q9oDn0M e9/7CICNqtH4Y4lcOJSGyP0o3GOAaG/KxdibKHNFQoiZQ5nyFlxeru4mYbsbMpIJiUFm aWWQ== X-Gm-Message-State: AOAM5312MOlUWUefriUWvPEzov+P2nwma9d+SgF0A6K439QLy69Yu22h YGRfN4i2FGMOveyDMCpBd63kLkBkDKdXkNTuJsU= X-Google-Smtp-Source: ABdhPJybg9oFilkeCBAgj727ohS1ttz6miPunDJMsWJhvp+uTbm1kaEwtFDY7Y2R8WzmRLxFk6D27omAtLDUAAz051c= X-Received: by 2002:a25:65c4:: with SMTP id z187mr423211ybb.113.1631047818433; Tue, 07 Sep 2021 13:50:18 -0700 (PDT) MIME-Version: 1.0 References: <20210902165706.2812867-1-songliubraving@fb.com> <20210902165706.2812867-2-songliubraving@fb.com> In-Reply-To: From: Andrii Nakryiko Date: Tue, 7 Sep 2021 13:50:07 -0700 Message-ID: Subject: Re: [PATCH v5 bpf-next 1/3] perf: enable branch record for software events To: Song Liu Cc: Peter Zijlstra , bpf , "linux-kernel@vger.kernel.org" , "acme@kernel.org" , "mingo@redhat.com" , "kjain@linux.ibm.com" , Kernel Team Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 7, 2021 at 12:02 PM Song Liu wrote: > > > > > On Sep 3, 2021, at 9:50 AM, Song Liu wrote: > > > > > > > >> On Sep 3, 2021, at 1:02 AM, Peter Zijlstra wrote: > >> > >> On Thu, Sep 02, 2021 at 09:57:04AM -0700, Song Liu wrote: > >>> +static int > >>> +intel_pmu_snapshot_branch_stack(struct perf_branch_entry *entries, unsigned int cnt) > >>> +{ > >>> + struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); > >>> + > >>> + intel_pmu_disable_all(); > >>> + intel_pmu_lbr_read(); > >>> + cnt = min_t(unsigned int, cnt, x86_pmu.lbr_nr); > >>> + > >>> + memcpy(entries, cpuc->lbr_entries, sizeof(struct perf_branch_entry) * cnt); > >>> + intel_pmu_enable_all(0); > >>> + return cnt; > >>> +} > >> > >> Would something like the below help get rid of that memcpy() ? > >> > >> (compile tested only) > > > > We can get rid of the memcpy. But we will need an extra "size" or "num_entries" > > parameter for intel_pmu_lbr_read. I can add this change in the next version. > > > > This is trickier than I thought. As current lbr_read() function works with > perf_branch_stack, while the BPF helper side uses array of perf_branch_entry. > And the array is passed into the helper by the BPF program. Therefore, to > really get rid of the memcpy, we need to refactor the lbr driver code more. > How about we keep the memcpy for now, and add the optimization later (if we > think it is necessary)? > Sounds good to me! > Thanks, > Song >