Message-Id: <200205021220.g42CK4ZN021180@picard.cs.ohiou.edu> From: "Shawn Ostermann" <ostermann@cs.ohiou.edu> Subject: Re: Why this code in tcptrace Date: Thu, 02 May 2002 08:20:04 -0400
> I'm not sure I post this in the right place. Below is the code in
> function ProcessFile(). I don't understand this code and the
> notes. Any one can help to explain this? Why the system call
> overhead will kill us?
I wanted to be able to hit ^C and have the program exit gracefully,
still providing a summary of what it had seen when it exited (try it!)
To make that work reliably, it was necessary to allow the program to
only stop "between packets", or there was a risk that internal data
structures would be inconsistant when trying to produce the output.
To make that work, the program disables ^C (which normally generates a
SIGINT) except for an instant between packets. This works fine except
that profiling showed that the overhead in the system calls required
to enable and then disable SIGINT was using up too much CPU time (and
I'm picky). Therefore I decided that the program would only handle ^C
every 1000 packets as a compromise. Normally, it behaves as you want
but with 1/1000th the syscall overhead.
Shawn
> Hi,
>
> /* for efficiency, only allow a signal every 1000 packets */
> /* (otherwise the system call overhead will kill us) */
> if (pnum % 1000 == 0) {
> sigset_t mask;
>
> sigemptyset(&mask);
> sigaddset(&mask,SIGINT);
>
> sigprocmask(SIG_UNBLOCK, &mask, NULL);
> /* signal can happen EXACTLY HERE, when data structures are consistant */
> sigprocmask(SIG_BLOCK, &mask, NULL);
> }
>
> Thanks
>
> Lu Guohan
> ----------------------------------------------------------------------------
> To unsubscribe, send a message with body containing "unsubscribe tcptrace" to
> majordomo@tcptrace.org.
----------------------------------------------------------------------------
To unsubscribe, send a message with body containing "unsubscribe tcptrace" to
majordomo@tcptrace.org.
This archive was generated by hypermail 2b30 : 05/02/02 EDT