unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Pip Cet via "Emacs development discussions." <emacs-devel@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gerd.moellmann@gmail.com, ofv@wanadoo.es, emacs-devel@gnu.org,
	eller.helmut@gmail.com, acorallo@gnu.org
Subject: Re: Some experience with the igc branch
Date: Fri, 27 Dec 2024 14:34:22 +0000	[thread overview]
Message-ID: <87ldw15h6s.fsf@protonmail.com> (raw)
In-Reply-To: <86pllexwru.fsf@gnu.org>

"Eli Zaretskii" <eliz@gnu.org> writes:

>> Date: Thu, 26 Dec 2024 15:24:14 +0000
>> From: Pip Cet <pipcet@protonmail.com>
>> Cc: gerd.moellmann@gmail.com, ofv@wanadoo.es, emacs-devel@gnu.org, eller.helmut@gmail.com, acorallo@gnu.org
>>
>> "Eli Zaretskii" <eliz@gnu.org> writes:
>>
>> >> Date: Wed, 25 Dec 2024 17:40:42 +0000
>> >> From: Pip Cet <pipcet@protonmail.com>
>> >> Cc: Eli Zaretskii <eliz@gnu.org>, ofv@wanadoo.es, emacs-devel@gnu.org, eller.helmut@gmail.com, acorallo@gnu.org
>> >>
>> >> I haven't seen a technical argument against using separate stacks for
>> >> MPS and signals
>> >
>> > You haven't actually presented it.
>>
>> That's correct: we have an idea and a PoC, no design to discuss or
>> anything close to a proposal, at this point.
>>
>> My idea was to ask for obvious problems precluding or complicating this
>> approach.
>
> OK, but still, since you wrote the code to implement it, I guess you
> have at least some initial design ideas?  I hoped you could describe
> those ideas, so we could better understand what you have in mind, and
> provide a more useful feedback about possible problems, if any, with
> those ideas.

The idea is that the main thread, after initialization, never calls into
MPS itself.

Instead, we create an allocation thread, reacting to messages from the
main thread.

The allocation thread never actually does anything in parallel with the
main thread: its purpose is to provide a separate stack, not
parallelization.

All redirected MPS calls wait synchronously for the allocation thread to
respond.

This includes the MPS SIGSEGV handler, which calls into MPS, so it must
be directed to another thread.

All this makes the previously fast allocation path very slow, and we
need a workaround for that:

We ensure that we allocate at least 1MB (magic number here) at a time,
then split the area into MPS objects when we need to.  The assumption
that we can split MPS allocations is significant but justifiable,
because MPS will be in the same state after two successful back-to-back
allocations and a single allocation combining the two.

dflt_skip must never lie to MPS about the size of an object, though.
Once dflt_skip told MPS how to skip it (i.e. how large the object is),
we can no longer split that object.  It is another significant but
justifiable assumption that this happens rarely enough.

> In general, as I wrote earlier, there's nothing problematic with
> adding a C thread to Emacs.  But since (AFAIU) the suggestion is to
> run MPS from that thread, I think we should understand in more detail
> how can GC be run from a separate thread.  I expect that to have at
> least some impact on the Emacs code elsewhere, since the original
> Emacs design assumed that GC runs synchronously, and the rest of the
> Lisp machine is stopped while it does.

Thanks for explaining.

I don't think that's a new problem (when comparing the allocation tread
code to scratch/igc), as the allocation thread does not trigger GC any
more spontaneously than the main thread would.  The spontaneous garbage
collection you're worried about can be triggered by another thread
allocating memory while the main thread is busy inspecting it, but the
allocatiion thread only allocates memory while the main thread is
waiting, so this cannot happen.

It's safe to assume no MPS collection happens when:

1. there is no other thread which might trigger a memory barrier (the
allocation thread doesn't)
2. there is no other thread which might allocate memory (the allocation
thread cannot do so while the main thread is in a critical section)
3. we don't allocate memory
4. we don't trigger memory barriers

In practice, (4) is very hard to guarantee, so it might be easier to
decide now that code should always be written to assume spontaneous GC
is possible no matter where we are, which is the third step to actually
enabling fully concurrent GC.  Once we have made that decision,
we can actually test whether it breaks things to trigger spontaneous GCs
from another thread (I've experimented with this, and IIRC I fixed a bug
this uncovered, but only because that bug could also have occurred
without spontaneous GC).  Once we've done that, we can seriously
consider whether spontaneous GCs might be good for performance or
usability rather than debugging.

>> I've found a few minor things; so far, nothing unfixable, and no
>> significant effects on performance, but the fixes will have to become
>> part of the design and discussion.
>
> Right, so I'm asking to describe these aspects, so that others could
> consider them and possibly additional issues, and provide feedback or
> raise concerns about that.

The main aspect is "dflt_skip must never lie, but it can delay deciding
what the truth is until it's called".  We keep eating ice cream until
we're asked how much we've had, at which point we answer truthfully and
stop eating.

>> I think rr (time-travel/reverse debugging with acceptable performance)
>> support is important, but I think I'm the only one? It seems to be
>> really slow on this branch, though I don't know how fast it is on
>> scratch/igc.
>
> Well, reverse debugging currently doesn't work on Windows, so at least
> for that platform we cannot rely on that.

Considering that rr is in a kind of arms race anyway (rseqs, hardware
lock elision, the E-core/P-core split, and spectre workarounds all broke
rr when introduced, and require workarounds, and CPU manufacturers
appear to be fundamentally unable to agree on when an instruction should
be counted as "retired"), relying on it may be a bad idea.

Unfortunately, qemu doesn't seem to be seeing very active development in
this area, so the qemu instruction counting mechanism is unlikely to
provide usable reverse debugging in many situations.  And plain old GDB
reverse debugging is unbearably slow (and has been for decades), AFAIK.

So it's not a safe bet that we will continue to have usable reverse
debugging.  It may become even more necessary to have the compiler or
the CPU assist in providing it.

BTW, speaking of debugging, there's always a nuclear option for signals:
Use ptrace from another process to step through MPS and resend the
signal at the first possible moment.  Breaks GDB, hard to fix.

Pip




  reply	other threads:[~2024-12-27 14:34 UTC|newest]

Thread overview: 175+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-22 15:40 Some experience with the igc branch Óscar Fuentes
2024-12-22 17:18 ` Gerd Möllmann
2024-12-22 17:29 ` Gerd Möllmann
2024-12-22 17:41 ` Pip Cet via Emacs development discussions.
2024-12-22 17:56   ` Gerd Möllmann
2024-12-22 19:11   ` Óscar Fuentes
2024-12-23  0:05     ` Pip Cet via Emacs development discussions.
2024-12-23  1:00       ` Óscar Fuentes
2024-12-24 22:34         ` Pip Cet via Emacs development discussions.
2024-12-25  4:25           ` Freezing frame with igc Gerd Möllmann
2024-12-25 11:19             ` Pip Cet via Emacs development discussions.
2024-12-25 11:55             ` Óscar Fuentes
2024-12-23  3:42       ` Some experience with the igc branch Gerd Möllmann
2024-12-23  6:27     ` Jean Louis
2024-12-22 20:29   ` Helmut Eller
2024-12-22 20:50   ` Gerd Möllmann
2024-12-22 22:26     ` Pip Cet via Emacs development discussions.
2024-12-23  3:23       ` Gerd Möllmann
     [not found]         ` <m234ieddeu.fsf_-_@gmail.com>
     [not found]           ` <87ttaueqp9.fsf@protonmail.com>
     [not found]             ` <m2frme921u.fsf@gmail.com>
     [not found]               ` <87ldw6ejkv.fsf@protonmail.com>
     [not found]                 ` <m2bjx2h8dh.fsf@gmail.com>
2024-12-23 14:45                   ` Make Signal handling patch platform-dependent? Pip Cet via Emacs development discussions.
2024-12-23 14:54                     ` Gerd Möllmann
2024-12-23 15:11                       ` Eli Zaretskii
2024-12-23 13:35       ` Some experience with the igc branch Eli Zaretskii
2024-12-23 14:03         ` Discussion with MPS people Gerd Möllmann
2024-12-23 14:04           ` Gerd Möllmann
2024-12-23 15:07         ` Some experience with the igc branch Pip Cet via Emacs development discussions.
2024-12-23 15:26           ` Gerd Möllmann
2024-12-23 16:03             ` Pip Cet via Emacs development discussions.
2024-12-23 16:44               ` Eli Zaretskii
2024-12-23 17:16                 ` Pip Cet via Emacs development discussions.
2024-12-23 18:35                   ` Eli Zaretskii
2024-12-23 18:48                     ` Gerd Möllmann
2024-12-23 19:25                       ` Eli Zaretskii
2024-12-23 20:30                     ` Benjamin Riefenstahl
2024-12-23 23:39                       ` Pip Cet via Emacs development discussions.
2024-12-24 12:14                         ` Eli Zaretskii
2024-12-24 13:18                           ` Pip Cet via Emacs development discussions.
2024-12-24 13:42                           ` Benjamin Riefenstahl
2024-12-24  3:37                       ` Eli Zaretskii
2024-12-24  8:48                         ` Benjamin Riefenstahl
2024-12-24 13:52                           ` Eli Zaretskii
2024-12-24 13:54                             ` Benjamin Riefenstahl
2024-12-23 17:44               ` Gerd Möllmann
2024-12-23 19:00                 ` Eli Zaretskii
2024-12-23 19:37                   ` Eli Zaretskii
2024-12-23 20:49                   ` Gerd Möllmann
2024-12-23 21:43                     ` Helmut Eller
2024-12-23 21:49                       ` Pip Cet via Emacs development discussions.
2024-12-23 21:58                         ` Helmut Eller
2024-12-23 23:20                           ` Pip Cet via Emacs development discussions.
2024-12-24  5:38                             ` Helmut Eller
2024-12-24  6:27                               ` Gerd Möllmann
2024-12-24 10:09                               ` Pip Cet via Emacs development discussions.
2024-12-24  4:05                       ` Gerd Möllmann
2024-12-24  8:50                         ` Gerd Möllmann
2024-12-24  6:03                     ` SIGPROF + SIGCHLD and igc Gerd Möllmann
2024-12-24  8:23                       ` Helmut Eller
2024-12-24  8:39                         ` Gerd Möllmann
2024-12-25  9:22                           ` Helmut Eller
2024-12-25  9:43                             ` Gerd Möllmann
2024-12-24 13:05                         ` Eli Zaretskii
2024-12-25 10:46                           ` Helmut Eller
2024-12-25 12:45                             ` Eli Zaretskii
2024-12-24 12:54                       ` Eli Zaretskii
2024-12-24 12:59                         ` Gerd Möllmann
2024-12-27  8:08                       ` Helmut Eller
2024-12-27  8:51                         ` Eli Zaretskii
2024-12-27 14:53                           ` Helmut Eller
2024-12-27 15:09                             ` Pip Cet via Emacs development discussions.
2024-12-27 15:19                             ` Eli Zaretskii
2024-12-27  8:55                         ` Gerd Möllmann
2024-12-27 15:40                           ` Helmut Eller
2024-12-27 15:53                             ` Gerd Möllmann
2024-12-27 11:36                         ` Pip Cet via Emacs development discussions.
2024-12-27 16:14                           ` Helmut Eller
2024-12-28 10:02                             ` Helmut Eller
2024-12-23 23:37                   ` Some experience with the igc branch Pip Cet via Emacs development discussions.
2024-12-24  4:03                     ` Gerd Möllmann
2024-12-24 10:25                       ` Pip Cet via Emacs development discussions.
2024-12-24 10:50                         ` Gerd Möllmann
2024-12-24 13:15                         ` Eli Zaretskii
2024-12-24 12:26                       ` Eli Zaretskii
2024-12-24 12:56                         ` Gerd Möllmann
2024-12-24 13:19                           ` Pip Cet via Emacs development discussions.
2024-12-24 13:38                             ` Gerd Möllmann
2024-12-24 13:46                           ` Eli Zaretskii
2024-12-24 14:12                             ` Gerd Möllmann
2024-12-24 14:40                               ` Eli Zaretskii
2024-12-25  4:56                                 ` Gerd Möllmann
2024-12-25 12:19                                   ` Eli Zaretskii
2024-12-25 12:50                                     ` Gerd Möllmann
2024-12-25 13:00                                       ` Eli Zaretskii
2024-12-25 13:08                                         ` Gerd Möllmann
2024-12-25 13:26                                           ` Eli Zaretskii
2024-12-25 14:07                                             ` Gerd Möllmann
2024-12-25 14:43                                               ` Helmut Eller
2024-12-25 14:59                                                 ` Eli Zaretskii
2024-12-25 20:44                                                   ` Helmut Eller
2024-12-26  6:29                                                     ` Eli Zaretskii
2024-12-26  8:02                                                       ` Helmut Eller
2024-12-26  9:32                                                         ` Eli Zaretskii
2024-12-26 12:24                                                           ` Helmut Eller
2024-12-26 15:23                                                             ` Eli Zaretskii
2024-12-26 23:29                                                               ` Paul Eggert
2024-12-27  7:57                                                                 ` Eli Zaretskii
2024-12-27 19:34                                                                   ` Paul Eggert
2024-12-28  8:06                                                                     ` Eli Zaretskii
2024-12-25 15:02                                                 ` Gerd Möllmann
2024-12-25 13:09                                       ` Eli Zaretskii
2024-12-25 13:46                                         ` Gerd Möllmann
2024-12-25 14:37                                           ` Eli Zaretskii
2024-12-25 14:57                                             ` Gerd Möllmann
2024-12-25 15:28                                               ` Eli Zaretskii
2024-12-25 15:49                                                 ` Gerd Möllmann
2024-12-25 17:26                                                   ` Eli Zaretskii
2024-12-26  5:25                                                     ` Gerd Möllmann
2024-12-26  7:43                                                       ` Eli Zaretskii
2024-12-26  7:57                                                         ` Gerd Möllmann
2024-12-26 11:56                                                           ` Eli Zaretskii
2024-12-26 15:27                                                           ` Stefan Kangas
2024-12-26 19:51                                                             ` Gerd Möllmann
2024-12-27  9:45                                                               ` Gerd Möllmann
2024-12-27 13:56                                                                 ` Gerd Möllmann
2024-12-27 15:01                                                                   ` Pip Cet via Emacs development discussions.
2024-12-27 15:28                                                                     ` Eli Zaretskii
2024-12-27 15:47                                                                       ` Pip Cet via Emacs development discussions.
2024-12-27 16:18                                                                       ` Gerd Möllmann
2024-12-28  9:10                                                                         ` Stefan Kangas
2024-12-28  9:20                                                                           ` Gerd Möllmann
2024-12-28  9:24                                                                             ` Gerd Möllmann
2024-12-27 16:05                                                                     ` Gerd Möllmann
2024-12-27 17:00                                                                       ` Pip Cet via Emacs development discussions.
2024-12-27 16:37                                                                   ` Eli Zaretskii
2024-12-27 17:26                                                                     ` Pip Cet via Emacs development discussions.
2024-12-27 19:12                                                                       ` Gerd Möllmann
2024-12-28  7:36                                                                       ` Eli Zaretskii
2024-12-28  9:29                                                                       ` Eli Zaretskii
2024-12-27 18:21                                                                     ` Gerd Möllmann
2024-12-27 19:23                                                                       ` Pip Cet via Emacs development discussions.
2024-12-27 20:28                                                                         ` Gerd Möllmann
2024-12-28  6:08                                                                     ` Gerd Möllmann
2024-12-25 17:40                                       ` Pip Cet via Emacs development discussions.
2024-12-25 17:51                                         ` Eli Zaretskii
2024-12-26 15:24                                           ` Pip Cet via Emacs development discussions.
2024-12-26 15:57                                             ` Eli Zaretskii
2024-12-27 14:34                                               ` Pip Cet via Emacs development discussions. [this message]
2024-12-27 15:58                                                 ` Eli Zaretskii
2024-12-27 16:42                                                   ` Pip Cet via Emacs development discussions.
2024-12-26  5:27                                         ` Gerd Möllmann
2024-12-26  5:29                                         ` Gerd Möllmann
2024-12-24 21:18                               ` Pip Cet via Emacs development discussions.
2024-12-25  5:23                                 ` Gerd Möllmann
2024-12-25 10:48                                   ` Pip Cet via Emacs development discussions.
2024-12-25 13:40                                     ` Stefan Kangas
2024-12-25 17:03                                       ` Pip Cet via Emacs development discussions.
2024-12-26  5:22                                         ` Gerd Möllmann
2024-12-26  7:33                                           ` Eli Zaretskii
2024-12-26  8:02                                             ` Gerd Möllmann
2024-12-26 15:50                                             ` Stefan Kangas
2024-12-26 16:13                                               ` Eli Zaretskii
2024-12-26 19:40                                                 ` Gerd Möllmann
2024-12-26 17:01                                               ` Pip Cet via Emacs development discussions.
2024-12-26 19:45                                                 ` Gerd Möllmann
2024-12-26 20:05                                                   ` Eli Zaretskii
2024-12-26 20:12                                                     ` Gerd Möllmann
2024-12-26 16:12                                         ` Stefan Kangas
2024-12-26 17:05                                           ` Eli Zaretskii
2024-12-25 11:48                                   ` Helmut Eller
2024-12-25 11:58                                     ` Gerd Möllmann
2024-12-25 12:52                                     ` Eli Zaretskii
2024-12-25 12:31                                   ` Eli Zaretskii
2024-12-25 12:54                                     ` Gerd Möllmann
2024-12-24 12:11                     ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2024-12-27  9:49 Sean Devlin
2024-12-27 12:34 ` Eli Zaretskii
2024-12-28  1:55   ` Sean Devlin

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=87ldw15h6s.fsf@protonmail.com \
    --to=emacs-devel@gnu.org \
    --cc=acorallo@gnu.org \
    --cc=eliz@gnu.org \
    --cc=eller.helmut@gmail.com \
    --cc=gerd.moellmann@gmail.com \
    --cc=ofv@wanadoo.es \
    --cc=pipcet@protonmail.com \
    /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).