2023-02-27 13:40:20 +01:00
|
|
|
/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC)
|
2022-09-19 12:39:02 +02:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later */
|
2021-12-10 18:23:47 +01:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2023-03-22 16:01:55 +01:00
|
|
|
#include "compat.h"
|
|
|
|
#include "ovni.h"
|
2023-11-10 12:34:57 +01:00
|
|
|
#include "instr.h"
|
2021-12-10 18:23:47 +01:00
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
static void
|
|
|
|
fail(const char *msg)
|
2021-12-10 18:23:47 +01:00
|
|
|
{
|
|
|
|
fprintf(stderr, "%s\n", msg);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
#define INSTR_3ARG(name, mcv, ta, a, tb, b, tc, c) \
|
|
|
|
static inline void name(ta a, tb b, tc c) \
|
|
|
|
{ \
|
|
|
|
struct ovni_ev ev = {0}; \
|
|
|
|
ovni_ev_set_mcv(&ev, mcv); \
|
|
|
|
ovni_ev_set_clock(&ev, ovni_clock_now()); \
|
|
|
|
ovni_payload_add(&ev, (uint8_t *) &a, sizeof(a)); \
|
|
|
|
ovni_payload_add(&ev, (uint8_t *) &b, sizeof(b)); \
|
|
|
|
ovni_payload_add(&ev, (uint8_t *) &c, sizeof(c)); \
|
|
|
|
ovni_ev_emit(&ev); \
|
2021-12-10 18:23:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTR_3ARG(instr_thread_execute, "OHx", int32_t, cpu, int32_t, creator_tid, uint64_t, tag)
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
static inline void
|
|
|
|
instr_thread_end(void)
|
2021-12-10 18:23:47 +01:00
|
|
|
{
|
|
|
|
struct ovni_ev ev = {0};
|
|
|
|
|
|
|
|
ovni_ev_set_mcv(&ev, "OHe");
|
|
|
|
ovni_ev_set_clock(&ev, ovni_clock_now());
|
|
|
|
ovni_ev_emit(&ev);
|
|
|
|
|
|
|
|
// Flush the events to disk before killing the thread
|
|
|
|
ovni_flush();
|
|
|
|
}
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
static inline void
|
|
|
|
instr_start(int rank, int nranks)
|
2021-12-10 18:23:47 +01:00
|
|
|
{
|
2023-03-22 16:01:55 +01:00
|
|
|
char hostname[OVNI_MAX_HOSTNAME];
|
2021-12-10 18:23:47 +01:00
|
|
|
|
2023-03-22 16:01:55 +01:00
|
|
|
if (gethostname(hostname, OVNI_MAX_HOSTNAME) != 0)
|
2021-12-10 18:23:47 +01:00
|
|
|
fail("gethostname failed");
|
|
|
|
|
|
|
|
ovni_proc_init(1, hostname, getpid());
|
2022-09-29 15:34:44 +02:00
|
|
|
|
2021-12-10 18:23:47 +01:00
|
|
|
ovni_proc_set_rank(rank, nranks);
|
|
|
|
|
2023-03-22 17:06:52 +01:00
|
|
|
ovni_thread_init(get_tid());
|
2021-12-10 18:23:47 +01:00
|
|
|
|
|
|
|
/* Only the rank 0 inform about all CPUs */
|
2022-09-29 15:34:44 +02:00
|
|
|
if (rank == 0) {
|
2021-12-10 18:23:47 +01:00
|
|
|
/* Fake nranks cpus */
|
2022-09-29 15:34:44 +02:00
|
|
|
for (int i = 0; i < nranks; i++)
|
2021-12-10 18:23:47 +01:00
|
|
|
ovni_add_cpu(i, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
int curcpu = rank;
|
|
|
|
|
|
|
|
fprintf(stderr, "thread %d has cpu %d (ncpus=%d)\n",
|
2023-03-22 17:06:52 +01:00
|
|
|
get_tid(), curcpu, nranks);
|
2021-12-10 18:23:47 +01:00
|
|
|
|
|
|
|
instr_thread_execute(curcpu, -1, 0);
|
|
|
|
}
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
static inline void
|
|
|
|
instr_end(void)
|
2021-12-10 18:23:47 +01:00
|
|
|
{
|
|
|
|
instr_thread_end();
|
|
|
|
ovni_thread_free();
|
|
|
|
ovni_proc_fini();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-06-02 15:46:22 +02:00
|
|
|
type_create(int32_t typeid)
|
|
|
|
{
|
|
|
|
struct ovni_ev ev = {0};
|
|
|
|
|
|
|
|
ovni_ev_set_mcv(&ev, "VYc");
|
|
|
|
ovni_ev_set_clock(&ev, ovni_clock_now());
|
|
|
|
|
|
|
|
char buf[256];
|
|
|
|
char *p = buf;
|
|
|
|
|
|
|
|
size_t nbytes = 0;
|
|
|
|
memcpy(buf, &typeid, sizeof(typeid));
|
|
|
|
p += sizeof(typeid);
|
|
|
|
nbytes += sizeof(typeid);
|
|
|
|
sprintf(p, "testtype%d", typeid);
|
|
|
|
nbytes += strlen(p) + 1;
|
|
|
|
|
|
|
|
ovni_ev_jumbo_emit(&ev, (uint8_t *) buf, nbytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
task(int32_t id, uint32_t typeid, int us)
|
2021-12-10 18:23:47 +01:00
|
|
|
{
|
|
|
|
struct ovni_ev ev = {0};
|
|
|
|
|
|
|
|
ovni_ev_set_mcv(&ev, "VTc");
|
|
|
|
ovni_ev_set_clock(&ev, ovni_clock_now());
|
|
|
|
ovni_payload_add(&ev, (uint8_t *) &id, sizeof(id));
|
|
|
|
ovni_payload_add(&ev, (uint8_t *) &typeid, sizeof(id));
|
|
|
|
ovni_ev_emit(&ev);
|
|
|
|
|
|
|
|
memset(&ev, 0, sizeof(ev));
|
|
|
|
|
|
|
|
ovni_ev_set_mcv(&ev, "VTx");
|
|
|
|
ovni_ev_set_clock(&ev, ovni_clock_now());
|
|
|
|
ovni_payload_add(&ev, (uint8_t *) &id, sizeof(id));
|
|
|
|
ovni_ev_emit(&ev);
|
|
|
|
|
2023-03-22 16:01:55 +01:00
|
|
|
sleep_us(us);
|
2021-12-10 18:23:47 +01:00
|
|
|
|
|
|
|
memset(&ev, 0, sizeof(ev));
|
|
|
|
|
|
|
|
ovni_ev_set_mcv(&ev, "VTe");
|
|
|
|
ovni_ev_set_clock(&ev, ovni_clock_now());
|
|
|
|
ovni_payload_add(&ev, (uint8_t *) &id, sizeof(id));
|
|
|
|
ovni_ev_emit(&ev);
|
|
|
|
}
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
int
|
|
|
|
main(void)
|
2021-12-10 18:23:47 +01:00
|
|
|
{
|
|
|
|
int rank = atoi(getenv("OVNI_RANK"));
|
|
|
|
int nranks = atoi(getenv("OVNI_NRANKS"));
|
2022-06-02 15:46:22 +02:00
|
|
|
uint32_t typeid = 1;
|
2021-12-10 18:23:47 +01:00
|
|
|
|
|
|
|
instr_start(rank, nranks);
|
2023-11-10 12:34:57 +01:00
|
|
|
instr_nosv_init();
|
2021-12-10 18:23:47 +01:00
|
|
|
|
2022-06-02 15:46:22 +02:00
|
|
|
type_create(typeid);
|
|
|
|
|
2021-12-10 18:23:47 +01:00
|
|
|
/* Create some fake nosv tasks */
|
2022-09-29 15:34:44 +02:00
|
|
|
for (int i = 0; i < 10; i++)
|
2022-06-02 15:46:22 +02:00
|
|
|
task(i + 1, typeid, 5000);
|
2021-12-10 18:23:47 +01:00
|
|
|
|
|
|
|
instr_end();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|