ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Makefile.PL
Revision: 1.40
Committed: Fri Dec 16 01:44:11 2005 UTC (18 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_0, rel-1_9, rel-1_7
Changes since 1.39: +20 -20 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.40 Some perls (mostly threaded ones and perl compiled under linux 2.6) and
148     some programs (inefficient regexes can use a lot of stack space) may
149     need much, much more: If Coro segfaults with weird backtraces (e.g. in a
150     function prologue) or in t/10_bugs.t, you might want to increase this to
151     65536 or more.
152 root 1.36
153     EOF
154    
155 root 1.38 my $stacksize = prompt ("C stack size factor", "16384");
156 root 1.36 $DEFINE .= " -DSTACKSIZE=$stacksize";
157    
158     print "using a stacksize of $stacksize * sizeof(long)\n";
159    
160 root 1.38 print <<EOF;
161    
162     *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
163    
164     EOF
165 root 1.36
166 root 1.1 WriteMakefile(
167 root 1.2 NAME => "Coro::State",
168     VERSION_FROM => "State.pm",
169     DEFINE => $DEFINE,
170     DIR => [],
171 root 1.1 );
172 root 1.2
173 root 1.15 sub conftest {
174     my $type = shift;
175    
176     print "\nTrying to detect stack growth direction (for $type)\n";
177     print "You might see some warnings, this should not concern you.\n\n";
178     system "$Config{cc} $Config{ccflags} -D$type libcoro/conftest.c";
179    
180     my $res = qx<./a.out>;
181     $res =~ s/\s+$//;
182     my ($sp, $ss) = split /,/, $res;
183    
184     print "\n\n*****************************************************************************\n";
185     print "If the testsuite fails PLEASE provide the following information\n";
186 root 1.32 print "to Marc Lehmann <schmorp\@schmorp.de>: operating system name, version,\n";
187 root 1.15 print "architecture name and this string '$sp|$ss'. Thanks a lot!\n";#d#
188     print "*****************************************************************************\n\n";
189    
190     unlink "a.out";
191 root 1.17 unlink "conftestval";
192 root 1.15 }
193 root 1.2
194 root 1.26 print <<EOF if $^O =~ /linux/;
195    
196     *****************************************************************************
197     * *
198     * HEY!! You are using Linux! That's not at all bad, but if you get seg- *
199     * faults with Coro almost all the time please refer to README.linux-glibc *
200     * *
201     *****************************************************************************
202    
203     EOF
204 root 1.1