diff --git a/docs/CONTRIBUTORS b/docs/CONTRIBUTORS index b94513cba..e124d4e26 100644 --- a/docs/CONTRIBUTORS +++ b/docs/CONTRIBUTORS @@ -316,6 +316,7 @@ Tracy Narine Trung Nguyen Tudor Timi Tymoteusz Blazejczyk +Tyrone Marhguy Udaya Raj Subedi Udi Finkelstein Unai Martinez-Corral diff --git a/docs/guide/simulating.rst b/docs/guide/simulating.rst index 6ace6014d..94da900fb 100644 --- a/docs/guide/simulating.rst +++ b/docs/guide/simulating.rst @@ -66,7 +66,7 @@ The information in this report is: .. describe:: "allocated 123 MB" - Total memory used during simulation in megabytes. + Peak resident memory used during simulation in megabytes. .. _benchmarking & optimization: diff --git a/docs/guide/verilating.rst b/docs/guide/verilating.rst index 6a856248d..cf0aa6f34 100644 --- a/docs/guide/verilating.rst +++ b/docs/guide/verilating.rst @@ -623,5 +623,5 @@ The information in this report is: .. describe:: "allocated 123 MB" - Total memory used during build by Verilator executable (excludes - :vlopt:`--build` compiler's usage) in megabytes. + Peak resident memory used by the Verilator executable during build + (excludes :vlopt:`--build` compiler's usage) in megabytes. diff --git a/include/verilatedos_c.h b/include/verilatedos_c.h index 67a6ef0f3..d329da089 100644 --- a/include/verilatedos_c.h +++ b/include/verilatedos_c.h @@ -169,17 +169,19 @@ void memUsageBytes(uint64_t& peakr, uint64_t& currentr) VL_MT_SAFE { } #else // Highly unportable. Sorry + // Use VmHWM (peak resident), matching Windows PeakWorkingSetSize and macOS resident_size_max. + // VmHWM excludes pages swapped out before the peak; /proc has no peak-(RSS+Swap) counter. std::ifstream is{"/proc/self/status"}; if (!is) return; std::string line; - uint64_t vmPeak = 0; + uint64_t vmHwm = 0; uint64_t vmRss = 0; uint64_t vmSwap = 0; std::string field; while (std::getline(is, line)) { - if (line.rfind("VmPeak:", 0) == 0) { + if (line.rfind("VmHWM:", 0) == 0) { std::stringstream ss{line}; - ss >> field >> vmPeak; + ss >> field >> vmHwm; } else if (line.rfind("VmRSS:", 0) == 0) { std::stringstream ss{line}; ss >> field >> vmRss; @@ -188,7 +190,7 @@ void memUsageBytes(uint64_t& peakr, uint64_t& currentr) VL_MT_SAFE { ss >> field >> vmSwap; } } - peakr = vmPeak * 1024; + peakr = vmHwm * 1024; currentr = (vmRss + vmSwap) * 1024; #endif } diff --git a/test_regress/t/t_opt_gate_blow_up.py b/test_regress/t/t_opt_gate_blow_up.py index 6e6d77fd3..5998dbc8a 100755 --- a/test_regress/t/t_opt_gate_blow_up.py +++ b/test_regress/t/t_opt_gate_blow_up.py @@ -11,11 +11,13 @@ import vltest_bootstrap test.scenarios('vlt') -test.compile(verilator_flags2=["--stats"]) +test.compile(verilator_flags2=["--stats --verilate-jobs 2"]) memUsageMB = int(test.file_grep(test.stats, r'Peak Memory Usage \(MB\) +(\d+)')[0]) if memUsageMB > 128 and not test.have_dev_asan: test.error("Consumed over 128MB memory") +test.file_grep(test.stats, r'Verilate jobs: 2') + test.passes()