xref: /haiku/headers/private/kernel/cpu.h (revision 45b01eb84189a623981270a02d21c7a8cb93a9e1)
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 <boot/kernel_args.h>
17 #include <arch/cpu.h>
18 
19 
20 // define PAUSE, if not done in arch/cpu.h
21 #ifndef PAUSE
22 #	define PAUSE()
23 #endif
24 
25 
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 
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 status_t cpu_preboot_init_percpu(struct kernel_args *args, int curr_cpu);
66 status_t cpu_init(struct kernel_args *args);
67 status_t cpu_init_percpu(kernel_args *ka, int curr_cpu);
68 status_t cpu_init_post_vm(struct kernel_args *args);
69 status_t cpu_init_post_modules(struct kernel_args *args);
70 bigtime_t cpu_get_active_time(int32 cpu);
71 
72 cpu_ent *get_cpu_struct(void);
73 extern inline cpu_ent *get_cpu_struct(void) { return &gCPU[smp_get_current_cpu()]; }
74 
75 void _user_clear_caches(void *address, size_t length, uint32 flags);
76 bool _user_cpu_enabled(int32 cpu);
77 status_t _user_set_cpu_enabled(int32 cpu, bool enabled);
78 
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 #endif	/* _KERNEL_CPU_H */
84