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 |
|
|
# 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 |
root |
1.8 |
} elsif ($^O =~ /solaris/) { |
25 |
|
|
$iface = "s"; |
26 |
root |
1.25 |
} elsif ($^O =~ /darwin/) { |
27 |
|
|
$iface = "s"; |
28 |
root |
1.2 |
} elsif (-e "/usr/include/ucontext.h") { |
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.34 |
C context sharing: This option makes it possible to share the C stack and |
37 |
|
|
context between many coroutines, resulting in large memory savings and |
38 |
|
|
slight speed gains, at the cost of potential (but mostly theoretical) |
39 |
|
|
segfaults. On my Linux/x86 machine this decreased the size of a new |
40 |
|
|
coroutine from 9k to 5k, but the savings are much more apparent on |
41 |
|
|
machines without mmap or good memory management. |
42 |
|
|
|
43 |
|
|
This algorithm relies on the non-fact that the same machine stack pointer |
44 |
|
|
indicates the same function call nesting level, which usually works good |
45 |
|
|
enough (no known cases of it failing are known) but might fail. |
46 |
|
|
|
47 |
|
|
The default (enabled) has been in-use on productions servers for some |
48 |
|
|
time now, without any problem reports, so you are encouraged to use the |
49 |
|
|
default. |
50 |
root |
1.6 |
|
51 |
|
|
EOF |
52 |
|
|
|
53 |
root |
1.27 |
if (prompt ("Do you want to enable C context sharing (y/n)", "y") !~ /^\s*n/i) { |
54 |
root |
1.34 |
print "\nC context sharing enabled.\n\n"; |
55 |
root |
1.6 |
$DEFINE .= " -DCORO_LAZY_STACK"; |
56 |
|
|
} |
57 |
|
|
|
58 |
root |
1.3 |
if ($iface) { |
59 |
|
|
print <<EOF; |
60 |
root |
1.2 |
|
61 |
root |
1.34 |
Coro can use various ways to implement coroutines at C level. The |
62 |
|
|
default is correct in most cases, but you still can chose between these |
63 |
|
|
alternatives: |
64 |
|
|
|
65 |
|
|
u The unix 'ucontext.h' functions are relatively new and not implemented |
66 |
|
|
or well-tested in older unices. They allow very fast coroutine creation |
67 |
|
|
and reasonably fast switching, and, most importantly, are very stable. |
68 |
root |
1.4 |
|
69 |
|
|
s 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 |
71 |
root |
1.34 |
setjmp/longjmp/sigaltstack (also standard unix functions). Coroutine |
72 |
root |
1.4 |
creation is rather slow, but switching is very fast as well (often much |
73 |
|
|
faster than with the ucontext functions). Unfortunately, glibc-2.1 and |
74 |
|
|
below don't even feature a working sigaltstack. |
75 |
|
|
|
76 |
root |
1.35 |
l GNU/Linux. Older GNU/Linux systems (glibc-2.1 and below) need this |
77 |
|
|
hack. Since it is very linux-specific it is also quite fast for newer |
78 |
|
|
versions; when it works, that is (currently x86 only)... |
79 |
root |
1.14 |
|
80 |
|
|
i IRIX. For some reason, SGI really does not like to follow the unix |
81 |
root |
1.20 |
standard (does that surprise you?), so this workaround might be needed |
82 |
|
|
(it's fast), although s and u should also work now. |
83 |
root |
1.2 |
|
84 |
root |
1.34 |
w Microsoft Windows. Try this on Microsoft Windows, although, as there is |
85 |
|
|
no standard on how to do this under windows, this might work only on |
86 |
|
|
cygwin or specific versions of msvc. Your problem. |
87 |
|
|
|
88 |
root |
1.28 |
For most systems, the default chosen should be OK. If you experience |
89 |
|
|
problems then you should experiment with this setting and/or turn off |
90 |
|
|
optimizations (make OPTIMIZE=-O0). |
91 |
|
|
|
92 |
root |
1.2 |
EOF |
93 |
root |
1.3 |
|
94 |
|
|
retry: |
95 |
root |
1.14 |
|
96 |
root |
1.27 |
my $r = prompt "Use which implementation,\n" . |
97 |
root |
1.34 |
"<s>etjmp/longjump, <u>context, <i>rix, <l>inux or <w>indows?", |
98 |
root |
1.27 |
$iface; |
99 |
root |
1.3 |
$iface = lc $1 if $r =~ /(\S)/; |
100 |
|
|
|
101 |
|
|
if ($iface eq "u") { |
102 |
|
|
$DEFINE .= " -DCORO_UCONTEXT"; |
103 |
|
|
print "\nUsing ucontext implementation\n\n"; |
104 |
root |
1.15 |
conftest("TEST_makecontext"); |
105 |
root |
1.3 |
} elsif ($iface eq "s") { |
106 |
|
|
$DEFINE .= " -DCORO_SJLJ"; |
107 |
|
|
print "\nUsing setjmp/longjmp/sigaltstack implementation\n\n"; |
108 |
root |
1.15 |
conftest("TEST_sigaltstack"); |
109 |
root |
1.4 |
} elsif ($iface eq "l") { |
110 |
|
|
$DEFINE .= " -DCORO_LINUX"; |
111 |
|
|
print "\nUsing linux-specific implementation\n\n"; |
112 |
root |
1.14 |
} elsif ($iface eq "i") { |
113 |
|
|
$DEFINE .= " -DCORO_IRIX"; |
114 |
|
|
print "\nUsing irix-specific implementation\n\n"; |
115 |
root |
1.34 |
} elsif ($iface eq "w") { |
116 |
|
|
$DEFINE .= " -DCORO_LOSER"; |
117 |
|
|
print "\nUsing windows-specific implementation\n\n"; |
118 |
root |
1.3 |
} else { |
119 |
|
|
print "\nUnknown implementation \"$iface\"\n"; |
120 |
|
|
goto retry; |
121 |
|
|
} |
122 |
|
|
} else { |
123 |
root |
1.16 |
print "\nUsing microsoft compatible coroutines\n\n"; |
124 |
root |
1.3 |
} |
125 |
root |
1.2 |
|
126 |
root |
1.36 |
print <<EOF; |
127 |
|
|
|
128 |
|
|
Per-context stack size: Depending on your settings, Coro tries to share |
129 |
|
|
the C stack as much as possible, but sometimes it needs to allocate a |
130 |
root |
1.37 |
new one. This setting controls the maximum size that gets allocated, |
131 |
|
|
and should not be too high, memory and address space still gets wasted |
132 |
|
|
even if it's not fully used. The value entered will be multiplied by |
133 |
|
|
sizeof(long), which is usually 4 on 32-bit systems, and 8 on 64-bit |
134 |
|
|
systems. |
135 |
|
|
|
136 |
|
|
A setting of 16384 (the default) therefore to a 64k..128k stack, which |
137 |
|
|
usually is ample space (you might wnat to try 8192 or lower if your |
138 |
|
|
program creates many coroutines). |
139 |
|
|
|
140 |
|
|
Some perls (mostly threaded ones) may need much, much more: If Coro |
141 |
|
|
segfaults with weird backtraces (e.g. in a function prologue) or in |
142 |
|
|
t/10_bugs.t, you might want to increase this to 65536 or more (debian |
143 |
|
|
might require this). |
144 |
root |
1.36 |
|
145 |
|
|
EOF |
146 |
|
|
|
147 |
|
|
my $stacksize = prompt ("C Stack Size", "16384"); |
148 |
|
|
$DEFINE .= " -DSTACKSIZE=$stacksize"; |
149 |
|
|
|
150 |
|
|
print "using a stacksize of $stacksize * sizeof(long)\n"; |
151 |
|
|
|
152 |
|
|
print "\n"; |
153 |
|
|
|
154 |
root |
1.1 |
WriteMakefile( |
155 |
root |
1.2 |
NAME => "Coro::State", |
156 |
|
|
VERSION_FROM => "State.pm", |
157 |
|
|
DEFINE => $DEFINE, |
158 |
|
|
DIR => [], |
159 |
root |
1.1 |
); |
160 |
root |
1.2 |
|
161 |
root |
1.15 |
sub conftest { |
162 |
|
|
my $type = shift; |
163 |
|
|
|
164 |
|
|
print "\nTrying to detect stack growth direction (for $type)\n"; |
165 |
|
|
print "You might see some warnings, this should not concern you.\n\n"; |
166 |
|
|
system "$Config{cc} $Config{ccflags} -D$type libcoro/conftest.c"; |
167 |
|
|
|
168 |
|
|
my $res = qx<./a.out>; |
169 |
|
|
$res =~ s/\s+$//; |
170 |
|
|
my ($sp, $ss) = split /,/, $res; |
171 |
|
|
|
172 |
|
|
print "\n\n*****************************************************************************\n"; |
173 |
|
|
print "If the testsuite fails PLEASE provide the following information\n"; |
174 |
root |
1.32 |
print "to Marc Lehmann <schmorp\@schmorp.de>: operating system name, version,\n"; |
175 |
root |
1.15 |
print "architecture name and this string '$sp|$ss'. Thanks a lot!\n";#d# |
176 |
|
|
print "*****************************************************************************\n\n"; |
177 |
|
|
|
178 |
|
|
unlink "a.out"; |
179 |
root |
1.17 |
unlink "conftestval"; |
180 |
root |
1.15 |
} |
181 |
root |
1.2 |
|
182 |
root |
1.26 |
print <<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 |
|
|
|
191 |
|
|
EOF |
192 |
root |
1.1 |
|