Fixing task worker utilization tracing plot. (#16131)
On startup no workers are marked idle so the accounting was off-by-one
resulting in >100% utilization for the first worker plotting the %.
diff --git a/runtime/src/iree/task/worker.c b/runtime/src/iree/task/worker.c
index b9c518c..f4ffed8 100644
--- a/runtime/src/iree/task/worker.c
+++ b/runtime/src/iree/task/worker.c
@@ -274,6 +274,7 @@
// structures we use.
iree_wait_token_t wait_token =
iree_notification_prepare_wait(&worker->wake_notification);
+
// The masks are accessed with 'relaxed' order because they are just hints.
iree_task_affinity_set_t old_idle_mask =
iree_atomic_task_affinity_set_fetch_and(
@@ -282,9 +283,11 @@
(void)old_idle_mask;
IREE_TRACE_PLOT_VALUE_F32(
worker->executor->trace_name,
- 100.0f - 100.0f *
- (iree_task_affinity_set_count_ones(old_idle_mask) - 1) /
- (float)worker->executor->worker_count);
+ old_idle_mask
+ ? (100.0f -
+ 100.0f * (iree_task_affinity_set_count_ones(old_idle_mask) - 1) /
+ (float)worker->executor->worker_count)
+ : 100.0f);
// Check state to see if we've been asked to exit.
if (iree_atomic_load_int32(&worker->state, iree_memory_order_acquire) ==