Răsfoiți Sursa

- first attempt at sparc64 asm sync

Andrei Pelinescu-Onciul 24 ani în urmă
părinte
comite
c4217e618d
4 a modificat fișierele cu 34 adăugiri și 13 ștergeri
  1. 4 0
      Makefile.defs
  2. 18 2
      fastlock.h
  3. 2 1
      main.c
  4. 10 10
      mem/mem.c

+ 4 - 0
Makefile.defs

@@ -76,6 +76,10 @@ ifeq ($(ARCH), i386)
 	DEFS+= -DFAST_LOCK
 endif
 
+ifeq ($(ARCH), sparc64)
+	DEFS+= -DFAST_LOCK
+endif
+
 
 #PROFILE=  -pg #set this if you want profiling
 #mode = debug

+ 18 - 2
fastlock.h

@@ -15,7 +15,6 @@
 #include <sched.h>
 
 
-#ifdef __i386
 
 
 typedef  volatile int lock_t;
@@ -30,12 +29,20 @@ typedef  volatile int lock_t;
 inline static int tsl(lock_t* lock)
 {
 	volatile char val;
+#ifdef __i386
 	
 	val=1;
 	asm volatile( 
 		" xchg %b0, %1" : "=q" (val), "=m" (*lock) : "0" (val) : "memory"
 	);
 	return val;
+#elif defined __sparc64
+	asm volatile(
+			"ldstub [%1], %0 \n\t"
+			"membar #StoreStore | #StoreLoad \n\t"
+			: "=r"(val) : "r"(lock):"memory"
+	);
+#endif
 }
 
 
@@ -54,13 +61,22 @@ inline static void release_lock(lock_t* lock)
 {
 	char val;
 
+#ifdef __i386
 	val=0;
 	asm volatile(
 		" xchg %b0, %1" : "=q" (val), "=m" (*lock) : "0" (val) : "memory"
+	); /* hmm, maybe lock; movb $0, [%1] would be faster ???*/
+#elif defined __sparc64
+	asm volatile(
+			"membar #LoadStore | #StoreStore \n\t" /*is this really needed?*/
+			"stb %%g0, [%0] \n\t"
+			: /*no output*/
+			: "r" (lock)
+			: "memory"
 	);
+#endif
 }
 
-#endif
 
 
 #endif

+ 2 - 1
main.c

@@ -647,7 +647,8 @@ int main(int argc, char** argv)
 	
 	if (children_no<=0) children_no=CHILD_NO;
 	else if (children_no >= MAX_PROCESSES ) {
-		fprintf(stderr, "ERROR: too many children processes configured; maximum is %d\n",
+		fprintf(stderr, "ERROR: too many children processes configured;"
+				" maximum is %d\n",
 			MAX_PROCESSES-1 );
 		goto error;
 	}

+ 10 - 10
mem/mem.c

@@ -28,25 +28,25 @@
 int init_mallocs()
 {
 #ifdef PKG_MALLOC
-        /*init mem*/
+	/*init mem*/
 	#ifdef VQ_MALLOC
-        	mem_block=vqm_malloc_init(mem_pool, PKG_MEM_POOL_SIZE);
+		mem_block=vqm_malloc_init(mem_pool, PKG_MEM_POOL_SIZE);
 	#elif F_MALLOC
 		mem_block=fm_malloc_init(mem_pool, PKG_MEM_POOL_SIZE);
 	#else
-        	mem_block=qm_malloc_init(mem_pool, PKG_MEM_POOL_SIZE);
+		mem_block=qm_malloc_init(mem_pool, PKG_MEM_POOL_SIZE);
 	#endif
-        if (mem_block==0){
-                LOG(L_CRIT, "could not initialize memory pool\n");
+	if (mem_block==0){
+		LOG(L_CRIT, "could not initialize memory pool\n");
 		return -1;
-        }
+	}
 #endif
 
 #ifdef SHM_MEM
-        if (shm_mem_init()<0) {
-                LOG(L_CRIT, "could not initialize shared memory pool, exiting...\n");
-                return -1;
-        }
+	if (shm_mem_init()<0) {
+		LOG(L_CRIT, "could not initialize shared memory pool, exiting...\n");
+		return -1;
+	}
 #endif
 	return 0;