@samitouri / QOSamiQemu / commits / 8afab0b99a

target/hexagon: Add pcycle setting functionality

Replace pcycle set stubs with real implementations that distribute cycle count changes across all active threads. Reviewed-by: Taylor Simpson <ltaylorsimpson@gmail.com> Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>

Brian Cain committed Jun 22, 2026 at 15:28 UTC 8afab0b99a5a85e2afb520823287a334a341aff8
1 file changed +40 -3
target/hexagon/cpu_helper.c
+40 -3
@@ -56,17 +56,54 @@ uint32_t hexagon_get_sys_pcycle_count_low(CPUHexagonState *env)
56
57 void hexagon_set_sys_pcycle_count_high(CPUHexagonState *env, uint32_t val)
58 {
59 - g_assert_not_reached();
59 + uint64_t old;
60 +
61 + g_assert(bql_locked());
62 + old = hexagon_get_sys_pcycle_count(env);
63 + old = deposit64(old, 32, 32, val);
64 + hexagon_set_sys_pcycle_count(env, old);
65 }
66
67 void hexagon_set_sys_pcycle_count_low(CPUHexagonState *env, uint32_t val)
68 {
64 - g_assert_not_reached();
69 + uint64_t old;
70 +
71 + g_assert(bql_locked());
72 + old = hexagon_get_sys_pcycle_count(env);
73 + old = deposit64(old, 0, 32, val);
74 + hexagon_set_sys_pcycle_count(env, old);
75 }
76
77 void hexagon_set_sys_pcycle_count(CPUHexagonState *env, uint64_t val)
78 {
69 - g_assert_not_reached();
79 + CPUState *cs;
80 + uint64_t total;
81 + int num_threads;
82 + int64_t delta, per_thread, remainder;
83 +
84 + g_assert(bql_locked());
85 + total = hexagon_get_sys_pcycle_count(env);
86 +
87 + /* Count active threads */
88 + num_threads = 0;
89 + CPU_FOREACH(cs) {
90 + num_threads++;
91 + }
92 + g_assert(num_threads > 0);
93 +
94 + /*
95 + * Distribute the delta evenly across all threads.
96 + * Any remainder goes to the calling thread.
97 + */
98 + delta = (int64_t)(val - total);
99 + per_thread = delta / num_threads;
100 + remainder = delta - per_thread * num_threads;
101 +
102 + CPU_FOREACH(cs) {
103 + CPUHexagonState *thread_env = cpu_env(cs);
104 + thread_env->t_cycle_count += per_thread;
105 + }
106 + env->t_cycle_count += remainder;
107 }
108
109 static void hexagon_resume_thread(CPUHexagonState *env)