Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions common/inc/tx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,19 @@ UINT _tx_trace_interrupt_control(UINT new_posture);
#endif


/* Define the number of consecutive stack fill pattern words the thread stack analyze function must
observe, working towards the lowest address of the stack, before it accepts a probe location as
unused. A value of one restores the original behavior, where a single word that happens to still
hold the fill pattern - an unwritten hole inside an otherwise used region, such as the padding of
a partially initialized local array - can make the binary search stop early and under-report the
stack usage. Larger values make the result more accurate at the cost of a few additional reads
per binary search iteration. This can be re-defined in tx_port.h. */

#ifndef TX_THREAD_STACK_ANALYZE_FILL_WORDS
#define TX_THREAD_STACK_ANALYZE_FILL_WORDS ((ULONG) 8)
#endif


/* Add a default macro that can be re-defined in tx_port.h to add processing to the initialize kernel enter function.
By default, this is simply defined as whitespace. */

Expand Down
50 changes: 48 additions & 2 deletions common/src/tx_thread_stack_analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* SPDX-License-Identifier: MIT
**************************************************************************/

// Some portions generated by Copilot (Opus 5).


/**************************************************************************/
/**************************************************************************/
Expand Down Expand Up @@ -70,6 +72,9 @@ TX_INTERRUPT_SAVE_AREA
ULONG *stack_ptr;
ULONG *stack_lowest;
ULONG *stack_highest;
ULONG *probe_ptr;
ULONG probe_count;
UINT fill_present;
ULONG size;


Expand Down Expand Up @@ -110,8 +115,49 @@ ULONG size;
size = (ULONG) (TX_ULONG_POINTER_DIF(stack_highest, stack_lowest))/((ULONG) 2);
stack_ptr = TX_ULONG_POINTER_ADD(stack_lowest, size);

/* Determine if the pattern is still there. */
if (*stack_ptr != TX_STACK_FILL)
/* Determine if the pattern is still there. To avoid stopping on an
unwritten hole inside an otherwise used region, require several
consecutive fill words, working towards the lowest address. The scan
stops at the lowest known fill location, since everything at or below
that point is already known to hold the fill pattern. */
fill_present = TX_TRUE;
probe_ptr = stack_ptr;
probe_count = TX_THREAD_STACK_ANALYZE_FILL_WORDS;
while (probe_count != ((ULONG) 0))
{

/* Determine if this word still holds the fill pattern. */
if (*probe_ptr != TX_STACK_FILL)
{

/* No, the probe location is in use. */
fill_present = TX_FALSE;
probe_count = ((ULONG) 0);
}
else
{

/* Yes, account for this word. */
probe_count--;

/* Determine if the lowest known fill location has been reached. */
if (probe_ptr <= stack_lowest)
{

/* Yes, nothing further to check. */
probe_count = ((ULONG) 0);
}
else
{

/* Position to the previous word in the stack. */
probe_ptr = TX_ULONG_POINTER_SUB(probe_ptr, 1);
}
}
}

/* Determine if the probe location is in use. */
if (fill_present == TX_FALSE)
{

/* Update the stack highest, since we need to look in the upper half now. */
Expand Down
13 changes: 13 additions & 0 deletions common_smp/inc/tx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,19 @@ UINT _tx_trace_interrupt_control(UINT new_posture);
#endif


/* Define the number of consecutive stack fill pattern words the thread stack analyze function must
observe, working towards the lowest address of the stack, before it accepts a probe location as
unused. A value of one restores the original behavior, where a single word that happens to still
hold the fill pattern - an unwritten hole inside an otherwise used region, such as the padding of
a partially initialized local array - can make the binary search stop early and under-report the
stack usage. Larger values make the result more accurate at the cost of a few additional reads
per binary search iteration. This can be re-defined in tx_port.h. */

#ifndef TX_THREAD_STACK_ANALYZE_FILL_WORDS
#define TX_THREAD_STACK_ANALYZE_FILL_WORDS ((ULONG) 8)
#endif


/* Add a default macro that can be re-defined in tx_port.h to add processing to the initialize kernel enter function.
By default, this is simply defined as whitespace. */

Expand Down
50 changes: 48 additions & 2 deletions common_smp/src/tx_thread_stack_analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* SPDX-License-Identifier: MIT
**************************************************************************/

// Some portions generated by Copilot (Opus 5).


/**************************************************************************/
/**************************************************************************/
Expand Down Expand Up @@ -70,6 +72,9 @@ TX_INTERRUPT_SAVE_AREA
ULONG *stack_ptr;
ULONG *stack_lowest;
ULONG *stack_highest;
ULONG *probe_ptr;
ULONG probe_count;
UINT fill_present;
ULONG size;


Expand Down Expand Up @@ -110,8 +115,49 @@ ULONG size;
size = (ULONG) (TX_ULONG_POINTER_DIF(stack_highest, stack_lowest))/((ULONG) 2);
stack_ptr = TX_ULONG_POINTER_ADD(stack_lowest, size);

/* Determine if the pattern is still there. */
if (*stack_ptr != TX_STACK_FILL)
/* Determine if the pattern is still there. To avoid stopping on an
unwritten hole inside an otherwise used region, require several
consecutive fill words, working towards the lowest address. The scan
stops at the lowest known fill location, since everything at or below
that point is already known to hold the fill pattern. */
fill_present = TX_TRUE;
probe_ptr = stack_ptr;
probe_count = TX_THREAD_STACK_ANALYZE_FILL_WORDS;
while (probe_count != ((ULONG) 0))
{

/* Determine if this word still holds the fill pattern. */
if (*probe_ptr != TX_STACK_FILL)
{

/* No, the probe location is in use. */
fill_present = TX_FALSE;
probe_count = ((ULONG) 0);
}
else
{

/* Yes, account for this word. */
probe_count--;

/* Determine if the lowest known fill location has been reached. */
if (probe_ptr <= stack_lowest)
{

/* Yes, nothing further to check. */
probe_count = ((ULONG) 0);
}
else
{

/* Position to the previous word in the stack. */
probe_ptr = TX_ULONG_POINTER_SUB(probe_ptr, 1);
}
}
}

/* Determine if the probe location is in use. */
if (fill_present == TX_FALSE)
{

/* Update the stack highest, since we need to look in the upper half now. */
Expand Down
Loading