2021-10-26 18:42:41 +02:00
|
|
|
/*
|
|
|
|
* MIT License
|
|
|
|
*
|
|
|
|
* Copyright (c) 2021 Barcelona Supercomputing Center (BSC)
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2021-07-19 15:11:41 +02:00
|
|
|
#ifndef OVNI_H
|
|
|
|
#define OVNI_H
|
|
|
|
|
2021-10-11 15:54:54 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-07-28 11:56:35 +02:00
|
|
|
#include <stdio.h>
|
2021-07-24 10:53:41 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <linux/limits.h>
|
2021-09-28 19:21:22 +02:00
|
|
|
#include <sys/types.h>
|
2021-08-02 20:03:20 +02:00
|
|
|
#include <limits.h>
|
2021-07-19 19:05:26 +02:00
|
|
|
|
2021-11-15 18:35:51 +01:00
|
|
|
/* Hardcode the JSON_Value to avoid a dependency with janson */
|
|
|
|
typedef struct json_value_t JSON_Value;
|
2021-08-03 17:48:37 +02:00
|
|
|
|
2021-07-24 10:53:41 +02:00
|
|
|
#define OVNI_MAX_CPU 256
|
2021-08-10 10:18:40 +02:00
|
|
|
#define OVNI_MAX_THR 256
|
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
|
|
|
|
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 {
|
2021-07-30 20:08:40 +02:00
|
|
|
|
2021-07-28 11:56:35 +02:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/* ----------------------- runtime ------------------------ */
|
|
|
|
|
|
|
|
/* State of each thread on runtime */
|
|
|
|
struct ovni_rthread {
|
|
|
|
/* Current cpu the thread is running on. Set to -1 if unbounded or
|
|
|
|
* unknown */
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
/* Current thread id */
|
|
|
|
pid_t tid;
|
|
|
|
|
|
|
|
/* Clock value of the events being emitted */
|
|
|
|
uint64_t clockvalue;
|
|
|
|
|
|
|
|
/* Stream trace file descriptor */
|
|
|
|
int streamfd;
|
|
|
|
|
|
|
|
int ready;
|
|
|
|
|
|
|
|
/* The number of bytes filled with events */
|
|
|
|
size_t evlen;
|
|
|
|
|
|
|
|
/* Buffer to write events */
|
|
|
|
uint8_t *evbuf;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* State of each process on runtime */
|
|
|
|
struct ovni_rproc {
|
|
|
|
/* Path of the process tracedir */
|
|
|
|
char dir[PATH_MAX];
|
|
|
|
|
2021-08-03 17:48:37 +02:00
|
|
|
int app;
|
2021-07-24 10:53:41 +02:00
|
|
|
int proc;
|
2021-08-10 10:16:41 +02:00
|
|
|
char loom[OVNI_MAX_HOSTNAME];
|
2021-07-24 10:53:41 +02:00
|
|
|
int ncpus;
|
|
|
|
clockid_t clockid;
|
|
|
|
char procdir[PATH_MAX];
|
|
|
|
|
|
|
|
int ready;
|
2021-08-03 17:48:37 +02:00
|
|
|
|
|
|
|
JSON_Value *meta;
|
2021-07-24 10:53:41 +02:00
|
|
|
};
|
|
|
|
|
2021-08-03 17:48:37 +02:00
|
|
|
int ovni_proc_init(int app, char *loom, int proc);
|
|
|
|
|
2021-10-18 12:47:51 +02:00
|
|
|
int ovni_proc_fini(void);
|
2021-07-24 10:53:41 +02:00
|
|
|
|
|
|
|
int ovni_thread_init(pid_t tid);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
void ovni_clock_update(void);
|
2021-07-24 10:53:41 +02:00
|
|
|
|
|
|
|
void ovni_ev_set_mcv(struct ovni_ev *ev, char *mcv);
|
|
|
|
|
|
|
|
uint64_t ovni_ev_get_clock(struct ovni_ev *ev);
|
|
|
|
|
2021-10-18 12:47:51 +02:00
|
|
|
uint64_t ovni_get_clock(void);
|
|
|
|
|
2021-07-24 10:53:41 +02:00
|
|
|
void ovni_payload_add(struct ovni_ev *ev, uint8_t *buf, int size);
|
|
|
|
|
|
|
|
int ovni_ev_size(struct ovni_ev *ev);
|
|
|
|
|
|
|
|
int ovni_payload_size(struct ovni_ev *ev);
|
|
|
|
|
2021-08-03 17:48:37 +02:00
|
|
|
void ovni_add_cpu(int index, int phyid);
|
|
|
|
|
2021-07-24 10:53:41 +02:00
|
|
|
/* Set the current clock in the event and queue it */
|
2021-10-29 17:04:42 +02:00
|
|
|
void ovni_ev_emit(struct ovni_ev *ev);
|
|
|
|
void ovni_ev_jumbo_emit(struct ovni_ev *ev, uint8_t *buf, uint32_t bufsize);
|
2021-07-24 10:53:41 +02:00
|
|
|
|
2021-10-18 12:47:51 +02:00
|
|
|
int 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
|
|
|
|
2021-07-19 15:11:41 +02:00
|
|
|
#endif /* OVNI_H */
|