Interrupts vs signals - Mailing list pgsql-hackers

From Thomas Munro
Subject Interrupts vs signals
Date
Msg-id CA+hUKG+3MkS21yK4jL4cgZywdnnGKiBg0jatoV6kzaniBmcqbQ@mail.gmail.com
Whole thread Raw
Responses Re: Interrupts vs signals  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
Hi,

I wonder if we really need signals to implement interrupts.  Given
that they are non-preemptive/cooperative (work happens at the next
CFI()), why not just use shared memory flags and latches?  That skips
a bunch of code, global variables and scary warnings about programming
in signal handlers.

I sketched out some code to try that a few months back, while
speculating about bite-sized subproblems that would come up if each
backend is, one day, a thread.

There are several other conditions that are also handled by
CHECK_FOR_INTERRUPTS(), but are not triggered by other backends
sending  signals, or are set by other signal handlers (SIGALRM,
SIGQUIT).  One idea is to convert those into "procsignals" too, for
consistency.  In the attached, they can be set (ie by the same
backend) with ProcSignalRaise(), but it's possible that in future we
might have a reason for another backend to set them too, so it seems
like a good idea to have a single system, effectively merging the
concepts of "procsignals" and "interrupts".

There are still a few more ad hoc (non-ProcSignal) uses of SIGUSR1 in
the tree.  For one thing, we don't allow the postmaster to set
latches; if we gave up on that rule, we wouldn't need the bgworker
please-signal-me thing.  Also the logical replication launcher does
the same sort of thing for no apparent reason.  Changed in the
attached -- mainly so I could demonstrate that check-world passes with
SIGUSR1 ignored.

The attached is only experiment grade code: in particular, I didn't
quite untangle the recovery conflict flags properly.  It's also doing
function calls where some kind of fast inlined magic is probably
required, and I probably have a few other details wrong, but I figured
it was good enough to demonstrate the concept.

Attachment

pgsql-hackers by date:

Previous
From: Greg Stark
Date:
Subject: Re: Extending amcheck to check toast size and compression
Next
From: John Naylor
Date:
Subject: Re: [RFC] speed up count(*)