Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
barusan's patch mostly retains compatibility with linux, but
unconditionally used machdep instead of /proc/cpuinfo

This attempts to merge the patch without harming behaviour on linux by
detecting the darwin platform and using machdep there but restores
/proc/cpuinfo elsewhere.
  • Loading branch information
mihalis68 authored and gstrauss committed Mar 24, 2016
1 parent a17d08e commit 64c45b4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 28 deletions.
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
9 changes: 5 additions & 4 deletions UnixBench/src/context1.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ char *argv[];
int duration;
unsigned long check;
int p1[2], p2[2];
ssize_t ret;

if (argc != 2) {
fprintf(stderr, "Usage: context duration\n");
Expand All @@ -70,8 +71,8 @@ char *argv[];
perror("master write failed");
exit(1);
}
if (read(p2[0], (char *)&check, sizeof(check)) != sizeof(check)) {
if ((errno != 0) && (errno != EINTR))
if ((ret = read(p2[0], (char *)&check, sizeof(check))) != sizeof(check)) {
if ((ret == -1) && (errno != 0) && (errno != EINTR))
perror("master read failed");
exit(1);
}
Expand All @@ -90,8 +91,8 @@ char *argv[];
/* slave, read p1 & write p2 */
close(p1[1]); close(p2[0]);
while (1) {
if (read(p1[0], (char *)&check, sizeof(check)) != sizeof(check)) {
if ((errno != 0) && (errno != EINTR))
if ((ret = read(p1[0], (char *)&check, sizeof(check))) != sizeof(check)) {
if ((ret == -1) && (errno != 0) && (errno != EINTR))
perror("slave read failed");
exit(1);
}
Expand Down

0 comments on commit 64c45b4

Please sign in to comment.