From patchwork Tue Mar 10 05:51:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel T. Lee" X-Patchwork-Id: 222785 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=-3.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT 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 319F2C18E5A for ; Tue, 10 Mar 2020 05:52:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0847224677 for ; Tue, 10 Mar 2020 05:52:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fTnAIgcf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726258AbgCJFwH (ORCPT ); Tue, 10 Mar 2020 01:52:07 -0400 Received: from mail-pf1-f171.google.com ([209.85.210.171]:46060 "EHLO mail-pf1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726100AbgCJFwH (ORCPT ); Tue, 10 Mar 2020 01:52:07 -0400 Received: by mail-pf1-f171.google.com with SMTP id 2so5953674pfg.12; Mon, 09 Mar 2020 22:52:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HNOG8CrlKL3slTLrSPZnUR+cDqJrNnsigdC65Wb4CVI=; b=fTnAIgcfivbWfRMxXEnvd7CBNdG+Mof0LLG7vmI2Eq0y+28YurIiddeDncYiVlLGR7 t32NieyiSMoFF0aHVKqn5WA+ohpE/uLYfIH7AmwhEhaa3sJZmD13/5ORd5D0AJHsFC6s FyuuQGqEelf4+9ErkB9hAIWkuRRzJhUznPETxtvs4I87m9GcD01LBupv3qhi02+qzUz5 isia/orp1XX2bBvc4b0Q1dyi1bQvaEXf5P2CA4UZXGuYdThOg20Cwp0r8oXuDPsGYHll dGLeGK86Z+uFCmKIWCtZ+g3FWd4a706ZbYImd/qo0t29aPKqB92pcwlFetCrLPuKJ3wL tc7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HNOG8CrlKL3slTLrSPZnUR+cDqJrNnsigdC65Wb4CVI=; b=nl7klxL2bCN0FMCUh8UMTbTl+XkXA42wliu12CyFXjOXqbcxmAV9b4L6E+Uk3NxvqM lo+xIJLv6KTjbQuvZVVy2ddfH9ZpVAp2BXdx3JAIpxdn6y47SeAgc0fiThNHDfOZ30xU 3Sc64TEdhUGgC58+8YQhjiVXFma4jaCLfKEj1b+ZrPmgCMmwXcJAQa4x1tIRVeFkf8YN OaG0vjwPOI+jPP02RJm8hhVgiAyXBazK7TLkd5lw3EmfLKe7ePRpP2Y0GKda1TdgljFX tbcIfP+soO3iM0u0d/dKCKemzCj+fxJHc4yF1eUPAnBG9rhtco8WEgnnHNVkN+SIDIbO M2uA== X-Gm-Message-State: ANhLgQ3IHUcUfrgptVTinW64EoE6WKKmjUTYFioh1XuMdK8zdKjmwMie lTfQ+r+Gw8sgkKV/XtDeeg== X-Google-Smtp-Source: ADFU+vuQzYNfI7kU8bd+27wNqICyC2qunS2YQoMbGNcbOfrvxVFP2hQDQozzgBcvam6s0bpglLL3EA== X-Received: by 2002:a63:2447:: with SMTP id k68mr19205448pgk.368.1583819525828; Mon, 09 Mar 2020 22:52:05 -0700 (PDT) Received: from localhost.localdomain ([110.35.161.54]) by smtp.gmail.com with ESMTPSA id c17sm5018980pfn.187.2020.03.09.22.52.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2020 22:52:05 -0700 (PDT) From: "Daniel T. Lee" To: Daniel Borkmann , Alexei Starovoitov Cc: Andrii Nakryiko , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH bpf-next 0/2] samples: bpf: refactor perf_event user program with libbpf bpf_link Date: Tue, 10 Mar 2020 14:51:45 +0900 Message-Id: <20200310055147.26678-1-danieltimlee@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently, some samples are using ioctl for enabling perf_event and attaching BPF programs to this event. However, the bpf_program__attach of libbpf(using bpf_link) is much more intuitive than the previous method using ioctl. bpf_program__attach_perf_event manages the enable of perf_event and attach of BPF programs to it, so there's no neeed to do this directly with ioctl. In addition, bpf_link provides consistency in the use of API because it allows disable (detach, destroy) for multiple events to be treated as one bpf_link__destroy. To refactor samples with using this libbpf API, the bpf_load in the samples were removed and migrated to libbbpf. Because read_trace_pipe is used in bpf_load, multiple samples cannot be migrated to libbpf, this function was moved to trace_helpers. Daniel T. Lee (2): samples: bpf: move read_trace_pipe to trace_helpers samples: bpf: refactor perf_event user program with libbpf bpf_link samples/bpf/Makefile | 8 +-- samples/bpf/bpf_load.c | 20 ------- samples/bpf/bpf_load.h | 1 - samples/bpf/sampleip_user.c | 58 +++++++++++++-------- samples/bpf/trace_event_user.c | 57 +++++++++++++------- samples/bpf/tracex1_user.c | 1 + samples/bpf/tracex5_user.c | 1 + tools/testing/selftests/bpf/trace_helpers.c | 23 ++++++++ tools/testing/selftests/bpf/trace_helpers.h | 1 + 9 files changed, 106 insertions(+), 64 deletions(-)