Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

k_pipe: fix trace point for blocking writes #84487

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

eriktamlin
Copy link
Collaborator

@eriktamlin eriktamlin commented Jan 24, 2025

Fix the trace point in k_pipe wait_for.

Fixes #84486

It checks if "waitq" points to pipe->space, in which case it is a write operation.
A read will have "waitq" point to pipe->data instead.

I'm not entirely satisfied with this fix since it relies on comparing the address passed to wait_for in order to determine which trace point to use. Maybe add another "is_read" parameter to wait_for instead?

If anyone has a better way of doing this please let me know.

Signed-off-by: Erik Tamlin [email protected]

Fix the trace point in k_pipe wait_for.

Signed-off-by: Erik Tamlin <[email protected]>
Fix the trace point in k_pipe wait_for.

Signed-off-by: Erik Tamlin <[email protected]>
@zephyrbot zephyrbot requested review from dcpleung and TaiJuWu January 24, 2025 11:17
@eriktamlin
Copy link
Collaborator Author

@Mattemagikern suggested an alternative approach where we put the NO_WAIT check outside wait_for together with the trace points in the calling functions instead.

Example for k_pipe_write would be (note the changed parameter list for wait_for that now expects timeout instead of end):
timeout = sys_timepoint_timeout(end);
if (K_TIMEOUT_EQ(timeout, K_NO_WAIT)) {
rc = written ? written : -EAGAIN;
break;
}
SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_pipe, write, pipe, timeout);
rc = wait_for(&pipe->space, pipe, &key, timeout, &need_resched);

Same changes in k_pipe_read.
Is this a preferred implementation?

Copy link
Collaborator

@npitre npitre left a comment

Choose a reason for hiding this comment

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

What you did is fine. The alternative would add potential runtime overhead
to the code even when tracing is disabled.

Please merge both commits together though.

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

Successfully merging this pull request may close these issues.

k_pipe_write generates read trace events instead of write trace events when blocking
5 participants