From: Pip Cet via "Emacs development discussions." <emacs-devel@gnu.org>
To: Sean Devlin <spd@toadstyle.org>
Cc: gerd.moellmann@gmail.com, emacs-devel@gnu.org
Subject: Re: igc, macOS avoiding signals
Date: Sat, 28 Dec 2024 16:29:14 +0000 [thread overview]
Message-ID: <87h66ng4bf.fsf@protonmail.com> (raw)
In-Reply-To: <799DDBC5-2C14-4476-B1E0-7BA2FE9E7901@toadstyle.org>
> I'll try to come up with a patch.
This should provide some data (on stderr) about which signals we delay,
and for how long (the "delayed" messages). It also includes some
information on additional points at which we can detect whether signals
are pending (the "delaying" messages); it's probably safe to run them at
that point, but the code might need some changes because other signals
(or even the signal in question) might be legitimately blocked when we
reach that point.
If the "delaying" messages indicate acceptable (initial) delays, we
might get away with simply calling gc_maybe_quit more often. If they
don't, further fixes will be necessary, or we need to find more such
points.
On POSIX systems where we can spare an additional signal, we can run a
separate thread to ask us to retry running signal handlers when the
arena lock might be available again.
Or we could move to a separate thread for slow-path allocations.
diff --git a/src/igc.c b/src/igc.c
index 4d9aec90340..1402b9d10a5 100644
--- a/src/igc.c
+++ b/src/igc.c
@@ -811,6 +811,7 @@ IGC_DEFINE_LIST (igc_thread);
/* Per-signal flags. These are `int' to reduce the chance of
* corruption when accessed non-atomically. */
int pending_signals[64];
+ struct timespec pending_since[64];
/* The real signal mask we want to restore after handling pending
* signals. */
sigset_t signal_mask;
@@ -3833,6 +3834,7 @@ alloc_impl (size_t size, enum igc_obj_type type, mps_ap_t ap)
case IGC_STATE_INITIAL:
emacs_abort ();
}
+ gc_maybe_dont_quit ();
return p;
}
@@ -4924,8 +4926,9 @@ gc_signal_handler_can_run (int sig)
if (igc_busy_p ())
{
sigset_t sigs;
- global_igc->signals_pending = 1;
+ clock_gettime (CLOCK_REALTIME, &global_igc->pending_since[sig]);
global_igc->pending_signals[sig] = 1;
+ global_igc->signals_pending = 1;
sigemptyset (&sigs);
sigaddset (&sigs, sig);
pthread_sigmask (SIG_BLOCK, &sigs, NULL);
@@ -4946,6 +4949,12 @@ gc_maybe_quit (void)
for (int i = 0; i < ARRAYELTS (global_igc->pending_signals); i++)
if (global_igc->pending_signals[i])
{
+ struct timespec ts;
+ clock_gettime (CLOCK_REALTIME, &ts);
+ long long nsec = ts.tv_nsec - global_igc->pending_since[i].tv_nsec;
+ long long sec = ts.tv_sec - global_igc->pending_since[i].tv_sec;
+ nsec += 1000000000 * sec;
+ fprintf (stderr, "delayed %d for %f sec\n", i, nsec * 1.0e-9);
global_igc->pending_signals[i] = 0;
raise (i);
}
@@ -4953,6 +4962,23 @@ gc_maybe_quit (void)
}
}
+void gc_maybe_dont_quit (void)
+{
+ if (global_igc->signals_pending)
+ {
+ for (int i = 0; i < ARRAYELTS (global_igc->pending_signals); i++)
+ if (global_igc->pending_signals[i])
+ {
+ struct timespec ts;
+ clock_gettime (CLOCK_REALTIME, &ts);
+ long long nsec = ts.tv_nsec - global_igc->pending_since[i].tv_nsec;
+ long long sec = ts.tv_sec - global_igc->pending_since[i].tv_sec;
+ nsec += 1000000000 * sec;
+ fprintf (stderr, "delaying %d for %f sec\n", i, nsec * 1.0e-9);
+ }
+ }
+}
+
DEFUN ("igc--add-extra-dependency", Figc__add_extra_dependency,
Sigc__add_extra_dependency, 3, 3, 0,
doc: /* Add an extra DEPENDENCY to object OBJ, associate it with KEY.
diff --git a/src/keyboard.c b/src/keyboard.c
index e875e98fde6..906595f3be9 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -8203,6 +8203,7 @@ unblock_input_to (int level)
interrupt_input_blocked = level;
if (level == 0)
{
+ gc_maybe_dont_quit ();
if (pending_signals && !fatal_error_in_progress)
process_pending_signals ();
}
diff --git a/src/lisp.h b/src/lisp.h
index 48585c2d8a1..fb7f3847a5d 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -47,12 +47,17 @@ #define EMACS_LISP_H
#ifdef HAVE_MPS
union gc_header;
extern void gc_maybe_quit (void);
+extern void gc_maybe_dont_quit (void);
extern bool gc_signal_handler_can_run (int);
#else
INLINE void gc_maybe_quit (void)
{
}
+INLINE void gc_maybe_dont_quit (void)
+{
+}
+
INLINE bool gc_signal_handler_can_run (int sig)
{
return true;
next prev parent reply other threads:[~2024-12-28 16:29 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-28 13:24 igc, macOS avoiding signals Sean Devlin
2024-12-28 13:28 ` Gerd Möllmann
2024-12-28 14:31 ` Eli Zaretskii
2024-12-28 14:45 ` Gerd Möllmann
2024-12-28 15:12 ` Pip Cet via Emacs development discussions.
2024-12-28 17:30 ` Eli Zaretskii
2024-12-28 18:40 ` Pip Cet via Emacs development discussions.
2024-12-28 18:50 ` Eli Zaretskii
2024-12-28 19:07 ` Eli Zaretskii
2024-12-28 19:20 ` Pip Cet via Emacs development discussions.
2024-12-28 19:36 ` Eli Zaretskii
2024-12-28 20:54 ` Pip Cet via Emacs development discussions.
2024-12-29 5:51 ` Eli Zaretskii
2024-12-28 19:15 ` Pip Cet via Emacs development discussions.
2024-12-28 19:30 ` Eli Zaretskii
2024-12-28 16:29 ` Pip Cet via Emacs development discussions. [this message]
2024-12-29 2:21 ` Sean Devlin
2024-12-29 12:22 ` Pip Cet via Emacs development discussions.
2024-12-29 15:01 ` Gerd Möllmann
-- strict thread matches above, loose matches on Subject: below --
2024-12-28 6:40 Gerd Möllmann
2024-12-28 12:49 ` Pip Cet via Emacs development discussions.
2024-12-28 12:55 ` Gerd Möllmann
2024-12-28 13:50 ` Óscar Fuentes
2024-12-29 8:02 ` Helmut Eller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h66ng4bf.fsf@protonmail.com \
--to=emacs-devel@gnu.org \
--cc=gerd.moellmann@gmail.com \
--cc=pipcet@protonmail.com \
--cc=spd@toadstyle.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.