From 2004e0c894424b92118cb8909ae45b22318b8442 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 4 Sep 2023 11:25:29 +0200 Subject: Merging upstream version 2.13.1. Signed-off-by: Daniel Baumann --- src/Makefile.in | 14 +++--- src/config.h.in | 10 ++-- src/dnsperf.c | 138 ++++++++++++++++++++++++++++++++------------------- src/net.h | 4 +- src/net_tcp.c | 7 ++- src/resperf.c | 2 +- src/test/Makefile.in | 11 ++-- 7 files changed, 115 insertions(+), 71 deletions(-) (limited to 'src') diff --git a/src/Makefile.in b/src/Makefile.in index 1b510c7..8b0716a 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.1 from Makefile.am. +# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2018 Free Software Foundation, Inc. +# Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -267,8 +267,8 @@ am__recursive_targets = \ AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ distdir distdir-am am__extra_recursive_targets = gcov-recursive -am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \ - $(LISP)config.h.in +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \ + config.h.in # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. @@ -285,8 +285,6 @@ am__define_uniq_tagged_files = \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` -ETAGS = etags -CTAGS = ctags DIST_SUBDIRS = $(SUBDIRS) am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in \ $(top_srcdir)/depcomp @@ -329,6 +327,8 @@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ +CSCOPE = @CSCOPE@ +CTAGS = @CTAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ @@ -339,6 +339,7 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ +ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ @@ -828,7 +829,6 @@ cscopelist-am: $(am__tagged_files) distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am diff --git a/src/config.h.in b/src/config.h.in index bdd273f..e0341dc 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -24,9 +24,6 @@ /* Define to 1 if you have the `nghttp2' library (-lnghttp2). */ #undef HAVE_LIBNGHTTP2 -/* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H - /* Define to 1 if you have the header file. */ #undef HAVE_NGHTTP2_H @@ -42,6 +39,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H +/* Define to 1 if you have the header file. */ +#undef HAVE_STDIO_H + /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H @@ -91,7 +91,9 @@ your system. */ #undef PTHREAD_CREATE_JOINABLE -/* Define to 1 if you have the ANSI C header files. */ +/* Define to 1 if all of the C90 standard headers exist (not just the ones + required in a freestanding environment). This macro is provided for + backward compatibility; new code need not use it. */ #undef STDC_HEADERS /* Version number of package */ diff --git a/src/dnsperf.c b/src/dnsperf.c index cca4710..f124f64 100644 --- a/src/dnsperf.c +++ b/src/dnsperf.c @@ -66,7 +66,7 @@ #define TIMEOUT_CHECK_TIME 100000 -#define MAX_INPUT_DATA (64 * 1024) +#define MAX_INPUT_DATA (64 * 1024) + 2 #define MAX_SOCKETS 256 @@ -853,6 +853,40 @@ wait_for_start(void) PERF_UNLOCK(&start_lock); } +static inline void +bit_set(unsigned char* bits, unsigned int bit) +{ + unsigned int shift, mask; + + shift = 7 - (bit % 8); + mask = 1 << shift; + + bits[bit / 8] |= mask; +} + +static inline void +bit_clear(unsigned char* bits, unsigned int bit) +{ + unsigned int shift, mask; + + shift = 7 - (bit % 8); + mask = 1 << shift; + + bits[bit / 8] &= ~mask; +} + +static inline bool +bit_check(unsigned char* bits, unsigned int bit) +{ + unsigned int shift; + + shift = 7 - (bit % 8); + + if ((bits[bit / 8] >> shift) & 0x01) + return true; + return false; +} + static void* do_send(void* arg) { @@ -871,9 +905,10 @@ do_send(void* arg) unsigned char packet_buffer[MAX_EDNS_PACKET]; unsigned char* base; unsigned int length; - int n, i, any_inprogress = 0; + int n, i, any_inprogress = 0, sock = 0; perf_result_t result; bool all_fail; + unsigned char socketbits[(MAX_SOCKETS / 8) + 1] = {}; tinfo = (threadinfo_t*)arg; config = tinfo->config; @@ -900,6 +935,21 @@ do_send(void* arg) now = perf_get_time(); } + /* Some sock might still be sending, try flush all of them */ + if (any_inprogress) { + any_inprogress = 0; + for (i = 0; i < tinfo->nsocks; i++) { + if (!bit_check(socketbits, i)) { + continue; + } + if (!perf_net_sockready(tinfo->socks[i], threadpipe[0], TIMEOUT_CHECK_TIME)) { + any_inprogress = 1; + } else { + bit_clear(socketbits, i); + } + } + } + /* Rate limiting */ if (tinfo->max_qps > 0) { /* the 1 second time slice where q_sent is calculated over */ @@ -910,36 +960,40 @@ do_send(void* arg) } /* limit QPS over the 1 second slice */ if (q_sent >= tinfo->max_qps) { - wait_us = q_slice - now; - if (config->qps_threshold_wait && wait_us > config->qps_threshold_wait) { - wait_us -= config->qps_threshold_wait; - struct timespec ts = { 0, 0 }; - if (wait_us >= MILLION) { - ts.tv_sec = wait_us / MILLION; - ts.tv_nsec = (wait_us % MILLION) * 1000; - } else { - ts.tv_sec = 0; - ts.tv_nsec = wait_us * 1000; + if (!any_inprogress) { // only if nothing is in-progress + wait_us = q_slice - now; + if (config->qps_threshold_wait && wait_us > config->qps_threshold_wait) { + wait_us -= config->qps_threshold_wait; + struct timespec ts = { 0, 0 }; + if (wait_us >= MILLION) { + ts.tv_sec = wait_us / MILLION; + ts.tv_nsec = (wait_us % MILLION) * 1000; + } else { + ts.tv_sec = 0; + ts.tv_nsec = wait_us * 1000; + } + nanosleep(&ts, NULL); } - nanosleep(&ts, NULL); } now = perf_get_time(); continue; } /* handle stepping to the next window to send a query on */ if (req_time > now) { - wait_us = req_time - now; - if (config->qps_threshold_wait && wait_us > config->qps_threshold_wait) { - wait_us -= config->qps_threshold_wait; - struct timespec ts = { 0, 0 }; - if (wait_us >= MILLION) { - ts.tv_sec = wait_us / MILLION; - ts.tv_nsec = (wait_us % MILLION) * 1000; - } else { - ts.tv_sec = 0; - ts.tv_nsec = wait_us * 1000; + if (!any_inprogress) { // only if nothing is in-progress + wait_us = req_time - now; + if (config->qps_threshold_wait && wait_us > config->qps_threshold_wait) { + wait_us -= config->qps_threshold_wait; + struct timespec ts = { 0, 0 }; + if (wait_us >= MILLION) { + ts.tv_sec = wait_us / MILLION; + ts.tv_nsec = (wait_us % MILLION) * 1000; + } else { + ts.tv_sec = 0; + ts.tv_nsec = wait_us * 1000; + } + nanosleep(&ts, NULL); } - nanosleep(&ts, NULL); } now = perf_get_time(); continue; @@ -951,7 +1005,9 @@ do_send(void* arg) /* Limit in-flight queries */ if (num_outstanding(stats) >= tinfo->max_outstanding) { - PERF_TIMEDWAIT(&tinfo->cond, &tinfo->lock, ×->stop_time_ns, NULL); + if (!any_inprogress) { // only if nothing is in-progress + PERF_TIMEDWAIT(&tinfo->cond, &tinfo->lock, ×->stop_time_ns, NULL); + } PERF_UNLOCK(&tinfo->lock); now = perf_get_time(); continue; @@ -964,7 +1020,8 @@ do_send(void* arg) i = tinfo->nsocks * 2; all_fail = true; while (i--) { - q->sock = tinfo->socks[tinfo->current_sock++ % tinfo->nsocks]; + sock = tinfo->current_sock++ % tinfo->nsocks; + q->sock = tinfo->socks[sock]; switch (perf_net_sockready(q->sock, threadpipe[0], TIMEOUT_CHECK_TIME)) { case 0: if (config->verbose && !config->suppress.sockready) { @@ -1060,6 +1117,7 @@ do_send(void* arg) perf_log_warning("network congested, packet sending in progress"); } any_inprogress = 1; + bit_set(socketbits, sock); } else { if (config->verbose && !config->suppress.sendfailed) { char __s[256]; @@ -1185,29 +1243,6 @@ recv_one(threadinfo_t* tinfo, int which_sock, return true; } -static inline void -bit_set(unsigned char* bits, unsigned int bit) -{ - unsigned int shift, mask; - - shift = 7 - (bit % 8); - mask = 1 << shift; - - bits[bit / 8] |= mask; -} - -static inline bool -bit_check(unsigned char* bits, unsigned int bit) -{ - unsigned int shift; - - shift = 7 - (bit % 8); - - if ((bits[bit / 8] >> shift) & 0x01) - return true; - return false; -} - static void* do_recv(void* arg) { @@ -1217,7 +1252,7 @@ do_recv(void* arg) received_query_t recvd[RECV_BATCH_SIZE] = { { 0, 0, 0, 0, 0, 0, false, false, 0 } }; unsigned int nrecvd; int saved_errno; - unsigned char socketbits[MAX_SOCKETS / 8]; + unsigned char socketbits[(MAX_SOCKETS / 8) + 1]; uint64_t now, latency; query_info* q; unsigned int current_socket, last_socket; @@ -1640,8 +1675,7 @@ int main(int argc, char** argv) perf_os_handlesignal(SIGINT, handle_sigint); perf_os_blocksignal(SIGINT, false); sock.fd = mainpipe[0]; - result = perf_os_waituntilreadable(&sock, intrpipe[0], - times.stop_time - times.start_time); + result = perf_os_waituntilreadable(&sock, intrpipe[0], times.stop_time - times.start_time); if (result == PERF_R_CANCELED) interrupted = true; diff --git a/src/net.h b/src/net.h index 56de624..25b9251 100644 --- a/src/net.h +++ b/src/net.h @@ -28,8 +28,8 @@ #include #include -#define TCP_RECV_BUF_SIZE (16 * 1024) -#define TCP_SEND_BUF_SIZE (4 * 1024) +#define TCP_RECV_BUF_SIZE (65535 + 2) +#define TCP_SEND_BUF_SIZE (65535 + 2) struct perf_sockaddr { union { diff --git a/src/net_tcp.c b/src/net_tcp.c index 026dcce..fe3317b 100644 --- a/src/net_tcp.c +++ b/src/net_tcp.c @@ -297,6 +297,9 @@ static int perf__tcp_sockready(struct perf_net_socket* sock, int pipe_fd, int64_ dnslen = ntohs(dnslen); n = sendto(sock->fd, self->sendbuf + self->sending, dnslen + 2 - self->sending, 0, 0, 0); if (n < 0) { + if (errno == EAGAIN) { + return 0; + } int fd = perf__tcp_connect(sock), oldfd = ck_pr_load_int(&sock->fd); ck_pr_store_int(&sock->fd, fd); close(oldfd); @@ -364,7 +367,9 @@ conn_cont: dnslen = ntohs(dnslen); n = sendto(sock->fd, self->sendbuf + self->sending, dnslen + 2 - self->sending, 0, 0, 0); if (n < 0) { - self->need_reconnect = true; + if (errno != EAGAIN) { + self->need_reconnect = true; + } return 0; } self->sending += n; diff --git a/src/resperf.c b/src/resperf.c index 031d751..d11e232 100644 --- a/src/resperf.c +++ b/src/resperf.c @@ -61,7 +61,7 @@ #define DEFAULT_MAX_OUTSTANDING (64 * 1024) #define DEFAULT_MAX_FALL_BEHIND 1000 -#define MAX_INPUT_DATA (64 * 1024) +#define MAX_INPUT_DATA (64 * 1024) + 2 #define TIMEOUT_CHECK_TIME 5000000 diff --git a/src/test/Makefile.in b/src/test/Makefile.in index 04eafad..836ced2 100644 --- a/src/test/Makefile.in +++ b/src/test/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.1 from Makefile.am. +# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2018 Free Software Foundation, Inc. +# Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -306,6 +306,7 @@ am__set_TESTS_bases = \ bases='$(TEST_LOGS)'; \ bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \ bases=`echo $$bases` +AM_TESTSUITE_SUMMARY_HEADER = ' for $(PACKAGE_STRING)' RECHECK_LOGS = $(TEST_LOGS) AM_RECURSIVE_TARGETS = check recheck TEST_SUITE_LOG = test-suite.log @@ -343,6 +344,8 @@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ +CSCOPE = @CSCOPE@ +CTAGS = @CTAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ @@ -353,6 +356,7 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ +ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ @@ -631,7 +635,7 @@ $(TEST_SUITE_LOG): $(TEST_LOGS) test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG); \ fi; \ echo "$${col}$$br$${std}"; \ - echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}"; \ + echo "$${col}Testsuite summary"$(AM_TESTSUITE_SUMMARY_HEADER)"$${std}"; \ echo "$${col}$$br$${std}"; \ create_testsuite_report --maybe-color; \ echo "$$col$$br$$std"; \ @@ -728,7 +732,6 @@ test7.sh.log: test7.sh @am__EXEEXT_TRUE@ --log-file $$b.log --trs-file $$b.trs \ @am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \ @am__EXEEXT_TRUE@ "$$tst" $(AM_TESTS_FD_REDIRECT) - distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am -- cgit v1.2.3