From 97b660251dbf4a99de9ff48e9d764eee95b35849 Mon Sep 17 00:00:00 2001 From: edwin Date: Wed, 12 Apr 2006 22:20:49 +0000 Subject: [PATCH] * src/vm/rt-timing.c: Added file. * src/vm/rt-timing.h: Likewise. * src/vm/jit/jit.c: Moved real-time timing stuff to rt-timing.[ch] * src/vm/jit/jit.h: Likewise. * src/vm/vm.c (vm_exit_handler): Call rt_timing_print_time_stats. * src/vm/Makefile.am (rt-timing.c, rt-timing.h): Added. --- src/vm/Makefile.am | 9 ++- src/vm/jit/jit.c | 135 +++++++-------------------------------------- src/vm/jit/jit.h | 6 +- src/vm/rt-timing.c | 126 ++++++++++++++++++++++++++++++++++++++++++ src/vm/rt-timing.h | 87 +++++++++++++++++++++++++++++ src/vm/vm.c | 3 +- 6 files changed, 245 insertions(+), 121 deletions(-) create mode 100644 src/vm/rt-timing.c create mode 100644 src/vm/rt-timing.h diff --git a/src/vm/Makefile.am b/src/vm/Makefile.am index 0112556b7..db3b93cbf 100644 --- a/src/vm/Makefile.am +++ b/src/vm/Makefile.am @@ -28,7 +28,7 @@ ## ## Changes: ## -## $Id: Makefile.am 4693 2006-03-28 10:42:04Z twisti $ +## $Id: Makefile.am 4762 2006-04-12 22:20:49Z edwin $ ## Process this file with automake to produce Makefile.in @@ -44,6 +44,11 @@ STATISTICS_OBJ = \ statistics.h endif +if ENABLE_RT_TIMING +RT_TIMING_OBJ = \ + rt-timing.c +endif + if ENABLE_ZLIB ZLIB_OBJ = \ zip.c \ @@ -91,6 +96,8 @@ libvmcore_la_SOURCES = \ references.h \ resolve.c \ resolve.h \ + $(RT_TIMING_OBJ) \ + rt-timing.h \ $(STATISTICS_OBJ) \ signal.c \ signallocal.h \ diff --git a/src/vm/jit/jit.c b/src/vm/jit/jit.c index 6a87e424b..1691b0db4 100644 --- a/src/vm/jit/jit.c +++ b/src/vm/jit/jit.c @@ -31,7 +31,7 @@ Christian Thalinger Christian Ullrich - $Id: jit.c 4737 2006-04-05 12:56:43Z edwin $ + $Id: jit.c 4762 2006-04-12 22:20:49Z edwin $ */ @@ -41,11 +41,6 @@ #include -#if defined(ENABLE_RT_TIMING) -#include -#include -#endif - #include "mm/memory.h" #include "native/native.h" #include "toolbox/logging.h" @@ -81,6 +76,7 @@ #include "vm/jit/loop/graph.h" #include "vm/jit/loop/loop.h" #include "vm/jit/verify/typecheck.h" +#include "vm/rt-timing.h" #if defined(USE_THREADS) # if defined(NATIVE_THREADS) @@ -1468,95 +1464,6 @@ u1 *jit_compile(methodinfo *m) return r; } -/*****************************************************************************/ -/* TIMING OF COMPILER PASSES */ -/*****************************************************************************/ - -#if defined(ENABLE_RT_TIMING) - -#define JIT_GET_TIME(ts) \ - do { if (clock_gettime(CLOCK_THREAD_CPUTIME_ID,&(ts)) != 0) { \ - fprintf(stderr,"could not get time: %s\n",strerror(errno)); \ - abort(); \ - }} while (0) - -#define JITTIME_CHECKS 0 -#define JITTIME_PARSE 1 -#define JITTIME_STACK 2 -#define JITTIME_TYPECHECK 3 -#define JITTIME_LOOP 4 -#define JITTIME_IFCONV 5 -#define JITTIME_ALLOC 6 -#define JITTIME_RPLPOINTS 7 -#define JITTIME_CODEGEN 8 -#define JITTIME_TOTAL 9 -#define JITTIME_N 10 - -struct jit_time_stat { - int index; - const char *name; -}; - -static struct jit_time_stat jit_time_stat_defs[] = { - { JITTIME_CHECKS, "checks at beginning" }, - { JITTIME_PARSE, "parse" }, - { JITTIME_STACK, "analyse_stack" }, - { JITTIME_TYPECHECK, "typecheck" }, - { JITTIME_LOOP, "loop" }, - { JITTIME_IFCONV, "if conversion" }, - { JITTIME_ALLOC, "register allocation" }, - { JITTIME_RPLPOINTS, "replacement point generation" }, - { JITTIME_CODEGEN, "codegen" }, - { JITTIME_TOTAL, "total" }, - { 0, NULL } -}; - -static long long jit_time_sum[JITTIME_N] = { 0 }; - -static long jit_time_diff_usec(struct timespec *a,struct timespec *b) -{ - long diff; - time_t atime; - - diff = (b->tv_nsec - a->tv_nsec) / 1000; - atime = a->tv_sec; - while (atime < b->tv_sec) { - atime++; - diff += 1000000; - } - return diff; -} - -static void jit_time_diff(struct timespec *a,struct timespec *b,int index) -{ - long diff; - - diff = jit_time_diff_usec(a,b); - jit_time_sum[index] += diff; -} - -void jit_print_time_stats(FILE *file) -{ - struct jit_time_stat *stats; - double total; - - stats = jit_time_stat_defs; - total = jit_time_sum[JITTIME_TOTAL]; - while (stats->name) { - fprintf(file,"%12lld usec %3.0f%% %s\n", - jit_time_sum[stats->index], - (total != 0.0) ? jit_time_sum[stats->index] / total * 100.0 : 0.0, - stats->name); - stats++; - } -} - -#else /* !defined(ENABLE_RT_TIMING) */ - -#define JIT_GET_TIME(ts) - -#endif /* defined(ENABLE_RT_TIMING) */ - /* jit_compile_intern ********************************************************** Static internal function which does the actual compilation. @@ -1575,7 +1482,7 @@ static u1 *jit_compile_intern(jitdata *jd) time_rplpoints,time_codegen; #endif - JIT_GET_TIME(time_start); + RT_TIMING_GET_TIME(time_start); /* get required compiler data */ @@ -1633,7 +1540,7 @@ static u1 *jit_compile_intern(jitdata *jd) } #endif - JIT_GET_TIME(time_checks); + RT_TIMING_GET_TIME(time_checks); /* call the compiler passes ***********************************************/ @@ -1646,7 +1553,7 @@ static u1 *jit_compile_intern(jitdata *jd) return NULL; } - JIT_GET_TIME(time_parse); + RT_TIMING_GET_TIME(time_parse); DEBUG_JIT_COMPILEVERBOSE("Parsing done: "); DEBUG_JIT_COMPILEVERBOSE("Analysing: "); @@ -1658,7 +1565,7 @@ static u1 *jit_compile_intern(jitdata *jd) return NULL; } - JIT_GET_TIME(time_stack); + RT_TIMING_GET_TIME(time_stack); DEBUG_JIT_COMPILEVERBOSE("Analysing done: "); @@ -1676,7 +1583,7 @@ static u1 *jit_compile_intern(jitdata *jd) DEBUG_JIT_COMPILEVERBOSE("Typechecking done: "); } #endif - JIT_GET_TIME(time_typecheck); + RT_TIMING_GET_TIME(time_typecheck); #if defined(ENABLE_LOOP) if (opt_loops) { @@ -1685,14 +1592,14 @@ static u1 *jit_compile_intern(jitdata *jd) optimize_loops(jd); } #endif - JIT_GET_TIME(time_loop); + RT_TIMING_GET_TIME(time_loop); #if defined(ENABLE_IFCONV) if (jd->flags & JITDATA_FLAG_IFCONV) if (!ifconv_static(jd)) return NULL; #endif - JIT_GET_TIME(time_ifconv); + RT_TIMING_GET_TIME(time_ifconv); #if defined(ENABLE_JIT) # if defined(ENABLE_INTRP) @@ -1723,7 +1630,7 @@ static u1 *jit_compile_intern(jitdata *jd) } # endif #endif /* defined(ENABLE_JIT) */ - JIT_GET_TIME(time_alloc); + RT_TIMING_GET_TIME(time_alloc); /* Allocate memory for basic block profiling information. This _must_ be done after loop optimization and register allocation, @@ -1738,7 +1645,7 @@ static u1 *jit_compile_intern(jitdata *jd) if (!replace_create_replacement_points(jd)) return NULL; - JIT_GET_TIME(time_rplpoints); + RT_TIMING_GET_TIME(time_rplpoints); /* now generate the machine code */ @@ -1766,7 +1673,7 @@ static u1 *jit_compile_intern(jitdata *jd) return NULL; } #endif - JIT_GET_TIME(time_codegen); + RT_TIMING_GET_TIME(time_codegen); DEBUG_JIT_COMPILEVERBOSE("Generating code done: "); @@ -1800,15 +1707,15 @@ static u1 *jit_compile_intern(jitdata *jd) m->code = code; #if defined(ENABLE_RT_TIMING) - jit_time_diff(&time_start,&time_checks,JITTIME_CHECKS); - jit_time_diff(&time_checks,&time_parse,JITTIME_PARSE); - jit_time_diff(&time_parse,&time_stack,JITTIME_STACK); - jit_time_diff(&time_stack,&time_typecheck,JITTIME_TYPECHECK); - jit_time_diff(&time_typecheck,&time_loop,JITTIME_LOOP); - jit_time_diff(&time_loop,&time_alloc,JITTIME_ALLOC); - jit_time_diff(&time_alloc,&time_rplpoints,JITTIME_RPLPOINTS); - jit_time_diff(&time_rplpoints,&time_codegen,JITTIME_CODEGEN); - jit_time_diff(&time_start,&time_codegen,JITTIME_TOTAL); + rt_timing_time_diff(&time_start,&time_checks,RT_TIMING_JIT_CHECKS); + rt_timing_time_diff(&time_checks,&time_parse,RT_TIMING_JIT_PARSE); + rt_timing_time_diff(&time_parse,&time_stack,RT_TIMING_JIT_STACK); + rt_timing_time_diff(&time_stack,&time_typecheck,RT_TIMING_JIT_TYPECHECK); + rt_timing_time_diff(&time_typecheck,&time_loop,RT_TIMING_JIT_LOOP); + rt_timing_time_diff(&time_loop,&time_alloc,RT_TIMING_JIT_ALLOC); + rt_timing_time_diff(&time_alloc,&time_rplpoints,RT_TIMING_JIT_RPLPOINTS); + rt_timing_time_diff(&time_rplpoints,&time_codegen,RT_TIMING_JIT_CODEGEN); + rt_timing_time_diff(&time_start,&time_codegen,RT_TIMING_JIT_TOTAL); #endif /* return pointer to the methods entry point */ diff --git a/src/vm/jit/jit.h b/src/vm/jit/jit.h index 2a0ff3d70..73f879e01 100644 --- a/src/vm/jit/jit.h +++ b/src/vm/jit/jit.h @@ -30,7 +30,7 @@ Changes: Christian Thalinger Edwin Steiner - $Id: jit.h 4758 2006-04-12 17:51:10Z edwin $ + $Id: jit.h 4762 2006-04-12 22:20:49Z edwin $ */ @@ -1010,10 +1010,6 @@ void md_dcacheflush(u1 *addr, s4 nbytes); void intrp_md_init(void); #endif -#if defined(ENABLE_RT_TIMING) -void jit_print_time_stats(FILE *file); -#endif - #endif /* _JIT_H */ diff --git a/src/vm/rt-timing.c b/src/vm/rt-timing.c new file mode 100644 index 000000000..9d995915e --- /dev/null +++ b/src/vm/rt-timing.c @@ -0,0 +1,126 @@ +/* src/vm/rt-timing.c - POSIX real-time timing utilities + + Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel, + C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring, + E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, + J. Wenninger, Institut f. Computersprachen - TU Wien + + This file is part of CACAO. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Contact: cacao@cacaojvm.org + + Authors: Edwin Steiner + + Changes: + + $Id$ + +*/ + + +#include "config.h" +#include "vm/types.h" + +#include +#include +#include + +#include "vm/rt-timing.h" +#include "mm/memory.h" +#include "vm/global.h" + +struct rt_timing_stat { + int index; + const char *name; +}; + +static struct rt_timing_stat rt_timing_stat_defs[] = { + { RT_TIMING_CHECKS, "checks at beginning" }, + { RT_TIMING_PARSE, "parse" }, + { RT_TIMING_STACK, "analyse_stack" }, + { RT_TIMING_TYPECHECK, "typecheck" }, + { RT_TIMING_LOOP, "loop" }, + { RT_TIMING_IFCONV, "if conversion" }, + { RT_TIMING_ALLOC, "register allocation" }, + { RT_TIMING_RPLPOINTS, "replacement point generation" }, + { RT_TIMING_CODEGEN, "codegen" }, + { RT_TIMING_TOTAL, "total" }, + { 0, NULL } +}; + +static long long rt_timing_sum[RT_TIMING_N] = { 0 }; + +void rt_timing_gettime(struct timespec *ts) +{ + if (clock_gettime(CLOCK_THREAD_CPUTIME_ID,ts) != 0) { + fprintf(stderr,"could not get time by clock_gettime: %s\n",strerror(errno)); + abort(); + } +} + +static long rt_timing_diff_usec(struct timespec *a,struct timespec *b) +{ + long diff; + time_t atime; + + diff = (b->tv_nsec - a->tv_nsec) / 1000; + atime = a->tv_sec; + while (atime < b->tv_sec) { + atime++; + diff += 1000000; + } + return diff; +} + +void rt_timing_diff(struct timespec *a,struct timespec *b,int index) +{ + long diff; + + diff = rt_timing_diff_usec(a,b); + rt_timing_sum[index] += diff; +} + +void rt_timing_print_time_stats(FILE *file) +{ + struct rt_timing_stat *stats; + double total; + + stats = rt_timing_stat_defs; + total = rt_timing_sum[RT_TIMING_TOTAL]; + while (stats->name) { + fprintf(file,"%12lld usec %3.0f%% %s\n", + rt_timing_sum[stats->index], + (total != 0.0) ? rt_timing_sum[stats->index] / total * 100.0 : 0.0, + stats->name); + stats++; + } +} + +/* + * These are local overrides for various environment variables in Emacs. + * Please do not remove this and leave it at the end of the file, where + * Emacs will automagically detect them. + * --------------------------------------------------------------------- + * Local variables: + * mode: c + * indent-tabs-mode: t + * c-basic-offset: 4 + * tab-width: 4 + * End: + * vim:noexpandtab:sw=4:ts=4: + */ diff --git a/src/vm/rt-timing.h b/src/vm/rt-timing.h new file mode 100644 index 000000000..8564cc38e --- /dev/null +++ b/src/vm/rt-timing.h @@ -0,0 +1,87 @@ +/* src/vm/rt-timing.h - POSIX real-time timing utilities + + Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel, + C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring, + E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, + J. Wenninger, Institut f. Computersprachen - TU Wien + + This file is part of CACAO. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Contact: cacao@cacaojvm.org + + Authors: Edwin Steiner + + Changes: + + $Id$ + +*/ + +#ifndef _RT_TIMING_H +#define _RT_TIMING_H + +#if defined(ENABLE_RT_TIMING) + +#include "config.h" +#include "vm/types.h" + +#include + +#include "mm/memory.h" +#include "vm/global.h" + +#define RT_TIMING_GET_TIME(ts) \ + rt_timing_gettime(&(ts)); + +#define RT_TIMING_JIT_CHECKS 0 +#define RT_TIMING_JIT_PARSE 1 +#define RT_TIMING_JIT_STACK 2 +#define RT_TIMING_JIT_TYPECHECK 3 +#define RT_TIMING_JIT_LOOP 4 +#define RT_TIMING_JIT_IFCONV 5 +#define RT_TIMING_JIT_ALLOC 6 +#define RT_TIMING_JIT_RPLPOINTS 7 +#define RT_TIMING_JIT_CODEGEN 8 +#define RT_TIMING_JIT_TOTAL 9 +#define RT_TIMING_N 10 + +void rt_timing_diff(struct timespec *a,struct timespec *b,int index); + +void rt_timing_print_time_stats(FILE *file); + +#else /* !defined(ENABLE_RT_TIMING) */ + +#define RT_TIMING_GET_TIME(ts) + +#endif /* defined(ENABLE_RT_TIMING) */ + +#endif /* _RT_TIMING_H */ + +/* + * These are local overrides for various environment variables in Emacs. + * Please do not remove this and leave it at the end of the file, where + * Emacs will automagically detect them. + * --------------------------------------------------------------------- + * Local variables: + * mode: c + * indent-tabs-mode: t + * c-basic-offset: 4 + * tab-width: 4 + * End: + * vim:noexpandtab:sw=4:ts=4: + */ diff --git a/src/vm/vm.c b/src/vm/vm.c index dcb460d42..8067172b9 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -68,6 +68,7 @@ #include "vm/jit/jit.h" #include "vm/jit/asmpart.h" #include "vm/jit/profile/profile.h" +#include "vm/rt-timing.h" #if defined(ENABLE_JVMTI) #include "native/jvmti/cacaodbg.h" @@ -1339,7 +1340,7 @@ void vm_exit_handler(void) #endif #if defined(ENABLE_RT_TIMING) - jit_print_time_stats(stderr); + rt_timing_print_time_stats(stderr); #endif if (opt_verbose || getcompilingtime || opt_stat) { -- 2.25.1