• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 #ifndef SCHED_CONTEXT_H
13 #define SCHED_CONTEXT_H
14 
15 #include <arch/sched/arch_sched.h>
16 #include <common/lock.h>
17 #include <common/macro.h>
18 #include <common/types.h>
19 #include <machine.h>
20 
21 typedef struct sched_context {
22     unsigned int budget;
23     unsigned int prio;
24 } sched_ctx_t;
25 
26 /* Thread context */
27 struct thread_ctx {
28     /* Arch-dependent */
29     /* Executing Context */
30     arch_exec_ctx_t ec;
31     /* FPU States */
32     void *fpu_state;
33     /* TLS Related States */
34     unsigned long tls_base_reg[TLS_REG_NUM];
35 
36     /* Arch-independent */
37     /* Is FPU owner on some CPU: -1 means No; other means CPU ID */
38     int is_fpu_owner;
39     /* Scheduling Context */
40     sched_ctx_t *sc;
41     /* Thread Type */
42     unsigned int type;
43     /* Thread state (can not be modified by other cores) */
44     unsigned int state;
45     /* SMP Affinity */
46     int affinity;
47     /* Current Assigned CPU */
48     unsigned int cpuid;
49     /* Thread kernel stack state */
50     volatile unsigned int kernel_stack_state;
51     /* Thread exit state */
52     volatile unsigned int thread_exit_state;
53 } __attribute__((aligned(CACHELINE_SZ)));
54 
55 struct thread;
56 
57 extern struct lock fpu_owner_locks[PLAT_CPU_NUM];
58 
59 struct thread_ctx *create_thread_ctx(unsigned int type);
60 void destroy_thread_ctx(struct thread *thread);
61 void init_thread_ctx(struct thread *thread, vaddr_t stack, vaddr_t func,
62                      unsigned int prio, unsigned int type, int aff);
63 
64 /* Arch-dependent */
65 void arch_set_thread_stack(struct thread *thread, vaddr_t stack);
66 void arch_set_thread_return(struct thread *thread, unsigned long ret);
67 vaddr_t arch_get_thread_stack(struct thread *thread);
68 void arch_set_thread_next_ip(struct thread *thread, vaddr_t ip);
69 vaddr_t arch_get_thread_next_ip(struct thread *thread);
70 void arch_set_thread_arg0(struct thread *thread, unsigned long arg);
71 void arch_set_thread_arg1(struct thread *thread, unsigned long arg);
72 void arch_set_thread_arg2(struct thread *thread, unsigned long arg);
73 void arch_set_thread_arg3(struct thread *thread, unsigned long arg);
74 void arch_set_thread_tls(struct thread *thread, unsigned long tls);
75 void set_thread_arch_spec_state(struct thread *thread);
76 void set_thread_arch_spec_state_ipc(struct thread *thread);
77 void switch_tls_info(struct thread *from, struct thread *to);
78 
79 #endif /* SCHED_CONTEXT_H */