[PATCH v2] Make bindresvport() function to multithread-safe
Peng Haitao
penght@cn.fujitsu.com
Fri Sep 28 09:27:00 GMT 2012
On 09/24/2012 11:08 PM, Carlos O'Donell wrote:
> Define a macro in an internal header that for generic unix uses __getpid,
> and for Linux it is overriden by a linux-specific header that defines
> that macro as a combination of either INTERNAL_SYSCALL/INLINE_SYSCALL.
>
Thanks.
I have sent v4 patch, please review.
> The whole point of that code is to create a hash function from which
> to start looking for free ports. If the hash function has poor spread
> because you only have __getpid in your OS, then that's not a serious
> issue.
>
> You will still need to present performance data to show how these changes
> effect the performance of the original non-thread-safe version.
>
The single-thread test result is as follows:
Before the patch, execute the test program with 100 times:
# perf stat -r 100 -e instructions -- ./bindresvport_test > /dev/null
Performance counter stats for './bindresvport_test' (100 runs):
106,594,501 instructions # 0.00 insns per cycle ( +- 0.35% )
0.028158698 seconds time elapsed ( +- 0.88% )
After the patch, execute the test program with 100 times:
# perf stat -r 100 -e instructions -- ./bindresvport_test > /dev/null
Performance counter stats for './bindresvport_test' (100 runs):
104,938,026 instructions # 0.00 insns per cycle ( +- 0.44% )
0.027621324 seconds time elapsed ( +- 0.94% )
The multi-threaded test result is as follows:
Before the patch, execute the test program with 100 times:
# perf stat -r 100 -e instructions -- ./bindresvport_mul_test > /dev/null
bindresvport: Address already in use
...
Performance counter stats for './bindresvport_mul_test' (100 runs):
116,481,478 instructions # 0.00 insns per cycle ( +- 0.25% )
0.023839225 seconds time elapsed ( +- 2.04% )
After the patch, execute the test program with 100 times:
# perf stat -r 100 -e instructions -- ./bindresvport_mul_test > /dev/nullbindresvport: Address already in use
bindresvport: Address already in use
...
Performance counter stats for './bindresvport_mul_test' (100 runs):
124,069,053 instructions # 0.00 insns per cycle ( +- 0.32% )
0.021486935 seconds time elapsed ( +- 0.84% )
The single-thread test program is bindresvport_test.c
The multi-thread test program is bindresvport_mul_test.c
--
Best Regards,
Peng
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bindresvport_mul_test.c
Type: text/x-csrc
Size: 1083 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20120928/0f0b3f3d/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bindresvport_test.c
Type: text/x-csrc
Size: 743 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20120928/0f0b3f3d/attachment-0001.bin>
More information about the Libc-alpha
mailing list