From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-vk1-xa2a.google.com (mail-vk1-xa2a.google.com [IPv6:2607:f8b0:4864:20::a2a]) by mail.toke.dk (Postfix) with ESMTPS id 74EC9A2DD7E for ; Mon, 2 Oct 2023 18:46:21 +0200 (CEST) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=UuyK6FPQ Received: by mail-vk1-xa2a.google.com with SMTP id 71dfb90a1353d-4963adb481dso2329e0c.1 for ; Mon, 02 Oct 2023 09:46:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696265180; x=1696869980; darn=xdp-project.net; 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=vGBqf2RnmzptaT9iLtaWez4RLGgdWxaNUdHCjJ7UdFY=; b=UuyK6FPQ0kIaHZLjEumAyyeia09/YoOVg6rBvl7ky1fFyLNBeliAGHpdDqR29bIQxP bctcWm3wWBx4fcEoDDu4fwI88GESjbHOiKMX5ue1i2mCU6z3mFf3eJFF0Uxh9LdKXvzK Lb8mUnEUho7Y06fSuXN/F8+Qhj//3ynHICQH4CsoZh5Pvf3RgN01Q3Z/KPtYG5Ar8DFh hEWKBik5+Ob3ugjSahRpkh6mO3851fKA9Yx8AUqGGxKNmkdEAvbXCQXT55MnzwJ75iy5 G6N7ARW+b7DUw1PWGRGYZvS/HRDma9edJRhyINw8XLN9H/OpqqerUOSMsidMfQJ+od5I z4sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696265180; x=1696869980; 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=vGBqf2RnmzptaT9iLtaWez4RLGgdWxaNUdHCjJ7UdFY=; b=XBmTaGLdHWhlSDM09Hl3Gr/lLDr076wjqEWGiu5nqboyxYVeAVU+WTc0uiOSDibF+c 7P/u4pT0aEttXclM8gerxpDScO/IKWyF8OYobYH7C/c1leCiMX5Nh+HwMOj/Rjdp/pZt 23ytN2zTM9TTLRFSWeIqxiTm6AZrv6NbmirkOqDsVWbsSL8wh/lbVpcL/0IBhYI5Qw6x 8VF3om3o212v7JrfCKftaebyetACG1RdMsda0CSkDMBmz2wnqmFcUyvbyoBikfPPAeZ1 ziBqvhm3UkK1rSB187Mz4NkUQEcid2T1U3HG496jh2Hrg6+cMJUQV/6hJhlhNuFB70AX GjDg== X-Gm-Message-State: AOJu0Ywnf3qeCm0Z1CaR6vYkGaWT+57SOy/p25gGxL7/Y1Lyy2a5NCxs M1Q//g/DlKtK/7JWp+hUnmHkfcwFLIDM/QqtC5ekPw== X-Google-Smtp-Source: AGHT+IFNJokdZvPkz1n1Kh3JJXi5svhRQyl6CpPYVybM+2pDTGJQQ0JUYWXxaSJtEPQt6TTebpYwxVqjmMJiI2nV1Ns= X-Received: by 2002:a1f:e182:0:b0:495:ee2e:23f9 with SMTP id y124-20020a1fe182000000b00495ee2e23f9mr7964509vkg.15.1696265179921; Mon, 02 Oct 2023 09:46:19 -0700 (PDT) MIME-Version: 1.0 References: <20231002162653.297318-1-larysa.zaremba@intel.com> In-Reply-To: <20231002162653.297318-1-larysa.zaremba@intel.com> From: Stanislav Fomichev Date: Mon, 2 Oct 2023 09:46:08 -0700 Message-ID: To: Larysa Zaremba Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 5BXBLMQWT54YS4WOTS5XDKT2S4I6QDMF X-Message-ID-Hash: 5BXBLMQWT54YS4WOTS5XDKT2S4I6QDMF X-MailFrom: sdf@google.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, haoluo@google.com, jolsa@kernel.org, David Ahern , Jakub Kicinski , Willem de Bruijn , Jesper Dangaard Brouer , Anatoly Burakov , Alexander Lobakin , Magnus Karlsson , Maryam Tahhan , xdp-hints@xdp-project.net, netdev@vger.kernel.org X-Mailman-Version: 3.3.8 Precedence: list Subject: [xdp-hints] Re: [PATCH bpf-next] selftests/bpf: add options and ZC mode to xdp_hw_metadata List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Mon, Oct 2, 2023 at 9:35=E2=80=AFAM Larysa Zaremba wrote: > > By default, xdp_hw_metadata runs in AF_XDP copy mode. However, hints are > also supposed to be supported in ZC mode, which is usually implemented > separately in driver, and so needs to be tested too. > > Add an option to run xdp_hw_metadata in ZC mode. > > As for now, xdp_hw_metadata accepts no options, so add simple option > parsing logic and a help message. > > For quick reference, also add an ingress packet generation command to the > help message. The command comes from [0]. > > [0] https://lore.kernel.org/all/20230119221536.3349901-18-sdf@google.com/ I did similar changes in my pending [0], but I made the zerocopy, not the copy mode, the default. If you want to get this in faster (my series will probably need another iteration), let's maybe do the same here? ZC as a default feels better. 0: https://lore.kernel.org/bpf/20230914210452.2588884-9-sdf@google.com/ > Signed-off-by: Larysa Zaremba > --- > tools/testing/selftests/bpf/xdp_hw_metadata.c | 59 ++++++++++++++++--- > 1 file changed, 52 insertions(+), 7 deletions(-) > > diff --git a/tools/testing/selftests/bpf/xdp_hw_metadata.c b/tools/testin= g/selftests/bpf/xdp_hw_metadata.c > index 613321eb84c1..c1d1b161a964 100644 > --- a/tools/testing/selftests/bpf/xdp_hw_metadata.c > +++ b/tools/testing/selftests/bpf/xdp_hw_metadata.c > @@ -26,6 +26,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -49,6 +50,7 @@ struct xsk { > struct xdp_hw_metadata *bpf_obj; > struct xsk *rx_xsk; > const char *ifname; > +bool zero_copy; > int ifindex; > int rxq; > > @@ -60,7 +62,7 @@ static int open_xsk(int ifindex, struct xsk *xsk, __u32= queue_id) > const struct xsk_socket_config socket_config =3D { > .rx_size =3D XSK_RING_PROD__DEFAULT_NUM_DESCS, > .tx_size =3D XSK_RING_PROD__DEFAULT_NUM_DESCS, > - .bind_flags =3D XDP_COPY, > + .bind_flags =3D zero_copy ? XDP_ZEROCOPY : XDP_COPY, > }; > const struct xsk_umem_config umem_config =3D { > .fill_size =3D XSK_RING_PROD__DEFAULT_NUM_DESCS, > @@ -404,6 +406,54 @@ static void timestamping_enable(int fd, int val) > error(1, errno, "setsockopt(SO_TIMESTAMPING)"); > } > > +static void print_usage(void) > +{ > + const char *usage =3D > + " Usage: xdp_hw_metadata [OPTIONS] [IFNAME]\n" Maybe [OPTIONS] to mark ifname as required? > + " Options:\n" > + " -z Run AF_XDP in ZC mode (copy mode is used= by default)\n" > + " -h Display this help and exit\n\n" > + " Generate test packets on other machine with:\n" > + " echo -n xdp | nc -u -q1 9091\n"; > + > + printf("%s", usage); > +} > + > +static void read_args(int argc, char *argv[]) > +{ > + char opt; > + > + while ((opt =3D getopt(argc, argv, "zh")) !=3D -1) { > + switch (opt) { > + case 'z': > + zero_copy =3D true; > + break; > + case 'h': > + print_usage(); > + exit(0); > + case '?': > + if (isprint(optopt)) > + fprintf(stderr, "Unknown option: -%c\n", = optopt); > + fallthrough; > + default: > + print_usage(); > + error(-1, opterr, "Command line options error"); > + } > + } > + > + if (optind >=3D argc) { > + fprintf(stderr, "No device name provided\n"); > + print_usage(); > + exit(-1); > + } > + > + ifname =3D argv[optind]; > + ifindex =3D if_nametoindex(ifname); > + > + if (!ifname) > + error(-1, errno, "Invalid interface name"); > +} > + > int main(int argc, char *argv[]) > { > clockid_t clock_id =3D CLOCK_TAI; > @@ -413,13 +463,8 @@ int main(int argc, char *argv[]) > > struct bpf_program *prog; > > - if (argc !=3D 2) { > - fprintf(stderr, "pass device name\n"); > - return -1; > - } > + read_args(argc, argv); > > - ifname =3D argv[1]; > - ifindex =3D if_nametoindex(ifname); > rxq =3D rxq_num(ifname); > > printf("rxq: %d\n", rxq); > -- > 2.41.0 >