Explorar el Código

- netbsd fixes
- 64 bit mini-cleanup

Andrei Pelinescu-Onciul hace 23 años
padre
commit
85f1f3eeca
Se han modificado 10 ficheros con 108 adiciones y 73 borrados
  1. 52 25
      Makefile.defs
  2. 2 2
      fastlock.h
  3. 17 11
      main.c
  4. 8 8
      mem/f_malloc.h
  5. 2 2
      mem/q_malloc.c
  6. 14 14
      mem/q_malloc.h
  7. 6 6
      mem/vq_malloc.h
  8. 4 2
      modules/tm/sip_msg.c
  9. 2 2
      test/stateless.cfg
  10. 1 1
      test/test-throughput.cfg

+ 52 - 25
Makefile.defs

@@ -12,7 +12,7 @@ EXTRAVERSION =
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
-ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc/  \
+ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/  \
 			-e s/armv4l/arm/)
 
  # install location
@@ -220,11 +220,13 @@ $(warning	Unknown compiler $(CC)\; supported compilers: \
 			gcc, sun cc, intel icc )
 endif
 
-# find ldname (gnu or solaris)
-ifeq ($(ARCH), sparc)
+# find ld & as name (gnu or solaris)
+ifeq ($(ARCH), sparc64)
 ifeq ($(CC_NAME), gcc)
 		LDGCC=$(shell $(CC) -v 2>&1 | grep with-ld| \
 				   sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
+		ASGCC=$(shell $(CC) -v 2>&1 | grep with-as| \
+				   sed -e 's/.*--with-as=\([^ ][^ ]*\).*/\1/' )
 		LDPATH=$(shell  if [ -z "$(LDGCC)" ] ; then echo "ld" ;\
 						else \
 						if $(LDGCC) -V 2>/dev/null 1>/dev/null; then \
@@ -232,7 +234,14 @@ ifeq ($(CC_NAME), gcc)
 						else echo "ld" ; \
 						fi\
 						fi)
-						
+		ASPATH=$(shell  if [ -z "$(ASGCC)" ] ; then echo "as" ;\
+						else \
+						if $(ASGCC) -V 2>/dev/null 1>/dev/null; then \
+							echo $(ASGCC); \
+						else echo "as" ; \
+						fi\
+						fi)
+							
 		LDTYPE=$(shell if $(LDPATH) -V 1>/dev/null  2>/dev/null; then \
 							if $(LDPATH) -V 2>&1|grep GNU >/dev/null; \
 							then echo gnu; \
@@ -244,6 +253,20 @@ ifeq ($(CC_NAME), gcc)
 							fi \
 							fi \
 						fi)
+		ASTYPE=$(shell if $(ASPATH) -V 1>/dev/null  2>/dev/null </dev/null; \
+						then \
+							if $(ASPATH) -V 2>&1 </dev/null |grep GNU >/dev/null; \
+							then echo gnu; \
+							else \
+							if $(ASPATH) -V 2>&1 </dev/null |grep Sun >/dev/null;\
+							then echo solaris; \
+							else \
+								echo unknown ; \
+							fi \
+							fi \
+						fi)
+#$(warning "using ld=$(LDPATH)/$(LDTYPE), as=$(ASPATH)/$(ASTYPE)")
+
 endif
 endif
 
@@ -252,7 +275,7 @@ ifeq ($(ARCH), i386)
 	DEFS+= -DFAST_LOCK
 endif
 
-ifeq ($(ARCH), sparc)
+ifeq ($(ARCH), sparc64)
 ifeq 	($(CC_NAME), gcc)
 		DEFS+= -DFAST_LOCK
 endif
@@ -310,11 +333,11 @@ endif	#ARCH, i386
 
 
 	#if sparc
-ifeq	($(ARCH), sparc)
+ifeq	($(ARCH), sparc64)
 			#if gcc
 ifeq		($(CC_NAME), gcc)
 				#common stuff
-				CFLAGS=-O9 -funroll-loops  $(PROFILE) \
+				CFLAGS=-g -O9 -funroll-loops  $(PROFILE) \
 					-Wall\
 					#-Wcast-align \
 					#-Wmissing-prototypes 
@@ -330,14 +353,24 @@ else			# CC_SHORTVER, 3.0
 ifeq			($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
 $(warning 			Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
 					for better results)
-					
-					CFLAGS+= -mv8 -Wa,-xarch=v8plus
+ifneq				($(OS), netbsd)
+						# on netbsd/sparc64,  gcc 2.95.3 does not compile
+						# ser with -mv8
+						CFLAGS+= -mv8 
+endif
+ifeq					($(ASTYPE), solaris)
+							CFLAGS+= -Wa,-xarch=v8plus
+endif					
 else			#CC_SHORTVER, 2.9x
 				#really old version
 $(warning			You are using an old and unsupported gcc \
 					 version ($(CC_SHORTVER)), compile at your own risk!)
 					
-					CFLAGS+= -mv8 -Wa,-xarch=v8plus
+					CFLAGS+= -mv8 
+ifeq					($(ASTYPE), solaris)
+							CFLAGS+= -Wa,-xarch=v8plus
+endif					
+	
 endif			#CC_SHORTVER, 2.9x
 endif			#CC_SHORTVER, 3.0
 
@@ -390,7 +423,7 @@ endif	#ARCH, i386
 LDFLAGS=
 # setting LDFLAGS
 ifeq	($(CC_NAME), gcc)
-ifeq		($(ARCH), sparc)
+ifeq		($(ARCH), sparc64)
 ifeq			($(LDTYPE), solaris)
 					# solaris ld
 					LDFLAGS+=-O2 $(PROFILE)
@@ -421,7 +454,7 @@ endif
 else	#mode,release
 ifeq	($(CC_NAME), gcc)
 		CFLAGS=-g -Wcast-align $(PROFILE)
-ifeq		($(ARCH), sparc)
+ifeq		($(ARCH), sparc64)
 			CFLAGS+= -mcpu=ultrasparc 
 endif
 ifeq		($(LDTYPE), solaris)
@@ -469,21 +502,14 @@ YACC_FLAGS=-d -b cfg
 # on solaris add -lxnet (e.g. LIBS= -lxnet)
 LIBS= -lfl -ldl -lresolv
 
-ifneq ($(OS), solaris)
-	DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN
-endif
-ifneq ($(OS), openbsd)
-	DEFS+=-DHAVE_SCHED_YIELD
-endif
-
 
 #os specific stuff
 ifeq ($(OS), linux)
-	#same as common
+	DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD
 endif
 
 ifeq  ($(OS), solaris)
-	DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H
+	DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H -DHAVE_SCHED_YIELD
 	ifeq ($(mode), release)
 		#use these only if you're using gcc with Solaris ld
 		#LDFLAGS=-O2 $(PROFILE)
@@ -503,13 +529,14 @@ endif
 endif
 
 ifeq ($(OS), freebsd)
-	DEFS+=-DHAVE_SOCKADDR_SA_LEN
+	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
+		-DHAVE_SCHED_YIELD
 	YACC=yacc
 	LIBS= -lfl  #dlopen is in libc
 endif
 
 ifeq ($(OS), openbsd)
-	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DDLSYM_PREFIX='"_"'
+	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DDLSYM_PREFIX='"_"' -DHAVE_GETHOSTBYNAME2 
 	# (symbols on openbsd are prefixed by "_")
 	YACC=yacc
 	# no sched_yield on openbsd unless linking with c_r (not recommended)
@@ -518,9 +545,9 @@ ifeq ($(OS), openbsd)
 endif
 	
 ifeq ($(OS), netbsd)
-	DEFS+=-DHAVE_SOCKADDR_SA_LEN
+	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 
 	YACC=yacc
-	LIBS= -lfl  -lc_r
+	LIBS= -lfl 
 endif
 
 ifneq (,$(findstring CYGWIN, $(OS)))

+ 2 - 2
fastlock.h

@@ -72,7 +72,7 @@ inline static int tsl(fl_lock_t* lock)
 		" xchg %b1, %0" : "=q" (val), "=m" (*lock) : "0" (val) : "memory"
 	);
 #endif /*NOSMP*/
-#elif defined __CPU_sparc
+#elif defined __CPU_sparc64
 	asm volatile(
 			"ldstub [%1], %0 \n\t"
 #ifndef NOSMP
@@ -125,7 +125,7 @@ inline static void release_lock(fl_lock_t* lock)
 		" movb $0, (%0)" : /*no output*/ : "r"(lock): "memory"
 		/*" xchg %b0, %1" : "=q" (val), "=m" (*lock) : "0" (val) : "memory"*/
 	); 
-#elif defined __CPU_sparc
+#elif defined __CPU_sparc64
 	asm volatile(
 #ifndef NOSMP
 			"membar #LoadStore | #StoreStore \n\t" /*is this really needed?*/

+ 17 - 11
main.c

@@ -38,8 +38,9 @@
 #include <arpa/inet.h>
 #include <sys/utsname.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/mman.h>
-#include <sys/fcntl.h>
+#include <fcntl.h>
 #include <sys/time.h>
 #include <sys/wait.h>
 #include <pwd.h>
@@ -747,9 +748,10 @@ static void sig_usr(int signo)
 int add_interfaces(char* if_name, int family, unsigned short port)
 {
 	struct ifconf ifc;
-	struct ifreq* ifr;
+	struct ifreq ifr;
 	struct ifreq ifrcopy;
 	char*  last;
+	char* p;
 	int size;
 	int lastlen;
 	int s;
@@ -787,27 +789,30 @@ int add_interfaces(char* if_name, int family, unsigned short port)
 	}
 	
 	last=(char*)ifc.ifc_req+ifc.ifc_len;
-	for(ifr=ifc.ifc_req; (char*)ifr<last;
-			ifr=(struct ifreq*)((char*)ifr+sizeof(ifr->ifr_name)+
+	for(p=(char*)ifc.ifc_req; p<last;
+			p+=(sizeof(ifr.ifr_name)+
 			#ifdef  HAVE_SOCKADDR_SA_LEN
-				MAX(ifr->ifr_addr.sa_len, sizeof(struct sockaddr))
+				MAX(ifr.ifr_addr.sa_len, sizeof(struct sockaddr))
 			#else
-				( (ifr->ifr_addr.sa_family==AF_INET)?
+				( (ifr.ifr_addr.sa_family==AF_INET)?
 					sizeof(struct sockaddr_in):
-					((ifr->ifr_addr.sa_family==AF_INET6)?
+					((ifr.ifr_addr.sa_family==AF_INET6)?
 						sizeof(struct sockaddr_in6):sizeof(struct sockaddr)) )
 			#endif
 				)
 		)
 	{
-		if (ifr->ifr_addr.sa_family!=family){
+		/* copy contents into ifr structure
+		 * warning: it might be longer (e.g. ipv6 address) */
+		memcpy(&ifr, p, sizeof(ifr));
+		if (ifr.ifr_addr.sa_family!=family){
 			/*printf("strange family %d skipping...\n",
 					ifr->ifr_addr.sa_family);*/
 			continue;
 		}
 		
 		/*get flags*/
-		memcpy(&ifrcopy, ifr, sizeof(ifrcopy));
+		ifrcopy=ifr;
 		if (ioctl(s, SIOCGIFFLAGS,  &ifrcopy)!=-1){ /* ignore errors */
 			/* ignore down ifs only if listening on all of them*/
 			if (if_name==0){ 
@@ -819,11 +824,12 @@ int add_interfaces(char* if_name, int family, unsigned short port)
 		
 		
 		if ((if_name==0)||
-			(strncmp(if_name, ifr->ifr_name, sizeof(ifr->ifr_name))==0)){
+			(strncmp(if_name, ifr.ifr_name, sizeof(ifr.ifr_name))==0)){
 			
 				/*add address*/
 			if (sock_no<MAX_LISTEN){
-				sockaddr2ip_addr(&addr, &ifr->ifr_addr);
+				sockaddr2ip_addr(&addr, 
+					(struct sockaddr*)(p+(long)&((struct ifreq*)0)->ifr_addr));
 				if ((tmp=ip_addr2a(&addr))==0) goto error;
 				/* fill the strings*/
 				sock_info[sock_no].name.s=(char*)malloc(strlen(tmp)+1);

+ 8 - 8
mem/f_malloc.h

@@ -55,26 +55,26 @@
  * +1 .... end -  size = 2^k, big buckets */
 
 struct fm_frag{
-	unsigned int size;
+	unsigned long size;
 	union{
 		struct fm_frag* nxt_free;
-		int reserved;
+		long reserved;
 	}u;
 #ifdef DBG_F_MALLOC
 	char* file;
 	char* func;
-	unsigned int line;
-	unsigned int check;
+	unsigned long line;
+	unsigned long check;
 #endif
 };
 
 
 struct fm_block{
-	unsigned int size; /* total size */
+	unsigned long size; /* total size */
 #ifdef DBG_F_MALLOC
-	unsigned int used; /* alloc'ed size*/
-	unsigned int real_used; /* used+malloc overhead*/
-	unsigned int max_real_used;
+	unsigned long used; /* alloc'ed size*/
+	unsigned long real_used; /* used+malloc overhead*/
+	unsigned long max_real_used;
 #endif
 	
 	struct fm_frag* first_frag;

+ 2 - 2
mem/q_malloc.c

@@ -149,11 +149,11 @@ struct qm_block* qm_malloc_init(char* address, unsigned int size)
 	char* start;
 	char* end;
 	struct qm_block* qm;
-	unsigned int init_overhead;
+	unsigned long init_overhead;
 	int h;
 	
 	/* make address and size multiple of 8*/
-	start=(char*)ROUNDUP((unsigned int) address);
+	start=(char*)ROUNDUP((unsigned long) address);
 	DBG("qm_malloc_init: QM_OPTIMIZE=%d, /ROUNDTO=%d\n",
 			QM_MALLOC_OPTIMIZE, QM_MALLOC_OPTIMIZE/ROUNDTO);
 	DBG("qm_malloc_init: QM_HASH_SIZE=%d, qm_block size=%d\n",

+ 14 - 14
mem/q_malloc.h

@@ -34,7 +34,7 @@
 
 /* defs*/
 #ifdef DBG_QM_MALLOC
-	#define ROUNDTO		 4 /* minimum possible ROUNDTO ->heavy debugging*/
+	#define ROUNDTO		 8 /* minimum possible ROUNDTO ->heavy debugging*/
 #else
 	#define ROUNDTO		16 /* size we round to, must be = 2^n  and also
 							 sizeof(qm_frag)+sizeof(qm_frag_end)
@@ -60,27 +60,27 @@
  * +1 .... end -  size = 2^k, big buckets */
 
 struct qm_frag{
-	unsigned int size;
+	unsigned long size;
 	union{
 		struct qm_frag* nxt_free;
-		int is_free;
+		long is_free;
 	}u;
 #ifdef DBG_QM_MALLOC
 	char* file;
 	char* func;
-	unsigned int line;
-	unsigned int check;
+	unsigned long line;
+	unsigned long check;
 #endif
 };
 
 struct qm_frag_end{
 #ifdef DBG_QM_MALLOC
-	unsigned int check1;
-	unsigned int check2;
-	unsigned int reserved1;
-	unsigned int reserved2;
+	unsigned long check1;
+	unsigned long check2;
+	unsigned long reserved1;
+	unsigned long reserved2;
 #endif
-	unsigned int size;
+	unsigned long size;
 	struct qm_frag* prev_free;
 };
 
@@ -93,10 +93,10 @@ struct qm_frag_full{
 
 
 struct qm_block{
-	unsigned int size; /* total size */
-	unsigned int used; /* alloc'ed size*/
-	unsigned int real_used; /* used+malloc overhead*/
-	unsigned int max_real_used;
+	unsigned long size; /* total size */
+	unsigned long used; /* alloc'ed size*/
+	unsigned long real_used; /* used+malloc overhead*/
+	unsigned long max_real_used;
 	
 	struct qm_frag* first_frag;
 	struct qm_frag_end* last_frag_end;

+ 6 - 6
mem/vq_malloc.h

@@ -77,7 +77,7 @@ struct vqm_frag {
 	/* total chunk size including all overhead/bellowfoot/roundings/etc */
 	/* useless as otherwise size implied by bucket (if I really want to save 
        bytes, I'll remove it  from here */
-	unsigned int size;
+	unsigned long size;
 	union{
 		/* pointer to next chunk in a bucket if free */
 		struct vqm_frag* nxt_free; 
@@ -90,18 +90,18 @@ struct vqm_frag {
 	/* source code info */
 	char* file;
 	char* func;
-	unsigned int line;
+	unsigned long line;
 	/* your safety is important to us! safety signatures */
-	unsigned int check;
+	unsigned long check;
 	char *end_check;
 	/* the size user was originally asking for */
-	unsigned int demanded_size;
+	unsigned long demanded_size;
 #endif
 };
 
 struct vqm_frag_end{
 	/* total chunk size including all overhead/bellowfoot/roundings/etc */
-	unsigned int size; 
+	unsigned long size; 
 	/* XXX */
 	/* used only for variable-size chunks; might have different
            data structures for variable/fixed length chunks */
@@ -121,7 +121,7 @@ struct vqm_block{
 	/* ... and its available net amount; note that there's lot of
            free memory in buckets too -- this just tells about memory
 	   which has not been assigned to chunks  */
-	unsigned int free_core;
+	unsigned long free_core;
 	/* we allocate huge chunks from the end on; this is the
 	   pointer to big chunks
     */

+ 4 - 2
modules/tm/sip_msg.c

@@ -46,9 +46,11 @@
 #include "../../ut.h"
 
 
-
+/* rounds to the first 4 byte multiple on 32 bit archs 
+ * and to the first 8 byte mutlipe on 64 bit archs */
 #define ROUND4(s) \
-	(((s)+3)&(~(3UL)))
+	(((s)+(sizeof(char*)-1))&(~(sizeof(char*)-1)))
+
 #define lump_len( _lump) \
 	(ROUND4(sizeof(struct lump)) +\
 	ROUND4(((_lump)->op==LUMP_ADD)?(_lump)->len:0))

+ 2 - 2
test/stateless.cfg

@@ -5,7 +5,7 @@
 #
 
 
-debug=9          # debug level (cmd line: -dddddddddd)
+#debug=9          # debug level (cmd line: -dddddddddd)
 #fork=yes          # (cmd. line: -D)
 #log_stderror=yes # (cmd line: -E)
 #log_stderror=no	# (cmd line: -E)
@@ -33,6 +33,6 @@ route{
 	if (myself==uri){
 		log("\n\nfrom myself\n\n");
 	};
-	log("\n\n continue \n\n");
+	log(" continue \n\n");
 	forward(uri:host, uri:port);
 }

+ 1 - 1
test/test-throughput.cfg

@@ -1,4 +1,4 @@
-debug=9			# for speed
+#debug=9			# for speed
 check_via=0
 dns=off
 rev_dns=off