Beware of using “perf top” and “perf record” simultaneously

My OS is RHEL7 and my perf version is:

perf version 3.10.0-514.16.1.el7.x86_64.debug

My application bonds some threads with dedicated CPUs (1-13,15-27,31-41,43-55). During its running, I use “perf top” to observe these dedicated CPUs:

$ sudo perf top -C 1-13,15-27,31-41,43-55

At the same time, if I use “perf record” to sample the whole process:

$ sudo perf record -g -p 22530

perf record” can’t sample threads running on CPUs monitored by “perf top“. So please be cautious when using “perf top” and “perf record” simultaneously.

Build open source projects without configure script

Some open source projects don’t provide configure script. Take nio-tlsf as an example. You can see there are only Makefile.am and configure.ac. For projects like it, you need to run autoreconf to generate configure script:

$ autoreconf
aclocal: warning: couldn't open directory 'm4': No such file or directory
configure.ac:21: error: required file 'build-aux/compile' not found
configure.ac:21:   'automake --add-missing' can install 'compile'
configure.ac:22: error: required file 'build-aux/config.guess' not found
configure.ac:22:   'automake --add-missing' can install 'config.guess'
configure.ac:22: error: required file 'build-aux/config.sub' not found
configure.ac:22:   'automake --add-missing' can install 'config.sub'
configure.ac:15: error: required file 'build-aux/install-sh' not found
configure.ac:15:   'automake --add-missing' can install 'install-sh'
configure.ac:22: error: required file 'build-aux/ltmain.sh' not found
configure.ac:15: error: required file 'build-aux/missing' not found
configure.ac:15:   'automake --add-missing' can install 'missing'
Makefile.am: error: required file 'build-aux/depcomp' not found
Makefile.am:   'automake --add-missing' can install 'depcomp'
autoreconf: automake failed with exit status: 1

There are so many “... not found” errors, and “autoreconf --install” can fix them:

$ autoreconf --install
aclocal: warning: couldn't open directory 'm4': No such file or directory
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'.
libtoolize: copying file 'build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
configure.ac:21: installing 'build-aux/compile'
configure.ac:22: installing 'build-aux/config.guess'
configure.ac:22: installing 'build-aux/config.sub'
configure.ac:15: installing 'build-aux/install-sh'
configure.ac:15: installing 'build-aux/missing'
Makefile.am: installing 'build-aux/depcomp'

Now configure script is generated successfully, and you can build the whole project.

Use alignof in gcc

alignof is defined in stdalign.h for gcc:

$ cat /usr/lib/gcc/x86_64-unknown-linux-gnu/9.1.0/include/stdalign.h
......
#ifndef _STDALIGN_H
#define _STDALIGN_H

#ifndef __cplusplus

#define alignas _Alignas
#define alignof _Alignof

#define __alignas_is_defined 1
#define __alignof_is_defined 1

#endif

#endif  /* stdalign.h */

To use alignofstdalign.h must be included, otherwise following errors will be reported:

......
warning: implicit declaration of function 'alignof' [-Wimplicit-function-declaration]
    3 |  return alignof(int);
      |         ^~~~~~~
 error: expected expression before

It is no need to include any header files to use _Alignof and __alignof__.

The ISN for retransmitting SYN

RFC 793 illustrates a scenario in which TCP client and server pick different ISN (Initial Sequence Number) when processing duplicate SYN packets. Form 13.2.3 Initial Sequence Number (ISN)TCP/IP Illustrated, Volume 1, I find following evidence:

Before each end sends its SYN to establish the connection, it chooses an ISN for that connection. The ISN should change over time, so that each connection has a different one. [RFC0793] specifies that the ISN should be viewed as a 32-bit counter that increments by 1 every 4μs. The purpose of doing this is to arrange for the sequence numbers for segments on one connection to not overlap with sequence numbers on a another (new) identical connection. In particular, new sequence numbers must not be allowed to overlap between different instantiations (or incarnations) of the same connection.

Reference:
What will happen at server side if it received 2 SYN packet from the same client application?.