Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp149284lqe; Fri, 5 Apr 2024 16:18:37 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXL7fJ0PbKe8yP9l8EU7UB8/cML/58F1/dmKZrcFSII+KHdWjkyQOowOtqZOpIyR7/Fk9HAOMAQjgACsC1E8qFSnKpZmoWHKErPcKLEoQ== X-Google-Smtp-Source: AGHT+IGvjbhD64VvGOkP4thTcfEIovPd7N/0+qqx3P952k/4tM/9rUf95g/UAv+TlgXFGEpoPvzY X-Received: by 2002:a05:6a00:1489:b0:6ea:b74e:31e2 with SMTP id v9-20020a056a00148900b006eab74e31e2mr3186487pfu.31.1712359116773; Fri, 05 Apr 2024 16:18:36 -0700 (PDT) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 27-20020a63145b000000b005dcbbbdb1c0si2065679pgu.437.2024.04.05.16.18.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 16:18:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-133703-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=QZKTLgEQ; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-133703-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133703-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 42E3AB226E6 for ; Fri, 5 Apr 2024 23:17:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 68E413714C; Fri, 5 Apr 2024 23:16:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QZKTLgEQ" Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C8B42E852; Fri, 5 Apr 2024 23:16:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712359009; cv=none; b=siHn4uCk+aL5gAqWBsXWTIpZ4egZub6ZgBGAh/qQqVcBHK9y6evvaucSWKRXHK431hLr6yKOCfn8pqtYvVhFtVa9FfMABwkjS/wvhzih1U6lzKvPubQCl1+Ne18oIWh1IVjZtmlu/aC8Tc/0537xr9DAAWrOy5CdrAU6SM2mXkM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712359009; c=relaxed/simple; bh=6AF7nJyIzV4qfOtMYOfEHVCkE3ZqMbi869i25rD9LwY=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=GY+twvlCOFipAyK8P/Q1iPOaq59jaiV0GS55HWgm2a2MqPtEQ4qWDEAmyMOiEQI+Vvx1S4m9tVCetOWdIA50Wwv8SE20E4oj7sb8Z8qYlijQkizDa1oncvwCBiziX8RnU3cBvYWHSKn9Av8MKhBgmn6UIqPZ22KHe4eW2ryiWH4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QZKTLgEQ; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-29e0a1fd9a7so1842560a91.2; Fri, 05 Apr 2024 16:16:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712359007; x=1712963807; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DMjaG1Ua4xv+U+nuPv0Swd2atb/OKUERpZDEdaO/BV4=; b=QZKTLgEQARx2ISnecy8WxYp5dzHb4oMHfKo993n2QhAMCRptQ6b2sTQYiFaFsQzmmN isqJ3L62i0QK7PVOWHDlt08kh4Xl7AigineyHuHLBnfYG3IoS0yvMYrY25bLSH+WgWYB r2q4wp7Vg4l05gMc01CfavbqyW3JxJg2GejIZQmqwR7bozEOUBbQrCf6wHwFqAvXCTrm 8K98APOKlOQoD5zjSHT5NWxqRKJL53te8TG4jTcEjsGNcW1shhc781Rz+6UXj9XqPVK1 4DCNC79o2p+svm80jJfFZ8jduA5t90LPKhJZWeibJ9va8yhXpDhd/yXjrPSDw+0a5fU/ 8hYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712359007; x=1712963807; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DMjaG1Ua4xv+U+nuPv0Swd2atb/OKUERpZDEdaO/BV4=; b=Lbblq2b0SanOxjO/ypaeGOuMeRtcwEHtElvs1dZa2cxsZXSo+0V48k8DkuX0j0YX2W RTdP9Gt5E+R2lFvd/RKKifc19x0dY5cyEhPlrdRCMx1k33/kzanHCWqst+AFn5b2LnTU hZXrII2riCBS9kVkgU1YKFNa1KDIOVpUAL/7fnmTAXC6LBum+1nJ44z50fmluqx2GZ3j AUCUW2MJp29SQy9LCYXZLYPT+yn1I7jd1EKz6qknnAwDR31s4O7kojYW2NEKpkaXhrv7 pEugGR0/cv1H34mcle5hjZ5ScjcoogeG7/3H2Y8R8XvmK8NJcVgChW4wA4Gi5hqpjvXy skTg== X-Forwarded-Encrypted: i=1; AJvYcCW6OoVE1q5BIVsHvMYgB6upniZ2/Rjf6z69a0MUAoiknDsw8VJgH9DaRiuEfmAWpz9oh2kFRhJq6gpAnxQqx2URGKpH5cDG3G3yE8lGwhDSXxasDwMWN3cyyQ24LL3lxpOW X-Gm-Message-State: AOJu0Yxz+DXe/FWgOKWt+enwowx2PTGevN2Nrk48e2fW71kJvN5mOb23 02UTlFdK9IQkHFz/voxxUojU1MCExd9tns8O8jufs59ENRP8+OiFnfKU4ovz9qzQh1kqNDlO4eO YXej//N38MVjq4F8YwIrjLrikAd8= X-Received: by 2002:a17:90a:c918:b0:2a2:c20e:7baf with SMTP id v24-20020a17090ac91800b002a2c20e7bafmr2717578pjt.6.1712359007297; Fri, 05 Apr 2024 16:16:47 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240405223556.11142-1-andrea.righi@canonical.com> In-Reply-To: <20240405223556.11142-1-andrea.righi@canonical.com> From: Andrii Nakryiko Date: Fri, 5 Apr 2024 16:16:34 -0700 Message-ID: Subject: Re: [PATCH v3 0/2] libbpf: API to partially consume items from ringbuffer To: Andrea Righi Cc: Andrii Nakryiko , Eduard Zingerman , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , David Vernet , Tejun Heo , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Apr 5, 2024 at 3:36=E2=80=AFPM Andrea Righi wrote: > > Introduce ring__consume_n() and ring_buffer__consume_n() API to > partially consume items from one (or more) ringbuffer(s). > > This can be useful, for example, to consume just a single item or when > we need to copy multiple items to a limited user-space buffer from the > ringbuffer callback. > > Practical example (where this API can be used): > https://github.com/sched-ext/scx/blob/b7c06b9ed9f72cad83c31e39e9c4e2cfd86= 83a55/rust/scx_rustland_core/src/bpf.rs#L217 > > See also: > https://lore.kernel.org/lkml/20240310154726.734289-1-andrea.righi@canonic= al.com/T/#u > > [ Note: I haven't implemented the special case of n =3D=3D 0 as "no limit= ", > because we still need to add a bunch of extra checks for INT_MAX, making > the code less readable and, from a performance perspective, it seems > that we may get more downsides than benefits, but I can try to look more > at this if you think it's worth it ] > > v3: > - rename ring__consume_max() -> ring__consume_n() and > ring_buffer__consume_max() -> ring_buffer__consume_n() > - add new API to a new 1.5.0 cycle You also need to update Makefile, CI is failing right now ([0]). Please also add a simple test to BPF selftests using the new API. Other than that the changes look good. [0] https://github.com/kernel-patches/bpf/actions/runs/8576515495/job/235= 07610313#step:11:73 pw-bot: cr > - fixed minor nits / comments > > v2: > - introduce a new API instead of changing the callback's retcode > behavior > > Andrea Righi (2): > libbpf: ringbuf: allow to consume up to a certain amount of items > libbpf: Add ring__consume_n / ring_buffer__consume_n > > tools/lib/bpf/libbpf.h | 12 ++++++++++ > tools/lib/bpf/libbpf.map | 6 +++++ > tools/lib/bpf/ringbuf.c | 59 ++++++++++++++++++++++++++++++++++++++++--= ------ > 3 files changed, 67 insertions(+), 10 deletions(-)