Kthreads stop zeroing the current_tf
[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 <syscall.h>
19
20 #ifdef __SHARC__
21 typedef sharC_env_t;
22 #endif
23
24 struct per_cpu_info {
25         spinlock_t lock;
26         /* Process management */
27         // cur_proc should be valid on all cores that are not management cores.
28         struct proc *cur_proc;
29         trapframe_t *cur_tf;
30         struct kthread *spare;          /* useful when restarting */
31         /* Syscall management */
32         // TODO: 2 sysc
33         struct syscall *syscalls;       /* ptr is into cur_proc's address space */
34         unsigned int nr_calls;
35         int *errno_loc;
36         uintreg_t *tf_retval_loc;
37
38 #ifdef __SHARC__
39         // held spin-locks. this will have to go elsewhere if multiple kernel
40         // threads can share a CPU.
41         // zra: Used by Ivy. Let me know if this should go elsewhere.
42         sharC_env_t sharC_env;
43 #endif
44 #ifdef __i386__
45         taskstate_t *tss;
46         segdesc_t *gdt;
47 #endif
48         /* KMSGs */
49         spinlock_t immed_amsg_lock;
50         struct kernel_msg_list NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) immed_amsgs;
51         spinlock_t routine_amsg_lock;
52         struct kernel_msg_list NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) routine_amsgs;
53 }__attribute__((aligned(HW_CACHE_ALIGN)));
54
55 typedef struct per_cpu_info NTPTV(t) NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) per_cpu_info_t;
56
57 extern per_cpu_info_t (RO per_cpu_info)[MAX_NUM_CPUS];
58 extern volatile uint32_t RO num_cpus;
59
60 /* SMP bootup functions */
61 void smp_boot(void);
62 void smp_idle(void) __attribute__((noreturn));
63 void smp_percpu_init(void); // this must be called by each core individually
64
65 /* SMP utility functions */
66 int smp_call_function_self(poly_isr_t handler, TV(t) data,
67                            handler_wrapper_t** wait_wrapper);
68 int smp_call_function_all(poly_isr_t handler, TV(t) data,
69                           handler_wrapper_t** wait_wrapper);
70 int smp_call_function_single(uint32_t dest, poly_isr_t handler, TV(t) data,
71                              handler_wrapper_t** wait_wrapper);
72 int smp_call_wait(handler_wrapper_t*SAFE wrapper);
73
74 #endif /* !ROS_INC_SMP_H */