Skip to content

Commit

Permalink
Allocate unique fd for each parallel to avoid unexpected syscall test…
Browse files Browse the repository at this point in the history
… result

If all the parallels dup the same fd 0 and share the same file reference
count, then the f_count will meet with heavy lock contention. The syscall
cost of dup/close will occupy only a few in the test result. Allocating
one unique fd for each parallel will reduce lots of the unexpected
lock contention cost. And it will fully perform the syscall cost of
dup/close.

If the parallel number is 1, the testing result with this patch is the
same with the original one on ICX server, which is expected. If the
parallel number is large, the testing result will accurately show the
syscall cost of dup/close without the impact of data sharing.

Signed-off-by: Jiebin Sun <[email protected]>
  • Loading branch information
jiebinn authored and gstrauss committed Jan 19, 2023
1 parent 2ebb4c5 commit fb4521c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions UnixBench/src/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ char SCCSid[] = "@(#) @(#)syscall.c:3.3 -- 5/15/91 19:30:21";
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/syscall.h>
#include <unistd.h>
#include "timeit.c"

unsigned long iter;
Expand All @@ -39,12 +40,23 @@ void report()
exit(0);
}

int create_fd()
{
int fd[2];

if (pipe(fd) != 0 || close(fd[1]) != 0)
exit(1);

return fd[0];
}

int main(argc, argv)
int argc;
char *argv[];
{
char *test;
int duration;
int fd;

if (argc < 2) {
fprintf(stderr,"Usage: %s duration [ test ]\n", argv[0]);
Expand All @@ -64,17 +76,19 @@ char *argv[];

switch (test[0]) {
case 'm':
fd = create_fd();
while (1) {
close(dup(0));
close(dup(fd));
syscall(SYS_getpid);
getuid();
umask(022);
iter++;
}
/* NOTREACHED */
case 'c':
fd = create_fd();
while (1) {
close(dup(0));
close(dup(fd));
iter++;
}
/* NOTREACHED */
Expand Down

0 comments on commit fb4521c

Please sign in to comment.