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));
58 static void setup_locks(int fd, int start, int end)
61 for (i=start;i<end;i++) {
62 brlock(fd, 2*i, F_WRLCK, F_SETLKW);
67 int main(int argc, char *argv[])
70 const char *fname = "lock_scaling.dat";
73 fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0600);
82 while (nlocks < 2<<20) {
86 printf("setting up %d locks...\r", nlocks);
88 setup_locks(fd, nlocks/2, nlocks);
92 while (end_timer() < 5.0) {
93 double t1 = end_timer();
94 while ((t=end_timer()) < t1+1.0) {
95 brlock(fd, 2*nlocks, F_WRLCK, F_SETLKW);
96 brlock(fd, 2*nlocks, F_UNLCK, F_SETLKW);
99 printf("%7d %8.1f locks/sec \r", nlocks, count/t);
102 printf("%7d %8.1f locks/sec\n", nlocks, count/t);