|
| 1 | +/** |
| 2 | + \page cfetaovr cFE Task Affinity (TA) Overview |
| 3 | + |
| 4 | + The cFE Task Affinity (TA) application provides a centralized mechanism for managing |
| 5 | + and configuring CPU core affinities for operating system tasks (threads) within the |
| 6 | + core Flight System (cFS). |
| 7 | + |
| 8 | + In multi-core processing environments, it is often critical to ensure that certain |
| 9 | + tasks run on specific CPU cores to meet real-time deadlines, reduce cache thrashing, |
| 10 | + or isolate high-priority operations from background processing. TA bridges the gap |
| 11 | + between the cFS environment and the underlying OS (via the OSAL), allowing system |
| 12 | + operators to dynamically monitor and alter the core affinity of running tasks. |
| 13 | + |
| 14 | + TA operates both autonomously during system startup (via OSAL event hooks) and |
| 15 | + interactively via ground commands. It is designed as an optional core module |
| 16 | + that can be conditionally compiled into the cFS objtab based on mission needs. |
| 17 | + |
| 18 | + <h3>Mission Integration</h3> |
| 19 | + |
| 20 | + Because TA is an optional core module, it must be explicitly enabled and configured |
| 21 | + for your specific mission deployment. To integrate TA into a cFS mission, follow |
| 22 | + these steps: |
| 23 | + |
| 24 | + <B>1. Enable the Module</B> <BR> |
| 25 | + Add the `ta` module to the core modules list in your mission's `targets.cmake` file: |
| 26 | + \code |
| 27 | + list(APPEND MISSION_CORE_MODULES ta) |
| 28 | + \endcode |
| 29 | + |
| 30 | + <B>2. Register Message IDs</B> <BR> |
| 31 | + The TA message IDs must be integrated into the mission's global message ID namespace. |
| 32 | + Include the TA message ID definitions in your mission's `cfe_msgids.h` file |
| 33 | + (typically located in the mission `sample_defs` directory): |
| 34 | + \code |
| 35 | + #include "cfe_ta_msgids.h" |
| 36 | + \endcode |
| 37 | + |
| 38 | + <B>3. Configure Target-Specific Affinities</B> <BR> |
| 39 | + The default task affinity assignments are defined in `cfe_ta_cpuaffinity.c`. |
| 40 | + Because different deployment targets (e.g., `cpu1`, `cpu2`) often have different |
| 41 | + hardware architectures and core counts, you can provide target-specific affinity |
| 42 | + configurations. Simply place a uniquely prefixed file in your mission definitions |
| 43 | + directory (e.g., `sample_defs/`), and the cFS build system will automatically |
| 44 | + locate and compile it. |
| 45 | + <BR><BR> |
| 46 | + For example, to configure affinities specifically for `cpu1`, create the file: |
| 47 | + <tt>cpu1_cfe_ta_cpuaffinity.c</tt> |
| 48 | + |
| 49 | + <hr> |
| 50 | + |
| 51 | + For additional detail on Task Affinity and how to manage it, see the following sections: |
| 52 | + |
| 53 | + <UL> |
| 54 | + <LI> \subpage cfetaugmanage <BR> |
| 55 | + <LI> \subpage cfetaugstartup <BR> |
| 56 | + <LI> \subpage cfetaugtelemetry <BR> |
| 57 | + <LI> \subpage cfetaugfaq <BR> |
| 58 | + <LI> \subpage cfetacmds <BR> |
| 59 | + <LI> \subpage cfetatlm <BR> |
| 60 | + <LI> \subpage cfetacfg <BR> |
| 61 | + </UL> |
| 62 | +**/ |
| 63 | + |
| 64 | +/** |
| 65 | + \page cfetaugmanage Managing Task Affinity |
| 66 | + |
| 67 | + Operators can interact with the TA application to query the current state of task |
| 68 | + affinities across the system and make real-time adjustments. |
| 69 | + |
| 70 | + When a multi-core OS schedules a task, it uses an "Affinity Mask" to determine which |
| 71 | + cores the task is permitted to run on. Each bit in the mask corresponds to a specific |
| 72 | + CPU core (e.g., Bit 0 = Core 0, Bit 1 = Core 1). A mask of `0x03` (binary `0011`) |
| 73 | + indicates the task can run on Core 0 or Core 1. |
| 74 | + |
| 75 | + The TA application maintains an internal list of tasks (`CpuTaskAffinity`) |
| 76 | + and their associated affinity masks. Operators can manage these masks using the |
| 77 | + following methods: |
| 78 | + |
| 79 | + <B>1. Setting Task Affinity</B> <BR> |
| 80 | + Operators can send the \ref CFE_TA_SET_TASK_AFFINITY_CC command, specifying a task |
| 81 | + name and a desired affinity mask. TA will look up the task via OSAL (`OS_TaskGetIdByName`), |
| 82 | + apply the new mask to the OS scheduling queue, and read the applied mask back |
| 83 | + from the OS to verify the change. |
| 84 | + |
| 85 | + <B>2. Getting Task Affinity</B> <BR> |
| 86 | + Operators can send the \ref CFE_TA_GET_TASK_AFFINITY_CC command to request the current active |
| 87 | + affinity mask for a specific task. TA will query the OS and update its internal |
| 88 | + table. If the OS reports a different affinity than what TA has on record, TA will |
| 89 | + log a discrepancy event and resynchronize its internal state. |
| 90 | + |
| 91 | + <B>3. Querying All Tasks</B> <BR> |
| 92 | + For a comprehensive view of the system, operators can send the \ref CFE_TA_QUERY_ALL_TASKS_CC |
| 93 | + command. TA will generate a diagnostic packet containing system-wide CPU |
| 94 | + capabilities (cores configured, cores online) and write the current affinity |
| 95 | + state of all tracked tasks into an onboard file. This file can then be downlinked |
| 96 | + and analyzed by the ground system. |
| 97 | +**/ |
| 98 | + |
| 99 | +/** |
| 100 | + \page cfetaugstartup Startup and Autonomous Operations |
| 101 | + |
| 102 | + Unlike standard cFE applications that only respond to commands, TA actively listens |
| 103 | + to the Operating System through an OSAL Event Handler (`CFE_TA_OS_EventHandler`). |
| 104 | + |
| 105 | + During the `CFE_TA_EarlyInit` phase, TA registers itself with OSAL to receive |
| 106 | + notifications whenever a new OS resource is created. Specifically, TA monitors for |
| 107 | + `OS_EVENT_TASK_STARTUP` events. |
| 108 | + |
| 109 | + When a new task starts, the following sequence occurs autonomously: |
| 110 | + -# The OSAL triggers the TA event handler. |
| 111 | + -# TA extracts the name of the newly started task. |
| 112 | + -# TA looks up the task name in its default configuration table |
| 113 | + (`CpuTaskAffinity`). |
| 114 | + -# If the task is found and configured to use a specific mask (`CFE_TA_Mask`), |
| 115 | + TA immediately applies that mask to the new task. |
| 116 | + -# If the task is not in the list, TA automatically adds it to its internal tracking |
| 117 | + table and flags it as `CFE_TA_Added`, leaving its affinity to the OS default. |
| 118 | + |
| 119 | + This allows mission developers to define a static layout of task affinities in the |
| 120 | + `cfe_ta_cpuaffinity.c` file before compilation. As the cFS system boots up and |
| 121 | + various apps start their child tasks, TA seamlessly intercepts them and pins them |
| 122 | + to their pre-assigned cores without requiring any manual ground intervention. |
| 123 | +**/ |
| 124 | + |
| 125 | +/** |
| 126 | + \page cfetaugtelemetry TA Telemetry and Diagnostics |
| 127 | + |
| 128 | + The TA application produces a standard Housekeeping packet (\ref CFE_TA_HK_TLM_MID) |
| 129 | + that provides operators with insight into the health and status of the application. |
| 130 | + |
| 131 | + The housekeeping packet tracks standard command processing statistics: |
| 132 | + <UL> |
| 133 | + <LI> `CommandCounter`: Increments on successfully executed commands. |
| 134 | + <LI> `CommandErrorCounter`: Increments when commands fail length checks, use |
| 135 | + invalid function codes, or encounter execution errors. |
| 136 | + </UL> |
| 137 | + |
| 138 | + Additionally, it tracks autonomous startup statistics: |
| 139 | + <UL> |
| 140 | + <LI> `StartupCounter`: The number of tasks successfully processed and assigned |
| 141 | + an affinity mask during system boot/task creation. |
| 142 | + <LI> `StartupErrorCounter`: The number of tasks that failed to receive their |
| 143 | + startup affinity assignment due to OSAL errors. |
| 144 | + </UL> |
| 145 | +**/ |
| 146 | + |
| 147 | +/** |
| 148 | + \page cfetaugfaq Frequently Asked Questions about Task Affinity |
| 149 | + |
| 150 | + <B> (Q) |
| 151 | + I sent a SET_TASK_AFFINITY command, but I received a CFE_TA_SET_AFFINITY_CMD_NOTFOUND_ERR_EID. |
| 152 | + What happened? |
| 153 | + </B> <BR> <BR> <I> |
| 154 | + The TA application maintains a finite internal list of tasks (`OS_MAX_TASKS`). |
| 155 | + If the task name provided in the command does not match any task currently |
| 156 | + tracked by TA, it cannot set the affinity. Ensure the task name is spelled |
| 157 | + correctly and matches the OSAL assigned name. |
| 158 | + </I> |
| 159 | + |
| 160 | + <B> (Q) |
| 161 | + Why does the GET_TASK_AFFINITY command sometimes generate a "discrepancy" event? |
| 162 | + </B> <BR> <BR> <I> |
| 163 | + TA tracks what it *believes* the affinity mask should be. However, the |
| 164 | + underlying OS (or a lower-level library) might have altered the thread's |
| 165 | + affinity outside of TA's awareness. When TA queries the OS and notices the |
| 166 | + real mask differs from its internal record, it issues a |
| 167 | + `CFE_TA_GET_TASK_AFFINITY_DISCREPANCY_INF_EID` to alert operators that an |
| 168 | + uncommanded change occurred, and it resynchronizes its table. |
| 169 | + </I> |
| 170 | + |
| 171 | + <B> (Q) |
| 172 | + Is TA dependent on the Platform Service Package (PSP)? |
| 173 | + </B> <BR> <BR> <I> |
| 174 | + No. In the modern cFS modular architecture, TA is implemented entirely at the |
| 175 | + CFE core module level. It utilizes OSAL APIs (`OS_TaskAffinitySetAffinity`, etc.) to |
| 176 | + abstract away the specific underlying operating system. If it is included in |
| 177 | + the `MISSION_CORE_MODULES` CMake list, the cFE Executive Services (ES) will |
| 178 | + automatically initialize it and generate its objtab entry. |
| 179 | + </I> |
| 180 | + |
| 181 | + <B> (Q) |
| 182 | + What happens if I try to set an affinity mask for a core that doesn't exist? |
| 183 | + </B> <BR> <BR> <I> |
| 184 | + TA safely clamps the user-provided mask. During the mask translation process |
| 185 | + (`CFE_TA_Cpu_Set`), TA checks the requested bits against `OS_MAX_CPUS` and |
| 186 | + the actual hardware cores configured (`OS_TaskAffinityCoresConfigured()`). Bits mapped |
| 187 | + to non-existent cores are safely ignored, preventing OS-level exceptions. |
| 188 | + </I> |
| 189 | +**/ |
| 190 | + |
| 191 | +/** |
| 192 | +** \page cfetacmds cFE TA Commands |
| 193 | +** |
| 194 | +** Upon receipt of any command, the TA application will confirm that the |
| 195 | +** message length embedded within the header (from `CFE_MSG_GetSize()`) matches the expected |
| 196 | +** length of that message, based on the size of the C structure defining that command. |
| 197 | +** If there is any discrepancy between the expected and actual message size, TA will generate |
| 198 | +** the #CFE_TA_LEN_ERR_EID event, increment the command error counter, and the |
| 199 | +** command will _not_ be accepted for processing. |
| 200 | +** |
| 201 | +** The following is a list of commands that are processed by the cFE TA Task: |
| 202 | +** |
| 203 | +** \tableofcontents |
| 204 | +** |
| 205 | +** <table border="1" cellpadding="2" width="100%"> |
| 206 | +** <tr><th>Command Name</th><th>Function Code</th><th>Payload Structure</th><th>Description</th></tr> |
| 207 | +** <tr><td>No-Op</td><td>\ref CFE_TA_NOOP_CC</td><td>\ref CFE_TA_NoopCmd_t</td><td>Generates an info event to verify app is alive.</td></tr> |
| 208 | +** <tr><td>Reset Counters</td><td>\ref CFE_TA_RESET_COUNTERS_CC</td><td>\ref CFE_TA_ResetCountersCmd_t</td><td>Resets the command and error counters to zero.</td></tr> |
| 209 | +** <tr><td>Query All Tasks</td><td>\ref CFE_TA_QUERY_ALL_TASKS_CC</td><td>\ref CFE_TA_QueryAllTasksCmd_t</td><td>Writes the current affinity state of all tracked tasks to an onboard file.</td></tr> |
| 210 | +** <tr><td>Set Task Affinity</td><td>\ref CFE_TA_SET_TASK_AFFINITY_CC</td><td>\ref CFE_TA_SetTaskAffinityCmd_t</td><td>Sets a new CPU affinity mask for a specific task.</td></tr> |
| 211 | +** <tr><td>Get Task Affinity</td><td>\ref CFE_TA_GET_TASK_AFFINITY_CC</td><td>\ref CFE_TA_GetTaskAffinityCmd_t</td><td>Queries the OS for a specific task's affinity and updates the internal tracking table.</td></tr> |
| 212 | +** </table> |
| 213 | +**/ |
| 214 | + |
| 215 | +/** |
| 216 | +** \page cfetatlm cFE TA Telemetry |
| 217 | +** |
| 218 | +** The following are telemetry packets generated by the cFE TA Task: |
| 219 | +** |
| 220 | +** \tableofcontents |
| 221 | +** |
| 222 | +** <table border="1" cellpadding="2" width="100%"> |
| 223 | +** <tr><th>Telemetry Packet Name</th><th>Message ID</th><th>Payload Structure</th><th>Description</th></tr> |
| 224 | +** <tr><td>Housekeeping (HK)</td><td>\ref CFE_TA_HK_TLM_MID</td><td>\ref CFE_TA_HousekeepingTlm_t</td><td>Contains command execution counters, errors, and startup tracking metrics. Generated upon receipt of the SEND_HK command.</td></tr> |
| 225 | +** </table> |
| 226 | +** |
| 227 | +** Additionally, the TA application defines a diagnostic structure (\ref CFE_TA_DiagInfo_t) |
| 228 | +** which is used to dump the complete system affinity state to a file when the |
| 229 | +** \ref CFE_TA_QUERY_ALL_TASKS_CC command is received. |
| 230 | +**/ |
| 231 | + |
| 232 | +/** |
| 233 | +** \page cfetacfg cFE TA Configuration Parameters |
| 234 | +** |
| 235 | +** The following are configuration parameters used to configure the cFE TA Application |
| 236 | +** for a specific platform or mission. These are defined in the associated configuration |
| 237 | +** header files. |
| 238 | +** |
| 239 | +** <table border="1" cellpadding="2" width="100%"> |
| 240 | +** <tr><th>Parameter Name</th><th>Description</th></tr> |
| 241 | +** <tr><td>\ref CFE_TA_PIPE_NAME</td><td>The string name used for the TA application's command pipe.</td></tr> |
| 242 | +** <tr><td>\ref CFE_TA_PIPE_DEPTH</td><td>The depth of the TA command pipe (number of messages it can hold).</td></tr> |
| 243 | +** <tr><td>\ref CFE_TA_MAX_EVENT_SEND_COUNT</td><td>The maximum number of times an identical event can be sent before being filtered.</td></tr> |
| 244 | +** <tr><td>\ref CFE_TA_TASK_LOG_DESC</td><td>The file description header placed in the file generated by the Query All Tasks command.</td></tr> |
| 245 | +** </table> |
| 246 | +**/ |
0 commit comments