xref: /xnu-11417.101.15/tests/sched/sched_test_harness/sched_migration_harness.h (revision e3723e1f17661b24996789d8afc084c0c3303b26) !
1 // Copyright (c) 2024 Apple Inc.  All rights reserved.
2 
3 #pragma once
4 
5 #include <stdint.h>
6 #include <stdbool.h>
7 #include <stdarg.h>
8 
9 #include "sched_runqueue_harness.h"
10 
11 /* Mocking the HW topology */
12 typedef enum {
13 	TEST_CPU_TYPE_EFFICIENCY,
14 	TEST_CPU_TYPE_PERFORMANCE,
15 	TEST_CPU_TYPE_MAX,
16 } test_cpu_type_t;
17 
18 typedef struct {
19 	test_cpu_type_t cpu_type;
20 	int num_cpus;
21 	int die_id;
22 } test_pset_t;
23 
24 typedef struct {
25 	test_pset_t *psets;
26 	int num_psets;
27 } test_hw_topology_t;
28 
29 extern int                   cpu_id_to_cluster_id(int cpu_id);
30 extern int                   cluster_id_to_cpu_id(int cluster_id);
31 extern test_hw_topology_t    get_hw_topology(void);
32 extern void                  set_hw_topology(test_hw_topology_t hw_topology);
33 
34 /* Given topologies */
35 extern test_hw_topology_t single_core; // 1P
36 extern test_hw_topology_t basic_amp; // 2P + 4E
37 extern test_hw_topology_t dual_die; // 2E + 4P + 4P + 2E + 4P + 4P
38 
39 /* Test harness utilities */
40 extern void      init_migration_harness(test_hw_topology_t hw_topology);
41 extern void      set_tg_sched_bucket_preferred_pset(struct thread_group *tg, int sched_bucket, int cluster_id);
42 extern void      set_thread_cluster_bound(test_thread_t thread, int cluster_id);
43 extern bool      choose_pset_for_thread_expect(test_thread_t thread, int expected_cluster_id);
44 extern void      set_current_processor(int cpu_id);
45 extern void      set_pset_load_avg(int cluster_id, int QoS, uint64_t load_avg);
46 extern void      set_pset_recommended(int cluster_id);
47 extern void      set_pset_derecommended(int cluster_id);
48 typedef enum {
49 	TEST_IPI_NONE              = 0x0,
50 	TEST_IPI_IMMEDIATE         = 0x1,
51 	TEST_IPI_IDLE              = 0x2,
52 	TEST_IPI_DEFERRED          = 0x3,
53 } test_ipi_type_t; // Mirrors sched_ipi_type_t
54 extern bool      ipi_expect(int cpu_id, test_ipi_type_t ipi_type);
55 typedef enum {
56 	TEST_IPI_EVENT_BOUND_THR   = 0x1,
57 	TEST_IPI_EVENT_PREEMPT     = 0x2,
58 	TEST_IPI_EVENT_SMT_REBAL   = 0x3,
59 	TEST_IPI_EVENT_SPILL       = 0x4,
60 	TEST_IPI_EVENT_REBALANCE   = 0x5,
61 	TEST_IPI_EVENT_RT_PREEMPT  = 0x6,
62 } test_ipi_event_t; // Mirrors sched_ipi_event_t
63 extern void      cpu_send_ipi_for_thread(int cpu_id, test_thread_t thread, test_ipi_event_t event);
64 #define QOS_PARALLELISM_REALTIME        0x2
65 #define QOS_PARALLELISM_CLUSTER_SHARED_RESOURCE              0x4
66 extern bool      max_parallelism_expect(int qos, uint64_t options, uint32_t expected_parallelism);
67