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: SIGPROF + SIGCHLD and igc Date: Tue, 24 Dec 2024 07:03:53 +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> 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="2605"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: pipcet@protonmail.com, ofv@wanadoo.es, emacs-devel@gnu.org, eller.helmut@gmail.com, acorallo@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Dec 24 07:04:50 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 1tPy2D-0000WJ-SA for ged-emacs-devel@m.gmane-mx.org; Tue, 24 Dec 2024 07:04:49 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tPy1W-00088Y-DY; Tue, 24 Dec 2024 01:04:07 -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 1tPy1S-00086g-3Z for emacs-devel@gnu.org; Tue, 24 Dec 2024 01:04:02 -0500 Original-Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tPy1P-0007yQ-59; Tue, 24 Dec 2024 01:04:01 -0500 Original-Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-5d3f57582a2so10540833a12.1; Mon, 23 Dec 2024 22:03:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735020236; x=1735625036; 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=v9x7S3fTRjtetwbOSJ9A4qH5ExOLHI0oCav2FDLYAA0=; b=QoWfjZkc7iLJ/8Wyl3L79f2sVzENd4QOzyFcBBpI9w+kbUn5UoQuhTM76rHuYNRz+8 upMy1JWBPXUneruYyrTSqfaduuTVwOz3Yl6fkj1FNsHlYpYiNkUzVeUzDovfZGlHttKJ RZH33by+65T8SxuyEOjst9tuooLaPpPYfcMPq2hZK0x2nlXysT8UIIyDP6V+wSG7sfQ4 ZIzi59pIPoENm/Y1NeDFlczc9bbdKgp4qmbS5RaJhgTi9bgZExPPDi0z4APfAhMO3YHI A4SS1kKFGHgB8gm6r1LKqY0papOAamxU4z5fjxuoJ5dzjb2hrV32XKtnHFCm/qpVjlH+ nC3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735020236; x=1735625036; 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=v9x7S3fTRjtetwbOSJ9A4qH5ExOLHI0oCav2FDLYAA0=; b=Qt5HaaxdakgXJSgZavn27aasD2UkPBUdB0aseMOIIQw2Snm9ds1uP4c3KOduVuy+bQ QrtojK5u9J+ttQ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:907:7ea0:b0:aab:ef03:6d46 with SMTP id a640c23a62f3a-aac3349c908mr1440053066b.4.1735020235803; Mon, 23 Dec 2024 22:03:55 -0800 (PST) Original-Received: from pro2 (p200300e0b7326d00f9ed2197837c3ebd.dip0.t-ipconnect.de. [2003:e0:b732:6d00:f9ed:2197:837c:3ebd]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0e82f7desm607087266b.15.2024.12.23.22.03.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2024 22:03:54 -0800 (PST) In-Reply-To: ("Gerd =?utf-8?Q?M=C3=B6llmann=22'?= =?utf-8?Q?s?= message of "Mon, 23 Dec 2024 21:49:02 +0100") Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=gerd.moellmann@gmail.com; helo=mail-ed1-x534.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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:326965 Archived-At: (I've given this a new subject.) Gerd M=C3=B6llmann writes: > Eli Zaretskii writes: > >>> From: Gerd M=C3=B6llmann >>> Cc: Eli Zaretskii , ofv@wanadoo.es, emacs-devel@gnu.org, >>> eller.helmut@gmail.com, acorallo@gnu.org >>> Date: Mon, 23 Dec 2024 18:44:42 +0100 >>>=20 >>> BTW, do you know which signal handlers use Lisp, i.e. allocate Lisp >>> objects or access some? All? Or, would it be realistic to rewrite signal >>> handlers to not do that? >> >> SIGPROF does (it's the basis for our Lisp profiler). >> >> SIGCHLD doesn't run Lisp (I think), but it examines objects and data >> structures of the Lisp machine (those related to child processes). >> >>> One thing I've seen done elsewhere is to publish a message to a message >>> board so that it can be handled outside of the signal handler. Something >>> like that, you know what I mean. >> >> This is tricky for the profiler, because you want to sample the >> function in which you are right there and then, not some time later. >> >> For SIGCHLD this could work, but it might make Emacs slower in >> handling subprocesses (there are some Lisp packages that fire >> subprocesses at very high rate). > > Thanks. > > 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. > > - Didn't see get_backtrace or functions called from it allocating Lisp > objects. > > - It reads from a Lisp object because of > > #define specpdl (current_thread->m_specpdl) > #define specpdl_end (current_thread->m_specpdl_end) > #define specpdl_ptr (current_thread->m_specpdl_ptr) > > current_thread is a struct thread_state which is a PVEC_THREAD. > > - I remember that I wrote a scanner for the specpdl stacks, so that's > not a Lisp object but a root, so no problem here, I think. > > - struct thread_state allocation is done in igc.c via alloc_immovable in > igc_alloc_pseudovector. That allocated from from an AMS pool, which > doesn't use barriers. > > - It doesn't seem to access other Lisp objects except current_thread. > > That doesn't look bad, I think. Worth mentioning is perhaps that > directly after get_backtrace here > > static void > record_backtrace (struct profiler_log *plog, EMACS_INT count) > { > log_t *log =3D plog->log; > get_backtrace (log->trace, log->depth); > EMACS_UINT hash =3D trace_hash (log->trace, log->depth); > > we access Lisp objects in trace_hash when computing the hash and in the > other hash table code. IIUC that code counts hits with the same > backtrace. Don't know how long that takes. But if posting the backtrace > would take the same time, we would be on par. > > I'll try to also look at SIGCHLD at some later point, but Christmas, > family etc. > > Happy holidays! Been up a bit early, so... This is about SIGCHLD, and I must say I find it a bit hard to tell if all other platforms do the same. There are simply too many #if's to consider in the signal handling code. Anyway, what I see here: SIGCHLD doesn't do anything dangerous in the signal handler. Instead, the occurrence of SIGCHLD is added to a queue with enqueue_async_work and that's basically it. The work items in the queue are processed by process_pending_signals, outside of the signal handler. Very nice, that's how it should be :-). (And maybe, just as an inspiration, one could use that construct for SIGPROF?) So, there is actually no problem at all with SIGCHLD that I can see.=20 My personal summary for SIGPROF + SIGCHLD at this point: - I recommend rewriting SIGPROF handling in the way I tried to describe, possibly using the existing work queue mechanism. Everything else looks too complicated to me. =20=20 - Lisp allocation in signal handlers cannot exist because alloc.c is not reentrant which means we would crash with the old GC. We don't need anything extra for that in igc. - No longer wondering why macOS does not show any problems in that whole area. The only problem is SIGPROF accessing Lisp objects, and the memory barrier is not a problem on macOS because it doesn't use signals. Please double-check!