Skip to content

Conversation

@rruuaanng
Copy link
Contributor

Add a set of 'SYS_PORT_TRACK_K_*' wrapper macros for visible access to the global tracking list, and a macro 'SYS_PORT_TRACK_FOREACH' for iterating over the tracking list.

@rruuaanng rruuaanng marked this pull request as ready for review March 8, 2025 11:59
@zephyrbot zephyrbot added Release Notes To be mentioned in the release notes area: Tracing Tracing labels Mar 8, 2025
@rruuaanng rruuaanng removed the Release Notes To be mentioned in the release notes label Mar 8, 2025
@zephyrbot zephyrbot added the Release Notes To be mentioned in the release notes label Mar 8, 2025
@nashif nashif assigned nashif and unassigned kartben and fabiobaltieri Mar 8, 2025
@sonarqubecloud
Copy link

@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Jul 14, 2025
@ubieda
Copy link
Member

ubieda commented Jul 14, 2025

@rruuaanng Can you look at the CI failure?

@ubieda ubieda added this to the v4.3.0 milestone Jul 14, 2025
@ubieda ubieda removed the Stale label Jul 14, 2025
@rruuaanng
Copy link
Contributor Author

rruuaanng commented Jul 15, 2025

@ubieda It looks like it's not an issue, the warning is caused by my syntax.

/*
  *   SYS_PORT_TRACK_FOREACH(k_mutex, m) {
  *       ...
  *   }
  */
#define SYS_PORT_TRACK_FOREACH(object, var)		\
	for (struct object *var = _track_list_##object	\
               ; var != NULL; var++)
BRACES

include/zephyr/tracing/tracking.h:67  braces {} are required around if/while/for/else

@rruuaanng rruuaanng requested a review from ubieda July 15, 2025 08:21
@ubieda
Copy link
Member

ubieda commented Jul 15, 2025

@ubieda It looks like it's not an issue, the warning is caused by my syntax.

/*
  *   SYS_PORT_TRACK_FOREACH(k_mutex, m) {
  *       ...
  *   }
  */
#define SYS_PORT_TRACK_FOREACH(object, var)		\
	for (struct object *var = _track_list_##object	\
               ; var != NULL; var++)
BRACES

include/zephyr/tracing/tracking.h:67  braces {} are required around if/while/for/else

Try adding it under the ForEachMacros list:

zephyr/.clang-format

Lines 34 to 85 in 0b1cff2

ForEachMacros:
- 'ARRAY_FOR_EACH'
- 'ARRAY_FOR_EACH_PTR'
- 'FOR_EACH'
- 'FOR_EACH_FIXED_ARG'
- 'FOR_EACH_IDX'
- 'FOR_EACH_IDX_FIXED_ARG'
- 'FOR_EACH_NONEMPTY_TERM'
- 'FOR_EACH_FIXED_ARG_NONEMPTY_TERM'
- 'RB_FOR_EACH'
- 'RB_FOR_EACH_CONTAINER'
- 'SYS_DLIST_FOR_EACH_CONTAINER'
- 'SYS_DLIST_FOR_EACH_CONTAINER_SAFE'
- 'SYS_DLIST_FOR_EACH_NODE'
- 'SYS_DLIST_FOR_EACH_NODE_SAFE'
- 'SYS_SEM_LOCK'
- 'SYS_SFLIST_FOR_EACH_CONTAINER'
- 'SYS_SFLIST_FOR_EACH_CONTAINER_SAFE'
- 'SYS_SFLIST_FOR_EACH_NODE'
- 'SYS_SFLIST_FOR_EACH_NODE_SAFE'
- 'SYS_SLIST_FOR_EACH_CONTAINER'
- 'SYS_SLIST_FOR_EACH_CONTAINER_SAFE'
- 'SYS_SLIST_FOR_EACH_NODE'
- 'SYS_SLIST_FOR_EACH_NODE_SAFE'
- '_WAIT_Q_FOR_EACH'
- 'Z_FOR_EACH'
- 'Z_FOR_EACH_ENGINE'
- 'Z_FOR_EACH_EXEC'
- 'Z_FOR_EACH_FIXED_ARG'
- 'Z_FOR_EACH_FIXED_ARG_EXEC'
- 'Z_FOR_EACH_IDX'
- 'Z_FOR_EACH_IDX_EXEC'
- 'Z_FOR_EACH_IDX_FIXED_ARG'
- 'Z_FOR_EACH_IDX_FIXED_ARG_EXEC'
- 'Z_GENLIST_FOR_EACH_CONTAINER'
- 'Z_GENLIST_FOR_EACH_CONTAINER_SAFE'
- 'Z_GENLIST_FOR_EACH_NODE'
- 'Z_GENLIST_FOR_EACH_NODE_SAFE'
- 'STRUCT_SECTION_FOREACH'
- 'STRUCT_SECTION_FOREACH_ALTERNATE'
- 'TYPE_SECTION_FOREACH'
- 'K_SPINLOCK'
- 'COAP_RESOURCE_FOREACH'
- 'COAP_SERVICE_FOREACH'
- 'COAP_SERVICE_FOREACH_RESOURCE'
- 'HTTP_RESOURCE_FOREACH'
- 'HTTP_SERVER_CONTENT_TYPE_FOREACH'
- 'HTTP_SERVICE_FOREACH'
- 'HTTP_SERVICE_FOREACH_RESOURCE'
- 'I3C_BUS_FOR_EACH_I3CDEV'
- 'I3C_BUS_FOR_EACH_I2CDEV'
- 'MIN_HEAP_FOREACH'

ubieda
ubieda previously approved these changes Sep 24, 2025
edersondisouza
edersondisouza previously approved these changes Sep 24, 2025
Copy link
Contributor

@edersondisouza edersondisouza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curiosity - do you have use cases for accessing these lists from inside Zephyr? I've imagined they would be used by external tools only, so they would only care about the symbol name.

@ubieda
Copy link
Member

ubieda commented Oct 24, 2025

@rruuaanng would you mind rebasing?

@rruuaanng
Copy link
Contributor Author

@ubieda Done :)


.. zephyr-keep-sorted-stop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: seems like an unrelated change

*/
#define SYS_PORT_TRACK_NEXT(list)((list)->_obj_track_next)

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see macros being added, but I do not see them being used, can you please elaborate on the usage of thos macros and why we need them?

Copy link
Contributor Author

@rruuaanng rruuaanng Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A large number of global variables with names like _track_list_k_xxx are exported to tracking.h. It seems that in Zephyr they're only used in tracing_tracking.c. If this kind of export is really necessary, I think we should add a wrapper macro to hide the implementation details of these variables.
(and provide a convenient way to operate on them.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the point being missed here - I don't think that _track_list_k_xxx are necessarily expected to be accessed from inside Zephyr. As I mentioned in my previous comment, external tools will be looking for these symbols, and macros won't be helpful to them, anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if you really need to access them internally, directly referencing the symbols doesn't seem like a sensible approach (although the purpose of accessing the symbols is merely to iterate over them).
If we have these macros, we can handle all the objects in the _track_list_ more effectively.

Add a set of `SYS_PORT_TRACK_K_*` wrapper macros for
visible access to the global tracking list, and a macro
`SYS_PORT_TRACK_FOR_EACH` for iterating over the tracking list.

Signed-off-by: James Roy <[email protected]>
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Coding Guidelines Coding guidelines and style area: Linters area: Tracing Tracing Release Notes To be mentioned in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants