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 cluster_id; 22 int die_id; 23 } test_pset_t; 24 25 typedef struct { 26 test_pset_t *psets; 27 int num_psets; 28 int total_cpus; 29 } test_hw_topology_t; 30 31 extern int pset_id_to_cpu_id(int pset_id); 32 extern int cpu_id_to_pset_id(int cpu_id); 33 extern test_hw_topology_t get_hw_topology(void); 34 extern void set_hw_topology(test_hw_topology_t hw_topology); 35 extern char test_cpu_type_to_char(test_cpu_type_t cpu_type); 36 37 /* Given topologies */ 38 extern test_hw_topology_t single_core; // 1P 39 extern test_hw_topology_t basic_amp; // 2P + 4E 40 extern test_hw_topology_t dual_die; // 2E + 4P + 4P + 2E + 4P + 4P 41 42 /* Test harness utilities */ 43 extern void init_migration_harness(test_hw_topology_t hw_topology); 44 extern void set_tg_sched_bucket_preferred_pset(struct thread_group *tg, int sched_bucket, int cluster_id); 45 extern void set_thread_cluster_bound(test_thread_t thread, int cluster_id); 46 extern int choose_pset_for_thread(test_thread_t thread); 47 extern bool choose_pset_for_thread_expect(test_thread_t thread, int expected_cluster_id); 48 extern test_thread_t cpu_steal_thread(int cpu_id); 49 extern bool cpu_processor_balance(int cpu_id); 50 extern bool thread_avoid_processor_expect(test_thread_t thread, int cpu_id, bool quantum_expiry, bool avoid_expected); 51 extern void cpu_expire_quantum(int cpu_id); 52 extern void set_current_processor(int cpu_id); 53 /* Note that load avg will be overriden by cpu_set_thread_current() or enqueue_thread() operations */ 54 extern void set_pset_load_avg(int cluster_id, int QoS, uint64_t load_avg); 55 extern void set_pset_recommended(int cluster_id); 56 extern void set_pset_derecommended(int cluster_id); 57 typedef enum { 58 TEST_IPI_NONE = 0x0, 59 TEST_IPI_IMMEDIATE = 0x1, 60 TEST_IPI_IDLE = 0x2, 61 TEST_IPI_DEFERRED = 0x3, 62 } test_ipi_type_t; // Mirrors sched_ipi_type_t 63 extern bool ipi_expect(int cpu_id, test_ipi_type_t ipi_type); 64 typedef enum { 65 TEST_IPI_EVENT_BOUND_THR = 0x1, 66 TEST_IPI_EVENT_PREEMPT = 0x2, 67 TEST_IPI_EVENT_SMT_REBAL = 0x3, 68 TEST_IPI_EVENT_SPILL = 0x4, 69 TEST_IPI_EVENT_REBALANCE = 0x5, 70 TEST_IPI_EVENT_RT_PREEMPT = 0x6, 71 } test_ipi_event_t; // Mirrors sched_ipi_event_t 72 extern void cpu_send_ipi_for_thread(int cpu_id, test_thread_t thread, test_ipi_event_t event); 73 #define QOS_PARALLELISM_REALTIME 0x2 74 #define QOS_PARALLELISM_CLUSTER_SHARED_RESOURCE 0x4 75 extern bool max_parallelism_expect(int qos, uint64_t options, uint32_t expected_parallelism); 76 extern int iterate_pset_search_order_expect(int src_pset_id, uint64_t candidate_map, int sched_bucket, int *expected_pset_ids, int num_psets); 77