From mboxrd@z Thu Jan 1 00:00:00 1970 From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= Subject: Re: [PATCH] samples/bpf: Add xdp_sample_pkts example Date: Thu, 31 May 2018 11:44:17 +0200 Message-ID: <87a7sgcg7i.fsf@toke.dk> References: <20180530164524.21760-1-toke@toke.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: Networking To: Song Liu Return-path: Received: from mail.toke.dk ([52.28.52.200]:45257 "EHLO mail.toke.dk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754342AbeEaJoU (ORCPT ); Thu, 31 May 2018 05:44:20 -0400 In-Reply-To: Sender: netdev-owner@vger.kernel.org List-ID: Song Liu writes: > On Wed, May 30, 2018 at 9:45 AM, Toke H=C3=B8iland-J=C3=B8rgensen wrote: >> This adds an example program showing how to sample packets from XDP using >> the perf event buffer. The example userspace program just prints the >> ethernet header for every packet sampled. >> >> Most of the userspace code is borrowed from other examples, most notably >> trace_output. >> >> Note that the example only works when everything runs on CPU0; so >> suitable smp_affinity needs to be set on the device. Some drivers seem >> to reset smp_affinity when loading an XDP program, so it may be >> necessary to change it after starting the example userspace program. > > Why does this only works when everything runs on CPU0? Is this > something we can improve? Yeah, good question. Basically, the call from XDP to bpf_perf_event_output() will fail with -EOPNOTSUPP. I tracked this down to this if statement in __bpf_perf_event_output() in bpf_trace.c: > if (unlikely(event->oncpu !=3D cpu)) > return -EOPNOTSUPP; I *think* that the way to fix this is for the userspace program to open a perf file descriptor for each CPU in the system and poll all of them, in which case the XDP program can pass the BPF_F_CURRENT_CPU flag to access the right one. I would love for someone more knowledgeable about perf internals to confirm this, though. And, well, the polling function in trace_helpers.c doesn't support currently this, and I didn't have the time to fix that while writing this example :) -Toke