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 27 namespace BKernel { 28 struct Thread; 29 } 30 31 using BKernel::Thread; 32 33 34 /* CPU local data structure */ 35 36 typedef struct cpu_ent { 37 int cpu_num; 38 39 // thread.c: used to force a reschedule at quantum expiration time 40 int preempted; 41 timer quantum_timer; 42 43 // keeping track of CPU activity 44 bigtime_t active_time; 45 bigtime_t last_kernel_time; 46 bigtime_t last_user_time; 47 48 // used in the kernel debugger 49 addr_t fault_handler; 50 addr_t fault_handler_stack_pointer; 51 jmp_buf fault_jump_buffer; 52 53 Thread* running_thread; 54 Thread* previous_thread; 55 bool invoke_scheduler; 56 bool invoke_scheduler_if_idle; 57 bool disabled; 58 59 // arch-specific stuff 60 arch_cpu_info arch; 61 } cpu_ent __attribute__((aligned(64))); 62 63 64 //extern cpu_ent gCPU[MAX_BOOT_CPUS]; 65 extern cpu_ent gCPU[]; 66 67 68 #ifdef __cplusplus 69 extern "C" { 70 #endif 71 72 status_t cpu_preboot_init_percpu(struct kernel_args *args, int curr_cpu); 73 status_t cpu_init(struct kernel_args *args); 74 status_t cpu_init_percpu(struct kernel_args *ka, int curr_cpu); 75 status_t cpu_init_post_vm(struct kernel_args *args); 76 status_t cpu_init_post_modules(struct kernel_args *args); 77 bigtime_t cpu_get_active_time(int32 cpu); 78 79 cpu_ent *get_cpu_struct(void); 80 extern inline cpu_ent *get_cpu_struct(void) { return &gCPU[smp_get_current_cpu()]; } 81 82 void _user_clear_caches(void *address, size_t length, uint32 flags); 83 bool _user_cpu_enabled(int32 cpu); 84 status_t _user_set_cpu_enabled(int32 cpu, bool enabled); 85 86 #ifdef __cplusplus 87 } 88 #endif 89 90 #endif /* _KERNEL_CPU_H */ 91