From c2f381af688fd35a00eae640cff39a85ecfcb4a2 Mon Sep 17 00:00:00 2001 From: vkaranth Date: Thu, 1 Oct 2026 17:49:00 +0000 Subject: [PATCH] multiload: fix hang when per-thread load bandwidth is below 1 MiB/s Load threads published (uint64_t)mibps in x.count, which is also the sample-ready handshake polled by main. Below 1 MiB/s the cast truncated to 0, so main waited forever. Publish bytes/s instead and convert back to MiB/s in main. Also print per-thread values with %.3f. --- multiload.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/multiload.c b/multiload.c index 97c2262..c9494ab 100644 --- a/multiload.c +++ b/multiload.c @@ -462,9 +462,11 @@ static const chase_t chases[] = { * nxt_sample ); */ \ /* printf(" %ld,%ld,%ld,%.0f:%.0f(%.1fMiBs)\n", cur_sample, loops, \ * t->x.count, bite_sum, timetot, mibps); */ \ - /* update the MiB/s count. Main thread will read and set to 0 so we know \ - * this sample is done. */ \ - __sync_add_and_fetch(&t->x.count, (uint64_t)mibps); \ + /* Report bytes/s (not MiB/s) so a slow thread (< 1 MiB/s) does not \ + * truncate to 0, which main would read as "not ready" forever. Main \ + * thread converts back to MiB/s, then sets count to 0 for next sample. \ + */ \ + __sync_add_and_fetch(&t->x.count, (uint64_t)(mibps * 1024 * 1024)); \ cur_sample = nxt_sample; \ loops = 0; \ time0 = (double)now_nsec(); \ @@ -1435,9 +1437,10 @@ int main(int argc, char **argv) { mibps); } } else { - load_thd_sum += (double)cur_samples[i]; + cur_samples[i] /= (1024 * 1024); // load threads report bytes/s + load_thd_sum += cur_samples[i]; if (verbosity > 1) { - printf(" ML(%ld)%.0f(MiB/s)", i, cur_samples[i]); + printf(" ML(%ld)%.3f(MiB/s)", i, cur_samples[i]); } } } @@ -1469,7 +1472,7 @@ int main(int argc, char **argv) { if (load_thd_sum < load_min_mibps) load_min_mibps = load_thd_sum; load_running_sum += load_thd_sum; if (verbosity > 0) { - printf(" main: threads=%ld, Total(MiB/s)=%.*f, PerThread=%.f\n", + printf(" main: threads=%ld, Total(MiB/s)=%.*f, PerThread=%.3f\n", nr_load_threads, load_thd_sum < 100. ? 3 : 1, load_thd_sum, load_thd_sum / nr_load_threads); }