benchmarks/latmus: latmon: fix retrieval of histogram data

This is a general fix addressing several issues in the retrieval of
histogram data from latmon, which reverts #6b2425d8 in the same move:

- use a safe socket send loop in order to cope with partial writes on
  the latmon side.

- drop the very notion of warmup time, the system must be ready to
  respond with no delay or preparation, and the average figures won't
  be affected over long enough runs anyway.

Signed-off-by: Philippe Gerum <rpm@xenomai.org>
This commit is contained in:
Philippe Gerum 2020-05-19 17:40:02 +02:00
parent 6b2425d8f6
commit 1377720f9f
2 changed files with 35 additions and 23 deletions

View File

@ -295,7 +295,7 @@ static void log_results(struct latmus_measurement *meas,
if (verbosity > 0 && data_lines && (round % data_lines) == 0) {
time(&now);
dt = now - start_time - 1; /* -1s warmup time */
dt = now - start_time;
printf("RTT| %.2ld:%.2ld:%.2ld "
"(%s, %u us period, priority %d, CPU%d%s)\n",
dt / 3600, (dt / 60) % 60, dt % 60,
@ -678,7 +678,7 @@ static void setup_measurement_on_gpio(void)
req.histogram_cells = 0;
ret = send(lat_sock, &req, sizeof(req), 0);
if (ret != sizeof(req)) {
error(0, errno, "send() stop");
error(1, errno, "send() stop");
latmon_hung = true;
} else {
clock_gettime(CLOCK_REALTIME, &timeout);
@ -689,7 +689,7 @@ static void setup_measurement_on_gpio(void)
}
if (latmon_hung)
error(0, ETIMEDOUT, "latmon at %s is unresponsive",
error(1, ETIMEDOUT, "latmon at %s is unresponsive",
inet_ntoa(gpio_monitor_ip));
close(lat_sock);
@ -753,6 +753,8 @@ static void dump_gnuplot(time_t duration)
(double)(all_sum / all_samples) / 1000.0);
fprintf(plot_fp, "# max latency: %.3f\n",
(double)all_maxlat / 1000.0);
fprintf(plot_fp, "# sample count: %lld\n",
(long long)all_samples);
for (n = 0; n < histogram_cells && histogram[n] == 0; n++)
;
@ -791,9 +793,7 @@ static void do_measurement(int type)
if (!(responder_cpu_state & EVL_CPU_ISOL))
cpu_s = " (not isolated)";
if (verbosity > 0)
fprintf(stderr, "warming up on CPU%d%s...\n", responder_cpu, cpu_s);
else
if (verbosity <= 0)
fprintf(stderr, "running quietly for %ld seconds on CPU%d%s\n",
timeout, responder_cpu, cpu_s);
@ -806,9 +806,9 @@ static void do_measurement(int type)
setup_measurement_on_timer();
}
duration = time(NULL) - start_time - 1;
duration = time(NULL) - start_time;
if (plot_fp) {
dump_gnuplot(duration); /* -1s warmup time */
dump_gnuplot(duration);
if (plot_fp != stdout)
fclose(plot_fp);
free(histogram);
@ -1224,7 +1224,7 @@ int main(int argc, char *const argv[])
error(1, EINVAL, "invalid time modifier: '%c'",
*endptr);
}
alarm(timeout + 1); /* +1s warmup time */
alarm(timeout);
break;
case 'v':
verbosity = optarg ? atoi(optarg) : 1;

View File

@ -161,6 +161,21 @@ static void reset_sampling_counters(void)
current_samples = 0;
}
static ssize_t write_socket(const void *buf, size_t count)
{
ssize_t n = 0, ret;
do {
ret = send(client_socket, (const char *)buf + n, count, 0);
if (ret <= 0)
return ret;
n += ret;
count -= ret;
} while (count > 0);
return n;
}
static bool send_sample_bulk(void)
{
struct latmon_net_data ndata;
@ -172,7 +187,7 @@ static bool send_sample_bulk(void)
ndata.max_lat = htonl(max_lat);
ndata.overruns = htonl(overruns);
ndata.samples = htonl(current_samples);
ret = send(client_socket, &ndata, sizeof(ndata), 0);
ret = write_socket(&ndata, sizeof(ndata));
if (ret <= 0)
return false;
@ -183,7 +198,8 @@ static bool send_sample_bulk(void)
static bool send_trailing_data(void)
{
int cell, ret;
int cell, count;
ssize_t ret;
if (current_samples > 0)
send_sample_bulk();
@ -195,10 +211,11 @@ static bool send_trailing_data(void)
if (histogram_cells > 0) {
for (cell = 0; cell < histogram_cells; cell++)
histogram[cell] = htonl(histogram[cell]);
ret = send(client_socket, histogram,
histogram_cells * sizeof(histogram[0]), 0);
if (ret != histogram_cells * sizeof(histogram[0])) {
LOG_INF("failed sending histogram data");
count = histogram_cells * sizeof(histogram[0]);
ret = write_socket(histogram, count);
if (ret <= 0) {
LOG_INF("failed sending histogram data (ret=%d, errno %d)",
ret, errno);
return false;
}
}
@ -228,7 +245,6 @@ static void gpio_ack_handler(struct device *port,
static int monitor(void)
{
u32_t pulse_date, delta, delta_ns, delta_usecs;
bool warmup = true;
unsigned int key;
int cell;
@ -285,13 +301,9 @@ static int monitor(void)
delta_usecs -= period_usecs;
}
if (++current_samples >= max_samples_per_bulk) {
if (warmup) {
warmup = false;
reset_sampling_counters();
} else if (!send_sample_bulk())
break;
}
if (++current_samples >= max_samples_per_bulk &&
!send_sample_bulk())
break;
}
k_sem_give(&monitor_done);