ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Makefile.PL
Revision: 1.41
Committed: Wed Nov 1 01:21:21 2006 UTC (17 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_5, rel-2_1, stack_sharing
Changes since 1.40: +31 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 use ExtUtils::MakeMaker;
2    
3 root 1.7 use 5.005;
4 root 1.1
5 root 1.2 use Config;
6    
7 root 1.6 $|=1;
8    
9 root 1.2 $DEFINE = "";
10    
11     $DEFINE .= " -DHAVE_MMAP" if $Config{d_mmap} eq "define" && $Config{d_munmap} eq "define";
12    
13 root 1.34 if ($^O =~ /win32/i or $^O =~ /cygwin/ or $^O =~ /mswin/) {
14     $iface = 'w';
15 root 1.14 } elsif ($^O =~ /irix/) {
16     $iface = "i";
17 root 1.4 } elsif ($^O =~ /linux/) {
18 root 1.23 # default to setjmp/longjmp on non-x86...
19 root 1.33 $iface = $Config{archname} =~ /^(i[3456]86|amd64|x86_64)-/ ? "l" : "s";
20 root 1.24 } elsif ($^O =~ /(free|net|open)bsd/) {
21 root 1.40 # FreeBSD 4.x has ucontext.h but no makecontext et al. (see BUGS section of
22 root 1.24 # man context). Assume the same problem for all other BSDs.
23     $iface = "s";
24 root 1.8 } elsif ($^O =~ /solaris/) {
25     $iface = "s";
26 root 1.25 } elsif ($^O =~ /darwin/) {
27     $iface = "s";
28 root 1.40 } elsif (-e "/usr/include/ucontext.h") { # shame on this heuristic
29 root 1.3 $iface = "u";
30 root 1.2 } else {
31 root 1.3 $iface = "s";
32 root 1.2 }
33    
34 root 1.6 print <<EOF;
35    
36 root 1.38 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
37    
38 root 1.34 C context sharing: This option makes it possible to share the C stack and
39     context between many coroutines, resulting in large memory savings and
40     slight speed gains, at the cost of potential (but mostly theoretical)
41     segfaults. On my Linux/x86 machine this decreased the size of a new
42     coroutine from 9k to 5k, but the savings are much more apparent on
43     machines without mmap or good memory management.
44    
45 root 1.40 The algorithm relies on the non-fact that the same machine stack pointer
46 root 1.34 indicates the same function call nesting level, which usually works good
47 root 1.40 enough (no known cases of it failing are known) but might fail in theory.
48 root 1.34
49 root 1.40 The default (enabled) has been in use on productions servers for some
50 root 1.34 time now, without any problem reports, so you are encouraged to use the
51     default.
52 root 1.6
53     EOF
54    
55 root 1.27 if (prompt ("Do you want to enable C context sharing (y/n)", "y") !~ /^\s*n/i) {
56 root 1.34 print "\nC context sharing enabled.\n\n";
57 root 1.6 $DEFINE .= " -DCORO_LAZY_STACK";
58     }
59    
60 root 1.3 if ($iface) {
61     print <<EOF;
62 root 1.2
63 root 1.38 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
64    
65 root 1.40 Coro can use a number of methods to implement coroutines at the C
66     level. The default chosen is based on your current confguration and is
67     correct in most cases, but you still can chose between these alternatives:
68 root 1.34
69     u The unix 'ucontext.h' functions are relatively new and not implemented
70     or well-tested in older unices. They allow very fast coroutine creation
71     and reasonably fast switching, and, most importantly, are very stable.
72 root 1.4
73     s If the ucontext functions are not working or you don't want
74     to use them for other reasons you can try a workaround using
75 root 1.34 setjmp/longjmp/sigaltstack (also standard unix functions). Coroutine
76 root 1.4 creation is rather slow, but switching is very fast as well (often much
77     faster than with the ucontext functions). Unfortunately, glibc-2.1 and
78     below don't even feature a working sigaltstack.
79    
80 root 1.38 l GNU/Linux. Very old GNU/Linux systems (glibc-2.1 and below) need
81     this hack. Since it is very linux-specific it is also quite fast and
82 root 1.40 recommended even for newer versions; when it works, that is (currently
83     x86 and a few others only. If it compiles, it's usually ok).
84 root 1.14
85 root 1.40 i IRIX. For some reason, SGI really does not like to follow the single
86     unix specification (does that surprise you?), so this workaround might
87     be needed (it's fast), although [s] and [u] should also work now.
88 root 1.2
89 root 1.34 w Microsoft Windows. Try this on Microsoft Windows, although, as there is
90     no standard on how to do this under windows, this might work only on
91     cygwin or specific versions of msvc. Your problem.
92    
93 root 1.28 For most systems, the default chosen should be OK. If you experience
94     problems then you should experiment with this setting and/or turn off
95     optimizations (make OPTIMIZE=-O0).
96    
97 root 1.2 EOF
98 root 1.3
99     retry:
100 root 1.14
101 root 1.27 my $r = prompt "Use which implementation,\n" .
102 root 1.34 "<s>etjmp/longjump, <u>context, <i>rix, <l>inux or <w>indows?",
103 root 1.27 $iface;
104 root 1.3 $iface = lc $1 if $r =~ /(\S)/;
105    
106     if ($iface eq "u") {
107     $DEFINE .= " -DCORO_UCONTEXT";
108     print "\nUsing ucontext implementation\n\n";
109 root 1.15 conftest("TEST_makecontext");
110 root 1.3 } elsif ($iface eq "s") {
111     $DEFINE .= " -DCORO_SJLJ";
112     print "\nUsing setjmp/longjmp/sigaltstack implementation\n\n";
113 root 1.15 conftest("TEST_sigaltstack");
114 root 1.4 } elsif ($iface eq "l") {
115     $DEFINE .= " -DCORO_LINUX";
116     print "\nUsing linux-specific implementation\n\n";
117 root 1.14 } elsif ($iface eq "i") {
118     $DEFINE .= " -DCORO_IRIX";
119     print "\nUsing irix-specific implementation\n\n";
120 root 1.34 } elsif ($iface eq "w") {
121     $DEFINE .= " -DCORO_LOSER";
122     print "\nUsing windows-specific implementation\n\n";
123 root 1.3 } else {
124     print "\nUnknown implementation \"$iface\"\n";
125     goto retry;
126     }
127     } else {
128 root 1.16 print "\nUsing microsoft compatible coroutines\n\n";
129 root 1.3 }
130 root 1.2
131 root 1.36 print <<EOF;
132    
133 root 1.38 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
134    
135     Per-context stack size factor: Depending on your settings, Coro tries to
136     share the C stack as much as possible, but sometimes it needs to allocate
137     a new one. This setting controls the maximum size that gets allocated,
138 root 1.40 and should not be set too high, as memory and address space still is
139 root 1.38 wasted even if it's not fully used. The value entered will be multiplied
140     by sizeof(long), which is usually 4 on 32-bit systems, and 8 on 64-bit
141 root 1.37 systems.
142    
143 root 1.38 A setting of 16384 (the default) therefore corresponds to a 64k..128k
144 root 1.40 stack, which usually is ample space (you might even want to try 8192 or
145 root 1.38 lower if your program creates many coroutines).
146 root 1.37
147 root 1.41 On systems supporting mmap and dynamic memory management, the actual
148     memory usually gets allocated on demand, but with many large stacks you
149     can still run out of address space on your typical 32 bit platform.
150    
151 root 1.40 Some perls (mostly threaded ones and perl compiled under linux 2.6) and
152     some programs (inefficient regexes can use a lot of stack space) may
153     need much, much more: If Coro segfaults with weird backtraces (e.g. in a
154     function prologue) or in t/10_bugs.t, you might want to increase this to
155     65536 or more.
156 root 1.36
157 root 1.41 The default should be fine.
158    
159 root 1.36 EOF
160    
161 root 1.38 my $stacksize = prompt ("C stack size factor", "16384");
162 root 1.36 $DEFINE .= " -DSTACKSIZE=$stacksize";
163    
164     print "using a stacksize of $stacksize * sizeof(long)\n";
165    
166 root 1.38 print <<EOF;
167    
168     *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
169    
170 root 1.41 Coro can optionally put a guard area before each stack segment. When the
171     stack is too small and the access is not too far outside the stack (i.e.
172     within the guard area), then the program will safely segfault instead of
173     running into other data. The cost is some additional overhead with is
174     usually negligible, and extra use of address space.
175    
176     The guard area size currently needs to be specified in pages (typical
177     pagesizes are 4k and 8k). The guard area is only enabled on a few
178     hardcoded architectures and is ignored on others. The actual preprocessor
179     expression disables this feature if:
180    
181     !__i386 && !__x86_64 && !__powerpc && !__m68k \
182     && !__alpha && !__mips && !__sparc64
183    
184     The default, as usual, should be just fine.
185    
186     EOF
187    
188     my $stackguard = prompt ("Number of guard pages (0 disables)", "4");
189     $DEFINE .= " -DSTACKGUARD=$stackguard";
190    
191     print <<EOF;
192    
193     *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
194    
195 root 1.38 EOF
196 root 1.36
197 root 1.1 WriteMakefile(
198 root 1.2 NAME => "Coro::State",
199     VERSION_FROM => "State.pm",
200     DEFINE => $DEFINE,
201     DIR => [],
202 root 1.1 );
203 root 1.2
204 root 1.15 sub conftest {
205     my $type = shift;
206    
207     print "\nTrying to detect stack growth direction (for $type)\n";
208     print "You might see some warnings, this should not concern you.\n\n";
209     system "$Config{cc} $Config{ccflags} -D$type libcoro/conftest.c";
210    
211     my $res = qx<./a.out>;
212     $res =~ s/\s+$//;
213     my ($sp, $ss) = split /,/, $res;
214    
215     print "\n\n*****************************************************************************\n";
216     print "If the testsuite fails PLEASE provide the following information\n";
217 root 1.32 print "to Marc Lehmann <schmorp\@schmorp.de>: operating system name, version,\n";
218 root 1.15 print "architecture name and this string '$sp|$ss'. Thanks a lot!\n";#d#
219     print "*****************************************************************************\n\n";
220    
221     unlink "a.out";
222 root 1.17 unlink "conftestval";
223 root 1.15 }
224 root 1.2
225 root 1.26 print <<EOF if $^O =~ /linux/;
226    
227     *****************************************************************************
228     * *
229     * HEY!! You are using Linux! That's not at all bad, but if you get seg- *
230     * faults with Coro almost all the time please refer to README.linux-glibc *
231     * *
232     *****************************************************************************
233    
234     EOF
235 root 1.1