Changeset 14610
- Timestamp:
- Jan 30, 2011, 12:41:54 AM (14 years ago)
- File:
-
- 1 edited
-
trunk/source/library/chud-metering.lisp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/library/chud-metering.lisp
r13174 r14610 18 18 ;;; (and possibly others.) 19 19 20 ;;; CHUD 4.4.3-5 claims to offer 64-bit support; however, the library21 ;;; which provides the API to control CHUD metering functions still22 ;;; seems to be 32-bit only. Conditionalization for x86-64 and23 ;;; for 64-bit targets is (so far) just an exercise.24 25 20 (defpackage "CHUD" 26 21 (:use "CL" "CCL") … … 37 32 (defparameter *shark-session-path* nil) 38 33 39 (defloadvar *written-spatch-file* nil)40 34 41 35 (defparameter *shark-session-native-namestring* nil) … … 66 60 (native-name (ccl::native-untranslated-namestring dir))) 67 61 (ensure-directories-exist dir) 68 (setenv "SHARK_SEARCH_PATH_PATCH_FILES" native-name)69 62 (setq *shark-session-native-namestring* 70 63 native-name … … 81 74 82 75 83 (defun safe-shark-function-name (function)84 (let* ((name (format nil "~s" function)))85 (subseq (nsubstitute #\0 #\# (nsubstitute #\. #\Space name)) 1)))86 76 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 091 #+ppc32-target target::misc-data-offset92 #-ppc32-target 0))93 (endaddr (+ startaddr94 #+x8664-target95 (1+ (ash (1- (ccl::%function-code-words fn)96 ) target::word-shift))97 #+ppc-target98 (* 4 (- (uvsize code-vector)99 #+ppc64-target 2100 #-ppc64-target 1)))))101 ;; i hope all lisp sym characters are allowed... we'll see102 (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 startaddr110 #+32-bit-target "0x~8,'0x" #+64-bit-target "0x~16,'0x"111 endaddr)))112 113 #+x8664-target114 (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-target123 (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-target132 (defun identify-functions-with-pure-code ()133 (ccl::freeze)134 (ccl::collect ((functions))135 (block walk136 (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-dynamic143 )))144 (functions)))145 146 #+x8632-target147 (defun identify-functions-with-pure-code ()148 (ccl::freeze)149 (ccl::collect ((functions))150 (block walk151 (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-dynamic158 )))159 (functions)))160 161 #+ppc-target162 (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 (return170 (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 functions194 #'(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-pathname204 :host nil205 :directory (pathname-directory206 (ensure-shark-session-path))207 :name (format nil "~a_~D"208 (pathname-name209 (car210 ccl::*command-line-argument-list*))211 (ccl::getpid))212 :type "spatch")213 :direction :output214 :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~%"))))219 77 220 78 (defun terminate-shark-process () … … 227 85 (if *shark-process* 228 86 (progn 229 (signal-external-process *shark-process* #$SIGUSR1)87 (signal-external-process *shark-process* (if *sampling* #$SIGUSR2 #$SIGUSR1)) 230 88 (setq *sampling* (not *sampling*))) 231 89 (warn "No active shark procsss"))) … … 240 98 (when (or (null *shark-process*) reset) 241 99 (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*))) 246 102 (when *shark-config-file* 247 103 (push (ccl::native-untranslated-namestring *shark-config-file*) … … 293 149 *sampling* nil)))) 294 150 (let* ((*debug-shark-process-output* ,debug-output)) 151 (ensure-shark-session-path) 295 152 (ensure-shark-process ,reset #',hook) 296 153 (unwind-protect
Note:
See TracChangeset
for help on using the changeset viewer.
