Browse Source

- introduced the ADAPTIVE_LOCK

Andrei Pelinescu-Onciul 23 năm trước cách đây
mục cha
commit
30f1f956f9
4 tập tin đã thay đổi với 40 bổ sung2 xóa
  1. 12 0
      Makefile.defs
  2. 10 0
      fastlock.h
  3. 17 1
      main.c
  4. 1 1
      test/th-uri-2.cfg

+ 12 - 0
Makefile.defs

@@ -55,10 +55,22 @@ ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/ )
 # -DFAST_LOCK
 #		uses fast arhitecture specific locking (see the arh. specific section)
 #
+# -DBUSY_WAIT
+#		uses busy waiting on the lock
+# -DADAPTIVE_WAIT
+#		try busy waiting for a while and if the lock is still held go to
+#		force reschedule
+# -DADAPTIVE_WAIT_LOOPS=number
+#		number of loops we busy wait, after "number" loops have elapsed we 
+#		force a reschedule
+# -DNOSMP
+#		don't use smp compliant locking (faster but won't work on SMP machines)
+#		(not yet enabled)
 
 DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
 	 -DOS='"$(OS)"' -DCOMPILER='"$(CC_VER)"'\
 	 -DDNS_IP_HACK  -DPKG_MALLOC -DSHM_MEM  -DSHM_MMAP \
+	 -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 \
 	 -DF_MALLOC  -DUSE_SYNONIM\
 	 -DNO_DEBUG
 	 #-DEXTRA_DEBUG 

+ 10 - 0
fastlock.h

@@ -29,6 +29,7 @@ typedef  volatile int fl_lock_t;
 inline static int tsl(fl_lock_t* lock)
 {
 	volatile int val;
+
 #ifdef __i386
 	
 	val=1;
@@ -51,9 +52,18 @@ inline static int tsl(fl_lock_t* lock)
 
 inline static void get_lock(fl_lock_t* lock)
 {
+#ifdef ADAPTIVE_WAIT
+	int i=ADAPTIVE_WAIT_LOOPS;
+#endif
 	
 	while(tsl(lock)){
+#ifdef BUSY_WAIT
+#elif defined ADAPTIVE_WAIT
+		if (i>0) i--;
+		else sched_yield();
+#else
 		sched_yield();
+#endif
 	}
 }
 

+ 17 - 1
main.c

@@ -88,7 +88,16 @@ static char flags[]=
 #endif
 #ifdef FAST_LOCK
 ", FAST_LOCK"
+#ifdef BUSY_WAIT
+"-BUSY_WAIT"
 #endif
+#ifdef ADAPTIVE_WAIT
+"-ADAPTIVE_WAIT"
+#endif
+#ifdef NOSMP
+"-NOSMP"
+#endif
+#endif /*FAST_LOCK*/
 ;
 
 static char help_msg[]= "\
@@ -129,7 +138,14 @@ Options:\n\
 /* print compile-time constants */
 void print_ct_constants()
 {
-	printf("MAX_RECV_BUFFER_SIZE %d, MAX_LISTEN %d, MAX_URI_SIZE %d, MAX_PROCESSES %d\n",
+#ifdef ADAPTIVE_WAIT
+	printf("ADAPTIVE_WAIT_LOOPS=%d, ", ADAPTIVE_WAIT_LOOPS);
+#endif
+#ifdef SHM_MEM
+	printf("SHM_MEM_SIZE=%d, ", SHM_MEM_SIZE);
+#endif
+	printf("MAX_RECV_BUFFER_SIZE %d, MAX_LISTEN %d,"
+			" MAX_URI_SIZE %d, MAX_PROCESSES %d\n",
 		MAX_RECV_BUFFER_SIZE, MAX_LISTEN, MAX_URI_SIZE, MAX_PROCESSES );
 }
 

+ 1 - 1
test/th-uri-2.cfg

@@ -15,7 +15,7 @@ log_stderror=yes # (cmd line: -E)
 #log_stderror=no	# (cmd line: -E)
 
 
-children=4
+children=2
 check_via=no     # (cmd. line: -v)
 dns=on           # (cmd. line: -r)
 rev_dns=yes      # (cmd. line: -R)