acrn-hypervisor/tools/acrntrace/acrntrace.h

111 lines
3.3 KiB
C

/*
* Copyright (C) 2018 Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "sbuf.h"
#define PCPU_NUM 4
#define TRACE_ELEMENT_SIZE 32 /* byte */
#define TRACE_ELEMENT_NUM ((4 * 1024 * 1024 - 64) / TRACE_ELEMENT_SIZE)
#define PAGE_SIZE 4096
#define PAGE_MASK (~(PAGE_SIZE - 1))
#define MMAP_SIZE (4 * 1024 * 1024)
/*
#define MMAP_SIZE ((TRACE_ELEMENT_SIZE * TRACE_ELEMENT_NUM \
+ PAGE_SIZE - 1) & PAGE_MASK)
*/
#define TRACE_FILE_NAME_LEN 36
#define TRACE_FILE_DIR_LEN (TRACE_FILE_NAME_LEN - 2)
#define TRACE_FILE_ROOT "/tmp/acrntrace/"
#define DEV_PATH_LEN 18
#define TIME_STR_LEN 16
#define CMD_MAX_LEN 48
#define pr_fmt(fmt) "acrntrace: " fmt
#define pr_info(fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__)
#define pr_err(fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__)
#ifdef DEBUG
#define pr_dbg(fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__)
#else
#define pr_dbg(fmt, ...)
#endif
/*
* flags:
* FLAG_TO_REL - resources need to be release
* FLAG_CLEAR_BUF - to clear buffered old data
*/
#define FLAG_TO_REL (1UL << 0)
#define FLAG_CLEAR_BUF (1UL << 1)
#define foreach_cpu(cpu) \
for ((cpu) = 0; (cpu) < (pcpu_num); (cpu)++)
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
typedef unsigned long uint64_t;
typedef struct {
uint64_t tsc;
uint64_t id;
union {
struct {
uint32_t a, b, c, d;
};
struct {
uint8_t a1, a2, a3, a4;
uint8_t b1, b2, b3, b4;
uint8_t c1, c2, c3, c4;
uint8_t d1, d2, d3, d4;
};
struct {
uint64_t e;
uint64_t f;
};
char str[16];
};
} trace_ev_t;
typedef struct {
uint32_t cpuid;
int exit_flag;
FILE *trace_filep;
shared_buf_t *sbuf;
pthread_mutex_t *sbuf_lock;
} param_t;
typedef struct {
int dev_fd;
char dev_name[DEV_PATH_LEN];
pthread_t thrd;
param_t param;
} reader_struct;