Skip to content

Commit

Permalink
Added FreeBSD 64bit support (built over 10.1-RELEASE, amd64)
Browse files Browse the repository at this point in the history
  • Loading branch information
menyy2@gmail.com committed Mar 19, 2015
1 parent ef6e82b commit 3f02461
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 39 deletions.
19 changes: 15 additions & 4 deletions configure.ac
Expand Up @@ -30,6 +30,8 @@ case "$host" in
powerpc-*-freebsd*) TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc;;
powerpc*-*-rtems*) TARGET=POWERPC; TARGETDIR=powerpc;;
x86_64-*-*) TARGET=X86_64; TARGETDIR=x86;;
amd64-*-freebsd*) TARGET=FREEBSD; TARGETDIR=x86;;
i386-*-freebsd*) TARGET=FREEBSD; TARGETDIR=x86;;
aarch64-*-*) TARGET=AARCH64; TARGETDIR=aarch64;;
esac

Expand All @@ -47,6 +49,7 @@ AM_CONDITIONAL(ARM, test x$TARGET = xARM)
AM_CONDITIONAL(POWERPC_AIX, test x$TARGET = xPOWERPC_AIX)
AM_CONDITIONAL(POWERPC_DARWIN, test x$TARGET = xPOWERPC_DARWIN)
AM_CONDITIONAL(POWERPC_FREEBSD, test x$TARGET = xPOWERPC_FREEBSD)
AM_CONDITIONAL(FREEBSD, test x$TARGET = xFREEBSD)
AM_CONDITIONAL(AARCH64, test x$TARGET = xAARCH64)

AC_SUBST(TARGET)
Expand Down Expand Up @@ -78,7 +81,11 @@ AC_PROG_CXX
#AC_PROG_LIBTOOL


CXXFLAGS="-Werror -Wall --param inline-unit-growth=200"
if test x$TARGET = xFREEBSD; then
CXXFLAGS="-Wall"
else
CXXFLAGS="-Werror -Wall --param inline-unit-growth=200"
fi
CXXFLAGS="$CXXFLAGS -D__LINUX__ -DVERSION=$VERSION"


Expand Down Expand Up @@ -179,9 +186,13 @@ AC_CHECK_LIB(
[rt], [clock_gettime], [], AC_MSG_ERROR([librt not found]))
AC_CHECK_LIB(
[pthread], [pthread_create], [], AC_MSG_ERROR([libpthread not found]))
AC_CHECK_LIB(
[dl], [dlsym], [], AC_MSG_ERROR([libdl not found]))

if test x$TARGET = xFREEBSD; then
AC_CHECK_LIB(
[execinfo], [backtrace], [], AC_MSG_ERROR([libexecinfo not found]))
else
AC_CHECK_LIB(
[dl], [dlsym], [], AC_MSG_ERROR([libdl not found]))
fi

RPM_RELEASE=1
AC_SUBST(RPM_RELEASE)
Expand Down
4 changes: 4 additions & 0 deletions readme
Expand Up @@ -56,4 +56,8 @@ LD=${CROSS_COMPILE}ld CC=${CROSS_COMPILE}gcc --host i386
4) Invoke make


* To build for FreeBSD

Make sure automake tools are installed.

Good luck!
2 changes: 2 additions & 0 deletions src/Client.cpp
Expand Up @@ -756,11 +756,13 @@ void client_handler(handler_info *p_info)
client_handler<IoPoll> (p_info->fd_min, p_info->fd_max, p_info->fd_num);
break;
}
#ifndef __FreeBSD__
case EPOLL:
{
client_handler<IoEpoll> (p_info->fd_min, p_info->fd_max, p_info->fd_num);
break;
}
#endif
#endif
default:
{
Expand Down
19 changes: 14 additions & 5 deletions src/Defs.h
Expand Up @@ -42,7 +42,13 @@ typedef uint16_t in_port_t;

#else

#ifdef __linux__

#include <features.h>
#include <sys/epoll.h>

#endif

#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
#include <bits/types.h>
#undef __FD_SETSIZE
Expand All @@ -60,7 +66,6 @@ typedef uint16_t in_port_t;
#include <sys/time.h> /* timers*/
#include <sys/socket.h> /* sockets*/
#include <sys/select.h> /* select() According to POSIX 1003.1-2001 */
#include <sys/epoll.h>
#include <sys/syscall.h>
#include <arpa/inet.h> /* internet address manipulation */
#include <netinet/in.h> /* internet address manipulation */
Expand All @@ -86,7 +91,7 @@ typedef uint16_t in_port_t;
#include "Message.h"
#include "Playback.h"

#ifndef WIN32
#if ! defined (WIN32) && ! defined (__FreeBSD__)
#include "vma-redirect.h"
//#define USING_VMA_EXTRA_API
#ifdef USING_VMA_EXTRA_API
Expand Down Expand Up @@ -447,7 +452,7 @@ typedef struct clt_session_info {
//hash/equal_to functions, by ourself.
namespace std
{
#ifndef WIN32
#if ! defined (WIN32) && ! defined (__FreeBSD__)
namespace tr1
{
#endif
Expand Down Expand Up @@ -479,7 +484,7 @@ namespace std
return key.s_addr & 0xFF;
}
};
#ifndef WIN32
#if ! defined (WIN32) && ! defined (__FreeBSD__)
} // closes namespace tr1
#endif
template<>
Expand Down Expand Up @@ -509,9 +514,13 @@ namespace std
}
};
}

#ifndef __FreeBSD__
typedef std::tr1::unordered_map<struct sockaddr_in, clt_session_info_t> seq_num_map;
typedef std::tr1::unordered_map<struct in_addr, size_t> addr_to_id;
#else
typedef std::unordered_map<struct sockaddr_in, clt_session_info_t> seq_num_map;
typedef std::unordered_map<struct in_addr, size_t> addr_to_id;
#endif

extern fds_data** g_fds_array;
extern int IGMP_MAX_MEMBERSHIPS;
Expand Down
3 changes: 2 additions & 1 deletion src/IoHandlers.cpp
Expand Up @@ -231,7 +231,7 @@ int IoPoll::prepareNetwork()

return rc;
}

#ifndef __FreeBSD__
//==============================================================================
//------------------------------------------------------------------------------
IoEpoll::IoEpoll(int _fd_min, int _fd_max, int _fd_num) : IoHandler(_fd_min, _fd_max, _fd_num, 0, 0)
Expand Down Expand Up @@ -291,3 +291,4 @@ int IoEpoll::prepareNetwork()
return rc;
}
#endif
#endif
3 changes: 2 additions & 1 deletion src/IoHandlers.h
Expand Up @@ -297,7 +297,7 @@ class IoPoll: public IoHandler {
struct pollfd *mp_poll_fd_arr;
};


#ifndef __FreeBSD__
//==============================================================================
class IoEpoll: public IoHandler {
public:
Expand Down Expand Up @@ -373,5 +373,6 @@ class IoEpoll: public IoHandler {
int m_max_events;
};
#endif
#endif

#endif /* IOHANDLERS_H_ */
4 changes: 4 additions & 0 deletions src/Message.cpp
Expand Up @@ -27,7 +27,11 @@
*
*/
#include "Message.h"

#ifndef __FreeBSD__
#include <malloc.h>
#endif

#include <string>
#include "common.h"

Expand Down
14 changes: 8 additions & 6 deletions src/Server.cpp
Expand Up @@ -70,7 +70,7 @@ int ServerBase::initBeforeLoop()
if (rc == SOCKPERF_ERR_NONE)
{
log_dbg("thread %lu: fd_min: %d, fd_max : %d, fd_num: %d"
, os_getthread().tid, m_ioHandlerRef.m_fd_min, m_ioHandlerRef.m_fd_max, m_ioHandlerRef.m_fd_num);
, (unsigned long)os_getthread().tid, m_ioHandlerRef.m_fd_min, m_ioHandlerRef.m_fd_max, m_ioHandlerRef.m_fd_num);

// cycle through all set fds in the array (with wrap around to beginning)
for (int ifd = m_ioHandlerRef.m_fd_min; ifd <= m_ioHandlerRef.m_fd_max; ifd++) {
Expand Down Expand Up @@ -123,7 +123,7 @@ int ServerBase::initBeforeLoop()
if (rc == SOCKPERF_ERR_NONE) {
sleep(g_pApp->m_const_params.pre_warmup_wait);
m_ioHandlerRef.warmup(m_pMsgRequest);
log_msg("[tid %lu] using %s() to block on socket(s)", os_getthread().tid, handler2str(g_pApp->m_const_params.fd_handler_type));
log_msg("[tid %lu] using %s() to block on socket(s)", (unsigned long)os_getthread().tid, handler2str(g_pApp->m_const_params.fd_handler_type));
}
}

Expand All @@ -133,7 +133,7 @@ int ServerBase::initBeforeLoop()
//------------------------------------------------------------------------------
void ServerBase::cleanupAfterLoop() {
// cleanup
log_dbg("thread %lu released allocations",os_getthread().tid);
log_dbg("thread %lu released allocations",(unsigned long)os_getthread().tid);

if (!g_pApp->m_const_params.mthread_server) {
log_msg("%s() exit", __func__);
Expand Down Expand Up @@ -377,11 +377,13 @@ void server_handler(handler_info *p_info)
server_handler<IoPoll>(p_info->fd_min, p_info->fd_max, p_info->fd_num);
break;
}
#ifndef __FreeBSD__
case EPOLL:
{
server_handler<IoEpoll>(p_info->fd_min, p_info->fd_max, p_info->fd_num);
break;
}
#endif
#endif
default:
ERROR_MSG("unknown file handler");
Expand Down Expand Up @@ -436,7 +438,7 @@ void find_min_max_fds(int start_look_from, int len, int* p_fd_min, int* p_fd_max
void server_sig_handler(int signum) {
if (g_b_exit) {
log_msg("Test end (interrupted by signal %d)", signum);
log_dbg("thread %lu - exiting", os_getthread().tid);
log_dbg("thread %lu - exiting", (unsigned long)os_getthread().tid);
return;
}

Expand All @@ -448,14 +450,14 @@ void server_sig_handler(int signum) {
if (g_pApp->m_const_params.mthread_server) {
if (os_getthread().tid == thread_pid_array[0].tid) { //main thread
if (g_debug_level >= LOG_LVL_DEBUG) {
log_dbg("Main thread %lu got signal %d - exiting",os_getthread().tid,signum);
log_dbg("Main thread %lu got signal %d - exiting",(unsigned long)os_getthread().tid,signum);
}
else {
log_msg("Got signal %d - exiting", signum);
}
}
else {
log_dbg("Secondary thread %lu got signal %d - exiting", os_getthread().tid,signum);
log_dbg("Secondary thread %lu got signal %d - exiting", (unsigned long)os_getthread().tid,signum);
}
}
else {
Expand Down
40 changes: 27 additions & 13 deletions src/SockPerf.cpp
Expand Up @@ -172,18 +172,22 @@ static const AOPT_DESC common_opt_desc[] =
},
{
'F', AOPT_ARG, aopt_set_literal( 'F' ), aopt_set_string( "iomux-type" ),
#ifndef WIN32
"Type of multiple file descriptors handle [s|select|p|poll|e|epoll|r|recvfrom](default select)."
#else
#ifdef WIN32
"Type of multiple file descriptors handle [s|select|r|recvfrom](default select)."
#elif __FreeBSD__
"Type of multiple file descriptors handle [s|select|p|poll|r|recvfrom](default select)."
#else
"Type of multiple file descriptors handle [s|select|p|poll|e|epoll|r|recvfrom](default select)."
#endif
},
{
OPT_SELECT_TIMEOUT, AOPT_ARG, aopt_set_literal( 0 ), aopt_set_string( "timeout" ),
#ifndef WIN32
"Set select/poll/epoll timeout to <msec>, -1 for infinite (default is 10 msec)."
#else
#ifdef WIN32
"Set select timeout to <msec>, -1 for infinite (default is 10 msec)."
#elif __FreeBSD__
"Set select/poll timeout to <msec>, -1 for infinite (default is 10 msec)."
#else
"Set select/poll/epoll timeout to <msec>, -1 for infinite (default is 10 msec)."
#endif
},
{
Expand Down Expand Up @@ -1681,10 +1685,13 @@ static int parse_common_opt( const AOPT_OBJECT *common_obj )
strncpy(fd_handle_type, optarg, MAX_ARGV_SIZE);
fd_handle_type[MAX_ARGV_SIZE - 1] = '\0';
#ifndef WIN32
#ifndef __FreeBSD__
if (!strcmp( fd_handle_type, "epoll" ) || !strcmp( fd_handle_type, "e")) {
s_user_params.fd_handler_type = EPOLL;
}
else if (!strcmp( fd_handle_type, "poll" )|| !strcmp( fd_handle_type, "p")) {
else
#endif
if (!strcmp( fd_handle_type, "poll" )|| !strcmp( fd_handle_type, "p")) {
s_user_params.fd_handler_type = POLL;
}
else
Expand Down Expand Up @@ -1769,10 +1776,12 @@ static int parse_common_opt( const AOPT_OBJECT *common_obj )
errno = 0;
int value = strtol(optarg, NULL, 0);
if (errno != 0 || value < -1) {
#ifndef WIN32
log_msg("'-%d' Invalid select/poll/epoll timeout val: %s", OPT_SELECT_TIMEOUT, optarg);
#else
#ifdef WIN32
log_msg("'-%d' Invalid select timeout val: %s", OPT_SELECT_TIMEOUT, optarg);
#elif __FreeBSD__
log_msg("'-%d' Invalid select/poll timeout val: %s", OPT_SELECT_TIMEOUT, optarg);
#else
log_msg("'-%d' Invalid select/poll/epoll timeout val: %s", OPT_SELECT_TIMEOUT, optarg);
#endif
rc = SOCKPERF_ERR_BAD_ARGUMENT;
}
Expand Down Expand Up @@ -1934,7 +1943,7 @@ static int parse_common_opt( const AOPT_OBJECT *common_obj )
rc = SOCKPERF_ERR_BAD_ARGUMENT;
}
#endif

#ifndef __FreeBSD__
if ( !rc && aopt_check(common_obj, OPT_LOAD_VMA) ) {
const char* optarg = aopt_value(common_obj, OPT_LOAD_VMA);
//s_user_params.b_load_vma = true;
Expand All @@ -1946,6 +1955,7 @@ static int parse_common_opt( const AOPT_OBJECT *common_obj )
rc = SOCKPERF_ERR_BAD_ARGUMENT;
}
}
#endif
#endif

if ( !rc && aopt_check(common_obj, OPT_TCP) ) {
Expand Down Expand Up @@ -2172,7 +2182,7 @@ static void set_select_timeout(int time_out_msec)
//------------------------------------------------------------------------------
void set_defaults()
{
#ifndef WIN32
#if ! defined (WIN32) && ! defined (__FreeBSD__)
bool success = vma_set_func_pointers(false);
if (!success) {
log_dbg("Failed to set function pointers for system functions.");
Expand Down Expand Up @@ -2753,7 +2763,11 @@ static int set_sockets_from_feedfile(const char *feedfile_name)
return SOCKPERF_ERR_NOT_EXIST;
}
/* a map to keep records on the address we received */
#ifndef __FreeBSD__
std::tr1::unordered_map<port_and_type, int> fd_socket_map; //<port,fd>
#else
std::unordered_map<port_and_type, int> fd_socket_map; //<port,fd>
#endif

while (!rc && (res = fgets(line, MAX_MCFILE_LINE_LENGTH, file_fd))) {
if (!res) {
Expand Down Expand Up @@ -3164,7 +3178,7 @@ int bringup(const int *p_daemonize)
Message::initMaxSize(_max_buff_size);
Message::initMaxSeqNo(_maxSequenceNo);

if (!s_user_params.b_stream && !s_user_params.mode == MODE_SERVER) {
if (!s_user_params.b_stream && (!s_user_params.mode) == MODE_SERVER) {
g_pPacketTimes = new PacketTimes(_maxSequenceNo,
s_user_params.reply_every,
s_user_params.client_work_with_srv_num);
Expand Down
4 changes: 4 additions & 0 deletions src/Ticks.h
Expand Up @@ -99,6 +99,10 @@ with simple integral values. The following describes these calculations:
#include <stdint.h>// for int64_t
#include <stdlib.h>// for qsort

#ifdef __FreeBSD__
#include <sys/time.h>
#endif

#include "ticks_os.h"

// usefull constants
Expand Down
2 changes: 1 addition & 1 deletion src/common.cpp
Expand Up @@ -166,7 +166,7 @@ int set_affinity_list(os_thread_t thread, const char * cpu_list)
}
if ( (rc == SOCKPERF_ERR_NONE) && os_set_affinity(thread, mycpuset))
{
log_err("Set thread affinity failed to set tid(%lu) to cpu(%s)", thread.tid, cpu_list);
log_err("Set thread affinity failed to set tid(%lu) to cpu(%s)", (unsigned long)thread.tid, cpu_list);
rc = SOCKPERF_ERR_FATAL;
}

Expand Down
6 changes: 4 additions & 2 deletions src/os_abstract.cpp
Expand Up @@ -63,7 +63,7 @@ void os_printf_backtrace(void)
char **strings;
void* m_backtrace[25];
int m_backtrace_size = backtrace(m_backtrace, 25);
printf("sockperf: [tid: %lu] ------\n", os_getthread().tid);
printf("sockperf: [tid: %lu] ------\n", (unsigned long)os_getthread().tid);
strings = backtrace_symbols(m_backtrace, m_backtrace_size);
for (int i = 0; i < m_backtrace_size; i++)
printf("sockperf: [%i] %p: %s\n", i, m_backtrace[i], strings[i]);
Expand Down Expand Up @@ -151,6 +151,8 @@ os_thread_t os_getthread(void)
#ifdef WIN32
mythread.tid = GetCurrentThreadId();
mythread.hThread = GetCurrentThread();
#elif __FreeBSD__
mythread.tid = pthread_self();
#else
mythread.tid = syscall(__NR_gettid);
#endif
Expand Down Expand Up @@ -386,7 +388,7 @@ int os_set_affinity(const os_thread_t & thread, const os_cpuset_t &_mycpuset)
return -1;
#else
// Can't use thread.tid since it's syscall and not pthread_t
if (0 != pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &(_mycpuset.cpuset)))
if (0 != pthread_setaffinity_np(pthread_self(), sizeof(os_cpuset_t), &(_mycpuset.cpuset)))
return -1;
#endif
return 0;
Expand Down

0 comments on commit 3f02461

Please sign in to comment.