Skip to content

Commit

Permalink
Merge pull request #34 from gstrauss/Makefile-modernization
Browse files Browse the repository at this point in the history
Makefile modernization. Looks good. Let's merge and see if anyone finds issues they cannot resolve.
  • Loading branch information
kdlucas committed May 1, 2016
2 parents e80d3f3 + 274c178 commit c22488d
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 113 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UnixBench/pgms
UnixBench/results
UnixBench/tmp
151 changes: 92 additions & 59 deletions UnixBench/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
# 09/30/07 adding ubgears, GRAPHIC_TESTS switch
# 10/14/07 adding large.txt
# 01/13/11 added support for parallel compilation
# 01/07/16 [refer to version control commit messages and
# cease using two-digit years in date formats]
##############################################################################

##############################################################################
Expand All @@ -39,9 +41,9 @@

SHELL = /bin/sh

# GRAPHICS TESTS: Uncomment the definition of "GRAPHIC_TESTS" to enable
# GRAPHIC TESTS: Uncomment the definition of "GRAPHIC_TESTS" to enable
# the building of the graphics benchmarks. This will require the
# X11 libraries on your system.
# X11 libraries on your system. (e.g. libX11-devel mesa-libGL-devel)
#
# Comment the line out to disable these tests.
# GRAPHIC_TESTS = defined
Expand Down Expand Up @@ -71,14 +73,33 @@ CC=gcc
# -m386 -malign-loops=1 -malign-jumps=1 -malign-functions=1

## For Solaris 2, or general-purpose GCC 2.7.x
OPTON = -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall
#OPTON = -O2 -fomit-frame-pointer -fforce-addr -ffast-math -Wall

## For Digital Unix v4.x, with DEC cc v5.x
#OPTON = -O4
#CFLAGS = -DTIME -std1 -verbose -w0

## gcc optimization flags
## (-ffast-math) disables strict IEEE or ISO rules/specifications for math funcs
OPTON = -O3 -ffast-math

## OS detection. Comment out if gmake syntax not supported by other 'make'.
OSNAME:=$(shell uname -s)

ifeq ($(OSNAME),Linux)
OPTON += -march=native -mtune=native
endif
ifeq ($(OSNAME),Darwin)
# (adjust flags or comment out this section for older versions of XCode or OS X)
# (-mmacosx-versin-min= requires at least that version of SDK be installed)
OPTON += -march=native -mmacosx-version-min=10.10
#http://stackoverflow.com/questions/9840207/how-to-use-avx-pclmulqdq-on-mac-os-x-lion/19342603#19342603
CFLAGS += -Wa,-q
endif


## generic gcc CFLAGS. -DTIME must be included.
CFLAGS = -DTIME -Wall -pedantic -ansi
CFLAGS = -Wall -pedantic $(OPTON) -I $(SRCDIR) -DTIME


##############################################################################
Expand All @@ -104,7 +125,7 @@ SOURCES = arith.c big.c context1.c \
dhry_1.c dhry_2.c dhry.h whets.c ubgears.c
TESTS = sort.src cctest.c dc.dat large.txt

ifdef GRAPHIC_TESTS
ifneq (,$(GRAPHIC_TESTS))
GRAPHIC_BINS = $(PROGDIR)/ubgears
else
GRAPHIC_BINS =
Expand All @@ -128,13 +149,15 @@ REQD = $(BINS) $(PROGDIR)/unixbench.logo \
$(TESTDIR)/large.txt

# ######################### the big ALL ############################
all: distr programs
all:
## Ick!!! What is this about??? How about let's not chmod everything bogusly.
# @chmod 744 * $(SRCDIR)/* $(PROGDIR)/* $(TESTDIR)/* $(DOCDIR)/*
$(MAKE) distr
$(MAKE) programs

# ####################### a check for Run ######################
check: $(REQD)
make all
$(MAKE) all
# ##############################################################
# distribute the files out to subdirectories if they are in this one
distr:
Expand Down Expand Up @@ -178,76 +201,86 @@ distr:
echo "$(RESULTDIR) exists" \
; fi

.PHONY: all check distr programs run clean spotless

programs: $(BINS)

# (use $< to link only the first dependency, instead of $^,
# since the programs matching this pattern have only
# one input file, and others are #include "xxx.c"
# within the first. (not condoning, just documenting))
# (dependencies could be generated by modern compilers,
# but let's not assume modern compilers are present)
$(PROGDIR)/%:
$(CC) -o $@ $(CFLAGS) $< $(LDFLAGS)

# Individual programs
$(PROGDIR)/arithoh: $(SRCDIR)/arith.c
$(CC) -o $(PROGDIR)/arithoh ${CFLAGS} ${OPTON} -Darithoh $(SRCDIR)/arith.c
$(PROGDIR)/register: $(SRCDIR)/arith.c
$(CC) -o $(PROGDIR)/register ${CFLAGS} ${OPTON} -Ddatum='register int' $(SRCDIR)/arith.c
$(PROGDIR)/short: $(SRCDIR)/arith.c
$(CC) -o $(PROGDIR)/short ${CFLAGS} ${OPTON} -Ddatum=short $(SRCDIR)/arith.c
$(PROGDIR)/int: $(SRCDIR)/arith.c
$(CC) -o $(PROGDIR)/int ${CFLAGS} ${OPTON} -Ddatum=int $(SRCDIR)/arith.c
$(PROGDIR)/long: $(SRCDIR)/arith.c
$(CC) -o $(PROGDIR)/long ${CFLAGS} ${OPTON} -Ddatum=long $(SRCDIR)/arith.c
$(PROGDIR)/float: $(SRCDIR)/arith.c
$(CC) -o $(PROGDIR)/float ${CFLAGS} ${OPTON} -Ddatum=float $(SRCDIR)/arith.c
$(PROGDIR)/double: $(SRCDIR)/arith.c
$(CC) -o $(PROGDIR)/double ${CFLAGS} ${OPTON} -Ddatum=double $(SRCDIR)/arith.c
# Sometimes the same source file is compiled in different ways.
# This limits the 'make' patterns that can usefully be applied.

$(PROGDIR)/arithoh: $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
$(PROGDIR)/arithoh: CFLAGS += -Darithoh
$(PROGDIR)/register: $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
$(PROGDIR)/register: CFLAGS += -Ddatum='register int'
$(PROGDIR)/short: $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
$(PROGDIR)/short: CFLAGS += -Ddatum=short
$(PROGDIR)/int: $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
$(PROGDIR)/int: CFLAGS += -Ddatum=int
$(PROGDIR)/long: $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
$(PROGDIR)/long: CFLAGS += -Ddatum=long
$(PROGDIR)/float: $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
$(PROGDIR)/float: CFLAGS += -Ddatum=float
$(PROGDIR)/double: $(SRCDIR)/arith.c $(SRCDIR)/timeit.c
$(PROGDIR)/double: CFLAGS += -Ddatum=double

$(PROGDIR)/poll: $(SRCDIR)/time-polling.c
$(PROGDIR)/poll: CFLAGS += -DUNIXBENCH -DHAS_POLL
$(PROGDIR)/poll2: $(SRCDIR)/time-polling.c
$(PROGDIR)/poll2: CFLAGS += -DUNIXBENCH -DHAS_POLL2
$(PROGDIR)/select: $(SRCDIR)/time-polling.c
$(PROGDIR)/select: CFLAGS += -DUNIXBENCH -DHAS_SELECT

$(PROGDIR)/whetstone-double: $(SRCDIR)/whets.c
$(CC) -o $(PROGDIR)/whetstone-double ${CFLAGS} ${OPTON} -DDP -DUNIX -DUNIXBENCH $(SRCDIR)/whets.c -lm
$(PROGDIR)/hanoi: $(SRCDIR)/hanoi.c
$(CC) -o $(PROGDIR)/hanoi ${CFLAGS} ${OPTON} $(SRCDIR)/hanoi.c
$(PROGDIR)/whetstone-double: CFLAGS += -DDP -DUNIX -DUNIXBENCH
$(PROGDIR)/whetstone-double: LDFLAGS += -lm

$(PROGDIR)/poll: $(SRCDIR)/time-polling.c
$(CC) -DHAS_POLL -DUNIXBENCH -o $(PROGDIR)/poll ${CFLAGS} ${OPTON} $(SRCDIR)/time-polling.c
$(PROGDIR)/pipe: $(SRCDIR)/pipe.c $(SRCDIR)/timeit.c

$(PROGDIR)/poll2: $(SRCDIR)/time-polling.c
$(CC) -DHAS_POLL2 -DUNIXBENCH -o $(PROGDIR)/poll2 ${CFLAGS} ${OPTON} $(SRCDIR)/time-polling.c
$(PROGDIR)/execl: $(SRCDIR)/execl.c $(SRCDIR)/big.c

$(PROGDIR)/spawn: $(SRCDIR)/spawn.c $(SRCDIR)/timeit.c

$(PROGDIR)/select: $(SRCDIR)/time-polling.c
$(CC) -DHAS_SELECT -DUNIXBENCH -o $(PROGDIR)/select ${CFLAGS} ${OPTON} $(SRCDIR)/time-polling.c
$(PROGDIR)/hanoi: $(SRCDIR)/hanoi.c $(SRCDIR)/timeit.c

$(PROGDIR)/fstime: $(SRCDIR)/fstime.c
$(CC) -o $(PROGDIR)/fstime ${CFLAGS} ${OPTON} $(SRCDIR)/fstime.c

$(PROGDIR)/syscall: $(SRCDIR)/syscall.c
$(CC) -o $(PROGDIR)/syscall ${CFLAGS} ${OPTON} $(SRCDIR)/syscall.c
$(PROGDIR)/context1: $(SRCDIR)/context1.c
$(CC) -o $(PROGDIR)/context1 ${CFLAGS} ${OPTON} $(SRCDIR)/context1.c
$(PROGDIR)/pipe: $(SRCDIR)/pipe.c
$(CC) -o $(PROGDIR)/pipe ${CFLAGS} ${OPTON} $(SRCDIR)/pipe.c
$(PROGDIR)/spawn: $(SRCDIR)/spawn.c
$(CC) -o $(PROGDIR)/spawn ${CFLAGS} ${OPTON} $(SRCDIR)/spawn.c
$(PROGDIR)/execl: $(SRCDIR)/execl.c $(SRCDIR)/big.c
$(CC) -o $(PROGDIR)/execl ${CFLAGS} ${OPTON} $(SRCDIR)/execl.c

$(PROGDIR)/dhry2: $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c $(SRCDIR)/dhry.h
cd $(SRCDIR); $(CC) -c ${CFLAGS} -DHZ=${HZ} ${OPTON} dhry_1.c
cd $(SRCDIR); $(CC) -c ${CFLAGS} -DHZ=${HZ} ${OPTON} dhry_2.c
$(CC) -o $(PROGDIR)/dhry2 ${CFLAGS} ${OPTON} $(SRCDIR)/dhry_1.o $(SRCDIR)/dhry_2.o
cd $(SRCDIR); rm -f dhry_1.o dhry_2.o
$(PROGDIR)/dhry2reg: $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c $(SRCDIR)/dhry.h
cd $(SRCDIR); $(CC) -c ${CFLAGS} -DREG=register -DHZ=${HZ} ${OPTON} dhry_1.c -o dhry_1_reg.o
cd $(SRCDIR); $(CC) -c ${CFLAGS} -DREG=register -DHZ=${HZ} ${OPTON} dhry_2.c -o dhry_2_reg.o
$(CC) -o $(PROGDIR)/dhry2reg ${CFLAGS} ${OPTON} $(SRCDIR)/dhry_1_reg.o $(SRCDIR)/dhry_2_reg.o
cd $(SRCDIR); rm -f dhry_1_reg.o dhry_2_reg.o

$(PROGDIR)/looper: $(SRCDIR)/looper.c
$(CC) -o $(PROGDIR)/looper ${CFLAGS} ${OPTON} $(SRCDIR)/looper.c

$(PROGDIR)/syscall: $(SRCDIR)/syscall.c $(SRCDIR)/timeit.c

$(PROGDIR)/context1: $(SRCDIR)/context1.c $(SRCDIR)/timeit.c

$(PROGDIR)/looper: $(SRCDIR)/looper.c $(SRCDIR)/timeit.c

$(PROGDIR)/ubgears: $(SRCDIR)/ubgears.c
$(CC) -o $(PROGDIR)/ubgears ${CFLAGS} ${OPTON} $(SRCDIR)/ubgears.c $(GL_LIBS)
$(PROGDIR)/ubgears: LDFLAGS += -lm $(GL_LIBS)

$(PROGDIR)/dhry2: CFLAGS += -DHZ=${HZ}
$(PROGDIR)/dhry2: $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c \
$(SRCDIR)/dhry.h $(SRCDIR)/timeit.c
$(CC) -o $@ ${CFLAGS} $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c

$(PROGDIR)/dhry2reg: CFLAGS += -DHZ=${HZ} -DREG=register
$(PROGDIR)/dhry2reg: $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c \
$(SRCDIR)/dhry.h $(SRCDIR)/timeit.c
$(CC) -o $@ ${CFLAGS} $(SRCDIR)/dhry_1.c $(SRCDIR)/dhry_2.c

# Run the benchmarks and create the reports
run:
sh ./Run

clean:
rm -f $(BINS) core *~ */*~
$(RM) $(BINS) core *~ */*~

spotless: clean
rm -f $(RESULTDIR)/* $(TMPDIR)/*
$(RM) $(RESULTDIR)/* $(TMPDIR)/*

## END ##
66 changes: 42 additions & 24 deletions UnixBench/Run
Original file line number Diff line number Diff line change
Expand Up @@ -672,30 +672,48 @@ sub processCpuFlags {
# these fields:
# describing the model etc. Returns undef if the information can't be got.
sub getCpuInfo {
open(my $fd, "<", "/proc/cpuinfo") || return undef;
if (!("$^O" eq "darwin")) {
open(my $fd, "<", "/proc/cpuinfo") || return undef;

my $cpus = [ ];
my $cpu = 0;
while (<$fd>) {
chomp;
my ( $field, $val ) = split(/[ \t]*:[ \t]*/);
next if (!$field || !$val);
if ($field eq "processor") {
$cpu = $val;
} elsif ($field eq "model name") {
my $model = $val;
$model =~ s/ +/ /g;
$cpus->[$cpu]{'model'} = $model;
} elsif ($field eq "bogomips") {
$cpus->[$cpu]{'bogo'} = $val;
} elsif ($field eq "flags") {
$cpus->[$cpu]{'flags'} = processCpuFlags($val);
}
}

my $cpus = [ ];
my $cpu = 0;
while (<$fd>) {
chomp;
my ( $field, $val ) = split(/[ \t]*:[ \t]*/);
next if (!$field || !$val);
if ($field eq "processor") {
$cpu = $val;
} elsif ($field eq "model name") {
my $model = $val;
$model =~ s/ +/ /g;
close($fd);

$cpus;

} else {

my $model = getCmdOutput("sysctl -n machdep.cpu.brand_string");
my $flags = getCmdOutput("sysctl -n machdep.cpu.features | tr [A-Z] [a-z]");
my $ncpu = getCmdOutput("sysctl -n hw.ncpu");

my $cpus = [ ];
my $cpu = 0;

for ($cpu = 0; $cpu < $ncpu; $cpu++) {
$cpus->[$cpu]{'model'} = $model;
} elsif ($field eq "bogomips") {
$cpus->[$cpu]{'bogo'} = $val;
} elsif ($field eq "flags") {
$cpus->[$cpu]{'flags'} = processCpuFlags($val);
$cpus->[$cpu]{'bogo'} = 0;
$cpus->[$cpu]{'flags'} = processCpuFlags($flags);
}
$cpus;
}

close($fd);

$cpus;
}


Expand Down Expand Up @@ -723,7 +741,7 @@ sub getSystemInfo {
$info->{'osRel'} = getCmdOutput("uname -r");
$info->{'osVer'} = getCmdOutput("uname -v");
$info->{'mach'} = getCmdOutput("uname -m");
$info->{'platform'} = getCmdOutput("uname -i");
$info->{'platform'} = getCmdOutput("uname -i") || "unknown";

# Get the system name (SUSE, Red Hat, etc.) if possible.
$info->{'system'} = $info->{'os'};
Expand All @@ -735,9 +753,9 @@ sub getSystemInfo {

# Get the language info.
my $lang = getCmdOutput("printenv LANG");
my $map = getCmdOutput("locale -k LC_CTYPE | grep charmap");
my $map = getCmdOutput("locale -k LC_CTYPE | grep charmap") || "";
$map =~ s/.*=//;
my $coll = getCmdOutput("locale -k LC_COLLATE | grep collate-codeset");
my $coll = getCmdOutput("locale -k LC_COLLATE | grep collate-codeset") || "";
$coll =~ s/.*=//;
$info->{'language'} = sprintf "%s (charmap=%s, collate=%s)",
$lang, $map, $coll;
Expand All @@ -753,7 +771,7 @@ sub getSystemInfo {
$info->{'graphics'} = getCmdOutput("3dinfo | cut -f1 -d\'(\'");

# Get system run state, load and usage info.
$info->{'runlevel'} = getCmdOutput("runlevel | cut -f2 -d\" \"");
$info->{'runlevel'} = getCmdOutput("who -r | awk '{print \$3}'");
$info->{'load'} = getCmdOutput("uptime");
$info->{'numUsers'} = getCmdOutput("who | wc -l");

Expand Down
15 changes: 5 additions & 10 deletions UnixBench/src/big.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,15 @@
#define MAXCHILD 12
#define MAXWORK 10

/* Can't seem to get this declared in the headers... */
extern int kill(pid_t pid, int sig);

void wrapup(char *);
void wrapup(const char *);
void onalarm(int);
void pipeerr();
void grunt();
void getwork(void);
#if debug
void dumpwork(void);
#endif
void fatal(char *s);
void fatal(const char *s);

float thres;
float est_rate = DEF_RATE;
Expand Down Expand Up @@ -420,7 +417,7 @@ void pipeerr()
sigpipe++;
}

void wrapup(char *reason)
void wrapup(const char *reason)
{
int i;
int killed = 0;
Expand Down Expand Up @@ -449,7 +446,6 @@ void getwork(void)
char *q = (void *)0;
struct st_work *w = (void *)0;
char line[MAXLINE];
char c;

while (fgets(line, MAXLINE, stdin) != NULL) {
if (nwork >= MAXWORK) {
Expand Down Expand Up @@ -492,7 +488,6 @@ void getwork(void)
/* standard input for this job */
q = ++lp;
while (*lp && *lp != ' ') lp++;
c = *lp;
*lp = '\0';
if ((f = open(q, 0)) == -1) {
fprintf(stderr, "cannot open input file (%s) for job %d\n",
Expand Down Expand Up @@ -580,10 +575,10 @@ void dumpwork(void)
}
#endif

void fatal(char *s)
void fatal(const char *s)
{
int i;
fprintf(stderr, s);
fprintf(stderr, "%s", s);
fflush(stderr);
perror("Reason?");
fflush(stderr);
Expand Down

0 comments on commit c22488d

Please sign in to comment.