From: Roman Dementiev <roman.dementiev@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 3/3] test scaling of HTM lock elision protecting rte_hash
Date: Tue, 2 Jun 2015 15:11:33 +0200 [thread overview]
Message-ID: <1433250693-23644-4-git-send-email-roman.dementiev@intel.com> (raw)
In-Reply-To: <1433250693-23644-1-git-send-email-roman.dementiev@intel.com>
This patch adds a new auto-test for testing the scaling
of concurrent inserts into rte_hash when protected by
the normal spinlock vs. the spinlock with HTM lock
elision. The test also benchmarks single-threaded
access without any locks.
Signed-off-by: Roman Dementiev <roman.dementiev@intel.com>
---
app/test/Makefile | 1 +
app/test/test_hash_scaling.c | 223 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 224 insertions(+)
create mode 100644 app/test/test_hash_scaling.c
diff --git a/app/test/Makefile b/app/test/Makefile
index 3c777bf..6ffe539 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -83,6 +83,7 @@ SRCS-y += test_memcpy_perf.c
SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash.c
SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_perf.c
+SRCS-$(CONFIG_RTE_LIBRTE_HASH) += test_hash_scaling.c
SRCS-$(CONFIG_RTE_LIBRTE_LPM) += test_lpm.c
SRCS-$(CONFIG_RTE_LIBRTE_LPM) += test_lpm6.c
diff --git a/app/test/test_hash_scaling.c b/app/test/test_hash_scaling.c
new file mode 100644
index 0000000..682ae94
--- /dev/null
+++ b/app/test/test_hash_scaling.c
@@ -0,0 +1,223 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright(c) 2015 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <rte_cycles.h>
+#include <rte_hash.h>
+#include <rte_hash_crc.h>
+#include <rte_spinlock.h>
+#include <rte_launch.h>
+
+#include "test.h"
+
+/*
+ * Check condition and return an error if true. Assumes that "handle" is the
+ * name of the hash structure pointer to be freed.
+ */
+#define RETURN_IF_ERROR(cond, str, ...) do { \
+ if (cond) { \
+ printf("ERROR line %d: " str "\n", __LINE__, \
+ ##__VA_ARGS__); \
+ if (handle) \
+ rte_hash_free(handle); \
+ return -1; \
+ } \
+} while (0)
+
+enum locking_mode_t {
+ NORMAL_LOCK,
+ LOCK_ELISION,
+ NULL_LOCK
+};
+
+struct {
+ uint32_t num_iterations;
+ struct rte_hash *h;
+ rte_spinlock_t *lock;
+ int locking_mode;
+} tbl_scaling_test_params;
+
+static rte_atomic64_t gcycles;
+
+static int test_hash_scaling_worker(__attribute__((unused)) void *arg)
+{
+ uint64_t i, key;
+ uint32_t thr_id = rte_sys_gettid();
+ uint64_t begin, cycles = 0;
+
+ switch (tbl_scaling_test_params.locking_mode) {
+
+ case NORMAL_LOCK:
+
+ for (i = 0; i < tbl_scaling_test_params.num_iterations; i++) {
+ /* different threads get different keys because
+ we use the thread-id in the key computation
+ */
+ key = rte_hash_crc(&i, sizeof(i), thr_id);
+ begin = rte_rdtsc_precise();
+ rte_spinlock_lock(tbl_scaling_test_params.lock);
+ rte_hash_add_key(tbl_scaling_test_params.h, &key);
+ rte_spinlock_unlock(tbl_scaling_test_params.lock);
+ cycles += rte_rdtsc_precise() - begin;
+ }
+ break;
+
+ case LOCK_ELISION:
+
+ for (i = 0; i < tbl_scaling_test_params.num_iterations; i++) {
+ key = rte_hash_crc(&i, sizeof(i), thr_id);
+ begin = rte_rdtsc_precise();
+ rte_spinlock_lock_tm(tbl_scaling_test_params.lock);
+ rte_hash_add_key(tbl_scaling_test_params.h, &key);
+ rte_spinlock_unlock_tm(tbl_scaling_test_params.lock);
+ cycles += rte_rdtsc_precise() - begin;
+ }
+ break;
+
+ default:
+
+ for (i = 0; i < tbl_scaling_test_params.num_iterations; i++) {
+ key = rte_hash_crc(&i, sizeof(i), thr_id);
+ begin = rte_rdtsc_precise();
+ rte_hash_add_key(tbl_scaling_test_params.h, &key);
+ cycles += rte_rdtsc_precise() - begin;
+ }
+ }
+
+ rte_atomic64_add(&gcycles, cycles);
+
+ return 0;
+}
+
+/*
+ * Do scalability perf tests.
+ */
+static int
+test_hash_scaling(int locking_mode)
+{
+ static unsigned calledCount = 1;
+ uint32_t num_iterations = 1024*1024;
+ uint64_t i, key;
+ struct rte_hash_parameters hash_params = {
+ .entries = num_iterations*2,
+ .bucket_entries = 16,
+ .key_len = sizeof(key),
+ .hash_func = rte_hash_crc,
+ .hash_func_init_val = 0,
+ .socket_id = rte_socket_id(),
+ };
+ struct rte_hash *handle;
+ char name[RTE_HASH_NAMESIZE];
+ rte_spinlock_t lock;
+
+ rte_spinlock_init(&lock);
+
+ snprintf(name, 32, "test%u", calledCount++);
+ hash_params.name = name;
+
+ handle = rte_hash_create(&hash_params);
+ RETURN_IF_ERROR(handle == NULL, "hash creation failed");
+
+ tbl_scaling_test_params.num_iterations =
+ num_iterations/rte_lcore_count();
+ tbl_scaling_test_params.h = handle;
+ tbl_scaling_test_params.lock = &lock;
+ tbl_scaling_test_params.locking_mode = locking_mode;
+
+ rte_atomic64_init(&gcycles);
+ rte_atomic64_clear(&gcycles);
+
+ /* fill up to initial size */
+ for (i = 0; i < num_iterations; i++) {
+ key = rte_hash_crc(&i, sizeof(i), 0xabcdabcd);
+ rte_hash_add_key(tbl_scaling_test_params.h, &key);
+ }
+
+ rte_eal_mp_remote_launch(test_hash_scaling_worker, NULL, CALL_MASTER);
+ rte_eal_mp_wait_lcore();
+
+ unsigned long long int cycles_per_operation =
+ rte_atomic64_read(&gcycles)/
+ (tbl_scaling_test_params.num_iterations*rte_lcore_count());
+ const char *lock_name;
+
+ switch (locking_mode) {
+ case NORMAL_LOCK:
+ lock_name = "normal spinlock";
+ break;
+ case LOCK_ELISION:
+ lock_name = "lock elision";
+ break;
+ default:
+ lock_name = "null lock";
+ }
+ printf("--------------------------------------------------------\n");
+ printf("Cores: %d; %s mode -> cycles per operation: %llu\n",
+ rte_lcore_count(), lock_name, cycles_per_operation);
+ printf("--------------------------------------------------------\n");
+ /* CSV output */
+ printf(">>>%d,%s,%llu\n", rte_lcore_count(), lock_name,
+ cycles_per_operation);
+
+ rte_hash_free(handle);
+ return 0;
+}
+
+static int
+test_hash_scaling_main(void)
+{
+ int r = 0;
+
+ if (rte_lcore_count() == 1)
+ r = test_hash_scaling(NULL_LOCK);
+
+ if (r == 0)
+ r = test_hash_scaling(NORMAL_LOCK);
+
+ if (!rte_tm_supported()) {
+ printf("Hardware transactional memory (lock elision) is NOT supported\n");
+ return r;
+ }
+ printf("Hardware transactional memory (lock elision) is supported\n");
+
+ if (r == 0)
+ r = test_hash_scaling(LOCK_ELISION);
+
+ return r;
+}
+
+
+static struct test_command hash_scaling_cmd = {
+ .command = "hash_scaling_autotest",
+ .callback = test_hash_scaling_main,
+};
+REGISTER_TEST_COMMAND(hash_scaling_cmd);
--
1.9.5.msysgit.0
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052
next prev parent reply other threads:[~2015-06-02 13:11 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-02 13:11 [dpdk-dev] add support for HTM lock elision for x86 Roman Dementiev
2015-06-02 13:11 ` [dpdk-dev] [PATCH 1/3] spinlock: " Roman Dementiev
2015-06-02 13:11 ` [dpdk-dev] [PATCH 2/3] rwlock: " Roman Dementiev
2015-06-02 13:11 ` Roman Dementiev [this message]
[not found] ` <CADNuJVpeKa9-R7WHkoCzw82vpYd=3XmhOoz2JfGsFLzDW+F5UQ@mail.gmail.com>
2015-06-02 13:39 ` [dpdk-dev] " Dementiev, Roman
2015-06-02 14:55 ` Roman Dementiev
2015-06-03 18:40 ` Stephen Hemminger
2015-06-05 15:12 ` Roman Dementiev
2015-06-16 17:16 ` [dpdk-dev] [PATCH v2 0/3] " Roman Dementiev
2015-06-16 17:16 ` [dpdk-dev] [PATCH v2 1/3] spinlock: " Roman Dementiev
2015-06-17 21:29 ` Thomas Monjalon
2015-06-18 10:00 ` Bruce Richardson
2015-06-19 13:35 ` Thomas Monjalon
2015-06-22 15:32 ` Adrien Mazarguil
2015-06-29 9:34 ` [dpdk-dev] [PATCH] eal: fix cpu_feature_table[] compilation with -pedantic Adrien Mazarguil
2015-06-29 12:10 ` David Marchand
2015-06-29 12:19 ` Thomas Monjalon
2015-06-16 17:16 ` [dpdk-dev] [PATCH v2 2/3] rwlock: add support for HTM lock elision for x86 Roman Dementiev
2015-06-16 17:16 ` [dpdk-dev] [PATCH v2 3/3] test scaling of HTM lock elision protecting rte_hash Roman Dementiev
2015-06-17 13:05 ` [dpdk-dev] [PATCH v2 0/3] add support for HTM lock elision for x86 Bruce Richardson
2015-06-17 13:14 ` Thomas Monjalon
2015-06-17 13:48 ` Bruce Richardson
2015-06-19 11:08 ` [dpdk-dev] [PATCH v3 " Roman Dementiev
2015-06-19 11:08 ` [dpdk-dev] [PATCH v3 1/3] spinlock: " Roman Dementiev
2015-06-19 11:08 ` [dpdk-dev] [PATCH v3 2/3] rwlock: " Roman Dementiev
2015-06-19 11:08 ` [dpdk-dev] [PATCH v3 3/3] test scaling of HTM lock elision protecting rte_hash Roman Dementiev
2015-06-19 14:38 ` [dpdk-dev] [PATCH v3 0/3] add support for HTM lock elision for x86 Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1433250693-23644-4-git-send-email-roman.dementiev@intel.com \
--to=roman.dementiev@intel.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).