ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Makefile.PL
(Generate patch)

Comparing Coro/Coro/Makefile.PL (file contents):
Revision 1.37 by root, Mon Dec 12 20:31:23 2005 UTC vs.
Revision 1.57 by root, Fri May 30 21:34:52 2008 UTC

1use 5.005;
2
3use strict;
1use ExtUtils::MakeMaker; 4use ExtUtils::MakeMaker;
2
3use 5.005;
4
5use Config; 5use Config;
6 6
7$|=1; 7$|=1;
8 8
9$DEFINE = ""; 9my $DEFINE;
10my @LIBS = [];
11
12# check for completely broken platforms (such as netbsd)
13if ($Config{usethreads} && $^O eq "netbsd") {
14 print <<EOF;
15
16***
17*** Your platform is BROKEN - netbsd pthreads are known to be completely broken.
18*** There is *no* way to implement coroutines on this platform until the bugs
19*** are fixed (this has been true for at least netbsd version 4.0).
20***
21*** This affects many modules currently, so the recommended build option
22*** for perl is to DISABLE THREAD support - it serves no practical purpose
23*** on POSIX systems anyways, except that it slows down your programs a lot
24*** and uses a lot more memory than fork (perl threads do not give you threads,
25*** they are only windows-process emulation ported to unix).
26***
27*** If you really want to try building Coro on your broken platform, enter
28*** "yes" at the prompt - report back if the bugs is fixed please. (Oh,
29*** and try out BDB or IO::AIO which suffer from other threading bugs on
30*** netbsd that never seem to get fixed).
31***
32
33EOF
34
35 print "prompt> "; <STDIN> =~ /^yes/ or exit 1;
36}
37
38print <<EOF;
39
40*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
41
42Coro has a number of configuration options. Due to its maturity, the
43defaults that Coro chooses are usually fine, so you can decide to skip
44these questions. Only if something went wrong you should select 'n'
45here and manually configure Coro, and, of course, report this to the
46maintainer :)
47
48EOF
49
50if (prompt ("Skip further questions and use defaults (y/n)?", "y") =~ /[yY]/) {
51 $ENV{PERL_MM_USE_DEFAULT} = 1;
52}
53
10 54
11$DEFINE .= " -DHAVE_MMAP" if $Config{d_mmap} eq "define" && $Config{d_munmap} eq "define"; 55$DEFINE .= " -DHAVE_MMAP" if $Config{d_mmap} eq "define" && $Config{d_munmap} eq "define";
12 56
57my $iface;
58
59if (exists $ENV{CORO_INTERFACE}) {
60 $iface = $ENV{CORO_INTERFACE};
61
13if ($^O =~ /win32/i or $^O =~ /cygwin/ or $^O =~ /mswin/) { 62} elsif ($^O =~ /win32/i or $^O =~ /cygwin/ or $^O =~ /mswin/) {
14 $iface = 'w'; 63 $iface = 'w';
64
15} elsif ($^O =~ /irix/) { 65} elsif ($^O =~ /irix/) {
16 $iface = "i"; 66 $iface = "i";
67
17} elsif ($^O =~ /linux/) { 68} elsif ($^O =~ /linux/) {
18 # default to setjmp/longjmp on non-x86... 69 # default to assembly on x86 and x86_64, and setjmp on others
19 $iface = $Config{archname} =~ /^(i[3456]86|amd64|x86_64)-/ ? "l" : "s"; 70 $iface = $Config{archname} =~ /^(i[3456]86|amd64|x86_64)-/ && $Config{optimize} =~ /-O/ ? "a" : "s";
71
20} elsif ($^O =~ /(free|net|open)bsd/) { 72} elsif ($^O =~ /(free|net|open)bsd/) {
21 # FreeBSD 4.x has ucontext.h but no makecontext et al (see BUGS section of 73 # FreeBSD 4.x has ucontext.h but no makecontext et al. (see BUGS section of
22 # man context). Assume the same problem for all other BSDs. 74 # man context). Assume the same problem for all other BSDs.
75
76 # netbsd is totally broken (pthreads are incomaptible with ucontext or other stack switchign mechanisms)
77
78 # therefore, default to setjmp
23 $iface = "s"; 79 $iface = "s";
80
24} elsif ($^O =~ /solaris/) { 81} elsif ($^O =~ /solaris/) {
25 $iface = "s"; 82 $iface = "s";
83
26} elsif ($^O =~ /darwin/) { 84} elsif ($^O =~ /darwin/) {
27 $iface = "s"; 85 $iface = "s";
86
28} elsif (-e "/usr/include/ucontext.h") { 87} elsif (-e "/usr/include/ucontext.h") { # shame on this heuristic
29 $iface = "u"; 88 $iface = "u";
89
30} else { 90} else {
31 $iface = "s"; 91 $iface = "s";
32} 92}
33 93
34print <<EOF; 94print <<EOF;
35 95
36C context sharing: This option makes it possible to share the C stack and 96*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
37context between many coroutines, resulting in large memory savings and
38slight speed gains, at the cost of potential (but mostly theoretical)
39segfaults. On my Linux/x86 machine this decreased the size of a new
40coroutine from 9k to 5k, but the savings are much more apparent on
41machines without mmap or good memory management.
42 97
43This algorithm relies on the non-fact that the same machine stack pointer 98Coro can use a number of methods to implement coroutines at the C
44indicates the same function call nesting level, which usually works good 99level. The default chosen is based on your current confguration and is
45enough (no known cases of it failing are known) but might fail.
46
47The default (enabled) has been in-use on productions servers for some
48time now, without any problem reports, so you are encouraged to use the
49default.
50
51EOF
52
53if (prompt ("Do you want to enable C context sharing (y/n)", "y") !~ /^\s*n/i) {
54 print "\nC context sharing enabled.\n\n";
55 $DEFINE .= " -DCORO_LAZY_STACK";
56}
57
58if ($iface) {
59 print <<EOF;
60
61Coro can use various ways to implement coroutines at C level. The
62default is correct in most cases, but you still can chose between these 100correct in most cases, but you still can chose between these alternatives:
63alternatives:
64 101
65u The unix 'ucontext.h' functions are relatively new and not implemented 102u The unix 'ucontext.h' functions are relatively new and not implemented
66 or well-tested in older unices. They allow very fast coroutine creation 103 or well-tested in older unices. They allow very fast coroutine creation
67 and reasonably fast switching, and, most importantly, are very stable. 104 and reasonably fast switching, and, most importantly, are very stable.
105 It is, however, usually slower than the other alternatives due to an
106 extra syscall done by swapcontext.
68 107
69s If the ucontext functions are not working or you don't want 108s If the ucontext functions are not working or you don't want
70 to use them for other reasons you can try a workaround using 109 to use them for other reasons you can try a workaround using
71 setjmp/longjmp/sigaltstack (also standard unix functions). Coroutine 110 setjmp/longjmp/sigaltstack (also standard unix functions). Coroutine
72 creation is rather slow, but switching is very fast as well (often much 111 creation is rather slow, but switching is very fast (often much faster
73 faster than with the ucontext functions). Unfortunately, glibc-2.1 and 112 than with the ucontext functions). Unfortunately, glibc-2.1 and
74 below don't even feature a working sigaltstack. 113 below don't even feature a working sigaltstack. You cannot use this
114 implementation if some other code uses SIGUSR2 or you plan to
115 create coroutines from an alternative signal stack, as both are being
116 used for coroutine creation.
75 117
118a Handcoded assembly. This is the fastest and most compatible method
119 with the least side effects, if it works, that is. It has been tested
120 on GNU/Linux x86 and x86_64 systems and should work on all x86/x86_64
121 systems using the SVR ELF ABI (it is also reported to be working on
122 Strawberry Perl for Windows using MinGW). This is the recommended
123 method on supported platforms. Note that you usually have to compile
124 this module with optimisation enabled for this method to work, and
125 also more esoteric switches such as -fomit-leaf-frame-pointer might be
126 required. When i doubt, use another method, such as (s)etjmp/longjmp.
127
76l GNU/Linux. Older GNU/Linux systems (glibc-2.1 and below) need this 128l GNU/Linux. Very old GNU/Linux systems (glibc-2.1 and below) need
77 hack. Since it is very linux-specific it is also quite fast for newer 129 this hack. Since it is very linux-specific it is also quite fast and
78 versions; when it works, that is (currently x86 only)... 130 recommended even for newer versions; when it works, that is (currently
131 x86 and a few others only. If it compiles, it's usually ok). Newer
132 glibc versions (>= 2.5) stop working with this implementation again.
79 133
80i IRIX. For some reason, SGI really does not like to follow the unix 134i IRIX. For some reason, SGI really does not like to follow the single
81 standard (does that surprise you?), so this workaround might be needed 135 unix specification (does that surprise you?), so this workaround might
82 (it's fast), although s and u should also work now. 136 be needed (it's fast), although [s] and [u] should also work now.
83 137
84w Microsoft Windows. Try this on Microsoft Windows, although, as there is 138w Microsoft Windows. Try this on Microsoft Windows when using Cygwin or
85 no standard on how to do this under windows, this might work only on 139 the MSVC compilers (e.g. ActiveState Perl, but see "a" for Strawberry
86 cygwin or specific versions of msvc. Your problem. 140 Perl), although, as there is no standard on how to do this under
141 windows, different enviroments might work differently. Doh.
142
143p Use pthread API. Try to avoid this option, it was only created to make
144 a point about the programming language shootout and might leak threads.
145 It might work fine as a last resort, however.
87 146
88For most systems, the default chosen should be OK. If you experience 147For most systems, the default chosen should be OK. If you experience
89problems then you should experiment with this setting and/or turn off 148problems then you should experiment with this setting and/or turn
90optimizations (make OPTIMIZE=-O0). 149optimisations on or off (make OPTIMIZE=-O0).
91 150
92EOF 151EOF
93 152
94retry: 153retry:
95 154
96 my $r = prompt "Use which implementation,\n" . 155my $r = prompt "Use which implementation,\n" .
97 "<s>etjmp/longjump, <u>context, <i>rix, <l>inux or <w>indows?", 156 "<s>et/longjump, <u>context, <a>ssembly, <i>rix, <l>inux or <w>indows?",
98 $iface; 157 $iface;
99 $iface = lc $1 if $r =~ /(\S)/; 158$iface = lc $1 if $r =~ /(\S)/;
100 159
101 if ($iface eq "u") { 160if ($iface eq "u") {
102 $DEFINE .= " -DCORO_UCONTEXT"; 161 $DEFINE .= " -DCORO_UCONTEXT";
103 print "\nUsing ucontext implementation\n\n"; 162 print "\nUsing ucontext implementation\n\n";
104 conftest("TEST_makecontext"); 163 conftest("TEST_makecontext");
105 } elsif ($iface eq "s") { 164} elsif ($iface eq "s") {
106 $DEFINE .= " -DCORO_SJLJ"; 165 $DEFINE .= " -DCORO_SJLJ";
107 print "\nUsing setjmp/longjmp/sigaltstack implementation\n\n"; 166 print "\nUsing setjmp/longjmp/sigaltstack implementation\n\n";
108 conftest("TEST_sigaltstack"); 167 conftest("TEST_sigaltstack");
109 } elsif ($iface eq "l") { 168} elsif ($iface eq "l") {
110 $DEFINE .= " -DCORO_LINUX"; 169 $DEFINE .= " -DCORO_LINUX";
111 print "\nUsing linux-specific implementation\n\n"; 170 print "\nUsing linux-specific implementation\n\n";
112 } elsif ($iface eq "i") { 171} elsif ($iface eq "i") {
113 $DEFINE .= " -DCORO_IRIX"; 172 $DEFINE .= " -DCORO_IRIX";
114 print "\nUsing irix-specific implementation\n\n"; 173 print "\nUsing irix-specific implementation\n\n";
115 } elsif ($iface eq "w") { 174} elsif ($iface eq "w") {
116 $DEFINE .= " -DCORO_LOSER"; 175 $DEFINE .= " -DCORO_LOSER";
117 print "\nUsing windows-specific implementation\n\n"; 176 print "\nUsing windows-specific implementation\n\n";
118 } else { 177} elsif ($iface eq "a") {
119 print "\nUnknown implementation \"$iface\"\n"; 178 $DEFINE .= " -DCORO_ASM";
120 goto retry; 179 print "\nUsing handcoded assembly implementation\n\n";
121 } 180} elsif ($iface eq "p") {
181 $DEFINE .= " -DCORO_PTHREAD";
182 @LIBS = ["-lpthread"];
183 print "\nUsing pthread implementation\n\n";
122} else { 184} else {
123 print "\nUsing microsoft compatible coroutines\n\n"; 185 print "\nUnknown implementation \"$iface\"\n";
186 goto retry;
124} 187}
125 188
126print <<EOF; 189print <<EOF;
127 190
191*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
192
128Per-context stack size: Depending on your settings, Coro tries to share 193Per-context stack size factor: Depending on your settings, Coro tries to
129the C stack as much as possible, but sometimes it needs to allocate a 194share the C stack as much as possible, but sometimes it needs to allocate
130new one. This setting controls the maximum size that gets allocated, 195a new one. This setting controls the maximum size that gets allocated,
131and should not be too high, memory and address space still gets wasted 196and should not be set too high, as memory and address space still is
132even if it's not fully used. The value entered will be multiplied by 197wasted even if it's not fully used. The value entered will be multiplied
133sizeof(long), which is usually 4 on 32-bit systems, and 8 on 64-bit 198by sizeof(long), which is usually 4 on 32-bit systems, and 8 on 64-bit
134systems. 199systems.
135 200
136A setting of 16384 (the default) therefore to a 64k..128k stack, which 201A setting of 16384 (the default) therefore corresponds to a 64k..128k
137usually is ample space (you might wnat to try 8192 or lower if your 202stack, which usually is ample space (you might even want to try 8192 or
138program creates many coroutines). 203lower if your program creates many coroutines).
139 204
140Some perls (mostly threaded ones) may need much, much more: If Coro 205On systems supporting mmap and dynamic memory management, the actual
141segfaults with weird backtraces (e.g. in a function prologue) or in 206memory usually gets allocated on demand, but with many large stacks you
142t/10_bugs.t, you might want to increase this to 65536 or more (debian 207can still run out of address space on your typical 32 bit platform.
143might require this).
144 208
145EOF 209Some perls (mostly threaded ones and perl compiled under linux 2.6) and
210some programs (inefficient regexes can use a lot of stack space) may
211need much, much more: If Coro segfaults with weird backtraces (e.g. in a
212function prologue) or in t/10_bugs.t, you might want to increase this to
21365536 or more.
146 214
215The default should be fine, and can be changed at runtime with
216Coro::State::cctx_stacksize.
217
218EOF
219
147my $stacksize = prompt ("C Stack Size", "16384"); 220my $stacksize = prompt ("C stack size factor?", "16384");
148$DEFINE .= " -DSTACKSIZE=$stacksize"; 221$DEFINE .= " -DCORO_STACKSIZE=$stacksize";
149 222
150print "using a stacksize of $stacksize * sizeof(long)\n"; 223print "using a stacksize of $stacksize * sizeof(long)\n";
151 224
152print "\n"; 225print <<EOF;
226
227*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
228
229Coro can optionally put a guard area before each stack segment. When the
230stack is too small and the access is not too far outside the stack (i.e.
231within the guard area), then the program will safely segfault instead of
232running into other data. The cost is some additional overhead with is
233usually negligible, and extra use of address space.
234
235The guard area size currently needs to be specified in pages (typical
236pagesizes are 4k and 8k). The guard area is only enabled on a few
237hardcoded architectures and is ignored on others. The actual preprocessor
238expression disables this feature if:
239
240 !__i386 && !__x86_64 && !__powerpc && !__m68k \
241 && !__alpha && !__mips && !__sparc64
242
243The default, as usual, should be just fine.
244
245EOF
246
247my $stackguard = prompt ("Number of guard pages (0 disables)?", "4");
248$DEFINE .= " -DCORO_STACKGUARD=$stackguard";
249
250print <<EOF;
251
252*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
253
254Coro can tell valgrind about its stacks and so reduce spurious warnings
255where valgrind would otherwise complain about possible stack switches.
256
257Enabling this does not incur visible runtime or memory overhead, but it
258requires that you have the <valgrind/valgrind.h> header file available.
259
260Valgrind support is completely optional, so the default of disabling it is
261the safe choice.
262
263EOF
264
265my $valgrind = prompt ("Enable valgrind support (y/n)?",
266 -r "/usr/include/valgrind/valgrind.h" ? "y" : "n");
267$DEFINE .= " -DCORO_USE_VALGRIND=1" if $valgrind =~ /[yY]/;
268
269
270print <<EOF;
271
272*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
273
274Coro can use (or even trick) some perl functions into doing what it needs
275instead of relying on (some) of its own functions. This might increase
276chances that it compiles and works, but it could just as well result in
277memory leaks, crashes or silent data corruption. It certainly does result
278in slightly slower speed and higher memory consumption, though, so YOU
279SHOULD ENABLE IT ONLY AS A LAST RESORT.
280
281EOF
282
283my $use_internals = prompt ("Prefer perl functions over coro functions (y/n)?", "n");
284$DEFINE .= " -DCORO_PREFER_PERL_FUNCTIONS=1" if $use_internals =~ /[yY]/;
285
286print <<EOF;
287
288*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
289
290EOF
153 291
154WriteMakefile( 292WriteMakefile(
155 NAME => "Coro::State", 293 NAME => "Coro::State",
156 VERSION_FROM => "State.pm", 294 VERSION_FROM => "State.pm",
157 DEFINE => $DEFINE, 295 DEFINE => $DEFINE,
296 LIBS => @LIBS,
158 DIR => [], 297 DIR => [],
159); 298);
160 299
161sub conftest { 300sub conftest {
162 my $type = shift; 301 my $type = shift;
177 316
178 unlink "a.out"; 317 unlink "a.out";
179 unlink "conftestval"; 318 unlink "conftestval";
180} 319}
181 320
182print <<EOF if $^O =~ /linux/;
183
184*****************************************************************************
185* *
186* HEY!! You are using Linux! That's not at all bad, but if you get seg- *
187* faults with Coro almost all the time please refer to README.linux-glibc *
188* *
189*****************************************************************************
190
191EOF
192

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines