@@ -17,6 +17,7 @@ mod task;
17
17
use crate :: config:: MAX_APP_NUM ;
18
18
use crate :: loader:: { get_num_app, init_app_cx} ;
19
19
use crate :: sync:: UPSafeCell ;
20
+ use crate :: syscall:: { SYSCALL_EXIT , SYSCALL_GET_TIME , SYSCALL_TRACE , SYSCALL_WRITE , SYSCALL_YIELD } ;
20
21
use lazy_static:: * ;
21
22
use switch:: __switch;
22
23
pub use task:: { TaskControlBlock , TaskStatus } ;
@@ -51,10 +52,7 @@ lazy_static! {
51
52
/// Global variable: TASK_MANAGER
52
53
pub static ref TASK_MANAGER : TaskManager = {
53
54
let num_app = get_num_app( ) ;
54
- let mut tasks = [ TaskControlBlock {
55
- task_cx: TaskContext :: zero_init( ) ,
56
- task_status: TaskStatus :: UnInit ,
57
- } ; MAX_APP_NUM ] ;
55
+ let mut tasks = [ TaskControlBlock :: new( ) ; MAX_APP_NUM ] ;
58
56
for ( i, task) in tasks. iter_mut( ) . enumerate( ) {
59
57
task. task_cx = TaskContext :: goto_restore( init_app_cx( i) ) ;
60
58
task. task_status = TaskStatus :: Ready ;
@@ -169,3 +167,37 @@ pub fn exit_current_and_run_next() {
169
167
mark_current_exited ( ) ;
170
168
run_next_task ( ) ;
171
169
}
170
+
171
+ /// Modified: to inc syscall_time in the TCB of current task
172
+
173
+ pub fn inc_current_syscall_times ( syscall_id : usize ) {
174
+ let mut inner = TASK_MANAGER . inner . exclusive_access ( ) ;
175
+ let current_app_id = inner. current_task ;
176
+ let current_tcb = inner. tasks . get_mut ( current_app_id) . unwrap ( ) ;
177
+
178
+ match syscall_id {
179
+ SYSCALL_WRITE => current_tcb. sys_write_times += 1 ,
180
+ SYSCALL_EXIT => current_tcb. sys_exit_times += 1 ,
181
+ SYSCALL_YIELD => current_tcb. sys_yield_times += 1 ,
182
+ SYSCALL_GET_TIME => current_tcb. sys_get_time_times += 1 ,
183
+ SYSCALL_TRACE => current_tcb. sys_trace_times += 1 ,
184
+ _ => panic ! ( "Unsupported syscall_id: {}" , syscall_id) ,
185
+ }
186
+ }
187
+
188
+ /// Modified: to query syscall_time in the TCB of current task
189
+
190
+ pub fn query_current_syscall_times ( syscall_id : usize ) -> usize {
191
+ let inner = TASK_MANAGER . inner . exclusive_access ( ) ;
192
+ let current_app_id = inner. current_task ;
193
+ let current_tcb = inner. tasks . get ( current_app_id) . unwrap ( ) ;
194
+
195
+ match syscall_id {
196
+ SYSCALL_WRITE => current_tcb. sys_write_times ,
197
+ SYSCALL_EXIT => current_tcb. sys_exit_times ,
198
+ SYSCALL_YIELD => current_tcb. sys_yield_times ,
199
+ SYSCALL_GET_TIME => current_tcb. sys_get_time_times ,
200
+ SYSCALL_TRACE => current_tcb. sys_trace_times ,
201
+ _ => panic ! ( "Unsupported syscall_id: {}" , syscall_id) ,
202
+ }
203
+ }
0 commit comments