Clarify the throughput unit conversion (#51)

This commit is contained in:
Simon Xiao 2021-05-03 17:55:53 -07:00 коммит произвёл GitHub
Родитель 1c297cfe77
Коммит fcebda4d7c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 26 добавлений и 21 удалений

Просмотреть файл

@ -38,14 +38,22 @@
#define MAX_UDP_SEND_SIZE (65535 - 8 - 20)
#define MAX_LOCAL_IP_PORT 65535
/* Unit conversion */
#define BYTE_TO_BITS 8
/* decimal based, used for throughput unit conversion */
#define DECIMAL_BASED_UNIT_K 1000
#define DECIMAL_BASED_UNIT_M (1000 * 1000)
/* binary based, used for buffer size unit conversion */
#define BINARY_BASED_UNIT_K 1024
/* default values */
#define DEFAULT_NUM_SERVER_PORTS 16
#define DEFAULT_THREADS_PER_SERVER_PORT 4
#define DEFAULT_CLIENT_CONNS_PER_THREAD 1
#define DEFAULT_BASE_DST_PORT 5001
#define DEFAULT_BASE_SRC_PORT 25001
#define DEFAULT_RECV_BUFFER_SIZE 64 * 1024
#define DEFAULT_SEND_BUFFER_SIZE 128 * 1024
#define DEFAULT_RECV_BUFFER_SIZE (64 * 1024)
#define DEFAULT_SEND_BUFFER_SIZE (128 * 1024)
#define DEFAULT_WARMUP_SEC 0
#define DEFAULT_TEST_DURATION 60
#define DEFAULT_COOLDOWN_SEC 0

Просмотреть файл

@ -468,16 +468,16 @@ int parse_arguments(struct ntttcp_test *test, int argc, char **argv)
break;
case 'b':
test->recv_buf_size = unit_atod(optarg);
test->send_buf_size = unit_atod(optarg);
test->recv_buf_size = unit_atod(optarg, BINARY_BASED_UNIT_K);
test->send_buf_size = unit_atod(optarg, BINARY_BASED_UNIT_K);
break;
case 'B':
test->bandwidth_limit = unit_atod(optarg);
test->bandwidth_limit = unit_atod(optarg, DECIMAL_BASED_UNIT_K);
break;
case LO_FQ_RATE_LIMIT:
test->fq_rate_limit = unit_atod(optarg);
test->fq_rate_limit = unit_atod(optarg, DECIMAL_BASED_UNIT_K);
break;
case 'W':

Просмотреть файл

@ -47,12 +47,7 @@ double get_time_diff(struct timeval *t1, struct timeval *t2)
return fabs( (t1->tv_sec + (t1->tv_usec / 1000000.0)) - (t2->tv_sec + (t2->tv_usec / 1000000.0)) );
}
const long KIBI = 1<<10;
const long MEBI = 1<<20;
const long GIBI = 1<<30;
const int BYTE_TO_BITS = 8;
double unit_atod(const char *s)
double unit_atod(const char *s, int unit_k)
{
double n;
char suffix = '\0';
@ -60,13 +55,13 @@ double unit_atod(const char *s)
sscanf(s, "%lf%c", &n, &suffix);
switch (suffix) {
case 'g': case 'G':
n *= GIBI;
n *= (unit_k * unit_k * unit_k);
break;
case 'm': case 'M':
n *= MEBI;
n *= (unit_k * unit_k);
break;
case 'k': case 'K':
n *= KIBI;
n *= unit_k;
break;
default:
break;
@ -82,6 +77,8 @@ const char *unit_bps[] =
"Gbps"
};
#define K 1000;
int process_test_results(struct ntttcp_test_endpoint *tep)
{
struct ntttcp_test_endpoint_results *tepr = tep->results;
@ -100,8 +97,8 @@ int process_test_results(struct ntttcp_test_endpoint *tep)
if (tep->results->threads[i]->is_sync_thread == true)
continue;
tepr->threads[i]->KBps = tepr->threads[i]->total_bytes / KIBI / tepr->threads[i]->actual_test_time;
tepr->threads[i]->MBps = tepr->threads[i]->KBps / KIBI;
tepr->threads[i]->KBps = tepr->threads[i]->total_bytes / tepr->threads[i]->actual_test_time / DECIMAL_BASED_UNIT_K;
tepr->threads[i]->MBps = tepr->threads[i]->KBps / DECIMAL_BASED_UNIT_K;
tepr->threads[i]->mbps = tepr->threads[i]->MBps * BYTE_TO_BITS;
}
@ -130,7 +127,7 @@ int process_test_results(struct ntttcp_test_endpoint *tep)
tepr->cpu_ps_softirq_usage = (tepr->final_cpu_ps->softirq_time - tepr->init_cpu_ps->softirq_time) / cpu_ps_total_diff;
/* calculate for counters for xml log (compatible with Windows ntttcp.exe) */
tepr->total_bytes_MB = total_bytes / MEBI;
tepr->total_bytes_MB = total_bytes / DECIMAL_BASED_UNIT_M;
tepr->throughput_MBps = tepr->total_bytes_MB / test_duration;
tepr->throughput_mbps = tepr->throughput_MBps * BYTE_TO_BITS;
tepr->cycles_per_byte = total_bytes == 0 ? 0 :
@ -439,8 +436,8 @@ char *format_throughput(uint64_t bytes_transferred, double test_duration)
char *throughput;
tmp = bytes_transferred * 8.0 / test_duration;
while (tmp > 1000 && unit_idx < 3) {
tmp /= 1000.0;
while (tmp > DECIMAL_BASED_UNIT_K && unit_idx < 3) {
tmp /= DECIMAL_BASED_UNIT_K;
unit_idx++;
}

Просмотреть файл

@ -92,7 +92,7 @@ struct ntttcp_test_endpoint_results{
};
void fill_buffer(register char *buf, register int count);
double unit_atod(const char *s);
double unit_atod(const char *s, int unit_k);
double get_time_diff(struct timeval *t1, struct timeval *t2);
int process_test_results(struct ntttcp_test_endpoint *tep);