#!/bin/bash

#-----------------------------
### initialize environment ###
# set the CPU2006 environment variables:
. ./shrc
ulimit -s unlimited
#limit the locked pages in memory:
ulimit -l 2097152
# limit the percentage of memory that can hold dirty cache before forcing sync:
echo 8 > /proc/sys/vm/dirty_ratio
# tell the Linux kernel to only swap if it is absolutely necessary:
echo 1 > /proc/sys/vm/swappiness
# tell the kernel to free local node memory rather than grabbing free memory from remote nodes:
echo 1 > /proc/sys/vm/zone_reclaim_mode

#Update SPEC CPU syntax checker to recognize updated cache format syntax 
specperl -pi -e 'BEGIN { for $f (splice @ARGV, 1) { $n{$f} = qx/specmd5sum -e $f/ if -f $f } } @f = split(/\s+/); $_ = $n{$f[3]} if exists($n{$f[3]})' MANIFEST bin/formats/cpu2006.syntax

drop_caches()
{
  # Linux is inefficient at disk cache management and paging can occur when
  # the disk cache grows big and the kernel is not fast enough to
  # free cache space for programs. sync + drop_caches resets the disk cache
  # size before the run starts:
  echo; echo; echo "Flushing disk caches. Please wait..."
  rm -r benchspec/CPU2006/*/run/ 2>/dev/null  
  sync
  echo 3 > /proc/sys/vm/drop_caches
  # pause briefly so the system can stabilize:
  sleep 2s
  echo "Finished flushing disk caches."; echo
}

drop_caches

#run benchmarks
#runspec --config=Hygon-open64-hygon-binary-0617.cfg --action=run --tune=all --size=all --reportable int  
#runspec --config=Hygon-open64-hygon-binary-0617.cfg --action=run --tune=all --size=all --reportable fp  
#1
#runspec --config=Hygon-open64-hygon-binary-0617.cfg --action=run --tune=base --size=ref  --iterations=1 --noreportable int
#runspec --config=Hygon-open64-hygon-binary-0617.cfg --action=run --tune=peak --size=ref  --iterations=1 --noreportable int

#runspec --config=Hygon-open64-hygon-binary-0617.cfg --action=run --tune=base --size=ref  --iterations=1 --noreportable fp
#runspec --config=Hygon-open64-hygon-binary-0617.cfg --action=run --tune=peak --size=ref  --iterations=1 --noreportable fp

#2 rate=1
#runspec --config=Hygon-open64-hygon-binary-0617.cfg --action=run --tune=base --size=ref  --iterations=1 --noreportable fp
#runspec --config=Hygon-open64-hygon-binary-0617.cfg --action=run --tune=peak --size=ref  --iterations=1 --noreportable fp

#runspec --config=Hygon-open64-hygon-binary-0617.cfg --action=run --tune=base --size=ref  --iterations=1 --noreportable int
#3 rate=1 修改speccpu2006/benchspec/CPU2006/CINT2006.bset，去掉403gcc
runspec --config=Hygon-open64-hygon-binary-0617.cfg --action=run --tune=peak --size=ref  --iterations=1 --noreportable int
