OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 546 to Rev 547
    Reverse comparison

Rev 546 → Rev 547

/trunk/or1ksim/mprofiler.c
0,0 → 1,242
/* mprofiler.c -- memory profiling utility
Copyright (C) 2002 Marko Mlinar, markom@opencores.org
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
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 of the License, 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
/* Command line utility, that displays profiling information, generated
by or1ksim. (use --mprofile option at command line, when running or1ksim. */
 
#include <stdio.h>
#include <malloc.h>
#include "support/profile.h"
 
/* output modes */
#define MODE_DETAIL 0
#define MODE_PRETTY 1
#define MODE_ACCESS 2
#define MODE_WIDTH 3
 
/* Input buffer size */
#define BUF_SIZE 100
 
/* HASH */
#define HASH_SIZE 0x10000
#define HASH_FUNC(x) ((x) & 0xffff)
struct memory_hash {
struct memory_hash *next;
unsigned long addr;
unsigned long cnt[3]; /* Various counters */
} *hash[HASH_SIZE];
 
/* Groups size -- how much addresses should be joined together */
int group_bits = 2;
 
/* Start address */
int start_addr = 0;
 
/* End address */
int end_addr = 0xffffffff;
 
/* File to read from */
static FILE *fprof = 0;
 
void help ()
{
printf ("USAGE: mprofiler <-d|-p|-a|-w> [-f filename] [-g group] from to\n");
printf ("\t-d\t--detail\t\tdetailed output\n");
printf ("\t-p\t--pretty\t\tpretty output\n");
printf ("\t-a\t--access\t\toutput accesses only\n");
printf ("\t-w\t--width\t\t\toutput by width\n");
printf ("\t-f\t--filename filename\tspecify mprofile file [sim.mprofile]\n");
printf ("\t-g\t--group bits\t\tgroup 2^bits successive\n");
printf ("\t\t\t\t\taddresses together [2]\n");
printf ("\t-h\t--help\t\t\toutput this screen\n");
}
 
void hash_add (unsigned long addr, int index)
{
struct memory_hash *h = hash[HASH_FUNC(addr)];
while (h && h->addr != addr) h = h->next;
if (!h) {
h = (struct memory_hash *)malloc (sizeof (struct memory_hash));
h->next = hash[HASH_FUNC(addr)];
hash[HASH_FUNC(addr)] = h;
h->addr = addr;
h->cnt[0] = h->cnt[1] = h->cnt[2] = 0;
}
h->cnt[index]++;
}
 
unsigned long hash_get (unsigned long addr, int index)
{
struct memory_hash *h = hash[HASH_FUNC(addr)];
while (h && h->addr != addr) h = h->next;
if (!h) return 0;
return h->cnt[index];
}
 
void init ()
{
int i;
for (i = 0; i < HASH_SIZE; i++)
hash[i] = NULL;
}
 
void read_file (FILE *f, int mode)
{
struct mprofentry_struct buf[BUF_SIZE];
int num_read;
do {
int i;
num_read = fread (buf, sizeof (struct mprofentry_struct), BUF_SIZE, f);
for (i = 0; i < num_read; i++) if (buf[i].addr >= start_addr && buf[i].addr <= end_addr) {
int index;
if (mode != MODE_WIDTH) buf[i].type >>= 3;
else buf[i].type &= 0x7;
switch (buf[i].type) {
case 1: index = 0; break;
case 2: index = 1; break;
case 4: index = 2; break;
}
hash_add (buf[i].addr >> group_bits, index);
}
} while (num_read > 0);
}
 
static inline int nbits (unsigned long a)
{
int cnt = 0;
int b = a;
if (!a) return 0;
while (a) a >>= 1, cnt++;
if (cnt > 1 && ((b >> (cnt - 2)) & 1))
cnt = cnt * 2 + 1;
else
cnt *= 2;
return cnt - 1;
}
 
void printout (int mode)
{
unsigned long addr = start_addr & ~((1 << group_bits) - 1);
printf ("%08x %08x %08x %08x %i\n", start_addr, end_addr, addr, group_bits, mode);
for (; addr <= end_addr; addr += (1 << group_bits)) {
int i;
unsigned long a = hash_get (addr >> group_bits, 0);
unsigned long b = hash_get (addr >> group_bits, 1);
unsigned long c = hash_get (addr >> group_bits, 2);
printf ("%08x:", addr);
switch (mode) {
case MODE_DETAIL:
if (a) printf (" %10i R", a);
else printf (" R");
if (b) printf (" %10i W", b);
else printf (" W");
if (c) printf (" %10i F", c);
else printf (" F");
break;
case MODE_ACCESS:
printf (" %10i", a + b + c);
break;
case MODE_PRETTY:
printf (" %10i ", a + b + c);
for (i = 0; i < nbits (a + b + c); i++)
printf ("#");
#if 0
for (; i < 64; i++)
printf (".");
#endif
break;
case MODE_WIDTH:
if (a) printf (" %10i B", a);
else printf (" B");
if (b) printf (" %10i H", b);
else printf (" H");
if (c) printf (" %10i W", c);
else printf (" W");
break;
}
printf ("\n");
}
}
 
int main (int argc, char *argv[])
{
char fmprofname[50] = "sim.mprofile";
int param = 0;
int mode = MODE_DETAIL;
 
argv++; argc--;
while (argc > 0) {
if (!strcmp(argv[0], "-d") || !strcmp(argv[0], "--detail")) {
mode = MODE_DETAIL;
argv++; argc--;
} else if (!strcmp(argv[0], "-p") || !strcmp(argv[0], "--pretty")) {
mode = MODE_PRETTY;
argv++; argc--;
} else if (!strcmp(argv[0], "-a") || !strcmp(argv[0], "--access")) {
mode = MODE_ACCESS;
argv++; argc--;
} else if (!strcmp(argv[0], "-w") || !strcmp(argv[0], "--width")) {
mode = MODE_WIDTH;
argv++; argc--;
} else if (!strcmp(argv[0], "-g") || !strcmp(argv[0], "--group")) {
argv++; argc--;
group_bits = strtoul (argv[0], NULL, 0);
argv++; argc--;
} else if (!strcmp(argv[0], "-h") || !strcmp(argv[0], "--help")) {
help ();
exit (0);
} else if (!strcmp(argv[0], "-f") || !strcmp(argv[0], "--filename")) {
argv++; argc--;
strcpy (&fmprofname[0], argv[0]);
argv++; argc--;
} else {
printf (": %s", argv[0]);
switch (param) {
case 0:
start_addr = strtoul (argv[0], NULL, 0);
break;
case 1:
end_addr = strtoul (argv[0], NULL, 0);
break;
default:
fprintf (stderr, "Invalid number of parameters.\n");
exit (-1);
}
argv++; argc--; param++;
}
}
 
fprof = fopen (&fmprofname[0], "rm");
 
if (!fprof) {
fprintf (stderr, "Cannot open profile file: %s\n", &fmprofname[0]);
exit(1);
}
init ();
read_file (fprof, mode);
fclose (fprof);
printout (mode);
return 0;
}
trunk/or1ksim/mprofiler.c Property changes : Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Index: trunk/or1ksim/sim-config.h =================================================================== --- trunk/or1ksim/sim-config.h (revision 546) +++ trunk/or1ksim/sim-config.h (revision 547) @@ -175,6 +175,9 @@ int profile; /* Is profiler running */ char prof_fn[STR_SIZE]; /* Profiler filename */ + + int mprofile; /* Is memory profiler running */ + char mprof_fn[STR_SIZE];/* Memory profiler filename */ int history; /* instruction stream history analysis */ int exe_log; /* Print out RTL states? */ @@ -201,6 +204,7 @@ struct runtime { struct { FILE *fprof; /* Profiler file */ + FILE *fmprof; /* Memory profiler file */ FILE *fexe_log; /* RTL state comparison file */ int init; /* Whether we are still initilizing sim */ int script_file_specified;/* Whether script file was already loaded */
/trunk/or1ksim/Makefile.in
93,7 → 93,7
SUBDIRS = cpu bpb support cache mmu peripheral tick pm pic debug vapi
 
bin_PROGRAMS = sim
EXTRA_PROGRAMS = profiler
EXTRA_PROGRAMS = profiler mprofiler
 
sim_SOURCES = toplevel.c sim-config.c
sim_LDADD = cpu/common/libcommon.a cpu/$(CPU_ARCH)/libarch.a cpu/or1k/libor1k.a support/libsupport.a mmu/libmmu.a bpb/libbpb.a cache/libcache.a peripheral/libperipheral.a tick/libtick.a pm/libpm.a pic/libpic.a debug/libdebug.a vapi/libvapi.a
100,6 → 100,7
 
sim_LDFLAGS = #-lreadline
profiler_SOURCES = profiler.c
mprofiler_SOURCES = mprofiler.c
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = config.h
115,6 → 116,10
profiler_LDADD = $(LDADD)
profiler_DEPENDENCIES =
profiler_LDFLAGS =
mprofiler_OBJECTS = mprofiler.o
mprofiler_LDADD = $(LDADD)
mprofiler_DEPENDENCIES =
mprofiler_LDFLAGS =
sim_OBJECTS = toplevel.o sim-config.o
sim_DEPENDENCIES = cpu/common/libcommon.a cpu/$(CPU_ARCH)/libarch.a \
cpu/or1k/libor1k.a support/libsupport.a mmu/libmmu.a bpb/libbpb.a \
133,9 → 138,10
 
TAR = gtar
GZIP_ENV = --best
DEP_FILES = .deps/profiler.P .deps/sim-config.P .deps/toplevel.P
SOURCES = $(profiler_SOURCES) $(sim_SOURCES)
OBJECTS = $(profiler_OBJECTS) $(sim_OBJECTS)
DEP_FILES = .deps/mprofiler.P .deps/profiler.P .deps/sim-config.P \
.deps/toplevel.P
SOURCES = $(profiler_SOURCES) $(mprofiler_SOURCES) $(sim_SOURCES)
OBJECTS = $(profiler_OBJECTS) $(mprofiler_OBJECTS) $(sim_OBJECTS)
 
all: all-redirect
.SUFFIXES:
228,6 → 234,10
@rm -f profiler
$(LINK) $(profiler_LDFLAGS) $(profiler_OBJECTS) $(profiler_LDADD) $(LIBS)
 
mprofiler: $(mprofiler_OBJECTS) $(mprofiler_DEPENDENCIES)
@rm -f mprofiler
$(LINK) $(mprofiler_LDFLAGS) $(mprofiler_OBJECTS) $(mprofiler_LDADD) $(LIBS)
 
sim: $(sim_OBJECTS) $(sim_DEPENDENCIES)
@rm -f sim
$(LINK) $(sim_LDFLAGS) $(sim_OBJECTS) $(sim_LDADD) $(LIBS)
/trunk/or1ksim/sim.cfg
302,7 → 302,14
prof_fn = "<filename>"
filename, where to generate profiling info, used
only if 'profile' is set
mprofile = 0/1
whether to generate memory profiling file 'sim.mprofile'
 
mprof_fn = "<filename>"
filename, where to generate memory profiling info, used
only if 'mprofile' is set
 
history = 0/1
whether instruction execution flow is tracked for
display by simulator hist command. Useful for
327,6 → 334,8
debug = 0
profile = 0
prof_fn = "sim.profile"
mprofile = 0
mprof_fn = "sim.mprofile"
 
history = 1
/* iprompt = 0 */
/trunk/or1ksim/cpu/common/abstract.c
39,6 → 39,7
#include "except.h"
#include "debug_unit.h"
#include "opcode/or32.h"
#include "support/profile.h"
 
extern unsigned long reg[];
extern char *disassembled;
255,6 → 256,9
unsigned long temp;
struct dev_memarea *dev;
 
if (config.sim.mprofile)
mprofile (memaddr, MPROF_32 | MPROF_READ);
 
cur_vadd = memaddr;
memaddr = simulate_dc_mmu_load(memaddr);
if (pending.valid)
279,6 → 283,8
unsigned long temp;
struct dev_memarea *dev;
 
if (config.sim.mprofile)
mprofile (memaddr, MPROF_32 | MPROF_FETCH);
// memaddr = simulate_ic_mmu_fetch(memaddr);
cur_vadd = pc;
ic_simulate_fetch(memaddr);
328,6 → 334,10
unsigned short eval_mem16(unsigned long memaddr,int* breakpoint)
{
unsigned short temp;
if (config.sim.mprofile)
mprofile (memaddr, MPROF_16 | MPROF_READ);
 
cur_vadd = memaddr;
memaddr = simulate_dc_mmu_load(memaddr);
if (pending.valid)
386,6 → 396,10
unsigned char eval_mem8(unsigned long memaddr,int* breakpoint)
{
unsigned long temp;
 
if (config.sim.mprofile)
mprofile (memaddr, MPROF_8 | MPROF_READ);
 
cur_vadd = memaddr;
memaddr = simulate_dc_mmu_load(memaddr);
if (pending.valid)
436,6 → 450,10
 
void set_mem32(unsigned long memaddr, unsigned long value,int* breakpoint)
{
 
if (config.sim.mprofile)
mprofile (memaddr, MPROF_32 | MPROF_WRITE);
cur_vadd = memaddr;
memaddr = simulate_dc_mmu_store(memaddr);
 
491,6 → 509,9
 
void set_mem16(unsigned long memaddr, unsigned short value,int* breakpoint)
{
if (config.sim.mprofile)
mprofile (memaddr, MPROF_16 | MPROF_WRITE);
cur_vadd = memaddr;
memaddr = simulate_dc_mmu_store(memaddr);
 
544,6 → 565,9
 
void set_mem8(unsigned long memaddr, unsigned char value,int* breakpoint)
{
if (config.sim.mprofile)
mprofile (memaddr, MPROF_8 | MPROF_WRITE);
cur_vadd = memaddr;
memaddr = simulate_dc_mmu_store(memaddr);
 
/trunk/or1ksim/profiler.c
1,6 → 1,24
/* profiler.c -- profiling utility
Copyright (C) 2001 Marko Mlinar, markom@opencores.org
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
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 of the License, 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
/* Command line utility, that displays profiling information, generated
by or1ksim. (use -profile option at command line, when running or1ksim.
GNU License (C) Marko Mlinar 2001. */
by or1ksim. (use --profile option at command line, when running or1ksim. */
 
#include <stdio.h>
 
/trunk/or1ksim/Makefile.am
7,7 → 7,7
SUBDIRS = cpu bpb support cache mmu peripheral tick pm pic debug vapi
 
bin_PROGRAMS = sim
EXTRA_PROGRAMS = profiler
EXTRA_PROGRAMS = profiler mprofiler
 
sim_SOURCES = toplevel.c sim-config.c
sim_LDADD = cpu/common/libcommon.a cpu/$(CPU_ARCH)/libarch.a \
17,3 → 17,4
vapi/libvapi.a
sim_LDFLAGS = #-lreadline
profiler_SOURCES = profiler.c
mprofiler_SOURCES = mprofiler.c
/trunk/or1ksim/toplevel.c
51,7 → 51,7
#include "coff.h"
 
/* CVS revision number. */
const char rcsrev[] = "$Revision: 1.62 $";
const char rcsrev[] = "$Revision: 1.63 $";
 
/* Continuos run versus single step tracing switch. */
int cont_run;
182,6 → 182,14
fprintf(runtime.sim.fprof, "+00000000 FFFFFFFF FFFFFFFF main\n");
}
if (config.sim.mprofile) {
runtime.sim.fmprof = fopen(config.sim.mprof_fn, "wb+");
if(!runtime.sim.fmprof) {
config.sim.mprofile = 0;
fprintf(stderr, "WARNING: Problems opening memory profile file. Memory profiling disabled. \n");
}
}
if (config.sim.exe_log) {
runtime.sim.fexe_log = fopen(config.sim.exe_log_fn, "wt+");
if(!runtime.sim.fexe_log) {
309,6 → 317,10
fprintf(runtime.sim.fprof,"-%08X FFFFFFFF\n", cycles);
fclose(runtime.sim.fprof);
}
if (config.sim.mprofile)
fclose(runtime.sim.fmprof);
 
if (config.sim.exe_log) fclose(runtime.sim.fexe_log);
if (config.vapi.enabled) vapi_done ();
done_memory_table ();
336,6 → 348,7
printf(" --nosrv do not launch JTAG proxy server\n"); /* (CZ) */
printf(" --srv <n> launch JTAG proxy server on port <n>; [random]\n"); /* (CZ) */
printf(" --profile enable profiling\n");
printf(" --mprofile enable memory profiling\n");
exit(-1);
}
 
/trunk/or1ksim/sim-config.c
60,6 → 60,8
config.sim.profile = 0;
runtime.sim.fprof = NULL;
strcpy (config.sim.prof_fn, "sim.profile");
runtime.sim.fmprof = NULL;
strcpy (config.sim.mprof_fn, "sim.mprofile");
runtime.sim.init = 1;
runtime.sim.script_file_specified = 0;
config.sim.clkcycle_ps = 4000; /* 4000 for 4ns (250MHz) */
179,6 → 181,10
if (strcmp(*argv, "--profile") == 0) {
config.sim.profile = 1;
argv++; argc--;
} else
if (strcmp(*argv, "--mprofile") == 0) {
config.sim.mprofile = 1;
argv++; argc--;
} else {
fprintf(stderr, "Unknown option: %s\n", *argv);
return 1;
435,6 → 441,8
{6, 0, "verbose", "=%i", NULL, (void *)(&config.sim.verbose)},
{6, 0, "profile", "=%i", NULL, (void *)(&config.sim.profile)},
{6, 0, "prof_fn", "=\"%s\"", NULL, (void *)(&config.sim.prof_fn[0])},
{6, 0, "mprofile", "=%i", NULL, (void *)(&config.sim.mprofile)},
{6, 0, "mprof_fn", "=\"%s\"", NULL, (void *)(&config.sim.mprof_fn[0])},
{6, 0, "history", "=%i", NULL, (void *)(&config.sim.history)},
{6, 0, "exe_log", "=%i", NULL, (void *)(&config.sim.exe_log)},
{6, 0, "exe_log_fn", "=\"%s\"", NULL, (void *)(&config.sim.exe_log_fn[0])},
/trunk/or1ksim/support/profile.c
0,0 → 1,32
/* profile.c -- functions for profiling
Copyright (C) 2002 Marko Mlinar, markom@opencores.org
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
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 of the License, 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
#include <stdio.h>
#include "profile.h"
#include "sim-config.h"
 
/* Adds a new entry to the memory profile file */
void mprofile (unsigned long memaddr, unsigned char type)
{
struct mprofentry_struct mp;
mp.addr = memaddr;
mp.type = type;
if(!fwrite (&mp, sizeof (struct mprofentry_struct), 1, runtime.sim.fmprof))
config.sim.mprofile = 0;
}
trunk/or1ksim/support/profile.c Property changes : Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Index: trunk/or1ksim/support/Makefile.in =================================================================== --- trunk/or1ksim/support/Makefile.in (revision 546) +++ trunk/or1ksim/support/Makefile.in (revision 547) @@ -105,7 +105,7 @@ host_os = @host_os@ noinst_LIBRARIES = libsupport.a -libsupport_a_SOURCES = simprintf.c dumpverilog.c +libsupport_a_SOURCES = simprintf.c dumpverilog.c profile.c mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = ../config.h CONFIG_CLEAN_FILES = @@ -117,7 +117,7 @@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ libsupport_a_LIBADD = -libsupport_a_OBJECTS = simprintf.o dumpverilog.o +libsupport_a_OBJECTS = simprintf.o dumpverilog.o profile.o COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ @@ -128,7 +128,7 @@ TAR = gtar GZIP_ENV = --best -DEP_FILES = .deps/dumpverilog.P .deps/simprintf.P +DEP_FILES = .deps/dumpverilog.P .deps/profile.P .deps/simprintf.P SOURCES = $(libsupport_a_SOURCES) OBJECTS = $(libsupport_a_OBJECTS)
/trunk/or1ksim/support/profile.h
0,0 → 1,33
/* profile.c -- definitions for profiling
Copyright (C) 2002 Marko Mlinar, markom@opencores.org
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
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 of the License, 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
#define MPROF_READ 1
#define MPROF_WRITE 2
#define MPROF_FETCH 4
#define MPROF_8 8
#define MPROF_16 16
#define MPROF_32 32
 
/* Adds a new entry to the memory profile file */
void mprofile (unsigned long memaddr, unsigned char type);
 
struct mprofentry_struct {
unsigned long addr;
unsigned char type;
};
trunk/or1ksim/support/profile.h Property changes : Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Index: trunk/or1ksim/support/Makefile.am =================================================================== --- trunk/or1ksim/support/Makefile.am (revision 546) +++ trunk/or1ksim/support/Makefile.am (revision 547) @@ -19,4 +19,4 @@ # noinst_LIBRARIES = libsupport.a -libsupport_a_SOURCES = simprintf.c dumpverilog.c +libsupport_a_SOURCES = simprintf.c dumpverilog.c profile.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.