xref: /xnu-11417.121.6/tests/sched/sched_test_harness/sched_clutch_harness.c (revision a1e26a70f38d1d7daa7b49b258e2f8538ad81650)
1 // Copyright (c) 2024 Apple Inc.  All rights reserved.
2 
3 #include "sched_clutch_harness_impl.c"
4 
5 void
impl_init_runqueue(void)6 impl_init_runqueue(void)
7 {
8 	/* Init runqueue */
9 	clutch_impl_init_topology(single_core);
10 	curr_hw_topo = single_core;
11 	assert(processor_avail_count == 1);
12 	sched_clutch_init();
13 	sched_clutch_pset_init(&pset0);
14 	sched_clutch_processor_init(&cpu0);
15 	increment_mock_time(100);
16 	clutch_impl_init_params();
17 	clutch_impl_init_tracepoints();
18 }
19 
20 struct thread_group *
impl_create_tg(int interactivity_score)21 impl_create_tg(int interactivity_score)
22 {
23 	return clutch_impl_create_tg(interactivity_score);
24 }
25 
26 test_thread_t
impl_create_thread(int root_bucket,struct thread_group * tg,int pri)27 impl_create_thread(int root_bucket, struct thread_group *tg, int pri)
28 {
29 	return clutch_impl_create_thread(root_bucket, tg, pri);
30 }
31 
32 void
impl_set_thread_sched_mode(test_thread_t thread,int mode)33 impl_set_thread_sched_mode(test_thread_t thread, int mode)
34 {
35 	clutch_impl_set_thread_sched_mode(thread, mode);
36 }
37 
38 void
impl_set_thread_processor_bound(test_thread_t thread,int cpu_id)39 impl_set_thread_processor_bound(test_thread_t thread, int cpu_id)
40 {
41 	clutch_impl_set_thread_processor_bound(thread, cpu_id);
42 }
43 
44 void
impl_cpu_set_thread_current(int cpu_id,test_thread_t thread)45 impl_cpu_set_thread_current(int cpu_id, test_thread_t thread)
46 {
47 	clutch_impl_cpu_set_thread_current(cpu_id, thread);
48 }
49 
50 void
impl_cpu_clear_thread_current(int cpu_id)51 impl_cpu_clear_thread_current(int cpu_id)
52 {
53 	clutch_impl_cpu_clear_thread_current(cpu_id);
54 }
55 
56 void
impl_cpu_enqueue_thread(int cpu_id,test_thread_t thread)57 impl_cpu_enqueue_thread(int cpu_id, test_thread_t thread)
58 {
59 	sched_clutch_processor_enqueue(cpus[cpu_id], thread, SCHED_TAILQ);
60 }
61 
62 test_thread_t
impl_cpu_dequeue_thread(int cpu_id)63 impl_cpu_dequeue_thread(int cpu_id)
64 {
65 	return sched_clutch_choose_thread(cpus[cpu_id], MINPRI, NULL, 0);
66 }
67 
68 test_thread_t
impl_cpu_dequeue_thread_compare_current(int cpu_id)69 impl_cpu_dequeue_thread_compare_current(int cpu_id)
70 {
71 	assert(cpus[cpu_id]->active_thread != NULL);
72 	return sched_clutch_choose_thread(cpus[cpu_id], MINPRI, cpus[cpu_id]->active_thread, 0);
73 }
74 
75 bool
impl_processor_csw_check(int cpu_id)76 impl_processor_csw_check(int cpu_id)
77 {
78 	ast_t preempt_ast = sched_clutch_processor_csw_check(cpus[cpu_id]);
79 	return preempt_ast & AST_PREEMPT;
80 }
81 
82 void
impl_pop_tracepoint(uint64_t * clutch_trace_code,uint64_t * arg1,uint64_t * arg2,uint64_t * arg3,uint64_t * arg4)83 impl_pop_tracepoint(uint64_t *clutch_trace_code, uint64_t *arg1, uint64_t *arg2, uint64_t *arg3, uint64_t *arg4)
84 {
85 	clutch_impl_pop_tracepoint(clutch_trace_code, arg1, arg2, arg3, arg4);
86 }
87