[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: SIGPROF + SIGCHLD and igc
From: |
Eli Zaretskii |
Subject: |
Re: SIGPROF + SIGCHLD and igc |
Date: |
Fri, 27 Dec 2024 10:51:48 +0200 |
> From: Helmut Eller <eller.helmut@gmail.com>
> Cc: Eli Zaretskii <eliz@gnu.org>, pipcet@protonmail.com, ofv@wanadoo.es,
> emacs-devel@gnu.org, acorallo@gnu.org
> Date: Fri, 27 Dec 2024 09:08:00 +0100
>
> On Tue, Dec 24 2024, Gerd Möllmann wrote:
>
> >> I've looked at SIGPROF. From an admittedly brief look at this, I'd
> >> summarize my results as:
> >>
> >> - The important part is get_backtrace. The rest could be done elsewhere
> >> by posting that to a message board, or whatever the mechanism is at
> >> the end.
>
> I have an idea how to make a safer profiler. First, remember that MPS
> will stop mutator threads to protect its own consistency.
Can you spell out what are "mutator threads" in this context, so we
all are on the same page?
> What happens if we make the profiler its own thread? MPS will stop
> the profiler like normal mutator threads. This is useful and is as
> it should be.
AFAIU, it means the profiler will not be able to account for GC, but
let's put this aside for a moment.
> The problem now is how the profiler thread can do what get_backtrace
> does. We can use a protocol between the profiler thread and the main
> thread that goes like this:
>
> 1. The profiler periodically sends a signal, say SIGPROF, to the main
> thread.
>
> 2. In the signal handler for SIGPROF, the main thread synchronizes
> itself with the profiler by communicating over a pipe (like the Unix
> fathers did it). It sends some token to the profiler and waits.
>
> 3. The profiler receives the token and can now access the virtual
> machine state because the main thread waits. The profiler now does
> what get_backtrace does. After logging the stack snapshot, the
> profiler sends the token back to the main thread
>
> 4. The main thread receives the token, returns from the signal handler,
> and continues execution.
You are basically describing the way SIGPROF emulation is implemented
on Windows (see w32proc.c for the details). But I don't understand
why you need that pipe: doesn't pthreads allow one thread to stop the
other? If so, just make the "profiler thread" stop the main thread
instead of your step 2, and resume the main thread instead of your
step 4. Am I missing something?
> Note that the signal handler only communicates over the pipe and doesn't
> read or write any memory that could mess up MPS. The profiler thread
> doesn't run any signal handlers (other than those that MPS may use
> behind the scenes).
You basically emulate blocking of SIGPROF by relying on MPS to stop
the profiler thread when it cannot allow access to memory that could
mess up MPS, is that right?
> Another observation: MPS sends SIGXFSZ and SIGXCPU to stop and resume
> threads. We could intercept those signals and block SIGPROF while the
> thread is stopped. Obviously a hack, but could still be useful.
Do these signals get delivered to the main thread as well? Or only to
mutator threads?
- Re: SIGPROF + SIGCHLD and igc, (continued)
- Re: SIGPROF + SIGCHLD and igc, Eli Zaretskii, 2024/12/24
- Re: SIGPROF + SIGCHLD and igc, Helmut Eller, 2024/12/25
- Re: SIGPROF + SIGCHLD and igc, Eli Zaretskii, 2024/12/25
- Re: SIGPROF + SIGCHLD and igc, Eli Zaretskii, 2024/12/24
- Re: SIGPROF + SIGCHLD and igc, Gerd Möllmann, 2024/12/24
- Re: SIGPROF + SIGCHLD and igc, Helmut Eller, 2024/12/27
- Re: SIGPROF + SIGCHLD and igc,
Eli Zaretskii <=
- Re: SIGPROF + SIGCHLD and igc, Helmut Eller, 2024/12/27
- Re: SIGPROF + SIGCHLD and igc, Eli Zaretskii, 2024/12/27
- Re: SIGPROF + SIGCHLD and igc, Pip Cet, 2024/12/27
- Re: SIGPROF + SIGCHLD and igc, Helmut Eller, 2024/12/29
- Re: SIGPROF + SIGCHLD and igc, Eli Zaretskii, 2024/12/29
- Re: SIGPROF + SIGCHLD and igc, Helmut Eller, 2024/12/29
- Re: SIGPROF + SIGCHLD and igc, Eli Zaretskii, 2024/12/29
- Re: SIGPROF + SIGCHLD and igc, Helmut Eller, 2024/12/29
- Re: SIGPROF + SIGCHLD and igc, Gerd Möllmann, 2024/12/27
- Re: SIGPROF + SIGCHLD and igc, Helmut Eller, 2024/12/27