Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3326012pxu; Tue, 15 Dec 2020 04:29:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxipSicUo+fGah1DNnF8OJIuOlRfghns5FkArYnACS2oO+y16VGPScuh1v6Y2Ijzxts1SQZ X-Received: by 2002:aa7:c98d:: with SMTP id c13mr30529990edt.188.1608035346306; Tue, 15 Dec 2020 04:29:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608035346; cv=none; d=google.com; s=arc-20160816; b=w5sPq8yUkubSN6HBC3cMweIziYaYr6blYEyoUIAGXgXG7beRS5TxJiVwYYu6zQYQuN IHN5h7T8dEW4Z4d5DzcbNe9d7eTn1/LVtE6Xnf/tioK/mdB7zAEJEA6fyf+uJI2BtecO sS3EB3RhK7d61T9/98npmcIdpD3Z3lnLP442gHmpIi3tNix2GtAq1Qv5fWx5Lx7f7fs1 GIQ4DT59hhXfyxDLUJGmNYA4ndeU9frEXrYhhGDsKirfmtsNvIZPjKiYNkDwO4pbMdDd jnG1iHZ6XBRHqSG121mHirPhMCUTvme77oBPo3+xyD1qqtljj9TtX6VqoIebXKcXW+dZ Th1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=uG9hUyn2l1hT7e+Msb6nBQLe6pVUc/Tidhzusbc3Z5E=; b=nj6R0aPfy+aCsqlJoo6UL17srUL2fdYux2pFVrECfouNd5AbVhrxWVjbdObz4ANnno C+MBnKfDqImvm6HvjRwSVo0jU2O8d2wmgt7KX+R9Hj5ivdzwr6rZe/q79Sxiy0AQY0NZ kdCNxoK1XCXvAQcfBLD5wXej2As2LRQqK+cea+LGsJJgfMWOMy+CzbB4Vkq43V1gLWOL lM/H/hubt/ixUd2cELFDTodLzBR/9bF2gdltDI3Y+iHoXM5JymTtpJU1tUNdWHTC1Uo+ vKe36Mura8Y5tmRC6yMSES34sI8CbXc/CnvEt4HnXPKvYBGfwaGVXJyXrdGfbRmX5d9v prqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=F554MBqs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q19si901031edv.156.2020.12.15.04.28.43; Tue, 15 Dec 2020 04:29:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=F554MBqs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729116AbgLOMT0 (ORCPT + 99 others); Tue, 15 Dec 2020 07:19:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729208AbgLOMTH (ORCPT ); Tue, 15 Dec 2020 07:19:07 -0500 Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D30EC06138C for ; Tue, 15 Dec 2020 04:18:26 -0800 (PST) Received: by mail-wm1-x34a.google.com with SMTP id c2so542882wme.0 for ; Tue, 15 Dec 2020 04:18:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=uG9hUyn2l1hT7e+Msb6nBQLe6pVUc/Tidhzusbc3Z5E=; b=F554MBqsbqXbey5idrt7miiBM6ZHDFHoG2ghFR7rjn7HdfCQZPYS1H43gysHs7NFbq /Lk/9pNJ7qSg0sIWFWPKL9WYjw9yvwgGduofqpUzxGhTlBbdQho+xweNJK8WTqV3rSk8 wXJ5RyRJuQgzgWXzD3P3mzYDwlH8Le2SCXpMS+NjpAPDuhH8EvhAHZ0Yg56Qkm/sAvZq KxfENSdqqqWdMtc7RFMWiMBxh3rIk5Av33lp7gHT80VAMbKB0QIP2HNvIVBXo5HY2lsB N3w3f18x9dyidDX3jib1zNgPBzOgp3iGR9GjhaRZfDkbWpqeDxuQ2jMnjq8C9pkWTsEi 0X5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=uG9hUyn2l1hT7e+Msb6nBQLe6pVUc/Tidhzusbc3Z5E=; b=ZPaRO3fwRKJJ+uRPS5abkhq5f/xk0srA+IMqfVRexjKwy9NWBX1InsyoIB7y7bCpry 3EfGhyIJisBLZzmT6XBuq7W0bFocnOoxeCQIn/uijXvSmD+TbI3vPfFV1srz+hwrqRU6 nOU7NeUusJwxvsa2NAMDyWDKvkOMfE/JDoX/PE1hCADEFLCgBcyrR7xj2aBnOpvVfizX kzIoBf2dSu8XGuUFSQ0ABgen9nbAHRQJO5tyPEsQ90UbdC//52cuZwCxrEq8UgBUrd/o dk4vsQ5YEPtvW6JHzNFWBu+poAAVJDQ5QMNxUuYAQCXuHBwoWRxjjE3rcTIFbI/Hjosd E+0w== X-Gm-Message-State: AOAM5333zXgnTWSPxD6bUk7aqGe+2sap74tkd88Ar0FBtuf4A9qPhIWx f3ELdQfAygtM/b0cDQSSV/T1LQ6n/+WnOg== Sender: "jackmanb via sendgmr" X-Received: from beeg.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:11db]) (user=jackmanb job=sendgmr) by 2002:a1c:2c89:: with SMTP id s131mr282870wms.0.1608034704833; Tue, 15 Dec 2020 04:18:24 -0800 (PST) Date: Tue, 15 Dec 2020 12:18:06 +0000 In-Reply-To: <20201215121816.1048557-1-jackmanb@google.com> Message-Id: <20201215121816.1048557-3-jackmanb@google.com> Mime-Version: 1.0 References: <20201215121816.1048557-1-jackmanb@google.com> X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog Subject: [PATCH bpf-next v2] libbpf: Expose libbpf ringbufer epoll_fd From: Brendan Jackman To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , KP Singh , Florent Revest , linux-kernel@vger.kernel.org, Brendan Jackman Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This provides a convenient perf ringbuf -> libbpf ringbuf migration path for users of external polling systems. It is analogous to perf_buffer__epoll_fd. Signed-off-by: Brendan Jackman --- Difference from v1: Added entry to libbpf.map. tools/lib/bpf/libbpf.h | 1 + tools/lib/bpf/libbpf.map | 1 + tools/lib/bpf/ringbuf.c | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 6909ee81113a..cde07f64771e 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -536,6 +536,7 @@ LIBBPF_API int ring_buffer__add(struct ring_buffer *rb, int map_fd, ring_buffer_sample_fn sample_cb, void *ctx); LIBBPF_API int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms); LIBBPF_API int ring_buffer__consume(struct ring_buffer *rb); +LIBBPF_API int ring_buffer__epoll_fd(struct ring_buffer *rb); /* Perf buffer APIs */ struct perf_buffer; diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 7c4126542e2b..7be850271be6 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -348,4 +348,5 @@ LIBBPF_0.3.0 { btf__new_split; xsk_setup_xdp_prog; xsk_socket__update_xskmap; + ring_buffer__epoll_fd; } LIBBPF_0.2.0; diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index 5c6522c89af1..45a36648b403 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -282,3 +282,9 @@ int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms) } return cnt < 0 ? -errno : res; } + +/* Get an fd that can be used to sleep until data is available in the ring(s) */ +int ring_buffer__epoll_fd(struct ring_buffer *rb) +{ + return rb->epoll_fd; +} base-commit: b4fe9fec51ef48011f11c2da4099f0b530449c92 -- 2.29.2.576.ga3fc446d84-goog