From 7e025a1ed97016c2afefc3e923d5c1cdd5ecd0e0 Mon Sep 17 00:00:00 2001 From: salsal97 Date: Thu, 11 Feb 2021 19:34:58 +0000 Subject: [PATCH 1/4] added changes to build on alpine without itimers --- config.h | 92 ++++++++++++++++++++++++++++++++++++++++++++++ src/client.cpp | 29 ++++++++++++++- src/ticks.h | 1 + src/vma-redirect.h | 3 +- 4 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 config.h diff --git a/config.h b/config.h new file mode 100644 index 00000000..a3db7158 --- /dev/null +++ b/config.h @@ -0,0 +1,92 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Enable debugging */ +/* #undef DEBUG */ + +/* Define to 1 if you have the header file. */ +#define HAVE_ARPA_INET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_NETINET_IN_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYSLOG_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_IOCTL_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_SOCKET_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TERMIOS_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Disable debugging */ +#define NDEBUG /**/ + +/* Name of package */ +#define PACKAGE "sockperf" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "http://github.com/mellanox/sockperf/issues" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "SOCKPERF" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "SOCKPERF 3.7-3.gita722495b9d92.dirty" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "sockperf" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "3.7-3.gita722495b9d92.dirty" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* [Enable using VMA extra API] */ +/* #undef USING_VMA_EXTRA_API */ + +/* Version number of package */ +#define VERSION "3.7-3.gita722495b9d92.dirty" + +/* When there is no itimer syscall support in the kernel */ +#define NO_TIMERS \ No newline at end of file diff --git a/src/client.cpp b/src/client.cpp index a355089e..6489f777 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -35,6 +35,11 @@ TicksTime s_startTime, s_endTime; +#ifdef NO_TIMERS + pthread_t parent; + struct itimerval timer; +#endif + //============================================================================== //============================================================================== @@ -524,6 +529,17 @@ static int _connect_check(int ifd) { return rc; } +#ifdef NO_TIMERS +void* thread_sleep(void* args) +{ + // struct itimerval *temp_timer = (struct itimerval *) args; + log_msg("Start sleep for %d seconds", (int)((struct itimerval *)args)->it_value.tv_sec); + sleep(((struct itimerval *)args)->it_value.tv_sec); + pthread_kill(parent, SIGUSR1); + return NULL; +} +#endif + //------------------------------------------------------------------------------ template @@ -637,12 +653,21 @@ int Clientm_const_params.pPlaybackVector) { - struct itimerval timer; - set_client_timer(&timer); + set_client_timer(&timer); // initializes ticks to timer + #ifndef NO_TIMERS if (os_set_duration_timer(timer, client_sig_handler)) { log_err("Failed setting test duration timer"); rc = SOCKPERF_ERR_FATAL; } + #else + parent = pthread_self(); + os_set_signal_action(SIGUSR1, client_sig_handler); + + os_thread_t thread; + os_thread_init(&thread); + os_thread_exec(&thread, thread_sleep, &timer); + os_thread_detach(&thread); + #endif } if (rc == SOCKPERF_ERR_NONE) { diff --git a/src/ticks.h b/src/ticks.h index 3bf932ad..69169ef7 100644 --- a/src/ticks.h +++ b/src/ticks.h @@ -103,6 +103,7 @@ with simple integral values. The following describes these calculations: #endif #include "ticks_os.h" +#include "os_abstract.h" // usefull constants static const int64_t USEC_IN_SEC = 1000 * 1000; diff --git a/src/vma-redirect.h b/src/vma-redirect.h index 2467bef0..aed846aa 100644 --- a/src/vma-redirect.h +++ b/src/vma-redirect.h @@ -33,7 +33,8 @@ #include #include #include -#include +#include +#include #include #include From 491c02a2aecbc4abc313c2f4862315e849f72714 Mon Sep 17 00:00:00 2001 From: salsal97 Date: Thu, 11 Feb 2021 19:41:08 +0000 Subject: [PATCH 2/4] remove config --- config.h | 92 -------------------------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 config.h diff --git a/config.h b/config.h deleted file mode 100644 index a3db7158..00000000 --- a/config.h +++ /dev/null @@ -1,92 +0,0 @@ -/* config.h. Generated from config.h.in by configure. */ -/* config.h.in. Generated from configure.ac by autoheader. */ - -/* Enable debugging */ -/* #undef DEBUG */ - -/* Define to 1 if you have the header file. */ -#define HAVE_ARPA_INET_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_NETINET_IN_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYSLOG_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_IOCTL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SOCKET_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TIME_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_TERMIOS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Disable debugging */ -#define NDEBUG /**/ - -/* Name of package */ -#define PACKAGE "sockperf" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "http://github.com/mellanox/sockperf/issues" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "SOCKPERF" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "SOCKPERF 3.7-3.gita722495b9d92.dirty" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "sockperf" - -/* Define to the home page for this package. */ -#define PACKAGE_URL "" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "3.7-3.gita722495b9d92.dirty" - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* [Enable using VMA extra API] */ -/* #undef USING_VMA_EXTRA_API */ - -/* Version number of package */ -#define VERSION "3.7-3.gita722495b9d92.dirty" - -/* When there is no itimer syscall support in the kernel */ -#define NO_TIMERS \ No newline at end of file From 2aafa927daf4b90bf0176af5701a3b2b38d55f05 Mon Sep 17 00:00:00 2001 From: salsal97 Date: Thu, 11 Feb 2021 19:51:17 +0000 Subject: [PATCH 3/4] handled timer declaration --- src/client.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/client.cpp b/src/client.cpp index 6489f777..092e21ef 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -653,13 +653,15 @@ int Clientm_const_params.pPlaybackVector) { - set_client_timer(&timer); // initializes ticks to timer #ifndef NO_TIMERS + struct itimerval timer; + set_client_timer(&timer); if (os_set_duration_timer(timer, client_sig_handler)) { log_err("Failed setting test duration timer"); rc = SOCKPERF_ERR_FATAL; } #else + set_client_timer(&timer); parent = pthread_self(); os_set_signal_action(SIGUSR1, client_sig_handler); From bff2d3556708a0de30beeb5d9f9e31c2d4c134a5 Mon Sep 17 00:00:00 2001 From: salsal97 Date: Fri, 12 Feb 2021 23:16:46 +0000 Subject: [PATCH 4/4] made sleep implementation independant of timer, addressed PR comments --- src/client.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 092e21ef..0ae36340 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -35,9 +35,8 @@ TicksTime s_startTime, s_endTime; -#ifdef NO_TIMERS +#ifdef NO_SETITIMERS_SYSCALL pthread_t parent; - struct itimerval timer; #endif //============================================================================== @@ -529,12 +528,15 @@ static int _connect_check(int ifd) { return rc; } -#ifdef NO_TIMERS +#ifdef NO_SETITIMERS_SYSCALL void* thread_sleep(void* args) { - // struct itimerval *temp_timer = (struct itimerval *) args; - log_msg("Start sleep for %d seconds", (int)((struct itimerval *)args)->it_value.tv_sec); - sleep(((struct itimerval *)args)->it_value.tv_sec); + int sec = (g_pApp->m_const_params.cooldown_msec + g_pApp->m_const_params.warmup_msec) / 1000 + + g_pApp->m_const_params.sec_test_duration; + int usec = (g_pApp->m_const_params.cooldown_msec + g_pApp->m_const_params.warmup_msec) % 1000; + log_msg("Start sleep for %d seconds %d useconds", sec, usec); + sleep(sec); + usleep(usec); pthread_kill(parent, SIGUSR1); return NULL; } @@ -653,7 +655,7 @@ int Clientm_const_params.pPlaybackVector) { - #ifndef NO_TIMERS + #ifndef NO_SETITIMERS_SYSCALL struct itimerval timer; set_client_timer(&timer); if (os_set_duration_timer(timer, client_sig_handler)) { @@ -661,13 +663,12 @@ int Client