Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!portc01.blue.aol.com!portc02.blue.aol.com!howland.erols.net!news.nacamar.de!news-kar1.dfn.de!news-han1.dfn.de!news-ham1.dfn.de!news.dkrz.de!news.rrz.uni-hamburg.de!news.Hanse.DE!wavehh.hanse.de!cracauer
From: cracauer@wavehh.hanse.de (Martin Cracauer)
Subject: Re: GET-INTERNAL-RUN-TIME in CMUCL 17f / Solaris 2.5?
Message-ID: <1996Nov28.124800.29136@wavehh.hanse.de>
Reply-To: cracauer@wavehh.hanse.de
Organization: '(a (cons)tructive site))
References: <ey3pw0z7def.fsf@staffa.aiai.ed.ac.uk>
Date: Thu, 28 Nov 96 12:48:00 GMT
Lines: 116

Tim Bradshaw <tfb@aiai.ed.ac.uk> writes:

>GET-INTERNAL-RUN-TIME returns 0 with CMUCL 17f on a sparc 5 running
>Solaris 2.5.  Does anyone have a fix for this?

The problem is that noone interfaced getrusage() on Solaris, but it
should not be too hard to do if you look over the sources for SunOS
and Solaris in comparision. 

This is a fix to get CMUCL's (time ...) function to report user and
system cputime, maybe that's sufficient for your needs.

~To: cmucl-bugs@cs.cmu.edu
~Cc: Casper Dik <casper@fwi.uva.nl>
~Subject: Bug (and fix) for cmucl-17f TIME (sunos5, alpha)
~Date: Fri, 25 Nov 1994 11:51:59 PST
~From: Andreas Stolcke <stolcke@ICSI.Berkeley.EDU>
~Status: RO


TIME in the solaris port doesn't report user and system cputime,
due to getrusage() lossage in solaris.  GET-INTERNAL-RUN-TIME
is also affected.  The patch below uses the times(2) system call
instead.
(Still no page fault statistics, sorry).

On alphas, TIME breaks because SYSTEM:GET-SYSTEM-INFO always returns
NIL.
This is probably just a typo.

--Andreas


;;;
;;; Addition to code/unix.lisp: support for times(2) system call
;;;

(in-package "UNIX")

(export '(unix-times unix-time-units-per-second))

;;; From sys/times.h

(def-alien-type nil
  (struct tms
    (tms-utime #-alpha long #+alpha int)        ; user time used
    (tms-stime #-alpha long #+alpha int)        ; system time used.
    (tms-cutime #-alpha long #+alpha int)       ; user time, children
    (tms-cstime #-alpha long #+alpha int)))     ; system time,
children

(defconstant unix-time-units-per-second 100
  "Machine-dependent units in which unix-times results are returned,
  not necessarily equal to internal-time-units-per-second")

#+(and sparc svr4)
(defun unix-times ()
  "Unix-times returns information about the cpu time usage
   of the process and its children. NIL and an error number
   is returned if the call fails."
  (with-alien ((usage (struct tms)))
    (syscall* ("times" (* (struct tms)))
              (values t
                      (slot usage 'tms-utime)
                      (slot usage 'tms-stime)
                      (slot usage 'tms-cutime)
                      (slot usage 'tms-cstime))
              (addr usage))))

;;;
;;; Fix to code/time.lisp
;;;

(in-package "SYSTEM")

;;; GET-SYSTEM-INFO  --  Interface
;;;
;;;    Return system time, user time and number of page faults.
;;;
#+(and sparc svr4)
(defun get-system-info ()
  (multiple-value-bind
      (err? utime stime cutime cstime)
      (unix:unix-times)
    (declare (ignore cutime cstime))
    (cond ((null err?)
           (error "Unix system call times failed: ~A."
                  (unix:get-unix-error-msg utime)))
          (T
           ;; return times in microseconds for getrusage compatibility
           ;; bummer: page fault statistics not supported
           (values (truncate (* utime 1000000)
unix:unix-time-units-per-second)
                   (truncate (* stime 1000000)
unix:unix-time-units-per-second)
                   0)))))

#+osf1
;; this definition is botched in the original
(defun get-system-info ()
  (multiple-value-bind (err? utime stime maxrss ixrss idrss
                             isrss minflt majflt)
                       (unix:unix-getrusage unix:rusage_self)
    (declare (ignore maxrss ixrss idrss isrss minflt))
    (unless err?
      (error "Unix system call getrusage failed: ~A."
             (unix:get-unix-error-msg utime)))

    (values utime stime majflt)))


-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin_Cracauer@wavehh.hanse.de http://cracauer.cons.org  Fax.: +4940 5228536
"As far as I'm concerned,  if something is so complicated that you can't ex-
 plain it in 10 seconds, then it's probably not worth knowing anyway"- Calvin
