File tree 1 file changed +24
-2
lines changed
1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -1969,17 +1969,39 @@ PHP_FUNCTION(socket_set_option)
1969
1969
opt_ptr = & ov ;
1970
1970
optname = SO_DETACH_BPF ;
1971
1971
} else {
1972
+ /**
1973
+ * this socket flag offers a tigher control over the SO_REUSEPORT's algorithm
1974
+ * here binding a socket to a particular cpu set as opposed to the Round-Robin
1975
+ * default one.
1976
+ */
1972
1977
uint32_t k = (uint32_t )Z_LVAL_P (arg4 );
1973
1978
static struct sock_filter cbpf [8 ] = {0 };
1974
1979
static struct sock_fprog bpfprog ;
1975
1980
1981
+ // TODO: might be a good enough approximation, more native api could be used potentially tough
1982
+ long onln = sysconf (_SC_NPROCESSORS_ONLN );
1983
+
1984
+ if (onln == -1 ) {
1985
+ php_error_docref (NULL , E_WARNING , "Online cores fetching failed" );
1986
+ RETURN_FALSE ;
1987
+ }
1988
+
1976
1989
switch (k ) {
1977
1990
case SKF_AD_CPU :
1978
1991
case SKF_AD_QUEUE :
1992
+ /**
1993
+ * we are putting the current socket's filter operation into `A`
1994
+ * instead of the current core, we are dispatching (modulo)
1995
+ * among `onln` cores as opposed to bind it via the raw_smp_processor_id()
1996
+ * kernel call.
1997
+ * Then the sock's filter returns `A`
1998
+ */
1979
1999
cbpf [0 ].code = (BPF_LD |BPF_W |BPF_ABS );
1980
2000
cbpf [0 ].k = (uint32_t )(SKF_AD_OFF + k );
1981
- cbpf [1 ].code = (BPF_RET |BPF_A );
1982
- bpfprog .len = 2 ;
2001
+ cbpf [1 ].code = (BPF_ALU | BPF_MOD );
2002
+ cbpf [1 ].k = (uint32_t )(onln );
2003
+ cbpf [2 ].code = (BPF_RET |BPF_A );
2004
+ bpfprog .len = 3 ;
1983
2005
break ;
1984
2006
default :
1985
2007
php_error_docref (NULL , E_WARNING , "Unsupported CBPF filter" );
You can’t perform that action at this time.
0 commit comments