Skip to content

Commit

Permalink
Two basic structures for consideration
Browse files Browse the repository at this point in the history
This is not a mergeable commit, as it includes modifications
to things that should not be committed upstream.
  • Loading branch information
Greg Link committed Jan 9, 2025
1 parent 485a02f commit 73756fd
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ target_sources(freertos-threadx
)
target_link_libraries(freertos-threadx PUBLIC threadx)


set(TX_USER_FILE "${CMAKE_CURRENT_LIST_DIR}/custom_tx_user.h" CACHE PATH "Path to custom tx_user.h")

# If the user provided an override, copy it to the custom directory
if (NOT TX_USER_FILE)
message(STATUS "Using default tx_user.h file")
Expand All @@ -55,7 +58,7 @@ target_include_directories(${PROJECT_NAME}
PUBLIC
${CUSTOM_INC_DIR}
)
target_compile_definitions(${PROJECT_NAME} PUBLIC "TX_INCLUDE_USER_DEFINE_FILE" )
target_compile_definitions(${PROJECT_NAME} PUBLIC "TX_INCLUDE_USER_DEFINE_FILE" "TX_ENABLE_THREAD_SYSTEM_RESUME_EXTENSION")

# Enable a build target that produces a ZIP file of all sources
set(CPACK_SOURCE_GENERATOR "ZIP")
Expand Down
1 change: 1 addition & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ target_sources(${PROJECT_NAME}
${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_stack_error_handler.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_stack_error_notify.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_suspend.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_suspend_resume_extension.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_system_preempt_check.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_system_resume.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_thread_system_suspend.c
Expand Down
23 changes: 21 additions & 2 deletions common/inc/tx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/* APPLICATION INTERFACE DEFINITION RELEASE */
/* */
/* tx_api.h PORTABLE C */
/* 6.4.1 */
/* 6.4.2 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
Expand Down Expand Up @@ -106,7 +106,10 @@
/* 03-01-2024 Tiejun Zhou Modified comment(s), */
/* update version number, */
/* resulting in version 6.4.1 */
/* */
/* XX-XX-2025 Greg Link Modified comment(s), */
/* update version number, */
/* add resume/suspend hooks, */
/* resulting in version 6.4.2 */
/**************************************************************************/

#ifndef TX_API_H
Expand Down Expand Up @@ -1779,6 +1782,22 @@ UINT _tx_thread_terminate(TX_THREAD *thread_ptr);
UINT _tx_thread_time_slice_change(TX_THREAD *thread_ptr, ULONG new_time_slice, ULONG *old_time_slice);
UINT _tx_thread_wait_abort(TX_THREAD *thread_ptr);

/* Two alternative ways to include the proposed extensions of Issue 426.
The first expects the extension to always have the same function prototype,
but it is a proper function, while the second uses a #define in tx_user.h
to extend the functionality instead. */

#ifdef TX_ENABLE_THREAD_SYSTEM_RESUME_EXTENSION
UINT _tx_thread_system_resume_extension(TX_THREAD *thread_ptr);
#define TX_THREAD_SYSTEM_RESUME_EXTENSION(a) _tx_thread_system_resume_extension(a)
#else
#warning TX_ENABLE_THREAD_SYSTEM_RESUME_EXTENSION is disabled
#define TX_THREAD_SYSTEM_RESUME_EXTENSION(a) ((void)(a))
#endif

#ifndef TX_THREAD_SYSTEM_SUSPEND_EXTENSION
#define TX_THREAD_SYSTEM_SUSPEND_EXTENSION(a) ((void)(a))
#endif

/* Define error checking shells for API services. These are only referenced by the
application. */
Expand Down
11 changes: 7 additions & 4 deletions common/src/tx_thread_resume.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ TX_THREAD *current_thread;
ULONG combined_flags;

#ifdef TX_ENABLE_EVENT_TRACE
TX_TRACE_BUFFER_ENTRY *entry_ptr;
ULONG time_stamp = ((ULONG) 0);
TX_TRACE_BUFFER_ENTRY *entry_ptr;
ULONG time_stamp = ((ULONG) 0);
#endif

#if TX_MAX_PRIORITIES > 32
UINT map_index;
UINT map_index;
#endif


Expand Down Expand Up @@ -241,6 +241,9 @@ UINT map_index;
/* Log the thread status change. */
TX_EL_THREAD_STATUS_CHANGE_INSERT(thread_ptr, TX_READY)

/* Handle the thread resume extension, if defined*/
TX_THREAD_SYSTEM_RESUME_EXTENSION(thread_ptr);

#ifdef TX_THREAD_ENABLE_PERFORMANCE_INFO

/* Increment the total number of thread resumptions. */
Expand All @@ -261,7 +264,7 @@ UINT map_index;
thread_ptr -> tx_thread_ready_next = thread_ptr;
thread_ptr -> tx_thread_ready_previous = thread_ptr;

#if TX_MAX_PRIORITIES > 32
#if TX_MAX_PRIORITIES > 32

/* Calculate the index into the bit map array. */
map_index = priority/((UINT) 32);
Expand Down
4 changes: 4 additions & 0 deletions common/src/tx_thread_suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ ULONG time_stamp = ((ULONG) 0);
/* Log the thread status change. */
TX_EL_THREAD_STATUS_CHANGE_INSERT(thread_ptr, thread_ptr -> tx_thread_state)


/* Handle the thread suspend extension, if defined*/
TX_THREAD_SYSTEM_SUSPEND_EXTENSION(thread_ptr);

#ifdef TX_ENABLE_EVENT_TRACE

/* If trace is enabled, save the current event pointer. */
Expand Down
34 changes: 34 additions & 0 deletions common/src/tx_thread_suspend_resume_extension.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/***************************************************************************
* Copyright (c) 2025 Microsoft Corporation
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/

/* Include necessary system files. */

#include "tx_api.h"
#include "tx_trace.h"
#include "tx_thread.h"
#include "tx_initialize.h"

/* Test only, demo of user extension. If the below is not defined,
no need to include this function at all - it will never be called */
#ifdef TX_ENABLE_THREAD_SYSTEM_RESUME_EXTENSION

UINT _tx_thread_system_resume_extension(TX_THREAD *thread_ptr)
{
UINT status = 0;
if (!thread_ptr->resume_recorded)
{
thread_ptr->resume_recorded_at += 1;
}

/* Return completion status. */
return(status);
}

#endif //TX_ENABLE_THREAD_SYSTEM_RESUME_EXTENSION
12 changes: 12 additions & 0 deletions common/src/tx_thread_system_resume.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ UINT map_index;
/* Log the thread status change. */
TX_EL_THREAD_STATUS_CHANGE_INSERT(thread_ptr, TX_READY)

/* Handle the thread resume extension, if defined*/
TX_THREAD_SYSTEM_RESUME_EXTENSION(thread_ptr);

#ifdef TX_THREAD_ENABLE_PERFORMANCE_INFO

/* Increment the total number of thread resumptions. */
Expand Down Expand Up @@ -435,6 +438,9 @@ UINT map_index;

/* Log the thread status change. */
TX_EL_THREAD_STATUS_CHANGE_INSERT(thread_ptr, TX_READY)

/* Handle the thread resume extension, if defined*/
TX_THREAD_SYSTEM_RESUME_EXTENSION(thread_ptr);
}
else
{
Expand Down Expand Up @@ -600,6 +606,9 @@ UINT state;
/* Log the thread status change. */
TX_EL_THREAD_STATUS_CHANGE_INSERT(thread_ptr, TX_READY)

/* Handle the thread resume extension, if defined*/
TX_THREAD_SYSTEM_RESUME_EXTENSION(thread_ptr);

#ifdef TX_THREAD_ENABLE_PERFORMANCE_INFO

/* Increment the total number of thread resumptions. */
Expand Down Expand Up @@ -702,6 +711,9 @@ UINT map_index;
/* Log the thread status change. */
TX_EL_THREAD_STATUS_CHANGE_INSERT(thread_ptr, TX_READY)

/* Handle the thread resume extension, if defined*/
TX_THREAD_SYSTEM_RESUME_EXTENSION(thread_ptr);

/* Pickup priority of thread. */
priority = thread_ptr -> tx_thread_priority;

Expand Down
6 changes: 6 additions & 0 deletions common/src/tx_thread_system_suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ ULONG time_stamp = ((ULONG) 0);
/* Log the thread status change. */
TX_EL_THREAD_STATUS_CHANGE_INSERT(thread_ptr, thread_ptr -> tx_thread_state)

/* Handle the thread suspend extension, if defined*/
TX_THREAD_SYSTEM_SUSPEND_EXTENSION(thread_ptr);

#ifdef TX_ENABLE_EVENT_TRACE

/* If trace is enabled, save the current event pointer. */
Expand Down Expand Up @@ -761,6 +764,9 @@ ULONG time_stamp = ((ULONG) 0);
/* Log the thread status change. */
TX_EL_THREAD_STATUS_CHANGE_INSERT(thread_ptr, thread_ptr -> tx_thread_state)

/* Handle the thread suspend extension, if defined*/
TX_THREAD_SYSTEM_SUSPEND_EXTENSION(thread_ptr);

#ifdef TX_ENABLE_EVENT_TRACE

/* If trace is enabled, save the current event pointer. */
Expand Down
33 changes: 33 additions & 0 deletions custom_tx_user.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/

#ifndef TX_USER_H
#define TX_USER_H

/* Define user-specified additional fields to be stored in TX_THREAD */
#define TX_THREAD_USER_EXTENSION UCHAR resume_recorded; \
ULONG resume_recorded_at; \
UCHAR suspend_recorded; \
ULONG suspend_recorded_at;

/* This is one way to define the extension. Because it's a macro, it
cannot handle static allocations internally, nor does it have a
proper calling context for tracing purposes. */
#define TX_THREAD_SYSTEM_SUSPEND_EXTENSION(thread_ptr) \
do { \
if (!thread_ptr->suspend_recorded) \
{ \
thread_ptr->suspend_recorded_at += 1; \
thread_ptr->suspend_recorded = 1; \
} \
} while(0)

#endif

0 comments on commit 73756fd

Please sign in to comment.