inline
Alejandro Colomar
alx.manpages at gmail.com
Thu Jun 2 15:12:06 UTC 2022
On 6/2/22 01:49, Alejandro Colomar wrote:
> I'm concerned that we may be inlining too much.
>
>
> See for example the following function calls:
>
> $ grep -rnA1 nxt_slow_path | grep -B1 nxt_thread_get_tid
> src/nxt_thread.c:247: if (nxt_slow_path(thr->tid == 0)) {
> src/nxt_thread.c-248- thr->tid = nxt_thread_get_tid();
> --
> src/nxt_thread.c:257: if (nxt_slow_path(thr->tid == 0)) {
> src/nxt_thread.c-258- thr->tid = nxt_thread_get_tid();
>
>
> Looks good, but then see the definition of nxt_thread_get_tid() (it has
> several difinitions, one for each system, but I'll copy here one that is
> pretty big (NXT_AIX)):
>
>
[...]
>
>
> We're inlining a *huge* function in some cases where we know it's a slow
> path. We could do better by marking the function as inline (without
> [[gnu::always_inline]]), and let the compiler decide that it doesn't
> want to inline when it's in an `nxt_slow_path()`.
>
I found the following functions that are being inlined within
nxt_slow_path(), which seems wrong:
$ find src \
| grep '\.[ch]$' \
| xargs pcregrep -M '(?s)nxt(_always)?_inline[\s\w\*]*\s\*?\w+\(' \
| grep -o '\w\+(' \
| sed 's/(//' \
| while read f; do
find src \
| grep '\.[ch]$' \
| xargs pcregrep -Mn
'(?s)^(\s+)[^\n]*nxt_slow_path(?:(?!^\1?}).)*?\b'"$f"'\b(?:(?!\1}).)*?^\1}'
\
| sed -E 's/^[^:]+:[0-9]+:/\n\n&\n/' \
| grep -o "\b$f\b";
# You can filter with the following instead of `grep -o ...`
# to view the code (remember to remove |sort|uniq):
# | perl -pe 's/('"$f"')/\033[32m\1\033[0m/';
done \
| sort \
| uniq;
nxt_array_init
nxt_array_remove_last
nxt_buf_cpystr
nxt_buf_dummy_completion
nxt_cpymem
nxt_fastcgi_param_length
nxt_h1p_request_error
nxt_http_date
nxt_mp_chunk_pages_index
nxt_next_highest_power_of_two
nxt_perl_psgi_add_sptr
nxt_perl_psgi_add_str
nxt_perl_psgi_add_value
nxt_perl_psgi_cb_request_done
nxt_pivot_root
nxt_port_close_fds
nxt_port_mmap_chunk_id
nxt_port_mmap_chunk_start
nxt_port_mmap_set_chunk_free
nxt_port_rpc_lhq_peer
nxt_port_socket_write
nxt_thread_event_engine
nxt_thread_get_tid
nxt_unit_close
nxt_unit_mmap_buf_insert
nxt_unit_process_release
These functions should not be forced to be inline (except oneliners).
Cheers,
Alex
--
Alejandro Colomar
<http://www.alejandro-colomar.es/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://mailman.nginx.org/pipermail/unit/attachments/20220602/ec512e5d/attachment.bin>
More information about the unit
mailing list