MCPs -> Many Filthy _S Ps
[akaros.git] / kern / include / smp.h
1 /*
2  * Copyright (c) 2009 The Regents of the University of California
3  * Barret Rhoden <brho@cs.berkeley.edu>
4  * See LICENSE for details.
5  */
6
7 #ifndef ROS_INC_SMP_H
8 #define ROS_INC_SMP_H
9
10 /* SMP related functions */
11
12 #include <arch/smp.h>
13 #include <ros/common.h>
14 #include <sys/queue.h>
15 #include <trap.h>
16 #include <atomic.h>
17 #include <process.h>
18
19 #ifdef __SHARC__
20 typedef sharC_env_t;
21 #endif
22
23 struct per_cpu_info {
24         spinlock_t lock;
25         struct proc *cur_proc;
26         trapframe_t *cur_tf;
27
28 #ifdef __SHARC__
29         // held spin-locks. this will have to go elsewhere if multiple kernel
30         // threads can share a CPU.
31         // zra: Used by Ivy. Let me know if this should go elsewhere.
32         sharC_env_t sharC_env;
33 #endif
34 #ifdef __i386__
35         segdesc_t *gdt;
36 #endif
37
38         spinlock_t immed_amsg_lock;
39         struct kernel_msg_list NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) immed_amsgs;
40         spinlock_t routine_amsg_lock;
41         struct kernel_msg_list NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) routine_amsgs;
42 #ifdef __CONFIG_EXPER_TRADPROC__
43         spinlock_t runqueue_lock;
44         struct proc_list runqueue;
45 #endif /* __CONFIG_EXPER_TRADPROC__ */
46 }__attribute__((aligned(HW_CACHE_ALIGN)));
47
48 typedef struct per_cpu_info NTPTV(t) NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) per_cpu_info_t;
49
50 extern per_cpu_info_t (RO per_cpu_info)[MAX_NUM_CPUS];
51 extern volatile uint32_t RO num_cpus;
52
53 /* SMP bootup functions */
54 void smp_boot(void);
55 void smp_idle(void) __attribute__((noreturn));
56 void smp_percpu_init(void); // this must be called by each core individually
57
58 /* SMP utility functions */
59 int smp_call_function_self(poly_isr_t handler, TV(t) data,
60                            handler_wrapper_t** wait_wrapper);
61 int smp_call_function_all(poly_isr_t handler, TV(t) data,
62                           handler_wrapper_t** wait_wrapper);
63 int smp_call_function_single(uint32_t dest, poly_isr_t handler, TV(t) data,
64                              handler_wrapper_t** wait_wrapper);
65 int smp_call_wait(handler_wrapper_t*SAFE wrapper);
66
67 #ifdef __CONFIG_EXPER_TRADPROC__
68
69 #define TIMER_uSEC 10000
70
71 void local_schedule(void);
72 void local_schedule_proc(uint32_t core, struct proc *p);
73
74 #endif /* __CONFIG_EXPER_TRADPROC__ */
75
76 #endif /* !ROS_INC_SMP_H */