Avi Kivity wrote:
Anthony Liguori wrote:
Oh okay. But signal delivery is slow; for example the FPU needs to
be reset.
Is it really justified to add all of this extra code (including
signalfd emulation) for something that probably isn't even measurable?
We don't have to add signalfd emulation; we can simply use signal+pipe
in that case.
We won't know if it's measurable or not until we measure it (or not).
I like using wiz-bang features of Linux as much as the next guy, but
I think we're stretching to justify it here :-)
I think it's worth it in this case. It will become more important in
time, too.
Out of curiosity, I measured this:
[avi@balrog test]$ ./signal
2777 ns/signal (pipe)
844 ns/signal (signalfd)
At 10000 signals/sec, this will save about 2% cpu time. It's definitely
worthwhile for the handful of lines it takes.
test program:
#include <signal.h>
#include <unistd.h>
#include <sys/signalfd.h>
#include <sys/time.h>
#include <stdio.h>
static int wfd;
static void handler(int signum)
{
char b;
write(wfd, &b, 1);
}
static int create_pipe(void)
{
int fd[2];
sigset_t s;
pipe(fd);
wfd = fd[1];
signal(SIGUSR1, handler);
sigemptyset(&s);
sigaddset(&s, SIGUSR1);
sigprocmask(SIG_UNBLOCK, &s, NULL);
return fd[0];
}
static int create_signalfd(void)
{
sigset_t s;
sigemptyset(&s);
sigaddset(&s, SIGUSR1);
sigprocmask(SIG_BLOCK, &s, NULL);
return signalfd(-1, &s, 0);
}
static uint64_t time_usec(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (uint64_t)tv.tv_sec * 1000000 + tv.tv_usec;
}
#define N 10000000
static void test(const char *name, int fd, int len)
{
int i;
uint64_t t1, t2;
char buf[128];
t1 = time_usec();
for (i = 0; i < N; ++i) {
raise(SIGUSR1);
read(fd, buf, len);
}
t2 = time_usec();
close(fd);
printf("%5d ns/signal (%s)\n", 1000 * (t2 - t1) / N, name);
}
int main(int ac, char **av)
{
test("pipe", create_pipe(), 1);
test("signalfd", create_signalfd(), 128);
return 0;
}
--
error compiling committee.c: too many arguments to function
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html