Changeset 14610


Ignore:
Timestamp:
Jan 30, 2011, 12:41:54 AM (14 years ago)
Author:
Gary Byers
Message:

New scheme (using native heap images.) Lose all of the .spatch
stuff.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/library/chud-metering.lisp

    r13174 r14610  
    1818;;; (and possibly others.)
    1919
    20 ;;; CHUD 4.4.3-5 claims to offer 64-bit support; however, the library
    21 ;;; which provides the API to control CHUD metering functions still
    22 ;;; seems to be 32-bit only.  Conditionalization for x86-64 and
    23 ;;; for 64-bit targets is (so far) just an exercise.
    24 
    2520(defpackage "CHUD"
    2621  (:use "CL" "CCL")
     
    3732(defparameter *shark-session-path* nil)
    3833
    39 (defloadvar *written-spatch-file* nil)
    4034
    4135(defparameter *shark-session-native-namestring* nil)
     
    6660             (native-name (ccl::native-untranslated-namestring dir)))
    6761        (ensure-directories-exist dir)
    68         (setenv "SHARK_SEARCH_PATH_PATCH_FILES" native-name)
    6962        (setq *shark-session-native-namestring*
    7063              native-name
     
    8174
    8275
    83 (defun safe-shark-function-name (function)
    84   (let* ((name (format nil "~s" function)))
    85     (subseq (nsubstitute #\0 #\# (nsubstitute #\. #\Space name)) 1)))
    8676
    87 (defun print-shark-spatch-record (fn &optional (stream t))
    88   (let* ((code-vector #+ppc-target (uvref fn 0) #-ppc-target fn)
    89          (startaddr (+ (ccl::%address-of code-vector)
    90                        #+x8664-target 0
    91                        #+ppc32-target target::misc-data-offset
    92                        #-ppc32-target 0))
    93          (endaddr (+ startaddr
    94                      #+x8664-target
    95                      (1+ (ash (1- (ccl::%function-code-words fn)
    96                                   ) target::word-shift))
    97                      #+ppc-target
    98                      (* 4 (- (uvsize code-vector)
    99                                        #+ppc64-target 2
    100                                        #-ppc64-target 1)))))
    101     ;; i hope all lisp sym characters are allowed... we'll see
    102     (format stream "{~%~@
    103                         ~a~@
    104                         ~@?~@
    105                         ~@?~@
    106                         }~%"
    107             (safe-shark-function-name fn)
    108             #+32-bit-target "0x~8,'0x" #+64-bit-target "0x~16,'0x"
    109             startaddr
    110             #+32-bit-target "0x~8,'0x" #+64-bit-target "0x~16,'0x"
    111             endaddr)))
    112 
    113 #+x8664-target
    114 (ccl::defx86lapfunction dynamic-dnode ((x arg_z))
    115   (movq (% x) (% imm0))
    116   (ref-global x86::heap-start arg_y)
    117   (subq (% arg_y) (% imm0))
    118   (shrq ($ x8664::dnode-shift) (% imm0))
    119   (box-fixnum imm0 arg_z)
    120   (single-value-return))
    121 
    122 #+x8632-target
    123 (ccl::defx8632lapfunction dynamic-dnode ((x arg_z))
    124   (movl (% x) (% imm0))
    125   (ref-global x86::heap-start arg_y)
    126   (subl (% arg_y) (% imm0))
    127   (shrl ($ x8632::dnode-shift) (% imm0))
    128   (box-fixnum imm0 arg_z)
    129   (single-value-return))
    130 
    131 #+x8664-target
    132 (defun identify-functions-with-pure-code ()
    133   (ccl::freeze)
    134   (ccl::collect ((functions))
    135     (block walk
    136       (let* ((frozen-dnodes (ccl::frozen-space-dnodes)))
    137         (ccl::%map-areas (lambda (o)
    138                            (when (>= (dynamic-dnode o) frozen-dnodes)
    139                              (return-from walk nil))
    140                            (when (typep o 'ccl::function-vector)
    141                              (functions (ccl::function-vector-to-function o))))
    142                          ccl::area-dynamic
    143                          )))
    144     (functions)))
    145 
    146 #+x8632-target
    147 (defun identify-functions-with-pure-code ()
    148   (ccl::freeze)
    149   (ccl::collect ((functions))
    150     (block walk
    151       (let* ((frozen-dnodes (ccl::frozen-space-dnodes)))
    152         (ccl::%map-areas (lambda (o)
    153                            (when (>= (dynamic-dnode o) frozen-dnodes)
    154                              (return-from walk nil))
    155                            (when (typep o 'function)
    156                              (functions o)))
    157                          ccl::area-dynamic
    158                          )))
    159     (functions)))
    160 
    161 #+ppc-target
    162 (defun identify-functions-with-pure-code ()
    163   (ccl::purify)
    164   (multiple-value-bind (pure-low pure-high)
    165                                  
    166       (ccl::do-gc-areas (a)
    167         (when (eql(ccl::%fixnum-ref a target::area.code)
    168                   ccl::area-readonly)
    169           (return
    170             (values (ash (ccl::%fixnum-ref a target::area.low) target::fixnumshift)
    171                     (ash (ccl::%fixnum-ref a target::area.active) target::fixnumshift)))))
    172     (let* ((hash (make-hash-table :test #'eq)))
    173       (ccl::%map-lfuns #'(lambda (f)
    174                            (let* ((code-vector  (ccl:uvref f 0))
    175                                   (startaddr (+ (ccl::%address-of code-vector)
    176                                                 target::misc-data-offset)))
    177                              (when (and (>= startaddr pure-low)
    178                                         (< startaddr pure-high))
    179                                (push f (gethash code-vector hash))))))
    180       (let* ((n 0))
    181         (declare (fixnum n))
    182         (maphash #'(lambda (k v)
    183                      (declare (ignore k))
    184                      (if (null (cdr v))
    185                        (incf n)))
    186                  hash)
    187         (let* ((functions ()))
    188           (maphash #'(lambda (k v)
    189                        (declare (ignore k))
    190                        (when (null (cdr v))
    191                          (push (car v) functions)))
    192                    hash)
    193           (sort functions
    194                 #'(lambda (x y)
    195                     (< (ccl::%address-of (uvref x 0) )
    196                        (ccl::%address-of  (uvref y 0))))))))))
    197        
    198                            
    199 
    200 
    201 (defun generate-shark-spatch-file ()
    202   (let* ((functions (identify-functions-with-pure-code)))
    203     (with-open-file (f (make-pathname
    204                         :host nil
    205                         :directory (pathname-directory
    206                                     (ensure-shark-session-path))
    207                         :name (format nil "~a_~D"
    208                                       (pathname-name
    209                                        (car
    210                                         ccl::*command-line-argument-list*))
    211                                       (ccl::getpid))
    212                         :type "spatch")
    213                        :direction :output
    214                        :if-exists :supersede)
    215       (format f "!SHARK_SPATCH_BEGIN~%")
    216       (dolist (fun functions)
    217         (print-shark-spatch-record fun f))
    218       (format f "!SHARK_SPATCH_END~%"))))
    21977
    22078(defun terminate-shark-process ()
     
    22785  (if *shark-process*
    22886    (progn
    229       (signal-external-process *shark-process* #$SIGUSR1)
     87      (signal-external-process *shark-process* (if *sampling* #$SIGUSR2 #$SIGUSR1))
    23088      (setq *sampling* (not *sampling*)))
    23189    (warn "No active shark procsss")))
     
    24098  (when (or (null *shark-process*) reset)
    24199    (terminate-shark-process)
    242     (when (or reset (not *written-spatch-file*))
    243       (generate-shark-spatch-file))
    244     (let* ((args (list "-b" "-1" "-a" (format nil "~d" (ccl::getpid))
    245                              "-d" *shark-session-native-namestring*)))
     100    (let* ((args (list "-r" "-b" "-1" "-a" (format nil "~d" (ccl::getpid))
     101                       "-d" *shark-session-native-namestring*)))
    246102      (when *shark-config-file*
    247103        (push (ccl::native-untranslated-namestring *shark-config-file*)
     
    293149                       *sampling* nil))))
    294150        (let* ((*debug-shark-process-output* ,debug-output))
     151          (ensure-shark-session-path)
    295152          (ensure-shark-process ,reset #',hook)
    296153          (unwind-protect
Note: See TracChangeset for help on using the changeset viewer.