From patchwork Wed Aug 25 09:37:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456821 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA069C432BE for ; Wed, 25 Aug 2021 09:37:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D13B36113C for ; Wed, 25 Aug 2021 09:37:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239661AbhHYJik (ORCPT ); Wed, 25 Aug 2021 05:38:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233076AbhHYJij (ORCPT ); Wed, 25 Aug 2021 05:38:39 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A609C061757; Wed, 25 Aug 2021 02:37:54 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id f5so35369868wrm.13; Wed, 25 Aug 2021 02:37:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TFxXv+JEDyBSP+0ivETIiLsWzQlD0yqEZGyjBoEiO6s=; b=rk2wAWkvRRrfHFqQk50LBGj4qn4gRz98DzLHgJkM7IvMIXnrK6zcYxxtYX88CQs39h 9TiPUq1Xe0SPDwAn9sOntpdPu5hn8KIQ9M9L6QbyrWMPsJzl5FVndqx4SrwZvj2WeiR2 EpJbrRWtePaA5RGX2IQd4aumXVj8oHRpG0kGKEqJOr3YylIi0wQe9TS+vZUyTgtltGgo n/Kr8IwxQtx/oxCryBmC9VLt7RWDabxMHldA56y9ttAnKu6xIPP/NzlNdrdEG0vgEhq3 IgjnDigF9f7P8VGbkrCFq7sBGLa5RrN1u2dDKV2D7TyW0vZ1WvzvycC1grWwZt82PqdE yDGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TFxXv+JEDyBSP+0ivETIiLsWzQlD0yqEZGyjBoEiO6s=; b=cO9ieexDsqACFaWMMAXACslz0q6uMeO6d0YSF7pKDiIEuZjTCcgO3HGlKQynhfneZc hwMpJTmzHpOBLGBGZXRFTh0NbPG/docBgaVW18QU1njAaPo27pkNPdMy4dl4dyVuV3H2 BbEjCj3X3aITAOll4Wjw5UTHNGB4Pkl7fbJFsbckrjhUlEjLtZTu/mctNxiaY1CGK1rn S7f2GXM+bjC1HKXL04NAfRscgdvSKOHbLoOIId+/8HKnZIBU3wC2cORr+T44CIVUqBdB RvFxVYwVmWhWehkpM1yw2aB1vsZDhHDBB9/d6iVE8XZaRlYCp2EoBXyI8HfMzRP3hKwv +yTg== X-Gm-Message-State: AOAM532e/x1F8q4SiKrBzB91DZjcFepjxtjSBypZo45Q1hVGDCRRsldr o9+ZB/20RqnKPSpPVlPzJZI= X-Google-Smtp-Source: ABdhPJwy0mx1HNys6N5qbZkTCm3nyQddm0xlHj0aTf94JvekvFggkoXMggUHfKomd+m+jiRz3v6ZSA== X-Received: by 2002:adf:e801:: with SMTP id o1mr22167273wrm.128.1629884272930; Wed, 25 Aug 2021 02:37:52 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.37.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:37:52 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 01/16] selftests: xsk: remove color mode Date: Wed, 25 Aug 2021 11:37:07 +0200 Message-Id: <20210825093722.10219-2-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Remove color mode since it does not add any value and having less code means less maintenance which is a good thing. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/test_xsk.sh | 10 +++----- tools/testing/selftests/bpf/xsk_prereqs.sh | 27 +++++----------------- 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/tools/testing/selftests/bpf/test_xsk.sh b/tools/testing/selftests/bpf/test_xsk.sh index 46633a3bfb0b..cd7bf32e6a17 100755 --- a/tools/testing/selftests/bpf/test_xsk.sh +++ b/tools/testing/selftests/bpf/test_xsk.sh @@ -63,14 +63,11 @@ # ---------------- # Must run with CAP_NET_ADMIN capability. # -# Run (full color-coded output): -# sudo ./test_xsk.sh -c +# Run: +# sudo ./test_xsk.sh # # If running from kselftests: -# sudo make colorconsole=1 run_tests -# -# Run (full output without color-coding): -# sudo ./test_xsk.sh +# sudo make run_tests # # Run with verbose output: # sudo ./test_xsk.sh -v @@ -83,7 +80,6 @@ while getopts "cvD" flag do case "${flag}" in - c) colorconsole=1;; v) verbose=1;; D) dump_pkts=1;; esac diff --git a/tools/testing/selftests/bpf/xsk_prereqs.sh b/tools/testing/selftests/bpf/xsk_prereqs.sh index dac1c5f78752..8fe022a4dbfa 100755 --- a/tools/testing/selftests/bpf/xsk_prereqs.sh +++ b/tools/testing/selftests/bpf/xsk_prereqs.sh @@ -8,11 +8,6 @@ ksft_xfail=2 ksft_xpass=3 ksft_skip=4 -GREEN='\033[0;92m' -YELLOW='\033[0;93m' -RED='\033[0;31m' -NC='\033[0m' -STACK_LIM=131072 SPECFILE=veth.spec XSKOBJ=xdpxceiver NUMPKTS=10000 @@ -50,22 +45,12 @@ validate_veth_spec_file() test_status() { statusval=$1 - if [ -n "${colorconsole+set}" ]; then - if [ $statusval -eq 2 ]; then - echo -e "${YELLOW}$2${NC}: [ ${RED}FAIL${NC} ]" - elif [ $statusval -eq 1 ]; then - echo -e "${YELLOW}$2${NC}: [ ${RED}SKIPPED${NC} ]" - elif [ $statusval -eq 0 ]; then - echo -e "${YELLOW}$2${NC}: [ ${GREEN}PASS${NC} ]" - fi - else - if [ $statusval -eq 2 ]; then - echo -e "$2: [ FAIL ]" - elif [ $statusval -eq 1 ]; then - echo -e "$2: [ SKIPPED ]" - elif [ $statusval -eq 0 ]; then - echo -e "$2: [ PASS ]" - fi + if [ $statusval -eq 2 ]; then + echo -e "$2: [ FAIL ]" + elif [ $statusval -eq 1 ]; then + echo -e "$2: [ SKIPPED ]" + elif [ $statusval -eq 0 ]; then + echo -e "$2: [ PASS ]" fi } From patchwork Wed Aug 25 09:37:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456823 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84744C4338F for ; Wed, 25 Aug 2021 09:38:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C54E6112D for ; Wed, 25 Aug 2021 09:38:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239746AbhHYJip (ORCPT ); Wed, 25 Aug 2021 05:38:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239700AbhHYJil (ORCPT ); Wed, 25 Aug 2021 05:38:41 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6BE3C061757; Wed, 25 Aug 2021 02:37:55 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id z9so35354712wrh.10; Wed, 25 Aug 2021 02:37:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SHN0knzzGUDpjgGLyjuHfb5FkhNeud4rrqTgmdVTNkY=; b=CP8O+bCjnQC2GH4fM4yB/W5yjfVituw17NH4tBpruQ0TGGW2iCHy+JFY6b263fThXK G5Zrc2leoyA+Omf6q6X1ykKG8kDZ5KInYl4jD98FFrZFWnsbXjUBk+bj3MGbD33Qt/pe riqol+FiYiK9W/RhOdNwP2DiyeCPE/g7c7MS8IotCAjkU4vHL/x6S4eEUU48rIu4IlCR 5whGkFd752QwmSBPoKdnXex8+0PKh/D7VUTX+HYUX2Q7UhJ0Q19H07kMC5Opbg+UhCIz xy4AfV4uTOwgMpceWLnrOlPrfp6DQuZLFAeW/Ch3yHtZKMgj1+7OjYdwLCBchQWMQQJq 11zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SHN0knzzGUDpjgGLyjuHfb5FkhNeud4rrqTgmdVTNkY=; b=NGq7sboeNPJi/f6/9yd05ZNXRF1WPQgS6N9BvGJr3NVh1jNL9rj/hqgh8Sipbbcnk9 GsDRy74BZ73I986+bVt/chsDaUMSeCSYiwjXqhwxk/l6hodzz3OWFYxnqf4xceGvPpRO Iscd+5ORmxa1wO8d1sfivr7IflXyMkcbK4HRiYHzXhThaaE0Bg7QsAY4wXkdFljT65kQ DiG2WiLBgOwr0N/n7ks6I1HfZuH24J8d6if3Vzh+GLUC6+xWwTM5jOymfRON8My7qKdj 3Z8p8BNehE6vkTBKVD+Ucva0K5x8jt0TiUT1R0xvTGXo/aI+l2/H1i9W/XTinwp7FC0F Rg7w== X-Gm-Message-State: AOAM530sbjSBJp452BQ/zfc2eC6AhAugXqWhd4Q8yRo8n8ed4zI96qqd 7iUJe50eDkCtcN3qc86TX54= X-Google-Smtp-Source: ABdhPJyOsivdfAw46qz7bOrsQK4dvtwR7FRffMqa4bQclv5ahZSkSy0nWd3Rf46eQom6cA6FV6YzsA== X-Received: by 2002:a5d:4f02:: with SMTP id c2mr24642975wru.311.1629884274428; Wed, 25 Aug 2021 02:37:54 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.37.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:37:54 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 02/16] selftests: xsk: remove the num_tx_packets option Date: Wed, 25 Aug 2021 11:37:08 +0200 Message-Id: <20210825093722.10219-3-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Remove the number of tx packet option as this should be decided by the test itself. Also change the number of packets to be sent to 4096 speeding up the execution. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 33 +++++++--------------- tools/testing/selftests/bpf/xdpxceiver.h | 4 +-- tools/testing/selftests/bpf/xsk_prereqs.sh | 3 +- 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 1135fb980814..1b0efe566278 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -333,20 +333,19 @@ static struct option long_options[] = { {"queue", optional_argument, 0, 'q'}, {"dump-pkts", optional_argument, 0, 'D'}, {"verbose", no_argument, 0, 'v'}, - {"tx-pkt-count", optional_argument, 0, 'C'}, {0, 0, 0, 0} }; static void usage(const char *prog) { const char *str = - " Usage: %s [OPTIONS]\n" - " Options:\n" - " -i, --interface Use interface\n" - " -q, --queue=n Use queue n (default 0)\n" - " -D, --dump-pkts Dump packets L2 - L5\n" - " -v, --verbose Verbose output\n" - " -C, --tx-pkt-count=n Number of packets to send\n"; + " Usage: %s [OPTIONS]\n" + " Options:\n" + " -i, --interface Use interface\n" + " -q, --queue=n Use queue n (default 0)\n" + " -D, --dump-pkts Dump packets L2 - L5\n" + " -v, --verbose Verbose output\n"; + ksft_print_msg(str, prog); } @@ -392,7 +391,7 @@ static void parse_command_line(int argc, char **argv) opterr = 0; for (;;) { - c = getopt_long(argc, argv, "i:DC:v", long_options, &option_index); + c = getopt_long(argc, argv, "i:Dv", long_options, &option_index); if (c == -1) break; @@ -415,9 +414,6 @@ static void parse_command_line(int argc, char **argv) case 'D': debug_pkt_dump = 1; break; - case 'C': - opt_pkt_count = atoi(optarg); - break; case 'v': opt_verbose = 1; break; @@ -427,11 +423,6 @@ static void parse_command_line(int argc, char **argv) } } - if (!opt_pkt_count) { - print_verbose("No tx-pkt-count specified, using default %u\n", DEFAULT_PKT_CNT); - opt_pkt_count = DEFAULT_PKT_CNT; - } - if (!validate_interfaces()) { usage(basename(argv[0])); ksft_exit_xfail(); @@ -554,9 +545,6 @@ static void tx_only(struct xsk_socket_info *xsk, u32 *frameptr, int batch_size) static int get_batch_size(int pkt_cnt) { - if (!opt_pkt_count) - return BATCH_SIZE; - if (pkt_cnt + BATCH_SIZE <= opt_pkt_count) return BATCH_SIZE; @@ -586,7 +574,7 @@ static void tx_only_all(struct ifobject *ifobject) fds[0].fd = xsk_socket__fd(ifobject->xsk->xsk); fds[0].events = POLLOUT; - while ((opt_pkt_count && pkt_cnt < opt_pkt_count) || !opt_pkt_count) { + while (pkt_cnt < opt_pkt_count) { int batch_size = get_batch_size(pkt_cnt); if (test_type == TEST_TYPE_POLL) { @@ -602,8 +590,7 @@ static void tx_only_all(struct ifobject *ifobject) pkt_cnt += batch_size; } - if (opt_pkt_count) - complete_tx_only_all(ifobject); + complete_tx_only_all(ifobject); } static void worker_pkt_dump(void) diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 6c428b276ab6..4ce5a18b32e7 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -39,7 +39,7 @@ #define SOCK_RECONF_CTR 10 #define BATCH_SIZE 64 #define POLL_TMOUT 1000 -#define DEFAULT_PKT_CNT 10000 +#define DEFAULT_PKT_CNT (4 * 1024) #define RX_FULL_RXQSIZE 32 #define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0) @@ -79,7 +79,7 @@ static u32 num_frames; static bool second_step; static int test_type; -static int opt_pkt_count; +static u32 opt_pkt_count = DEFAULT_PKT_CNT; static u8 opt_verbose; static u32 xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; diff --git a/tools/testing/selftests/bpf/xsk_prereqs.sh b/tools/testing/selftests/bpf/xsk_prereqs.sh index 8fe022a4dbfa..bf29d2549bee 100755 --- a/tools/testing/selftests/bpf/xsk_prereqs.sh +++ b/tools/testing/selftests/bpf/xsk_prereqs.sh @@ -10,7 +10,6 @@ ksft_skip=4 SPECFILE=veth.spec XSKOBJ=xdpxceiver -NUMPKTS=10000 validate_root_exec() { @@ -92,5 +91,5 @@ validate_ip_utility() execxdpxceiver() { - ./${XSKOBJ} -i ${VETH0} -i ${VETH1},${NS1} -C ${NUMPKTS} ${VERBOSE_ARG} ${DUMP_PKTS_ARG} + ./${XSKOBJ} -i ${VETH0} -i ${VETH1},${NS1} ${VERBOSE_ARG} ${DUMP_PKTS_ARG} } From patchwork Wed Aug 25 09:37:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456825 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0AA8C4320E for ; Wed, 25 Aug 2021 09:38:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C364E6113C for ; Wed, 25 Aug 2021 09:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239700AbhHYJip (ORCPT ); Wed, 25 Aug 2021 05:38:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239735AbhHYJio (ORCPT ); Wed, 25 Aug 2021 05:38:44 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BE53C06179A; Wed, 25 Aug 2021 02:37:57 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id v10so24196567wrd.4; Wed, 25 Aug 2021 02:37:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q6qddnNCl+ddNnMLMws7fqahAlg13r+FeqAPD2rVFjc=; b=vchVMbl8Wp0tBl7cQY3VM7H/TPLTsI6oRVZWkoUkIM5uCIbDZXRe13Zit9Yymjgaaa Xwe2WzvzquMzoOWWX1++3X0yzcklXBJnZuBVwVJ77sA+tf2ALze58iLduqhyd5ec6uZu q6R2wMHLWGfUz3krqnKMsqMxuqTWTN5F0WE+FsWF0JVTKUCGz9c+xZTNGGxmHAxDz41R 0ZChUARavAy0uyV5rShk8eH6k+Y5hCoS2SVc1AGUQTlt/SKmH8BpnxaK6w+YcexR3S2N R0cDOAQEycNA6846xF6sigxcJglkZ6tW2/Njpp1a89fRF5RiazoXZXaq1zjvq3cg24aY LT5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q6qddnNCl+ddNnMLMws7fqahAlg13r+FeqAPD2rVFjc=; b=J6qrp5z5O2UVsQaZ7jPhkvgtXV3UTKlABHXyQpMaXwTTJJqPsRqyWSYNILa63/E8Rt 8ze6+ZMGPRAjmN9ZXwXrQDqbPSfIlhOGHy0hhcwKW+otSUiJKWlGeiiaahhq+pxLb357 ioeVZ1ZZlavX6pDWtZYTF3hsfecWUdCDyxCQ5b1alkL+IITaUu1Y9IY7RK9N8vP1YKHE ZiX66/gK0JHPKqM/U2AtaQQ3CF0/V3xKNAMte9xqhZI0B8r42AIiGVlw32utpkFWsXnV zHYI5tXnENxnresYdKvRyzmQQGFd7Zd0figoRYUWBAuuap0xTDJ0mrpL9iUL4ImJqnZl 9APA== X-Gm-Message-State: AOAM5336ZLPWNoA2UBU1piYN0TNhcsQdw+fG8V2w/kq8EIxfHp2zr/K9 HukIbDjaUnD90k3kOrM9xws= X-Google-Smtp-Source: ABdhPJzZ56YEXzGbkAOqbUwVfCoAEMu6/yWc9LKrW4u8oRSUbq7RJ5uRTRsMUXZdFnjZPhd9XEjzWA== X-Received: by 2002:a05:6000:18a:: with SMTP id p10mr20116694wrx.40.1629884275899; Wed, 25 Aug 2021 02:37:55 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.37.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:37:55 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 03/16] selftests: xsk: remove unused variables Date: Wed, 25 Aug 2021 11:37:09 +0200 Message-Id: <20210825093722.10219-4-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Remove unused variables and typedefs. The *_npkts variables are incremented but never used. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 3 --- tools/testing/selftests/bpf/xdpxceiver.h | 8 -------- 2 files changed, 11 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 1b0efe566278..4d8ee636fc24 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -70,7 +70,6 @@ #include #include #include -typedef __u16 __sum16; #include #include #include @@ -454,7 +453,6 @@ static void complete_tx_only(struct xsk_socket_info *xsk, int batch_size) if (rcvd) { xsk_ring_cons__release(&xsk->umem->cq, rcvd); xsk->outstanding_tx -= rcvd; - xsk->tx_npkts += rcvd; } } @@ -512,7 +510,6 @@ static void rx_pkt(struct xsk_socket_info *xsk, struct pollfd *fds) xsk_ring_prod__submit(&xsk->umem->fq, rcvd); xsk_ring_cons__release(&xsk->rx, rcvd); - xsk->rx_npkts += rcvd; } static void tx_only(struct xsk_socket_info *xsk, u32 *frameptr, int batch_size) diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 4ce5a18b32e7..02b7d0d6f45d 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -44,10 +44,6 @@ #define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0) -typedef __u32 u32; -typedef __u16 u16; -typedef __u8 u8; - enum TEST_MODES { TEST_MODE_UNCONFIGURED = -1, TEST_MODE_SKB, @@ -104,10 +100,6 @@ struct xsk_socket_info { struct xsk_ring_prod tx; struct xsk_umem_info *umem; struct xsk_socket *xsk; - unsigned long rx_npkts; - unsigned long tx_npkts; - unsigned long prev_rx_npkts; - unsigned long prev_tx_npkts; u32 outstanding_tx; }; From patchwork Wed Aug 25 09:37:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456827 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC240C43216 for ; Wed, 25 Aug 2021 09:38:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E09E61100 for ; Wed, 25 Aug 2021 09:38:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239759AbhHYJiq (ORCPT ); Wed, 25 Aug 2021 05:38:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239742AbhHYJio (ORCPT ); Wed, 25 Aug 2021 05:38:44 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5CECC0613A3; Wed, 25 Aug 2021 02:37:58 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id z4so19775928wrr.6; Wed, 25 Aug 2021 02:37:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RrmKLByNzzoypaDx7zqqevtKRSZED5KqWCuj6czuLk4=; b=N9RGDrZic02uNWM2Y61zZb+XdjGVW+o0TnFLr8IPAFlvQjv1Rt9Btdjz3A0IdikWXq zauOuo2d1DUf8p3sC1QOL5slCw1lMTsouqh1M8gCuBDTdza/BerbcjXN/P6MJUA0kWjb WLe2YdUetyABWZD2XhGPvgUfmIoOWDk5U0xXl//IfgnusCasDn+tzA9Xi3jZWxRzSwEu sNoYiSdAQHusIXxy82Y9mLZoopGRkii0vXnYM3zOCRYCf5ERirhyxbAhEjl34024uewC jip63LXWfimSiMWZVVUIHgbhsg+XMoi3g8fl5RUC24hI6Wi3WMpColsc+MG27kIJpBPB /iVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RrmKLByNzzoypaDx7zqqevtKRSZED5KqWCuj6czuLk4=; b=ZYwVukU5oytU0wHIiS0Z7ZEZDaLmW+G4T1ix8dwolU+DNaCyOylrD2/8HH1DMgB+PA u0lNzzRXP0Xc0GlNgCfnQ8tu1bxwllGUNQXti4wPCE7E/vG8XNlHU+ey2kt1mBoiHF9b sKghkSjrTHw4zukHQgJhpzui6gUIOXmpqzDDtUZP5p33AGJ5SRB4iKWtumZuDXU1025Y 1xFgzmUAsClvBmcm8ZGppJsvHnaLiYHpnDsXO9hRi7mxYlVz7XnuXDjRYKTlHYLDori/ 6aCOF3RVGQzgfAnvP0PpUMiGOs7b5H4+KOYhfxgScZGCpk9yKx1p+tS6Y1C4WvsinuPw JR2A== X-Gm-Message-State: AOAM530diu484WCo/fTHaY9xOBUoaD9P3TqKlpMThKEvbhkfaP/F3XG8 eY3eMJI6MU0Z3JLca+6jSP8= X-Google-Smtp-Source: ABdhPJxMG7jBQvYCLpt7AZitWshurWkoBjWCO9ZBFvTYbg9waphqKQqVLivlyL8ofyhZfpyoT5Ok3g== X-Received: by 2002:adf:c3c3:: with SMTP id d3mr24110219wrg.373.1629884277482; Wed, 25 Aug 2021 02:37:57 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.37.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:37:57 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 04/16] selftests: xsk: return correct error codes Date: Wed, 25 Aug 2021 11:37:10 +0200 Message-Id: <20210825093722.10219-5-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Return the correct error codes so they can be printed correctly. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 4d8ee636fc24..f221bc5dae17 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -270,7 +270,7 @@ static void xsk_configure_umem(struct ifobject *data, void *buffer, int idx) ret = xsk_umem__create(&umem->umem, buffer, size, &umem->fq, &umem->cq, &cfg); if (ret) - exit_with_error(ret); + exit_with_error(-ret); umem->buffer = buffer; @@ -284,7 +284,7 @@ static void xsk_populate_fill_ring(struct xsk_umem_info *umem) ret = xsk_ring_prod__reserve(&umem->fq, XSK_RING_PROD__DEFAULT_NUM_DESCS, &idx); if (ret != XSK_RING_PROD__DEFAULT_NUM_DESCS) - exit_with_error(ret); + exit_with_error(-ret); for (i = 0; i < XSK_RING_PROD__DEFAULT_NUM_DESCS; i++) *xsk_ring_prod__fill_addr(&umem->fq, idx++) = i * XSK_UMEM__DEFAULT_FRAME_SIZE; xsk_ring_prod__submit(&umem->fq, XSK_RING_PROD__DEFAULT_NUM_DESCS); @@ -467,7 +467,7 @@ static void rx_pkt(struct xsk_socket_info *xsk, struct pollfd *fds) if (xsk_ring_prod__needs_wakeup(&xsk->umem->fq)) { ret = poll(fds, 1, POLL_TMOUT); if (ret < 0) - exit_with_error(ret); + exit_with_error(-ret); } return; } @@ -475,11 +475,11 @@ static void rx_pkt(struct xsk_socket_info *xsk, struct pollfd *fds) ret = xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq); while (ret != rcvd) { if (ret < 0) - exit_with_error(ret); + exit_with_error(-ret); if (xsk_ring_prod__needs_wakeup(&xsk->umem->fq)) { ret = poll(fds, 1, POLL_TMOUT); if (ret < 0) - exit_with_error(ret); + exit_with_error(-ret); } ret = xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq); } From patchwork Wed Aug 25 09:37:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456829 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73DCAC4338F for ; Wed, 25 Aug 2021 09:38:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 609A661153 for ; Wed, 25 Aug 2021 09:38:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239739AbhHYJir (ORCPT ); Wed, 25 Aug 2021 05:38:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239718AbhHYJip (ORCPT ); Wed, 25 Aug 2021 05:38:45 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59CC9C061757; Wed, 25 Aug 2021 02:38:00 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id d22-20020a1c1d16000000b002e7777970f0so3793337wmd.3; Wed, 25 Aug 2021 02:38:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p1ZV12Wr3LwBHVU+XKp6bzmBy9RlmTyfmIyQtKDzVq4=; b=u+FyZ5VJdKGWnfMbjNKgHNRoYHqOzR+5+0mXiKT3/Y+TmSmlY2t59nZZ9ixIux1Bo5 ow/8Tt+h2NiTtFz2ybkB0waZR32zXbn5KsIZMt53LCVD1UVFd4/t8QinOxatKxcUAVVz H4vVXLeZILrqaDL9t+PggNTjTj7gzlKhsZlyq+fdvCrClEyWM8XM+hbt6hMc4SLY8B7Y uTCexHHk/jJQadWDnIB0b7TGCLLC33CRldE+pUdBwFrq09AyXz4IYN+G8yAHoPpwaJAh drE0tsFiA6tnQ54MYbZZ9ONPCfxNew15t/i3pJ+f06qRPOtl2Z9NQQzCOhjWW4+V2aeR m/Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p1ZV12Wr3LwBHVU+XKp6bzmBy9RlmTyfmIyQtKDzVq4=; b=Qs4Oy5zxDP6P4rEsba+zJkWGMgoAbjUxi2Ji9P7xpR/V1l077YTMCicVNbeFEokXeu knMZZnj6t4I6pXfkwMdLI0Yu7hzKoTWYZFQ1p9qt3T5Pk0DHhm+s6MkbvrxVH5RQY6zn +RlfIrgIhemobtosJbMaUYsM1EhvL/O/cvdNuazSk8kKE+Ttq5fYxnGreT/ANQtClbJs MEeojeQ8cueH34/cgHxhGsS/R+9uh0y5mUO1ROJ/sDiwvNa5+fxbJbPE2JyAiJCoDVWq HTFcR2AEnZr+VOBNLgfiUzA1+4Kd51115uE2OZ+h8LtRkjAZr1bh7QnKyHspZE8HOg+m o2Pw== X-Gm-Message-State: AOAM530A78E3xNWrGlj5BXgBlG3UQA+wxWYzJtnYHuslVlcWaWNlaKpB QqgOv9GhDq+J/2Eg67YH5vk= X-Google-Smtp-Source: ABdhPJyVIZ7d8sDYLKoOI5DhDOrYdy+RSMsarjpftLHBziPxOWfMDlpR94CZi+vCezolMn4hkcLbjw== X-Received: by 2002:a7b:c401:: with SMTP id k1mr1465911wmi.141.1629884279012; Wed, 25 Aug 2021 02:37:59 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.37.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:37:58 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 05/16] selftests: xsk: simplify the retry code Date: Wed, 25 Aug 2021 11:37:11 +0200 Message-Id: <20210825093722.10219-6-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Simplify the retry code and make it more efficient by waiting first, instead of trying immediately which always fails due to the asynchronous nature of xsk socket close. Also decrease the wait time to significantly lower the run-time of the test suite. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 23 ++++++++++------------- tools/testing/selftests/bpf/xdpxceiver.h | 2 +- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index f221bc5dae17..b7d193a96083 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -745,24 +745,19 @@ static void thread_common_ops(struct ifobject *ifobject, void *bufs) if (bufs == MAP_FAILED) exit_with_error(errno); - xsk_configure_umem(ifobject, bufs, 0); - ifobject->umem = ifobject->umem_arr[0]; - ret = xsk_configure_socket(ifobject, 0); - - /* Retry Create Socket if it fails as xsk_socket__create() - * is asynchronous - */ - while (ret && ctr < SOCK_RECONF_CTR) { + while (ctr++ < SOCK_RECONF_CTR) { xsk_configure_umem(ifobject, bufs, 0); ifobject->umem = ifobject->umem_arr[0]; ret = xsk_configure_socket(ifobject, 0); + if (!ret) + break; + + /* Retry Create Socket if it fails as xsk_socket__create() is asynchronous */ usleep(USLEEP_MAX); - ctr++; + if (ctr >= SOCK_RECONF_CTR) + exit_with_error(-ret); } - if (ctr >= SOCK_RECONF_CTR) - exit_with_error(ret); - ifobject->umem = ifobject->umem_arr[0]; ifobject->xsk = ifobject->xsk_arr[0]; @@ -1125,8 +1120,10 @@ int main(int argc, char **argv) ksft_set_plan(TEST_MODE_MAX * TEST_TYPE_MAX); for (i = 0; i < TEST_MODE_MAX; i++) { - for (j = 0; j < TEST_TYPE_MAX; j++) + for (j = 0; j < TEST_TYPE_MAX; j++) { run_pkt_test(i, j); + usleep(USLEEP_MAX); + } } cleanup: diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 02b7d0d6f45d..1c94230c351a 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -35,7 +35,7 @@ #define UDP_PKT_SIZE (IP_PKT_SIZE - sizeof(struct iphdr)) #define UDP_PKT_DATA_SIZE (UDP_PKT_SIZE - sizeof(struct udphdr)) #define EOT (-1) -#define USLEEP_MAX 200000 +#define USLEEP_MAX 10000 #define SOCK_RECONF_CTR 10 #define BATCH_SIZE 64 #define POLL_TMOUT 1000 From patchwork Wed Aug 25 09:37:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456831 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1F52C4338F for ; Wed, 25 Aug 2021 09:38:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC59E61100 for ; Wed, 25 Aug 2021 09:38:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239810AbhHYJix (ORCPT ); Wed, 25 Aug 2021 05:38:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239760AbhHYJir (ORCPT ); Wed, 25 Aug 2021 05:38:47 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDB0DC061757; Wed, 25 Aug 2021 02:38:01 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id i3so3747105wmq.3; Wed, 25 Aug 2021 02:38:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kgPj7G38SyrgEwWt/WKASQsH5BeWP3MgfM+9IFhFdKc=; b=LemYS2h1v1Gu3pghc4oyHtwh7qh7yKTV3bYJl68UYt9+eJUT1ICnUJh9LRNOjBGvlq zHdwI00HD56Bd98ynBbXbmXE3fNGw7fpnUCU7SshB+WJZu2A639WV6p6wlt+Jvq1jamw YlC/35PvbiBkvQum5Qxc6USs/3JTnT3PpI5dHu+5pUHO9Uk8IZAi9CUy4piOAiRgyVP5 ChywfgTOTmLcfeWgiz3wV+e+/eP7gw4sBsRk3lxym33ikmzpnvOzTjRImvGUHSgMmJp3 fgf1JUjX4jCrSCc0qO/PLzahbFyd4fbzNAzqQNsQ6v0gVbCvTpyshLs51XqL+wpCFqi4 TqcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kgPj7G38SyrgEwWt/WKASQsH5BeWP3MgfM+9IFhFdKc=; b=Cipq6RLAZM72mfkgAhoK5NjJPacR5ULCUnJ2wwq7scxWnpacmT+Z2I1vPpWZNDbvJf 5ook1wEulHkk3PaWF0LkTDk7yFOvq1MUXtFgYcgno6eMG/9pk1FL9OMPuende9i6LHMS gyrd4E6yYDwrmgj8e+6l+p5Lqo4f7kUPZRajQ5YLGXCStctclDpHDQijxLhpwiA5G9GJ 9Ib96Spu5lP13nYjnTvFiI4X5sK/4iKF7V0RIOk6E5+T8JQZ9a7I0Hs0a2zwxtkjU+fo nJmP6Dml3jCuNISvRz0lSdIS823a427u4X0DFI4ES+SHkCe0SWDGY21QBo9oFYdJo2rG 3HDQ== X-Gm-Message-State: AOAM531QwIAJwjcwaXtD9b53tA+fVDZY0Ke1AD+L+m8zEJ9BngmKRKNk ukOfMHCpE/B9msahpCbuwBg= X-Google-Smtp-Source: ABdhPJzwJuNeCeOPwpLiXu2rPl2uR5NsNiQ6SyUuziUNNdJ26JRT/hU/qeDW04Vz7OuKvomqxFJY6A== X-Received: by 2002:a05:600c:2058:: with SMTP id p24mr5180185wmg.108.1629884280502; Wed, 25 Aug 2021 02:38:00 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.37.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:38:00 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 06/16] selftests: xsk: remove end-of-test packet Date: Wed, 25 Aug 2021 11:37:12 +0200 Message-Id: <20210825093722.10219-7-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Get rid of the end-of-test packet and just count the number of packets received and quit when the expected number as been received. Simplifies the code. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 42 +++++++----------------- tools/testing/selftests/bpf/xdpxceiver.h | 2 -- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index b7d193a96083..b0fee71355bf 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -600,7 +600,7 @@ static void worker_pkt_dump(void) void *ptr; fprintf(stdout, "---------------------------------------\n"); - for (int iter = 0; iter < num_frames - 1; iter++) { + for (int iter = 0; iter < num_frames; iter++) { ptr = pkt_buf[iter]->payload; ethhdr = ptr; iphdr = ptr + sizeof(*ethhdr); @@ -627,11 +627,6 @@ static void worker_pkt_dump(void) /*extract L5 frame */ payload = *((uint32_t *)(ptr + PKT_HDR_SIZE)); - if (payload == EOT) { - print_verbose("End-of-transmission frame received\n"); - fprintf(stdout, "---------------------------------------\n"); - break; - } fprintf(stdout, "DEBUG>> L5: payload: %d\n", payload); fprintf(stdout, "---------------------------------------\n"); } @@ -694,28 +689,24 @@ static void worker_pkt_validate(void) /*do not increment pktcounter if !(tos=0x9 and ipv4) */ if (iphdr->version == IP_PKT_VER && iphdr->tos == IP_PKT_TOS) { payloadseqnum = *((uint32_t *)(pkt_node_rx_q->pkt_frame + PKT_HDR_SIZE)); - if (debug_pkt_dump && payloadseqnum != EOT) { + if (debug_pkt_dump) { pkt_obj = malloc(sizeof(*pkt_obj)); pkt_obj->payload = malloc(PKT_SIZE); memcpy(pkt_obj->payload, pkt_node_rx_q->pkt_frame, PKT_SIZE); pkt_buf[payloadseqnum] = pkt_obj; } - if (payloadseqnum == EOT) { - print_verbose("End-of-transmission frame received: PASS\n"); - sigvar = 1; - break; - } - - if (prev_pkt + 1 != payloadseqnum) { + if (pkt_counter % num_frames != payloadseqnum) { ksft_test_result_fail - ("ERROR: [%s] prev_pkt [%d], payloadseqnum [%d]\n", - __func__, prev_pkt, payloadseqnum); + ("ERROR: [%s] expected counter [%d], payloadseqnum [%d]\n", + __func__, pkt_counter, payloadseqnum); ksft_exit_xfail(); } - prev_pkt = payloadseqnum; - pkt_counter++; + if (++pkt_counter == opt_pkt_count) { + sigvar = 1; + break; + } } else { ksft_print_msg("Invalid frame received: "); ksft_print_msg("[IP_PKT_VER: %02X], [IP_PKT_TOS: %02X]\n", iphdr->version, @@ -800,11 +791,7 @@ static void *worker_testapp_validate_tx(void *arg) thread_common_ops(ifobject, bufs); for (int i = 0; i < num_frames; i++) { - /*send EOT frame */ - if (i == (num_frames - 1)) - data.seqnum = -1; - else - data.seqnum = i; + data.seqnum = i; gen_udp_hdr(&data, ifobject, udp_hdr); gen_ip_hdr(ifobject, ip_hdr); gen_udp_csum(udp_hdr, ip_hdr); @@ -812,8 +799,7 @@ static void *worker_testapp_validate_tx(void *arg) gen_eth_frame(ifobject->umem, i * XSK_UMEM__DEFAULT_FRAME_SIZE); } - print_verbose("Sending %d packets on interface %s\n", - (opt_pkt_count - 1), ifobject->ifname); + print_verbose("Sending %d packets on interface %s\n", opt_pkt_count, ifobject->ifname); tx_only_all(ifobject); testapp_cleanup_xsk_res(ifobject); @@ -888,7 +874,7 @@ static void testapp_validate(void) if (debug_pkt_dump && test_type != TEST_TYPE_STATS) { worker_pkt_dump(); - for (int iter = 0; iter < num_frames - 1; iter++) { + for (int iter = 0; iter < num_frames; iter++) { free(pkt_buf[iter]->payload); free(pkt_buf[iter]); } @@ -905,7 +891,6 @@ static void testapp_teardown(void) for (i = 0; i < MAX_TEARDOWN_ITER; i++) { pkt_counter = 0; - prev_pkt = -1; sigvar = 0; print_verbose("Creating socket\n"); testapp_validate(); @@ -933,7 +918,6 @@ static void testapp_bidi(void) { for (int i = 0; i < MAX_BIDI_ITER; i++) { pkt_counter = 0; - prev_pkt = -1; sigvar = 0; print_verbose("Creating socket\n"); testapp_validate(); @@ -967,7 +951,6 @@ static void testapp_bpf_res(void) for (i = 0; i < MAX_BPF_ITER; i++) { pkt_counter = 0; - prev_pkt = -1; sigvar = 0; print_verbose("Creating socket\n"); testapp_validate(); @@ -1043,7 +1026,6 @@ static void run_pkt_test(int mode, int type) xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; pkt_counter = 0; second_step = 0; - prev_pkt = -1; sigvar = 0; stat_test_type = -1; rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS; diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 1c94230c351a..a4371d9e2798 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -34,7 +34,6 @@ #define IP_PKT_TOS 0x9 #define UDP_PKT_SIZE (IP_PKT_SIZE - sizeof(struct iphdr)) #define UDP_PKT_DATA_SIZE (UDP_PKT_SIZE - sizeof(struct udphdr)) -#define EOT (-1) #define USLEEP_MAX 10000 #define SOCK_RECONF_CTR 10 #define BATCH_SIZE 64 @@ -82,7 +81,6 @@ static u32 xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; static u32 xdp_bind_flags = XDP_USE_NEED_WAKEUP | XDP_COPY; static u8 pkt_data[XSK_UMEM__DEFAULT_FRAME_SIZE]; static u32 pkt_counter; -static long prev_pkt = -1; static int sigvar; static int stat_test_type; static u32 rxqsize; From patchwork Wed Aug 25 09:37:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456833 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B23AC432BE for ; Wed, 25 Aug 2021 09:38:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 422A361100 for ; Wed, 25 Aug 2021 09:38:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239775AbhHYJiy (ORCPT ); Wed, 25 Aug 2021 05:38:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239787AbhHYJis (ORCPT ); Wed, 25 Aug 2021 05:38:48 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A3F3C061796; Wed, 25 Aug 2021 02:38:03 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id g138so14540600wmg.4; Wed, 25 Aug 2021 02:38:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FkSX+q6lNV8RfsiU+JBNPDdX/Xw/Tk761bFEK2gJIzY=; b=Qwekri2ljCH4GOMRo/smmnCN4xyUvnGkO6m8v0epeGSOvIrGwaCNPzEou2axVj/eCc nssG+3VAocubf0AWbCcirqEiIpFVlTlXJ6Q96rGak5/1S9Gz47FH3byskLyqLomAu+/0 g8jgMFTMlH4yjpaXvPPaI7ob9ySjVREhPQC2QB8Qmeq9QlJSnyK3twPtY468K54FGNpG Aj7m2aK5XfS9jl8B1T9VygW+V1zeLvU5GEnpcpdYy7i5Rzrp1Nypi8s/lCr/RGJraLtj TwdBcvzCbvsiJb8CpfN8GJzDPLDow+6MWjZeLr/PpPGOk2xsw6J8WIHYVRL+OOYTsazS wXsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FkSX+q6lNV8RfsiU+JBNPDdX/Xw/Tk761bFEK2gJIzY=; b=oDTyQOWHkddqq7nONCqXjuO+4m3vHKugiB7nzLMaChA8YUZ+iwn+yvzVJMPPPHqxuk YSj/7Fl7boY7CrHuPasWhZV7RbFtWC+k5uHYEt7FNoU9bkLqCpcHPMcSxQpzNFf9NkR6 HAi0HUpC4OKkVM1Ic056lDJPl4Qy9j6l3dt8t0pO/q1vzn0YzCR4Bt/NdwBZR8Pmp1eS 3WXedan8+9Re63bRyaQkdXxd2rkte4A89zGFmkPX63/vhWsi9v9DumLfI2L4cpTtI66w 0agwmb299k42t32GS/+iHSAa59Rl/HPwW9LBnkQ2L/IrgKzdgFBnXlzH+sPGrXVa2ZtO d+JQ== X-Gm-Message-State: AOAM5310lYhDFPV0RhpirTwWBpMAVyFOtglIplmIOHUqlNTzG/cpRG1E cdCkWd4xrmAOK3KCqKiQZWs= X-Google-Smtp-Source: ABdhPJxMbLckaMtHxcUEBQNUgkMR3aXc/7Z1f3bnhRKpQM1xnQFFtS+fRwlUtSCQTBsm0qqf4E1nKw== X-Received: by 2002:a1c:2702:: with SMTP id n2mr8292096wmn.78.1629884281951; Wed, 25 Aug 2021 02:38:01 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.38.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:38:01 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 07/16] selftests: xsk: disassociate umem size with packets sent Date: Wed, 25 Aug 2021 11:37:13 +0200 Message-Id: <20210825093722.10219-8-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Disassociate the number of packets sent with the number of buffers in the umem. This so we can loop over the umem to test more things. Set the size of the umem to be a multiple of 2M. A requirement for huge pages that are needed in unaligned mode. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 18 ++++++++---------- tools/testing/selftests/bpf/xdpxceiver.h | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index b0fee71355bf..ebed88c13509 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -250,7 +250,7 @@ static void gen_eth_frame(struct xsk_umem_info *umem, u64 addr) memcpy(xsk_umem__get_data(umem->buffer, addr), pkt_data, PKT_SIZE); } -static void xsk_configure_umem(struct ifobject *data, void *buffer, int idx) +static void xsk_configure_umem(struct ifobject *data, void *buffer, u64 size, int idx) { struct xsk_umem_config cfg = { .fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS, @@ -259,7 +259,6 @@ static void xsk_configure_umem(struct ifobject *data, void *buffer, int idx) .frame_headroom = frame_headroom, .flags = XSK_UMEM__DEFAULT_FLAGS }; - int size = num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE; struct xsk_umem_info *umem; int ret; @@ -722,22 +721,23 @@ static void worker_pkt_validate(void) static void thread_common_ops(struct ifobject *ifobject, void *bufs) { - int umem_sz = num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE; + u64 umem_sz = num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE; + int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE; + size_t mmap_sz = umem_sz; int ctr = 0; int ret; ifobject->ns_fd = switch_namespace(ifobject->nsname); if (test_type == TEST_TYPE_BPF_RES) - umem_sz *= 2; + mmap_sz *= 2; - bufs = mmap(NULL, umem_sz, - PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + bufs = mmap(NULL, mmap_sz, PROT_READ | PROT_WRITE, mmap_flags, -1, 0); if (bufs == MAP_FAILED) exit_with_error(errno); while (ctr++ < SOCK_RECONF_CTR) { - xsk_configure_umem(ifobject, bufs, 0); + xsk_configure_umem(ifobject, bufs, umem_sz, 0); ifobject->umem = ifobject->umem_arr[0]; ret = xsk_configure_socket(ifobject, 0); if (!ret) @@ -753,7 +753,7 @@ static void thread_common_ops(struct ifobject *ifobject, void *bufs) ifobject->xsk = ifobject->xsk_arr[0]; if (test_type == TEST_TYPE_BPF_RES) { - xsk_configure_umem(ifobject, (u8 *)bufs + (umem_sz / 2), 1); + xsk_configure_umem(ifobject, (u8 *)bufs + umem_sz, umem_sz, 1); ifobject->umem = ifobject->umem_arr[1]; ret = xsk_configure_socket(ifobject, 1); } @@ -1094,8 +1094,6 @@ int main(int argc, char **argv) parse_command_line(argc, argv); - num_frames = ++opt_pkt_count; - init_iface(ifdict[0], MAC1, MAC2, IP1, IP2, UDP_PORT1, UDP_PORT2, tx); init_iface(ifdict[1], MAC2, MAC1, IP2, IP1, UDP_PORT2, UDP_PORT1, rx); diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index a4371d9e2798..131bd998e374 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -70,7 +70,7 @@ enum STAT_TEST_TYPES { static int configured_mode = TEST_MODE_UNCONFIGURED; static u8 debug_pkt_dump; -static u32 num_frames; +static u32 num_frames = DEFAULT_PKT_CNT / 4; static bool second_step; static int test_type; From patchwork Wed Aug 25 09:37:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456835 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E57CC4338F for ; Wed, 25 Aug 2021 09:38:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 168186112D for ; Wed, 25 Aug 2021 09:38:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239787AbhHYJi4 (ORCPT ); Wed, 25 Aug 2021 05:38:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239735AbhHYJix (ORCPT ); Wed, 25 Aug 2021 05:38:53 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDADDC0617AE; Wed, 25 Aug 2021 02:38:04 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id j14-20020a1c230e000000b002e748b9a48bso3310121wmj.0; Wed, 25 Aug 2021 02:38:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1xUet7aDAy2GCLrD/Oo0nVgpuM2fnYwVexflXHXXhyA=; b=CJ6WJkor/YwwTTQg0+FjDgnIpmRm9gBpTFa+SwT3BhltEfglweLv9YWUrq9qmAop8H aEv8G+I/3/mL9TwxbA3LXepc5B/zj4IjGoWs7YQjqU/h7pfA9kDM7GB0lXmYtK+FOOKc irMIAkTLBO53CXY8BQ8n4w8PGVayG/y8TaPr1K6+nLU7m0/U3PycbMQoqVQpwtiRNkla MRG7JyilqTWJD526Vr4b+1rxFS+GIdRGInvZP/b8mgJ1G32NjkYXweJpmig6Oa9r8TnS YmqHr9xwjpQSlzoZ8jQLa7LV08up/fGJkK9K3+bRUf7S8YK/41tTxQjJRXKSbcJNm6a1 crKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1xUet7aDAy2GCLrD/Oo0nVgpuM2fnYwVexflXHXXhyA=; b=T2LYtE1KOZre1C3lorFK3JDqqiVQTdb24IAynbJ+ZrUREh3Ditls90OI3DrNcJBXe9 tsr0PeGGh658V/fRkKuRDiikDAWwockgnaUQcdy64PB+BqXn0PZLiiwuBjJlV6ZnwejH 3EEjZgqJw10NKhvdV4tjRCRnT7R6igNet4m80Rcnn/cueER36pxrgM4QX6VKVQb8+hoD 6vJfyx91iTC4JV31C3ESx/6BxaxdcdXxtvpEiSQtGaI8WxOt/X1EQqCEc7EwiorTIKHy tEf8j5UKdjfT3PASa0wwRZHmrVEO5lFvsCkt41dJtH2eGdDgI8x/9IWGB+nI9p1IILe4 EvyA== X-Gm-Message-State: AOAM531er0ob2ZVesPag+d+d3yQcqxy06qjepFbluJNVQT6H5kPrc79K fxUVB6HzQs7260LuwH7VZck= X-Google-Smtp-Source: ABdhPJyn/VGNF68eu/7mEewrEX9hhQ4DHhF8+G3cMx0Ry5B9oHfMzGrmARAiLkpqvgswbzCTNzDftw== X-Received: by 2002:a7b:c447:: with SMTP id l7mr120253wmi.15.1629884283428; Wed, 25 Aug 2021 02:38:03 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.38.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:38:03 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 08/16] selftests: xsk: rename worker_* functions that are not thread entry points Date: Wed, 25 Aug 2021 11:37:14 +0200 Message-Id: <20210825093722.10219-9-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Rename worker_* functions that are not thread entry points to something else. This was confusing. Now only thread entry points are worker_something. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index ebed88c13509..17956fdeb49e 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -589,7 +589,7 @@ static void tx_only_all(struct ifobject *ifobject) complete_tx_only_all(ifobject); } -static void worker_pkt_dump(void) +static void pkt_dump(void) { struct ethhdr *ethhdr; struct iphdr *iphdr; @@ -631,7 +631,7 @@ static void worker_pkt_dump(void) } } -static void worker_stats_validate(struct ifobject *ifobject) +static void stats_validate(struct ifobject *ifobject) { struct xdp_statistics stats; socklen_t optlen; @@ -673,7 +673,7 @@ static void worker_stats_validate(struct ifobject *ifobject) } } -static void worker_pkt_validate(void) +static void pkt_validate(void) { u32 payloadseqnum = -2; struct iphdr *iphdr; @@ -833,9 +833,9 @@ static void *worker_testapp_validate_rx(void *arg) while (1) { if (test_type != TEST_TYPE_STATS) { rx_pkt(ifobject->xsk, fds); - worker_pkt_validate(); + pkt_validate(); } else { - worker_stats_validate(ifobject); + stats_validate(ifobject); } if (sigvar) break; @@ -873,7 +873,7 @@ static void testapp_validate(void) pthread_join(t0, NULL); if (debug_pkt_dump && test_type != TEST_TYPE_STATS) { - worker_pkt_dump(); + pkt_dump(); for (int iter = 0; iter < num_frames; iter++) { free(pkt_buf[iter]->payload); free(pkt_buf[iter]); From patchwork Wed Aug 25 09:37:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456837 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7D90C4320A for ; Wed, 25 Aug 2021 09:38:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BDA1061100 for ; Wed, 25 Aug 2021 09:38:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239718AbhHYJi5 (ORCPT ); Wed, 25 Aug 2021 05:38:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239773AbhHYJiy (ORCPT ); Wed, 25 Aug 2021 05:38:54 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 777B1C06129D; Wed, 25 Aug 2021 02:38:06 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 79-20020a1c0452000000b002e6cf79e572so3818338wme.1; Wed, 25 Aug 2021 02:38:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v2G7VaPISORqVkgrkmEmFicS9tj5hklL0AfR8I06gQY=; b=lTUrMf/0jwTezuirqs9uy60jEBgpDPkZyNnIXlLk9fJd753M/oW9gNxLpVZcptJw6/ K04KX1NhhqdX+kyPlVaHB/lH0VTQ50+H274L7nqSz0Eu3EDZ2Cc+kKmiqu/PRZReqnxs 9dO5y6UTPyHjHuInEzaJMCEMdNLDG3n/R5rzCeBkoslrLXB4jQpQtTwISB8wE6aHfhx4 MN8hEv8j2BJwzXWXsr/dv8rHKY+k80m9I/aGDYss/2Y6zgUdZdimt3DZQJWhpxNyvCxE sX8cu0YwfgLU/7hdWDE6mX4UvKs+lSNGxYTPD9vo7kNZL71DF7kiplDa1s56ebMtdwN2 xJyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v2G7VaPISORqVkgrkmEmFicS9tj5hklL0AfR8I06gQY=; b=ChxZ93tkFS/JAXPzRgp1sU3YjN18jrHjTrYBPYNbSDYojKin4sT5r07QgL0TMGs8FL 1TyzHZzH6MmkxxK85IQ+azT98Grph50ipnaGaUXIrxcpyIYmGWcPTrye8qW+8VIFz7Ki xnugCwrJDjAq45jzNivlUxkwspEFWg+3nok6chxdZfVkBJgVYLd6k5vz+3aaSp/nZhoX DKH2u6cfjFGkydggooA6f8CVbuMj40WO+gg5pZAnfnWB9UHdB6vc0S+bWl17OJbv/cOW Vo/0Ya4suuO8l+7MIUQrU6k3bW5kzNgzoZQZtU4V1If79juzcQDBiNZgwTsN/bc/5T4w IwLQ== X-Gm-Message-State: AOAM5330GcDmDT0D+nXonmPESUpbwsRnPx9E4IhBC+pLwcNGnhpi/Gfw qw2VKB+yd93iZZXR8aPV0vw= X-Google-Smtp-Source: ABdhPJymcnF+icvWaxHZuhchaCaThG0ipWr9L1GEpUminOOLdOg2qMFovi9Xyt02/5jEV/Qs399vWw== X-Received: by 2002:a1c:23d2:: with SMTP id j201mr8231403wmj.163.1629884285007; Wed, 25 Aug 2021 02:38:05 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.38.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:38:04 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 09/16] selftests: xsk: simplify packet validation in xsk tests Date: Wed, 25 Aug 2021 11:37:15 +0200 Message-Id: <20210825093722.10219-10-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Simplify packet validation in the xsk selftests by performing it at once for every packet. The current code performed this per batch and did this on copied packet data. Make it simpler and faster by validating it at once and on the umem packet data thus skipping the copy and the memory allocation for the temprary buffer. The optional packet dump feature is also simplified in the same manner. Memory allocation and copying is removed and the dump is performed directly on the umem data. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 182 ++++++++--------------- tools/testing/selftests/bpf/xdpxceiver.h | 14 -- 2 files changed, 65 insertions(+), 131 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 17956fdeb49e..fe3d281a0575 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -427,6 +427,70 @@ static void parse_command_line(int argc, char **argv) } } +static void pkt_dump(void *pkt, u32 len) +{ + char s[INET_ADDRSTRLEN]; + struct ethhdr *ethhdr; + struct udphdr *udphdr; + struct iphdr *iphdr; + int payload, i; + + ethhdr = pkt; + iphdr = pkt + sizeof(*ethhdr); + udphdr = pkt + sizeof(*ethhdr) + sizeof(*iphdr); + + /*extract L2 frame */ + fprintf(stdout, "DEBUG>> L2: dst mac: "); + for (i = 0; i < ETH_ALEN; i++) + fprintf(stdout, "%02X", ethhdr->h_dest[i]); + + fprintf(stdout, "\nDEBUG>> L2: src mac: "); + for (i = 0; i < ETH_ALEN; i++) + fprintf(stdout, "%02X", ethhdr->h_source[i]); + + /*extract L3 frame */ + fprintf(stdout, "\nDEBUG>> L3: ip_hdr->ihl: %02X\n", iphdr->ihl); + fprintf(stdout, "DEBUG>> L3: ip_hdr->saddr: %s\n", + inet_ntop(AF_INET, &iphdr->saddr, s, sizeof(s))); + fprintf(stdout, "DEBUG>> L3: ip_hdr->daddr: %s\n", + inet_ntop(AF_INET, &iphdr->daddr, s, sizeof(s))); + /*extract L4 frame */ + fprintf(stdout, "DEBUG>> L4: udp_hdr->src: %d\n", ntohs(udphdr->source)); + fprintf(stdout, "DEBUG>> L4: udp_hdr->dst: %d\n", ntohs(udphdr->dest)); + /*extract L5 frame */ + payload = *((uint32_t *)(pkt + PKT_HDR_SIZE)); + + fprintf(stdout, "DEBUG>> L5: payload: %d\n", payload); + fprintf(stdout, "---------------------------------------\n"); +} + +static void pkt_validate(void *pkt) +{ + struct iphdr *iphdr = (struct iphdr *)(pkt + sizeof(struct ethhdr)); + + /*do not increment pktcounter if !(tos=0x9 and ipv4) */ + if (iphdr->version == IP_PKT_VER && iphdr->tos == IP_PKT_TOS) { + u32 payloadseqnum = *((uint32_t *)(pkt + PKT_HDR_SIZE)); + + if (debug_pkt_dump && test_type != TEST_TYPE_STATS) + pkt_dump(pkt, PKT_SIZE); + + if (pkt_counter % num_frames != payloadseqnum) { + ksft_test_result_fail + ("ERROR: [%s] expected seqnum [%d], got seqnum [%d]\n", + __func__, pkt_counter, payloadseqnum); + ksft_exit_xfail(); + } + + if (++pkt_counter == opt_pkt_count) + sigvar = 1; + } else { + ksft_print_msg("Invalid frame received: "); + ksft_print_msg("[IP_PKT_VER: %02X], [IP_PKT_TOS: %02X]\n", iphdr->version, + iphdr->tos); + } +} + static void kick_tx(struct xsk_socket_info *xsk) { int ret; @@ -491,18 +555,7 @@ static void rx_pkt(struct xsk_socket_info *xsk, struct pollfd *fds) orig = xsk_umem__extract_addr(addr); addr = xsk_umem__add_offset_to_addr(addr); - pkt_node_rx = malloc(sizeof(struct pkt) + PKT_SIZE); - if (!pkt_node_rx) - exit_with_error(errno); - - pkt_node_rx->pkt_frame = malloc(PKT_SIZE); - if (!pkt_node_rx->pkt_frame) - exit_with_error(errno); - - memcpy(pkt_node_rx->pkt_frame, xsk_umem__get_data(xsk->umem->buffer, addr), - PKT_SIZE); - - TAILQ_INSERT_HEAD(&head, pkt_node_rx, pkt_nodes); + pkt_validate(xsk_umem__get_data(xsk->umem->buffer, addr)); *xsk_ring_prod__fill_addr(&xsk->umem->fq, idx_fq++) = orig; } @@ -589,48 +642,6 @@ static void tx_only_all(struct ifobject *ifobject) complete_tx_only_all(ifobject); } -static void pkt_dump(void) -{ - struct ethhdr *ethhdr; - struct iphdr *iphdr; - struct udphdr *udphdr; - char s[128]; - int payload; - void *ptr; - - fprintf(stdout, "---------------------------------------\n"); - for (int iter = 0; iter < num_frames; iter++) { - ptr = pkt_buf[iter]->payload; - ethhdr = ptr; - iphdr = ptr + sizeof(*ethhdr); - udphdr = ptr + sizeof(*ethhdr) + sizeof(*iphdr); - - /*extract L2 frame */ - fprintf(stdout, "DEBUG>> L2: dst mac: "); - for (int i = 0; i < ETH_ALEN; i++) - fprintf(stdout, "%02X", ethhdr->h_dest[i]); - - fprintf(stdout, "\nDEBUG>> L2: src mac: "); - for (int i = 0; i < ETH_ALEN; i++) - fprintf(stdout, "%02X", ethhdr->h_source[i]); - - /*extract L3 frame */ - fprintf(stdout, "\nDEBUG>> L3: ip_hdr->ihl: %02X\n", iphdr->ihl); - fprintf(stdout, "DEBUG>> L3: ip_hdr->saddr: %s\n", - inet_ntop(AF_INET, &iphdr->saddr, s, sizeof(s))); - fprintf(stdout, "DEBUG>> L3: ip_hdr->daddr: %s\n", - inet_ntop(AF_INET, &iphdr->daddr, s, sizeof(s))); - /*extract L4 frame */ - fprintf(stdout, "DEBUG>> L4: udp_hdr->src: %d\n", ntohs(udphdr->source)); - fprintf(stdout, "DEBUG>> L4: udp_hdr->dst: %d\n", ntohs(udphdr->dest)); - /*extract L5 frame */ - payload = *((uint32_t *)(ptr + PKT_HDR_SIZE)); - - fprintf(stdout, "DEBUG>> L5: payload: %d\n", payload); - fprintf(stdout, "---------------------------------------\n"); - } -} - static void stats_validate(struct ifobject *ifobject) { struct xdp_statistics stats; @@ -673,52 +684,6 @@ static void stats_validate(struct ifobject *ifobject) } } -static void pkt_validate(void) -{ - u32 payloadseqnum = -2; - struct iphdr *iphdr; - - while (1) { - pkt_node_rx_q = TAILQ_LAST(&head, head_s); - if (!pkt_node_rx_q) - break; - - iphdr = (struct iphdr *)(pkt_node_rx_q->pkt_frame + sizeof(struct ethhdr)); - - /*do not increment pktcounter if !(tos=0x9 and ipv4) */ - if (iphdr->version == IP_PKT_VER && iphdr->tos == IP_PKT_TOS) { - payloadseqnum = *((uint32_t *)(pkt_node_rx_q->pkt_frame + PKT_HDR_SIZE)); - if (debug_pkt_dump) { - pkt_obj = malloc(sizeof(*pkt_obj)); - pkt_obj->payload = malloc(PKT_SIZE); - memcpy(pkt_obj->payload, pkt_node_rx_q->pkt_frame, PKT_SIZE); - pkt_buf[payloadseqnum] = pkt_obj; - } - - if (pkt_counter % num_frames != payloadseqnum) { - ksft_test_result_fail - ("ERROR: [%s] expected counter [%d], payloadseqnum [%d]\n", - __func__, pkt_counter, payloadseqnum); - ksft_exit_xfail(); - } - - if (++pkt_counter == opt_pkt_count) { - sigvar = 1; - break; - } - } else { - ksft_print_msg("Invalid frame received: "); - ksft_print_msg("[IP_PKT_VER: %02X], [IP_PKT_TOS: %02X]\n", iphdr->version, - iphdr->tos); - } - - TAILQ_REMOVE(&head, pkt_node_rx_q, pkt_nodes); - free(pkt_node_rx_q->pkt_frame); - free(pkt_node_rx_q); - pkt_node_rx_q = NULL; - } -} - static void thread_common_ops(struct ifobject *ifobject, void *bufs) { u64 umem_sz = num_frames * XSK_UMEM__DEFAULT_FRAME_SIZE; @@ -818,13 +783,6 @@ static void *worker_testapp_validate_rx(void *arg) if (stat_test_type != STAT_TEST_RX_FILL_EMPTY) xsk_populate_fill_ring(ifobject->umem); - TAILQ_INIT(&head); - if (debug_pkt_dump) { - pkt_buf = calloc(num_frames, sizeof(*pkt_buf)); - if (!pkt_buf) - exit_with_error(errno); - } - fds[0].fd = xsk_socket__fd(ifobject->xsk->xsk); fds[0].events = POLLIN; @@ -833,7 +791,6 @@ static void *worker_testapp_validate_rx(void *arg) while (1) { if (test_type != TEST_TYPE_STATS) { rx_pkt(ifobject->xsk, fds); - pkt_validate(); } else { stats_validate(ifobject); } @@ -872,15 +829,6 @@ static void testapp_validate(void) pthread_join(t1, NULL); pthread_join(t0, NULL); - if (debug_pkt_dump && test_type != TEST_TYPE_STATS) { - pkt_dump(); - for (int iter = 0; iter < num_frames; iter++) { - free(pkt_buf[iter]->payload); - free(pkt_buf[iter]); - } - free(pkt_buf); - } - if (!(test_type == TEST_TYPE_TEARDOWN) && !bidi && !bpf && !(test_type == TEST_TYPE_STATS)) print_ksft_result(); } diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 131bd998e374..0fb657b505ae 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -139,18 +139,4 @@ static struct ifobject *ifdict_tx; pthread_barrier_t barr; pthread_t t0, t1; -TAILQ_HEAD(head_s, pkt) head = TAILQ_HEAD_INITIALIZER(head); -struct head_s *head_p; -struct pkt { - char *pkt_frame; - - TAILQ_ENTRY(pkt) pkt_nodes; -} *pkt_node_rx, *pkt_node_rx_q; - -struct pkt_frame { - char *payload; -} *pkt_obj; - -struct pkt_frame **pkt_buf; - #endif /* XDPXCEIVER_H */ From patchwork Wed Aug 25 09:37:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456839 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C9EEC432BE for ; Wed, 25 Aug 2021 09:38:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 464C66115A for ; Wed, 25 Aug 2021 09:38:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239760AbhHYJi6 (ORCPT ); Wed, 25 Aug 2021 05:38:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239840AbhHYJiz (ORCPT ); Wed, 25 Aug 2021 05:38:55 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E886FC06129E; Wed, 25 Aug 2021 02:38:07 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id 79-20020a1c0452000000b002e6cf79e572so3818385wme.1; Wed, 25 Aug 2021 02:38:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FkJ6l/1JcnDsZ1+j4Ei1va5lDdBESZYy8Ogo4L7H+ew=; b=D50PUZQr9xjQW+vSdPF3qIh8SrofbvQLqaR0P0sWlMutvfYYFN+mOpgzf6E4ovFam4 O5RyrHxXP3oNpjC9cAfS6IcDF7KD4pohfxhMp3miYRJv2FzHMiZgIzMGjXTXqJl8jRhn Uzkiz9Tw35wvZFuD3Jq7y9KNaCBg6Br6AuzZPMpeg9TujBlAOB2kIR4QFsOG/XQHzY6X eW/tIx3H7QsZBEoE2K4r+EmA1oWSGpPh5psy54XohHSOsB+EPWhAVGjAm7X46joPS6aX SAQNM5kxyRThw3gUWRxSZpZ/WdeZvdu3YeFHYv7EKRg6RdsvysmN4zX9jS/op+86iLeW YrIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FkJ6l/1JcnDsZ1+j4Ei1va5lDdBESZYy8Ogo4L7H+ew=; b=iJ987Kgu9gbXNiAGzW/PPHn7HSU/8kJn/vTSCoGIUW+mxJdyJCy/NAeXyqiRhxYlxr i8qppzpyQv0gYCOV5HRx4d1YTvXxs91Yz6eYkC2FdBuaWKM+ZGpTKxpJcXQq+dp53KqX 8T5DLapyVUhdIFju6SHEgIHgjM1y68t4K+re3RyvXX86/53twaKP2yhSO34jpQhwpG0h voPO56g5nlMOJCBGSRt3cWHP3lY2VdBBq/dlmt5BjhBcnq964m8XvdQ1YdL0SZWamwaF wjxusNladTeB+8odebZN2kP7RHt/DgwpFCocOLntjDdZR9XNVGCPCLEl1JaVItDbXCvA hthg== X-Gm-Message-State: AOAM533OH1irertCIV/Gs0Y/HTNpSzEh9ecgSviI8vD+l3CjC71wQFAG UZrD6C71sE8xKwV7NYYasR4= X-Google-Smtp-Source: ABdhPJz9WLs7JI/Y3G04g7mVh8j/2GNNwqxwhzIs92IUVlWj078q9w8ze+U+hD2kvpXbNSFeL67XMA== X-Received: by 2002:a05:600c:2058:: with SMTP id p24mr5180584wmg.108.1629884286532; Wed, 25 Aug 2021 02:38:06 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.38.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:38:06 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 10/16] selftests: xsk: validate tx stats on tx thread Date: Wed, 25 Aug 2021 11:37:16 +0200 Message-Id: <20210825093722.10219-11-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Validate the tx stats on the Tx thread instead of the Rx tread. Depending on your settings, you might not be allowed to query the statistics of a socket you do not own, so better to do this on the correct thread to start with. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 55 ++++++++++++++++++------ 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index fe3d281a0575..8ff24472ef1e 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -642,23 +642,22 @@ static void tx_only_all(struct ifobject *ifobject) complete_tx_only_all(ifobject); } -static void stats_validate(struct ifobject *ifobject) +static bool rx_stats_are_valid(struct ifobject *ifobject) { + u32 xsk_stat = 0, expected_stat = opt_pkt_count; + struct xsk_socket *xsk = ifobject->xsk->xsk; + int fd = xsk_socket__fd(xsk); struct xdp_statistics stats; socklen_t optlen; int err; - struct xsk_socket *xsk = stat_test_type == STAT_TEST_TX_INVALID ? - ifdict[!ifobject->ifdict_index]->xsk->xsk : - ifobject->xsk->xsk; - int fd = xsk_socket__fd(xsk); - unsigned long xsk_stat = 0, expected_stat = opt_pkt_count; - - sigvar = 0; optlen = sizeof(stats); err = getsockopt(fd, SOL_XDP, XDP_STATISTICS, &stats, &optlen); - if (err) - return; + if (err) { + ksft_test_result_fail("ERROR: [%s] getsockopt(XDP_STATISTICS) error %u %s\n", + __func__, -err, strerror(-err)); + return true; + } if (optlen == sizeof(struct xdp_statistics)) { switch (stat_test_type) { @@ -666,8 +665,7 @@ static void stats_validate(struct ifobject *ifobject) xsk_stat = stats.rx_dropped; break; case STAT_TEST_TX_INVALID: - xsk_stat = stats.tx_invalid_descs; - break; + return true; case STAT_TEST_RX_FULL: xsk_stat = stats.rx_ring_full; expected_stat -= RX_FULL_RXQSIZE; @@ -680,8 +678,33 @@ static void stats_validate(struct ifobject *ifobject) } if (xsk_stat == expected_stat) - sigvar = 1; + return true; + } + + return false; +} + +static void tx_stats_validate(struct ifobject *ifobject) +{ + struct xsk_socket *xsk = ifobject->xsk->xsk; + int fd = xsk_socket__fd(xsk); + struct xdp_statistics stats; + socklen_t optlen; + int err; + + optlen = sizeof(stats); + err = getsockopt(fd, SOL_XDP, XDP_STATISTICS, &stats, &optlen); + if (err) { + ksft_test_result_fail("ERROR: [%s] getsockopt(XDP_STATISTICS) error %u %s\n", + __func__, -err, strerror(-err)); + return; } + + if (stats.tx_invalid_descs == opt_pkt_count) + return; + + ksft_test_result_fail("ERROR: [%s] tx_invalid_descs incorrect. Got [%u] expected [%u]\n", + __func__, stats.tx_invalid_descs, opt_pkt_count); } static void thread_common_ops(struct ifobject *ifobject, void *bufs) @@ -767,6 +790,9 @@ static void *worker_testapp_validate_tx(void *arg) print_verbose("Sending %d packets on interface %s\n", opt_pkt_count, ifobject->ifname); tx_only_all(ifobject); + if (stat_test_type == STAT_TEST_TX_INVALID) + tx_stats_validate(ifobject); + testapp_cleanup_xsk_res(ifobject); pthread_exit(NULL); } @@ -792,7 +818,8 @@ static void *worker_testapp_validate_rx(void *arg) if (test_type != TEST_TYPE_STATS) { rx_pkt(ifobject->xsk, fds); } else { - stats_validate(ifobject); + if (rx_stats_are_valid(ifobject)) + break; } if (sigvar) break; From patchwork Wed Aug 25 09:37:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456843 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D86AC432BE for ; Wed, 25 Aug 2021 09:38:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB3BB6112D for ; Wed, 25 Aug 2021 09:38:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239862AbhHYJjB (ORCPT ); Wed, 25 Aug 2021 05:39:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239845AbhHYJiz (ORCPT ); Wed, 25 Aug 2021 05:38:55 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61BEBC0613CF; Wed, 25 Aug 2021 02:38:09 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id d26so15074515wrc.0; Wed, 25 Aug 2021 02:38:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wmeoMz7zyWlaplotPTP1bJSPa6W8At1MPBr8WrlXXNw=; b=n9HgJx0xRdZTX7M0k1qicRaRayKoKGI9pzuGReEgIwnb6Y3kzKKJAYo8p+Pgst55iQ Ss0+f3/6fGRxxZnmGeGf6stCRBZJEr9jRBdsiHjCMt654QqHPp6MVvguREMTZsldLqmn fTDf45C9PPS7aKHVFgtLjhMWPH/CwatwId1nvopYhKTUTx73nOzfdjQ67jrwX9M79Xl/ 8BTlGesqGvqKiQM33etp5dyvlAGHiUU4V3SN6oyR7EAc+ld6boA98GqptBTHSq5/+ItR gj8gDiVLXmjQ8BaiUp8SDNz3ijskKtz9mQaqZmXEY8xFu0oixCk67Zde5SA91p8UFz+i USSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wmeoMz7zyWlaplotPTP1bJSPa6W8At1MPBr8WrlXXNw=; b=KUr4wE7SBujcJmX0A3Dqt5ccF9iIzZcKFQAEa6A8VqZtsMV9W4QZxuHlKwt/IfnIQn zFVuK86WfpyfIa19gVZ+Br5+o/6K+yObYe/ae4cmt5qqFKLNoJ3EnkYoPB6vmemLre6I clNJsKff6ZTtkuM+9DXS89/ahv+uf0UuyZ0wIiqcBG1XLrlsdahGDppuLjltad/1AHg3 i4DrEnk3G7qNrF3qM7QUSlLtVDRrnqSpiDeZSjUz89NcEilO+89JFNQoY4sO2ncs9Ifj kFHeipn4kHI3+Z1Y4hm/tZurunZO6v8psxcHvm2Vr3Ij3pYS2JQW7iE2gwbM33wygOFL //4Q== X-Gm-Message-State: AOAM530Klg07Zx/+F8WsCU/J4aiWKtmK8EggCoZ9vn7tYeO8vZpd92xl 5W/+GCiBngsRtVkbJEKQAu4= X-Google-Smtp-Source: ABdhPJwGZKwRcDejUYwQrMSIJw/uOXSrqWjN1cjNuvooxLLN8R2nwpZCdlhW8NC9lboZ/i3h7VmxsQ== X-Received: by 2002:adf:fb44:: with SMTP id c4mr23630744wrs.179.1629884288036; Wed, 25 Aug 2021 02:38:08 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.38.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:38:07 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 11/16] selftests: xsk: decrease sending speed Date: Wed, 25 Aug 2021 11:37:17 +0200 Message-Id: <20210825093722.10219-12-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Decrease sending speed to avoid potentially overflowing some buffers in the skb case that leads to dropped packets we cannot control (and thus the tests may generate false negatives). Decrease batch size and introduce a usleep in the transmit thread to not overflow the receiver. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 1 + tools/testing/selftests/bpf/xdpxceiver.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 8ff24472ef1e..bc7d6bbbb867 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -637,6 +637,7 @@ static void tx_only_all(struct ifobject *ifobject) tx_only(ifobject->xsk, &frame_nb, batch_size); pkt_cnt += batch_size; + usleep(10); } complete_tx_only_all(ifobject); diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 0fb657b505ae..1c5457e9f1d6 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -36,7 +36,7 @@ #define UDP_PKT_DATA_SIZE (UDP_PKT_SIZE - sizeof(struct udphdr)) #define USLEEP_MAX 10000 #define SOCK_RECONF_CTR 10 -#define BATCH_SIZE 64 +#define BATCH_SIZE 8 #define POLL_TMOUT 1000 #define DEFAULT_PKT_CNT (4 * 1024) #define RX_FULL_RXQSIZE 32 From patchwork Wed Aug 25 09:37:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456841 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0260BC4320E for ; Wed, 25 Aug 2021 09:38:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD4A76115A for ; Wed, 25 Aug 2021 09:38:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239803AbhHYJjA (ORCPT ); Wed, 25 Aug 2021 05:39:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239807AbhHYJi4 (ORCPT ); Wed, 25 Aug 2021 05:38:56 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF1E6C0617A8; Wed, 25 Aug 2021 02:38:10 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id u9so501079wrg.8; Wed, 25 Aug 2021 02:38:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o2fnNDxyYpKyxamB+m0HKg46XLLE6g1mX0MO5afICgk=; b=dWoprSC1KJMwtf+M4WH8Bzr8pR0D1tvBccge1I9zj9f0DdbbIZtVgt7hTumKUfcCzD bXMnMn27tL8l/yhxSxJLhk5QNJW+odKX5uZYxpiLcejrLidDY8AN4vUvg7FELbHDfNBD 065uTeWsE+DaBGaBSdk7QEVLQHycbvozgN7RKCVETTyeK/aUHGzu8XRedkL0/T367DIv qHenmsG3qMbKxIksOlO7hXLOM8F7R+T6unzFYsfDZwSJRWRZ1W1Xt0KagUd77wv5THmZ CJtETPolcXk85K7yy1ZlEpvGKwzGOWOP5grbls6iDxJrv3lexHVXWU1SQH60k4JMxZyd rszw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o2fnNDxyYpKyxamB+m0HKg46XLLE6g1mX0MO5afICgk=; b=qwpZ3B7HoC/AL2ooSqmcpYD3+547jYqpewtaEdNebfvsLEuUjEFwzZVrOd+k98wKFg 3u4ZAGnAhJHQKKKVQIYOyVRj5+QZPRn1Yl151e2ghSf92u0We/PnaRow3mKEPjPRsabY gOjlCNwv2qD10n3qnKQfjXExQlrEPE9nL8cOFSb2YsF520wC7Eb4zDZOd9I08FwqJy+/ 2e+3WAQGUC3OMZduZb7EujaGjfuTubehohu88w8TfvIfc5xX+sj5iucHJEiV21WVRYf9 15TgHDYjLUj/UP8Ii8pUK+1Qt+JutEnQMDwMhVeCJcdMyee38m6Xyf80ypY0wAkzwe4m issQ== X-Gm-Message-State: AOAM532PygEgGBWUWPKq2XRQpN1tJ+wSZeOl3G6POJ/C44rUGCU31ATV k7/xup76RZyY41OXF3VSwsl1NlFjRZPcdIrYfoDDXQ== X-Google-Smtp-Source: ABdhPJw7/IdZRVMMQ5dF6rMH6vZzzxgULGhPUyOIXOaHZkH1uDs784GdXr6N8QqTCpoP8lW4K5WtKQ== X-Received: by 2002:adf:eb4c:: with SMTP id u12mr25028854wrn.111.1629884289456; Wed, 25 Aug 2021 02:38:09 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.38.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:38:09 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 12/16] selftests: xsk: simplify cleanup of ifobjects Date: Wed, 25 Aug 2021 11:37:18 +0200 Message-Id: <20210825093722.10219-13-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Simpify the cleanup of ifobjects right before the program exits by introducing functions for creating and destroying these objects. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 72 +++++++++++++----------- tools/testing/selftests/bpf/xdpxceiver.h | 1 - 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index bc7d6bbbb867..5e586a696742 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -1039,62 +1039,70 @@ static void run_pkt_test(int mode, int type) } } +static struct ifobject *ifobject_create(void) +{ + struct ifobject *ifobj; + + ifobj = calloc(1, sizeof(struct ifobject)); + if (!ifobj) + return NULL; + + ifobj->xsk_arr = calloc(2, sizeof(struct xsk_socket_info *)); + if (!ifobj->xsk_arr) + goto out_xsk_arr; + + ifobj->umem_arr = calloc(2, sizeof(struct xsk_umem_info *)); + if (!ifobj->umem_arr) + goto out_umem_arr; + + return ifobj; + +out_umem_arr: + free(ifobj->xsk_arr); +out_xsk_arr: + free(ifobj); + return NULL; +} + +static void ifobject_delete(struct ifobject *ifobj) +{ + free(ifobj->umem_arr); + free(ifobj->xsk_arr); + free(ifobj); +} + int main(int argc, char **argv) { struct rlimit _rlim = { RLIM_INFINITY, RLIM_INFINITY }; - bool failure = false; int i, j; if (setrlimit(RLIMIT_MEMLOCK, &_rlim)) exit_with_error(errno); - for (int i = 0; i < MAX_INTERFACES; i++) { - ifdict[i] = malloc(sizeof(struct ifobject)); + for (i = 0; i < MAX_INTERFACES; i++) { + ifdict[i] = ifobject_create(); if (!ifdict[i]) - exit_with_error(errno); - - ifdict[i]->ifdict_index = i; - ifdict[i]->xsk_arr = calloc(2, sizeof(struct xsk_socket_info *)); - if (!ifdict[i]->xsk_arr) { - failure = true; - goto cleanup; - } - ifdict[i]->umem_arr = calloc(2, sizeof(struct xsk_umem_info *)); - if (!ifdict[i]->umem_arr) { - failure = true; - goto cleanup; - } + exit_with_error(ENOMEM); } setlocale(LC_ALL, ""); parse_command_line(argc, argv); - init_iface(ifdict[0], MAC1, MAC2, IP1, IP2, UDP_PORT1, UDP_PORT2, tx); - init_iface(ifdict[1], MAC2, MAC1, IP2, IP1, UDP_PORT2, UDP_PORT1, rx); + init_iface(ifdict[tx], MAC1, MAC2, IP1, IP2, UDP_PORT1, UDP_PORT2, tx); + init_iface(ifdict[rx], MAC2, MAC1, IP2, IP1, UDP_PORT2, UDP_PORT1, rx); ksft_set_plan(TEST_MODE_MAX * TEST_TYPE_MAX); - for (i = 0; i < TEST_MODE_MAX; i++) { + for (i = 0; i < TEST_MODE_MAX; i++) for (j = 0; j < TEST_TYPE_MAX; j++) { run_pkt_test(i, j); usleep(USLEEP_MAX); } - } -cleanup: - for (int i = 0; i < MAX_INTERFACES; i++) { - if (ifdict[i]->ns_fd != -1) - close(ifdict[i]->ns_fd); - free(ifdict[i]->xsk_arr); - free(ifdict[i]->umem_arr); - free(ifdict[i]); - } - - if (failure) - exit_with_error(errno); + for (i = 0; i < MAX_INTERFACES; i++) + ifobject_delete(ifdict[i]); ksft_exit_pass(); - return 0; } diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 1c5457e9f1d6..316c3565a99e 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -122,7 +122,6 @@ struct ifobject { void *(*func_ptr)(void *arg); struct flow_vector fv; int ns_fd; - int ifdict_index; u32 dst_ip; u32 src_ip; u16 src_port; From patchwork Wed Aug 25 09:37:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456845 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EDADC4320E for ; Wed, 25 Aug 2021 09:38:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1CDD26112D for ; Wed, 25 Aug 2021 09:38:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239820AbhHYJjL (ORCPT ); Wed, 25 Aug 2021 05:39:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239857AbhHYJi6 (ORCPT ); Wed, 25 Aug 2021 05:38:58 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65F26C061757; Wed, 25 Aug 2021 02:38:12 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id h13so35469538wrp.1; Wed, 25 Aug 2021 02:38:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+bDtCcmlNOG2a+6jxB/3zKz9WLjTMBXSlVLPtW6tIBk=; b=T06VNODLBGN0w8gQblmxp8BVFBuZbZJCoxY6ifLVRiT+Aj8KojIs2hd+2H8/V5NBHV l0NH20qFyezfRchKCjEaluuLqZ5DVeg4+gdm/tOk/2HMU/AT2f+bgXA4tGETdJJAqoGJ 1Cy8y/37Ddats/V5cJTz+wIyJ+R0Cn8LfRjTBL6tGLJFXHOzKjuzsFxj4mVzbi36dh6A OatBwCHuzT8m64EW7e6fMM1ZDEBG1ofxe1LE7AQ++U1amUsDvlhZes5mqDC77BZ2jNBk ypU/s4JssFFGIi50Vm2Qfd1tRdYnicS0uKulUd3HCcYi8UBPQVpHl8gQL8Wtl+008dVF kwaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+bDtCcmlNOG2a+6jxB/3zKz9WLjTMBXSlVLPtW6tIBk=; b=LtJxy2BuuQp8Vl0Oix2pWM/EqatIkThEhXLShntaCf9B00UAX7oufGj0sRrSk2oPq6 7sk/F4YdEPF6h0y77wqr+WhVor81Mx55mJRQgCsBsxrjc9qf0b61QhoVyG0Rn6Ba0kz7 a0TUPzlN7mlw36k+T2XTuRdUS7LRTffwXJtmllnLfpJ35/iEFFCFe7Qeb5GthRVItqpB 8qbL1w59aQXTUGyW+C0Q2S7qe7V/LM2kHhb00ArIicW/jrV4aq4UnKBsBHVVq30n91Fz rMpBUKmuOisxtn9vL0zspnw56jhnm17++5cKsxtxvGpJiyZu0RvlF/EGVtZBuqnF0WGk 6opQ== X-Gm-Message-State: AOAM531WsiWEIo90xlWbZf585XwajcxknO1a/8Urjlp2mePjVW4hzbGX YUOgRLtJsL7u9EnKSMyIrik= X-Google-Smtp-Source: ABdhPJyx8RZ3XHijMIOZt1UN3iCz/fnPfSNRXU3ThC1O5XIGldT3GP7mHlL89kVxgoeqpPTCeAb6LQ== X-Received: by 2002:a05:6000:120d:: with SMTP id e13mr24392690wrx.6.1629884290967; Wed, 25 Aug 2021 02:38:10 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.38.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:38:10 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 13/16] selftests: xsk: generate packet directly in umem Date: Wed, 25 Aug 2021 11:37:19 +0200 Message-Id: <20210825093722.10219-14-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Generate the packet directly in the umem instead of in a temporary buffer that is copied out. Simplifies the code and improves performance. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 70 +++++++++++------------- tools/testing/selftests/bpf/xdpxceiver.h | 5 -- 2 files changed, 32 insertions(+), 43 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 5e586a696742..433c5c7b1928 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -125,7 +125,7 @@ static void __exit_with_error(int error, const char *file, const char *func, int test_type == TEST_TYPE_STATS ? "Stats" : "",\ test_type == TEST_TYPE_BPF_RES ? "BPF RES" : "")) -static void *memset32_htonl(void *dest, u32 val, u32 size) +static void memset32_htonl(void *dest, u32 val, u32 size) { u32 *ptr = (u32 *)dest; int i; @@ -134,11 +134,6 @@ static void *memset32_htonl(void *dest, u32 val, u32 size) for (i = 0; i < (size & (~0x3)); i += 4) ptr[i >> 2] = val; - - for (; i < size; i++) - ((char *)dest)[i] = ((char *)&val)[i & 3]; - - return dest; } /* @@ -229,13 +224,13 @@ static void gen_ip_hdr(struct ifobject *ifobject, struct iphdr *ip_hdr) ip_hdr->check = 0; } -static void gen_udp_hdr(struct generic_data *data, struct ifobject *ifobject, +static void gen_udp_hdr(u32 payload, void *pkt, struct ifobject *ifobject, struct udphdr *udp_hdr) { udp_hdr->source = htons(ifobject->src_port); udp_hdr->dest = htons(ifobject->dst_port); udp_hdr->len = htons(UDP_PKT_SIZE); - memset32_htonl(pkt_data + PKT_HDR_SIZE, htonl(data->seqnum), UDP_PKT_DATA_SIZE); + memset32_htonl(pkt + PKT_HDR_SIZE, payload, UDP_PKT_DATA_SIZE); } static void gen_udp_csum(struct udphdr *udp_hdr, struct iphdr *ip_hdr) @@ -245,11 +240,6 @@ static void gen_udp_csum(struct udphdr *udp_hdr, struct iphdr *ip_hdr) udp_csum(ip_hdr->saddr, ip_hdr->daddr, UDP_PKT_SIZE, IPPROTO_UDP, (u16 *)udp_hdr); } -static void gen_eth_frame(struct xsk_umem_info *umem, u64 addr) -{ - memcpy(xsk_umem__get_data(umem->buffer, addr), pkt_data, PKT_SIZE); -} - static void xsk_configure_umem(struct ifobject *data, void *buffer, u64 size, int idx) { struct xsk_umem_config cfg = { @@ -427,6 +417,20 @@ static void parse_command_line(int argc, char **argv) } } +static void pkt_generate(struct ifobject *ifobject, u32 pkt_nb, u64 addr) +{ + void *data = xsk_umem__get_data(ifobject->umem->buffer, addr); + struct udphdr *udp_hdr = + (struct udphdr *)(data + sizeof(struct ethhdr) + sizeof(struct iphdr)); + struct iphdr *ip_hdr = (struct iphdr *)(data + sizeof(struct ethhdr)); + struct ethhdr *eth_hdr = (struct ethhdr *)data; + + gen_udp_hdr(pkt_nb, data, ifobject, udp_hdr); + gen_ip_hdr(ifobject, ip_hdr); + gen_udp_csum(udp_hdr, ip_hdr); + gen_eth_hdr(ifobject, eth_hdr); +} + static void pkt_dump(void *pkt, u32 len) { char s[INET_ADDRSTRLEN]; @@ -464,22 +468,23 @@ static void pkt_dump(void *pkt, u32 len) fprintf(stdout, "---------------------------------------\n"); } -static void pkt_validate(void *pkt) +static void pkt_validate(void *buffer, u64 addr) { - struct iphdr *iphdr = (struct iphdr *)(pkt + sizeof(struct ethhdr)); + void *data = xsk_umem__get_data(buffer, addr); + struct iphdr *iphdr = (struct iphdr *)(data + sizeof(struct ethhdr)); - /*do not increment pktcounter if !(tos=0x9 and ipv4) */ if (iphdr->version == IP_PKT_VER && iphdr->tos == IP_PKT_TOS) { - u32 payloadseqnum = *((uint32_t *)(pkt + PKT_HDR_SIZE)); + u32 seqnum = ntohl(*((u32 *)(data + PKT_HDR_SIZE))); + u32 expected_seqnum = pkt_counter % num_frames; if (debug_pkt_dump && test_type != TEST_TYPE_STATS) - pkt_dump(pkt, PKT_SIZE); + pkt_dump(data, PKT_SIZE); - if (pkt_counter % num_frames != payloadseqnum) { + if (expected_seqnum != seqnum) { ksft_test_result_fail ("ERROR: [%s] expected seqnum [%d], got seqnum [%d]\n", - __func__, pkt_counter, payloadseqnum); - ksft_exit_xfail(); + __func__, expected_seqnum, seqnum); + sigvar = 1; } if (++pkt_counter == opt_pkt_count) @@ -488,6 +493,7 @@ static void pkt_validate(void *pkt) ksft_print_msg("Invalid frame received: "); ksft_print_msg("[IP_PKT_VER: %02X], [IP_PKT_TOS: %02X]\n", iphdr->version, iphdr->tos); + sigvar = 1; } } @@ -555,7 +561,7 @@ static void rx_pkt(struct xsk_socket_info *xsk, struct pollfd *fds) orig = xsk_umem__extract_addr(addr); addr = xsk_umem__add_offset_to_addr(addr); - pkt_validate(xsk_umem__get_data(xsk->umem->buffer, addr)); + pkt_validate(xsk->umem->buffer, addr); *xsk_ring_prod__fill_addr(&xsk->umem->fq, idx_fq++) = orig; } @@ -564,8 +570,9 @@ static void rx_pkt(struct xsk_socket_info *xsk, struct pollfd *fds) xsk_ring_cons__release(&xsk->rx, rcvd); } -static void tx_only(struct xsk_socket_info *xsk, u32 *frameptr, int batch_size) +static void tx_only(struct ifobject *ifobject, u32 *frameptr, int batch_size) { + struct xsk_socket_info *xsk = ifobject->xsk; u32 idx = 0; unsigned int i; bool tx_invalid_test = stat_test_type == STAT_TEST_TX_INVALID; @@ -579,6 +586,7 @@ static void tx_only(struct xsk_socket_info *xsk, u32 *frameptr, int batch_size) tx_desc->addr = (*frameptr + i) << XSK_UMEM__DEFAULT_FRAME_SHIFT; tx_desc->len = len; + pkt_generate(ifobject, *frameptr + i, tx_desc->addr); } xsk_ring_prod__submit(&xsk->tx, batch_size); @@ -635,7 +643,7 @@ static void tx_only_all(struct ifobject *ifobject) continue; } - tx_only(ifobject->xsk, &frame_nb, batch_size); + tx_only(ifobject, &frame_nb, batch_size); pkt_cnt += batch_size; usleep(10); } @@ -768,26 +776,12 @@ static void testapp_cleanup_xsk_res(struct ifobject *ifobj) static void *worker_testapp_validate_tx(void *arg) { - struct udphdr *udp_hdr = - (struct udphdr *)(pkt_data + sizeof(struct ethhdr) + sizeof(struct iphdr)); - struct iphdr *ip_hdr = (struct iphdr *)(pkt_data + sizeof(struct ethhdr)); - struct ethhdr *eth_hdr = (struct ethhdr *)pkt_data; struct ifobject *ifobject = (struct ifobject *)arg; - struct generic_data data; void *bufs = NULL; if (!second_step) thread_common_ops(ifobject, bufs); - for (int i = 0; i < num_frames; i++) { - data.seqnum = i; - gen_udp_hdr(&data, ifobject, udp_hdr); - gen_ip_hdr(ifobject, ip_hdr); - gen_udp_csum(udp_hdr, ip_hdr); - gen_eth_hdr(ifobject, eth_hdr); - gen_eth_frame(ifobject->umem, i * XSK_UMEM__DEFAULT_FRAME_SIZE); - } - print_verbose("Sending %d packets on interface %s\n", opt_pkt_count, ifobject->ifname); tx_only_all(ifobject); diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 316c3565a99e..7670df7e7746 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -79,7 +79,6 @@ static u8 opt_verbose; static u32 xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; static u32 xdp_bind_flags = XDP_USE_NEED_WAKEUP | XDP_COPY; -static u8 pkt_data[XSK_UMEM__DEFAULT_FRAME_SIZE]; static u32 pkt_counter; static int sigvar; static int stat_test_type; @@ -108,10 +107,6 @@ struct flow_vector { } vector; }; -struct generic_data { - u32 seqnum; -}; - struct ifobject { char ifname[MAX_INTERFACE_NAME_CHARS]; char nsname[MAX_INTERFACES_NAMESPACE_CHARS]; From patchwork Wed Aug 25 09:37:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456849 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D043C4338F for ; Wed, 25 Aug 2021 09:38:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 631E961100 for ; Wed, 25 Aug 2021 09:38:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239912AbhHYJjO (ORCPT ); Wed, 25 Aug 2021 05:39:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239923AbhHYJjG (ORCPT ); Wed, 25 Aug 2021 05:39:06 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BAE2C0617AE; Wed, 25 Aug 2021 02:38:14 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id u15so14535494wmj.1; Wed, 25 Aug 2021 02:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P3gmMFF/pARRjL2MbmTlFa4EJ5UypikEnXafJNPFVec=; b=BuXFVrMEaELWGkieTn+mbGtLWc6eiGWLtH8hrbliwiMJpDQh6rzOkONpej4NpKeAi8 ucCe1K7UKrohm+DVZbJTz3SgQfUDjqD1p4bN4wPu+Bqk+iS0vL6eiYoxCfdYgeBFRWEL X3IHTSM4EhAnOrvCXXR8XPB4PRUZ0mhHEjEv9pWGgaQzGUkLRfj/CxjlH3ASs+9Z/Zog 8cD5cCqUnec+aTF9dRjmWbCa2bprWM2eotdbcu/6YuwiHyaFnn9MVavBNOnoqB/Ed0lg tcdB4KEQkaI6O7LhzzsDESo4ulxkMWOimRT62VOw8SkNarLMjT5GADPwqgVUH+LU+Jz0 3Gjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=P3gmMFF/pARRjL2MbmTlFa4EJ5UypikEnXafJNPFVec=; b=X9NqS9tgjoVzXOjLEecOKw0Ek5mD3ZtjjnKjIclMU5GcpoouotaOAxEtCyZ3nGnv1D yNKQbaQaQFQaoRk0RsuEUXxkV3zpP2owf/cL7c5vhdEnTxzAEPGAeRQf6eFhQZ+oPpou J/r5SeZ9l6slNPj9anOxBKxEFLq6PTmbsSzuTPiDfuWuIncZCRB4KoJSqcv6sUwhX8TJ owkKfhiNeZ9W5GWpeG7R9CuHLOw/z3o5OPfvKQRsqyoD6wn/IIVRB6JQbXLJ84lVN3A7 Uq1FcBqZNuteg0O2HrGuW5+YBIC4Pig2FQnXsCinwsjHnWp4JeN113BnazT/nIch/PS8 RPmw== X-Gm-Message-State: AOAM53292wLAjRy7sBqndvxpoBcKaVHrdZxRYjRvmURXMgGAiFZ2cGrc GwqcXEnIhwHlmqEh1WkTM7A= X-Google-Smtp-Source: ABdhPJxjY98+a9UXWSgcMuEMNJ2mTPKZGlhVj4aQD6KlUGHQCBzGRVduCDwl4SuBDQl0WYA4QGtX/g== X-Received: by 2002:a05:600c:1ca7:: with SMTP id k39mr8695263wms.115.1629884292571; Wed, 25 Aug 2021 02:38:12 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.38.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:38:12 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 14/16] selftests: xsk: generate packets from specification Date: Wed, 25 Aug 2021 11:37:20 +0200 Message-Id: <20210825093722.10219-15-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Generate packets from a specification instead of something hard coded. The idea is that a test generates one or more packet specifications and provides it/them to both Tx and Rx. The Tx thread will generate from this specification and Rx will validate that it receives what is in the specification. The specification can be the same on both ends, meaning that everything that was sent should be received, or different which means that Rx will only receive part of the sent packets. Currently, the packet specification is the same for both Rx and Tx and the same for each test. This will change in later work as features and tests are added. The data path functions are also renamed to better reflect what actions they are performing after introducing this feature. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 271 +++++++++++++---------- tools/testing/selftests/bpf/xdpxceiver.h | 16 +- 2 files changed, 166 insertions(+), 121 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 433c5c7b1928..5ca853cf27a1 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -417,18 +417,59 @@ static void parse_command_line(int argc, char **argv) } } -static void pkt_generate(struct ifobject *ifobject, u32 pkt_nb, u64 addr) +static struct pkt *pkt_stream_get_pkt(struct pkt_stream *pkt_stream, u32 pkt_nb) { - void *data = xsk_umem__get_data(ifobject->umem->buffer, addr); - struct udphdr *udp_hdr = - (struct udphdr *)(data + sizeof(struct ethhdr) + sizeof(struct iphdr)); - struct iphdr *ip_hdr = (struct iphdr *)(data + sizeof(struct ethhdr)); - struct ethhdr *eth_hdr = (struct ethhdr *)data; + if (pkt_nb >= pkt_stream->nb_pkts) + return NULL; + + return &pkt_stream->pkts[pkt_nb]; +} + +static struct pkt_stream *pkt_stream_generate(u32 nb_pkts, u32 pkt_len) +{ + struct pkt_stream *pkt_stream; + u32 i; + + pkt_stream = malloc(sizeof(*pkt_stream)); + if (!pkt_stream) + exit_with_error(ENOMEM); + + pkt_stream->pkts = calloc(nb_pkts, sizeof(*pkt_stream->pkts)); + if (!pkt_stream->pkts) + exit_with_error(ENOMEM); + + pkt_stream->nb_pkts = nb_pkts; + for (i = 0; i < nb_pkts; i++) { + pkt_stream->pkts[i].addr = (i % num_frames) * XSK_UMEM__DEFAULT_FRAME_SIZE; + pkt_stream->pkts[i].len = pkt_len; + pkt_stream->pkts[i].payload = i; + } + + return pkt_stream; +} + +static struct pkt *pkt_generate(struct ifobject *ifobject, u32 pkt_nb) +{ + struct pkt *pkt = pkt_stream_get_pkt(ifobject->pkt_stream, pkt_nb); + struct udphdr *udp_hdr; + struct ethhdr *eth_hdr; + struct iphdr *ip_hdr; + void *data; + + if (!pkt) + return NULL; + + data = xsk_umem__get_data(ifobject->umem->buffer, pkt->addr); + udp_hdr = (struct udphdr *)(data + sizeof(struct ethhdr) + sizeof(struct iphdr)); + ip_hdr = (struct iphdr *)(data + sizeof(struct ethhdr)); + eth_hdr = (struct ethhdr *)data; gen_udp_hdr(pkt_nb, data, ifobject, udp_hdr); gen_ip_hdr(ifobject, ip_hdr); gen_udp_csum(udp_hdr, ip_hdr); gen_eth_hdr(ifobject, eth_hdr); + + return pkt; } static void pkt_dump(void *pkt, u32 len) @@ -468,33 +509,43 @@ static void pkt_dump(void *pkt, u32 len) fprintf(stdout, "---------------------------------------\n"); } -static void pkt_validate(void *buffer, u64 addr) +static bool is_pkt_valid(struct pkt *pkt, void *buffer, const struct xdp_desc *desc) { - void *data = xsk_umem__get_data(buffer, addr); + void *data = xsk_umem__get_data(buffer, desc->addr); struct iphdr *iphdr = (struct iphdr *)(data + sizeof(struct ethhdr)); + if (!pkt) { + ksft_test_result_fail("ERROR: [%s] too many packets received\n", __func__); + return false; + } + if (iphdr->version == IP_PKT_VER && iphdr->tos == IP_PKT_TOS) { u32 seqnum = ntohl(*((u32 *)(data + PKT_HDR_SIZE))); - u32 expected_seqnum = pkt_counter % num_frames; if (debug_pkt_dump && test_type != TEST_TYPE_STATS) pkt_dump(data, PKT_SIZE); - if (expected_seqnum != seqnum) { + if (pkt->len != desc->len) { ksft_test_result_fail - ("ERROR: [%s] expected seqnum [%d], got seqnum [%d]\n", - __func__, expected_seqnum, seqnum); - sigvar = 1; + ("ERROR: [%s] expected length [%d], got length [%d]\n", + __func__, pkt->len, desc->len); + return false; } - if (++pkt_counter == opt_pkt_count) - sigvar = 1; + if (pkt->payload != seqnum) { + ksft_test_result_fail + ("ERROR: [%s] expected seqnum [%d], got seqnum [%d]\n", + __func__, pkt->payload, seqnum); + return false; + } } else { ksft_print_msg("Invalid frame received: "); ksft_print_msg("[IP_PKT_VER: %02X], [IP_PKT_TOS: %02X]\n", iphdr->version, iphdr->tos); - sigvar = 1; + return false; } + + return true; } static void kick_tx(struct xsk_socket_info *xsk) @@ -507,7 +558,7 @@ static void kick_tx(struct xsk_socket_info *xsk) exit_with_error(errno); } -static void complete_tx_only(struct xsk_socket_info *xsk, int batch_size) +static void complete_pkts(struct xsk_socket_info *xsk, int batch_size) { unsigned int rcvd; u32 idx; @@ -525,116 +576,105 @@ static void complete_tx_only(struct xsk_socket_info *xsk, int batch_size) } } -static void rx_pkt(struct xsk_socket_info *xsk, struct pollfd *fds) +static void receive_pkts(struct pkt_stream *pkt_stream, struct xsk_socket_info *xsk, + struct pollfd *fds) { - unsigned int rcvd, i; - u32 idx_rx = 0, idx_fq = 0; + u32 idx_rx = 0, idx_fq = 0, rcvd, i, pkt_count = 0; + struct pkt *pkt; int ret; - rcvd = xsk_ring_cons__peek(&xsk->rx, BATCH_SIZE, &idx_rx); - if (!rcvd) { - if (xsk_ring_prod__needs_wakeup(&xsk->umem->fq)) { - ret = poll(fds, 1, POLL_TMOUT); - if (ret < 0) - exit_with_error(-ret); + pkt = pkt_stream_get_pkt(pkt_stream, pkt_count++); + while (pkt) { + rcvd = xsk_ring_cons__peek(&xsk->rx, BATCH_SIZE, &idx_rx); + if (!rcvd) { + if (xsk_ring_prod__needs_wakeup(&xsk->umem->fq)) { + ret = poll(fds, 1, POLL_TMOUT); + if (ret < 0) + exit_with_error(-ret); + } + continue; } - return; - } - ret = xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq); - while (ret != rcvd) { - if (ret < 0) - exit_with_error(-ret); - if (xsk_ring_prod__needs_wakeup(&xsk->umem->fq)) { - ret = poll(fds, 1, POLL_TMOUT); + ret = xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq); + while (ret != rcvd) { if (ret < 0) exit_with_error(-ret); + if (xsk_ring_prod__needs_wakeup(&xsk->umem->fq)) { + ret = poll(fds, 1, POLL_TMOUT); + if (ret < 0) + exit_with_error(-ret); + } + ret = xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq); } - ret = xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq); - } - for (i = 0; i < rcvd; i++) { - u64 addr, orig; + for (i = 0; i < rcvd; i++) { + const struct xdp_desc *desc = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx++); + u64 addr = desc->addr, orig; - addr = xsk_ring_cons__rx_desc(&xsk->rx, idx_rx)->addr; - xsk_ring_cons__rx_desc(&xsk->rx, idx_rx++); - orig = xsk_umem__extract_addr(addr); + orig = xsk_umem__extract_addr(addr); + addr = xsk_umem__add_offset_to_addr(addr); + if (!is_pkt_valid(pkt, xsk->umem->buffer, desc)) + return; - addr = xsk_umem__add_offset_to_addr(addr); - pkt_validate(xsk->umem->buffer, addr); + *xsk_ring_prod__fill_addr(&xsk->umem->fq, idx_fq++) = orig; + pkt = pkt_stream_get_pkt(pkt_stream, pkt_count++); + } - *xsk_ring_prod__fill_addr(&xsk->umem->fq, idx_fq++) = orig; + xsk_ring_prod__submit(&xsk->umem->fq, rcvd); + xsk_ring_cons__release(&xsk->rx, rcvd); } - - xsk_ring_prod__submit(&xsk->umem->fq, rcvd); - xsk_ring_cons__release(&xsk->rx, rcvd); } -static void tx_only(struct ifobject *ifobject, u32 *frameptr, int batch_size) +static u32 __send_pkts(struct ifobject *ifobject, u32 pkt_nb) { struct xsk_socket_info *xsk = ifobject->xsk; - u32 idx = 0; - unsigned int i; - bool tx_invalid_test = stat_test_type == STAT_TEST_TX_INVALID; - u32 len = tx_invalid_test ? XSK_UMEM__DEFAULT_FRAME_SIZE + 1 : PKT_SIZE; + u32 i, idx; - while (xsk_ring_prod__reserve(&xsk->tx, batch_size, &idx) < batch_size) - complete_tx_only(xsk, batch_size); + while (xsk_ring_prod__reserve(&xsk->tx, BATCH_SIZE, &idx) < BATCH_SIZE) + complete_pkts(xsk, BATCH_SIZE); - for (i = 0; i < batch_size; i++) { + for (i = 0; i < BATCH_SIZE; i++) { struct xdp_desc *tx_desc = xsk_ring_prod__tx_desc(&xsk->tx, idx + i); + struct pkt *pkt = pkt_generate(ifobject, pkt_nb); - tx_desc->addr = (*frameptr + i) << XSK_UMEM__DEFAULT_FRAME_SHIFT; - tx_desc->len = len; - pkt_generate(ifobject, *frameptr + i, tx_desc->addr); - } + if (!pkt) + break; - xsk_ring_prod__submit(&xsk->tx, batch_size); - if (!tx_invalid_test) { - xsk->outstanding_tx += batch_size; - } else if (xsk_ring_prod__needs_wakeup(&xsk->tx)) { - kick_tx(xsk); + tx_desc->addr = pkt->addr; + tx_desc->len = pkt->len; + pkt_nb++; } - *frameptr += batch_size; - *frameptr %= num_frames; - complete_tx_only(xsk, batch_size); -} -static int get_batch_size(int pkt_cnt) -{ - if (pkt_cnt + BATCH_SIZE <= opt_pkt_count) - return BATCH_SIZE; + xsk_ring_prod__submit(&xsk->tx, i); + if (stat_test_type != STAT_TEST_TX_INVALID) + xsk->outstanding_tx += i; + else if (xsk_ring_prod__needs_wakeup(&xsk->tx)) + kick_tx(xsk); + complete_pkts(xsk, i); - return opt_pkt_count - pkt_cnt; + return i; } -static void complete_tx_only_all(struct ifobject *ifobject) +static void wait_for_tx_completion(struct xsk_socket_info *xsk) { - bool pending; - - do { - pending = false; - if (ifobject->xsk->outstanding_tx) { - complete_tx_only(ifobject->xsk, BATCH_SIZE); - pending = !!ifobject->xsk->outstanding_tx; - } - } while (pending); + while (xsk->outstanding_tx) + complete_pkts(xsk, BATCH_SIZE); } -static void tx_only_all(struct ifobject *ifobject) +static void send_pkts(struct ifobject *ifobject) { struct pollfd fds[MAX_SOCKS] = { }; - u32 frame_nb = 0; - int pkt_cnt = 0; - int ret; + u32 pkt_cnt = 0; fds[0].fd = xsk_socket__fd(ifobject->xsk->xsk); fds[0].events = POLLOUT; - while (pkt_cnt < opt_pkt_count) { - int batch_size = get_batch_size(pkt_cnt); + while (pkt_cnt < ifobject->pkt_stream->nb_pkts) { + u32 sent; if (test_type == TEST_TYPE_POLL) { + int ret; + ret = poll(fds, 1, POLL_TMOUT); if (ret <= 0) continue; @@ -643,17 +683,17 @@ static void tx_only_all(struct ifobject *ifobject) continue; } - tx_only(ifobject, &frame_nb, batch_size); - pkt_cnt += batch_size; + sent = __send_pkts(ifobject, pkt_cnt); + pkt_cnt += sent; usleep(10); } - complete_tx_only_all(ifobject); + wait_for_tx_completion(ifobject->xsk); } static bool rx_stats_are_valid(struct ifobject *ifobject) { - u32 xsk_stat = 0, expected_stat = opt_pkt_count; + u32 xsk_stat = 0, expected_stat = ifobject->pkt_stream->nb_pkts; struct xsk_socket *xsk = ifobject->xsk->xsk; int fd = xsk_socket__fd(xsk); struct xdp_statistics stats; @@ -709,11 +749,11 @@ static void tx_stats_validate(struct ifobject *ifobject) return; } - if (stats.tx_invalid_descs == opt_pkt_count) + if (stats.tx_invalid_descs == ifobject->pkt_stream->nb_pkts) return; ksft_test_result_fail("ERROR: [%s] tx_invalid_descs incorrect. Got [%u] expected [%u]\n", - __func__, stats.tx_invalid_descs, opt_pkt_count); + __func__, stats.tx_invalid_descs, ifobject->pkt_stream->nb_pkts); } static void thread_common_ops(struct ifobject *ifobject, void *bufs) @@ -782,8 +822,9 @@ static void *worker_testapp_validate_tx(void *arg) if (!second_step) thread_common_ops(ifobject, bufs); - print_verbose("Sending %d packets on interface %s\n", opt_pkt_count, ifobject->ifname); - tx_only_all(ifobject); + print_verbose("Sending %d packets on interface %s\n", ifobject->pkt_stream->nb_pkts, + ifobject->ifname); + send_pkts(ifobject); if (stat_test_type == STAT_TEST_TX_INVALID) tx_stats_validate(ifobject); @@ -809,19 +850,11 @@ static void *worker_testapp_validate_rx(void *arg) pthread_barrier_wait(&barr); - while (1) { - if (test_type != TEST_TYPE_STATS) { - rx_pkt(ifobject->xsk, fds); - } else { - if (rx_stats_are_valid(ifobject)) - break; - } - if (sigvar) - break; - } - - print_verbose("Received %d packets on interface %s\n", - pkt_counter, ifobject->ifname); + if (test_type == TEST_TYPE_STATS) + while (!rx_stats_are_valid(ifobject)) + continue; + else + receive_pkts(ifobject->pkt_stream, ifobject->xsk, fds); if (test_type == TEST_TYPE_TEARDOWN) print_verbose("Destroying socket\n"); @@ -834,10 +867,18 @@ static void testapp_validate(void) { bool bidi = test_type == TEST_TYPE_BIDI; bool bpf = test_type == TEST_TYPE_BPF_RES; + struct pkt_stream *pkt_stream; if (pthread_barrier_init(&barr, NULL, 2)) exit_with_error(errno); + if (stat_test_type == STAT_TEST_TX_INVALID) + pkt_stream = pkt_stream_generate(DEFAULT_PKT_CNT, XSK_UMEM__INVALID_FRAME_SIZE); + else + pkt_stream = pkt_stream_generate(DEFAULT_PKT_CNT, PKT_SIZE); + ifdict_tx->pkt_stream = pkt_stream; + ifdict_rx->pkt_stream = pkt_stream; + /*Spawn RX thread */ pthread_create(&t0, NULL, ifdict_rx->func_ptr, ifdict_rx); @@ -860,8 +901,6 @@ static void testapp_teardown(void) int i; for (i = 0; i < MAX_TEARDOWN_ITER; i++) { - pkt_counter = 0; - sigvar = 0; print_verbose("Creating socket\n"); testapp_validate(); } @@ -887,8 +926,6 @@ static void swap_vectors(struct ifobject *ifobj1, struct ifobject *ifobj2) static void testapp_bidi(void) { for (int i = 0; i < MAX_BIDI_ITER; i++) { - pkt_counter = 0; - sigvar = 0; print_verbose("Creating socket\n"); testapp_validate(); if (!second_step) { @@ -920,8 +957,6 @@ static void testapp_bpf_res(void) int i; for (i = 0; i < MAX_BPF_ITER; i++) { - pkt_counter = 0; - sigvar = 0; print_verbose("Creating socket\n"); testapp_validate(); if (!second_step) @@ -949,6 +984,8 @@ static void testapp_stats(void) case STAT_TEST_RX_FULL: rxqsize = RX_FULL_RXQSIZE; break; + case STAT_TEST_TX_INVALID: + continue; default: break; } @@ -994,9 +1031,7 @@ static void run_pkt_test(int mode, int type) /* reset defaults after potential previous test */ xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; - pkt_counter = 0; second_step = 0; - sigvar = 0; stat_test_type = -1; rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS; frame_headroom = XSK_UMEM__DEFAULT_FRAME_HEADROOM; diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 7670df7e7746..3e5394295ac1 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -40,6 +40,7 @@ #define POLL_TMOUT 1000 #define DEFAULT_PKT_CNT (4 * 1024) #define RX_FULL_RXQSIZE 32 +#define XSK_UMEM__INVALID_FRAME_SIZE (XSK_UMEM__DEFAULT_FRAME_SIZE + 1) #define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0) @@ -74,13 +75,10 @@ static u32 num_frames = DEFAULT_PKT_CNT / 4; static bool second_step; static int test_type; -static u32 opt_pkt_count = DEFAULT_PKT_CNT; static u8 opt_verbose; static u32 xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; static u32 xdp_bind_flags = XDP_USE_NEED_WAKEUP | XDP_COPY; -static u32 pkt_counter; -static int sigvar; static int stat_test_type; static u32 rxqsize; static u32 frame_headroom; @@ -107,6 +105,17 @@ struct flow_vector { } vector; }; +struct pkt { + u64 addr; + u32 len; + u32 payload; +}; + +struct pkt_stream { + u32 nb_pkts; + struct pkt *pkts; +}; + struct ifobject { char ifname[MAX_INTERFACE_NAME_CHARS]; char nsname[MAX_INTERFACES_NAMESPACE_CHARS]; @@ -116,6 +125,7 @@ struct ifobject { struct xsk_umem_info *umem; void *(*func_ptr)(void *arg); struct flow_vector fv; + struct pkt_stream *pkt_stream; int ns_fd; u32 dst_ip; u32 src_ip; From patchwork Wed Aug 25 09:37:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456847 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A62CEC4320A for ; Wed, 25 Aug 2021 09:38:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F25661100 for ; Wed, 25 Aug 2021 09:38:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239926AbhHYJjO (ORCPT ); Wed, 25 Aug 2021 05:39:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239928AbhHYJjG (ORCPT ); Wed, 25 Aug 2021 05:39:06 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D584C0617AF; Wed, 25 Aug 2021 02:38:15 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id k20-20020a05600c0b5400b002e87ad6956eso2460360wmr.1; Wed, 25 Aug 2021 02:38:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k1HJRSJMwl0Oep5SI3/5ET+XuXdJP32c8tVWrTf0FdU=; b=bl9vHTzutCnxlStSFlq56I2B0tS+1t33qeosIMbdjbZe7I3kW73cq0qy+PzSXpyq8W o3IVA4bIPVSHlXL7DJKvkCHNkTWPIfGfNBt5Nmn958+W/VjWyEtol8lPKafhBPuhQeVQ ClCNvcb/TZAT73OI3ZmOzgVEkhHBFCHzCeX4fVdLAzX5Y+Jbx3Fej03lSYm5cKjLy2Aw AXI3iLI8Qg725RGzkXlAHdvaoFSGWDGJs63fibniKuvpAFvGsY9144JbnI195vrraZfi Luj3NcEglKFYVWoHCIHC5p4lZ0qkVDT+553MYVvspcYj/X5TJeAptpBsvNz+PNP/xxHL jbbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k1HJRSJMwl0Oep5SI3/5ET+XuXdJP32c8tVWrTf0FdU=; b=RXti0AvNL++jKgCtvciIKtP8Z+z/cPRcJwfKmRoXrtAgGBwsirVArEwuloZOkmnxbS eUanCfRLPc7Bh+W9DcEiZ+YlU9Pw1hTT+DK9hcq1hW8IVzfhuxywvRdRSEIqlEv/pXGS nVCbk/xme+e5Fd09pMJEzBxY2IzIrlDSMgsG+/MzS+iUqAwkkEYJciv77hpcJ83J9vib 8ngaYKlP3GqCeTrtjp0gZSTK3uRd2ujcXnIgqwjxOW48SOLHB0hFxdhIPWOd235CnBNe LKDCWMorPhpNP57zqdAQfVdFSLpkg3uJ5Xg4lu3UjpYEqxsUzuJJ+H9hL32z/AmIUNnm RpIg== X-Gm-Message-State: AOAM5329UVp4lbiWZlMFI74MUvLIQxnQbL+G+qKiBaptHCsiSPrWgteH +KSZOn3yH4x2Mng3fMHMqlk= X-Google-Smtp-Source: ABdhPJyLQalIztQWckm2f17BF/EbdjiIHusQOJi8/5p/mGxWQL+hlA6QzyYaBW9/t33V80pFtcN4ag== X-Received: by 2002:a05:600c:1c08:: with SMTP id j8mr8464798wms.27.1629884294099; Wed, 25 Aug 2021 02:38:14 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.38.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:38:13 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 15/16] selftests: xsk: make enums lower case Date: Wed, 25 Aug 2021 11:37:21 +0200 Message-Id: <20210825093722.10219-16-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Make enums lower case as that is the standard. Also drop the unnecessary TEST_MODE_UNCONFIGURED mode. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 11 +++-------- tools/testing/selftests/bpf/xdpxceiver.h | 9 ++++----- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 5ca853cf27a1..0c7b40d5f4b6 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -105,14 +105,9 @@ static const u16 UDP_PORT2 = 2121; static void __exit_with_error(int error, const char *file, const char *func, int line) { - if (configured_mode == TEST_MODE_UNCONFIGURED) { - ksft_exit_fail_msg - ("[%s:%s:%i]: ERROR: %d/\"%s\"\n", file, func, line, error, strerror(error)); - } else { - ksft_test_result_fail - ("[%s:%s:%i]: ERROR: %d/\"%s\"\n", file, func, line, error, strerror(error)); - ksft_exit_xfail(); - } + ksft_test_result_fail("[%s:%s:%i]: ERROR: %d/\"%s\"\n", file, func, line, error, + strerror(error)); + ksft_exit_xfail(); } #define exit_with_error(error) __exit_with_error(error, __FILE__, __func__, __LINE__) diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 3e5394295ac1..582af3505c15 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -44,14 +44,13 @@ #define print_verbose(x...) do { if (opt_verbose) ksft_print_msg(x); } while (0) -enum TEST_MODES { - TEST_MODE_UNCONFIGURED = -1, +enum test_mode { TEST_MODE_SKB, TEST_MODE_DRV, TEST_MODE_MAX }; -enum TEST_TYPES { +enum test_type { TEST_TYPE_NOPOLL, TEST_TYPE_POLL, TEST_TYPE_TEARDOWN, @@ -61,7 +60,7 @@ enum TEST_TYPES { TEST_TYPE_MAX }; -enum STAT_TEST_TYPES { +enum stat_test_type { STAT_TEST_RX_DROPPED, STAT_TEST_TX_INVALID, STAT_TEST_RX_FULL, @@ -69,7 +68,7 @@ enum STAT_TEST_TYPES { STAT_TEST_TYPE_MAX }; -static int configured_mode = TEST_MODE_UNCONFIGURED; +static int configured_mode; static u8 debug_pkt_dump; static u32 num_frames = DEFAULT_PKT_CNT / 4; static bool second_step; From patchwork Wed Aug 25 09:37:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 12456851 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E11AC4320E for ; Wed, 25 Aug 2021 09:38:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 15D3F61100 for ; Wed, 25 Aug 2021 09:38:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239948AbhHYJjP (ORCPT ); Wed, 25 Aug 2021 05:39:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239930AbhHYJjG (ORCPT ); Wed, 25 Aug 2021 05:39:06 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03F79C0613A3; Wed, 25 Aug 2021 02:38:17 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id m2so2934025wmm.0; Wed, 25 Aug 2021 02:38:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JcRVqLzHeSEWPjvqu7NmOVLbnG/CtRpAiVX3Or4n/E0=; b=Ckw1Wt0nIOh5Q3L8TEDGZNLf3pDioly7UHn18B754/5CwM80ghVs7pa8coLlj1xwHR NXViyUajssshs3QQvUeDDyAiLBvYY/4KrAtMmN4KE0BjFitgWFjaFnQjjTwhnTpxmDbm +y22yVHBr7ZQHowjBmaS3aL14g00+PmVDiZ1nJFbpzPx6//1bYNtrjt7YWOwfizhdhmY CVoJ/uwwhYyxhx5NHOa4WXsz/yzuGbdEJUi8qwuReKc37jsWj+B7UAjAwzBLPy6dQ8aw WQHE2R0e4Vp58dC5y4JeFzANo4xuM8Lx9BKwhdcau+OriQc10eg+Gj8wpTxm8WDjTFog +tNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JcRVqLzHeSEWPjvqu7NmOVLbnG/CtRpAiVX3Or4n/E0=; b=Y0PvORwRrQusztTubEJ5vxct8T62ESahFiwa4jCc77MMgkxNwQWa5+M8LI22YoPdaH 5C3qOT3nLOQeMx2HDJBAO2HtvrPLAeW0TbpiXvhY9u4MSu85k7MWsfp9ZeYCT3vOZNFz qn/v2cA9+X46CEX9Ubb9c9QEoM/qG+U7o7rd9V90QvF5aLjhC3V1VmlJ36EnQWs9esEm C/CCpkfGh44Gqt/FoqjPDGT4B5sdzgf3ipmyMS4BI+0Wl6kaRBQuBMI9nu+sDHomSGYi C6Su5VOnRljsUNiiyVP0WEUY7wfzsiX6fgi0XNZ30SFUewp50B7eURGXPYNOx/qf3BP3 /BpA== X-Gm-Message-State: AOAM533UVTcCPf+6jDzhmH1esVh2gIlfAIP1+aRXP2AzuxuD2EN89Bp5 av/AU1F/mKRNPK/3sbumFFM= X-Google-Smtp-Source: ABdhPJyEXiTJo/KSsm8gPhYnCH9tEAD9o5ozMzGxhs4gdku+K1tDvpVtj27XMIGSws18HLdAfxeFcw== X-Received: by 2002:a05:600c:ac7:: with SMTP id c7mr8164537wmr.40.1629884295588; Wed, 25 Aug 2021 02:38:15 -0700 (PDT) Received: from localhost.localdomain (h-46-59-47-246.A165.priv.bahnhof.se. [46.59.47.246]) by smtp.gmail.com with ESMTPSA id k18sm4767910wmi.25.2021.08.25.02.38.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Aug 2021 02:38:15 -0700 (PDT) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, maciej.fijalkowski@intel.com Cc: jonathan.lemon@gmail.com, ciara.loftus@intel.com, bpf@vger.kernel.org, yhs@fb.com, andrii@kernel.org Subject: [PATCH bpf-next v3 16/16] selftests: xsk: preface options with opt Date: Wed, 25 Aug 2021 11:37:22 +0200 Message-Id: <20210825093722.10219-17-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20210825093722.10219-1-magnus.karlsson@gmail.com> References: <20210825093722.10219-1-magnus.karlsson@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Preface all options with opt_ and make them booleans. Signed-off-by: Magnus Karlsson --- tools/testing/selftests/bpf/xdpxceiver.c | 6 +++--- tools/testing/selftests/bpf/xdpxceiver.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/bpf/xdpxceiver.c b/tools/testing/selftests/bpf/xdpxceiver.c index 0c7b40d5f4b6..f53ce2683f8d 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.c +++ b/tools/testing/selftests/bpf/xdpxceiver.c @@ -395,10 +395,10 @@ static void parse_command_line(int argc, char **argv) interface_index++; break; case 'D': - debug_pkt_dump = 1; + opt_pkt_dump = true; break; case 'v': - opt_verbose = 1; + opt_verbose = true; break; default: usage(basename(argv[0])); @@ -517,7 +517,7 @@ static bool is_pkt_valid(struct pkt *pkt, void *buffer, const struct xdp_desc *d if (iphdr->version == IP_PKT_VER && iphdr->tos == IP_PKT_TOS) { u32 seqnum = ntohl(*((u32 *)(data + PKT_HDR_SIZE))); - if (debug_pkt_dump && test_type != TEST_TYPE_STATS) + if (opt_pkt_dump && test_type != TEST_TYPE_STATS) pkt_dump(data, PKT_SIZE); if (pkt->len != desc->len) { diff --git a/tools/testing/selftests/bpf/xdpxceiver.h b/tools/testing/selftests/bpf/xdpxceiver.h index 582af3505c15..7e49b9fbe25e 100644 --- a/tools/testing/selftests/bpf/xdpxceiver.h +++ b/tools/testing/selftests/bpf/xdpxceiver.h @@ -69,12 +69,12 @@ enum stat_test_type { }; static int configured_mode; -static u8 debug_pkt_dump; +static bool opt_pkt_dump; static u32 num_frames = DEFAULT_PKT_CNT / 4; static bool second_step; static int test_type; -static u8 opt_verbose; +static bool opt_verbose; static u32 xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST; static u32 xdp_bind_flags = XDP_USE_NEED_WAKEUP | XDP_COPY;