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 36 /* Given topologies */ 37 extern test_hw_topology_t single_core; // 1P 38 extern test_hw_topology_t basic_amp; // 2P + 4E 39 extern test_hw_topology_t dual_die; // 2E + 4P + 4P + 2E + 4P + 4P 40 41 /* Test harness utilities */ 42 extern void init_migration_harness(test_hw_topology_t hw_topology); 43 extern void set_tg_sched_bucket_preferred_pset(struct thread_group *tg, int sched_bucket, int cluster_id); 44 extern void set_thread_cluster_bound(test_thread_t thread, int cluster_id); 45 extern int choose_pset_for_thread(test_thread_t thread); 46 extern bool choose_pset_for_thread_expect(test_thread_t thread, int expected_cluster_id); 47 extern test_thread_t cpu_steal_thread(int cpu_id); 48 extern bool cpu_processor_balance(int cpu_id); 49 extern bool thread_avoid_processor_expect(test_thread_t thread, int cpu_id, bool quantum_expiry, bool avoid_expected); 50 extern void cpu_expire_quantum(int cpu_id); 51 extern void set_current_processor(int cpu_id); 52 extern void set_pset_load_avg(int cluster_id, int QoS, uint64_t load_avg); 53 extern void set_pset_recommended(int cluster_id); 54 extern void set_pset_derecommended(int cluster_id); 55 typedef enum { 56 TEST_IPI_NONE = 0x0, 57 TEST_IPI_IMMEDIATE = 0x1, 58 TEST_IPI_IDLE = 0x2, 59 TEST_IPI_DEFERRED = 0x3, 60 } test_ipi_type_t; // Mirrors sched_ipi_type_t 61 extern bool ipi_expect(int cpu_id, test_ipi_type_t ipi_type); 62 typedef enum { 63 TEST_IPI_EVENT_BOUND_THR = 0x1, 64 TEST_IPI_EVENT_PREEMPT = 0x2, 65 TEST_IPI_EVENT_SMT_REBAL = 0x3, 66 TEST_IPI_EVENT_SPILL = 0x4, 67 TEST_IPI_EVENT_REBALANCE = 0x5, 68 TEST_IPI_EVENT_RT_PREEMPT = 0x6, 69 } test_ipi_event_t; // Mirrors sched_ipi_event_t 70 extern void cpu_send_ipi_for_thread(int cpu_id, test_thread_t thread, test_ipi_event_t event); 71 #define QOS_PARALLELISM_REALTIME 0x2 72 #define QOS_PARALLELISM_CLUSTER_SHARED_RESOURCE 0x4 73 extern bool max_parallelism_expect(int qos, uint64_t options, uint32_t expected_parallelism); 74 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); 75