Skip to content

Conversation

dschatzberg
Copy link
Contributor

Much of the logic was pretty confusing with many gotos and various release_cpumask/group/rcu lock, etc. This creates a few macros for common types and uses the gcc/clang attribute(cleanup, ...) to do the proper destruction of the resource once the variable goes out of scope.

Much of the logic was pretty confusing with many gotos and various
release_cpumask/group/rcu lock, etc. This creates a few macros for common types
and uses the gcc/clang __attribute__(cleanup, ...) to do the proper destruction
of the resource once the variable goes out of scope.
Copy link
Contributor

@JakeHillion JakeHillion left a comment

Choose a reason for hiding this comment

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

This is beautiful. Is it worth putting some of these in a common header?

@htejun
Copy link
Contributor

htejun commented Sep 23, 2025

Can we copy the guard() macros from the kernel and use them? They're pretty much the same things and it'd be nice to have some commonality.

@dschatzberg
Copy link
Contributor Author

I wasn't aware of the guard() macros, let me look those up

@dschatzberg dschatzberg marked this pull request as draft September 23, 2025 16:36
Copy link
Contributor

@tommy-u tommy-u left a comment

Choose a reason for hiding this comment

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

I think this is much easier to understand than gotos.

cpu = bpf_cpumask_any_distribute(cast_mask(tctx->cpumask));
else
cpu = prev_cpu;
return bpf_cpumask_any_distribute(cast_mask(tctx->cpumask));
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] I know the tctx->cpumask part of the condition above this line is redundant with the check before it & probably just there for the verifier. But it still looks weird to see the check in that order bc the short circuit implications of:

!bpf_cpumask_test_cpu(prev_cpu, cast_mask(tctx->cpumask)) && tctx->cpumask
vs
tctx->cpumask && !bpf_cpumask_test_cpu(prev_cpu, cast_mask(tctx->cpumask))

s32 cpu;
DECLARE_IDLE_CPUMASK(idle_smtmask) = scx_bpf_get_idle_smtmask();

if (!(task_cpumask = (struct cpumask *)tctx->cpumask) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Know this is outside the diff, but the bpf_cpumask is larger than the task_cpumask. I think we'll be fine using it as a pointer as long as we never e.g. copy size of bpf_cpumask into a cpumask

https://elixir.bootlin.com/linux/v6.16.8/source/kernel/bpf/cpumask.c#L25

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.

4 participants