all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Helmut Eller <eller.helmut@gmail.com>
Cc: pipcet@protonmail.com, gerd.moellmann@gmail.com, ofv@wanadoo.es,
	emacs-devel@gnu.org, acorallo@gnu.org
Subject: Re: SIGPROF + SIGCHLD and igc
Date: Sat, 28 Dec 2024 16:25:22 +0200	[thread overview]
Message-ID: <86frm7sx4d.fsf@gnu.org> (raw)
In-Reply-To: <877c7jlxsu.fsf@gmail.com> (message from Helmut Eller on Sat, 28 Dec 2024 14:52:33 +0100)

> From: Helmut Eller <eller.helmut@gmail.com>
> Cc: pipcet@protonmail.com,  gerd.moellmann@gmail.com,  ofv@wanadoo.es,
>   emacs-devel@gnu.org,  acorallo@gnu.org
> Date: Sat, 28 Dec 2024 14:52:33 +0100
> 
> On Sat, Dec 28 2024, Eli Zaretskii wrote:
> 
> >> It seems that the statement
> >> 
> >>   block SIGPROF while MPS holds the lock
> >> 
> >> is logically equivalent to
> >> 
> >>   deliver SIGPROF only while MPS does not hold the lock.
> >
> > Not necessarily.  Blocking a signals delays its delivery until the
> > time the signal is unblocked.  By contrast, what you propose will be
> > unable to profile code which caused MPS to take the lock.
> 
> Hmm, I think I disagree.  But I'm not sure of what sequence of events
> you're thinking of.

I'm thinking about a situation where SIGPROF was delivered while it
was blocked.  In that case, it will be re-delivered once we unblock
it.

By contrast, if we avoid delivering SIGPROF in the first place, it
will never be delivered until the next time SIGPROF is due.

So imagine a function FUNC that conses some Lisp object.  This calls
into MPS, which blocks SIGPROF, takes the arena lock, then does its
thing, then releases the lock and unblocks SIGPROF.  If SIGPROF
happened while MPS was working with SIGPROF blocked, then the moment
SIGPROF is unblocked, the SIGPROF handler in the main thread will be
called, and will have the opportunity to see that we were executing
FUNC.  By contrast, if the profiler thread avoided delivering SIGPROF
because it saw the arena locked, the next time the profiler thread
decides to deliver SIGPROF, execution could have already left FUNC,
and thus FUNC will not be in the profile.

I hope I made myself more clear this time.

> >> This variant might be bit easier to implement.  The "while MPS does not
> >> hold the lock" part can be implemented by claiming the lock in the
> >> profiler thread like so:
> >> 
> >>   mps_arena_t arena = global_igc->arena;
> >>   ArenaEnter (arena);
> >>   ... deliver SIGPROF part goes here ...
> >>   ArenaLeave (arena);
> >
> > What happens if, when we call ArenaEnter, MPS already holds the arena
> > lock?
> 
> Since MPS holds the lock, it would run in a different thread.

Yes, of course: we are talking about an implementation where the
profiler thread is separate, so the above code, which AFAIU runs in
the profiler thread, will be in a thread separate from the one where
MPS runs.

> So the profiler thread blocks until MPS releases the lock.
> 
> ArenaEnter uses non-recursive locks.

Hm... if ArenaEnter uses non-recursive locks, how come we get aborts
if some code tries to lock the arena when it is already locked?  IOW,
how is this situation different from what we already saw several times
in the crashes related to having SIGPROF delivered while MPS holds the
arena lock?

> 
> >> The "deliver SIGPROF" part goes like this:
> >> 
> >> 1. The profiler thread calls pthread_kill (SIGPROF, <main_thread>) and
> >>    then waits (on a pipe or whatever).
> >> 
> >> 2. The SIGPROF handler gets called and immediately notifies the profiler
> >>    thread (without waiting for a reply).  After that, it continues as
> >>    usual calling get_backtrace etc.
> >> 
> >> 3. The profiler thread awakes and releases the lock.
> >
> > This leaves a small window between the time the SIGPROF handler writes
> > to the pipe and the time the profiler thread calls ArenaLeave.  During
> > that window, the arena is locked, AFAIU, and we can still have
> > recursive-lock situations, which cause an abort.  Am I missing
> > something?
> 
> During that time window, the lock is held by the profiler thread.  The
> SIGPROF handler runs in the main thread.  If the main thread tries to
> claim the lock, it will block until the profiler thread releases it.

See above: I thought that such a situation triggers crashes.  I'm
probably missing something.

> >> Regarding deadlocks: the profiler thread holds the lock while it waits.
> >> So MPS should not be able to stop the profiler thread there.
> >
> > Which means we don't register the profiler thread with MPS, right?
> 
> I'm not sure. It may not be safe to call ArenaEnter in non-registered
> threads.

But if we do register the thread, then MPS _will_ stop it, no?



  reply	other threads:[~2024-12-28 14:25 UTC|newest]

Thread overview: 200+ 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-28 10:50                               ` Eli Zaretskii
2024-12-28 13:52                                 ` Helmut Eller
2024-12-28 14:25                                   ` Eli Zaretskii [this message]
2024-12-28 16:46                                     ` Helmut Eller
2024-12-28 17:35                                       ` Eli Zaretskii
2024-12-28 18:08                                         ` Helmut Eller
2024-12-28 19:00                                           ` Eli Zaretskii
2024-12-28 19:28                                             ` Helmut Eller
2024-12-28 19:32                                       ` Pip Cet via Emacs development discussions.
2024-12-28 19:51                                         ` Helmut Eller
2024-12-28 20:43                                           ` Pip Cet via Emacs development discussions.
2024-12-29  5:44                                             ` Eli Zaretskii
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-28 20:44                                                                       ` Paul Eggert
2024-12-29  5:47                                                                         ` 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 12:35                                                                         ` Pip Cet via Emacs development discussions.
2024-12-28 12:51                                                                           ` Gerd Möllmann
2024-12-28 13:13                                                                           ` Eli Zaretskii
2024-12-28  9:29                                                                       ` Eli Zaretskii
2024-12-28 13:12                                                                         ` Pip Cet via Emacs development discussions.
2024-12-28 14:08                                                                           ` 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 10:39                                                                       ` Eli Zaretskii
2024-12-28 11:07                                                                         ` Gerd Möllmann
2024-12-28 11:23                                                                           ` Gerd Möllmann
2024-12-28 14:04                                                                           ` Pip Cet via Emacs development discussions.
2024-12-28 14:25                                                                             ` Gerd Möllmann
2024-12-28 16:27                                                                             ` Eli Zaretskii
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.
2024-12-27 15:58                                                 ` Eli Zaretskii
2024-12-27 16:42                                                   ` Pip Cet via Emacs development discussions.
2024-12-28 18:02                                                     ` Eli Zaretskii
2024-12-28 21:05                                                       ` Pip Cet via Emacs development discussions.
2024-12-29  6:15                                                         ` Eli Zaretskii
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

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=86frm7sx4d.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=acorallo@gnu.org \
    --cc=eller.helmut@gmail.com \
    --cc=emacs-devel@gnu.org \
    --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 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.