Load balancing for EXPER_TRADPROC
[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         unsigned int ticks; /* how many times the tick went off.  can roll over */
44         spinlock_t runqueue_lock;
45         struct proc_list runqueue;
46 #endif /* __CONFIG_EXPER_TRADPROC__ */
47 }__attribute__((aligned(HW_CACHE_ALIGN)));
48
49 typedef struct per_cpu_info NTPTV(t) NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) per_cpu_info_t;
50
51 extern per_cpu_info_t (RO per_cpu_info)[MAX_NUM_CPUS];
52 extern volatile uint32_t RO num_cpus;
53
54 /* SMP bootup functions */
55 void smp_boot(void);
56 void smp_idle(void) __attribute__((noreturn));
57 void smp_percpu_init(void); // this must be called by each core individually
58
59 /* SMP utility functions */
60 int smp_call_function_self(poly_isr_t handler, TV(t) data,
61                            handler_wrapper_t** wait_wrapper);
62 int smp_call_function_all(poly_isr_t handler, TV(t) data,
63                           handler_wrapper_t** wait_wrapper);
64 int smp_call_function_single(uint32_t dest, poly_isr_t handler, TV(t) data,
65                              handler_wrapper_t** wait_wrapper);
66 int smp_call_wait(handler_wrapper_t*SAFE wrapper);
67
68 #ifdef __CONFIG_EXPER_TRADPROC__
69
70 #define TIMER_uSEC 10000
71
72 void local_schedule(void);
73 void local_schedule_proc(uint32_t core, struct proc *p);
74 void load_balance(void);
75
76 #endif /* __CONFIG_EXPER_TRADPROC__ */
77
78 #endif /* !ROS_INC_SMP_H */