Thread local storage for x86
[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 #include <workqueue.h>
19
20 #ifdef __SHARC__
21 typedef sharC_env_t;
22 #endif
23
24 struct per_cpu_info {
25         spinlock_t lock;
26         struct proc *cur_proc;
27         trapframe_t *cur_tf;
28         bool preempt_pending;
29         struct workqueue NTPTV(t) workqueue;
30
31 #ifdef __SHARC__
32         // held spin-locks. this will have to go elsewhere if multiple kernel
33         // threads can share a CPU.
34         // zra: Used by Ivy. Let me know if this should go elsewhere.
35         sharC_env_t sharC_env;
36 #endif
37 #ifdef __i386__
38         segdesc_t *gdt;
39 #endif
40
41         spinlock_t amsg_lock;
42         struct active_msg_list NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) active_msgs;
43 }__attribute__((aligned(HW_CACHE_ALIGN)));
44
45 typedef struct per_cpu_info NTPTV(t) NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) per_cpu_info_t;
46
47 extern per_cpu_info_t (RO per_cpu_info)[MAX_NUM_CPUS];
48 extern volatile uint32_t RO num_cpus;
49
50 /* SMP bootup functions */
51 void smp_boot(void);
52 void smp_idle(void);
53 void smp_percpu_init(void); // this must be called by each core individually
54
55 /* SMP utility functions */
56 int smp_call_function_self(poly_isr_t handler, TV(t) data,
57                            handler_wrapper_t** wait_wrapper);
58 int smp_call_function_all(poly_isr_t handler, TV(t) data,
59                           handler_wrapper_t** wait_wrapper);
60 int smp_call_function_single(uint32_t dest, poly_isr_t handler, TV(t) data,
61                              handler_wrapper_t** wait_wrapper);
62 int smp_call_wait(handler_wrapper_t*SAFE wrapper);
63
64 #endif /* !ROS_INC_SMP_H */