Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2495317ybd; Thu, 27 Jun 2019 13:25:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFNYKBjutsvpsIQYZ1wJk9IAz0BEOVQakqBfCy9DSlwFCzGjlOtjmVBhIFRNqwVgQ2RyjY X-Received: by 2002:a17:902:722:: with SMTP id 31mr6763637pli.163.1561667128759; Thu, 27 Jun 2019 13:25:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561667128; cv=none; d=google.com; s=arc-20160816; b=VOxJtWg+6HZYW11kheFcOAdVhg3q01pSKbPLMGWm1pNZdlZlTIyASmd3yHoSbtkL5k i17yME654dZlNf8bmNxLEt7rJk+ScpKMK3Gmrv2QQmpTFHpLoLaKVbMIrtHVvWgiXmgi ZHoYrP2SQxc91au8c1Pxz+na9YvG7Nzc8zovZz3hU3onjEo0xiH+1A1v4Lvqw/9qSrhl R1K/FzOcwa9NOjzbfCD9VZ2B8/z3IL55Quq6Ag8L/EOv3bd8VZWFQxstLsFzgWHF0smp UYRixkMXwVdCe3SM0NVrWlyRTq/JJR73kYW/Y2C5bwm0ctE3WcFmYjt6Eq8E1+DdiDRY +FWw== 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=q4bLerPxPI/p40u6FH2tSkmlq6kW9PUTNzNiWDLO44KbxbMHFN4DnMzwKVwJCHUlLu u1gLOvl54MltSgbBQDaRZSaugoB3xZ57s6ODavio7YgLla8qy4J8eV5WOs1Os/JFduWH Fb0Dt3WpJJgBSLJ9P71l/w/qKxQQAki+MMv1XwiCmQwpkqeiu6oeJe31cldynPJ8qkxa ZkxLmXT0mYAg9TOrCCIjesk5bR4xMxWDJFaEjn9+H8slXD/OsPxXYhgeEPqyQkB8y/LT sqKzKkrL2JmfNjupxsS5gmnrV6KIqPA3VJCgfQO2JGy0neiKipy3jQQ+rKb1WiY6aNV8 2p1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LnjgvAfD; 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 v5si95586pgs.285.2019.06.27.13.25.12; Thu, 27 Jun 2019 13:25:28 -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=LnjgvAfD; 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 S1726718AbfF0UYw (ORCPT + 99 others); Thu, 27 Jun 2019 16:24:52 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:44308 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726681AbfF0UYs (ORCPT ); Thu, 27 Jun 2019 16:24:48 -0400 Received: by mail-pf1-f202.google.com with SMTP id 5so2260253pff.11 for ; Thu, 27 Jun 2019 13:24:48 -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=LnjgvAfDybABi6V7lSQb+wdIq4e6RdOJkUtvtk6sYkCLxLtq5GrRR1+AIAdagnbn2M 32D60TgTSpoLNVtw4iateRMzPpu3hmdEkGLGGiBeWISyIr0MoIvWGL3QxdSgDgXG62Dy aDahwrys2fBFWhS+O6oF86FtlHhyU2ajOd2adaRnF7rHCTIjkzpf9Geu277wjRsmIREb 0g9+jDvNSSKwpijDljMb/UXHyZ4zV0d3w3ltMhNkgWi4ljmOdAHCmU8nloUJQEMU7ZFa LR4usRHay9bY1yH4UgLjVzbLGuEtECeZbP4gxMhdyXxkGko3iYmmIOJPf8PDrQlqKrv+ 69vQ== 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=b9MGxTDBB0xgX1lkQnqb5IV5TcplBQqoY73BjidlZXTyK49h4fy2Qz9Kb2RbM3tcHv +QLstikkjuJEthpnU3R9KHE1eIg0J3gjqt3ZukCXK4tPbaGVZ1dEF6N8BRvyu6+X0lVC arlmlh70ncnjRxeJJrQ8Pe+OYQsqx2RNX4dqLPa872BTPFryeC5V/ULkZ5QwXlBDvyXB yyGscVPaF7bw1XIDpASvJsIuzb68A7YiebLvpgrkskFgN7AyQSIlBWgeCiFTMSAEziZF 4/6jMeEfoRFOfMFlWWn8kV9jfs2Fr/aqjFznudAHR9kaiEXiMrX8Ldmo/FA768/xQJJG wdRQ== X-Gm-Message-State: APjAAAWSkrrUKywpLXukD/i3mTUuH37l+Y7Id9eJ+vDviBMJ/trw83xT STSOsVdVR66/WXCyP3rzl2OCrMBBv/dO X-Received: by 2002:a65:6656:: with SMTP id z22mr5327171pgv.197.1561667087667; Thu, 27 Jun 2019 13:24:47 -0700 (PDT) Date: Thu, 27 Jun 2019 13:24:17 -0700 In-Reply-To: <20190627202417.33370-1-brianvv@google.com> Message-Id: <20190627202417.33370-7-brianvv@google.com> Mime-Version: 1.0 References: <20190627202417.33370-1-brianvv@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH bpf-next v2 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