• 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_FPU_H
13 #define SCHED_FPU_H
14 
15 #include <object/thread.h>
16 #include <sched/sched.h>
17 
18 #define EAGER_FPU_MODE 0
19 #define LAZY_FPU_MODE  1
20 
21 /* RISC-V only supports eager mode. */
22 #ifdef CHCORE_ARCH_RISCV64
23 #define FPU_SAVING_MODE EAGER_FPU_MODE
24 #else
25 #define FPU_SAVING_MODE LAZY_FPU_MODE
26 #endif
27 
28 void arch_init_thread_fpu(struct thread_ctx *ctx);
29 
30 void save_fpu_state(struct thread *thread);
31 void restore_fpu_state(struct thread *thread);
32 
33 #if FPU_SAVING_MODE == LAZY_FPU_MODE
34 void disable_fpu_usage(void);
35 void enable_fpu_usage(void);
36 
37 /* Used when hanlding FPU traps */
38 void change_fpu_owner(void);
39 /* Used when migrating a thread from local CPU to other CPUs */
40 void save_and_release_fpu(struct thread *thread);
41 void save_and_release_fpu_owner(void);
42 #endif
43 
44 #endif /* SCHED_FPU_H */