1 /* 2 * Copyright 2002-2006, Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Copyright 2002, Travis Geiselbrecht. All rights reserved. 6 * Distributed under the terms of the NewOS License. 7 */ 8 #ifndef _KERNEL_CPU_H 9 #define _KERNEL_CPU_H 10 11 12 #include <setjmp.h> 13 14 #include <smp.h> 15 #include <timer.h> 16 #include <arch/cpu.h> 17 18 19 // define PAUSE, if not done in arch/cpu.h 20 #ifndef PAUSE 21 # define PAUSE() 22 #endif 23 24 25 struct kernel_args; 26 struct thread; 27 28 29 /* CPU local data structure */ 30 31 typedef struct cpu_ent { 32 int cpu_num; 33 34 // thread.c: used to force a reschedule at quantum expiration time 35 int preempted; 36 timer quantum_timer; 37 38 // keeping track of CPU activity 39 bigtime_t active_time; 40 bigtime_t last_kernel_time; 41 bigtime_t last_user_time; 42 43 // used in the kernel debugger 44 addr_t fault_handler; 45 addr_t fault_handler_stack_pointer; 46 jmp_buf fault_jump_buffer; 47 48 struct thread* running_thread; 49 bool invoke_scheduler; 50 bool invoke_scheduler_if_idle; 51 bool disabled; 52 53 // arch-specific stuff 54 arch_cpu_info arch; 55 } cpu_ent __attribute__((aligned(64))); 56 57 58 //extern cpu_ent gCPU[MAX_BOOT_CPUS]; 59 extern cpu_ent gCPU[]; 60 61 62 #ifdef __cplusplus 63 extern "C" { 64 #endif 65 66 status_t cpu_preboot_init_percpu(struct kernel_args *args, int curr_cpu); 67 status_t cpu_init(struct kernel_args *args); 68 status_t cpu_init_percpu(struct kernel_args *ka, int curr_cpu); 69 status_t cpu_init_post_vm(struct kernel_args *args); 70 status_t cpu_init_post_modules(struct kernel_args *args); 71 bigtime_t cpu_get_active_time(int32 cpu); 72 73 cpu_ent *get_cpu_struct(void); 74 extern inline cpu_ent *get_cpu_struct(void) { return &gCPU[smp_get_current_cpu()]; } 75 76 void _user_clear_caches(void *address, size_t length, uint32 flags); 77 bool _user_cpu_enabled(int32 cpu); 78 status_t _user_set_cpu_enabled(int32 cpu, bool enabled); 79 80 #ifdef __cplusplus 81 } 82 #endif 83 84 #endif /* _KERNEL_CPU_H */ 85