##// END OF EJS Templates
zstd: vendor python-zstandard 0.7.0...
zstd: vendor python-zstandard 0.7.0 Commit 3054ae3a66112970a091d3939fee32c2d0c1a23e from https://github.com/indygreg/python-zstandard is imported without modifications (other than removing unwanted files). The vendored zstd library within has been upgraded from 1.1.2 to 1.1.3. This version introduced new APIs for threads, thread pools, multi-threaded compression, and a new dictionary builder (COVER). These features are not yet used by python-zstandard (or Mercurial for that matter). However, that will likely change in the next python-zstandard release (and I think there are opportunities for Mercurial to take advantage of the multi-threaded APIs). Relevant to Mercurial, the CFFI bindings are now fully implemented. This means zstd should "just work" with PyPy (although I haven't tried). The python-zstandard test suite also runs all tests against both the C extension and CFFI bindings to ensure feature parity. There is also a "decompress_content_dict_chain()" API. This was derived from discussions with Yann Collet on list about alternate ways of encoding delta chains. The change most relevant to Mercurial is a performance enhancement in the simple decompression API to reuse a data structure across operations. This makes decompression of multiple inputs significantly faster. (This scenario occurs when reading revlog delta chains, for example.) Using python-zstandard's bench.py to measure the performance difference... On changelog chunks in the mozilla-unified repo: decompress discrete decompress() reuse zctx 1.262243 wall; 1.260000 CPU; 1.260000 user; 0.000000 sys 170.43 MB/s (best of 3) 0.949106 wall; 0.950000 CPU; 0.950000 user; 0.000000 sys 226.66 MB/s (best of 4) decompress discrete dict decompress() reuse zctx 0.692170 wall; 0.690000 CPU; 0.690000 user; 0.000000 sys 310.80 MB/s (best of 5) 0.437088 wall; 0.440000 CPU; 0.440000 user; 0.000000 sys 492.17 MB/s (best of 7) On manifest chunks in the mozilla-unified repo: decompress discrete decompress() reuse zctx 1.367284 wall; 1.370000 CPU; 1.370000 user; 0.000000 sys 274.01 MB/s (best of 3) 1.086831 wall; 1.080000 CPU; 1.080000 user; 0.000000 sys 344.72 MB/s (best of 3) decompress discrete dict decompress() reuse zctx 0.993272 wall; 0.990000 CPU; 0.990000 user; 0.000000 sys 377.19 MB/s (best of 3) 0.678651 wall; 0.680000 CPU; 0.680000 user; 0.000000 sys 552.06 MB/s (best of 5) That should make reads on zstd revlogs a bit faster ;) # no-check-commit

File last commit:

r30693:baee0f47 default
r30895:c32454d6 default
Show More
procutil.c
227 lines | 5.2 KiB | text/x-c | CLexer
Jun Wu
chg: move signal and pager handling to a separate file...
r30689 /*
* Utilities about process handling - signal and subprocess (ex. pager)
*
* Copyright (c) 2011 Yuya Nishihara <yuya@tcha.org>
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2 or any later version.
*/
Jun Wu
chg: add procutil.h...
r30693 #include <assert.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include "procutil.h"
#include "util.h"
Jun Wu
chg: move signal and pager handling to a separate file...
r30689 static pid_t pagerpid = 0;
static pid_t peerpgid = 0;
static pid_t peerpid = 0;
static void forwardsignal(int sig)
{
assert(peerpid > 0);
if (kill(peerpid, sig) < 0)
abortmsgerrno("cannot kill %d", peerpid);
debugmsg("forward signal %d", sig);
}
static void forwardsignaltogroup(int sig)
{
/* prefer kill(-pgid, sig), fallback to pid if pgid is invalid */
pid_t killpid = peerpgid > 1 ? -peerpgid : peerpid;
if (kill(killpid, sig) < 0)
abortmsgerrno("cannot kill %d", killpid);
debugmsg("forward signal %d to %d", sig, killpid);
}
static void handlestopsignal(int sig)
{
sigset_t unblockset, oldset;
struct sigaction sa, oldsa;
if (sigemptyset(&unblockset) < 0)
goto error;
if (sigaddset(&unblockset, sig) < 0)
goto error;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
sa.sa_flags = SA_RESTART;
if (sigemptyset(&sa.sa_mask) < 0)
goto error;
forwardsignal(sig);
if (raise(sig) < 0) /* resend to self */
goto error;
if (sigaction(sig, &sa, &oldsa) < 0)
goto error;
if (sigprocmask(SIG_UNBLOCK, &unblockset, &oldset) < 0)
goto error;
/* resent signal will be handled before sigprocmask() returns */
if (sigprocmask(SIG_SETMASK, &oldset, NULL) < 0)
goto error;
if (sigaction(sig, &oldsa, NULL) < 0)
goto error;
return;
error:
abortmsgerrno("failed to handle stop signal");
}
static void handlechildsignal(int sig UNUSED_)
{
if (peerpid == 0 || pagerpid == 0)
return;
/* if pager exits, notify the server with SIGPIPE immediately.
* otherwise the server won't get SIGPIPE if it does not write
* anything. (issue5278) */
if (waitpid(pagerpid, NULL, WNOHANG) == pagerpid)
kill(peerpid, SIGPIPE);
}
Jun Wu
chg: add procutil.h...
r30693 void setupsignalhandler(pid_t pid, pid_t pgid)
Jun Wu
chg: move signal and pager handling to a separate file...
r30689 {
if (pid <= 0)
return;
peerpid = pid;
peerpgid = (pgid <= 1 ? 0 : pgid);
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = forwardsignaltogroup;
sa.sa_flags = SA_RESTART;
if (sigemptyset(&sa.sa_mask) < 0)
goto error;
if (sigaction(SIGHUP, &sa, NULL) < 0)
goto error;
if (sigaction(SIGINT, &sa, NULL) < 0)
goto error;
/* terminate frontend by double SIGTERM in case of server freeze */
sa.sa_handler = forwardsignal;
sa.sa_flags |= SA_RESETHAND;
if (sigaction(SIGTERM, &sa, NULL) < 0)
goto error;
/* notify the worker about window resize events */
sa.sa_flags = SA_RESTART;
if (sigaction(SIGWINCH, &sa, NULL) < 0)
goto error;
/* propagate job control requests to worker */
sa.sa_handler = forwardsignal;
sa.sa_flags = SA_RESTART;
if (sigaction(SIGCONT, &sa, NULL) < 0)
goto error;
sa.sa_handler = handlestopsignal;
sa.sa_flags = SA_RESTART;
if (sigaction(SIGTSTP, &sa, NULL) < 0)
goto error;
/* get notified when pager exits */
sa.sa_handler = handlechildsignal;
sa.sa_flags = SA_RESTART;
if (sigaction(SIGCHLD, &sa, NULL) < 0)
goto error;
return;
error:
abortmsgerrno("failed to set up signal handlers");
}
Jun Wu
chg: add procutil.h...
r30693 void restoresignalhandler(void)
Jun Wu
chg: move signal and pager handling to a separate file...
r30689 {
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
sa.sa_flags = SA_RESTART;
if (sigemptyset(&sa.sa_mask) < 0)
goto error;
if (sigaction(SIGHUP, &sa, NULL) < 0)
goto error;
if (sigaction(SIGTERM, &sa, NULL) < 0)
goto error;
if (sigaction(SIGWINCH, &sa, NULL) < 0)
goto error;
if (sigaction(SIGCONT, &sa, NULL) < 0)
goto error;
if (sigaction(SIGTSTP, &sa, NULL) < 0)
goto error;
if (sigaction(SIGCHLD, &sa, NULL) < 0)
goto error;
/* ignore Ctrl+C while shutting down to make pager exits cleanly */
sa.sa_handler = SIG_IGN;
if (sigaction(SIGINT, &sa, NULL) < 0)
goto error;
peerpid = 0;
return;
error:
abortmsgerrno("failed to restore signal handlers");
}
/* This implementation is based on hgext/pager.py (post 369741ef7253)
* Return 0 if pager is not started, or pid of the pager */
Jun Wu
chg: add procutil.h...
r30693 pid_t setuppager(const char *pagercmd)
Jun Wu
chg: move signal and pager handling to a separate file...
r30689 {
Jun Wu
chg: let procutil maintain its own pagerpid...
r30692 assert(pagerpid == 0);
Jun Wu
chg: move signal and pager handling to a separate file...
r30689 if (!pagercmd)
return 0;
int pipefds[2];
if (pipe(pipefds) < 0)
return 0;
pid_t pid = fork();
if (pid < 0)
goto error;
if (pid > 0) {
close(pipefds[0]);
if (dup2(pipefds[1], fileno(stdout)) < 0)
goto error;
if (isatty(fileno(stderr))) {
if (dup2(pipefds[1], fileno(stderr)) < 0)
goto error;
}
close(pipefds[1]);
Jun Wu
chg: let procutil maintain its own pagerpid...
r30692 pagerpid = pid;
Jun Wu
chg: move signal and pager handling to a separate file...
r30689 return pid;
} else {
dup2(pipefds[0], fileno(stdin));
close(pipefds[0]);
close(pipefds[1]);
int r = execlp("/bin/sh", "/bin/sh", "-c", pagercmd, NULL);
if (r < 0) {
abortmsgerrno("cannot start pager '%s'", pagercmd);
}
return 0;
}
error:
close(pipefds[0]);
close(pipefds[1]);
abortmsgerrno("failed to prepare pager");
return 0;
}
Jun Wu
chg: add procutil.h...
r30693 void waitpager(void)
Jun Wu
chg: move signal and pager handling to a separate file...
r30689 {
Jun Wu
chg: let procutil maintain its own pagerpid...
r30692 if (pagerpid == 0)
return;
Jun Wu
chg: move signal and pager handling to a separate file...
r30689 /* close output streams to notify the pager its input ends */
fclose(stdout);
fclose(stderr);
while (1) {
Jun Wu
chg: let procutil maintain its own pagerpid...
r30692 pid_t ret = waitpid(pagerpid, NULL, 0);
Jun Wu
chg: move signal and pager handling to a separate file...
r30689 if (ret == -1 && errno == EINTR)
continue;
break;
}
}