📄 vmem.c
字号:
fill(base, size, ipat) long *base; int size; unsigned long ipat; /* initial pattern, to be modified */{ int nwords; func_name = "fill"; TRACE_IN nwords = size / sizeof(long); while (nwords--) { /* This is ambiguous C code and fail vmem in 5.0DR * *base++ = ipat | (unsigned long)base; */ *base = ipat | (unsigned long)base ; base++ ; } TRACE_OUT}/* * check() * * reads from memory starting at base. The expected pattern is * ipat 'or'ed with the virtual address of each location. ipat * is just the current pass count logically shifted left to the * highest byte. Long words are read. * If an error occurs during comparison, then we record the * address of the initial error and continue to compare until * a successful comparison is found, at which time we stop * reading unless the run_on_error flag is set. If it's not * set, then we continue to check and fill in the verr[] array * upon finding compare errors. Each noncontiguous error is * stored in an element of the verr[] array. * The number of contiguous errors are recorded and also * the observed patterns of the 1st 30 errors are recorded if * there are more than 30 errors. * When we read, we want to read the data from memory only once * and store the data in local memory (preferably a register). This * is because in systems with cache, sometimes when there's a timing * problem in the cache, the first time we read the data it may be * incorrect, but the second time we read it, the data would be correct. * * return value: 0 if no error found. * number_of _errors if found some errors. */check(base, size, ipat, vindex) register long *base; int size; unsigned long ipat; int vindex; /* index into verr[] array */{ register unsigned long obs_pat = 0; /* pattern read from memory */ int nwords; /* size (in words) to check */ int errflag = 0, errs = 0, pagesize = 0; func_name = "check"; TRACE_IN pagesize = getpagesize() / sizeof (long); nwords = size /sizeof(long); while (nwords--) { if ((numerrs+errs) >= MAXERRS) break; /* stop test if found 10 noncontiguous errors */#ifdef sun386 obs_pat = (*base)-4; /* read from memory and store in local variable */#else sun386 obs_pat = *base; /* read from memory and store in local variable */#endif sun386 if (obs_pat != (ipat | (unsigned long)base)) { if (!errflag) { /* record initial err addr */ verr[vindex].base = (unsigned long *)base; verr[vindex].conterrs = 0; /* reset contigous error counter */ } errflag = 1; /* indicate an error occured */ if (verr[vindex].conterrs <= SHOW_ERRS) /* record up to 30 errs */ verr[vindex].observe[verr[vindex].conterrs] = obs_pat; verr[vindex].conterrs++;#ifndef NEW /* pre- 4.1 only hack -JCH- 4/3/90 */ /* ALERT!!! This hack is used to cover up a kernel bug. This * code should be removed as soon as the kernel is fixed. */ if (verr[vindex].conterrs == pagesize) errflag = 0; /* */#endif } else if (errflag) { /* comes here on 1st correct compare after a contigous number of * incorect compares. */ errs++; vindex++; errflag = 0; /* reset to indicate end of contiguous errors */ if (!run_on_error) break; } base++; /* next word */ } /* if we have only 1 set of contiguous errors and then correct * compares, then errflag==0 and errs==1; if have 1 large * set of contiguous errors to the end of the range we're testing, * then errflag==1 and errs==0 */ if (errflag) errs++; TRACE_OUT return(errs);}/* * printerrs() * * This routine accepts a pointer to the error information structure filled * in during the comparison phase of test (check()). The structure contains * the address of the initial error, the number of contiguous errors starting * at that address, and up to 30 observed patterns. We display the * virtual address, observed pattern, and expected pattern. The expected * pattern is calculated: ipat 'or'ed with the virtual address of each * location. ipat is just the current pass count logically shifted left * to the highest byte (<< 24). * * no return value. */printerrs(ipat, vindex, page, recompare) unsigned long ipat; /* the initial pattern used */ int vindex; /* index into verr[] that we're to print */ int page; /* which page did the error occur at */ int recompare; /* flag for displaying recompare header */{ unsigned long i; func_name = "printerrs"; TRACE_IN errheader(page, vindex, recompare); /* print header */ for (i = 0; i < SHOW_ERRS; i++) { /* display up to 30 data errors */ send_message(0, LOGFILE, show_err_msg, verr[vindex].base, verr[vindex].observe[i], ipat | (u_long)verr[vindex].base); verr[vindex].base++; /* next address */ if (i == (verr[vindex].conterrs - 1)) break; /* stop printing if less than 30 errors */ } if (verr[vindex].conterrs > SHOW_ERRS) send_message(0, LOGFILE, contig_err_msg, SHOW_ERRS); TRACE_OUT}/* * errheader() prints a header saying that miscompare errors have * been found. errheader() should be called prior to printing * each element of the verr[] array. */errheader(page, vindex, recompare) int page; /* which page did the error occur at */ int vindex; /* index into the verr[] array */ int recompare; /* flag for displaying recompare header */{ char pagestr[20]; func_name = "errheader"; TRACE_IN if (pagemode) sprintf(pagestr, "page %d", page); else strcpy(pagestr, "memory"); if (recompare) send_message(0, LOGFILE, re_mis_msg, pagestr, 4*verr[vindex].conterrs); else send_message(0, LOGFILE, miscompare_msg, vindex+1, pagestr, 4*verr[vindex].conterrs); send_message(0, LOGFILE, errheader_msg); TRACE_OUT}/* * size = get_vmem_size(); * * int size: size of available virtual memory in bytes. * * get_vmem_size() reads the kernel to find the amount of virtual memory * available. * */get_vmem_size(){ kvm_t *mem; struct anoninfo ai; int pageshift = 0; char *vmunix, *getenv(); func_name = "get_vmem_size"; TRACE_IN check_superuser(); vmunix = getenv("KERNELNAME"); if ((mem = kvm_open(vmunix, NULL, NULL, O_RDONLY, NULL)) == NULL) send_message(1, CONSOLE, kvm_err_msg, "open"); if (kvm_nlist(mem, nl) == -1) send_message(1, CONSOLE, kvm_err_msg, "nlist"); kvm_read(mem, nl[NL_SANON].n_value, (char *)&ai, sizeof(struct anoninfo)); for (pageshift = 1; pageshift < 32; pageshift++) if ((getpagesize() >> pageshift) == 1) break; kvm_close(mem); TRACE_OUT return((ai.ani_max - ai.ani_resv) << pageshift); /* virtural memory size */}/* * clean_up() is needed to satisfy libtest.a. */clean_up(){ unlink(PAGEFILE); /* remove temp file used for paging memory */ if (numerrs) /* in case being killed during "run_on_error"(bug 1027673) */ send_message(1, ERROR, test_fail_msg, numerrs);}process_vmem_args(argv, arrcount) char *argv[]; int arrcount;{ if (strncmp(argv[arrcount], "cg2", 3) == 0) { cg2 = TRUE; } else if (strncmp(argv[arrcount], "cg4", 3) == 0) { cg4 = TRUE; } else if (strncmp(argv[arrcount], "cg5", 3) == 0) { cg5 = TRUE; } else if (strncmp(argv[arrcount], "cg12", 4) == 0) { cg12 = TRUE; } else if (strncmp(argv[arrcount], "gt", 2) == 0) { gttest = TRUE; } else if (strncmp(argv[arrcount], "gp2", 3) == 0) { gp2 = TRUE; } else if (strncmp(argv[arrcount], "ibis", 4) == 0) { ibis = TRUE; } else if (strncmp(argv[arrcount], "taac", 4) == 0) { taac = TRUE; } else if (strncmp(argv[arrcount], "zebra=", 6) == 0) { zebra = atoi(&argv[arrcount][6]); } else if (strncmp(argv[arrcount], "ipcs=", 5) == 0) { ipcs = atoi(&argv[arrcount][5]); } else if (strncmp(argv[arrcount], "U", 1) == 0) { test_description(); exit(0); } else if (strncmp(argv[arrcount], "M=", 2) == 0) { pattern = atoi(&argv[arrcount][2]) << PAT_SHIFT; } else if (strncmp(argv[arrcount], "m=", 2) == 0) { margin = atoi(&argv[arrcount][2]) * 0x100000; } else if (strncmp(argv[arrcount], "R=", 2) == 0) { reserve = atoi(&argv[arrcount][2]) * 0x100000; } else if (strncmp(argv[arrcount], "page", 4) == 0) { pagemode = TRUE; } else if (strncmp(argv[arrcount], "cerrs=", 6) == 0) { sim_cerrs = atoi(&argv[arrcount][6]); } else if (strncmp(argv[arrcount], "nerrs=", 6) == 0) { sim_nerrs = atoi(&argv[arrcount][6]); } else { return(FALSE); } return(TRUE);}select_margin(){ func_name = "select_margin"; TRACE_IN if (!margin) { /* Margin of memory to save for OS if user didn't select */ if (gp2) margin += GP2_MARGIN; else if (cg5) margin += CG5_MARGIN; else if (cg2) margin += COLOR_MARGIN; else if (cg12) margin += CG12_MARGIN; if (ibis) margin += IBIS_MARGIN; else if (cg4) margin += COLOR_MARGIN; if (ipcs) margin += IPC_MARGIN * ipcs; if (taac) margin += TAAC_MARGIN; if (zebra) margin += ZEBRA_MARGIN * zebra; if (gttest) margin += COLOR_MARGIN; /* gttest use 2M bytes, same as COLOR */ margin += FIXED_MARGIN; } TRACE_OUT}routine_usage(){ send_message (0, CONSOLE, routine1_msg, test_name); send_message (0, CONSOLE, routine2_msg); send_message (0, CONSOLE, routine3_msg);}test_description(){ send_message (0, CONSOLE, describe1_msg); send_message (0, CONSOLE, describe2_msg); send_message (0, CONSOLE, describe3_msg); send_message (0, CONSOLE, describe4_msg); send_message (0, CONSOLE, describe5_msg); send_message (0, CONSOLE, describe6_msg); send_message (0, CONSOLE, describe7_msg);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -