From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Helmut Eller Newsgroups: gmane.emacs.devel Subject: Re: MPS: profiler Date: Fri, 21 Jun 2024 10:21:10 +0200 Message-ID: <87frt63dvt.fsf@gmail.com> References: <87v823xvq1.fsf@localhost> <86cyobmmhc.fsf@gnu.org> <87r0crxung.fsf@localhost> <87le2zxsqx.fsf@localhost> <8634p6n7jd.fsf@gnu.org> <87tthm3gq2.fsf@gmail.com> <87sex6ags5.fsf@localhost> <87msne3flr.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31141"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Ihor Radchenko , Eli Zaretskii , emacs-devel@gnu.org To: Gerd =?utf-8?Q?M=C3=B6llmann?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Jun 21 10:22:05 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 1sKZX2-0007wM-3X for ged-emacs-devel@m.gmane-mx.org; Fri, 21 Jun 2024 10:22:04 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKZWG-0007Gi-FJ; Fri, 21 Jun 2024 04:21:16 -0400 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 1sKZWF-0007FS-GL for emacs-devel@gnu.org; Fri, 21 Jun 2024 04:21:15 -0400 Original-Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sKZWD-0002lm-L8; Fri, 21 Jun 2024 04:21:15 -0400 Original-Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-57d1d45ba34so1884468a12.3; Fri, 21 Jun 2024 01:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718958072; x=1719562872; darn=gnu.org; h=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=WLZ7cBvOJ8lm7AbwTVRW64t9d9WKLJXrAjJTkWsEzAE=; b=OvfxrSDXhxno1qPtILMDMPTubB2gah5Q+W53y781b8HiDi4UDb4hZIMlKioaDbC5od pfP/4B3luIyxlyLMWRiOGc0M0wB7HQwW4VhpqWKcjO7AAxqHr217hV93geYu1NSlAZZh v8dZV7erCAKvjaD+1SexXwlbAq/sKGRRvtFusUGtcbeZAkDUECd72y4pFSvDAxU3EwLW m4iAd76ktxTiIdZTgLb99Y1JDDdgbVNO8QmD4MKUPcEtRE5WWTCb1iQh3aVk+hLtel8O spQPmSM07g+icB9QM35ftJ16ZlmT1lEIzufHNAeKaiNyPMqB7wDPhO6fyl9yvzeYwUdV iklQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718958072; x=1719562872; h=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=WLZ7cBvOJ8lm7AbwTVRW64t9d9WKLJXrAjJTkWsEzAE=; b=B61G1jKRMacIwiUVJlzYPEv+QJfeF+/AKP0bEm8ZwITXCqtPWAwD+hZNF/czfTtdYT Dyxi+V3Q52meDVheynFAZItYTv51SfV0WLoZKCQBAmENACbQMvGXG/sdk3YL9DcfEezW EzgWeKy4ydE49lDx8niE6O8cN67SIoQyfX1QoIfmYoAekWninPcXD1lW4Zp7jt3UwqG9 LKRlp26Mqs2zQzA9oGLnFFTtwfuyV8PsfSkPh/+8t3p+OGCvFCIf4HEyd5qpcdM/O6Is fL+GzFoXv050I2SD00aWeZNh6WnTu0DARq3TUSkHuKxX32Uesx/pBrCACXwRcfZh1p3V tbWA== X-Forwarded-Encrypted: i=1; AJvYcCXwPB6armCzIBv+SuqaLMyTEKhy6DssdqTlFikMw8AsyPU4w6+rGSgBSWZC7a72680SKmHWECUoY5FahYTOBt6JOpXxuYO6DKGL5Bl3MOXHNzs= X-Gm-Message-State: AOJu0YwSL4SEPnPdZDLyFy7ja8fkRfX+6V1VyGCjdWlAcWlryZzPT6LB 3eRwcIEkkvD1ITmnGl5Itf9k2lWHPRj0QPcnxhdgWV2XG3a4NsK9Hqju2w== X-Google-Smtp-Source: AGHT+IHyZMl5Cm+9BVAnkw79lReCgb2nFAWQyKmA29UJYM8fXWFg3AjxLUd9ozk0o5pgISut383eyQ== X-Received: by 2002:a17:906:7943:b0:a6e:f62d:bd02 with SMTP id a640c23a62f3a-a6fab60b987mr546735166b.7.1718958071570; Fri, 21 Jun 2024 01:21:11 -0700 (PDT) Original-Received: from caladan ([31.177.116.19]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57d303d7aaasm605525a12.4.2024.06.21.01.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 01:21:11 -0700 (PDT) In-Reply-To: ("Gerd =?utf-8?Q?M=C3=B6llman?= =?utf-8?Q?n=22's?= message of "Fri, 21 Jun 2024 09:51:52 +0200") Received-SPF: pass client-ip=2a00:1450:4864:20::533; envelope-from=eller.helmut@gmail.com; helo=mail-ed1-x533.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, T_SCC_BODY_TEXT_LINE=-0.01 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:320373 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Fri, Jun 21 2024, Gerd M=C3=B6llmann wrote: >> There is a function mps_arena_busy, that might be useful. The doc says >> that it should only be used for debugging. But the implementation >> actually checks if the arena holds a lock. > > Yes, the SIBPROF handler could at least return early then. Perhaps something like this? --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Be-careful-while-profiling.patch >From d86baa8b2af2059b00c9cbec5f404008c73705a8 Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Fri, 21 Jun 2024 10:12:28 +0200 Subject: [PATCH] Be careful while profiling SIGPROF can be delived while the SIGSEGV handler is running. In this situation we shouldn't access MPS-managed memory. E.g. the profiler should not look inside closures when recording backtraces. * src/igc.h (igc_busy_p): New. * src/profiler.c (add_sample): When igc_busy_p, do the same as the old GC does when it is called during GC, i.e. only increace a counter and don't record a backtrace. * src/igc.c (igc_busy_p): Implement it. --- src/igc.c | 6 ++++++ src/igc.h | 1 + src/profiler.c | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/src/igc.c b/src/igc.c index ce4058fb25c..7ccde80e329 100644 --- a/src/igc.c +++ b/src/igc.c @@ -4021,6 +4021,12 @@ igc_alloc_dump (size_t nbytes) return base_to_client (block); } +bool +igc_busy_p (void) +{ + return mps_arena_busy (global_igc->arena); +} + /*********************************************************************** Init ***********************************************************************/ diff --git a/src/igc.h b/src/igc.h index 485f23090c2..fc80a92d1a8 100644 --- a/src/igc.h +++ b/src/igc.h @@ -154,6 +154,7 @@ #define EMACS_IGC_H char *igc_dump_finish_obj (void *client, enum igc_obj_type type, char *base, char *end); void *igc_alloc_dump (size_t nbytes); +bool igc_busy_p (void); # define eassert_not_mps() eassert (false) #else diff --git a/src/profiler.c b/src/profiler.c index 98d83bcf264..c24a92de6d7 100644 --- a/src/profiler.c +++ b/src/profiler.c @@ -341,7 +341,11 @@ record_backtrace (struct profiler_log *plog, EMACS_INT count) static void add_sample (struct profiler_log *plog, EMACS_INT count) { +#ifdef HAVE_MPS + if (igc_busy_p ()) +#else if (EQ (backtrace_top_function (), QAutomatic_GC)) /* bug#60237 */ +#endif /* Special case the time-count inside GC because the hash-table code is not prepared to be used while the GC is running. More specifically it uses ASIZE at many places where it does -- 2.39.2 --=-=-=--