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: MIT */
|
2021-10-26 18:42:41 +02:00
|
|
|
|
2021-07-19 15:11:41 +02:00
|
|
|
#ifndef OVNI_H
|
|
|
|
#define OVNI_H
|
|
|
|
|
2023-04-13 17:16:31 +02:00
|
|
|
#pragma GCC visibility push(default)
|
|
|
|
|
2021-10-11 15:54:54 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-09-29 15:34:44 +02:00
|
|
|
#include <limits.h>
|
|
|
|
#include <linux/limits.h>
|
2021-07-24 10:53:41 +02:00
|
|
|
#include <stdint.h>
|
2022-09-29 15:34:44 +02:00
|
|
|
#include <stdio.h>
|
2021-07-24 10:53:41 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2021-09-28 19:21:22 +02:00
|
|
|
#include <sys/types.h>
|
2021-07-19 19:05:26 +02:00
|
|
|
|
2022-06-07 11:00:15 +02:00
|
|
|
#define OVNI_METADATA_VERSION 1
|
|
|
|
|
2021-07-24 10:53:41 +02:00
|
|
|
#define OVNI_TRACEDIR "ovni"
|
2021-08-10 10:16:41 +02:00
|
|
|
#define OVNI_MAX_HOSTNAME 512
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2021-08-02 10:08:58 +02:00
|
|
|
/* Reserved buffer for event allocation per thread */
|
|
|
|
#define OVNI_MAX_EV_BUF (2 * 1024LL * 1024LL) /* 2 MiB */
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2022-07-26 19:04:08 +02:00
|
|
|
#define OVNI_STREAM_MAGIC "ovni"
|
|
|
|
#define OVNI_STREAM_VERSION 1
|
2022-08-29 17:09:21 +02:00
|
|
|
#define OVNI_MODEL_VERSION "O1 V1 T1 M1 D1 K1 61"
|
2022-07-26 19:04:08 +02:00
|
|
|
|
2023-02-13 11:23:47 +01:00
|
|
|
#define OVNI_STREAM_EXT ".obs"
|
|
|
|
|
2022-12-13 13:11:44 +01:00
|
|
|
/* Follow https://semver.org rules for versioning */
|
2023-07-07 10:42:40 +02:00
|
|
|
#define OVNI_LIB_VERSION "@PROJECT_VERSION@"
|
2023-07-26 17:13:28 +02:00
|
|
|
#define OVNI_GIT_COMMIT "@OVNI_GIT_COMMIT@"
|
2022-12-13 13:11:44 +01:00
|
|
|
|
2021-07-24 10:53:41 +02:00
|
|
|
/* ----------------------- common ------------------------ */
|
2021-07-19 15:11:41 +02:00
|
|
|
|
2021-07-30 20:08:40 +02:00
|
|
|
enum ovni_ev_flags {
|
|
|
|
OVNI_EV_JUMBO = 0x10,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct __attribute__((__packed__)) ovni_jumbo_payload {
|
|
|
|
uint32_t size;
|
|
|
|
uint8_t data[1];
|
|
|
|
};
|
|
|
|
|
2021-07-28 11:56:35 +02:00
|
|
|
union __attribute__((__packed__)) ovni_ev_payload {
|
|
|
|
int8_t i8[16];
|
|
|
|
int16_t i16[8];
|
|
|
|
int32_t i32[4];
|
|
|
|
int64_t i64[2];
|
2021-07-30 20:08:40 +02:00
|
|
|
|
|
|
|
uint8_t u8[16];
|
|
|
|
uint16_t u16[8];
|
|
|
|
uint32_t u32[4];
|
|
|
|
uint64_t u64[2];
|
|
|
|
|
|
|
|
struct ovni_jumbo_payload jumbo;
|
2021-07-28 11:56:35 +02:00
|
|
|
};
|
|
|
|
|
2021-07-30 20:08:40 +02:00
|
|
|
struct __attribute__((__packed__)) ovni_ev_header {
|
2021-07-24 10:53:41 +02:00
|
|
|
/* first 4 bits reserved, last 4 for payload size */
|
|
|
|
uint8_t flags;
|
|
|
|
uint8_t model;
|
2021-10-11 15:46:49 +02:00
|
|
|
uint8_t category;
|
2021-07-24 10:53:41 +02:00
|
|
|
uint8_t value;
|
2021-08-11 11:50:07 +02:00
|
|
|
uint64_t clock;
|
2021-07-30 20:08:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct __attribute__((__packed__)) ovni_ev {
|
|
|
|
struct ovni_ev_header header;
|
|
|
|
|
|
|
|
/* The payload size may vary depending on the ev type:
|
|
|
|
* - normal: 0, or 2 to 16 bytes
|
|
|
|
* - jumbo: 0 to 2^32 - 1 bytes */
|
2021-07-28 11:56:35 +02:00
|
|
|
union ovni_ev_payload payload;
|
2021-07-24 10:53:41 +02:00
|
|
|
};
|
|
|
|
|
2022-07-26 19:04:08 +02:00
|
|
|
struct __attribute__((__packed__)) ovni_stream_header {
|
|
|
|
char magic[4];
|
|
|
|
uint32_t version;
|
|
|
|
};
|
|
|
|
|
2021-07-24 10:53:41 +02:00
|
|
|
/* ----------------------- runtime ------------------------ */
|
|
|
|
|
2022-12-13 13:11:44 +01:00
|
|
|
#define ovni_version_check() ovni_version_check_str(OVNI_LIB_VERSION)
|
|
|
|
void ovni_version_check_str(const char *version);
|
2023-07-26 17:13:28 +02:00
|
|
|
void ovni_version_get(const char **version, const char **commit);
|
2022-12-13 13:11:44 +01:00
|
|
|
|
2021-12-07 17:26:08 +01:00
|
|
|
void ovni_proc_init(int app, const char *loom, int pid);
|
2021-08-03 17:48:37 +02:00
|
|
|
|
2021-12-10 18:20:31 +01:00
|
|
|
/* Sets the MPI rank of the current process and the number of total nranks */
|
|
|
|
void ovni_proc_set_rank(int rank, int nranks);
|
|
|
|
|
2021-12-07 17:26:08 +01:00
|
|
|
void ovni_proc_fini(void);
|
2021-07-24 10:53:41 +02:00
|
|
|
|
2021-12-07 17:26:08 +01:00
|
|
|
void ovni_thread_init(pid_t tid);
|
2021-07-24 10:53:41 +02:00
|
|
|
|
2023-11-09 15:10:13 +01:00
|
|
|
void ovni_thread_require(const char *model, const char *version);
|
|
|
|
|
2021-10-18 12:47:51 +02:00
|
|
|
void ovni_thread_free(void);
|
2021-07-24 10:53:41 +02:00
|
|
|
|
2021-10-18 12:47:51 +02:00
|
|
|
int ovni_thread_isready(void);
|
|
|
|
|
2021-11-19 17:09:39 +01:00
|
|
|
void ovni_ev_set_mcv(struct ovni_ev *ev, const char *mcv);
|
2021-07-24 10:53:41 +02:00
|
|
|
|
2021-11-16 14:35:39 +01:00
|
|
|
/* Gets the event clock in ns */
|
2021-11-19 17:09:39 +01:00
|
|
|
uint64_t ovni_ev_get_clock(const struct ovni_ev *ev);
|
2021-07-24 10:53:41 +02:00
|
|
|
|
2021-11-16 14:35:39 +01:00
|
|
|
/* Sets the event clock in ns */
|
|
|
|
void ovni_ev_set_clock(struct ovni_ev *ev, uint64_t clock);
|
|
|
|
|
|
|
|
/* Returns the current value of the ovni clock in ns */
|
|
|
|
uint64_t ovni_clock_now(void);
|
2021-10-18 12:47:51 +02:00
|
|
|
|
2021-11-19 17:09:39 +01:00
|
|
|
void ovni_payload_add(struct ovni_ev *ev, const uint8_t *buf, int size);
|
2021-07-24 10:53:41 +02:00
|
|
|
|
2021-11-19 17:09:39 +01:00
|
|
|
int ovni_ev_size(const struct ovni_ev *ev);
|
2021-07-24 10:53:41 +02:00
|
|
|
|
2021-11-19 17:09:39 +01:00
|
|
|
int ovni_payload_size(const struct ovni_ev *ev);
|
2021-07-24 10:53:41 +02:00
|
|
|
|
2021-08-03 17:48:37 +02:00
|
|
|
void ovni_add_cpu(int index, int phyid);
|
|
|
|
|
2021-11-16 14:35:39 +01:00
|
|
|
/* Adds the event to the events buffer. The buffer is flushed first if the event
|
|
|
|
* doesn't fit in the buffer. */
|
2021-10-29 17:04:42 +02:00
|
|
|
void ovni_ev_emit(struct ovni_ev *ev);
|
2021-11-19 17:09:39 +01:00
|
|
|
void ovni_ev_jumbo_emit(struct ovni_ev *ev, const uint8_t *buf, uint32_t bufsize);
|
2021-07-24 10:53:41 +02:00
|
|
|
|
2021-12-07 17:26:08 +01:00
|
|
|
void ovni_flush(void);
|
2021-07-24 10:53:41 +02:00
|
|
|
|
2021-10-11 15:54:54 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2021-07-22 12:35:02 +02:00
|
|
|
|
2023-04-13 17:16:31 +02:00
|
|
|
#pragma GCC visibility pop
|
|
|
|
|
2021-07-19 15:11:41 +02:00
|
|
|
#endif /* OVNI_H */
|