Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2220477pxb; Wed, 30 Mar 2022 19:45:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMTTc4n224vo+1BJVLf4t/dtXMqdDDWPpklq5QNP9pHWWGT6iVjaE+AX4GIwKGuqnpnrAC X-Received: by 2002:a17:90a:380d:b0:1c9:d9bb:7602 with SMTP id w13-20020a17090a380d00b001c9d9bb7602mr3355475pjb.216.1648694739141; Wed, 30 Mar 2022 19:45:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648694739; cv=none; d=google.com; s=arc-20160816; b=uiy919vAJUyNuVa+KTyOvUvS11D/m4fLAsKbWR7Ko+M12qXKK/LZd3b02NZ+hudTaJ 3liDQ5PEJOc6srqQ1fNvp3nX2kCRGCKAlq2dPkLFPhBHDaTz2Rrl5+i3i2dsGqtTlofD Eb1CZWRMjcP24yTqoTiNKeNjA9zHWNLv+ko1f9S4nSfpADThbFHyq8HcesbYM8UdoFfB a1reyePw6HE9l9PBQRgJsYtW9vanEvsiFX1nkUEkOcGKeamSzB83ae1RgJWNL6zE3R9V KDcZbmkCK798yBTEc0YXm8NzG7AZKYbEE+uDckYbYO6IC7QxGOOXN02Ec0WfIsCtWVFr Gf2A== 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=WdbIOqIAUHlIwd2WJUxUanSkPEK5+dBLSu0Daw2T0jM=; b=pnj+2w1mKdxZWY+LkpMcbTo1T9PuptQAh1bCMbr8I6YGQBHnpmzizllse8p1Fhhxrs +YhIiLw8CrU/VV/CTpjnmwDr+CwyA+phWU5RS7SS6iewiBJgQzGcf/GLdYnNdlgIo9b0 IPa5iIpW4FI9Lkl6javcXNEKHdKozqBvSiONVeQybwAPrwvxMUnoPSKQrzR0q85RnBv4 ETkOJbiN9yaeHjC8hubdin9V+/W28epCP+IMKoQvtfnImIX8WamTt9B/xb099WZ08GLS Jlm9HS2rRvEGnzrW4JxpnkQQgLfwQ49PMyAnB3nRue+EBhTO2nZ6muSv1VND66cTTf78 yPUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ROFmG6dW; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x1-20020a17090ad68100b001c65a7f49d0si1689902pju.92.2022.03.30.19.45.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 19:45:39 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ROFmG6dW; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 191BEB0D0D; Wed, 30 Mar 2022 19:35:38 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351442AbiC3V7x (ORCPT + 99 others); Wed, 30 Mar 2022 17:59:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240323AbiC3V7t (ORCPT ); Wed, 30 Mar 2022 17:59:49 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4270545060; Wed, 30 Mar 2022 14:58:03 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id c2so18504065pga.10; Wed, 30 Mar 2022 14:58:03 -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=WdbIOqIAUHlIwd2WJUxUanSkPEK5+dBLSu0Daw2T0jM=; b=ROFmG6dW48xX6bAjWgGPsksoQIU2Cz56khySELC3RT1VgBp5m0Z69jGtO7GiMSISha 4xJC1VFjrbx+tHN0A75nLmVWI4PXmjJIjX71tQmgxd8omBzRQswNpoTqGDzd1/yFNYpJ RrdtAQatyCMB1Z1jA++t0D2c1ctm8SLP1I9kdFD11VdOKAIzrqWX1FIQfui1w3ZbT8zd x4GbqDPgfOvq7Wpi0Y+4eGHUh1Y43b9azeV0hWSskxAnsdYQ3bVS774vSE0tiQzTQ3Ou xJgrdldU+P83xZw5FwPPSE68Fu2T6ya/WSh0VhKMO4kj6SYwHAzLgaPIWvxhVfCbcEx/ ZkvQ== 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=WdbIOqIAUHlIwd2WJUxUanSkPEK5+dBLSu0Daw2T0jM=; b=knkTXNrO8nyJbSIeFA+zOdI5Yf0ycJpxqvabe+zDy7hn53FOc5lupfrdH7lp0ykdn8 5IVq4J6Zv55A65CR3+5Og/uXnuM4vBD2ond75BRPA9Expw6JFVH+E9qU8olMHQvxjHOE WW2F63AFjoG+Vj8EbOVEtf/CvKx7ETuRnIW0tmhBSeAotY34+gUqAVFDFHq66GNOAu/6 HyNgtxRfqnLKTzcSYttUi0QIRnD6WbOBF9NeLRo3sFWcvFBhllh0ia+ASXd2LXiWV3Ro 0P5atLY7Lv8QAqn4UTbhs3mgOmLcU/twS5zkeEiSVxEx7xa0+vrUdq3O/1RinoemFiao qiWg== X-Gm-Message-State: AOAM530zjbDcyXsKRhisHvoTHDDND6tI9b+Uk6/Tp7u+AYf24Z+k1UXe VKOSmsi9bIJZtEorkIV8UijtGbATzDXo//Uwgh5LbFGm X-Received: by 2002:a63:6809:0:b0:37c:68d3:1224 with SMTP id d9-20020a636809000000b0037c68d31224mr7730055pgc.287.1648677482682; Wed, 30 Mar 2022 14:58:02 -0700 (PDT) MIME-Version: 1.0 References: <20220329181935.2183-1-beaub@linux.microsoft.com> <20220329201057.GA2549@kbox> <20220329231137.GA3357@kbox> <20220330163411.GA1812@kbox> <20220330191551.GA2377@kbox> <20220330212708.GA2759@kbox> In-Reply-To: <20220330212708.GA2759@kbox> From: Alexei Starovoitov Date: Wed, 30 Mar 2022 14:57:51 -0700 Message-ID: Subject: Re: [PATCH] tracing/user_events: Add eBPF interface for user_event created events To: Beau Belgrave Cc: Song Liu , Steven Rostedt , Masami Hiramatsu , linux-trace-devel , LKML , bpf , Network Development , linux-arch , Mathieu Desnoyers Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 Wed, Mar 30, 2022 at 2:27 PM Beau Belgrave wrote: > > On Wed, Mar 30, 2022 at 01:39:49PM -0700, Alexei Starovoitov wrote: > > On Wed, Mar 30, 2022 at 12:15 PM Beau Belgrave > > wrote: > > > > > > On Wed, Mar 30, 2022 at 11:22:32AM -0700, Alexei Starovoitov wrote: > > > > On Wed, Mar 30, 2022 at 9:34 AM Beau Belgrave wrote: > > > > > > > > > > > > > > But you are fine with uprobe costs? uprobes appear to be much more costly > > > > > > > than a syscall approach on the hardware I've run on. > > > > > > > > Care to share the numbers? > > > > uprobe over USDT is a single trap. > > > > Not much slower compared to syscall with kpti. > > > > > > > > > > Sure, these are the numbers we have from a production device. > > > > > > They are captured via perf via PERF_COUNT_HW_CPU_CYCLES. > > > It's running a 20K loop emitting 4 bytes of data out. > > > Each 4 byte event time is recorded via perf. > > > At the end we have the total time and the max seen. > > > > > > null numbers represent a 20K loop with just perf start/stop ioctl costs. > > > > > > null: min=2863, avg=2953, max=30815 > > > uprobe: min=10994, avg=11376, max=146682 > > > > I suspect it's a 3 trap case of uprobe. > > USDT is a nop. It's a 1 trap case. > > > > > uevent: min=7043, avg=7320, max=95396 > > > lttng: min=6270, avg=6508, max=41951 > > > > > > These costs include the data getting into a buffer, so they represent > > > what we would see in production vs the trap cost alone. For uprobe this > > > means we created a uprobe and attached it via tracefs to get the above > > > numbers. > > > > > > There also seems to be some thinking around this as well from Song Liu. > > > Link: https://lore.kernel.org/lkml/20200801084721.1812607-1-songliubraving@fb.com/ > > > > > > From the link: > > > 1. User programs are faster. The new selftest added in 5/5, shows that a > > > simple uprobe program takes 1400 nanoseconds, while user program only > > > takes 300 nanoseconds. > > > > > > Take a look at Song's code. It's 2 trap case. > > The USDT is a half of that. ~700ns. > > Compared to 300ns of syscall that difference > > could be acceptable. > > > > > > > > > > > > > > > > > Can we achieve the same/similar performance with sys_bpf(BPF_PROG_RUN)? > > > > > > > > > > > > > > > > I think so, the tough part is how do you let the user-space know which > > > > > program is attached to run? In the current code this is done by the BPF > > > > > program attaching to the event via perf and we run the one there if > > > > > any when data is emitted out via write calls. > > > > > > > > > > I would want to make sure that operators can decide where the user-space > > > > > data goes (perf/ftrace/eBPF) after the code has been written. With the > > > > > current code this is done via the tracepoint callbacks that perf/ftrace > > > > > hook up when operators enable recording via perf, tracefs, libbpf, etc. > > > > > > > > > > We have managed code (C#/Java) where we cannot utilize stubs or traps > > > > > easily due to code movement. So we are limited in how we can approach > > > > > this problem. Having the interface be mmap/write has enabled this > > > > > for us, since it's easy to interact with in most languages and gives us > > > > > lifetime management of the trace objects between user-space and the > > > > > kernel. > > > > > > > > Then you should probably invest into making USDT work inside > > > > java applications instead of reinventing the wheel. > > > > > > > > As an alternative you can do a dummy write or any other syscall > > > > and attach bpf on the kernel side. > > > > No kernel changes are necessary. > > > > > > We only want syscall/tracing overheads for the specific events that are > > > hooked. I don't see how we could hook up a dummy write that is unique > > > per-event without having a way to know when the event is being traced. > > > > You're adding writev-s to user apps. Keep that writev without > > any user_events on the kernel side and pass -1 as FD. > > Hook bpf prog to sys_writev and filter by pid. > > I see. That would have all events incur a syscall cost regardless if a > BPF program is attached or not. We are typically monitoring all processes > so we would not want that overhead on each writev invocation. > > We would also have to decode each writev payload to determine if it's > the event we are interested in. The mmap part of user_events solves that > part for us, the byte/bits get set to non-zero when the writev cost is > worth it. Please don't reinvent the wheel. This problem is already solved by USDT semaphores.