On 29/5/26 23:55, Brian Cain wrote:
Replace pcycle set stubs with real implementations that
distribute cycle count changes across all active threads.

Reviewed-by: Taylor Simpson <[email protected]>
Signed-off-by: Brian Cain <[email protected]>
---
  target/hexagon/cpu_helper.c | 43 ++++++++++++++++++++++++++++++++++---
  1 file changed, 40 insertions(+), 3 deletions(-)

diff --git a/target/hexagon/cpu_helper.c b/target/hexagon/cpu_helper.c
index bb991a671e8..64c5746c6d9 100644
--- a/target/hexagon/cpu_helper.c
+++ b/target/hexagon/cpu_helper.c


  void hexagon_set_sys_pcycle_count(CPUHexagonState *env, uint64_t val)
  {
-    g_assert_not_reached();
+    CPUState *cs;
+    uint64_t total;
+    int num_threads;
+    int64_t delta, per_thread, remainder;
+
+    g_assert(bql_locked());
+    total = hexagon_get_sys_pcycle_count(env);
+
+    /* Count active threads */
+    num_threads = 0;
+    CPU_FOREACH(cs) {

Not an issue as of today, but this won't scale in heterogeneous setup.

I suppose we'd need some cluster concept here:

       CPUClusterState *cluster = cpu_get_cluster(cs);
       CPU_CLUSTER_FOREACH(cluster, cs) {

+        num_threads++;
+    }
+    g_assert(num_threads > 0);
+
+    /*
+     * Distribute the delta evenly across all threads.
+     * Any remainder goes to the calling thread.
+     */
+    delta = (int64_t)(val - total);
+    per_thread = delta / num_threads;
+    remainder = delta - per_thread * num_threads;
+
+    CPU_FOREACH(cs) {

CPU_FOREACH's @cs variable declaration overrides the other one
declared in prologue.

+        CPUHexagonState *thread_env = cpu_env(cs);
+        thread_env->t_cycle_count += per_thread;
+    }
+    env->t_cycle_count += remainder;
  }
static void hexagon_resume_thread(CPUHexagonState *env)


Reply via email to