Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,28 @@ foreach target : target_dirs
suite: 'lat-pr-fast',
)

aot_cache_reader_test = executable(
'test-latx-aot-cache-reader',
files(
'target/i386/latx/sbt/tests/aot-cache-reader-test.c',
'target/i386/latx/sbt/aot.c',
'target/i386/latx/sbt/aot_lib.c',
'target/i386/latx/sbt/file_ctx.c'
) + genh + tcg_trace_genh + [syscall_nr_generated],
c_args: smc_reload_test_c_args + ['-DLATX_AOT_CACHE_READER_TEST'],
dependencies: [glib, m],
include_directories: target_inc,
link_args: smc_reload_test_link_args + [
'-Wl,--wrap=fdopen',
'-Wl,--wrap=fclose'
]
)
test(
'latx-aot-cache-reader',
aot_cache_reader_test,
suite: 'lat-pr-fast',
)

aot_exit_worker_test = executable(
'test-latx-aot-exit-worker',
files(
Expand Down
1 change: 1 addition & 0 deletions target/i386/latx/include/file_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ int aot_file_get_tmp_path(const char *aot_file, char *tmp_path,
size_t tmp_path_size);
int aot_file_get_lock_path(const char *aot_file, char *lock_path,
size_t lock_path_size);
bool aot_file_has_footer(FILE *file, const char *footer);
int aot_file_complete_write(FILE *file, const char *tmp_path);
/*
* Negative: rename failed. Zero: rename and directory sync succeeded.
Expand Down
95 changes: 64 additions & 31 deletions target/i386/latx/sbt/aot.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "qemu.h"
#include "lsenv.h"
#include "file_ctx.h"
#ifdef LATX_AOT_CACHE_READER_TEST
#include "tests/aot-cache-reader-test.h"
#endif
#include "aot_merge.h"
#include "aot_recover_tb.h"
#include "aot_smc.h"
Expand Down Expand Up @@ -890,43 +893,54 @@ char in_white_list(char *lib)

static int get_tb_num(char *lib_name, char *aot_file_name, CPUState *cpu)
{
void *buffer = MAP_FAILED;
FILE *pf = NULL;
long file_size;
size_t file_sz = 0;
int aim_tb_num = 0;
int fd;

if (get_aot_path(aot_file_name, aot_file_path, PATH_MAX) < 0) {
return 0;
}
if (access(aot_file_path, 0) < 0) {
return 0;
}
int fd = open(aot_file_path, O_RDONLY);
FILE *pf = fdopen(fd, "r");
lsassert(pf && ("open aot file failed!"));
/* Get file size */
fseek(pf, 0, SEEK_END); /* seek to end of file */
size_t file_sz = ftell(pf); /* get current file pointer */
char aot_version[strlen(AOT_VERSION) + 1];
/*check aot complete.*/
if (fseek(pf, -strlen(AOT_VERSION), SEEK_END) != 0) {
qemu_log_mask(LAT_LOG_AOT, "can't fseek aot file\n");
fclose(pf);
fd = open(aot_file_path, O_RDONLY);
if (fd < 0) {
return 0;
}
if (fread(aot_version, strlen(AOT_VERSION), 1, pf) != 1) {
qemu_log_mask(LAT_LOG_AOT, "get error.\n");
fclose(pf);
pf = fdopen(fd, "r");
if (!pf) {
close(fd);
return 0;
}
if (!strstr(aot_version, AOT_VERSION)) {

/* Get file size */
if (fseek(pf, 0, SEEK_END) || (file_size = ftell(pf)) < 0) {
goto out;
}
file_sz = file_size;
if (file_sz < sizeof(aot_header)) {
qemu_log_mask(LAT_LOG_AOT, "aot file is too short %s\n", lib_name);
remove(aot_file_path);
goto out;
}

/*check aot complete.*/
if (!aot_file_has_footer(pf, AOT_VERSION)) {
qemu_log_mask(LAT_LOG_AOT, "aot file is not complete %s\n", lib_name);
remove(aot_file_path);
return 0;
goto out;
}
fseek(pf, 0, SEEK_SET); /* seek back to beginning of file */

/* Read aot file */
/* buffer = malloc(file_sz); */
void *buffer = mmap(NULL, file_sz, PROT_READ, MAP_SHARED, fd, 0);
if (buffer < 0) {
buffer = mmap(NULL, file_sz, PROT_READ, MAP_SHARED, fd, 0);
if (buffer == MAP_FAILED) {
qemu_log_mask(LAT_LOG_AOT, "aot file mmap error\n");
return 0;
goto out;
}
assert(buffer);
aot_header *p_header = (aot_header *)buffer;
Expand All @@ -941,21 +955,30 @@ static int get_tb_num(char *lib_name, char *aot_file_name, CPUState *cpu)
aot_file_path, p_header->lib_size, statbuf.st_size);
remove(aot_file_path);
qemu_log_mask(LAT_LOG_AOT, "remove end\n");
return 0;
goto out;
}

int aim_tb_num = 0;
if (cpu->tcg_cflags & CF_PARALLEL) {
aim_tb_num = p_header->parallel_tb_num;
} else {
aim_tb_num = p_header->unparallel_tb_num;
}

munmap(buffer, file_sz);
out:
if (buffer != MAP_FAILED) {
munmap(buffer, file_sz);
}
fclose(pf);
return aim_tb_num;
}

#ifdef LATX_AOT_CACHE_READER_TEST
int aot_test_get_tb_num(char *lib_name, char *aot_file_name, CPUState *cpu)
{
return get_tb_num(lib_name, aot_file_name, cpu);
}
#endif

#define PROLIFERATION_RATE 10
static inline int need_gen_aot(CPUState *cpu,
char *lib_name, char *aot_file_name, int *lockfd, uint32_t tb_count)
Expand Down Expand Up @@ -1305,23 +1328,32 @@ lib_info *aot_load(char *lib_name, char *aot_file_name,
struct stat statbuf;
lib_info *curr_lib_info = NULL;
size_t file_sz = 0;
char aot_version[strlen(AOT_VERSION) + 1];
long file_size;
int fd = open(aot_file_path, O_RDONLY);
FILE *pf = NULL;

if (fd < 0) {
goto exit_aot_load;
}
pf = fdopen(fd, "r");
lsassert(pf && ("open aot file failed!"));
fseek(pf, 0, SEEK_END); /* seek to end of file */
file_sz = ftell(pf); /* get current file pointer */
if (!pf) {
close(fd);
fd = -1;
goto exit_aot_load;
}

/*check aot complete.*/
if (fseek(pf, -strlen(AOT_VERSION), SEEK_END) != 0
|| fread(aot_version, strlen(AOT_VERSION), 1, pf) != 1) {
if (fseek(pf, 0, SEEK_END) || (file_size = ftell(pf)) < 0) {
goto exit_aot_load;
}
if (!strstr(aot_version, AOT_VERSION)) {
if ((size_t)file_size < sizeof(aot_header)) {
qemu_log_mask(LAT_LOG_AOT, "aot file is too short %s\n", lib_name);
remove_curr_aot_file(fd);
goto exit_aot_load;
}
file_sz = file_size;

/*check aot complete.*/
if (!aot_file_has_footer(pf, AOT_VERSION)) {
qemu_log_mask(LAT_LOG_AOT, "aot file is not complete %s\n", lib_name);
remove_curr_aot_file(fd);
goto exit_aot_load;
Expand Down Expand Up @@ -1360,8 +1392,9 @@ lib_info *aot_load(char *lib_name, char *aot_file_name,
}
if (likely(pf)) {
fclose(pf);
} else if (fd >= 0) {
close(fd);
}
close(fd);
return curr_lib_info;
}

Expand Down
22 changes: 22 additions & 0 deletions target/i386/latx/sbt/file_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ int aot_file_get_lock_path(const char *aot_file, char *lock_path,
return 0;
}

bool aot_file_has_footer(FILE *file, const char *footer)
{
size_t footer_len;
char *actual;
bool matches;

if (!file || !footer) {
return false;
}

footer_len = strlen(footer);
if (!footer_len || fseek(file, -(long)footer_len, SEEK_END) != 0) {
return false;
}

actual = g_malloc(footer_len);
matches = fread(actual, footer_len, 1, file) == 1 &&
!memcmp(actual, footer, footer_len);
g_free(actual);
return matches;
}

int aot_file_complete_write(FILE *file, const char *tmp_path)
{
int saved_errno = 0;
Expand Down
Loading
Loading