Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1133320ybi; Wed, 3 Jul 2019 10:03:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqyBQILDF0R3mDomaX7nSXpHM1cPbZ3r0Bp1FYvhsZ3IGK6nH+wgMoNYXuRomMreC9w1nRrT X-Received: by 2002:a63:4105:: with SMTP id o5mr39402099pga.308.1562173419442; Wed, 03 Jul 2019 10:03:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562173419; cv=none; d=google.com; s=arc-20160816; b=f173XL1DKT+3DjgSb8PatJK8Ae07barnnGHCO+iekLURuGsM2dMk0SOAq4mL8b+XKI zz3F676CC0N6Zw6WR1h+nOFD4zTU7yaoDHf9WIuakXJjXTN3n/w5R3nBexTup2iakTzv q582PFLlh5J58ITPcAmtPPglK3p08RpANys/GEYVPxouQN2k2BMV14NvBjBAo+5SU9YZ hZN0EMMuDwVGgACckkN3Zd5ohPC26jdf8voKqUeto68Sb6pYTzdL5WThghw89yZbIjwr +KLjJWK0aUnxVcdHcxR1Q6W4EylSZvvgIUjoxlTXtoDSjerTuv3L8BArYUnVppIVI95g JfUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=ld5qNoKshdyRmavLPGoPc6BR++OK/w6IRlR9/ebcOn4=; b=kBjGs0FY50FLLtpVcYL8mZe5ZmvTaEY/waUiChbeaKVwJLW7VZrn6Hq88ilcWJZR3N yT39g+cu0YWvL92npT5mxDnip2OEshgmKIj0U5zNLWkSCvneU/FOEmS5cKST32RUhy7p DDmYoRwkSs7zCPncFrPHzB1xVqPAEz8+jnxrU0SfzCgQo+Q5LZAg1SR2W7OGvmWke6gn PcQmYhTwuX3Xabj65ItOSlz9OM12DnqAnwk3EIAgIz9Uscmq6BRVaGUf5FovxlMzC/8m alvt0YFv2mhDIFCYYSiFzK3qFXD76VRoyRaGwxF8BggIzlDsUhgkQBl4/EMSWkaYu2q1 GvLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TZrCGi3j; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l7si2547979pgp.318.2019.07.03.10.03.14; Wed, 03 Jul 2019 10:03:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TZrCGi3j; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727353AbfGCRCV (ORCPT + 99 others); Wed, 3 Jul 2019 13:02:21 -0400 Received: from mail-qk1-f202.google.com ([209.85.222.202]:54271 "EHLO mail-qk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727355AbfGCRCT (ORCPT ); Wed, 3 Jul 2019 13:02:19 -0400 Received: by mail-qk1-f202.google.com with SMTP id i196so3717736qke.20 for ; Wed, 03 Jul 2019 10:02:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ld5qNoKshdyRmavLPGoPc6BR++OK/w6IRlR9/ebcOn4=; b=TZrCGi3jcqjHluRGRqVScSH3nnF0ngfzc7kFNydCQYZVuwuUp9YebJ1FMq1bxqWMB2 tHhtCnnfbK7nhfIkJVSbdsly1Sb2uJEw63ORMMbMjGr+rgwFeja8VYmU9bIvdijewmMB skRF5jPJjA2NhKt8fyeSp1jCTaAEYa1NkzzKxF1iRkEaRFI3/EQRfY+F+d+TlRIsPdAv IzoPvqZd+U6VyoEB4zaqJQ0v0zehg1PHAldRx3VPq/5pID7CAoImHt+9f8+LdaSB4iK/ jfZo3e5+EO4pm+3WJra8HHkX2pcDrI7PQWAwwDh+lDqqDiUn/6Y+hvW1lnoMzw3cM47K dJnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ld5qNoKshdyRmavLPGoPc6BR++OK/w6IRlR9/ebcOn4=; b=fjYUBQDxzvfBTtifKuT1MHOLzItrCsLCDZ4s+H3MbG+DgWf2TBt6iwW/bkfFPBSG4z MOetX8PKnsYZ73TSMi5RgK2JrNFvp7Vj2Q7gA2ggv8dG//FohHLLlhMvpQbhlnq9lLir aZEUWYP0MaZdQQeG4hXIirpYeA7bJy2xU/hmi416BKh7NTU4JgbwgU6PoSA+amu0yGnL SpaY+2E/UeZrpUfJuvvXOk2HpEmh55WeGu2b+lto2YuBlvuO6FdvWQGrWAvqje0AiBKq BqWceRoZSTKavMFTfKD1kd8i5hqungRPZd1HqKOgjgOr82j6//plOzasFx65gO9HdY5r YA/w== X-Gm-Message-State: APjAAAUWFMe+73XA8va/ih5LHSwJRHntHqDxGkDMJnezJhQTPGRK6uP9 xkWkv0Izv4onmIUKt47B1Wfc3Ajf4Gzi X-Received: by 2002:ac8:6958:: with SMTP id n24mr32368355qtr.360.1562173338277; Wed, 03 Jul 2019 10:02:18 -0700 (PDT) Date: Wed, 3 Jul 2019 10:01:18 -0700 In-Reply-To: <20190703170118.196552-1-brianvv@google.com> Message-Id: <20190703170118.196552-7-brianvv@google.com> Mime-Version: 1.0 References: <20190703170118.196552-1-brianvv@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [PATCH bpf-next RFC v3 6/6] selftests/bpf: add test to measure performance of BPF_MAP_DUMP From: Brian Vazquez To: Brian Vazquez , Alexei Starovoitov , Daniel Borkmann , "David S . Miller" Cc: Stanislav Fomichev , Willem de Bruijn , Petar Penkov , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Brian Vazquez Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This tests compares the amount of time that takes to read an entire table of 100K elements on a bpf hashmap using both BPF_MAP_DUMP and BPF_MAP_GET_NEXT_KEY + BPF_MAP_LOOKUP_ELEM. Signed-off-by: Brian Vazquez --- tools/testing/selftests/bpf/test_maps.c | 65 +++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c index b19ba6aa8e36..786d0e340aed 100644 --- a/tools/testing/selftests/bpf/test_maps.c +++ b/tools/testing/selftests/bpf/test_maps.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -388,6 +389,69 @@ static void test_hashmap_dump(void) close(fd); } +static void test_hashmap_dump_perf(void) +{ + int fd, i, max_entries = 100000; + uint64_t key, value, next_key; + bool next_key_valid = true; + void *buf; + u32 buf_len, entries; + int j = 0; + int clk_id = CLOCK_MONOTONIC; + struct timespec begin, end; + long long time_spent, dump_time_spent; + double res; + int tests[] = {1, 2, 230, 5000, 73000, 100000, 234567}; + int test_len = ARRAY_SIZE(tests); + const int elem_size = sizeof(key) + sizeof(value); + + fd = helper_fill_hashmap(max_entries); + // Alloc memory considering the largest buffer + buf = malloc(elem_size * tests[test_len-1]); + assert(buf != NULL); + +test: + entries = tests[j]; + buf_len = elem_size*tests[j]; + j++; + clock_gettime(clk_id, &begin); + errno = 0; + i = 0; + while (errno == 0) { + bpf_map_dump(fd, !i ? NULL : &key, + buf, &buf_len); + if (errno) + break; + if (!i) + key = *((uint64_t *)(buf + buf_len - elem_size)); + i += buf_len / elem_size; + } + clock_gettime(clk_id, &end); + assert(i == max_entries); + dump_time_spent = NSEC_PER_SEC * (end.tv_sec - begin.tv_sec) + + end.tv_nsec - begin.tv_nsec; + next_key_valid = true; + clock_gettime(clk_id, &begin); + assert(bpf_map_get_next_key(fd, NULL, &key) == 0); + for (i = 0; next_key_valid; i++) { + next_key_valid = bpf_map_get_next_key(fd, &key, &next_key) == 0; + assert(bpf_map_lookup_elem(fd, &key, &value) == 0); + key = next_key; + } + clock_gettime(clk_id, &end); + time_spent = NSEC_PER_SEC * (end.tv_sec - begin.tv_sec) + + end.tv_nsec - begin.tv_nsec; + res = (1-((double)dump_time_spent/time_spent))*100; + printf("buf_len_%u:\t %llu entry-by-entry: %llu improvement %lf\n", + entries, dump_time_spent, time_spent, res); + assert(i == max_entries); + + if (j < test_len) + goto test; + free(buf); + close(fd); +} + static void test_hashmap_zero_seed(void) { int i, first, second, old_flags; @@ -1748,6 +1812,7 @@ static void run_all_tests(void) test_hashmap_walk(0, NULL); test_hashmap_zero_seed(); test_hashmap_dump(); + test_hashmap_dump_perf(); test_arraymap(0, NULL); test_arraymap_percpu(0, NULL); -- 2.22.0.410.gd8fdbe21b5-goog