This commit is contained in:
quackerd 2023-03-13 09:08:44 +01:00
parent b4e9801d98
commit 1f8a006678
10 changed files with 88 additions and 33 deletions

View File

@ -6,12 +6,14 @@ find_package(PkgConfig REQUIRED)
find_package(OpenSSL REQUIRED)
pkg_check_modules(bsock REQUIRED bsock)
set(CFLAGS -Wall -Wextra -Werror -std=c++20 -O3 -g)
set(CXXFLAGS -Wall -Wextra -Werror -std=c++20 -O3 -g)
set(CFLAGS -Wall -Wextra -Werror -std=c2x -O3 -g)
add_library(common OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/common/io.cc)
add_library(common OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/common/io.cc
${CMAKE_CURRENT_SOURCE_DIR}/common/logger.cc)
target_link_directories(common PRIVATE ${bsock_LIBRARY_DIRS})
target_link_libraries(common ${bsock_LIBRARIES})
target_compile_options(common PRIVATE ${CFLAGS})
target_compile_options(common PRIVATE ${CXXFLAGS})
target_include_directories(common PRIVATE ${bsock_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_executable(dsmbr ${CMAKE_CURRENT_SOURCE_DIR}/dsmbr/dsmbr.cc
@ -19,13 +21,13 @@ add_executable(dsmbr ${CMAKE_CURRENT_SOURCE_DIR}/dsmbr/dsmbr.cc
${CMAKE_CURRENT_SOURCE_DIR}/dsmbr/generator.cc)
target_link_libraries(dsmbr common pthread OpenSSL::SSL ${bsock_LIBRARIES})
target_link_directories(dsmbr PRIVATE ${bsock_LIBRARY_DIRS})
target_compile_options(dsmbr PRIVATE ${CFLAGS})
target_compile_options(dsmbr PRIVATE ${CXXFLAGS})
target_include_directories(dsmbr PRIVATE ${bsock_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_executable(ppd ${CMAKE_CURRENT_SOURCE_DIR}/ppd/ppd.cc)
target_link_libraries(ppd pthread common OpenSSL::SSL ${bsock_LIBRARIES})
target_link_directories(ppd PRIVATE ${bsock_LIBRARY_DIRS})
target_compile_options(ppd PRIVATE ${CFLAGS})
target_compile_options(ppd PRIVATE ${CXXFLAGS})
target_include_directories(ppd PRIVATE ${bsock_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/modules)

View File

@ -10,7 +10,6 @@
#include "io.h"
#include <algorithm>
#include <cerrno>
static ssize_t
ppd_read_ssl(void * _ctx, void *buf, size_t len)

15
common/logger.cc Normal file
View File

@ -0,0 +1,15 @@
#include <logger.h>
static unsigned int verbosity = 0;
void
logger_set_verbosity(unsigned int v)
{
verbosity = v;
}
unsigned int
logger_get_verbosity(void)
{
return verbosity;
}

View File

@ -388,7 +388,7 @@ dsmbr_worker_main(void *ctx)
rec->recv_size = recv_size;
rec->recv_ts = cur_ts;
tinfo->stats.push_back(rec);
V("Thread %d connection %d RECV msg of size %u latency %lu\n",
D("Thread %d connection %d RECV msg of size %u latency %lu\n",
tinfo->tid, conn->conn_fd, mbuf->size,
rec->recv_ts - rec->send_ts);
} else {
@ -428,7 +428,7 @@ dsmbr_worker_main(void *ctx)
conn->req_in_flight.push_back(rec);
conn->next_send += (uint64_t)(conn->ia_gen->generate() *
(double)S2US);
V("Thread %d connection %d SEND msg of size %lu\n", tinfo->tid,
D("Thread %d connection %d SEND msg of size %lu\n", tinfo->tid,
conn->conn_fd, out_sz);
}
}
@ -636,8 +636,13 @@ dsmbr_getopt(int argc, char *argv[])
break;
}
case 'v': {
options.verbose = 1;
W("Verbose mode can cause SUBSTANTIAL latency fluctuations in some(XFCE) terminals!\n");
options.verbose++;
if (options.verbose == INFO_VERBOSITY) {
W("Verbose mode may cause SUBSTANTIAL latency fluctuation in some terminals emulators\n");
} else if (options.verbose == DEBUG_VERBOSITY) {
W("Debug mode enabled. Expect very verbose output.\n");
}
logger_set_verbosity(options.verbose);
break;
}
case 't': {

View File

@ -47,7 +47,7 @@ Generator* createGenerator(std::string str) {
char *a_ptr = strtok_r(NULL, ":", &saveptr);
if (t_ptr == NULL) // || a_ptr == NULL)
DIE("strtok(.., \":\") failed to parse %s", str.c_str());
GEN_DIE("strtok(.., \":\") failed to parse %s", str.c_str());
// char t = t_ptr[0];
@ -69,7 +69,7 @@ Generator* createGenerator(std::string str) {
else if (strcasestr(str.c_str(), "gev")) return new GEV(a1, a2, a3);
else if (strcasestr(str.c_str(), "uniform")) return new Uniform(a1);
DIE("Unable to create Generator '%s'", str.c_str());
GEN_DIE("Unable to create Generator '%s'", str.c_str());
return NULL;
}

View File

@ -23,8 +23,8 @@
#include <string.h>
#include <sys/param.h>
#define D(fmt, ...)
#define DIE(fmt, ...)
#define GEN_DBG(fmt, ...)
#define GEN_DIE(fmt, ...)
uint64_t
fnv_64_buf(const void* buf, size_t len);
@ -51,14 +51,14 @@ public:
virtual ~Generator() {}
virtual double generate(double U = -1.0) = 0;
virtual void set_lambda(__attribute__((unused)) double lambda) { DIE("set_lambda() not implemented");}
virtual void set_lambda(__attribute__((unused)) double lambda) { GEN_DIE("set_lambda() not implemented");}
protected:
std::string type;
};
class Fixed : public Generator {
public:
Fixed(double _value = 1.0) : value(_value) { D("Fixed(%f)", value); }
Fixed(double _value = 1.0) : value(_value) { GEN_DBG("Fixed(%f)", value); }
virtual double generate(__attribute__((unused)) double U = -1.0) { return value; }
virtual void set_lambda(double lambda) {
if (lambda > 0.0) value = 1.0 / lambda;
@ -71,7 +71,7 @@ private:
class Uniform : public Generator {
public:
Uniform(double _scale) : scale(_scale) { D("Uniform(%f)", scale); }
Uniform(double _scale) : scale(_scale) { GEN_DBG("Uniform(%f)", scale); }
virtual double generate(double U = -1.0) {
if (U < 0.0) U = drand48();
@ -90,7 +90,7 @@ private:
class Normal : public Generator {
public:
Normal(double _mean = 1.0, double _sd = 1.0) : mean(_mean), sd(_sd) {
D("Normal(mean=%f, sd=%f)", mean, sd);
GEN_DBG("Normal(mean=%f, sd=%f)", mean, sd);
}
virtual double generate(double U = -1.0) {
@ -112,7 +112,7 @@ private:
class Exponential : public Generator {
public:
Exponential(double _lambda = 1.0) : lambda(_lambda) {
D("Exponential(lambda=%f)", lambda);
GEN_DBG("Exponential(lambda=%f)", lambda);
}
virtual double generate(double U = -1.0) {
@ -132,7 +132,7 @@ public:
GPareto(double _loc = 0.0, double _scale = 1.0, double _shape = 1.0) :
loc(_loc), scale(_scale), shape(_shape) {
assert(shape != 0.0);
D("GPareto(loc=%f, scale=%f, shape=%f)", loc, scale, shape);
GEN_DBG("GPareto(loc=%f, scale=%f, shape=%f)", loc, scale, shape);
}
virtual double generate(double U = -1.0) {
@ -155,7 +155,7 @@ public:
GEV(double _loc = 0.0, double _scale = 1.0, double _shape = 1.0) :
e(1.0), loc(_loc), scale(_scale), shape(_shape) {
assert(shape != 0.0);
D("GEV(loc=%f, scale=%f, shape=%f)", loc, scale, shape);
GEN_DBG("GEV(loc=%f, scale=%f, shape=%f)", loc, scale, shape);
}
virtual double generate(double U = -1.0) {
@ -208,7 +208,7 @@ public:
char key[256];
snprintf(key, 256, "%0*" PRIu64, keylen, ind);
// D("%d = %s", ind, key);
// GEN_DBG("%d = %s", ind, key);
return std::string(key);
}
private:

View File

@ -1,8 +1,18 @@
#pragma once
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
void logger_set_verbosity(unsigned int v);
unsigned int logger_get_verbosity(void);
#define DEBUG_VERBOSITY (2)
#define INFO_VERBOSITY (1)
#define W(fmt, ...) do { \
fprintf(stderr, "[WARN] %s: " fmt, __func__, ##__VA_ARGS__); \
fprintf(stderr, "[WARNING] %s: " fmt, __func__, ##__VA_ARGS__); \
} while(0)
#define E(fmt, ...) do { \
@ -11,7 +21,17 @@
} while(0)
#define V(fmt, ...) do { \
if (options.verbose) { \
if (logger_get_verbosity() >= INFO_VERBOSITY) { \
fprintf(stdout, "[INFO] %s: " fmt, __func__, ##__VA_ARGS__); \
} \
} while(0)
#define D(fmt, ...) do { \
if (logger_get_verbosity() >= DEBUG_VERBOSITY) { \
fprintf(stdout, "[DEBUG] %s: " fmt, __func__, ##__VA_ARGS__); \
} \
} while(0)
#ifdef __cplusplus
}
#endif

View File

@ -1,7 +1,10 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <cstddef>
// Max 16MB per message
struct ppd_msg {
@ -9,7 +12,11 @@ struct ppd_msg {
char data[0];
} __attribute__((packed));
static constexpr unsigned long PPD_MSG_MAX_SZ = 1024 * 16 * 1024;
static constexpr unsigned long PPD_MSG_HDR_SZ = offsetof(struct ppd_msg, data);
static_assert(PPD_MSG_HDR_SZ == sizeof(ppd_msg));
static constexpr unsigned long PPD_MSG_MAX_DATA_SZ = PPD_MSG_MAX_SZ - PPD_MSG_HDR_SZ;
#define PPD_MSG_MAX_SZ (1024 * 16 * 1024)
#define PPD_MSG_HDR_SZ (offsetof(struct ppd_msg, data))
_Static_assert(PPD_MSG_HDR_SZ == sizeof(struct ppd_msg));
#define PPD_MSG_MAX_DATA_SZ (PPD_MSG_MAX_SZ - PPD_MSG_HDR_SZ)
#ifdef __cplusplus
}
#endif

View File

@ -1,4 +1,6 @@
#include <mod.h>
#include <logger.h>
#define UNUSED __attribute__((unused))
static int

View File

@ -300,7 +300,7 @@ handle_event(struct ppd_thread_ctx *tinfo, struct kevent *kev)
}
msg = (struct ppd_msg *)tinfo->m_buf;
V("Thread %d connection %d RECV msg of size %u\n", tinfo->tid, conn_fd, msg->size);
D("Thread %d connection %d RECV msg of size %u\n", tinfo->tid, conn_fd, msg->size);
status = options.m_info->conn_recv_cb(msg->data, msg->size, options.m_global_ctx,
tinfo->m_thread_ctx, hint->m_conn_ctx);
if (status != 0) {
@ -325,7 +325,7 @@ handle_event(struct ppd_thread_ctx *tinfo, struct kevent *kev)
goto fail;
}
V("Thread %d connection %d SEND msg of size %lu\n", tinfo->tid, conn_fd, out_sz);
D("Thread %d connection %d SEND msg of size %lu\n", tinfo->tid, conn_fd, out_sz);
// flush bsock immediately
status = bsock_flush(hint->bsock);
if (status < 0) {
@ -727,8 +727,13 @@ main(int argc, char *argv[])
snprintf(options.module_path, sizeof(options.module_path), "%s", optarg);
break;
case 'v':
options.verbose = 1;
W("Verbose mode can cause SUBSTANTIAL latency fluctuations in some terminals!\n");
options.verbose++;
if (options.verbose == INFO_VERBOSITY) {
W("Verbose mode may cause SUBSTANTIAL latency fluctuation in some terminals emulators\n");
} else if (options.verbose == DEBUG_VERBOSITY) {
W("Debug mode enabled. Expect very verbose output.\n");
}
logger_set_verbosity(options.verbose);
break;
case 'r': {
char *eip = new char[INET_ADDRSTRLEN + 1];