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

[PATCH v2] linux-gen: sched: use restrict keyword to help optimizer #2123

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

JannePeltonen
Copy link
Collaborator

Now that -fno-strict-aliasing was added in the default compiler flags, the compiler cannot use type based alias analysis when optimizing and has to assume potential aliasing if it cannot prove otherwise. This slowed down scheduling because the compiler could not deduce that the out_ev parameter of copy_from_stash() does not alias sched_local.

Most of the slowdown seems to come from the use of the ev_index and num_ev fields of sched_local.stash in the loop body. Using local variables instead would solve the issue for the most part but it appears that qualifying the out_ev pointer with restrict has a similar effect with gcc and clang even though the problematic accesses have a different type from *out_ev.

Fix the problem by using the restrict keyword to indicate that *out_ev does not alias with anything else within the function.

@odpbuild odpbuild changed the title linux-gen: sched: use restrict keyword to help optimizer [PATCH v1] linux-gen: sched: use restrict keyword to help optimizer Sep 23, 2024
@@ -1196,7 +1196,7 @@ static inline int balance_spread(int grp, int prio, int cur_spr)
return new_spr;
}

static inline int copy_from_stash(odp_event_t out_ev[], uint32_t max)
static inline int copy_from_stash(odp_event_t *restrict out_ev, uint32_t max)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could also use static inline int copy_from_stash(odp_event_t out_ev[restrict], uint32_t max) to maintain the same style but either method is OK for me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but I felt that it is a bit weird syntax and harder to understand. But maybe it is just me. Did not change it in v2 though.

Now that -fno-strict-aliasing was added in the default compiler flags,
the compiler cannot use type based alias analysis when optimizing and
has to assume potential aliasing if it cannot prove otherwise. This
slowed down scheduling because the compiler could not deduce that
the out_ev parameter of copy_from_stash() does not alias sched_local.

Most of the slowdown seems to come from the use of the ev_index and num_ev
fields of sched_local.stash in the loop body. Using local variables instead
would solve the issue for the most part but it appears that qualifying
the out_ev pointer with restrict has a similar effect with gcc and clang
even though the problematic accesses have a different type from *out_ev.

Fix the problem by using the restrict keyword to indicate that *out_ev
does not alias with anything else within the function.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
Reviewed-by: Matias Elo <matias.elo@nokia.com>
@odpbuild odpbuild changed the title [PATCH v1] linux-gen: sched: use restrict keyword to help optimizer [PATCH v2] linux-gen: sched: use restrict keyword to help optimizer Sep 23, 2024
@JannePeltonen
Copy link
Collaborator Author

v2: review-tag

@MatiasElo MatiasElo merged commit b9f4563 into OpenDataPlane:master Sep 24, 2024
170 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants