2023-02-27 13:40:20 +01:00
|
|
|
/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC)
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
|
|
|
2023-01-13 11:27:13 +01:00
|
|
|
#define _POSIX_C_SOURCE 200112L
|
|
|
|
|
|
|
|
#include "emu/bay.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#define N 10000
|
|
|
|
#define BASE "testchannelultramegahyperverylongname"
|
|
|
|
|
|
|
|
struct chan *channels = NULL;
|
|
|
|
int64_t dummy_value = 1;
|
|
|
|
|
|
|
|
static double
|
|
|
|
get_time(void)
|
|
|
|
{
|
|
|
|
struct timespec ts;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
|
return (double) ts.tv_sec + (double) ts.tv_nsec * 1.0e-9;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
populate(struct bay *bay)
|
|
|
|
{
|
|
|
|
char name[MAX_CHAN_NAME];
|
|
|
|
|
|
|
|
channels = calloc(N, sizeof(struct chan));
|
|
|
|
if (channels == NULL)
|
|
|
|
die("calloc failed\n");
|
|
|
|
|
|
|
|
for (long i = 0; i < N; i++) {
|
|
|
|
sprintf(name, "%s.%ld", BASE, i);
|
|
|
|
chan_init(&channels[i], CHAN_SINGLE, name);
|
|
|
|
if (bay_register(bay, &channels[i]) != 0)
|
|
|
|
die("bay_register failed\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dummy_work(struct chan *c)
|
|
|
|
{
|
|
|
|
if (chan_set(c, value_int64(dummy_value++)) != 0)
|
|
|
|
die("chan_set failed\n");
|
|
|
|
if (chan_flush(c) != 0)
|
|
|
|
die("chan_flush failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static double
|
2023-01-16 15:06:28 +01:00
|
|
|
measure_hash(struct bay *bay, double T)
|
2023-01-13 11:27:13 +01:00
|
|
|
{
|
|
|
|
double t0 = get_time();
|
|
|
|
double t1 = t0 + T;
|
|
|
|
|
|
|
|
char name[MAX_CHAN_NAME];
|
|
|
|
long nlookups = 0;
|
|
|
|
srand(1);
|
|
|
|
|
|
|
|
while (get_time() < t1) {
|
|
|
|
long i = rand() % N;
|
|
|
|
sprintf(name, "%s.%ld", BASE, i);
|
|
|
|
struct chan *c = bay_find(bay, name);
|
|
|
|
if (c == NULL)
|
|
|
|
die("bay_find failed\n");
|
|
|
|
dummy_work(c);
|
|
|
|
nlookups++;
|
|
|
|
}
|
|
|
|
|
|
|
|
double speed = (double) nlookups / T;
|
|
|
|
|
|
|
|
err("bay_find: %e lookups/s\n", speed);
|
|
|
|
return speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
static double
|
2023-01-16 15:06:28 +01:00
|
|
|
measure_direct(double T)
|
2023-01-13 11:27:13 +01:00
|
|
|
{
|
|
|
|
double t0 = get_time();
|
|
|
|
double t1 = t0 + T;
|
|
|
|
|
|
|
|
long nlookups = 0;
|
|
|
|
srand(1);
|
|
|
|
|
|
|
|
while (get_time() < t1) {
|
|
|
|
long i = rand() % N;
|
|
|
|
dummy_work(&channels[i]);
|
|
|
|
nlookups++;
|
|
|
|
}
|
|
|
|
|
|
|
|
double speed = (double) nlookups / T;
|
|
|
|
|
|
|
|
err("direct: %e lookups/s\n", speed);
|
|
|
|
return speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_speed(struct bay *bay)
|
|
|
|
{
|
2023-01-16 15:06:28 +01:00
|
|
|
double T = 0.200;
|
|
|
|
double hash = measure_hash(bay, T);
|
|
|
|
double direct = measure_direct(T);
|
2023-01-13 11:27:13 +01:00
|
|
|
double slowdown = hash / direct;
|
|
|
|
err("slowdown speed_hash/speed_direct = %f\n", slowdown);
|
|
|
|
|
|
|
|
if (slowdown < 0.2)
|
|
|
|
die("hash speed is too slow\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
struct bay bay;
|
|
|
|
bay_init(&bay);
|
|
|
|
|
|
|
|
populate(&bay);
|
|
|
|
test_speed(&bay);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|