2023-02-27 13:40:20 +01:00
|
|
|
/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC)
|
2022-10-07 12:43:15 +02:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
2023-03-22 16:01:55 +01:00
|
|
|
#include <stdlib.h>
|
2022-10-07 12:43:15 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include "common.h"
|
2023-03-22 16:01:55 +01:00
|
|
|
#include "compat.h"
|
2022-10-07 12:43:15 +02:00
|
|
|
#include "ovni.h"
|
2023-11-10 12:34:57 +01:00
|
|
|
#include "instr.h"
|
2022-10-07 12:43:15 +02:00
|
|
|
|
|
|
|
static inline void
|
|
|
|
init(void)
|
|
|
|
{
|
2023-03-22 16:01:55 +01:00
|
|
|
char hostname[OVNI_MAX_HOSTNAME];
|
2022-10-07 12:43:15 +02:00
|
|
|
|
2023-03-22 16:01:55 +01:00
|
|
|
if (gethostname(hostname, OVNI_MAX_HOSTNAME) != 0) {
|
2022-10-07 12:43:15 +02:00
|
|
|
perror("gethostname failed");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ovni_proc_init(0, hostname, getpid());
|
2023-03-22 17:06:52 +01:00
|
|
|
ovni_thread_init(get_tid());
|
2022-10-07 12:43:15 +02:00
|
|
|
ovni_add_cpu(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
emit(char *mcv, int64_t clock)
|
|
|
|
{
|
|
|
|
struct ovni_ev ev = {0};
|
|
|
|
ovni_ev_set_mcv(&ev, mcv);
|
|
|
|
ovni_ev_set_clock(&ev, clock);
|
|
|
|
ovni_ev_emit(&ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
|
2022-12-19 15:46:37 +01:00
|
|
|
int64_t t0 = ovni_clock_now();
|
|
|
|
|
2022-10-07 12:43:15 +02:00
|
|
|
/* Leave some room to prevent clashes */
|
2023-03-22 16:01:55 +01:00
|
|
|
sleep_us(100000); /* 100000000 ns */
|
2022-10-07 12:43:15 +02:00
|
|
|
|
2022-12-19 15:46:37 +01:00
|
|
|
int64_t t1 = ovni_clock_now();
|
2022-10-07 12:43:15 +02:00
|
|
|
|
2022-12-19 15:46:37 +01:00
|
|
|
emit("OU[", t1);
|
2022-10-07 12:43:15 +02:00
|
|
|
|
|
|
|
/* Fill the ring buffer */
|
2023-02-16 15:58:56 +01:00
|
|
|
long n = 1000000 + 10;
|
2022-10-07 12:43:15 +02:00
|
|
|
|
2023-03-21 16:09:01 +01:00
|
|
|
err("using n=%ld events", n);
|
2022-10-07 12:43:15 +02:00
|
|
|
|
|
|
|
/* Go back 100 ns for each event (with some space) */
|
2022-12-19 15:46:37 +01:00
|
|
|
int64_t delta = 10000;
|
|
|
|
int64_t t = t0 + delta;
|
2022-10-07 12:43:15 +02:00
|
|
|
|
|
|
|
for (long i = 0; i < n; i++) {
|
2022-12-19 15:46:37 +01:00
|
|
|
if (t <= t0 || t >= t1)
|
2023-03-21 16:09:01 +01:00
|
|
|
die("bad time");
|
2022-10-07 12:43:15 +02:00
|
|
|
emit("OB.", t);
|
|
|
|
t += 33;
|
|
|
|
}
|
|
|
|
|
|
|
|
emit("OU]", ovni_clock_now());
|
|
|
|
|
|
|
|
ovni_flush();
|
|
|
|
ovni_proc_fini();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|