From 4e115d4b69d3978abb5220e33bcba6e316489502 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 3 Jun 2019 19:13:03 -0400 Subject: [PATCH] Fix performance when mulithreaded on 1 CPU, bug1455. --- Changes | 2 ++ include/verilated_threads.h | 15 +++++++++++--- test_regress/t/t_bench_mux4k_onecpu.pl | 28 ++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100755 test_regress/t/t_bench_mux4k_onecpu.pl diff --git a/Changes b/Changes index 92f1d8734..a423786f9 100644 --- a/Changes +++ b/Changes @@ -28,6 +28,8 @@ The contributors that suggested a given feature are shown in []. Thanks! **** Fix invalid XML output due to special chars, bug1444. [Kanad Kanhere] +**** Fix performance when mulithreaded on 1 CPU, bug1455. [Stefan Wallentowitz] + * Verilator 4.014 2019-05-08 diff --git a/include/verilated_threads.h b/include/verilated_threads.h index bd5b3d5f3..363a0ce35 100644 --- a/include/verilated_threads.h +++ b/include/verilated_threads.h @@ -52,6 +52,10 @@ public: // METHODS static vluint64_t yields() { return s_yields; } + static void yieldThread() { + ++s_yields; // Statistics + std::this_thread::yield(); + } // Block until notify() has occurred, then return. // If notify() has already occurred, return immediately. @@ -63,11 +67,10 @@ public: unsigned ct = 0; while (VL_UNLIKELY(!notified())) { VL_CPU_RELAX(); - ct++; + ++ct; if (VL_UNLIKELY(ct > VL_LOCK_SPINS)) { ct = 0; - ++s_yields; // Statistics - std::this_thread::yield(); + yieldThread(); } } } @@ -149,8 +152,14 @@ public: return m_upstreamDepsDone.load(std::memory_order_acquire) == target; } inline void waitUntilUpstreamDone(bool evenCycle) const { + unsigned ct = 0; while (VL_UNLIKELY(!areUpstreamDepsDone(evenCycle))) { VL_CPU_RELAX(); + ++ct; + if (VL_UNLIKELY(ct > VL_LOCK_SPINS)) { + ct = 0; + VlNotification::yieldThread(); + } } } }; diff --git a/test_regress/t/t_bench_mux4k_onecpu.pl b/test_regress/t/t_bench_mux4k_onecpu.pl new file mode 100755 index 000000000..e15715eb5 --- /dev/null +++ b/test_regress/t/t_bench_mux4k_onecpu.pl @@ -0,0 +1,28 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 by Wilson Snyder. This program is free software; you can +# redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. + +scenarios(vltmt => 1); + +top_filename("t/t_bench_mux4k.v"); + +compile( + v_flags2 => ["--stats"], + ); + +if (`numactl --show` !~ /cpu/) { + skip("No numactl available"); +} else { + execute( + run_env => 'numactl -m 0 -C 0,0,0,0,0,0,0,0', + check_finished => 1, + ); + ok(1); +} + +1;