From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pip Cet via "Emacs development discussions." Newsgroups: gmane.emacs.devel Subject: Re: igc, macOS avoiding signals Date: Sat, 28 Dec 2024 16:29:14 +0000 Message-ID: <87h66ng4bf.fsf@protonmail.com> References: <799DDBC5-2C14-4476-B1E0-7BA2FE9E7901@toadstyle.org> Reply-To: Pip Cet Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27233"; mail-complaints-to="usenet@ciao.gmane.io" Cc: gerd.moellmann@gmail.com, emacs-devel@gnu.org To: Sean Devlin Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Dec 28 18:28:04 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tRabc-0006uZ-3U for ged-emacs-devel@m.gmane-mx.org; Sat, 28 Dec 2024 18:28:04 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tRab3-00037x-BK; Sat, 28 Dec 2024 12:27:29 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tRZgr-0008S2-Hb for emacs-devel@gnu.org; Sat, 28 Dec 2024 11:29:25 -0500 Original-Received: from mail-4316.protonmail.ch ([185.70.43.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tRZgp-0000Po-PQ for emacs-devel@gnu.org; Sat, 28 Dec 2024 11:29:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1735403361; x=1735662561; bh=U9P4YjDw8PqXN6fIgTCRR8ISkfFiEh677cmXzN1XPjU=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=xnOIpowBfBGPPCft7459khcmaJN4ms5hGgfdodGQcKrJnfOfsGe/6QvOhWX7JSIAF g8Ic+jenzJQtemVgzvREm6p5E+XCLrrzza5jlAHVrOafHXiOxYfQeDSDk0d/N0DS5K fw4WXH6bocXms4bQxDBv3tWEbkPBTr+ENBhAftY4kZLQVQ+gOKfnTNBASN7q1lP/Cx KPr0oFFdygbfBhTY87LqHRh+MHq9sQakCAMgB0bNZtIvDaJyqVlfxE1MdmZ/etsj/Q z4pYpkKe5t5IWBzu7RNuGGjgjXxNeRq2wTEfZCxsFJpJfUGnuxQ8W3khrnbWnf2TOW +HSu8ATG4rZKQ== In-Reply-To: <799DDBC5-2C14-4476-B1E0-7BA2FE9E7901@toadstyle.org> Feedback-ID: 112775352:user:proton X-Pm-Message-ID: 99be086555c6840dc30aa80c3f8b50a2d3c744de Received-SPF: pass client-ip=185.70.43.16; envelope-from=pipcet@protonmail.com; helo=mail-4316.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 28 Dec 2024 12:27:28 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:327278 Archived-At: > 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; } =20 @@ -4924,8 +4926,9 @@ gc_signal_handler_can_run (int sig) if (igc_busy_p ()) { sigset_t sigs; - global_igc->signals_pending =3D 1; + clock_gettime (CLOCK_REALTIME, &global_igc->pending_since[sig]); global_igc->pending_signals[sig] =3D 1; + global_igc->signals_pending =3D 1; sigemptyset (&sigs); sigaddset (&sigs, sig); pthread_sigmask (SIG_BLOCK, &sigs, NULL); @@ -4946,6 +4949,12 @@ gc_maybe_quit (void) for (int i =3D 0; i < ARRAYELTS (global_igc->pending_signals); i++) =09if (global_igc->pending_signals[i]) =09 { +=09 struct timespec ts; +=09 clock_gettime (CLOCK_REALTIME, &ts); +=09 long long nsec =3D ts.tv_nsec - global_igc->pending_since[i].tv_nse= c; +=09 long long sec =3D ts.tv_sec - global_igc->pending_since[i].tv_sec; +=09 nsec +=3D 1000000000 * sec; +=09 fprintf (stderr, "delayed %d for %f sec\n", i, nsec * 1.0e-9); =09 global_igc->pending_signals[i] =3D 0; =09 raise (i); =09 } @@ -4953,6 +4962,23 @@ gc_maybe_quit (void) } } =20 +void gc_maybe_dont_quit (void) +{ + if (global_igc->signals_pending) + { + for (int i =3D 0; i < ARRAYELTS (global_igc->pending_signals); i++) +=09if (global_igc->pending_signals[i]) +=09 { +=09 struct timespec ts; +=09 clock_gettime (CLOCK_REALTIME, &ts); +=09 long long nsec =3D ts.tv_nsec - global_igc->pending_since[i].tv_nse= c; +=09 long long sec =3D ts.tv_sec - global_igc->pending_since[i].tv_sec; +=09 nsec +=3D 1000000000 * sec; +=09 fprintf (stderr, "delaying %d for %f sec\n", i, nsec * 1.0e-9); +=09 } + } +} + 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 KE= Y. 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 =3D level; if (level =3D=3D 0) { + gc_maybe_dont_quit (); if (pending_signals && !fatal_error_in_progress) =09process_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) { } =20 +INLINE void gc_maybe_dont_quit (void) +{ +} + INLINE bool gc_signal_handler_can_run (int sig) { return true;