From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Gerd_M=C3=B6llmann?= Newsgroups: gmane.emacs.devel Subject: Re: SIGPROF + SIGCHLD and igc Date: Fri, 27 Dec 2024 09:55:57 +0100 Message-ID: References: <87o713wwsi.fsf@telefonica.net> <87ldw7fwet.fsf@protonmail.com> <87a5cnfj8t.fsf@protonmail.com> <86seqe4j4f.fsf@gnu.org> <87ttaucub8.fsf@protonmail.com> <87pllicrpi.fsf@protonmail.com> <864j2u442i.fsf@gnu.org> <87a5ch5z1b.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10369"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , pipcet@protonmail.com, ofv@wanadoo.es, emacs-devel@gnu.org, acorallo@gnu.org To: Helmut Eller Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Dec 27 09:56:22 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tR68q-0002Vl-NT for ged-emacs-devel@m.gmane-mx.org; Fri, 27 Dec 2024 09:56:20 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tR68Z-0007aB-P2; Fri, 27 Dec 2024 03:56:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tR68Y-0007a1-KG for emacs-devel@gnu.org; Fri, 27 Dec 2024 03:56:02 -0500 Original-Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tR68X-0007wX-0K; Fri, 27 Dec 2024 03:56:02 -0500 Original-Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5d7e527becaso11193945a12.3; Fri, 27 Dec 2024 00:56:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735289758; x=1735894558; darn=gnu.org; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xMT5dvUyhfhXDL92ay9lTLX8Ov3h+e5uaznNiPS1Ezg=; b=lPgiFPL3zIRpUQF5Hn7Mfv7jh46lDsVwJVsKxUTbuF2B61+iiL1dD6oK5dH+4v04Nm X5GTi99h8PQFqPEKm6E0y/pDi2dhCvuriw12I4WI937mpqTXqtqPtpvK01pEaTbiq/1z 2e3kdCPWP//sBMsLJG8i4aJnsT5zLiKkc+OEdCG6Eu1RT4plsIWSXIPh1zBEmajRyqjm laRA0g6A8rs6th36BIlguQ/HCbiWp3vFwIve0GeWKxeGupNFRCUIrTKoG6blrVCjiQ/t U+9gJuc+e3PMAxotPH+PNHDI1AMGqDNaJylsxCbnZHpt3BzczU2lW/ktpAKvnnETE90n WmFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735289758; x=1735894558; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=xMT5dvUyhfhXDL92ay9lTLX8Ov3h+e5uaznNiPS1Ezg=; b=OM/zTHzPgijbyl9dmcJom6of6dpNhrpzDKlDPrlgbD2BZnj1pHHc4Hz/gqDNc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cpJbuRYYcp2/6bA== X-Received: by 2002:a05:6402:2693:b0:5d6:688d:b683 with SMTP id 4fb4d7f45d1cf-5d81dd9c716mr57781467a12.9.1735289758248; Fri, 27 Dec 2024 00:55:58 -0800 (PST) Original-Received: from pro2 (p200300e0b74e5900bde19f98ca9a60df.dip0.t-ipconnect.de. [2003:e0:b74e:5900:bde1:9f98:ca9a:60df]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0f06c7a8sm1098824366b.182.2024.12.27.00.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Dec 2024 00:55:57 -0800 (PST) In-Reply-To: <87a5ch5z1b.fsf@gmail.com> (Helmut Eller's message of "Fri, 27 Dec 2024 09:08:00 +0100") Received-SPF: pass client-ip=2a00:1450:4864:20::52b; envelope-from=gerd.moellmann@gmail.com; helo=mail-ed1-x52b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:327179 Archived-At: Helmut Eller writes: > On Tue, Dec 24 2024, Gerd M=C3=B6llmann 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. 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. That sounds interesting. > 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. > > 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). I think I've seen a pipe being used in similar circumstances elsewhere, not in Emacs, in an actor system handling signals. Very interesting. I like it. > 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 you know if it does the same on macOS? It sounds like something the Mach heritage of macOS might kick in. > > Helmut