lockperf: a few small improvments
cover lockperf: a few small improvments
From: Daniel Wagner <[email protected]>
Hi Jeff,
I had a bunch of small patches in my tree, which I forgot to send. So here they are...
cheers,
daniel
Daniel Wagner (3):
Synchronize all clients on start up
posix03, posix04: Use '-l' instead of '-i' as option argument name
posix03: Do not kill everything in the process group
flock01.c | 24 ++++++++++++++++++++++-- flock02.c | 24 ++++++++++++++++++++++-- posix01.c | 24 ++++++++++++++++++++++-- posix02.c | 24 ++++++++++++++++++++++-- posix03.c | 23 ++++++++++++++++++----- posix04.c | 6 +++--- 6 files changed, 109 insertions(+), 16 deletions(-)
Signature · 1 line
2.5.5
PATCH 1/3 Synchronize all clients on start up
From: Daniel Wagner <[email protected]>
The child process start working as soon as they are forked. Sometimes that leads to a workload pattern that no contention happens at all even with a high number of processes. Since the main motivation of this this is to benchmark the contention overhead let the clients wait till all client processes are created.
--- flock01.c | 24 ++++++++++++++++++++++-- flock02.c | 24 ++++++++++++++++++++++-- posix01.c | 24 ++++++++++++++++++++++-- posix02.c | 24 ++++++++++++++++++++++-- 4 files changed, 88 insertions(+), 8 deletions(-)
flock01.c +22 -2
@@ -29,6 +29,8 @@#define NRPROC (128)#define NRLOCK (10240) +#define TFR TEMP_FAILURE_RETRY +static struct timespec *diff; static int
@@ -84,7 +86,8 @@ usage(char *prog)int main (int argc,char **argv) { -int i, opt, valid =0 ; +int i, c, opt, valid =0 ; +int to_lockers[2 ];int nproc =NRPROC ;int nlock =NRLOCK ;pid_t *pids;
@@ -123,11 +126,28 @@ main(int argc, char **argv)return 1 ; } +if (pipe (to_lockers)) { +fprintf (stderr,"pipe (to_lockers)" ); +return 1 ; + } +for (i =0 ; i < nproc; ++i) { pids[i] =fork (); -if (!pids[i]) +if (!pids[i]) { +while (TFR (read (to_lockers[0 ], &c,1 )) !=1 ) + ;return lockunlock (argv[optind], nlock, &diff[i]); + } + } + +close (to_lockers[0 ]); +for (i =0 ; i < nproc; ++i) { +if (TFR (write (to_lockers[1 ], &c,1 )) !=1 ) { +perror ("write child" ); +return 1 ; + } } +close (to_lockers[1 ]);for (i =0 ; i < nproc; ++i) {int status;
flock02.c +22 -2
@@ -30,6 +30,8 @@#define NRPROC (128)#define NRLOCK (20480) +#define TFR TEMP_FAILURE_RETRY +static struct timespec *diff; static int
@@ -91,7 +93,8 @@ usage(char *prog)int main (int argc,char **argv) { -int i, opt, valid =0 ; +int i, c, opt, valid =0 ; +int to_lockers[2 ];int nproc =NRPROC ;int nlock =NRLOCK ;pid_t *pids;
@@ -142,11 +145,28 @@ main(int argc, char **argv)return 1 ; } +if (pipe (to_lockers)) { +fprintf (stderr,"pipe (to_lockers)" ); +return 1 ; + } +for (i =0 ; i < nproc; ++i) { pids[i] =fork (); -if (!pids[i]) +if (!pids[i]) { +while (TFR (read (to_lockers[0 ], &c,1 )) !=1 ) + ;return lockunlock (nlock, &diff[i]); + } + } + +close (to_lockers[0 ]); +for (i =0 ; i < nproc; ++i) { +if (TFR (write (to_lockers[1 ], &c,1 )) !=1 ) { +perror ("write child" ); +return 1 ; + } } +close (to_lockers[1 ]);for (i =0 ; i < nproc; ++i) {int status;
posix01.c +22 -2
@@ -30,6 +30,8 @@#define NRPROC (128)#define NRLOCK (10240) +#define TFR TEMP_FAILURE_RETRY +static struct timespec *diff; static int
@@ -97,7 +99,8 @@ int main(int argc, char **argv) { bool verbose = false, yield = false; -int i, opt, valid =0 ; +int i, c, opt, valid =0 ; +int to_lockers[2 ];int nproc =NRPROC ;int nlock =NRLOCK ;pid_t *pids;
@@ -142,12 +145,29 @@ main(int argc, char **argv)return 1 ; } +if (pipe (to_lockers)) { +fprintf (stderr,"pipe (to_lockers)" ); +return 1 ; + } +for (i =0 ; i < nproc; ++i) { pids[i] =fork (); -if (!pids[i]) +if (!pids[i]) { +while (TFR (read (to_lockers[0 ], &c,1 )) !=1 ) + ;return lockunlock (argv[optind], nlock, &diff[i], verbose, yield); + } + } + +close (to_lockers[0 ]); +for (i =0 ; i < nproc; ++i) { +if (TFR (write (to_lockers[1 ], &c,1 )) !=1 ) { +perror ("write child" ); +return 1 ; + } } +close (to_lockers[1 ]);for (i =0 ; i < nproc; ++i) {int status;
posix02.c +22 -2
@@ -29,6 +29,8 @@#define NRPROC (128)#define NRLOCK (20480) +#define TFR TEMP_FAILURE_RETRY +static struct timespec *diff; static int
@@ -93,7 +95,8 @@ usage(char *prog)int main (int argc,char **argv) { -int i, opt, valid =0 ; +int i, c, opt, valid =0 ; +int to_lockers[2 ];int nproc =NRPROC ;int nlock =NRLOCK ;pid_t *pids;
@@ -144,11 +147,28 @@ main(int argc, char **argv)return 1 ; } +if (pipe (to_lockers)) { +fprintf (stderr,"pipe (to_lockers)" ); +return 1 ; + } +for (i =0 ; i < nproc; ++i) { pids[i] =fork (); -if (!pids[i]) +if (!pids[i]) { +while (TFR (read (to_lockers[0 ], &c,1 )) !=1 ) + ;return lockunlock (nlock, &diff[i]); + } + } + +close (to_lockers[0 ]); +for (i =0 ; i < nproc; ++i) { +if (TFR (write (to_lockers[1 ], &c,1 )) !=1 ) { +perror ("write child" ); +return 1 ; + } } +close (to_lockers[1 ]);for (i =0 ; i < nproc; ++i) {int status;
Signature · 1 line
2.5.5
PATCH 2/3 posix03, posix04: Use '-l' instead of '-i' as option argument name
In reply to Daniel WagnerFrom: Daniel Wagner <[email protected]>
All other test use '=l' instead of '-i' to as option name for defining how many loops should be executed. Let's streamline posix03 and posix04.
--- posix03.c | 6 +++--- posix04.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
posix03.c +3 -3
@@ -109,7 +109,7 @@ static int do_child(int lockfd, int i, int to_lockers, int from_lockers)static int usage (char *argv0) { -errx (1 ,"Usage: %s [-i iterations] [-n nr_children] <filename>" , argv0); +errx (1 ,"Usage: %s [-n nr_procs] [-l nr_loops] <filename>" , argv0); }int main (int argc,char *argv[])
@@ -126,9 +126,9 @@ int main(int argc, char *argv[]) total.tv_sec =0 ; total.tv_nsec =0 ; -while ((opt =getopt (argc, argv,"i:n:" )) !=-1 ) { +while ((opt =getopt (argc, argv,"l:n:" )) !=-1 ) {switch (opt) { -case 'i' : +case 'l' : iter =atoi (optarg);break ;case 'n' :
posix04.c +3 -3
@@ -158,7 +158,7 @@ static int do_child(int fd, int id, int nproc, int to_lockers, int from_lockers)static int usage (char *argv0) { -errx (1 ,"Usage: %s [-i iterations] [-n nr_children] [-s] <filename>" , argv0); +errx (1 ,"Usage: %s [-n nr_procs] [-l nr_loops] [-s] <filename>" , argv0); }int main (int argc,char *argv[])
@@ -175,9 +175,9 @@ int main(int argc, char *argv[]) total.tv_sec =0 ; total.tv_nsec =0 ; -while ((opt =getopt (argc, argv,"i:n:s" )) !=-1 ) { +while ((opt =getopt (argc, argv,"l:n:s" )) !=-1 ) {switch (opt) { -case 'i' : +case 'l' : iter =atoi (optarg);break ;case 'n' :
Signature · 1 line
2.5.5
PATCH 3/3 posix03: Do not kill everything in the process group
In reply to Daniel WagnerFrom: Daniel Wagner <[email protected]>
kill(0, SIGINT) sends to all in the process group the signal including the parent shell.
Instead remember the PIDs of all children and just send the signal to these processes.
--- posix03.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
posix03.c +15 -2
@@ -71,13 +71,18 @@ static int fcntl_unlock(int fd, off_t off, off_t len)return fcntl (fd,F_SETLKW , &fl); } +/* The PIDs of all children */ +static pid_t *cpids; +static void kill_children () {siginfo_t infop; +int i;signal (SIGINT ,SIG_IGN ); -kill (0 ,SIGINT ); +for (i =0 ; cpids[i]; i++) +kill (cpids[i],SIGINT );while (waitid (P_ALL ,0 , &infop,WEXITED ) !=-1 ); }
@@ -161,14 +166,21 @@ int main(int argc, char *argv[])signal (SIGINT , sighandler); + cpids =malloc ((num +1 ) *sizeof (pid_t)); +if (!cpids) +err (1 ,"malloc" ); + cpids[num] =0 ; +for (i =0 ; i < num; i++) { -switch (fork ()) { +pid_t pid =fork (); +switch (pid) {case 0 :signal (SIGINT ,SIG_DFL );return do_child (lockfd, i, to_lockers[0 ], from_lockers[1 ]);case -1 :err (1 ,"fork failed" ); } + cpids[i] = pid; }close (to_lockers[0 ]);
@@ -208,5 +220,6 @@ int main(int argc, char *argv[])printf ("%ld.%09ld\n" , total.tv_sec, total.tv_nsec);kill_children (); +free (cpids);return 0 ; }
Signature · 1 line
2.5.5