2 demonstrate problem with linear lock lists
4 tridge@samba.org, February 2004
18 static struct timeval tp1,tp2;
20 static double tvdiff(struct timeval *tv1, struct timeval *tv2)
22 return (tv2->tv_sec + (tv2->tv_usec*1.0e-6)) -
23 (tv1->tv_sec + (tv1->tv_usec*1.0e-6));
26 static void start_timer()
28 gettimeofday(&tp1,NULL);
31 static double end_timer()
33 gettimeofday(&tp2,NULL);
35 return tvdiff(&tp1, &tp2);
38 static int brlock(int fd, off_t offset, int rw_type, int lck_type)
44 fl.l_whence = SEEK_SET;
49 ret = fcntl(fd,lck_type,&fl);
52 printf("brlock failed offset=%d rw_type=%d lck_type=%d : %s\n",
53 (int)offset, rw_type, lck_type, strerror(errno));
59 int main(int argc, char *argv[])
63 const char *fname = "lock_scaling.dat";
66 printf("Usage: lock_scaling <nlocks>\n");
70 nlocks = atoi(argv[1]);
72 fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0600);
78 for (i=0;i<nlocks;i++) {
79 brlock(fd, 2*i, F_WRLCK, F_SETLKW);
87 while ((t=end_timer()) < 1.0) {
88 brlock(fd, 2*nlocks, F_WRLCK, F_SETLKW);
89 brlock(fd, 2*nlocks, F_UNLCK, F_SETLKW);
92 printf("%.1f locks/sec\r", count/t);