From: "Gerd Möllmann" <gerd.moellmann@gmail.com>
To: Helmut Eller <eller.helmut@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>,
spd@toadstyle.org, pipcet@protonmail.com, emacs-devel@gnu.org
Subject: Re: igc, macOS avoiding signals
Date: Mon, 30 Dec 2024 12:53:33 +0100 [thread overview]
Message-ID: <m2h66le69u.fsf@gmail.com> (raw)
In-Reply-To: <87cyh9mpn5.fsf@gmail.com> (Helmut Eller's message of "Mon, 30 Dec 2024 11:27:58 +0100")
Helmut Eller <eller.helmut@gmail.com> writes:
> On Mon, Dec 30 2024, Gerd Möllmann wrote:
>
>>> My interpretation of this design document[*], is that MPS's arena lock
>>> protects most of MPS entry points. There are a few (e.g. mps_reserve
>>> and mp_ld_add) that don't claim the arena lock and for those it's the
>>> burden of the client to call them in a thread safe way. For us this
>>> probably means: don't call them in a signal handler.
>>>
>>> The main entry point that we want to call in the signal handler is the
>>> SEGFAULT handler (not sure how this works on MacOS). The fault handler
>>> claims the non-recursive arena lock. So, in the signal handler we
>>> should not hold the lock while hitting a barrier.
>>
>> Okay, that I think I understand then. The "only" difference between
>> macOS and Linux is that on macOS no SEGV handler is involved. Hitting
>> the barrier on macOS means that the EXC_BAD_ACCESS port thread, which
>> was waiting for Mach message, receives a message from the OS and starts
>> working.
>
> I guess that both, macOS and Linux version, will end up in ArenaAccess.
> Perhaps on macOS in the other thread.
>
>>>> I think I understand that, except when the Emacs thread is interrupted
>>>> while in MPS code, which happens for allocation points running out of
>>>> memory and mps_arena_step (idle time).
>>>
>>> Hmm, is that sentence incomplete? I don't quite understand it.
>>
>> What I meant is that I imagine a signal interrupts the Emacs thread at a
>> point where we are "in MPS". AreaEnter/Leave I think I understand, it's
>> some pthread_mutex_t, I think, from other mails. A problematic "in MPS"
>> could then be "while the Emacs thread owns the mutex". The places where
>> I imagine that mutex could be owned are mps_arena_step (I call it Emacs
>> is idle) and mps_commit (in alloc_impl, when the allocation point used
>> runs out of memory). Maybe other places, but mainly these two.
>
> Yes.
>
>> And the question on macOS for me would be if the port thread tries to
>> qcquire the same mutex, or how the heck that works. Or IOW, if there is
>> a problem, why I've never seen it happening in all that time I'm using
>> igc.
>
> Maybe you could set a breakpoint in AreaAccess to find out which thread
> removes the barriers.
>
>> I find that difficult to understand. But it may be just a
>> statistical phenomenon. Maybe filling up an APs memory is so fast so
>> that the probability of a signal hitting while owning the mutex is close
>> to zero, or something.
>
> Very few of Emacs' signal handlers actually touch a barrier. I've also
> not seen any reproducable receipes for the "signal issues" that the igc
> branch supposedly has.
>
> Helmut
I've got something, using Eglot/clangd.
Executive summary: If a signal interrupts the Emacs thread, and we are
"inside MPS", meaning the Emacs threads owns an arena's mutex, the macOS
port thread can try to acquire the same mutex and won't get because the
Emacs thread that owns it is stopped by the signal.
It goes like this:
** mps_commit
mps_commit
-> mps_ap_trip
-> ArenaEnter
** ArenaEnter
ArenaEnter
-> ArenaEnterLock non-recursive
-> LockClaim arena lock
-> pthread_mutex_lock.
-> ShieldEnter
-> shieldQueueReset
Sets some members of a Shield, .inside = true
** MPS port thread
protCatchThread
-> mach_msg waiting
-> protCatchOne thread involved has been stopped by OS
-> ArenaAccess
-> arenaClaimRingLock
-> LockClaimGlobal
-> LockClaim globalLock (static LockStruct)
-> RING_FOR uninteresting macrology
-> ArenaEnter for the 1 arena we have
** Global lock (uninteresting here)
LockInitGlobal
-> LockInit globalLock
-> LockInit globalLockRecLock
-> pthread_mutex_init with no interesting attrs
Sp, I'd say
- It's possible to freeze on macOS because of hitting a barrier, or
allocating Lisp objects. I don't believe that I would have overlooked
something preventing it.
- It's apparently very unlikely to happen, for me at least it
never happened in, don't know, half a year or so of daily usage.
Maybe one could make it happen when profiling for long enough.
- Only signal handlers are affected, and what you said about signal
handlers using Lisp and so on.
Hm.
next prev parent reply other threads:[~2024-12-30 11:53 UTC|newest]
Thread overview: 117+ 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-30 7:13 ` Gerd Möllmann
2024-12-30 7:23 ` Gerd Möllmann
2024-12-30 7:39 ` Helmut Eller
2024-12-30 7:51 ` Gerd Möllmann
2024-12-30 8:02 ` Helmut Eller
2024-12-30 8:47 ` Gerd Möllmann
2024-12-30 9:29 ` Helmut Eller
2024-12-30 9:47 ` Helmut Eller
2024-12-30 11:54 ` Gerd Möllmann
2024-12-30 10:05 ` Gerd Möllmann
2024-12-30 10:27 ` Helmut Eller
2024-12-30 11:53 ` Gerd Möllmann [this message]
2024-12-30 14:54 ` Eli Zaretskii
2024-12-30 15:05 ` Gerd Möllmann
2024-12-30 15:05 ` Pip Cet via Emacs development discussions.
2024-12-30 12:32 ` Pip Cet via Emacs development discussions.
2024-12-30 14:24 ` Eli Zaretskii
2024-12-30 14:59 ` Helmut Eller
2024-12-30 15:15 ` Eli Zaretskii
2024-12-30 15:24 ` Helmut Eller
2024-12-30 15:25 ` Pip Cet via Emacs development discussions.
2024-12-30 15:34 ` Gerd Möllmann
2024-12-30 19:02 ` Helmut Eller
2024-12-30 20:03 ` Pip Cet via Emacs development discussions.
2024-12-30 15:30 ` Gerd Möllmann
2024-12-30 16:57 ` Helmut Eller
2024-12-30 17:41 ` Gerd Möllmann
2024-12-30 17:49 ` Pip Cet via Emacs development discussions.
2024-12-30 18:33 ` Helmut Eller
2024-12-30 17:49 ` Eli Zaretskii
2024-12-30 18:37 ` Gerd Möllmann
2024-12-30 19:15 ` Eli Zaretskii
2024-12-30 19:55 ` Gerd Möllmann
2024-12-31 7:34 ` Helmut Eller
2024-12-31 9:19 ` Gerd Möllmann
2024-12-31 9:51 ` Helmut Eller
2024-12-31 10:00 ` Gerd Möllmann
2024-12-31 13:49 ` Pip Cet via Emacs development discussions.
2024-12-31 14:13 ` Eli Zaretskii
2024-12-31 9:51 ` Gerd Möllmann
2024-12-31 13:18 ` Eli Zaretskii
2024-12-31 14:15 ` Gerd Möllmann
2024-12-31 14:27 ` Eli Zaretskii
2024-12-31 15:05 ` Gerd Möllmann
2024-12-31 15:14 ` Eli Zaretskii
2024-12-31 15:20 ` Gerd Möllmann
2024-12-31 15:12 ` Helmut Eller
2024-12-31 15:31 ` Gerd Möllmann
2024-12-31 15:37 ` Helmut Eller
2024-12-31 15:39 ` Gerd Möllmann
2024-12-31 10:09 ` Pip Cet via Emacs development discussions.
2024-12-31 13:27 ` Eli Zaretskii
2024-12-31 14:29 ` Pip Cet via Emacs development discussions.
2024-12-31 14:34 ` Eli Zaretskii
2024-12-31 15:08 ` Gerd Möllmann
2024-12-31 15:07 ` Gerd Möllmann
2024-12-31 13:14 ` Eli Zaretskii
2024-12-31 14:19 ` Pip Cet via Emacs development discussions.
2024-12-31 14:31 ` Eli Zaretskii
2024-12-31 14:40 ` Helmut Eller
2024-12-31 14:55 ` Gerd Möllmann
2024-12-31 15:07 ` Eli Zaretskii
2024-12-31 15:13 ` Gerd Möllmann
2024-12-31 15:16 ` Helmut Eller
2025-01-02 8:37 ` Stefan Kangas
2025-01-02 9:05 ` Eli Zaretskii
2025-01-02 10:00 ` Helmut Eller
2025-01-02 12:34 ` Pip Cet via Emacs development discussions.
2025-01-02 13:08 ` Gerd Möllmann
2025-01-02 15:42 ` Eli Zaretskii
2025-01-02 17:56 ` Pip Cet via Emacs development discussions.
2024-12-30 12:42 ` Pip Cet via Emacs development discussions.
2024-12-30 13:40 ` Gerd Möllmann
2024-12-30 13:53 ` Pip Cet via Emacs development discussions.
2024-12-30 14:02 ` Gerd Möllmann
2024-12-30 14:32 ` Pip Cet via Emacs development discussions.
2024-12-30 14:52 ` Gerd Möllmann
2024-12-30 11:18 ` Pip Cet via Emacs development discussions.
2024-12-30 12:23 ` Gerd Möllmann
2024-12-30 11:11 ` Pip Cet via Emacs development discussions.
2024-12-30 12:13 ` Gerd Möllmann
2024-12-30 10:53 ` Pip Cet via Emacs development discussions.
2024-12-30 10:46 ` Pip Cet via Emacs development discussions.
2024-12-30 12:00 ` Gerd Möllmann
2024-12-30 12:07 ` 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.
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
2024-12-29 19:44 ` Pip Cet via Emacs development discussions.
2024-12-30 6:16 ` Gerd Möllmann
2024-12-30 12:51 ` Gerd Möllmann
2024-12-30 13:09 ` Pip Cet via Emacs development discussions.
2024-12-30 13:28 ` Gerd Möllmann
2024-12-30 5:24 ` Sean Devlin
2024-12-30 6:17 ` Gerd Möllmann
2024-12-30 5:23 ` Sean Devlin
-- 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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2h66le69u.fsf@gmail.com \
--to=gerd.moellmann@gmail.com \
--cc=eliz@gnu.org \
--cc=eller.helmut@gmail.com \
--cc=emacs-devel@gnu.org \
--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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).