Let SIGALRM do its thing even if we're on the right millisecond.
authorTaylor R Campbell <campbell@mumble.net>
Wed, 29 May 2019 16:10:52 +0000 (16:10 +0000)
committerTaylor R Campbell <campbell@mumble.net>
Wed, 29 May 2019 16:10:52 +0000 (16:10 +0000)
If we request a timer interrupt now in logic that closes a lot of
files, which runs through %deregister-io-descriptor, it looks like
_all_ the time is spent in closing files even if it's merely the case
that at least one file is closed every millisecond.

If we instead let SIGALRM do its thing, unless the interrupt is
_overdue_, then the profiler can discriminate at sub-millisecond
resolution where the time is spent which is what I really want.

src/runtime/thread.scm

index e514075104fa1651edfd0a7be011a536bc93fc97..1f0adb5fd7db5fad0651ef7bafe36cdd04e3e0b0 100644 (file)
@@ -1143,12 +1143,20 @@ USA.
       (cond (timer-records
             (let ((next-event-time (timer-record/time timer-records)))
               (if (<= next-event-time now)
-                  ;; Don't set the timer to non-positive values.
-                  ;; Instead signal the interrupt now.  This is ugly
-                  ;; but much simpler than refactoring the scheduler
-                  ;; so that we can do the right thing here.
-                  ((ucode-primitive request-interrupts! 1)
-                   interrupt-bit/timer)
+                  ;; We're due.  If the timer is already scheduled for
+                  ;; the next event time, let it fire when it is ready
+                  ;; -- it's a difference of microseconds.  Otherwise,
+                  ;; if we're overdue, request a timer interrupt now.
+                  (if (or (not next-scheduled-timeout)
+                          (< next-event-time next-scheduled-timeout))
+                      (begin
+                        ;; Don't set the timer to non-positive values.
+                        ;; Instead signal the interrupt now.  This is ugly
+                        ;; but much simpler than refactoring the scheduler
+                        ;; so that we can do the right thing here.
+                        (set! next-scheduled-timeout now)
+                        ((ucode-primitive request-interrupts! 1)
+                         interrupt-bit/timer)))
                   (start
                    (if (and consider-non-timers? timer-interval)
                        (min next-event-time (+ now timer-interval))