mwrap (Perl version) user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH 0/2] allow tracking allocations earlier
@ 2022-09-04  7:44 Eric Wong
  2022-09-04  7:44 ` [PATCH 1/2] Makefile.PL: check for execinfo on FreeBSD Eric Wong
  2022-09-04  7:44 ` [PATCH 2/2] create the `totals' rculfhash as early as possible Eric Wong
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2022-09-04  7:44 UTC (permalink / raw)
  To: mwrap-perl

This brings us closer to the Ruby version in being able to track
early allocations.  On FreeBSD, this requires properly loading
libexecinfo ourselves instead of relying on something else in
the process to load it.

Eric Wong (2):
  Makefile.PL: check for execinfo on FreeBSD
  create the `totals' rculfhash as early as possible

 Makefile.PL | 31 +++++++++++++++++++++++++++++++
 Mwrap.xs    |  7 ++++---
 2 files changed, 35 insertions(+), 3 deletions(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] Makefile.PL: check for execinfo on FreeBSD
  2022-09-04  7:44 [PATCH 0/2] allow tracking allocations earlier Eric Wong
@ 2022-09-04  7:44 ` Eric Wong
  2022-09-04  7:44 ` [PATCH 2/2] create the `totals' rculfhash as early as possible Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2022-09-04  7:44 UTC (permalink / raw)
  To: mwrap-perl

This is required for it to work reliably in FreeBSD if we hit a
code path which calls backtrace_symbols before BOOT:.  This will
allow the next commit to setup `totals' rculfhash earlier in the
constructor, rather than BOOT, allowing allocations to be
tracked as early as possible.
---
 Makefile.PL | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/Makefile.PL b/Makefile.PL
index c3caf6c..7ea7929 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -32,6 +32,37 @@ END
 chomp(my $INC = `$pkg_config --cflags liburcu-cds liburcu-bp`);
 my @writemakefile_args = ();
 
+use IO::Handle;
+STDOUT->autoflush(1);
+require ExtUtils::CBuilder;
+require File::Temp;
+my $cb = ExtUtils::CBuilder->new(quiet => $ENV{V} ? 0 : 1);
+my $d = File::Temp->newdir('mwrap-perl-build-XXXX');
+my $olderr;
+print '# checking for -lexecinfo... ';
+{
+	use autodie;
+	open my $fh, '>', "$d/execinfo.c";
+	print $fh <<EOM;
+#include <execinfo.h>
+int main(void) { return backtrace_symbols ? 1 : 0; }
+EOM
+	close $fh;
+	open $olderr, '+>&', *STDERR{IO};
+	open STDERR, '>', "$d/err.log";
+}
+eval {
+	my $obj = $cb->compile(source => "$d/execinfo.c");
+	$cb->link(objects => $obj, extra_linker_flags => '-lexecinfo');
+	$LIBS .= ' -lexecinfo';
+	say " yes on $^O";
+};
+say " no on $^O" if $@;
+{
+	use autodie;
+	open STDERR, '+>&', $olderr or die "dup stderr: $!";
+}
+
 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
 # the contents of the Makefile that is written.
 push @writemakefile_args, (

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] create the `totals' rculfhash as early as possible
  2022-09-04  7:44 [PATCH 0/2] allow tracking allocations earlier Eric Wong
  2022-09-04  7:44 ` [PATCH 1/2] Makefile.PL: check for execinfo on FreeBSD Eric Wong
@ 2022-09-04  7:44 ` Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2022-09-04  7:44 UTC (permalink / raw)
  To: mwrap-perl

This allows us to start tracking allocations before Perl calls
our BOOT code, which can be far later if it has to boot other
modules first.  As an LD_PRELOAD, the constructor can fire
before Perl's main().
---
 Mwrap.xs | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Mwrap.xs b/Mwrap.xs
index 510e211..092aaf4 100644
--- a/Mwrap.xs
+++ b/Mwrap.xs
@@ -144,6 +144,10 @@ __attribute__((constructor)) static void resolve_malloc(void)
 		}
 #endif /* !__FreeBSD__ */
 	}
+	CMM_STORE_SHARED(totals, lfht_new());
+	if (!CMM_LOAD_SHARED(totals))
+		fprintf(stderr, "failed to allocate totals table\n");
+
 	err = pthread_atfork(call_rcu_before_fork,
 				call_rcu_after_fork_parent,
 				call_rcu_after_fork_child);
@@ -805,9 +809,6 @@ BOOT:
 #ifndef PERL_IMPLICIT_CONTEXT
 	root_locating = &locating;
 #endif
-	CMM_STORE_SHARED(totals, lfht_new());
-	if (!CMM_LOAD_SHARED(totals))
-		fprintf(stderr, "failed to allocate totals table\n");
 
 PROTOTYPES: ENABLE
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-04  7:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-04  7:44 [PATCH 0/2] allow tracking allocations earlier Eric Wong
2022-09-04  7:44 ` [PATCH 1/2] Makefile.PL: check for execinfo on FreeBSD Eric Wong
2022-09-04  7:44 ` [PATCH 2/2] create the `totals' rculfhash as early as possible Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mwrap-perl.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).