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 */
|
2022-07-07 16:31:15 +02:00
|
|
|
|
2022-08-25 18:56:55 +02:00
|
|
|
#ifndef INSTR_H
|
|
|
|
#define INSTR_H
|
2022-07-07 16:31:15 +02:00
|
|
|
|
2022-08-23 16:40:44 +02:00
|
|
|
#define _GNU_SOURCE /* For gethostname() */
|
|
|
|
|
|
|
|
#include "common.h"
|
2022-09-05 20:18:42 +02:00
|
|
|
#include "compat.h"
|
2022-07-07 16:31:15 +02:00
|
|
|
#include "ovni.h"
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2023-02-24 11:55:54 +01:00
|
|
|
extern int first_clock_set;
|
|
|
|
extern int64_t first_clock;
|
|
|
|
extern int64_t last_clock;
|
|
|
|
|
|
|
|
int64_t get_clock(void);
|
|
|
|
int64_t get_delta(void);
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
#define INSTR_0ARG(name, mcv) \
|
|
|
|
static inline void name(void) \
|
|
|
|
{ \
|
|
|
|
struct ovni_ev ev = {0}; \
|
2023-02-24 11:55:54 +01:00
|
|
|
ovni_ev_set_clock(&ev, get_clock()); \
|
2022-09-29 15:34:44 +02:00
|
|
|
ovni_ev_set_mcv(&ev, mcv); \
|
|
|
|
ovni_ev_emit(&ev); \
|
2022-07-07 16:31:15 +02:00
|
|
|
}
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
#define INSTR_1ARG(name, mcv, ta, a) \
|
|
|
|
static inline void name(ta a) \
|
|
|
|
{ \
|
|
|
|
struct ovni_ev ev = {0}; \
|
2023-02-24 11:55:54 +01:00
|
|
|
ovni_ev_set_clock(&ev, get_clock()); \
|
2022-09-29 15:34:44 +02:00
|
|
|
ovni_ev_set_mcv(&ev, mcv); \
|
2022-07-07 16:31:15 +02:00
|
|
|
ovni_payload_add(&ev, (uint8_t *) &a, sizeof(a)); \
|
2022-09-29 15:34:44 +02:00
|
|
|
ovni_ev_emit(&ev); \
|
2022-07-07 16:31:15 +02:00
|
|
|
}
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
#define INSTR_2ARG(name, mcv, ta, a, tb, b) \
|
|
|
|
static inline void name(ta a, tb b) \
|
|
|
|
{ \
|
|
|
|
struct ovni_ev ev = {0}; \
|
2023-02-24 11:55:54 +01:00
|
|
|
ovni_ev_set_clock(&ev, get_clock()); \
|
2022-09-29 15:34:44 +02:00
|
|
|
ovni_ev_set_mcv(&ev, mcv); \
|
2022-07-07 16:31:15 +02:00
|
|
|
ovni_payload_add(&ev, (uint8_t *) &a, sizeof(a)); \
|
|
|
|
ovni_payload_add(&ev, (uint8_t *) &b, sizeof(b)); \
|
2022-09-29 15:34:44 +02:00
|
|
|
ovni_ev_emit(&ev); \
|
2022-07-07 16:31:15 +02:00
|
|
|
}
|
|
|
|
|
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}; \
|
2023-02-24 11:55:54 +01:00
|
|
|
ovni_ev_set_clock(&ev, get_clock()); \
|
2022-09-29 15:34:44 +02:00
|
|
|
ovni_ev_set_mcv(&ev, mcv); \
|
2022-07-07 16:31:15 +02:00
|
|
|
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)); \
|
2022-09-29 15:34:44 +02:00
|
|
|
ovni_ev_emit(&ev); \
|
2022-07-07 16:31:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTR_3ARG(instr_thread_execute, "OHx", int32_t, cpu, int32_t, creator_tid, uint64_t, tag)
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
instr_thread_end(void)
|
|
|
|
{
|
|
|
|
struct ovni_ev ev = {0};
|
|
|
|
|
|
|
|
ovni_ev_set_mcv(&ev, "OHe");
|
2023-02-24 11:55:54 +01:00
|
|
|
ovni_ev_set_clock(&ev, get_clock());
|
2022-07-07 16:31:15 +02:00
|
|
|
ovni_ev_emit(&ev);
|
|
|
|
|
|
|
|
/* Flush the events to disk before killing the thread */
|
|
|
|
ovni_flush();
|
|
|
|
}
|
|
|
|
|
2022-08-23 16:40:44 +02:00
|
|
|
static inline void
|
|
|
|
instr_start(int rank, int nranks)
|
|
|
|
{
|
|
|
|
char hostname[OVNI_MAX_HOSTNAME];
|
|
|
|
char rankname[OVNI_MAX_HOSTNAME + 64];
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
if (gethostname(hostname, HOST_NAME_MAX) != 0)
|
2022-08-23 16:40:44 +02:00
|
|
|
die("gethostname failed");
|
|
|
|
|
|
|
|
sprintf(rankname, "%s.%d", hostname, rank);
|
|
|
|
|
2022-12-13 13:11:44 +01:00
|
|
|
ovni_version_check();
|
2022-08-23 16:40:44 +02:00
|
|
|
ovni_proc_init(1, rankname, getpid());
|
|
|
|
ovni_proc_set_rank(rank, nranks);
|
|
|
|
ovni_thread_init(gettid());
|
|
|
|
|
|
|
|
/* All ranks inform CPUs */
|
2022-09-29 15:34:44 +02:00
|
|
|
for (int i = 0; i < nranks; i++)
|
2022-08-23 16:40:44 +02:00
|
|
|
ovni_add_cpu(i, i);
|
|
|
|
|
|
|
|
int curcpu = rank;
|
|
|
|
|
|
|
|
dbg("thread %d has cpu %d (ncpus=%d)\n",
|
2022-09-30 10:25:09 +02:00
|
|
|
gettid(), curcpu, nranks);
|
2022-08-23 16:40:44 +02:00
|
|
|
|
|
|
|
instr_thread_execute(curcpu, -1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
instr_end(void)
|
|
|
|
{
|
|
|
|
instr_thread_end();
|
|
|
|
ovni_thread_free();
|
|
|
|
ovni_proc_fini();
|
|
|
|
}
|
|
|
|
|
2022-08-25 18:56:55 +02:00
|
|
|
#endif /* INSTR_H */
|