ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/Makefile.PL
Revision: 1.38
Committed: Mon Dec 12 20:37:28 2005 UTC (18 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-1_6
Changes since 1.37: +30 -19 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") {
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 This 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.
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 various ways to implement coroutines at C level. The default
66 chosen is based on your current confguration and is correct in most cases,
67 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 for newer versions; when it works, that is (currently x86
83 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 unix
86 standard (does that surprise you?), so this workaround might be needed
87 (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 gets
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 enough space (you might want to try 8192 or
145 lower if your program creates many coroutines).
146
147 Some perls (mostly threaded ones) may need much, much more: If Coro
148 segfaults with weird backtraces (e.g. in a function prologue) or in
149 t/10_bugs.t, you might want to increase this to 65536 or more (debian
150 perls might require this).
151
152 EOF
153
154 my $stacksize = prompt ("C stack size factor", "16384");
155 $DEFINE .= " -DSTACKSIZE=$stacksize";
156
157 print "using a stacksize of $stacksize * sizeof(long)\n";
158
159 print <<EOF;
160
161 *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
162
163 EOF
164
165 WriteMakefile(
166 NAME => "Coro::State",
167 VERSION_FROM => "State.pm",
168 DEFINE => $DEFINE,
169 DIR => [],
170 );
171
172 sub conftest {
173 my $type = shift;
174
175 print "\nTrying to detect stack growth direction (for $type)\n";
176 print "You might see some warnings, this should not concern you.\n\n";
177 system "$Config{cc} $Config{ccflags} -D$type libcoro/conftest.c";
178
179 my $res = qx<./a.out>;
180 $res =~ s/\s+$//;
181 my ($sp, $ss) = split /,/, $res;
182
183 print "\n\n*****************************************************************************\n";
184 print "If the testsuite fails PLEASE provide the following information\n";
185 print "to Marc Lehmann <schmorp\@schmorp.de>: operating system name, version,\n";
186 print "architecture name and this string '$sp|$ss'. Thanks a lot!\n";#d#
187 print "*****************************************************************************\n\n";
188
189 unlink "a.out";
190 unlink "conftestval";
191 }
192
193 print <<EOF if $^O =~ /linux/;
194
195 *****************************************************************************
196 * *
197 * HEY!! You are using Linux! That's not at all bad, but if you get seg- *
198 * faults with Coro almost all the time please refer to README.linux-glibc *
199 * *
200 *****************************************************************************
201
202 EOF
203