Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1279830lqz; Mon, 1 Apr 2024 00:32:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXd3Cf5Lbqy7fLUa9S8ZUFIaiuDzCV7Ki3gcYGfapyx7FJ4Q8n4WuDI7Iogg1CL7u6k5pshoXkpjh9bCkHvTpFhn5jV4pLQzZNrfpDvHg== X-Google-Smtp-Source: AGHT+IHNED0ONzk6Drz3li5O/eysNkrh647J8r1pAYW1eMZeUVOE5NNPbczt+P7iaEivpgxV1CAB X-Received: by 2002:a05:6a20:7d8b:b0:1a3:a8da:918b with SMTP id v11-20020a056a207d8b00b001a3a8da918bmr7910589pzj.47.1711956747356; Mon, 01 Apr 2024 00:32:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711956747; cv=pass; d=google.com; s=arc-20160816; b=Hnf4cUdiq/l6q6sM9zhKAd77HOvC5IUXYnWMMvXxXM/Cu9ahGlbQqtJevpQKN9VSxD DTio0gqGioEWF9VhRz+5zmtlPVq9pAqamdQjQvKqkz65nZfHRMdhywDYsNzQrya3pmph +zS3OAHyxxP+ijBZlNOY6ID5DzHTZ+UeNbxe3tqMzRSNGUsCYKNC8NxZqa69hAhR/J9v 0oijsrYwvEcDvxPPi/mXahe8ueWIRATc1ZFzfA8iMKlkHd9GE9AElK4mfGt7IZSulf9L 5mYDGMoE4Vh6/Mg4Gno/w7jN6TQMy7uKYTaARS9Yc19/nXUYhhhPB+LHUJw+wCYHeFEK s7OQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=QCCLiPNOxpS2FShA4qPYs8euISrDLAWIFv7k+ZCMiCE=; fh=PRy9yfde9hUfzK6Bq0pR6qcNmmjZclOtx+AWA+i9sUE=; b=PqE2Hl+Ancf1UQ6iPiKnHLznGqM7WApFUkScBdjpxltYUz+ozM0QGZQbRgOuYvNxy8 Wwh6Jou/CTfoqSMXh7KsNiDY3E+99YaDeWbwzOGgUy4GlzKUrvpETcJM3h1X8rHbDknB T3Ula/TYoG/YhedOPKn84UQpBTP8/9QiCg8KpQciDF4a0T4AI396qdNbPKe1rh9a+22p vLfIRgkV7xBrsqUTBGHL2BTL5oeYfuoH73wcGcwV3nhKPV2B4EYkgiIZpcbkWfQVaw9b TLxSI+uqFn6irCVyO0OJNWA6TAxCxvXvwVJ98Z05Fn72OULoB5gTDwq3+sApRSRrQRzM 7Ahg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=hXhTFi3Q; arc=pass (i=1 spf=pass spfdomain=canonical.com dkim=pass dkdomain=canonical.com dmarc=pass fromdomain=canonical.com); spf=pass (google.com: domain of linux-kernel+bounces-126495-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-126495-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x10-20020a170902ec8a00b001dd62fbcf75si9076033plg.536.2024.04.01.00.32.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 00:32:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-126495-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=hXhTFi3Q; arc=pass (i=1 spf=pass spfdomain=canonical.com dkim=pass dkdomain=canonical.com dmarc=pass fromdomain=canonical.com); spf=pass (google.com: domain of linux-kernel+bounces-126495-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-126495-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0BDD9281AA5 for ; Mon, 1 Apr 2024 07:32:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E52B6B676; Mon, 1 Apr 2024 07:32:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b="hXhTFi3Q" Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0B8653BE for ; Mon, 1 Apr 2024 07:32:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711956741; cv=none; b=mOzwlcNXtFST1Ojatjd9NkLMtulKCQ9YNip20vDHjGDQvqm02+mHzn6XxJa2QNpi3123/sXZb744AXBLlTyctkekhASTymb8bWJdv9XvKeRlU1Jmaf2Loj+nu/3Da2w+6DtHFbz2VO95sPPP9UM4przQwe2RGWWKZbMv2Vy+ec8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711956741; c=relaxed/simple; bh=oIq/k7QSNY4VXE5qTIzdmpP02YxKDabeCib0tznAHpk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=c1hLLeDXHPg4UL6EjB8eNmjbgD77/Y5aCwrAGELxxc0sdcs5vYlfcUODuoMGnCApyCv3m9UjG2vpDKBw/8lp8RWQYWfJUcx+SKet6VyHYtbeapM34m3UAJLmcRiZZxFbblasbqw/lVl/hskW5L1vLXKQiBPDEiTBQa5wAdcxmp4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (2048-bit key) header.d=canonical.com header.i=@canonical.com header.b=hXhTFi3Q; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 075BB411BD for ; Mon, 1 Apr 2024 07:32:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1711956729; bh=QCCLiPNOxpS2FShA4qPYs8euISrDLAWIFv7k+ZCMiCE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hXhTFi3QEJzAAq4+Q42iXVRbDjuUr/mcoJdGfca7tu7AvTYuvFNQ5yRsATV8VyZU2 27DYTuGPWVOMDrj9nyNWjbdQqlguzUafAm/Corz/FsgY/MvSgdjesT7s2xz764VJgq Dx/FMWpGCzxnlMVQq2IGfSLzo84d2OUwBW7xdLNmA3BoPhjy/ZdytNReWW3jAomc/5 zDhfUTlyiY802lfGypKVopHcREW94BnQueD1Ne7YT6HpXnESwNQ3t3A62m9t6nLyjE 6n+T0bPWJckvb5nS3gO5KVPIx7R1PpjLSp4bxxISS8SizkFiuf+WNywjWPjXhLA3rA VxPf+nwgmA+hQ== Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-568728e521bso3893211a12.0 for ; Mon, 01 Apr 2024 00:32:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711956728; x=1712561528; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QCCLiPNOxpS2FShA4qPYs8euISrDLAWIFv7k+ZCMiCE=; b=KABXNcOGKHJLhVBFTVJUwB/MWvOgd8PvezhApEXxsnBbKp0GhT1ENvtZ+Gvn99Adoi iyNph4UqK/WdA2N9IhsZjjbzXmhzjl3Q8ITJtfXnbIoUP8WoN81P9OxmV/Z/MpK9H9Qv e8z6Qs9EPx5Ev/vOQ7EPhFJZa0Uhs+0tYrTneCGxxoY4+oXQYL4uc+Uj955r033fCh7y cRDPjgRPk8RU9wasBgW9WO2Q8P2si4o8GUzJnOLYcWpMS7hDNY9WfzXuT0MM3dNbBdBK NurJn/2AoqUbwGAFRYMvzalXnnAN0XQ782fvcxeF8wv0kOqpkVZWm/D6UAsAR9b1Qrcz /cfA== X-Forwarded-Encrypted: i=1; AJvYcCXSXdSN2M7FE2vgjBtb94HiViff7qrNA3bd6HwKH0rdQuv1MSKxDJFoJU0FfgD2pmjeseQOFUUSXiSCtrAfNJwY2+RoSZnNRL/YAE9C X-Gm-Message-State: AOJu0Yw0jVAZlqVaYyCDt6FT/M0LKieC0zo1X+/HBXSsZHZt2qpSd0Tj O8xtBDb63leErO/JrTIUEqrTY3y11UxUOyhE9kVv574RaxwFgN/OJhSHekxO9QnKysS13wPf6B4 vUE7iYRhOVCxkml7xCftpkl7hwq20jYp70ak9nPQZle2Ocn1+n6fb9AGw8Bba2TM3VslLcgRs6O rvvw== X-Received: by 2002:a50:a697:0:b0:56b:d212:b032 with SMTP id e23-20020a50a697000000b0056bd212b032mr5327016edc.14.1711956728197; Mon, 01 Apr 2024 00:32:08 -0700 (PDT) X-Received: by 2002:a50:a697:0:b0:56b:d212:b032 with SMTP id e23-20020a50a697000000b0056bd212b032mr5326998edc.14.1711956727672; Mon, 01 Apr 2024 00:32:07 -0700 (PDT) Received: from localhost.localdomain (host-95-248-169-71.retail.telecomitalia.it. [95.248.169.71]) by smtp.gmail.com with ESMTPSA id b23-20020aa7df97000000b0056b2c5c58d2sm5096511edy.21.2024.04.01.00.32.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 00:32:07 -0700 (PDT) From: Andrea Righi To: Andrii Nakryiko , Eduard Zingerman Cc: 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 Subject: [PATCH v2 0/2] libbpf: API to partially consume items from ringbuffer Date: Mon, 1 Apr 2024 09:19:00 +0200 Message-ID: <20240401073159.16668-1-andrea.righi@canonical.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Introduce ring__consume_max() and ring_buffer__consume_max() 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/b7c06b9ed9f72cad83c31e39e9c4e2cfd8683a55/rust/scx_rustland_core/src/bpf.rs#L217 See also: https://lore.kernel.org/lkml/20240310154726.734289-1-andrea.righi@canonical.com/T/#u 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_max / ring_buffer__consume_max tools/lib/bpf/libbpf.h | 13 +++++++++++++ tools/lib/bpf/libbpf.map | 2 ++ tools/lib/bpf/ringbuf.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++-------------