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 (19 years, 1 month 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

# Content
1 use ExtUtils::MakeMaker;
2
3 use 5.005;
4
5 use Config;
6
7 $|=1;
8
9 $DEFINE = "";
10
11 $DEFINE .= " -DHAVE_MMAP" if $Config{d_mmap} eq "define" && $Config{d_munmap} eq "define";
12
13 if ($^O =~ /win32/i or $^O =~ /cygwin/ or $^O =~ /mswin/) {
14 $iface = 'w';
15 } elsif ($^O =~ /irix/) {
16 $iface = "i";
17 } elsif ($^O =~ /linux/) {
18 # default to setjmp/longjmp on non-x86...
19 $iface = $Config{archname} =~ /^(i[3456]86|amd64|x86_64)-/ ? "l" : "s";
20 } elsif ($^O =~ /(free|net|open)bsd/) {
21 # 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.
23 $iface = "s";
24 } elsif ($^O =~ /solaris/) {
25 $iface = "s";
26 } elsif ($^O =~ /darwin/) {
27 $iface = "s";
28 } elsif (-e "/usr/include/ucontext.h") { # shame on this heuristic
29 $iface = "u";
30 } else {
31 $iface = "s";
32 }
33
34 print <<EOF;
35
36 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
37
38 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 The algorithm relies on the non-fact that the same machine stack pointer
46 indicates the same function call nesting level, which usually works good
47 enough (no known cases of it failing are known) but might fail in theory.
48
49 The default (enabled) has been in use on productions servers for some
50 time now, without any problem reports, so you are encouraged to use the
51 default.
52
53 EOF
54
55 if (prompt ("Do you want to enable C context sharing (y/n)", "y") !~ /^\s*n/i) {
56 print "\nC context sharing enabled.\n\n";
57 $DEFINE .= " -DCORO_LAZY_STACK";
58 }
59
60 if ($iface) {
61 print <<EOF;
62
63 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
64
65 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
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
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 setjmp/longjmp/sigaltstack (also standard unix functions). Coroutine
76 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 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 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
85 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
89 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 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 EOF
98
99 retry:
100
101 my $r = prompt "Use which implementation,\n" .
102 "<s>etjmp/longjump, <u>context, <i>rix, <l>inux or <w>indows?",
103 $iface;
104 $iface = lc $1 if $r =~ /(\S)/;
105
106 if ($iface eq "u") {
107 $DEFINE .= " -DCORO_UCONTEXT";
108 print "\nUsing ucontext implementation\n\n";
109 conftest("TEST_makecontext");
110 } elsif ($iface eq "s") {
111 $DEFINE .= " -DCORO_SJLJ";
112 print "\nUsing setjmp/longjmp/sigaltstack implementation\n\n";
113 conftest("TEST_sigaltstack");
114 } elsif ($iface eq "l") {
115 $DEFINE .= " -DCORO_LINUX";
116 print "\nUsing linux-specific implementation\n\n";
117 } elsif ($iface eq "i") {
118 $DEFINE .= " -DCORO_IRIX";
119 print "\nUsing irix-specific implementation\n\n";
120 } elsif ($iface eq "w") {
121 $DEFINE .= " -DCORO_LOSER";
122 print "\nUsing windows-specific implementation\n\n";
123 } else {
124 print "\nUnknown implementation \"$iface\"\n";
125 goto retry;
126 }
127 } else {
128 print "\nUsing microsoft compatible coroutines\n\n";
129 }
130
131 print <<EOF;
132
133 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
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 and should not be set too high, as memory and address space still is
139 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 systems.
142
143 A setting of 16384 (the default) therefore corresponds to a 64k..128k
144 stack, which usually is ample space (you might even want to try 8192 or
145 lower if your program creates many coroutines).
146
147 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
153 EOF
154
155 my $stacksize = prompt ("C stack size factor", "16384");
156 $DEFINE .= " -DSTACKSIZE=$stacksize";
157
158 print "using a stacksize of $stacksize * sizeof(long)\n";
159
160 print <<EOF;
161
162 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
163
164 EOF
165
166 WriteMakefile(
167 NAME => "Coro::State",
168 VERSION_FROM => "State.pm",
169 DEFINE => $DEFINE,
170 DIR => [],
171 );
172
173 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 print "to Marc Lehmann <schmorp\@schmorp.de>: operating system name, version,\n";
187 print "architecture name and this string '$sp|$ss'. Thanks a lot!\n";#d#
188 print "*****************************************************************************\n\n";
189
190 unlink "a.out";
191 unlink "conftestval";
192 }
193
194 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