Skip to content

socket module add SO_ATTACH_REUSEPORT_CPBF for Linux. #8062

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

Closed
wants to merge 1 commit into from

Conversation

devnexen
Copy link
Member

@devnexen devnexen commented Feb 8, 2022

to be used in conjunction with SO_REUSPORT, giving a greater control
over how we bind a socket instead of the round robin workflow, we do
instead attach to the processor id as :

  • we assign the processor_id to A in the BPF filter.
  • then returns A.

in other words, a more modern version of SO_INCOMING_CPU (ie can have a per
worker notion we do not use here).

@devnexen devnexen force-pushed the reuseport_cpbf_linux branch 3 times, most recently from 612c075 to f78674b Compare February 9, 2022 06:03
@devnexen devnexen marked this pull request as ready for review February 9, 2022 06:36
@ramsey ramsey added this to the PHP 8.2 milestone May 25, 2022
Comment on lines 515 to 516
REGISTER_LONG_CONSTANT("SO_DETACH_FILTER", SO_DETACH_FILTER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SO_DETACH_BPF", SO_DETACH_BPF, CONST_CS | CONST_PERSISTENT);
Copy link
Member

Choose a reason for hiding this comment

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

would be probably good to have a test for those.

Comment on lines 2026 to 1967
BPF_STMT((BPF_LD|BPF_W|BPF_ABS), (uint32_t)(SKF_AD_OFF+SKF_AD_CPU)),
BPF_STMT((BPF_RET|BPF_A), 0),
Copy link
Member

Choose a reason for hiding this comment

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

This kind support just one use case so it's sort of limited. I think it's useful but we are sort of introducing a single behavior that cannot be changed. Maybe we should use arg4 as a constant that will identify type of the program that will be used. Then if someone comes with another classic BPF program use case it could be simply added. It would also allow us to overload arg4 in the future if we ever decide to provide some sort of interface to BPF.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I planned to pick it up at some point but too late for 8.2

@bukka bukka removed this from the PHP 8.2 milestone Jul 19, 2022
@devnexen devnexen force-pushed the reuseport_cpbf_linux branch from f78674b to 7ee377f Compare September 3, 2022 07:32
@devnexen devnexen requested a review from bukka September 8, 2022 16:10
Copy link
Member

@bukka bukka left a comment

Choose a reason for hiding this comment

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

It looks good to me - just added some suggestion for better readability but otherwise I think it's good.

switch (k) {
case SKF_AD_CPU:
cbpf[0].code = (BPF_LD|BPF_W|BPF_ABS);
cbpf[0].k = (uint32_t)(SKF_AD_OFF+k);
Copy link
Member

Choose a reason for hiding this comment

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

It took me quite a bit of time to realise that this is for getting to current cpu id because I have to realise that k is actually SKF_AD_CPU. I know it is obvious as it is a switch case but it could be a bit clearer just by using SKF_AD_CPU

Copy link
Member

Choose a reason for hiding this comment

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

also NIT that we usually write a space around +...

static struct sock_fprog bpfprog;

switch (k) {
case SKF_AD_CPU:
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking if this is the best name as it's a part of actual CBPF. Although it's the part that actual matters so it makes some sense. Basically I couldn't come up with anything better so guess it's fine :)

@devnexen devnexen force-pushed the reuseport_cpbf_linux branch from aec6bba to 37cba3a Compare September 29, 2022 19:47
to be used in conjunction with SO_REUSPORT, giving a greater control
over how we bind a socket instead of the round robin workflow, we do
 instead attach to the processor id as :
- we assign the processor_id to A in the BPF filter.
- then returns A.

in other words, a more modern version of SO_INCOMING_CPU (ie can have a per
 worker notion we do not use here).
@devnexen devnexen force-pushed the reuseport_cpbf_linux branch from 37cba3a to d5c1acc Compare September 29, 2022 20:42
@devnexen devnexen closed this in 615b800 Sep 29, 2022
@jrfnl
Copy link
Contributor

jrfnl commented Jul 31, 2023

Just checking - if I look in the UPGRADING guide, I can see the new SO_ATTACH_REUSEPORT_CBPF constant mentioned, but not the SO_DETACH_FILTER and SO_DETACH_BPF constants. Am I reading the commit wrong or were these missed when updating the changelog ?

@bukka
Copy link
Member

bukka commented Aug 24, 2023

Yeah I think those should be added as well. @devnexen are you fine to do that?

@devnexen
Copy link
Member Author

no problem for me, will do today.

@jrfnl
Copy link
Contributor

jrfnl commented Aug 24, 2023

Thanks for handling this. For anyone looking: the update was made by @devnexen in 9eb032b

jrfnl added a commit to PHPCompatibility/PHPCompatibility that referenced this pull request Sep 10, 2023
From the PHP 8.3 changelog:
>   . SO_ATTACH_REUSEPORT_CBPF (Linux only).

The other two constants are visible in the commit, but not mentioned in the changelog. I've left [a comment asking if this needs fixing up](php/php-src#8062 (comment)).

Ref:
* https://github.com/php/php-src/blob/655f116be57b46efe32221d7adfec6d6b81eeece/UPGRADING#L462
* php/php-src 8062
* php/php-src@615b800

Related to 1589
llaville added a commit to llaville/php-compatinfo-db that referenced this pull request Oct 11, 2023
llaville added a commit to llaville/php-compatinfo-db that referenced this pull request Nov 18, 2023
llaville added a commit to llaville/php-compatinfo-db that referenced this pull request Nov 23, 2023
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.

4 participants