arch-arm,cpu: Add initial support for Arm SVE
[gem5.git] / util / qdo
index 3a475b420e1414a98fc3723ec486bc7676f3d0ff..8008a40c4748e029e891e0a70691c95835f3cd48 100755 (executable)
--- a/util/qdo
+++ b/util/qdo
@@ -1,6 +1,6 @@
-#! /usr/bin/env python
+#! /usr/bin/env python2.7
 
-# Copyright (c) 2004-2005 The Regents of The University of Michigan
+# Copyright (c) 2004-2005, 2007 The Regents of The University of Michigan
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Steve Reinhardt
+#          Ali Saidi
+
+# Important!
+# This script expects a simple $ prompt, if you are using a shell other than
+# sh which defaults to this you'll need to add something like the following
+# to your bashrc/bash_profile script:
+#if [ "$OAR_USER" = "xxxx" ]; then
+#   PS1='$ '
+
 
 import sys
 import os
@@ -44,9 +55,13 @@ optparser.add_option('-e', dest='stderr_file',
 optparser.add_option('-o', dest='stdout_file',
                      help='command stdout output file')
 optparser.add_option('-l', dest='save_log', action='store_true',
-                     help='save qsub output log file')
-optparser.add_option('-q', dest='qsub_timeout', type='int',
-                     help='qsub queue wait timeout', default=30*60)
+                     help='save oarsub output log file')
+optparser.add_option('-N', dest='job_name',
+                     help='oarsub job name')
+optparser.add_option('-q', dest='dest_queue',
+                     help='oarsub destination queue')
+optparser.add_option('--qwait', dest='oarsub_timeout', type='int',
+                     help='oarsub queue wait timeout', default=30*60)
 optparser.add_option('-t', dest='cmd_timeout', type='int',
                      help='command execution timeout', default=600*60)
 
@@ -56,6 +71,12 @@ if cmd == []:
     print >>sys.stderr, "%s: missing command" % progname
     sys.exit(1)
 
+# If we want to do this, need to add check here to make sure cmd[0] is
+# a valid PBS job name, else oarsub will die on us.
+#
+#if not options.job_name:
+#    options.job_name = cmd[0]
+
 cwd = os.getcwd()
 
 # Deal with systems where /n is a symlink to /.automount
@@ -76,21 +97,21 @@ class Shell(pexpect.spawn):
 
     def __init__(self, cmd):
         # initialize base pexpect.spawn object
-       try:
+        try:
             pexpect.spawn.__init__(self, cmd)
-       except pexpect.ExceptionPexpect, exc:
-           print "%s:" % progname, exc
-           sys.exit(1)
+        except pexpect.ExceptionPexpect, exc:
+            print "%s:" % progname, exc
+            sys.exit(1)
         # full_output accumulates the full output of the session
         self.full_output = ""
         self.quick_timeout = 15
         # wait for a prompt, then change it
         try:
-            self.expect('\$ ', options.qsub_timeout)
+            self.expect('\$ ', options.oarsub_timeout)
         except pexpect.TIMEOUT:
-            print >>sys.stderr, "%s: qsub timed out." % progname
-            self.kill(15)
-            self.close(wait=True)
+            print >>sys.stderr, "%s: oarsub timed out." % progname
+            self.kill(9)
+            self.safe_close()
             sys.exit(1)
         self.do_command('unset PROMPT_COMMAND; PS1="qdo$ "')
 
@@ -126,6 +147,15 @@ class Shell(pexpect.spawn):
                                             self.quick_timeout)
         return status == 0
 
+    # Don't actually try to close it.. just wait until it closes by itself
+    # We can't actually kill the pid which is what it's trying to do, and if
+    # we call wait we could be in an unfortunate situation of it printing input
+    # right as we call wait, so the input is never read and the process never ends
+    def safe_close(self):
+        count = 0
+        while self.isalive() and count < 10:
+            time.sleep(1)
+        self.close(force=False)
 
 # Spawn the interactive pool job.
 
@@ -136,7 +166,12 @@ if False and len(cmd) > 50:
     shell_cmd = 'ssh -t poolfs /bin/sh -l'
     print "%s: running %s on poolfs" % (progname, cmd[0])
 else:
-    shell_cmd = 'qsub -I -S /bin/sh'
+    shell_cmd = 'oarsub -I'
+    if options.job_name:
+        shell_cmd += ' -n "%s"' % options.job_name
+    if options.dest_queue:
+        shell_cmd += ' -q ' + options.dest_queue
+    shell_cmd += ' -d %s' % cwd
 
 shell = Shell(shell_cmd)
 
@@ -165,10 +200,10 @@ try:
 
     if output_dir:
         secs_waited = 0
-        while not shell.dir_exists(output_dir) and secs_waited < 45:
+        while not shell.dir_exists(output_dir) and secs_waited < 90:
             time.sleep(5)
             secs_waited += 5
-        if secs_waited > 10:
+        if secs_waited > 30:
             print "waited", secs_waited, "seconds for", output_dir
 
     # run command
@@ -181,25 +216,23 @@ try:
     except pexpect.TIMEOUT:
             print >>sys.stderr, "%s: command timed out after %d seconds." \
                   % (progname, options.cmd_timeout)
-            shell.sendline('~.') # qsub/ssh termination escape sequence
-            shell.close(wait=True)
+            shell.sendline('~.') # oarsub/ssh termination escape sequence
+            shell.safe_close()
             status = 3
     if output:
         print output
-
 finally:
     # end job
     if shell.isalive():
         shell.sendline('exit')
-        shell.expect('qsub: job .* completed\r\n')
-        shell.close(wait=True)
+        shell.expect('Disconnected from OAR job .*')
+        shell.safe_close()
 
     # if there was an error, log the output even if not requested
     if status != 0 or options.save_log:
         log = file('qdo-log.' + str(os.getpid()), 'w')
         log.write(shell.full_output)
         log.close()
-
 del shell
 
 sys.exit(status)