22# Copyright (c) 2016-2020 Arm Limited
33# Copyright (c) 2022 Intel Corporation
44# Copyright (c) 2022 Chris Reed
5+ # Copyright (c) 2025 STMicroelectronics
56# SPDX-License-Identifier: Apache-2.0
67#
78# Licensed under the Apache License, Version 2.0 (the "License");
@@ -147,22 +148,29 @@ def read_core_registers_raw(self, reg_list):
147148class ZephyrThread (TargetThread ):
148149 """@brief A Zephyr task."""
149150
150- READY = 0
151+ # Keep in sync with include/zephyr/kernel_structs.h
152+ DUMMY = 1 << 0 # attribute rather than state
151153 PENDING = 1 << 1
152- PRESTART = 1 << 2
154+ SLEEPING = 1 << 2
153155 DEAD = 1 << 3
154156 SUSPENDED = 1 << 4
155- POLLING = 1 << 5
156- RUNNING = 1 << 6
157+ ABORTING = 1 << 5
158+ SUSPENDING = 1 << 6
159+ QUEUED = 1 << 7 # thread in ready queue
160+
161+ # Not a real value; for bookkeeping purposes only
162+ RUNNING = 1 << 31
157163
158164 STATE_NAMES = {
159- READY : "Ready " ,
165+ DUMMY : "Dummy " ,
160166 PENDING : "Pending" ,
161- PRESTART : "Prestart " ,
167+ SLEEPING : "Sleeping " ,
162168 DEAD : "Dead" ,
163169 SUSPENDED : "Suspended" ,
164- POLLING : "Polling" ,
165- RUNNING : "Running" ,
170+ ABORTING : "Aborting" ,
171+ SUSPENDING : "Suspending" ,
172+ QUEUED : "Ready" ,
173+ RUNNING : "Running"
166174 }
167175
168176 def __init__ (self , targetContext , provider , base , offsets ):
@@ -172,7 +180,7 @@ def __init__(self, targetContext, provider, base, offsets):
172180 self ._base = base
173181 self ._thread_context = ZephyrThreadContext (self ._target_context , self )
174182 self ._offsets = offsets
175- self ._state = ZephyrThread . READY
183+ self ._state = 0
176184 self ._priority = 0
177185 self ._name = "Unnamed"
178186
@@ -224,6 +232,25 @@ def name(self):
224232
225233 @property
226234 def description (self ):
235+ # Idle threads must be handled separately: when not running,
236+ # they are neither SLEEPING, PENDING nor QUEUED and simply
237+ # exist in a "limbo state" outside scheduler consideration.
238+ #
239+ # NOTE: RUNNING state indicates that 'current' of a CPU is
240+ # equal to self._base, unlike all other values which come
241+ # directly from 'base.thread_state'; as such, it will be
242+ # valid even for idle threads, unlike all other values.
243+ #
244+ # HACK: assume threads called "idle" are idle threads.
245+ # A proper method would check that this is one of the threads
246+ # in the "z_idle_threads" array (or that it matches one of
247+ # _kernel.cpus[].idle_thread, which is the same thing).
248+ if self ._name == "idle" :
249+ if self .state == ZephyrThread .RUNNING :
250+ return "Running"
251+ else :
252+ return "Ready"
253+
227254 return "%s; Priority %d" % (self .STATE_NAMES .get (self .state , "UNKNOWN" ), self .priority )
228255
229256 @property
0 commit comments