⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pangen6.h

📁 对软件进行可达性测试的软件
💻 H
📖 第 1 页 / 共 5 页
字号:
	"",	"	if (must_exit)",	"	{	rm_shared_segments();",	"		fprintf(stderr, \"pan: check './pan --' for usage details\\n\");",	"		pan_exit(1);	/* calls cleanup_shm */",	"	}",	"}",	"",	"static uchar *",	"prep_shmid_S(size_t n)		/* either sets SS or H_tab, linux/cygwin */",	"{	char	*rval;",	"#ifndef SEP_STATE",	"	key_t	key;",	"",	"	if (verbose && core_id == 0)",	"	{",	"	#ifdef BITSTATE",	"		printf(\"cpu0: step 1: allocate shared bitstate %%g Mb\\n\",",	"			(double) n / (1024. * 1024.));",	"	#else",	"		printf(\"cpu0: step 1: allocate shared hastable %%g Mb\\n\",",	"			(double) n / (1024. * 1024.));",	"	#endif",	"	}",	"	#ifdef MEMLIM", /* memlim has a value */	"	if (memcnt + (double) n > memlim)",	"	{	printf(\"cpu0: S %%8g + %%d Kb exceeds memory limit of %%8g Mb\\n\",",	"			memcnt/1024., n/1024, memlim/(1024.*1024.));",	"		printf(\"cpu0: insufficient memory -- aborting\\n\");",	"		exit(1);",	"	}",	"	#endif",	"",	"	key = ftok(PanSource, NCORE+2);	/* different from queues */",	"	if (key == -1)",	"	{	perror(\"ftok shared bitstate or hashtable\");",	"		fprintf(stderr, \"pan: check './pan --' for usage details\\n\");",	"		pan_exit(1);",	"	}",	"",	"	if (core_id == 0)	/* root */",	"	{	shmid_S = shmget(key, n, 0600);",	"		if (shmid_S != -1)",	"		{	printf(\"cpu0: removing stale segment, status: %%d\\n\",",	"				shmctl(shmid_S, IPC_RMID, NULL));",	"		}",	"		shmid_S = shmget(key, n, 0600 | IPC_CREAT | IPC_EXCL);",	"	} else			/* worker */",	"	{	shmid_S = shmget(key, n, 0600);",	"	}",	"	if (shmid_S == -1)",	"	{	perror(\"shmget shared bitstate or hashtable too large?\");",	"		fprintf(stderr, \"pan: check './pan --' for usage details\\n\");",	"		pan_exit(1);",	"	}",	"",	"	rval = (char *) shmat(shmid_S, (void *) 0, 0);	/* attach */",	"	if ((char *) rval == (char *) -1)",	"	{	perror(\"shmat shared bitstate or hashtable\");",	"		fprintf(stderr, \"pan: check './pan --' for usage details\\n\");",	"		pan_exit(1);",	"	}",	"	memcnt += (double) n;",	"#else",	"	rval = (char *) emalloc(n);",	"#endif",	"	return (uchar *) rval;",	"}",	"",	"#define TRY_AGAIN	1",	"#define NOT_AGAIN	0",	"",	"static char shm_prep_result;",	"",	"static uchar *",	"prep_state_mem(size_t n)		/* sets memory arena for states linux/cygwin */",	"{	char	*rval;",	"	key_t	key;",	"	static int cnt = 3;		/* start larger than earlier ftok calls */",	"",	"	shm_prep_result = NOT_AGAIN;	/* default */",	"	if (verbose && core_id == 0)",	"	{	printf(\"cpu0: step 2+: pre-allocate memory arena of %%g Mb\\n\",",	"			(double) n / (1024. * 1024.));",	"	}",	"	#ifdef MEMLIM",	"	if (memcnt + (double) n > memlim)",	"	{	printf(\"cpu0: error: M %%.0f + %%.0f Kb exceeds memory limit of %%.0f Mb\\n\",",	"			memcnt/1024.0, (double) n/1024.0, memlim/(1024.0*1024.0));",	"		return NULL;",	"	}",	"	#endif",	"",	"	key = ftok(PanSource, NCORE+cnt); cnt++;", /* starts at NCORE+3 */	"	if (key == -1)",	"	{	perror(\"ftok T\");",	"		printf(\"pan: check './pan --' for usage details\\n\");",	"		pan_exit(1);",	"	}",	"",	"	if (core_id == 0)",	"	{	shmid_M = shmget(key, n, 0600);",	"		if (shmid_M != -1)",	"		{	printf(\"cpu0: removing stale memory segment %%d, status: %%d\\n\",",	"				cnt-2, shmctl(shmid_M, IPC_RMID, NULL));",	"		}",	"		shmid_M = shmget(key, n, 0600 | IPC_CREAT | IPC_EXCL);",	"	} else",	"	{	shmid_M = shmget(key, n, 0600);",	"	",	"	}",	"	if (shmid_M == -1)",	"	{	if (verbose)",	"		{	printf(\"error: failed to get pool of shared memory %%d of %%.0f Mb\\n\",",	"				cnt-2, ((double)n)/(1024.0*1024.0));",	"			perror(\"state mem\");",	"			printf(\"pan: check './pan --' for usage details\\n\");",	"		}",	"		shm_prep_result = TRY_AGAIN;",	"		return NULL;",	"	}",	"	rval = (char *) shmat(shmid_M, (void *) 0, 0);	/* attach */",	"",	"	if ((char *) rval == (char *) -1)",	"	{	printf(\"error: failed to attach pool of shared memory %%d of %%.0f Mb\\n\",",	"			 cnt-2, ((double)n)/(1024.0*1024.0));",	"		perror(\"state mem\");",	"		return NULL;",	"	}",	"	return (uchar *) rval;",	"}",	"",	"void",	"init_HT(unsigned long n)	/* cygwin/linux version */",	"{	volatile char	*x;",	"	double  get_mem;",	"#ifndef SEP_STATE",	"	volatile char	*dc_mem_start;",	"	double  need_mem, got_mem = 0.;",	"#endif",	"","#ifdef SEP_STATE",	" #ifndef MEMLIM",	"	if (verbose)",	"	{	printf(\"cpu0: steps 0,1: no -DMEMLIM set\\n\");", /* cannot happen */	"	}",	" #else",	"	if (verbose)",	"	{	printf(\"cpu0: steps 0,1: -DMEMLIM=%%d Mb - (hashtable %%g Mb + workqueues %%g Mb)\\n\",",	"		MEMLIM, ((double)n/(1024.*1024.)), (2. * WQ_SIZE)/(1024.*1024.));",	"	}",	" #endif",	"	get_mem = NCORE * sizeof(double) + (1 + CS_NR) * sizeof(void *) + 3*sizeof(void *) + 2*sizeof(double);",	"	/* NCORE * is_alive + search_terminated + CS_NR * sh_lock + 5 gr vars */",	"	get_mem += 2 * NCORE * sizeof(void *);", /* prfree[NCORE] and prfull[NCORE] */	" #ifdef FULL_TRAIL",	"	get_mem += (NCORE) * sizeof(Stack_Tree *);",	"	/* NCORE * stack_last */",	" #endif",	"	x = (volatile char *) prep_state_mem((size_t) get_mem); /* work queues and basic structs */",	"	shmid_X = (long) x;",	"	if (x == NULL)", /* do not repeat for smaller sizes */	"	{	printf(\"cpu0: could not allocate shared memory, see ./pan --\\n\");",	"		exit(1);",	"	}",	"	search_terminated = (volatile unsigned int *) x; /* comes first */",	"	x += sizeof(void *); /* maintain alignment */",	"",	"	is_alive   = (volatile double *) x;",	"	x += NCORE * sizeof(double);",	"",	"	sh_lock   = (volatile int *) x;",	"	x += CS_NR * sizeof(void *);", /* allow 1 word per entry */	"",	"	grfree    = (volatile int *) x;",	"	x += sizeof(void *);",	"	grfull    = (volatile int *) x;",	"	x += sizeof(void *);",	"	grcnt    = (volatile int *) x;",	"	x += sizeof(void *);",	"	prfree = (volatile int *) x;",	"	x += NCORE * sizeof(void *);",	"	prfull = (volatile int *) x;",	"	x += NCORE * sizeof(void *);",	"	gr_readmiss    = (volatile double *) x;",	"	x += sizeof(double);",	"	gr_writemiss    = (volatile double *) x;",	"	x += sizeof(double);",	"",	"	#ifdef FULL_TRAIL",	"		stack_last = (volatile Stack_Tree **) x;",	"		x += NCORE * sizeof(Stack_Tree *);",	"	#endif",	"",	"	#ifndef BITSTATE",	"		H_tab = (struct H_el **) emalloc(n);",	"	#endif","#else",	"	#ifndef MEMLIM", /* cannot happen */	"		memlim = memcnt + 2. * WQ_SIZE + (double) n + 1024.*1024.*1024. ;",	"		/* end up with 1 Gb -- the default memlim in pan.c is 1 Gb",	"		 * which isn't enough on linux given that the WQ_SIZES can take 1 Gb",	"		 */",	"		if (core_id == 0 && verbose)",	"		printf(\"cpu0: step 0: no -DMEMLIM - reserving %%g Mb for state storage\\n\",",	"		(memlim - memcnt - (double) n - (2. * WQ_SIZE))/(1024.*1024.));",	"	#else",	"		if (core_id == 0 && verbose)",	"		printf(\"cpu0: step 0: -DMEMLIM=%%d Mb - (hashtable+workqs: %%g + %%g Mb) = %%g Mb\\n\",",	"		MEMLIM, ((double)n/(1024.*1024.)), (2. * WQ_SIZE)/(1024.*1024.),",	"		(memlim - memcnt - (double) n - (2. * WQ_SIZE))/(1024.*1024.));",	"	#endif",	"	#ifndef BITSTATE",	"		H_tab = (struct H_el **) prep_shmid_S((size_t) n);	/* hash_table */",	"	#endif",	"	need_mem = memlim - memcnt - 2. * (double) (WQ_SIZE);		/* try to get max */",	"	if (need_mem <= 0)",	"	{	Uerror(\"internal error -- shared state memory\");",	"	}",	"",	"	if (core_id == 0 && verbose)",	"	{	printf(\"cpu0: step 2: pre-allocate shared state memory %%g Mb\\n\",",	"			need_mem/(1024.*1024.));",	"	}",	"	while (need_mem > 0.)",	"	{	get_mem = need_mem;",	"shm_more:",	"		if (get_mem > (double) SEG_SIZE)",	"		{	get_mem = (double) SEG_SIZE;",	"		}",	"",	"		/* for allocating states: */",	"		x = dc_mem_start = (volatile char *) prep_state_mem((size_t) get_mem);",	"		if (x == NULL)",	"		{	if (shm_prep_result == NOT_AGAIN",	"			||  first_pool != NULL",	"			||  SEG_SIZE < (16. * 1024. * 1024.))",	"			{	break;",	"			}",	"			SEG_SIZE /= 2.;",	"			if (verbose)",	"			{	printf(\"pan: lowered segsize to %f\\n\", SEG_SIZE);",	"			}",	"			goto shm_more;", /* always terminates */	"		}",	"",	"		need_mem -= get_mem;",	"		got_mem  += get_mem;",	"		if (first_pool == NULL)",	"		{	search_terminated = (volatile unsigned int *) x; /* comes first */",	"			x += sizeof(void *); /* maintain alignment */",	"",	"			is_alive   = (volatile double *) x;",	"			x += NCORE * sizeof(double);",	"",	"			sh_lock   = (volatile int *) x;",	"			x += CS_NR * sizeof(void *);", /* allow 1 word per entry */	"",	"			grfree    = (volatile int *) x;",	"			x += sizeof(void *);",	"			grfull    = (volatile int *) x;",	"			x += sizeof(void *);",	"			grcnt    = (volatile int *) x;",	"			x += sizeof(void *);",	"			prfree = (volatile int *) x;",	"			x += NCORE * sizeof(void *);",	"			prfull = (volatile int *) x;",	"			x += NCORE * sizeof(void *);",	"			gr_readmiss  = (volatile double *) x;",	"			x += sizeof(double);",	"			gr_writemiss = (volatile double *) x;",	"			x += sizeof(double);",	" #ifdef FULL_TRAIL",	"			stack_last = (volatile Stack_Tree **) x;",	"			x += NCORE * sizeof(Stack_Tree *);",	" #endif",	"			if (((long)x)&(sizeof(void *)-1)) /* 64-bit word alignment */",	"			{	x += sizeof(void *)-(((long)x)&(sizeof(void *)-1));",	"			}",	"",	"			#ifdef COLLAPSE",	"			ncomps = (unsigned long *) x;",	"			x += (256+2) * sizeof(unsigned long);",	"			#endif",	"		}",	"",	"		dc_shared = (sh_Allocater *) x; /* must be in shared memory */",	"		x += sizeof(sh_Allocater);",	"",	"		if (core_id == 0)	/* root only */",	"		{	dc_shared->dc_id     = shmid_M;",	"			dc_shared->dc_start  = dc_mem_start;",	"			dc_shared->dc_arena  = x;",	"			dc_shared->pattern   = 1234567; /* protection */",	"			dc_shared->dc_size   = (long) get_mem - (long) (x - dc_mem_start);",	"			dc_shared->nxt       = (long) 0;",	"",	"			if (last_pool == NULL)",	"			{	first_pool = last_pool = dc_shared;",	"			} else",	"			{	last_pool->nxt = dc_shared;",	"				last_pool = dc_shared;",	"			}",	"		} else if (first_pool == NULL)",	"		{	first_pool = dc_shared;",	"	}	}",	"",	"	if (need_mem > 0.)",	"	{	printf(\"cpu0: could allocate only %%g Mb of shared memory (wanted %%g more)\\n\",",	"			got_mem/(1024.*1024.), need_mem/(1024.*1024.));",	"	}",	"",	"	if (!first_pool)",	"	{	printf(\"cpu0: insufficient memory -- aborting.\\n\");",	"		exit(1);",	"	}",	"	dc_shared = first_pool;","#endif", /* !SEP_STATE */	"}",	"",	"	/* Test and Set assembly code */",	"",	"	#if defined(__i386__) || defined(__x86_64__)",	"		int",	"		tas(volatile int *s)	/* tested */",	"		{	int r;",	"			__asm__ __volatile__(",	"				\"xchgl %%0, %%1 \\n\\t\"",	"		       		: \"=r\"(r), \"=m\"(*s)",	"				: \"0\"(1), \"m\"(*s)",	"				: \"memory\");",	"		",	"			return r;",	"		}",	"	#elif defined(__arm__)",	"		int",	"		tas(volatile int *s)	/* not tested */",	"		{	int r = 1;",	"			__asm__ __volatile__(",	"				\"swpb %%0, %%0, [%%3] \\n\"",	"				: \"=r\"(r), \"=m\"(*s)",	"				: \"0\"(r), \"r\"(s));",	"",	"			return r;",	"		}",	"	#elif defined(__sparc__)",	"		int",	"		tas(volatile int *s)	/* not tested */",	"		{	int r = 1;",	"			__asm__ __volatile__(",	"				\" ldstub [%%2], %%0 \\n\"",	"				: \"=r\"(r), \"=m\"(*s)",	"				: \"r\"(s));",	"",	"			return r;",	"		}",	"	#elif defined(__ia64__)",	"		/* Intel Itanium */",	"		int",	"		tas(volatile int *s)",	"		{	long int r;",	"			__asm__ __volatile__(",	"				\"	xchg4 	%%0=%%1,%%2	\\n\"",	"		:		\"=r\"(r), \"+m\"(*s)",	"		:		\"r\"(1)",	"		:		\"memory\");",	"			return (int) r;",	"		}",	"	#else",	"		#error missing definition of test and set operation for this platform",	"	#endif",	"",	"void",	"cleanup_shm(int val)",	"{	volatile sh_Allocater *nxt_pool;",	"	unsigned long cnt = 0;",	"	int m;",	"",	"	if (nibis != 0)",	"	{	printf(\"cpu%%d: Redundant call to cleanup_shm(%%d)\\n\", core_id, val);",	"		return;",	"	} else",	"	{	nibis = 1;",	"	}",	"	if (search_terminated != NULL)",	"	{	*search_terminated |= 16; /* cleanup_shm */",	"	}",	"",	"	for (m = 0; m < NR_QS; m++)",	"	{	if (shmdt((void *) shared_mem[m]) > 0)",	"		{	perror(\"shmdt detaching from shared queues\");",	"	}	}",	"",	"#ifdef SEP_STATE",

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -