• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# Control script for a program that tests shared memory access speeds.
4
5# Copyright (C) 2003-2006 IBM
6#
7# This program is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License as
9# published by the Free Software Foundation; either version 2 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful, but
13# WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15# General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20# 02111-1307, USA.
21
22# Kill anything in this process group
23trap 'kill -9 `pgrep -P $$` 2> /dev/null; exit 0' 1 2 15
24
25# Try to find ramsnake
26PROGRAM="$POUNDER_SRCDIR/ramsnake/snake.exe"
27if [ -z "$PROGRAM" ]; then
28	echo "Cannot find ramsnake; did you run Install?"
29	exit -1
30fi
31
32# We want enough nodes to consume 1/2 of whatever RAM isn't being used
33# for programs or buffers.  Note that we must divide again by the number
34# of CPUs in the system so that the _total_ memory used is 1/4.
35#
36# Does the LONG_BIT config variable really refer to the size
37# of a pointer?
38MEM_AVAIL=$(( `grep ^MemFree: /proc/meminfo | awk -F " " '{print $2}'` + `grep ^Cached: /proc/meminfo | awk -F " " '{print $2}'`))
39NUM_NODES=$(( (MEM_AVAIL * 1024 / (2 * NR_CPUS)) / $((`getconf LONG_BIT` / 8)) ))
40
41# Start up a bunch of ramsnakes in the background.
42for ((k=0; k < $NR_CPUS; k++))
43do
44	"$POUNDER_HOME/timed_loop" 300 "$PROGRAM" -p $NR_CPUS -n $NUM_NODES &
45done
46
47LOGFILE=/proc/$$/fd/1
48OLD_ERRORS=0
49
50# Check for errors while snake runs.
51while [ `pgrep -P $$ | wc -l` -gt 1 ];
52do
53	NEW_ERRORS=`egrep -ic "(segmentation|fault|error|illegal)" $LOGFILE`
54	ERRORS=$(( NEW_ERRORS - OLD_ERRORS ))
55	if [ $ERRORS -eq 255 ]; then
56		ERRORS=254
57	fi
58
59	if [ $ERRORS -gt 0 ]; then
60		echo "Program crash detected.  Aborting."
61		exit 1
62	fi
63	OLD_ERRORS=$ERRORS
64	sleep 5
65done
66
67# Failures will probably hang the system or segfault snake.
68exit 0
69