@@ -50,19 +50,12 @@ pub struct Task {
50
50
/// restarted.
51
51
descriptor : & ' static TaskDesc ,
52
52
53
- /// Tracks the lowest stack pointer value (e.g. fullest stack) observed on
54
- /// any kernel entry for this instance of this task.
53
+ /// Stack watermark tracking support.
55
54
///
56
- /// Initialized to `u32::MAX` if the task has not yet run.
55
+ /// This field is completely missing if the feature is disabled to make that
56
+ /// clear to debug tools.
57
57
#[ cfg( feature = "stack-watermark" ) ]
58
- stack_pointer_low : u32 ,
59
-
60
- /// Tracks the lowest stack pointer value (e.g. fullest stack) observed on
61
- /// any kernel entry across *any* instance of this task.
62
- ///
63
- /// Initialized to `u32::MAX` if the task has not yet run.
64
- #[ cfg( feature = "stack-watermark" ) ]
65
- past_stack_pointer_low : u32 ,
58
+ stack_watermark : StackWatermark ,
66
59
}
67
60
68
61
impl Task {
@@ -84,9 +77,7 @@ impl Task {
84
77
save : crate :: arch:: SavedState :: default ( ) ,
85
78
timer : crate :: task:: TimerState :: default ( ) ,
86
79
#[ cfg( feature = "stack-watermark" ) ]
87
- stack_pointer_low : u32:: MAX ,
88
- #[ cfg( feature = "stack-watermark" ) ]
89
- past_stack_pointer_low : u32:: MAX ,
80
+ stack_watermark : StackWatermark :: default ( ) ,
90
81
}
91
82
}
92
83
@@ -341,9 +332,11 @@ impl Task {
341
332
342
333
#[ cfg( feature = "stack-watermark" ) ]
343
334
{
344
- self . past_stack_pointer_low =
345
- u32:: min ( self . past_stack_pointer_low , self . stack_pointer_low ) ;
346
- self . stack_pointer_low = u32:: MAX ;
335
+ self . stack_watermark . past_low = u32:: min (
336
+ self . stack_watermark . past_low ,
337
+ self . stack_watermark . current_low ,
338
+ ) ;
339
+ self . stack_watermark . current_low = u32:: MAX ;
347
340
}
348
341
349
342
crate :: arch:: reinitialize ( self ) ;
@@ -356,8 +349,10 @@ impl Task {
356
349
pub fn update_stack_watermark ( & mut self ) {
357
350
#[ cfg( feature = "stack-watermark" ) ]
358
351
{
359
- self . stack_pointer_low =
360
- u32:: min ( self . stack_pointer_low , self . save ( ) . stack_pointer ( ) ) ;
352
+ self . stack_watermark . current_low = u32:: min (
353
+ self . stack_watermark . current_low ,
354
+ self . save ( ) . stack_pointer ( ) ,
355
+ ) ;
361
356
}
362
357
}
363
358
@@ -418,6 +413,32 @@ impl Task {
418
413
}
419
414
}
420
415
416
+ #[ cfg( feature = "stack-watermark" ) ]
417
+ #[ derive( Copy , Clone , Debug ) ]
418
+ struct StackWatermark {
419
+ /// Tracks the lowest stack pointer value (e.g. fullest stack) observed on
420
+ /// any kernel entry for this instance of this task.
421
+ ///
422
+ /// Initialized to `u32::MAX` if the task has not yet run.
423
+ current_low : u32 ,
424
+
425
+ /// Tracks the lowest stack pointer value (e.g. fullest stack) observed on
426
+ /// any kernel entry across *any* instance of this task.
427
+ ///
428
+ /// Initialized to `u32::MAX` if the task has not yet run.
429
+ past_low : u32 ,
430
+ }
431
+
432
+ #[ cfg( feature = "stack-watermark" ) ]
433
+ impl Default for StackWatermark {
434
+ fn default ( ) -> Self {
435
+ Self {
436
+ current_low : u32:: MAX ,
437
+ past_low : u32:: MAX ,
438
+ }
439
+ }
440
+ }
441
+
421
442
/// Interface that must be implemented by the `arch::SavedState` type. This
422
443
/// gives architecture-independent access to task state for the rest of the
423
444
/// kernel.
0 commit comments