Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1203282ybi; Fri, 21 Jun 2019 16:17:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpSMf7WEwZRcNH6EIq1xpNwJRVrZ98oM9MN7mcoHHJFGf/rypuGXfG119ZfROTm9/C7hlS X-Received: by 2002:a63:4f07:: with SMTP id d7mr20404093pgb.77.1561159075009; Fri, 21 Jun 2019 16:17:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561159075; cv=none; d=google.com; s=arc-20160816; b=JGWLSH3Ka/nEc7l4IWDXElo196BTJjHCRYEV9UzXnCQ8coGQ7BcEadKmKGjL6zLYKB UIpvn2wwQbrxLlpVhozPftMSgkR7e5RZbIEch0C8b7K0uFDT5ANHb3SocacUdimHX7F+ hsKVnxHc94qu1Wx05suxj7Nr8oePtDG+NL7KKlhfRAmqsfSeKOe+lE8HZISEn1/nFG4e gBAZ8RDzV2J+jksVaiYLIXT0Gamw2vUKJdhuCX/1GIyPdqtSP7/4+fcLXyL5bNQOh2zR OPYiV3xN/vdcpe/hEbL51uSiQkmJzrgBdiq9KMwP/GLQTVquKTViOUVl/tn++xFV0ss6 zRIA== 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=CUCPsO3jo98uPWQzYPGBmLbPJQj/PLpHh9qafy5RrRc=; b=jE1bT9GAf3M9a6JUW/SQuHF6xbq08vog8NUgHcR9QH0cPbMlFQ3ngm47X7GbFG5P3l ehwLq1BgrXNzLH5WyVi3XGm4I9KVy7sRavN9BMXCGFeDCcBZVs77uiP/57M49OGG2U74 vk/wz0G5Av6FxrokT0W7d5N0jyxJc7DdZektyuaVyuJ4CjEr5/AAE2hQlXaq9BZuJQWF tPrZQgMhHUkehFVf8pdm3RMUqqUoq0r3bpl8OOlTqerxQevpcnaPKNBvp+TCl2ivu2cx a4aR6LHI9RT68A8tA8Am5vqg3hrBlJ1GztV62Gi3eZEYjGtY/YtWuXcQBCW7E7oFD/SJ IHog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HZK8KCjJ; 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 c8si3728271pls.436.2019.06.21.16.17.39; Fri, 21 Jun 2019 16:17:54 -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=HZK8KCjJ; 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 S1726299AbfFUXRQ (ORCPT + 99 others); Fri, 21 Jun 2019 19:17:16 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:43235 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726259AbfFUXRO (ORCPT ); Fri, 21 Jun 2019 19:17:14 -0400 Received: by mail-pf1-f202.google.com with SMTP id j7so5259422pfn.10 for ; Fri, 21 Jun 2019 16:17:13 -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=CUCPsO3jo98uPWQzYPGBmLbPJQj/PLpHh9qafy5RrRc=; b=HZK8KCjJImIc7GaiInhM8ZZ/258RRA2Voe62DwCyvpjD8nA7Lw/bF+G4AkFymv2J6v O7aN1jKPiR4BSV3MHpXtCQchPzekAqEtrsrSXMZfEF5kKtBtAiBUpFktqslwp1aJMqUX E5jnTKGOvXz2fg6ObmERGenqiVYoud3ya1wWGbtPyHaNRaMr8OxpgHkLZdLBgNieLfP3 Z8AFI3kiGPnMKMGfrneLKhxmNMx7qKiqNYEyvt5vS3gmr72hAOChLjr5v6wHm31VXaKo UiwoHxYa2hylnNqTX5YodwEF8MnkzhI5rcM9iJMrIu7Xxol/q/jD2wRVLRopeaoCZJAx dnuw== 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=CUCPsO3jo98uPWQzYPGBmLbPJQj/PLpHh9qafy5RrRc=; b=uOcsE8Cjnaw1T9E7xSglPrWulBkG/yjgfeasPPxDQ1f7atSITO+9r/JNbsg5zkFONG xuvncHdyMaOaPDVp5zzXb6c8e9fwfKICJrKzCuIORrJlfukSsqK+jLQ5n05h4p2KX108 0+d0olieLubEbyAMP3ynaQL1mp37X3H8WJr3mI0Nhd8w1ppFsRJ8q5+uz+29Whe5ZA1m KtP5cZO7kBPD8+n0dCwchkfMKqB9Z57vS7m8+fOdbTUUbERa9lcmWOM7KvEo8365PEyP vF5X8aGe+TX9uXGhZeGLXUuMCb4BlLn/FdSr9nvZqRR6yHcmHuvlH8Vl+EYL1TYqZAVw PExg== X-Gm-Message-State: APjAAAXC+bzLrDTa9rxryehdBKT5Uai7oSLO08tJ9ySFcmTZ5Hvgnjb6 tqdiZgFrFkOPlB2yGeB96UwjH96pih4s X-Received: by 2002:a63:3f48:: with SMTP id m69mr20448994pga.17.1561159033052; Fri, 21 Jun 2019 16:17:13 -0700 (PDT) Date: Fri, 21 Jun 2019 16:16:50 -0700 In-Reply-To: <20190621231650.32073-1-brianvv@google.com> Message-Id: <20190621231650.32073-7-brianvv@google.com> Mime-Version: 1.0 References: <20190621231650.32073-1-brianvv@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH 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 | 71 +++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c index 3df72b46fd1d9..61050272c20ee 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 @@ -376,6 +377,75 @@ 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, k = 0; + int num_ent, off; + 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[k]; + buf_len = elem_size*tests[k]; + k++; + 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; + num_ent = buf_len / elem_size; + for (j = 0, off = 0; j < num_ent; j++) { + key = *((uint64_t *)(buf + off)); + off += sizeof(key); + value = *((uint64_t *)(buf + off)); + off += sizeof(value); + } + i += num_ent; + } + 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 (k < test_len) + goto test; + free(buf); + close(fd); +} + static void test_hashmap_zero_seed(void) { int i, first, second, old_flags; @@ -1736,6 +1806,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