Commit Graph

22 Commits

Author SHA1 Message Date
Ben Noordhuis
8f931a229a linux: fix epoll_pwait() fallback on arm64
arm64 doesn't have a epoll_wait() system call but a logic error stopped
libuv from falling back to epoll_pwait().

This bug was introduced in commit 67bb2b5 ("linux: fix epoll_pwait()
regression with < 2.6.19") which sadly exchanged one regression for
another.

This is a backport of 1d8332f (v1.x)

PR-URL: https://github.com/libuv/libuv/pull/308
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-05-06 22:28:25 +02:00
Ben Noordhuis
b214fe66ef linux: fix epoll_pwait() regression with < 2.6.19
Linux before kernel 2.6.19 does not support epoll_pwait().  Due to a
logic error in commit 2daf944 ("unix: add flag for blocking SIGPROF
during poll"), the fallback path for ENOSYS was not taken.

This commit also adds epoll_pwait() emulation using pthread_sigmask().
The block/unblock operations are not atomic but that is fine for our
particular use case, to wit, sleep through SIGPROF signals.

This is a back-port of commit 67bb2b5 from the v1.x branch.

Original-PR-URL: https://github.com/libuv/libuv/pull/162
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>

PR-URL: https://github.com/libuv/libuv/pull/165
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-25 14:59:28 +01:00
Ben Noordhuis
fa0b08ff5a linux: fix epoll_pwait() sigmask size calculation
Revisit the fix from commit b705b53.  The problem with using sigset_t
and _NSIG is that the size of sigset_t and the value of _NSIG depend
on what headers libuv picks up first, <signal.h> or <asm/signal.h>.
With the former, sizeof(sigset_t) = 128; with the latter, it's 8.

Simply sidestep the issue by calculating the signal mask as a 64 bits
integer, without using sigset_t or _NSIG.

This is a partial cherry-pick of commit 751ac48 from the v1.x branch.

Original PR-URL: https://github.com/libuv/libuv/pull/83
PR-URL: https://github.com/libuv/libuv/pull/84
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-12-25 15:30:52 +01:00
Ben Noordhuis
2daf9448b1 unix: add flag for blocking SIGPROF during poll
Add a per-event loop flag for blocking SIGPROF signals when polling for
events.

The motivation for this addition is to reduce the number of wakeups and
subsequent clock_gettime() system calls when using a sampling profiler.

On Linux, this switches from epoll_wait() to epoll_pwait() when enabled.
Other platforms bracket the poll syscall with pthread_sigmask() calls.

Refs strongloop/strong-agent#3 and strongloop-internal/scrum-cs#37.

PR-URL: https://github.com/libuv/libuv/pull/15
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-12-05 17:38:31 +01:00
Michael Hudson-Doyle
ef7b783d8d linux: try epoll_pwait if epoll_wait is missing
It seems that epoll_wait is implemented in glibc in terms of epoll_pwait and
new architectures (like arm64) do not implement the epoll_wait syscall at all.
So if epoll_wait errors with ENOSYS, just call epoll_pwait.

This is a backport of 861de3d71d for v0.10
branch.
2014-10-20 23:40:28 +02:00
Geoffry Song
84f305915f linux: always deregister closing fds from epoll
If the same file description is open in two different processes, then
closing the file descriptor is not sufficient to deregister it from the
epoll instance (as described in epoll(7)), resulting in spurious events
that cause the event loop to spin repeatedly. So always explicitly
deregister it.

Fixes #1099.

Conflicts:
	test/test-spawn.c
2014-03-10 17:27:36 +04:00
Fedor Indutny
3e2446d18d linux: fix C99/C++ comment 2014-01-29 17:01:35 +04:00
Trevor Norris
7c8ff3bc25 linux: move sscanf() out of the assert()
If asserts are turned off then the sscanf() wouldn't have run, being
placed directly in the assert() itself.
2014-01-29 17:01:26 +04:00
Luca Bruno
993151bc40 linux: relax assumption on /proc/stat parsing
CPU entries in /proc/stat are not guaranteed to be monotonically
increasing, asserting on this assumption can break in cases such
as the UltraSparc II machine shown in #1080.

Signed-off-by: Luca Bruno <lucab@debian.org>
2014-01-20 08:45:34 -08:00
Fedor Indutny
bbccafbe70 unix: fix reopened fd bug
When fd is closed and new one (with the same number) is opened inside
kqueue/epoll/port loop's callback - stale events might invoke callbacks
on wrong watchers.

Check if watcher was changed after invocation and invalidate all events
with the same fd.

fix #826
2013-11-12 15:02:59 +04:00
Ben Noordhuis
0c76cdb98f linux: handle EPOLLHUP without EPOLLIN/EPOLLOUT
Work around an epoll quirk where it sometimes reports just the EPOLLERR
or EPOLLHUP event.  In order to force the event loop to move forward,
we merge in the read/write events that the watcher is interested in;
uv__read() and uv__write() will then deal with the error or hangup in
the usual fashion.

Fixes #982.

This is a back-port of commit 24bfef2 from the master branch.
2013-11-08 05:38:55 +01:00
Fedor Indutny
29fdb3471b unix: update events from pevents between polls
Watchers could be stopped between two `kevent()`/`epoll_wait()` calls
(which may happen in the same loop in `uv__io_poll()`), in such cases
`watcher->events` could be stale and won't be updated to
`watcher->pevents`.

Try to use and rely on `watcher->pevents` instead of blindly expecting
`watcher->events` to be always correct.
2013-10-30 12:40:25 +04:00
Andrei Sedoi
5096f1e096 linux: add support for MIPS 2013-06-13 09:04:15 +02:00
Ben Noordhuis
b93cf8b594 linux: don't ignore OOM errors in uv_cpu_info() 2013-05-29 01:43:05 +02:00
Ben Noordhuis
31282a97e7 linux: fix memory leak in uv_cpu_info() error path
Any memory allocated to hold CPU model strings wasn't freed on error.
2013-05-29 01:43:05 +02:00
Ben Noordhuis
92c72f58bf linux: fix cpu model parsing on newer arm kernels
The format of /proc/cpuinfo on ARM kernels >= 3.8 has changed. Scan for
the string "model name" (like x86) first, "Processor" second.

Fixes #812.
2013-05-29 01:40:09 +02:00
Ben Noordhuis
cd10637d0b linux: don't use fopen() in uv_resident_set_memory()
RSS is a reflection of the number of pages that a process has mapped.
glibc implements fopen() in terms of mmap() which means that trying
to read the number of mapped pages changes it. Switch to open().
2013-04-22 08:26:53 +02:00
Ben Noordhuis
7e59f9bb53 linux: make uv_cpu_info() handle absent procfs
Return an error when reading from /proc files fails because the procfs
isn't mounted.
2013-03-02 01:48:44 +01:00
Ben Noordhuis
e89aced8d6 darwin: implement uv_set_process_title, part 2
Make changes to the process title visible to tools like `ps`.

The argv clobber technique is reasonably portable across Unices;
the common code has been moved into src/unix/proctitle.c and is used
on Linux and OS X. Other platforms will probably follow in the future.
2013-02-24 03:56:02 +01:00
Ben Noordhuis
c98083ef26 unix: short-circuit on no-op io watcher changes
Don't add the io watcher to the watcher queue if the requested change
is effectively a no-op, that is, when the event mask doesn't change.

The exception here is sunos because the event ports backend requires
that watched file descriptors are re-added on every turn of the event
loop.

This commit is a micro-optimization, it does not change the event
loop's observable behavior in any way.
2013-02-22 17:02:05 +01:00
Ben Noordhuis
26fa6f8031 linux: fix abort() on epoll_ctl() race condition
Don't check the return value of epoll_ctl(EPOLL_CTL_DEL). When the
file descriptor is closed, we're potentially racing with another
thread and that means the errno is not a reliable indicator of
the actual error.

The other event mechanisms (kqueue, event ports) are not affected
because:

* kqueue returns either EBADF or ENOENT. Both are handled by libuv.
* event ports rearms all file descriptors on each call to port_getn().

Fixes joyent/node#4558.
2013-02-20 21:28:39 +01:00
Ben Noordhuis
b607a7fed7 linux: move files out of src/unix/linux
Flattens the source tree and simplifies the Makefile.
2013-01-29 17:07:41 +01:00