mirror of
https://github.com/clearlinux/graphene.git
synced 2026-10-03 15:39:36 +00:00
apply internal patches
This commit is contained in:
@@ -15,4 +15,6 @@
|
||||
|
||||
#define CP_INIT_VMA_SIZE (64 * 1024 * 1024) /* 64MB */
|
||||
|
||||
#define EXECVE_RTLD 1
|
||||
|
||||
#endif /* _SHIM_DEFS_H_ */
|
||||
|
||||
@@ -163,14 +163,14 @@ enum {
|
||||
|
||||
/* CLD_EXIT: thread exit */
|
||||
struct shim_ipc_cld_exit {
|
||||
IDTYPE tid;
|
||||
IDTYPE ppid, tid;
|
||||
unsigned int exitcode;
|
||||
#ifdef PROFILE
|
||||
unsigned long time;
|
||||
#endif
|
||||
} __attribute__((packed));
|
||||
|
||||
int ipc_cld_exit_send (IDTYPE tid, unsigned int exitcode);
|
||||
int ipc_cld_exit_send (IDTYPE ppid, IDTYPE tid, unsigned int exitcode);
|
||||
int ipc_cld_exit_callback (IPC_CALLBACK_ARGS);
|
||||
|
||||
/* CLD_JOIN: child join the parent group */
|
||||
|
||||
@@ -456,9 +456,6 @@ void __handle_signal (shim_tcb_t * tcb, int sig, ucontext_t * uc)
|
||||
|
||||
sig = begin_sig;
|
||||
|
||||
if (!thread->has_signal.counter)
|
||||
return;
|
||||
|
||||
while (atomic_read(&thread->has_signal)) {
|
||||
struct shim_signal * signal = NULL;
|
||||
|
||||
@@ -476,9 +473,8 @@ void __handle_signal (shim_tcb_t * tcb, int sig, ucontext_t * uc)
|
||||
__handle_one_signal(tcb, sig, signal);
|
||||
free(signal);
|
||||
DkThreadYieldExecution();
|
||||
tcb->context.preempt &= ~SIGNAL_DELAYED;
|
||||
}
|
||||
|
||||
tcb->context.preempt &= ~SIGNAL_DELAYED;
|
||||
}
|
||||
|
||||
void handle_signal (bool delayed_only)
|
||||
|
||||
@@ -197,6 +197,9 @@ static bool check_vma_flags (const struct shim_vma * vma, const int * flags)
|
||||
if (!flags)
|
||||
return true;
|
||||
|
||||
if (vma->flags & VMA_UNMAPPED)
|
||||
return true;
|
||||
|
||||
if ((vma->flags & VMA_INTERNAL) != ((*flags) & VMA_INTERNAL)) {
|
||||
bug();
|
||||
return false;
|
||||
@@ -644,6 +647,7 @@ void * get_unmapped_vma (int length, int flags)
|
||||
new->addr = heap_top - length;
|
||||
new->length = length;
|
||||
new->flags = flags|VMA_UNMAPPED;
|
||||
new->prot = PROT_NONE;
|
||||
|
||||
list_for_each_entry_reverse(prev, &vma_list, list) {
|
||||
if (new->addr >= prev->addr + prev->length)
|
||||
@@ -699,10 +703,15 @@ void * get_unmapped_vma_for_cp (int length)
|
||||
|
||||
unsigned long top = (unsigned long) PAL_CB(user_address.end) - length;
|
||||
unsigned long bottom = (unsigned long) heap_top;
|
||||
int flags = MAP_ANONYMOUS|VMA_UNMAPPED|VMA_INTERNAL;
|
||||
void * addr;
|
||||
|
||||
if (bottom >= top)
|
||||
return NULL;
|
||||
if (bottom >= top) {
|
||||
unlock(vma_list_lock);
|
||||
return get_unmapped_vma(length, flags);
|
||||
}
|
||||
|
||||
debug("find unmapped vma between %p-%p\n", bottom, top);
|
||||
|
||||
for (int i = 0 ; i < NTRIES ; i++) {
|
||||
unsigned long rand;
|
||||
@@ -714,13 +723,16 @@ void * get_unmapped_vma_for_cp (int length)
|
||||
addr = NULL;
|
||||
}
|
||||
|
||||
if (!addr)
|
||||
if (!addr) {
|
||||
unlock(vma_list_lock);
|
||||
debug("cannot find unmapped vma for checkpoint\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new->addr = addr;
|
||||
new->length = length;
|
||||
new->flags = MAP_ANONYMOUS|VMA_UNMAPPED|VMA_INTERNAL;
|
||||
new->prot = PROT_READ|PROT_WRITE;
|
||||
new->flags = flags;
|
||||
new->prot = PROT_NONE;
|
||||
|
||||
list_add(&new->list, prev ? &prev->list : &vma_list);
|
||||
unlock(vma_list_lock);
|
||||
@@ -758,13 +770,23 @@ int lookup_overlap_vma (const void * addr, int length,
|
||||
struct shim_vma ** vma)
|
||||
{
|
||||
struct shim_vma * tmp = NULL;
|
||||
void * tmp_addr = NULL;
|
||||
int tmp_length;
|
||||
lock(vma_list_lock);
|
||||
|
||||
if ((tmp = __lookup_overlap_vma(addr, length, NULL)) && vma)
|
||||
get_vma((tmp));
|
||||
|
||||
if (tmp) {
|
||||
tmp_addr = tmp->addr;
|
||||
tmp_length = tmp->length;
|
||||
}
|
||||
|
||||
unlock(vma_list_lock);
|
||||
|
||||
if (tmp)
|
||||
debug("vma overlapped at %p-%p\n", tmp_addr, tmp_addr + tmp_length);
|
||||
|
||||
if (vma)
|
||||
*vma = tmp;
|
||||
return tmp ? 0: -ENOENT;
|
||||
@@ -1145,6 +1167,9 @@ BEGIN_RS_FUNC(vma)
|
||||
|
||||
unlock(vma_list_lock);
|
||||
|
||||
debug ("vma: %p-%p flags %x prot %p\n", vma->addr, vma->addr +
|
||||
vma->length, vma->flags, vma->prot);
|
||||
|
||||
if (!(vma->flags & VMA_UNMAPPED)) {
|
||||
if (vma->file) {
|
||||
struct shim_mount * fs = vma->file->fs;
|
||||
@@ -1177,7 +1202,7 @@ BEGIN_RS_FUNC(vma)
|
||||
}
|
||||
|
||||
if (need_mapped < vma->addr + vma->length) {
|
||||
int pal_alloc_type = (vma->flags & MAP_32BIT) ? PAL_ALLOC_32BIT : 0;
|
||||
int pal_alloc_type = 0;
|
||||
int pal_prot = vma->prot;
|
||||
if (DkVirtualMemoryAlloc(need_mapped,
|
||||
vma->addr + vma->length - need_mapped,
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
static int ipc_thread_exit (IDTYPE vmid, IDTYPE tid, unsigned int exitcode,
|
||||
unsigned long exit_time)
|
||||
static int ipc_thread_exit (IDTYPE vmid, IDTYPE ppid, IDTYPE tid,
|
||||
unsigned int exitcode, unsigned long exit_time)
|
||||
{
|
||||
assert(vmid != cur_process.vmid);
|
||||
|
||||
@@ -178,7 +178,7 @@ DEFINE_PROFILE_INTERVAL(ipc_cld_exit_turnaround, ipc);
|
||||
DEFINE_PROFILE_INTERVAL(ipc_cld_exit_send, ipc);
|
||||
DEFINE_PROFILE_INTERVAL(ipc_cld_exit_callback, ipc);
|
||||
|
||||
int ipc_cld_exit_send (IDTYPE tid, unsigned int exitcode)
|
||||
int ipc_cld_exit_send (IDTYPE ppid, IDTYPE tid, unsigned int exitcode)
|
||||
{
|
||||
unsigned long send_time = GET_PROFILE_INTERVAL();
|
||||
BEGIN_PROFILE_INTERVAL_SET(send_time);
|
||||
@@ -189,13 +189,14 @@ int ipc_cld_exit_send (IDTYPE tid, unsigned int exitcode)
|
||||
sizeof(struct shim_ipc_cld_exit), 0);
|
||||
struct shim_ipc_cld_exit * msgin =
|
||||
(struct shim_ipc_cld_exit *) &msg->msg;
|
||||
msgin->ppid = ppid;
|
||||
msgin->tid = tid;
|
||||
msgin->exitcode = exitcode;
|
||||
#ifdef PROFILE
|
||||
msgin->time = send_time;
|
||||
#endif
|
||||
|
||||
debug("ipc broadcast: IPC_CLD_EXIT(%u, %d)\n", tid, exitcode);
|
||||
debug("ipc broadcast: IPC_CLD_EXIT(%u, %u, %d)\n", ppid, tid, exitcode);
|
||||
|
||||
ret = broadcast_ipc(msg, NULL, 0, IPC_PORT_DIRPRT|IPC_PORT_DIRCLD);
|
||||
SAVE_PROFILE_INTERVAL(ipc_cld_exit_send);
|
||||
@@ -215,10 +216,11 @@ int ipc_cld_exit_callback (IPC_CALLBACK_ARGS)
|
||||
BEGIN_PROFILE_INTERVAL_SET(time);
|
||||
SAVE_PROFILE_INTERVAL(ipc_cld_exit_turnaround);
|
||||
|
||||
debug("ipc callback from %u: IPC_CLD_EXIT(%u, %d)\n",
|
||||
msg->src, msgin->tid, msgin->exitcode);
|
||||
debug("ipc callback from %u: IPC_CLD_EXIT(%u, %u, %d)\n",
|
||||
msg->src, msgin->ppid, msgin->tid, msgin->exitcode);
|
||||
|
||||
int ret = ipc_thread_exit(msg->src, msgin->tid, msgin->exitcode, time);
|
||||
int ret = ipc_thread_exit(msg->src, msgin->ppid, msgin->tid,
|
||||
msgin->exitcode, time);
|
||||
SAVE_PROFILE_INTERVAL(ipc_cld_exit_callback);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -577,13 +577,16 @@ int restore_checkpoint (struct cp_header * cphdr, struct mem_header * memhdr,
|
||||
if (entry->paddr) {
|
||||
*entry->paddr = entry->data;
|
||||
} else {
|
||||
debug("memory entry [%p]: %p-%p\n", entry, entry->addr,
|
||||
entry->addr + entry->size);
|
||||
|
||||
PAL_PTR addr = ALIGN_DOWN(entry->addr);
|
||||
PAL_NUM size = ALIGN_UP(entry->addr + entry->size) -
|
||||
(void *) addr;
|
||||
PAL_FLG prot = entry->prot;
|
||||
|
||||
if (!DkVirtualMemoryAlloc(addr, size, 0, prot|PAL_PROT_WRITE)) {
|
||||
debug("fail protecting %p-%p\n", addr, addr + size);
|
||||
debug("failed allocating %p-%p\n", addr, addr + size);
|
||||
return -PAL_ERRNO;
|
||||
}
|
||||
|
||||
@@ -592,8 +595,7 @@ int restore_checkpoint (struct cp_header * cphdr, struct mem_header * memhdr,
|
||||
|
||||
if (!(entry->prot & PAL_PROT_WRITE) &&
|
||||
!DkVirtualMemoryProtect(addr, size, prot)) {
|
||||
debug("fail protecting %p-%p\n", addr, addr + size);
|
||||
return -PAL_ERRNO;
|
||||
debug("failed protecting %p-%p (ignored)\n", addr, addr + size);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -916,6 +918,7 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
|
||||
cpstore->bound = CP_INIT_VMA_SIZE;
|
||||
|
||||
while (1) {
|
||||
debug("try allocate checkpoint store (size = %d)\n", cpstore->bound);
|
||||
cpstore->base = (ptr_t) cp_alloc(cpstore, 0, cpstore->bound);
|
||||
if (cpstore->base)
|
||||
break;
|
||||
@@ -926,6 +929,7 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
|
||||
|
||||
if (!cpstore->base) {
|
||||
ret = -ENOMEM;
|
||||
debug("failed creating checkpoint store\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -935,8 +939,10 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
|
||||
va_start(ap, thread);
|
||||
ret = (*migrate) (cpstore, thread, new_process, ap);
|
||||
va_end(ap);
|
||||
if (ret < 0)
|
||||
if (ret < 0) {
|
||||
debug("failed creating checkpoint (ret = %d)\n", ret);
|
||||
goto err;
|
||||
}
|
||||
|
||||
SAVE_PROFILE_INTERVAL(migrate_save_checkpoint);
|
||||
|
||||
@@ -981,6 +987,7 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
|
||||
bytes = DkStreamWrite(proc, 0, sizeof(struct newproc_header), &hdr, NULL);
|
||||
if (!bytes) {
|
||||
ret = -PAL_ERRNO;
|
||||
debug("failed writing to process stream (ret = %d)\n", ret);
|
||||
goto err;
|
||||
} else if (bytes < sizeof(struct newproc_header)) {
|
||||
ret = -EACCES;
|
||||
@@ -993,8 +1000,10 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
|
||||
ret = cpstore->use_gipc ? send_checkpoint_by_gipc(gipc_hdl, cpstore) :
|
||||
send_checkpoint_on_stream(proc, cpstore);
|
||||
|
||||
if (ret < 0)
|
||||
if (ret < 0) {
|
||||
debug("failed sending checkpoint (ret = %d)\n", ret);
|
||||
goto err;
|
||||
}
|
||||
|
||||
SAVE_PROFILE_INTERVAL(migrate_send_checkpoint);
|
||||
|
||||
@@ -1057,7 +1066,7 @@ int do_migration (struct newproc_cp_header * hdr, void ** cpptr)
|
||||
debug("checkpoint detected (%d bytes, expected at %p)\n",
|
||||
size, base);
|
||||
|
||||
if (base && !lookup_overlap_vma((void *) base, size, NULL)) {
|
||||
if (base && lookup_overlap_vma((void *) base, size, NULL) == -ENOENT) {
|
||||
mapaddr = (PAL_PTR) ALIGN_DOWN(base);
|
||||
mapsize = (PAL_PTR) ALIGN_UP(base + size) - mapaddr;
|
||||
mapoff = base - (ptr_t) mapaddr;
|
||||
|
||||
@@ -253,8 +253,6 @@ int shim_do_clone (int flags, void * user_stack_addr, int * parent_tidptr,
|
||||
thread->stack_red = thread->stack = vma->addr;
|
||||
tcb->shim_tcb.context.sp = user_stack_addr;
|
||||
tcb->shim_tcb.context.ret_ip = *(void **) user_stack_addr;
|
||||
} else {
|
||||
tcb->shim_tcb.context.ret_ip = *(void **) tcb->shim_tcb.context.sp;
|
||||
}
|
||||
|
||||
thread->is_alive = true;
|
||||
|
||||
@@ -345,9 +345,11 @@ err:
|
||||
|
||||
SAVE_PROFILE_INTERVAL(open_file_for_exec);
|
||||
|
||||
#if EXECVE_RTLD == 1
|
||||
int is_last = check_last_thread(cur_thread) == 0;
|
||||
if (is_last)
|
||||
return shim_do_execve_rtld(exec, argv, envp);
|
||||
#endif
|
||||
|
||||
INC_PROFILE_OCCURENCE(syscall_use_ipc);
|
||||
|
||||
|
||||
@@ -50,11 +50,12 @@ int thread_exit(struct shim_thread * self, bool send_ipc)
|
||||
/* Chia-Che: Broadcast exit message as early as possible,
|
||||
so other process can start early on responding. */
|
||||
if (self->in_vm && send_ipc)
|
||||
ipc_cld_exit_send(self->tid, self->exit_code);
|
||||
ipc_cld_exit_send(self->ppid, self->tid, self->exit_code);
|
||||
|
||||
lock(self->lock);
|
||||
|
||||
if (!self->is_alive) {
|
||||
debug("thread %d is dead\n", self->tid);
|
||||
out:
|
||||
unlock(self->lock);
|
||||
return 0;
|
||||
@@ -95,11 +96,14 @@ out:
|
||||
info.si_uid = self->uid;
|
||||
info.si_status = (exit_code & 0xff) << 8;
|
||||
|
||||
append_signal(parent, SIGCHLD, &info, false);
|
||||
append_signal(parent, SIGCHLD, &info, true);
|
||||
}
|
||||
unlock(parent->lock);
|
||||
|
||||
DkEventSet(parent->child_exit_event);
|
||||
} else {
|
||||
debug("parent not here, need to tell another process\n");
|
||||
ipc_cld_exit_send(self->ppid, self->tid, self->exit_code);
|
||||
}
|
||||
|
||||
struct robust_list_head * robust_list = (void *) self->robust_list;
|
||||
@@ -127,7 +131,8 @@ int try_process_exit (int error_code)
|
||||
{
|
||||
struct shim_thread * cur_thread = get_cur_thread();
|
||||
|
||||
thread_exit(cur_thread, true);
|
||||
if (cur_thread->in_vm)
|
||||
thread_exit(cur_thread, true);
|
||||
|
||||
if (check_last_thread(cur_thread))
|
||||
return 0;
|
||||
@@ -136,6 +141,8 @@ int try_process_exit (int error_code)
|
||||
|
||||
if (!exit_with_ipc_helper(true))
|
||||
shim_clean();
|
||||
else
|
||||
DkThreadExit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,10 @@ void * shim_do_mmap (void * addr, size_t length, int prot, int flags, int fd,
|
||||
|
||||
assert(!(flags & (VMA_UNMAPPED|VMA_TAINTED)));
|
||||
|
||||
int pal_alloc_type = ((flags & MAP_32BIT) ? PAL_ALLOC_32BIT : 0);
|
||||
if (flags & MAP_32BIT)
|
||||
return -ENOSYS;
|
||||
|
||||
int pal_alloc_type = 0;
|
||||
|
||||
if (!addr) {
|
||||
addr = get_unmapped_vma(ALIGN_UP(length), flags);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
subdirs = inline native benchmark regression apps
|
||||
subdirs = native apps
|
||||
|
||||
SYS ?= $(shell gcc -dumpmachine)
|
||||
export SYS
|
||||
@@ -14,20 +14,18 @@ LDFLAGS-debug = $(LDFLAGS) -L$(level)../src -L$(level)../../../Pal/src \
|
||||
-Wl,-rpath-link=$(abspath $(level)../../../Pal/src) \
|
||||
-lpal -lsysdb_debug
|
||||
|
||||
include $(level)../../../Pal/src/Makefile.Test
|
||||
|
||||
libs = $(level)../src/libsysdb_debug.so $(level)../../../Pal/src/libpal.so
|
||||
glibc_dir = $(level)../../build
|
||||
|
||||
all: $(target) $(if $(level),,build-subdirs)
|
||||
all: $(call expand_target,$(exec_target)) $(target) $(if $(level),,build-subdirs)
|
||||
|
||||
debug: DEBUG=debug
|
||||
debug: CC=gcc -g
|
||||
debug: CXX=g++ -g
|
||||
debug: $(target) $(if $(level),,build-subdirs)
|
||||
|
||||
manifest: manifest.template
|
||||
rm -rf $@
|
||||
cp $@.template $@
|
||||
|
||||
pal:
|
||||
[ ! -f $(level)../../../Pal/src/pal ] || ln -sf $(level)../../../Pal/src/pal pal
|
||||
|
||||
@@ -37,7 +35,7 @@ pal_sec:
|
||||
.PHONY: test clean
|
||||
|
||||
clean: $(clean-extra) $(if $(level),,clean-subdirs)
|
||||
rm -rf $(target)
|
||||
rm -rf $(call expand_target,$(exec_target)) $(target)
|
||||
|
||||
build-subdirs:
|
||||
for f in $(subdirs); do (cd $$f; $(MAKE) $(DEBUG); cd ..); done
|
||||
|
||||
@@ -28,7 +28,6 @@ manifest_rules = \
|
||||
$(extra_rules)
|
||||
|
||||
%.manifest: %.manifest.template
|
||||
rm -f $@ $@.backup
|
||||
sed $(manifest_rules) $< >$@
|
||||
chmod +x $@
|
||||
|
||||
|
||||
@@ -6,9 +6,14 @@ CORES = 4
|
||||
|
||||
conf_files = lighttpd-server.conf lighttpd.conf lighttpd-multithreaded.conf
|
||||
|
||||
all: build/sbin/lighttpd $(manifests) $(conf_files) test-data
|
||||
target = build/sbin/lighttpd $(conf_files) test-data
|
||||
exec_target = $(manifests)
|
||||
clean-extra = clean-others
|
||||
|
||||
%.manifest: %.manifest.template
|
||||
level = ../../
|
||||
include ../../Makefile
|
||||
|
||||
$(manifests): %.manifest: %.manifest.template build/sbin/lighttpd build/sbin/lighttpd-angel
|
||||
$(MAKE) -C .. lighttpd/$@ appdir=lighttpd/ \
|
||||
extra_rules="-e 's:\\\$$\$$(HOST):$(HOST):g' -e 's:\\\$$\$$(PORT):$(PORT):g'"
|
||||
|
||||
@@ -109,5 +114,5 @@ test-data: $(test-data)
|
||||
distclean: clean
|
||||
rm -rf build $(SRCDIR)
|
||||
|
||||
clean:
|
||||
clean-others:
|
||||
rm -rf $(conf_files) $(test-data)
|
||||
|
||||
@@ -28,7 +28,9 @@ fs.mount.other.pwd.type = chroot
|
||||
fs.mount.other.pwd.path = $(PWD)
|
||||
fs.mount.other.pwd.uri = file:
|
||||
|
||||
sys.stack.size = 131072
|
||||
|
||||
# allow to bind on port for listening
|
||||
net.rules.1 = $(HOST):$(PORT):0.0.0.0:0-65535
|
||||
|
||||
sys.stack.size = 256K
|
||||
sys.brk.size = 4M
|
||||
glibc.heap_size = 16M
|
||||
|
||||
@@ -28,7 +28,9 @@ fs.mount.other.pwd.type = chroot
|
||||
fs.mount.other.pwd.path = $(PWD)
|
||||
fs.mount.other.pwd.uri = file:
|
||||
|
||||
sys.stack.size = 131072
|
||||
|
||||
# allow to bind on port for listening
|
||||
net.rules.1 = $(HOST):$(PORT):0.0.0.0:0-65535
|
||||
|
||||
sys.stack.size = 256K
|
||||
sys.brk.size = 4M
|
||||
glibc.heap_size = 16M
|
||||
|
||||
@@ -1,51 +1,65 @@
|
||||
SYS ?= $(shell gcc -dumpmachine)
|
||||
export SYS
|
||||
|
||||
LMBENCHDIR = lmbench-2.5
|
||||
LINUXDIR=$(LMBENCHDIR)/bin/linux/
|
||||
GRAPHENEDIR=$(LMBENCHDIR)/bin/graphene/
|
||||
RUNDIR=$(LMBENCHDIR)/bin/graphene.run/
|
||||
|
||||
HOST_BINARIES = /bin/sh /usr/include/x86_64-linux-gnu/sys/types.h
|
||||
BINARIES = $(LMBENCHDIR)/bin/linux test-list $(addprefix host,$(HOST_BINARIES))
|
||||
NO_MANIFEST = lmbench lmbench.a *.o hello INFO.*
|
||||
BINARIES = $(LINUXDIR) $(addprefix host,$(HOST_BINARIES))
|
||||
LMBENCH_TESTS = lat_syscall lat_connect lat_fcntl lat_select lat_fs \
|
||||
lat_mmap lat_fifo lat_mem_rd lat_msg lat_tcp lat_udp \
|
||||
lat_unix_connect lat_pagefault \
|
||||
bw_tcp bw_mem bw_unix lat_proc lat_ctx lat_rpc \
|
||||
lat_unix lat_sig lat_http lat_pipe \
|
||||
bw_pipe bw_file_rd bw_mmap_rd lmhttp lmdd
|
||||
MANIFESTS = $(addsuffix .manifest,$(addprefix $(RUNDIR),$(LMBENCH_TESTS)))
|
||||
RUNTIME_BINS = $(LINUXDIR)hello /bin/sh
|
||||
RUNTIME_MANIFESTS=$(addsuffix .manifest,$(addprefix $(RUNDIR),$(foreach f,$(RUNTIME_BINS),$(notdir $(f)))))
|
||||
|
||||
target = $(addprefix $(LINUXDIR),$(LMBENCH_TESTS)) $(GRAPHENEDIR)
|
||||
exec_target = $(MANIFESTS) $(RUNTIME_MANIFESTS)
|
||||
clean-extra = clean-lmbench
|
||||
|
||||
level = ../../
|
||||
include ../../Makefile
|
||||
|
||||
export CC
|
||||
export CFLAGS
|
||||
|
||||
all debug: test-list $(LMBENCHDIR)/bin/linux
|
||||
for f in `cat test-list`; do \
|
||||
[ -f $(LMBENCHDIR)/bin/graphene/$$f.manifest ] || \
|
||||
$(MAKE) $(LMBENCHDIR)/bin/graphene/$$f.manifest; \
|
||||
ln -sf $$f.manifest $(LMBENCHDIR)/bin/graphene/$$f; \
|
||||
done
|
||||
cp -f $(foreach p,$(addprefix $(LMBENCHDIR)/bin/linux/,$(NO_MANIFEST)),$(wildcard $(p))) \
|
||||
$(LMBENCHDIR)/bin/graphene
|
||||
|
||||
debug: CC="gcc -g"
|
||||
|
||||
kvm: CFLAGS += -DKVM_BENCH -D_DEBUG
|
||||
kvm: all
|
||||
|
||||
servers = lat_udp lat_tcp lat_rpc lat_connect bw_tcp
|
||||
|
||||
$(LMBENCHDIR)/bin/graphene/%.manifest: $(LMBENCHDIR)/bin/graphene/%.manifest.template
|
||||
$(GRAPHENEDIR): $(MANIFESTS) $(addprefix $(RUNDIR),$(LMBENCH_TESTS)) $(LINUXDIR)
|
||||
mkdir -p $@
|
||||
for f in $(MANIFESTS); do \
|
||||
f=$${f##*/}; f=$${f%.manifest}; \
|
||||
echo "#!/bin/sh\ncd $(abspath $(RUNDIR)) && exec ./$$f.manifest \$$@" > $(GRAPHENEDIR)$$f; \
|
||||
chmod +x $(GRAPHENEDIR)$$f; \
|
||||
done
|
||||
cd $(LINUXDIR) && for f in *; do \
|
||||
if [ ! -f ../graphene/$$f ]; then cp $$f ../graphene/$$f; fi; \
|
||||
done
|
||||
|
||||
$(MANIFESTS): $(RUNDIR)%.manifest: $(RUNDIR)%.manifest.template $(LINUXDIR)%
|
||||
$(MAKE) -C .. lmbench/$@ appdir=lmbench/
|
||||
|
||||
$(LMBENCHDIR)/bin/graphene/%.manifest.template: manifest.template $(LMBENCHDIR)/bin/graphene
|
||||
ln -s ../../../$< $@
|
||||
$(addsuffix .template,$(MANIFESTS)): $(RUNDIR)%.manifest.template: manifest.template $(RUNDIR)
|
||||
ln -sf ../../../$< $@
|
||||
|
||||
$(LMBENCHDIR)/bin/graphene:
|
||||
$(RUNTIME_MANIFESTS): %.manifest: %.manifest.template
|
||||
$(MAKE) -C .. lmbench/$@ appdir=lmbench/
|
||||
|
||||
$(addsuffix .template,$(RUNTIME_MANIFESTS)): $(RUNDIR)%.manifest.template: %.manifest.template $(RUNDIR)
|
||||
ln -sf ../../../$< $@
|
||||
|
||||
$(addprefix $(RUNDIR),$(LMBENCH_TESTS)): $(RUNDIR)%: $(LINUXDIR)%
|
||||
ln -sf ../linux/$(notdir $@) $@
|
||||
|
||||
$(RUNDIR):
|
||||
mkdir -p $@
|
||||
|
||||
ifeq ($(SYS),x86_64-linux-gnu)
|
||||
$(LMBENCHDIR)/bin/linux: $(wildcard $(LMBENCHDIR)/src/*.c) $(wildcard $(LMBENCHDIR)/src/*.h)
|
||||
$(addprefix $(LINUXDIR),$(LMBENCH_TESTS)): \
|
||||
$(wildcard $(LMBENCHDIR)/src/*.c) $(wildcard $(LMBENCHDIR)/src/*.h)
|
||||
$(MAKE) -C $(LMBENCHDIR)/src OS=linux CC="gcc -g"
|
||||
|
||||
test-list: $(LMBENCHDIR)/bin/linux
|
||||
for f in `find $(LMBENCHDIR)/bin/linux/ \
|
||||
-type f -executable \
|
||||
$(subst *,\\*,$(addprefix -not -name ,$(NO_MANIFEST)))`; \
|
||||
do \
|
||||
echo $${f##*/}; \
|
||||
done > test-list
|
||||
|
||||
.PHONY: pack
|
||||
$(addprefix host,$(HOST_BINARIES)):
|
||||
@echo "$(patsubst host%,%,$@) -> $@"
|
||||
@@ -66,21 +80,20 @@ endif
|
||||
|
||||
LMBENCHCONFIG = $(shell $(LMBENCHDIR)/scripts/config)
|
||||
|
||||
$(LMBENCHDIR)/bin/linux/$(LMBENCHCONFIG):
|
||||
$(LINUXDIR)$(LMBENCHCONFIG):
|
||||
cd $(LMBENCHDIR)/scripts && env OS=linux ./config-run
|
||||
|
||||
/tmp/hello: $(LMBENCHDIR)/bin/linux/hello
|
||||
/tmp/hello: $(LINUXDIR)hello
|
||||
cp -f $< $@
|
||||
|
||||
test-native: $(LMBENCHDIR)/bin/linux $(LMBENCHDIR)/bin/linux/$(LMBENCHCONFIG) /tmp/hello
|
||||
test-native: $(LINUXDIR) $(LINUXDIR)$(LMBENCHCONFIG) /tmp/hello
|
||||
cd $(LMBENCHDIR)/scripts && env OS=linux ./results
|
||||
|
||||
$(LMBENCHDIR)/bin/graphene/$(LMBENCHCONFIG): $(LMBENCHDIR)/bin/linux/$(LMBENCHCONFIG)
|
||||
$(RUNDIR)$(LMBENCHCONFIG): $(LINUXDIR)$(LMBENCHCONFIG)
|
||||
sed -e "s/OS=\"linux\"/OS=\"graphene\"/g" $< > $@
|
||||
|
||||
test-graphene: all $(LMBENCHDIR)/bin/graphene/$(LMBENCHCONFIG) /tmp/hello
|
||||
test-graphene: all $(RUNDIR)$(LMBENCHCONFIG) /tmp/hello
|
||||
cd $(LMBENCHDIR)/scripts && env OS=graphene ./results
|
||||
|
||||
clean:
|
||||
rm -rf test-list
|
||||
clean-lmbench:
|
||||
$(MAKE) -C $(LMBENCHDIR) clean
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
#!$(PAL)
|
||||
|
||||
loader.preload = file:$(SHIMPATH)
|
||||
loader.exec = file:$(PWD)lmbench-2.5/bin/linux/$(BIN)
|
||||
loader.exec = file:$(BIN)
|
||||
loader.env.LD_LIBRARY_PATH = /lib:/lib64
|
||||
loader.debug_type = none
|
||||
|
||||
fs.mount.root.type = chroot
|
||||
fs.mount.root.uri = file:$(PWD)lmbench-2.5/bin/linux
|
||||
|
||||
fs.mount.other.graphene.type = chroot
|
||||
fs.mount.other.graphene.path = /graphene
|
||||
fs.mount.other.graphene.uri = file:$(PWD)lmbench-2.5/bin/graphene
|
||||
fs.mount.root.uri = file:
|
||||
|
||||
fs.mount.other.tmp1.type = chroot
|
||||
fs.mount.other.tmp1.path = /tmp
|
||||
@@ -32,6 +28,11 @@ fs.mount.other.inc.type = chroot
|
||||
fs.mount.other.inc.path = /usr/include/x86_64-linux-gnu/sys/types.h
|
||||
fs.mount.other.inc.uri = file:$(HOSTDIR)/usr/include/x86_64-linux-gnu/sys/types.h
|
||||
|
||||
fs.mount.other.tmp3.type = chroot
|
||||
fs.mount.other.tmp3.path = /tmp/hello
|
||||
fs.mount.other.tmp3.uri = file:../linux/hello
|
||||
|
||||
net.allow_bind.1 = 0.0.0.0:31233-31237
|
||||
net.allow_bind.2 = 0.0.0.0:34297-34298
|
||||
net.allow_peer.1 = 127.0.0.1:0-65535
|
||||
|
||||
|
||||
@@ -4,7 +4,14 @@ ifeq ($(OS),Linux)
|
||||
NPROCS := $(shell grep -c ^processor /proc/cpuinfo)
|
||||
endif
|
||||
|
||||
all: java test java.manifest
|
||||
TEST_CLASS = $(patsubst %.java,%,$(wildcard classes/*.java))
|
||||
|
||||
target = java test java.manifest
|
||||
exec_target = java.manifest
|
||||
clean-extra = clean-classes
|
||||
|
||||
level = ../../
|
||||
include ../../Makefile
|
||||
|
||||
USE_UBUNTU_SRC = no
|
||||
VERSION := 7
|
||||
@@ -115,12 +122,10 @@ $(JAVA_HOME)/bin/java: $(JRE_DIR)/bin/java
|
||||
find $(JAVA_HOME) -type f -executable -exec strip --strip-debug {} \;
|
||||
|
||||
distclean: clean
|
||||
rm -rf $(INSTALL_DIR) $(JAVA_HOME)
|
||||
rm -rf $(JAVA_DIR) $(JAVA_HOME)
|
||||
|
||||
endif
|
||||
|
||||
TEST_CLASS = $(patsubst %.java,%,$(wildcard *.java))
|
||||
|
||||
java: $(TARGET)
|
||||
test: $(addsuffix .class,$(TEST_CLASS))
|
||||
|
||||
@@ -134,5 +139,5 @@ java_home:
|
||||
%.class: %.java $(JAVAC)
|
||||
$(JAVAC) $<
|
||||
|
||||
clean:
|
||||
rm -rf java.manifest $(addsuffix .class,$(TEST_CLASS))
|
||||
clean-classes:
|
||||
rm -f $(addsuffix .class,$(TEST_CLASS))
|
||||
|
||||
@@ -8,7 +8,7 @@ loader.env.PATH = /jre/bin:/bin:/usr/bin
|
||||
loader.debug_type = none
|
||||
|
||||
fs.mount.root.type = chroot
|
||||
fs.mount.root.uri = file:
|
||||
fs.mount.root.uri = file:classes
|
||||
|
||||
fs.mount.other.lib1.type = chroot
|
||||
fs.mount.other.lib1.path = /lib
|
||||
|
||||
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -1,13 +1,17 @@
|
||||
manifests = python.manifest python-local.manifest
|
||||
manifest = python$(if $(LOCAL),-local,).manifest
|
||||
|
||||
all debug: $(manifests) benchmarks
|
||||
target = benchmarks
|
||||
exec_target = $(manifest)
|
||||
clean-extra = clean-local
|
||||
|
||||
level = ../../
|
||||
include ../../Makefile
|
||||
|
||||
local:
|
||||
make LOCAL=1
|
||||
|
||||
PYTHON_SRC = Python-2.7.9
|
||||
PYTHON_INSTALL = $(PYTHON_SRC)/build
|
||||
local: python-local
|
||||
|
||||
python-local: $(PYTHON_INSTALL)/bin/python
|
||||
cp -f $< $@
|
||||
|
||||
$(PYTHON_INSTALL)/bin/python: $(PYTHON_SRC)/Makefile
|
||||
cd $(PYTHON_SRC) && $(MAKE)
|
||||
@@ -27,9 +31,9 @@ test: all $(test_targets)
|
||||
python.manifest: python.manifest.template
|
||||
$(MAKE) -C .. python/$@ appdir=python/
|
||||
|
||||
python-local.manifest: python-local.manifest.template
|
||||
python-local.manifest: python-local.manifest.template $(PYTHON_INSTALL)/bin/python
|
||||
$(MAKE) -C .. python/$@ appdir=python/ \
|
||||
extra_rules="-e 's:\\\$$\$$(PYTHONDIR):$(shell readlink -f $(PYTHON_INSTALL)):g'"
|
||||
extra_rules="-e 's:\\\$$\$$(PYTHONDIR):$(shell readlink -f $(PYTHON_INSTALL))/:g'"
|
||||
|
||||
benchmarks: benchmarks.tar.gz
|
||||
tar -xzf $<
|
||||
@@ -40,9 +44,9 @@ test-graphene: benchmarks
|
||||
cd benchmarks && ./perf.py -b $(BENCHMARK) --csv ../results.csv /usr/bin/python $(PWD)/python.manifest
|
||||
|
||||
distclean: clean
|
||||
rm -rf $(PYTHON_SRC) python-local benchmarks
|
||||
rm -rf $(PYTHON_SRC) benchmarks
|
||||
|
||||
clean: clean-manifests
|
||||
|
||||
clean-manifests:
|
||||
rm -rf $(manifests)
|
||||
clean-local:
|
||||
ifneq ($(LOCAL),1)
|
||||
make clean LOCAL=1
|
||||
endif
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#!$(PAL)
|
||||
|
||||
loader.preload = file:$(SHIMPATH)
|
||||
loader.exec = file:python-local
|
||||
loader.exec = file:$(PYTHONDIR)bin/python
|
||||
loader.execname = python
|
||||
loader.env.LD_LIBRARY_PATH = $(PYTHONDIR)/lib:/graphene:/host:/usr/lib:/usr/lib/x86_64-linux-gnu
|
||||
loader.env.LD_LIBRARY_PATH = $(PYTHONDIR)lib:/graphene:/host:/usr/lib:/usr/lib/x86_64-linux-gnu
|
||||
loader.env.PATH = $(PYTHONDIR)/bin:/usr/bin:/bin
|
||||
loader.env.USERNAME =
|
||||
loader.env.HOME =
|
||||
loader.env.PWD =
|
||||
loader.env.PYTHONPATH = $(PYTHONDIR)/bin/python
|
||||
loader.env.PYTHONPATH = $(PYTHONDIR)bin/python
|
||||
loader.env.PYTHONHOME = $(PYTHONDIR)
|
||||
loader.debug_type = none
|
||||
|
||||
@@ -35,4 +35,6 @@ fs.mount.other.usr.type = chroot
|
||||
fs.mount.other.usr.path = /usr
|
||||
fs.mount.other.usr.uri = file:/usr
|
||||
|
||||
sys.brk.size = 262144 # 256K
|
||||
sys.stack.size = 256K
|
||||
sys.brk.size = 4M
|
||||
glibc.heap_size = 16M
|
||||
|
||||
@@ -29,4 +29,6 @@ fs.mount.other.usr.type = chroot
|
||||
fs.mount.other.usr.path = /usr
|
||||
fs.mount.other.usr.uri = file:/usr
|
||||
|
||||
sys.brk.size = 262144 # 256K
|
||||
sys.stack.size = 256K
|
||||
sys.brk.size = 4M
|
||||
glibc.heap_size = 16M
|
||||
|
||||
+116
-116
@@ -1,116 +1,116 @@
|
||||
"""
|
||||
Downloaded from https://code.google.com/p/benchrun/
|
||||
|
||||
A benchmark is defined by creating a subclass of Benchmark.
|
||||
The subclass should define a method run() that executes the code
|
||||
to be timed and returns the elapsed time in seconds (as a float),
|
||||
or None if the benchmark should be skipped.
|
||||
|
||||
See fibonacci.py for example.
|
||||
"""
|
||||
|
||||
import sys
|
||||
if sys.platform=='win32':
|
||||
from time import clock
|
||||
else:
|
||||
from time import time as clock
|
||||
|
||||
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/302478
|
||||
def combinations(*seqin):
|
||||
def rloop(seqin,comb):
|
||||
if seqin:
|
||||
for item in seqin[0]:
|
||||
newcomb = comb + [item]
|
||||
for item in rloop(seqin[1:],newcomb):
|
||||
yield item
|
||||
else:
|
||||
yield comb
|
||||
return rloop(seqin,[])
|
||||
|
||||
|
||||
class Benchmark:
|
||||
sort_by = []
|
||||
reference = None
|
||||
|
||||
def __init__(self):
|
||||
self.pnames = []
|
||||
self.pvalues = []
|
||||
self.results = []
|
||||
self.results_dict = {}
|
||||
for pname in self.parameters:
|
||||
value = getattr(self, pname)
|
||||
self.pnames.append(pname)
|
||||
self.pvalues.append(value)
|
||||
self.pcombos = list(combinations(*self.pvalues))
|
||||
if self.reference:
|
||||
self.reference_param = self.reference[0]
|
||||
self.reference_value = self.reference[1]
|
||||
|
||||
def time_all(self):
|
||||
"""Run benchmark for all versions and parameters."""
|
||||
for params in self.pcombos:
|
||||
args = dict(zip(self.pnames, params))
|
||||
t = self.run(**args)
|
||||
self.results.append(tuple(params) + (t,))
|
||||
self.results_dict[tuple(params)] = t
|
||||
|
||||
def sort_results(self):
|
||||
sort_keys = []
|
||||
for name in self.sort_by:
|
||||
sort_keys += [self.pnames.index(name)]
|
||||
for i, name in enumerate(self.pnames):
|
||||
if i not in sort_keys:
|
||||
sort_keys += [i]
|
||||
def key(v):
|
||||
return list(v[i] for i in sort_keys)
|
||||
self.results.sort(key=key)
|
||||
|
||||
def get_factor(self, pvalues, time):
|
||||
if not self.reference or not time:
|
||||
return None
|
||||
pvalues = list(pvalues)
|
||||
i = self.pnames.index(self.reference_param)
|
||||
if pvalues[i] == self.reference_value:
|
||||
return None
|
||||
else:
|
||||
pvalues[i] = self.reference_value
|
||||
ref = self.results_dict[tuple(pvalues)]
|
||||
if ref == None:
|
||||
return None
|
||||
return ref / time
|
||||
|
||||
def print_result(self):
|
||||
"""Run benchmark for all versions and parameters and print results
|
||||
in tabular form to the standard output."""
|
||||
self.time_all()
|
||||
self.sort_results()
|
||||
|
||||
print "=" * 78
|
||||
print
|
||||
print self.__class__.__name__
|
||||
print self.__doc__, "\n"
|
||||
|
||||
colwidth = 15
|
||||
reftimes = {}
|
||||
|
||||
ts = "seconds"
|
||||
if self.reference:
|
||||
ts += " (x faster than " + (str(self.reference_value)) + ")"
|
||||
print " ", " ".join([str(r).ljust(colwidth) for r in self.pnames + [ts]])
|
||||
print "-"*79
|
||||
|
||||
rows = []
|
||||
for vals in self.results:
|
||||
pvalues = vals[:-1]
|
||||
time = vals[-1]
|
||||
if time == None:
|
||||
stime = "(n/a)"
|
||||
else:
|
||||
stime = "%.8f" % time
|
||||
factor = self.get_factor(pvalues, time)
|
||||
if factor != None:
|
||||
stime += (" (%.2f)" % factor)
|
||||
vals = pvalues + (stime,)
|
||||
row = [str(val).ljust(colwidth) for val in vals]
|
||||
print " ", " ".join(row)
|
||||
print
|
||||
"""
|
||||
Downloaded from https://code.google.com/p/benchrun/
|
||||
|
||||
A benchmark is defined by creating a subclass of Benchmark.
|
||||
The subclass should define a method run() that executes the code
|
||||
to be timed and returns the elapsed time in seconds (as a float),
|
||||
or None if the benchmark should be skipped.
|
||||
|
||||
See fibonacci.py for example.
|
||||
"""
|
||||
|
||||
import sys
|
||||
if sys.platform=='win32':
|
||||
from time import clock
|
||||
else:
|
||||
from time import time as clock
|
||||
|
||||
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/302478
|
||||
def combinations(*seqin):
|
||||
def rloop(seqin,comb):
|
||||
if seqin:
|
||||
for item in seqin[0]:
|
||||
newcomb = comb + [item]
|
||||
for item in rloop(seqin[1:],newcomb):
|
||||
yield item
|
||||
else:
|
||||
yield comb
|
||||
return rloop(seqin,[])
|
||||
|
||||
|
||||
class Benchmark:
|
||||
sort_by = []
|
||||
reference = None
|
||||
|
||||
def __init__(self):
|
||||
self.pnames = []
|
||||
self.pvalues = []
|
||||
self.results = []
|
||||
self.results_dict = {}
|
||||
for pname in self.parameters:
|
||||
value = getattr(self, pname)
|
||||
self.pnames.append(pname)
|
||||
self.pvalues.append(value)
|
||||
self.pcombos = list(combinations(*self.pvalues))
|
||||
if self.reference:
|
||||
self.reference_param = self.reference[0]
|
||||
self.reference_value = self.reference[1]
|
||||
|
||||
def time_all(self):
|
||||
"""Run benchmark for all versions and parameters."""
|
||||
for params in self.pcombos:
|
||||
args = dict(zip(self.pnames, params))
|
||||
t = self.run(**args)
|
||||
self.results.append(tuple(params) + (t,))
|
||||
self.results_dict[tuple(params)] = t
|
||||
|
||||
def sort_results(self):
|
||||
sort_keys = []
|
||||
for name in self.sort_by:
|
||||
sort_keys += [self.pnames.index(name)]
|
||||
for i, name in enumerate(self.pnames):
|
||||
if i not in sort_keys:
|
||||
sort_keys += [i]
|
||||
def key(v):
|
||||
return list(v[i] for i in sort_keys)
|
||||
self.results.sort(key=key)
|
||||
|
||||
def get_factor(self, pvalues, time):
|
||||
if not self.reference or not time:
|
||||
return None
|
||||
pvalues = list(pvalues)
|
||||
i = self.pnames.index(self.reference_param)
|
||||
if pvalues[i] == self.reference_value:
|
||||
return None
|
||||
else:
|
||||
pvalues[i] = self.reference_value
|
||||
ref = self.results_dict[tuple(pvalues)]
|
||||
if ref == None:
|
||||
return None
|
||||
return ref / time
|
||||
|
||||
def print_result(self):
|
||||
"""Run benchmark for all versions and parameters and print results
|
||||
in tabular form to the standard output."""
|
||||
self.time_all()
|
||||
self.sort_results()
|
||||
|
||||
print "=" * 78
|
||||
print
|
||||
print self.__class__.__name__
|
||||
print self.__doc__, "\n"
|
||||
|
||||
colwidth = 15
|
||||
reftimes = {}
|
||||
|
||||
ts = "seconds"
|
||||
if self.reference:
|
||||
ts += " (x faster than " + (str(self.reference_value)) + ")"
|
||||
print " ", " ".join([str(r).ljust(colwidth) for r in self.pnames + [ts]])
|
||||
print "-"*79
|
||||
|
||||
rows = []
|
||||
for vals in self.results:
|
||||
pvalues = vals[:-1]
|
||||
time = vals[-1]
|
||||
if time == None:
|
||||
stime = "(n/a)"
|
||||
else:
|
||||
stime = "%.8f" % time
|
||||
factor = self.get_factor(pvalues, time)
|
||||
if factor != None:
|
||||
stime += (" (%.2f)" % factor)
|
||||
vals = pvalues + (stime,)
|
||||
row = [str(val).ljust(colwidth) for val in vals]
|
||||
print " ", " ".join(row)
|
||||
print
|
||||
+54
-54
@@ -1,54 +1,54 @@
|
||||
"""
|
||||
Downloaded from https://code.google.com/p/benchrun/
|
||||
|
||||
Fibonacci numbers test benchmark
|
||||
"""
|
||||
|
||||
from benchrun import Benchmark, clock
|
||||
|
||||
def fib1(n):
|
||||
if n < 2:
|
||||
return n
|
||||
return fib1(n-1) + fib1(n-2)
|
||||
|
||||
def fib2(n):
|
||||
if n < 2:
|
||||
return n
|
||||
a, b = 1, 0
|
||||
for i in xrange(n-1):
|
||||
a, b = a+b, a
|
||||
return a
|
||||
|
||||
class FibonacciBenchmark(Benchmark):
|
||||
"""Compare time to compute the nth Fibonacci number recursively
|
||||
(fib1) and iteratively (fib2)."""
|
||||
|
||||
# Execute for all combinations of these parameters
|
||||
parameters = ['version', 'n']
|
||||
version = ['fib1', 'fib2']
|
||||
n = range(0, 60, 5)
|
||||
|
||||
# Compare timings against this parameter value
|
||||
reference = ('version', 'fib1')
|
||||
|
||||
def run(self, n, version):
|
||||
f = globals()[version]
|
||||
# Don't repeat when slow
|
||||
if version == 'fib1' and n > 10:
|
||||
# Skip altogether
|
||||
if n > 30:
|
||||
return None
|
||||
t1 = clock()
|
||||
f(n)
|
||||
t2 = clock()
|
||||
return t2-t1
|
||||
# Need to repeat many times to get accurate timings for small n
|
||||
else:
|
||||
t1 = clock()
|
||||
f(n); f(n); f(n); f(n); f(n); f(n); f(n)
|
||||
f(n); f(n); f(n); f(n); f(n); f(n); f(n)
|
||||
t2 = clock()
|
||||
return (t2 - t1) / 14
|
||||
|
||||
if __name__ == '__main__':
|
||||
FibonacciBenchmark().print_result()
|
||||
"""
|
||||
Downloaded from https://code.google.com/p/benchrun/
|
||||
|
||||
Fibonacci numbers test benchmark
|
||||
"""
|
||||
|
||||
from benchrun import Benchmark, clock
|
||||
|
||||
def fib1(n):
|
||||
if n < 2:
|
||||
return n
|
||||
return fib1(n-1) + fib1(n-2)
|
||||
|
||||
def fib2(n):
|
||||
if n < 2:
|
||||
return n
|
||||
a, b = 1, 0
|
||||
for i in xrange(n-1):
|
||||
a, b = a+b, a
|
||||
return a
|
||||
|
||||
class FibonacciBenchmark(Benchmark):
|
||||
"""Compare time to compute the nth Fibonacci number recursively
|
||||
(fib1) and iteratively (fib2)."""
|
||||
|
||||
# Execute for all combinations of these parameters
|
||||
parameters = ['version', 'n']
|
||||
version = ['fib1', 'fib2']
|
||||
n = range(0, 60, 5)
|
||||
|
||||
# Compare timings against this parameter value
|
||||
reference = ('version', 'fib1')
|
||||
|
||||
def run(self, n, version):
|
||||
f = globals()[version]
|
||||
# Don't repeat when slow
|
||||
if version == 'fib1' and n > 10:
|
||||
# Skip altogether
|
||||
if n > 30:
|
||||
return None
|
||||
t1 = clock()
|
||||
f(n)
|
||||
t2 = clock()
|
||||
return t2-t1
|
||||
# Need to repeat many times to get accurate timings for small n
|
||||
else:
|
||||
t1 = clock()
|
||||
f(n); f(n); f(n); f(n); f(n); f(n); f(n)
|
||||
f(n); f(n); f(n); f(n); f(n); f(n); f(n)
|
||||
t2 = clock()
|
||||
return (t2 - t1) / 14
|
||||
|
||||
if __name__ == '__main__':
|
||||
FibonacciBenchmark().print_result()
|
||||
+70
-70
@@ -1,70 +1,70 @@
|
||||
"""
|
||||
Downloaded from https://code.google.com/p/benchrun/
|
||||
|
||||
Test code for benchrun: sympy performance benchmark.
|
||||
"""
|
||||
|
||||
from benchrun import Benchmark, clock
|
||||
|
||||
import sympycore
|
||||
import sympy
|
||||
|
||||
class SympyBenchmark(Benchmark):
|
||||
version = ['sympy', 'sympycore']
|
||||
reference = ('version', 'sympy')
|
||||
|
||||
|
||||
class DirectSymbolicAddition(SympyBenchmark):
|
||||
"""Add small polynomials with rational coefficients"""
|
||||
parameters = ['version']
|
||||
def run(self, version):
|
||||
module = __import__(version)
|
||||
x, y, z = map(module.Symbol, 'xyz')
|
||||
a = 3*x + 2*x*y - module.Rational(1,2)*z + 2
|
||||
b = 2*x + module.Rational(3,2)*x*y + 4*z - 2
|
||||
n = N = 100
|
||||
t1 = clock()
|
||||
while n:
|
||||
a + n*b
|
||||
n -= 1
|
||||
t2 = clock()
|
||||
return (t2-t1)/N
|
||||
|
||||
class PowerExpansion(SympyBenchmark):
|
||||
"""Expand (x+y+z)**n * (y+x)**(n-1)"""
|
||||
parameters = ['version', 'n']
|
||||
n = [5, 10, 20]
|
||||
def run(self, version, n):
|
||||
module = __import__(version)
|
||||
if version == 'sympy' and n > 10:
|
||||
return None
|
||||
x, y, z = map(module.Symbol, 'xyz')
|
||||
t1 = clock()
|
||||
e = ((x+y+z)**n * (y+x)**(n-1)).expand()
|
||||
t2 = clock()
|
||||
return t2-t1
|
||||
|
||||
class LegendreRecurrence(SympyBenchmark):
|
||||
"""Calculate the nth Legendre polynomial by recurrence."""
|
||||
parameters = ['version', 'n']
|
||||
n = [3, 10, 30, 100]
|
||||
def run(self, version, n):
|
||||
module = __import__(version)
|
||||
x = module.Symbol('x')
|
||||
if version == 'sympy' and n > 30:
|
||||
return None
|
||||
b, a = x, 1
|
||||
t1 = clock()
|
||||
for n in range(1, n):
|
||||
b, a = (((2*n+1)*x*b - n*a)/(n+1)).expand(), b
|
||||
t2 = clock()
|
||||
return t2-t1
|
||||
|
||||
all_benchmarks = [
|
||||
DirectSymbolicAddition(),
|
||||
PowerExpansion(),
|
||||
LegendreRecurrence(),
|
||||
]
|
||||
|
||||
for bench in all_benchmarks:
|
||||
bench.print_result()
|
||||
"""
|
||||
Downloaded from https://code.google.com/p/benchrun/
|
||||
|
||||
Test code for benchrun: sympy performance benchmark.
|
||||
"""
|
||||
|
||||
from benchrun import Benchmark, clock
|
||||
|
||||
import sympycore
|
||||
import sympy
|
||||
|
||||
class SympyBenchmark(Benchmark):
|
||||
version = ['sympy', 'sympycore']
|
||||
reference = ('version', 'sympy')
|
||||
|
||||
|
||||
class DirectSymbolicAddition(SympyBenchmark):
|
||||
"""Add small polynomials with rational coefficients"""
|
||||
parameters = ['version']
|
||||
def run(self, version):
|
||||
module = __import__(version)
|
||||
x, y, z = map(module.Symbol, 'xyz')
|
||||
a = 3*x + 2*x*y - module.Rational(1,2)*z + 2
|
||||
b = 2*x + module.Rational(3,2)*x*y + 4*z - 2
|
||||
n = N = 100
|
||||
t1 = clock()
|
||||
while n:
|
||||
a + n*b
|
||||
n -= 1
|
||||
t2 = clock()
|
||||
return (t2-t1)/N
|
||||
|
||||
class PowerExpansion(SympyBenchmark):
|
||||
"""Expand (x+y+z)**n * (y+x)**(n-1)"""
|
||||
parameters = ['version', 'n']
|
||||
n = [5, 10, 20]
|
||||
def run(self, version, n):
|
||||
module = __import__(version)
|
||||
if version == 'sympy' and n > 10:
|
||||
return None
|
||||
x, y, z = map(module.Symbol, 'xyz')
|
||||
t1 = clock()
|
||||
e = ((x+y+z)**n * (y+x)**(n-1)).expand()
|
||||
t2 = clock()
|
||||
return t2-t1
|
||||
|
||||
class LegendreRecurrence(SympyBenchmark):
|
||||
"""Calculate the nth Legendre polynomial by recurrence."""
|
||||
parameters = ['version', 'n']
|
||||
n = [3, 10, 30, 100]
|
||||
def run(self, version, n):
|
||||
module = __import__(version)
|
||||
x = module.Symbol('x')
|
||||
if version == 'sympy' and n > 30:
|
||||
return None
|
||||
b, a = x, 1
|
||||
t1 = clock()
|
||||
for n in range(1, n):
|
||||
b, a = (((2*n+1)*x*b - n*a)/(n+1)).expand(), b
|
||||
t2 = clock()
|
||||
return t2-t1
|
||||
|
||||
all_benchmarks = [
|
||||
DirectSymbolicAddition(),
|
||||
PowerExpansion(),
|
||||
LegendreRecurrence(),
|
||||
]
|
||||
|
||||
for bench in all_benchmarks:
|
||||
bench.print_result()
|
||||
@@ -1,13 +1,17 @@
|
||||
manifests = R.manifest R-local.manifest
|
||||
manifest = R$(if $(LOCAL),-local,).manifest
|
||||
|
||||
all debug: $(manifests)
|
||||
target =
|
||||
exec_target = $(manifest)
|
||||
clean-extra = clean-local
|
||||
|
||||
level = ../../
|
||||
include ../../Makefile
|
||||
|
||||
local:
|
||||
make LOCAL=1
|
||||
|
||||
R_SRC = R-3.1.2
|
||||
R_INSTALL = $(R_SRC)/build
|
||||
local: R-local
|
||||
|
||||
R-local: $(R_INSTALL)/lib/R/bin/exec/R
|
||||
cp -f $< $@
|
||||
|
||||
$(R_INSTALL)/lib/R/bin/exec/R: $(R_SRC)/Makefile
|
||||
cd $(R_SRC) && $(MAKE)
|
||||
@@ -27,14 +31,14 @@ test: all $(test_targets)
|
||||
R.manifest: R.manifest.template
|
||||
$(MAKE) -C .. r/$@ appdir=r/
|
||||
|
||||
R-local.manifest: R-local.manifest.template
|
||||
R-local.manifest: R-local.manifest.template $(R_INSTALL)/lib/R/bin/exec/R
|
||||
$(MAKE) -C .. r/$@ appdir=r/ \
|
||||
extra_rules="-e 's:\\\$$\$$(RDIR):$(shell readlink -f $(R_INSTALL)/lib/R):g'"
|
||||
extra_rules="-e 's:\\\$$\$$(RDIR):$(shell readlink -f $(R_INSTALL)/lib/R)/:g'"
|
||||
|
||||
distclean: clean
|
||||
rm -rf $(R_SRC) R-local
|
||||
rm -rf $(R_SRC)
|
||||
|
||||
clean: clean-manifests
|
||||
|
||||
clean-manifests:
|
||||
rm -rf $(manifests)
|
||||
clean-local:
|
||||
ifneq ($(LOCAL),1)
|
||||
make clean LOCAL=1
|
||||
endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!$(PAL)
|
||||
|
||||
loader.preload = file:$(SHIMPATH)
|
||||
loader.exec = file:R-local
|
||||
loader.exec = file:$(RDIR)/bin/exec/R
|
||||
loader.execname = $(RDIR)/bin/exec/R
|
||||
loader.env.LD_LIBRARY_PATH = $(RDIR)/lib:/lib:/lib/x86_64-linux-gnu:/usr/lib:/usr/lib/x86_64-linux-gnu
|
||||
loader.env.PATH = $(RDIR)/bin:/usr/bin:/bin
|
||||
@@ -42,4 +42,6 @@ fs.mount.other.tmp.type = chroot
|
||||
fs.mount.other.tmp.path = /tmp
|
||||
fs.mount.other.tmp.uri = file:
|
||||
|
||||
sys.brk.size = 262144 # 256K
|
||||
sys.stack.size = 256K
|
||||
sys.brk.size = 4M
|
||||
glibc.heap_size = 16M
|
||||
|
||||
@@ -38,4 +38,6 @@ fs.mount.other.tmp.type = chroot
|
||||
fs.mount.other.tmp.path = /tmp
|
||||
fs.mount.other.tmp.uri = file:
|
||||
|
||||
sys.brk.size = 262144 # 256K
|
||||
sys.stack.size = 256K
|
||||
sys.brk.size = 4M
|
||||
glibc.heap_size = 16M
|
||||
|
||||
@@ -4,12 +4,16 @@ special_executables = static pie
|
||||
c_executables = $(filter-out $(special_executables),$(patsubst %.c,%,$(wildcard *.c)))
|
||||
cxx_executables = $(patsubst %.cpp,%,$(wildcard *.cpp))
|
||||
|
||||
target = $(special_executables) $(c_executables) $(cxx_executables) \
|
||||
manifest static.manifest pal pal_sec
|
||||
exec_target = $(special_executables) $(c_executables) $(cxx_executables)
|
||||
target = $(exec_target) manifest static.manifest pal pal_sec
|
||||
|
||||
level = ../
|
||||
include ../Makefile
|
||||
|
||||
manifest: manifest.template
|
||||
rm -rf $@
|
||||
cp $@.template $@
|
||||
|
||||
%.manifest: %.manifest.template
|
||||
rm -rf $@
|
||||
cp $@.template $@
|
||||
|
||||
@@ -83,7 +83,7 @@ int get_norm_path (const char * path, char * buf, int offset, int size)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (offset || c != '/') {
|
||||
if (offset || c != '/' || *path == '/') {
|
||||
if (offset >= size - 1)
|
||||
return -PAL_ERROR_TOOLONG;
|
||||
buf[offset++] = c;
|
||||
|
||||
@@ -4,9 +4,6 @@ CC = gcc -g
|
||||
CFLAGS = -Wall -O2 -std=gnu99 -fgnu89-inline -fno-builtin -nostdlib \
|
||||
-I../include/pal -I../lib
|
||||
|
||||
target = $(patsubst %.c,%,$(wildcard *.c)) \
|
||||
manifest $(patsubst %.manifest.template,%.manifest,$(wildcard *.manifest.template))
|
||||
|
||||
preloads = $(patsubst %.c,%,$(wildcard *.so.c))
|
||||
executables = $(filter-out $(preloads),$(patsubst %.c,%,$(wildcard *.c)))
|
||||
manifests = manifest $(patsubst %.manifest.template,%.manifest,$(wildcard *.manifest.template))
|
||||
@@ -17,7 +14,9 @@ graphene_lib = .lib/graphene-lib.a
|
||||
pal_lib = ../src/libpal.so
|
||||
headers = $(wildcard ../include/pal/*.h)
|
||||
|
||||
all: $(target)
|
||||
include ../src/Makefile.Test
|
||||
|
||||
all: $(call expand_target,$(target))
|
||||
|
||||
manifest_rules = \
|
||||
-e 's:\$$(PAL):$(abspath ../src/pal):g' \
|
||||
@@ -61,7 +60,7 @@ endif
|
||||
|
||||
PYTHONENV = "PYTHONPATH=../../Scripts"
|
||||
|
||||
regression: $(target)
|
||||
regression: $(call expand_target,$(target))
|
||||
@printf "\n\nBasic Bootstrapping:\n"
|
||||
@for f in $(wildcard 00_*.py); do env $(PYTHONENV) python $$f; done
|
||||
@printf "\n\nException Handling:\n"
|
||||
@@ -77,4 +76,4 @@ regression: $(target)
|
||||
@printf "\n\n"
|
||||
|
||||
clean:
|
||||
rm -rf $(target) *.tmp .lib
|
||||
rm -rf $(call expand_target,$(target)) *.tmp .lib
|
||||
|
||||
@@ -99,8 +99,7 @@ extern struct pal_bsd_state {
|
||||
|
||||
static inline int HOST_FLAGS (int alloc_type, int prot)
|
||||
{
|
||||
return ((alloc_type & PAL_ALLOC_32BIT) ? MAP_32BIT : 0) |
|
||||
((alloc_type & PAL_ALLOC_RESERVE) ? MAP_NORESERVE : 0) |
|
||||
return ((alloc_type & PAL_ALLOC_RESERVE) ? MAP_NORESERVE : 0) |
|
||||
((prot & PAL_PROT_WRITECOPY) ? MAP_PRIVATE : MAP_SHARED);
|
||||
}
|
||||
|
||||
|
||||
@@ -122,8 +122,7 @@ extern struct pal_linux_state {
|
||||
|
||||
static inline int HOST_FLAGS (int alloc_type, int prot)
|
||||
{
|
||||
return ((alloc_type & PAL_ALLOC_32BIT) ? MAP_32BIT : 0) |
|
||||
((alloc_type & PAL_ALLOC_RESERVE) ? MAP_NORESERVE|MAP_UNINITIALIZED : 0) |
|
||||
return ((alloc_type & PAL_ALLOC_RESERVE) ? MAP_NORESERVE|MAP_UNINITIALIZED : 0) |
|
||||
((prot & PAL_PROT_WRITECOPY) ? MAP_PRIVATE : MAP_SHARED);
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -182,8 +182,11 @@ PAL_CONTROL * pal_control_addr (void);
|
||||
*/
|
||||
|
||||
/* Memory Allocation Flags */
|
||||
#define PAL_ALLOC_32BIT 0x0001 /* Only give out 32-bit addresses */
|
||||
#define PAL_ALLOC_RESERVE 0x0002 /* Only reserve the memory */
|
||||
#define PAL_ALLOC_RESERVE 0x0001 /* Only reserve the memory */
|
||||
|
||||
#ifdef IN_PAL
|
||||
#define PAL_ALLOC_INTERNAL 0x8000
|
||||
#endif
|
||||
|
||||
/* Memory Protection Flags */
|
||||
#define PAL_PROT_NONE 0x0 /* 0x0 Page can not be accessed. */
|
||||
|
||||
+3
-2
@@ -38,7 +38,7 @@ static PAL_LOCK slab_mgr_lock = LOCK_INIT;
|
||||
|
||||
#if STATIC_SLAB == 1
|
||||
# warning "Using static slab"
|
||||
# define POOL_SIZE 4 * 1024 * 1024 /* 4MB by default */
|
||||
# define POOL_SIZE 64 * 1024 * 1024 /* 64MB by default */
|
||||
static char mem_pool[POOL_SIZE];
|
||||
static char *bump = mem_pool;
|
||||
static char *mem_pool_end = &mem_pool[POOL_SIZE];
|
||||
@@ -61,7 +61,8 @@ static inline void * __malloc (int size)
|
||||
}
|
||||
#endif
|
||||
|
||||
_DkVirtualMemoryAlloc(&addr, size, 0, PAL_PROT_READ|PAL_PROT_WRITE);
|
||||
_DkVirtualMemoryAlloc(&addr, size, PAL_ALLOC_INTERNAL,
|
||||
PAL_PROT_READ|PAL_PROT_WRITE);
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,6 @@
|
||||
int main (int argc, char ** argv, char ** envp)
|
||||
{
|
||||
PAL_NUM values[4];
|
||||
DkCpuIdRetrieve(0, values);
|
||||
|
||||
pal_printf("cpuid[0] = %08x %08x %08x %08x\n", values[0], values[1],
|
||||
values[2], values[3]);
|
||||
|
||||
asm volatile("mov $0, %%rax\n"
|
||||
"cpuid\n"
|
||||
: "=a"(values[0]),
|
||||
|
||||
+5
-3
@@ -4,9 +4,11 @@ CC = gcc
|
||||
CFLAGS = -Wall -O2 -std=gnu99 -fgnu89-inline -fno-builtin -nostdlib \
|
||||
-I../include/pal -I../lib
|
||||
|
||||
include ../src/Makefile.Test
|
||||
|
||||
executables = HelloWorld File Failure Thread Fork Event Process Exception \
|
||||
Memory Pipe Tcp Udp Yield Broadcast Ipc Server Wait HandleSend \
|
||||
Select Segment Cpuid Pie
|
||||
Select Segment Sleep Cpuid Pie
|
||||
manifests = manifest
|
||||
|
||||
target = $(executables) $(manifests)
|
||||
@@ -15,7 +17,7 @@ graphene_lib = .lib/graphene-lib.a
|
||||
pal_lib = ../src/libpal.so
|
||||
headers = $(wildcard ../include/pal/*.h)
|
||||
|
||||
all: $(target)
|
||||
all: $(call expand_target,$(target))
|
||||
|
||||
debug: CC=gcc -g
|
||||
debug: $(target)
|
||||
@@ -43,4 +45,4 @@ $(executables): .packed/test.tar.gz
|
||||
endif
|
||||
|
||||
clean:
|
||||
rm -rf $(target) .lib
|
||||
rm -rf $(call expand_target,$(target)) .lib
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
|
||||
/* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
|
||||
|
||||
/* This Hello World simply print out "Hello World" */
|
||||
|
||||
#include "pal.h"
|
||||
#include "pal_debug.h"
|
||||
|
||||
char str[13];
|
||||
|
||||
int main (int argc, char ** argv, char ** envp)
|
||||
{
|
||||
long sleeping = 3000000;
|
||||
|
||||
if (argc > 1) {
|
||||
const char * c = argv[1];
|
||||
sleeping = 0;
|
||||
while (*c) {
|
||||
if ((*c) > '9' || (*c) < '0')
|
||||
break;
|
||||
sleeping *= 10;
|
||||
sleeping += (*c) - '0';
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
pal_printf("Enter Main Thread\n");
|
||||
|
||||
if (sleeping) {
|
||||
pal_printf("Sleeping %ld microsecond...\n", sleeping);
|
||||
DkThreadDelayExecution(sleeping);
|
||||
} else {
|
||||
while (1);
|
||||
}
|
||||
|
||||
pal_printf("Leave Main Thread\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user