Skip to content

Commit

Permalink
linux-gen: sched: use restrict keyword to help optimizer
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
JannePeltonen committed Sep 23, 2024
1 parent 69feb8c commit 07930f6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion platform/linux-generic/odp_schedule_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
int i = 0;

Expand Down

0 comments on commit 07930f6

Please sign in to comment.