int main(){ int c,car; float sistema[100][100]; int seleccion = 0; float **r_matriz = NULL; do{ printf("Operaciones y metodos de resolucion de matrices\n\t1. Operaciones con matrices\n\t2. Metodos de resolucion de matrices\n\t3. Salir\n"); scanf("%d", &seleccion); system("cls"); switch(seleccion){ case 1: puts("Operaciones de resolucion de matrices\n\t1. Multiplicacion\n\t2. Suma\n\t3. Resta"); scanf("%d", &seleccion); r_matriz = Operacion_de_matriz(r_matriz, seleccion); extern int dim_mat3[]; puts("\tMatriz Resultante:"); printp(r_matriz, dim_mat3); liberacion(dim_mat3, r_matriz); break; case 2: puts("Metodos de resolucion de matrices\n\t1.Gauss Jordan\n\t2. Gauss\n\t3. Matriz inversa\n"); scanf("%d", &seleccion); switch(seleccion){ case 1: // gauss_jordan(); case 2: ing_igc(&car,sistema); printf("\n\n\nSistema introducido: \n\n"); imp_sis(car,sistema); operador_metodo_gauss(car,sistema); printf("\n\n\nLas solucion es:\n"); for(c=1;c<=car;c++){ printf("\n X%d=%f\n",c,sistema[c][car+1]); } case 3: default: break; } case 3: seleccion = 0; break; default: puts("No le he comprendido, acaso:"); break; } if(seleccion != 0){ printf("Desea realizar alguna otra operacion?[1/0]\t"); scanf("%d", &seleccion); system("cls"); } }while(seleccion != 0); //mi parte scanf(""); return 0; }
void Trees::printp(Node* ptr) { //Check to see if empty if(root != NULL) { //Possible to move to the left side of the tree if(ptr->left != NULL) { printp(ptr->left); } cout << ptr->data << " "; //Possibe to move to the right side of the tree if(ptr->right != NULL) { printp(ptr->right); } } else { cout << "The Tree is empty" << endl; } }
/** * test_alloc_help - Print help message to proc buffer * @procentry: Which proc buffer to write to */ void test_alloc_help(int procentry) { vmrproc_openbuffer(&testinfo[procentry]); printp("%s%s\n\n", MODULENAME, testinfo[procentry].name); printp("To run test, run \n"); printp("echo order number > /proc/vmregress/%s\n\n", MODULENAME); printp("gfp_highuser = %d\n", gfp_highuser); printp("ms_delay = %d\n", ms_delay); printp("expected_count = %d\n", expected_count); printp("procbuf starting pages = %lu\n", PROCBUF_INIT_PAGES); vmrproc_closebuffer(&testinfo[procentry]); }
int main() { int cost[2][STEP] = { /* cost of each step */ {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {5, 5, 5, 5, 5, 5, 5, 5, 5, 5}}; double pheromone[2][STEP] = {0}; int mstep [NOA][STEP]; srand (SEED); int i; /* initialize */ for (i = 0; i < ILIMIT; i++) { printf ("%d:\n", i); printp (pheromone); walk (cost, pheromone, mstep); update (cost, pheromone, mstep); } printf ("%d:\n", i); printp (pheromone); return 0; }
/** * test_fault_help - Print help message to proc buffer * @procentry: Which proc buffer to write to */ void test_fault_help(int procentry) { /* Efficively clear the proc buffer */ vmrproc_openbuffer(&testinfo[procentry]); printp("%s%s\n\n", MODULENAME, testinfo[procentry].name); printp("To run test, run \n"); printp("echo numpasses [numpages] > /proc/vmregress/%s%s\n\n", MODULENAME, testinfo[procentry].name); printp("Where numpasses is how many times to reference all the pages within\n"); printp("a mapped area in memory numpages is an optional parameter of how many\n"); printp("pages to allocate. When the test completes, cat this proc entry again\n"); printp("to see the results.\n"); printp("For more information, read the comment at the top of src/test/fault.c\n\n"); vmrproc_closebuffer(&testinfo[procentry]); /* Set flags */ testinfo[procentry].flags |= VMR_PRINTMAP; }
void Trees::print() { printp(root); cout << endl; }
static void state_smart(unsigned n, tommy_list* low) { tommy_node* i; unsigned j; size_t device_pad; size_t serial_pad; int have_parent; double array_failure_rate; double p_at_least_one_failure; int make_it_fail = 0; uint64_t mask32 = 0xffffffffU; uint64_t mask16 = 0xffffU; char esc_buffer[ESC_MAX]; /* compute lengths for padding */ device_pad = 0; serial_pad = 0; have_parent = 0; for (i = tommy_list_head(low); i != 0; i = i->next) { size_t len; devinfo_t* devinfo = i->data; len = strlen(devinfo->file); if (len > device_pad) device_pad = len; len = strlen(devinfo->smart_serial); if (len > serial_pad) serial_pad = len; if (devinfo->parent != 0) have_parent = 1; } printf("SnapRAID SMART report:\n"); printf("\n"); printf(" Temp"); printf(" Power"); printf(" Error"); printf(" FP"); printf(" Size"); printf("\n"); printf(" C"); printf(" OnDays"); printf(" Count"); printf(" "); printf(" TB"); printf(" "); printl("Serial", serial_pad); printf(" "); printl("Device", device_pad); printf(" Disk"); printf("\n"); /* |<##################################################################72>|####80>| */ printf(" -----------------------------------------------------------------------\n"); array_failure_rate = 0; for (i = tommy_list_head(low); i != 0; i = i->next) { devinfo_t* devinfo = i->data; double afr; uint64_t flag; if (devinfo->smart[194] != SMART_UNASSIGNED) printf("%7" PRIu64, devinfo->smart[194] & mask16); else if (devinfo->smart[190] != SMART_UNASSIGNED) printf("%7" PRIu64, devinfo->smart[190] & mask16); else printf(" -"); if (devinfo->smart[9] != SMART_UNASSIGNED) printf("%7" PRIu64, (devinfo->smart[9] & mask32) / 24); else printf(" -"); if (devinfo->smart[SMART_FLAGS] != SMART_UNASSIGNED) flag = devinfo->smart[SMART_FLAGS]; else flag = 0; if (flag & SMARTCTL_FLAG_FAIL) printf(" FAIL"); else if (flag & SMARTCTL_FLAG_PREFAIL) printf(" PREFAIL"); else if (flag & SMARTCTL_FLAG_PREFAIL_LOGGED) printf(" logfail"); else if (devinfo->smart[SMART_ERROR] != SMART_UNASSIGNED && devinfo->smart[SMART_ERROR] != 0) printf("%8" PRIu64, devinfo->smart[SMART_ERROR]); else if (flag & SMARTCTL_FLAG_ERROR) printf(" logerr"); else if (flag & SMARTCTL_FLAG_ERROR_LOGGED) printf(" selferr"); else if (devinfo->smart[SMART_ERROR] == 0) printf(" 0"); else printf(" -"); /* if some fail/prefail attribute, make the command to fail */ if (flag & (SMARTCTL_FLAG_FAIL | SMARTCTL_FLAG_PREFAIL)) make_it_fail = 1; /* note that in older smartmontools, like 5.x, rotation rate is not present */ /* and then it could remain unassigned */ if (flag & (SMARTCTL_FLAG_UNSUPPORTED | SMARTCTL_FLAG_OPEN)) { /* if error running smartctl, skip AFR estimation */ afr = 0; printf(" n/a"); } else if (devinfo->smart[SMART_ROTATION_RATE] == 0) { /* if SSD, skip AFR estimation as data is from not SSD disks */ afr = 0; printf(" SSD"); } else { afr = smart_afr(devinfo->smart); if (afr == 0) { /* this happens only if no data */ printf(" -"); } else { /* use only the disks in the array */ if (devinfo->parent != 0 || !have_parent) array_failure_rate += afr; printf("%4.0f%%", poisson_prob_n_or_more_failures(afr, 1) * 100); } } if (devinfo->smart[SMART_SIZE] != SMART_UNASSIGNED) printf(" %4.1f", devinfo->smart[SMART_SIZE] / 1E12); else printf(" -"); printf(" "); if (*devinfo->smart_serial) printl(devinfo->smart_serial, serial_pad); else printl("-", serial_pad); printf(" "); if (*devinfo->file) printl(devinfo->file, device_pad); else printl("-", device_pad); printf(" "); if (*devinfo->name) printf("%s", devinfo->name); else printf("-"); printf("\n"); log_tag("smart:%s:%s\n", devinfo->file, devinfo->name); if (devinfo->smart_serial[0]) log_tag("attr:%s:%s:serial:%s\n", devinfo->file, devinfo->name, esc(devinfo->smart_serial, esc_buffer)); if (afr != 0) log_tag("attr:%s:%s:afr:%g\n", devinfo->file, devinfo->name, afr); if (devinfo->smart[SMART_SIZE] != SMART_UNASSIGNED) log_tag("attr:%s:%s:size:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_SIZE]); if (devinfo->smart[SMART_ERROR] != SMART_UNASSIGNED) log_tag("attr:%s:%s:error:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_ERROR]); if (devinfo->smart[SMART_ROTATION_RATE] != SMART_UNASSIGNED) log_tag("attr:%s:%s:rotationrate:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_ROTATION_RATE]); if (devinfo->smart[SMART_FLAGS] != SMART_UNASSIGNED) log_tag("attr:%s:%s:flags:%" PRIu64 ":%" PRIx64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_FLAGS], devinfo->smart[SMART_FLAGS]); for (j = 0; j < 256; ++j) if (devinfo->smart[j] != SMART_UNASSIGNED) log_tag("attr:%s:%s:%u:%" PRIu64 ":%" PRIx64 "\n", devinfo->file, devinfo->name, j, devinfo->smart[j], devinfo->smart[j]); } printf("\n"); /* |<##################################################################72>|####80>| */ printf("The FP column is the estimated probability (in percentage) that the disk\n"); printf("is going to fail in the next year.\n"); printf("\n"); /* * The probability of one and of at least one failure is computed assuming * a Poisson distribution with the estimated array failure rate. */ p_at_least_one_failure = poisson_prob_n_or_more_failures(array_failure_rate, 1); printf("Probability that at least one disk is going to fail in the next year is %.0f%%.\n", p_at_least_one_failure * 100); log_tag("summary:array_failure:%g:%g\n", array_failure_rate, p_at_least_one_failure); /* print extra stats only in verbose mode */ if (msg_level < MSG_VERBOSE) goto bail; /* |<##################################################################72>|####80>| */ printf("\n"); printf("Probability of data loss in the next year for different parity and\n"); printf("combined scrub and repair time:\n"); printf("\n"); printf(" Parity 1 Week 1 Month 3 Months\n"); printf(" -----------------------------------------------------------------------\n"); for (j = 0; j < RAID_PARITY_MAX; ++j) { printf("%6u", j + 1); printf(" "); printp(raid_prob_of_one_or_more_failures(array_failure_rate, 365.0 / 7, n, j + 1) * 100, 19); printf(" "); printp(raid_prob_of_one_or_more_failures(array_failure_rate, 365.0 / 30, n, j + 1) * 100, 17); printf(" "); printp(raid_prob_of_one_or_more_failures(array_failure_rate, 365.0 / 90, n, j + 1) * 100, 13); printf("\n"); } printf("\n"); /* |<##################################################################72>|####80>| */ printf("These values are the probabilities that in the next year you'll have a\n"); printf("sequence of failures that the parity WONT be able to recover, assuming\n"); printf("that you regularly scrub, and in case repair, the array in the specified\n"); printf("time.\n"); bail: if (make_it_fail) { printf("\n"); printf("DANGER! SMART is reporting that one or more disks are FAILING!\n"); printf("Please take immediate action!\n"); exit(EXIT_FAILURE); } }
/** * * test_alloc_runtest - Allocate and free a number of pages from a ZONE_NORMAL * @params: Parameters read from the proc entry * @argc: Number of parameters actually entered * @procentry: Proc buffer to write to * * If pages is set to 0, pages will be allocated until the pages_high watermark * is hit * Returns * 0 on success * -1 on failure * */ int test_alloc_runtest(int *params, int argc, int procentry) { unsigned long order; /* Order of pages */ unsigned long numpages; /* Number of pages to allocate */ struct page **pages; /* Pages that were allocated */ unsigned long attempts=0; unsigned long alloced=0; unsigned long nextjiffies = jiffies; unsigned long lastjiffies = jiffies; unsigned long success=0; unsigned long fail=0; unsigned long resched_count=0; unsigned long aborted=0; unsigned long long start_cycles, cycles; unsigned long page_dma=0, page_dma32=0, page_normal=0, page_highmem=0, page_easyrclm=0; struct zone *zone; char finishString[60]; int timing_pages, pages_required; /* Set gfp_flags based on the module parameter */ if (gfp_highuser) { #ifdef GFP_RCLMUSER vmr_printk("Using highmem with GFP_RCLMUSER\n"); gfp_flags = GFP_RCLMUSER; #elif defined(GFP_HIGH_MOVABLE) vmr_printk("Using highmem with GFP_HIGH_MOVABLE\n"); gfp_flags = GFP_HIGH_MOVABLE; #elif defined(GFP_HIGHUSER_MOVABLE) vmr_printk("Using highmem with GFP_HIGHUSER_MOVABLE\n"); gfp_flags = GFP_HIGHUSER_MOVABLE; #else vmr_printk("Using highmem with GFP_HIGHUSER | __GFP_EASYRCLM\n"); gfp_flags = GFP_HIGHUSER | __GFP_EASYRCLM; #endif } else { vmr_printk("Using lowmem\n"); gfp_flags |= __GFP_EASYRCLM|__GFP_MOVABLE; } vmr_printk("__GFP_EASYRCLM is 0x%8X\n", __GFP_EASYRCLM); vmr_printk("__GFP_MOVABLE is 0x%8X\n", __GFP_MOVABLE); vmr_printk("gfp_flags = 0x%8X\n", gfp_flags); /* Get the parameters */ order = params[0]; numpages = params[1]; /* Make sure a buffer is available */ if (vmrproc_checkbuffer(testinfo[HIGHALLOC_REPORT])) BUG(); if (vmrproc_checkbuffer(testinfo[HIGHALLOC_TIMING])) BUG(); if (vmrproc_checkbuffer(testinfo[HIGHALLOC_BUDDYINFO])) BUG(); vmrproc_openbuffer(&testinfo[HIGHALLOC_REPORT]); vmrproc_openbuffer(&testinfo[HIGHALLOC_TIMING]); vmrproc_openbuffer(&testinfo[HIGHALLOC_BUDDYINFO]); /* Check parameters */ if (order < 0 || order >= MAX_ORDER) { vmr_printk("Order request of %lu makes no sense\n", order); return -1; } if (numpages < 0) { vmr_printk("Number of pages %lu makes no sense\n", numpages); return -1; } /* * Allocate memory to store pointers to pages. */ pages = __vmalloc((numpages+1) * sizeof(struct page **), GFP_KERNEL|__GFP_HIGHMEM|__GFP_KERNRCLM|__GFP_RECLAIMABLE, PAGE_KERNEL); if (pages == NULL) { printp("Failed to allocate space to store page pointers\n"); vmrproc_closebuffer(&testinfo[HIGHALLOC_REPORT]); vmrproc_closebuffer(&testinfo[HIGHALLOC_TIMING]); vmrproc_closebuffer(&testinfo[HIGHALLOC_BUDDYINFO]); return 0; } /* Setup proc buffer for timings */ timing_pages = testinfo[HIGHALLOC_TIMING].procbuf_size / PAGE_SIZE; pages_required = (numpages * 20) / PAGE_SIZE; if (pages_required > timing_pages) { vmrproc_growbuffer(pages_required - timing_pages, &testinfo[HIGHALLOC_TIMING]); } /* Setup proc buffer for highorder alloc */ timing_pages = testinfo[HIGHALLOC_BUDDYINFO].procbuf_size / PAGE_SIZE; pages_required = (numpages * ((256 + 30 + 15 * MAX_ORDER) * num_online_nodes())) / PAGE_SIZE; if (pages_required > timing_pages) { vmrproc_growbuffer(pages_required - timing_pages, &testinfo[HIGHALLOC_BUDDYINFO]); } #if defined(OOM_DISABLE) && (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,19)) /* Disable OOM Killer */ vmr_printk("Disabling OOM killer for running process\n"); oomkilladj = current->oomkilladj; current->oomkilladj = OOM_DISABLE; #endif /* OOM_DISABLE */ /* * Attempt to allocate the requested number of pages */ while (attempts++ != numpages) { struct page *page; if (lastjiffies > jiffies) nextjiffies = jiffies; while (jiffies < nextjiffies) check_resched(resched_count); nextjiffies = jiffies + ( (HZ * ms_delay)/1000); /* Print message if this is taking a long time */ if (jiffies - lastjiffies > HZ) { printk("High order alloc test attempts: %lu (%lu)\n", attempts-1, alloced); } /* Print out a message every so often anyway */ if (attempts > 1 && (attempts-1) % 10 == 0) { printp_entry(HIGHALLOC_TIMING, "\n"); printk("High order alloc test attempts: %lu (%lu)\n", attempts-1, alloced); } lastjiffies = jiffies; start_cycles = read_clockcycles(); page = alloc_pages(gfp_flags | __GFP_NOWARN, order); cycles = read_clockcycles() - start_cycles; if (page) { printp_entry(HIGHALLOC_TIMING, "%-11llu ", cycles); printp_buddyinfo(testinfo, HIGHALLOC_BUDDYINFO, attempts, 1); success++; pages[alloced++] = page; /* Count what zone this is */ zone = page_zone(page); if (zone->name != NULL && !strcmp(zone->name, "EasyRclm")) page_easyrclm++; if (zone->name != NULL && !strcmp(zone->name, "Movable")) page_easyrclm++; if (zone->name != NULL && !strcmp(zone->name, "HighMem")) page_highmem++; if (zone->name != NULL && !strcmp(zone->name, "Normal")) page_normal++; if (zone->name != NULL && !strcmp(zone->name, "DMA32")) page_dma32++; if (zone->name != NULL && !strcmp(zone->name, "DMA")) page_dma++; /* Give up if it takes more than 60 seconds to allocate */ if (jiffies - lastjiffies > HZ * 600) { printk("Took more than 600 seconds to allocate a block, giving up"); aborted = attempts; attempts = numpages; break; } } else { printp_entry(HIGHALLOC_TIMING, "-%-10llu ", cycles); printp_buddyinfo(testinfo, HIGHALLOC_BUDDYINFO, attempts, 0); fail++; /* Give up if it takes more than 30 seconds to fail */ if (jiffies - lastjiffies > HZ * 1200) { printk("Took more than 1200 seconds and still failed to allocate, giving up"); aborted = attempts; attempts = numpages; break; } } } /* Re-enable OOM Killer state */ #ifdef OOM_DISABLED vmr_printk("Re-enabling OOM Killer status\n"); current->oomkilladj = oomkilladj; #endif vmr_printk("Test completed with %lu allocs, printing results\n", alloced); /* Print header */ printp("Order: %lu\n", order); printp("Allocation type: %s\n", gfp_highuser ? "HighMem" : "Normal"); printp("Attempted allocations: %lu\n", numpages); printp("Success allocs: %lu\n", success); printp("Failed allocs: %lu\n", fail); printp("DMA32 zone allocs: %lu\n", page_dma32); printp("DMA zone allocs: %lu\n", page_dma); printp("Normal zone allocs: %lu\n", page_normal); printp("HighMem zone allocs: %lu\n", page_highmem); printp("EasyRclm zone allocs: %lu\n", page_easyrclm); printp("%% Success: %lu\n", (success * 100) / (unsigned long)numpages); /* * Free up the pages */ vmr_printk("Test complete, freeing %lu pages\n", alloced); if (alloced > 0) { do { alloced--; if (pages[alloced] != NULL) __free_pages(pages[alloced], order); } while (alloced != 0); vfree(pages); } if (aborted == 0) strcpy(finishString, "Test completed successfully\n"); else sprintf(finishString, "Test aborted after %lu allocations due to delays\n", aborted); printp(finishString); vmr_printk("Test completed, closing buffer\n"); vmrproc_closebuffer(&testinfo[HIGHALLOC_REPORT]); vmrproc_closebuffer(&testinfo[HIGHALLOC_TIMING]); vmrproc_closebuffer(&testinfo[HIGHALLOC_BUDDYINFO]); vmr_printk("%s", finishString); return 0; }
/** * * test_fault_runtest - Allocate and free a number of pages from a zone * @params: Parameters read from the proc entry * @argc: Number of parameters actually entered * @procentry: Proc buffer to write to * * If pages is set to 0, pages will be allocated until the pages_high watermark * is hit * Returns * 0 on success * -1 on failure * */ int test_fault_runtest(int *params, int argc, int procentry) { unsigned long nopages; /* Number of pages to allocate */ int nopasses; /* Number of times to run test */ C_ZONE *zone; /* Zone been tested on */ unsigned long freelimit; /* The min no. free pages in zone */ unsigned long alloccount; /* Number of pages alloced */ unsigned long present; /* Number of pages present */ unsigned long addr=0; /* Address mapped area starts */ unsigned long len; /* Length of mapped area */ unsigned long sched_count; /* How many times schedule is called */ unsigned long start; /* Start of a test in jiffies */ int totalpasses; /* Total number of passes */ int failed=0; /* Failed mappings */ /* Get the parameters */ nopasses = params[0]; nopages = params[1]; /* Make sure a buffer is available */ if (vmrproc_checkbuffer(testinfo[procentry])) BUG(); vmrproc_openbuffer(&testinfo[procentry]); /* Make sure passes is valid */ if (nopasses <= 0) { vmr_printk("Cannot make 0 or negative number of passes\n"); return -1; } /* Print header */ printp("%s Test Results (" UTS_RELEASE ").\n\n", testinfo[procentry].name); /* Get the parameters for the test */ if (test_fault_calculate_parameters(procentry, &zone, &nopages, &freelimit) == -1) { printp("Test failed\n"); return -1; } len = nopages * PAGE_SIZE; /* * map a region of memory where our pages are going to be stored * This is the same as the system call to mmap * */ addr = do_mmap(NULL, /* No struct file */ 0, /* No starting address */ len, /* Length of address space */ PROT_WRITE | PROT_READ, /* Protection */ MAP_PRIVATE | MAP_ANONYMOUS, /* Private mapping */ 0); /* get_unmapped area has a horrible way of returning errors */ if (addr == -1) { printp("Failed to mmap"); return -1; } /* Print area information */ printp("Mapped Area Information\n"); printp("o address: 0x%lX\n", addr); printp("o length: %lu (%lu pages)\n", len, nopages); printp("\n"); /* Begin test */ printp("Test Parameters\n"); printp("o Passes: %d\n", nopasses); printp("o Starting Free pages: %lu\n", zone->free_pages); printp("o Free page limit: %lu\n", freelimit); printp("o References: %lu\n", nopages); printp("\n"); printp("Test Results\n"); printp("Pass Refd Present Time\n"); totalpasses = nopasses; /* Copy the string into every page once to alloc all ptes */ alloccount=0; start = jiffies; while (nopages-- > 0) { check_resched(sched_count); copy_to_user((unsigned long *)(addr + (nopages * PAGE_SIZE)), test_string, strlen(test_string)); alloccount++; } /* * Step through the page tables pass number of times swapping in * pages as necessary */ for (;;) { /* Count the number of pages present */ present = countpages_mm(current->mm, addr, len, &sched_count); /* Print test info */ printp("%-8d %8lu %8lu %8lums\n", totalpasses-nopasses, alloccount, present, jiffies_to_ms(start)); if (nopasses-- == 0) break; /* Touch all the pages in the mapped area */ start = jiffies; alloccount = forall_pte_mm(current->mm, addr, len, &sched_count, NULL, touch_pte); } printp("\nPost Test Information\n"); printp("o Finishing Free pages: %lu\n", zone->free_pages); printp("o Schedule() calls: %lu\n", sched_count); printp("o Failed mappings: %u\n", failed); printp("\n"); printp("Test completed successfully\n"); /* Print out a process map */ vmr_printmap(current->mm, addr, len, &sched_count, &testinfo[procentry]); /* Unmap the area */ if (do_munmap(current->mm, addr, len) == -1) { printp("WARNING: Failed to unmap memory area"); } vmrproc_closebuffer(&testinfo[procentry]); return 0; }
/** * test_fault_calculate_parameters - Calculate the parameters of the test * @procentry: Indicates which test is been run * @rzone: Return the zone been tested on * @rnopages: Return the number of pages to allocate * @rfreelimit: The number of pages that must be free for the test to continue * * nopages is the number of pages that should be allocated and * freed for the test. If passed in as 0, it will be the maximum * number of pages to allocate. If a value is provided, that * number of pages will be used if possible * * The freelimit is a number of pages that must be free for the * test to continue running. It is defined as to be pages_high * plus 5% of the total number of pages that can be allocated * at the beginning of the test. This is to give a safe margin * * Return value * 0 on success * -1 on failure */ int test_fault_calculate_parameters(int procentry, C_ZONE **rzone, unsigned long *rnopages, unsigned long *rfreelimit) { pg_data_t *pgdat; /* node to allocate from */ unsigned long flags; /* IRQ flags */ C_ZONE *zone=NULL; unsigned long nopages, freelimit; nopages = *rnopages; /* Get the zone we are to alloc from */ pgdat = get_pgdat_list(); if (pgdat) zone = &pgdat->node_zones[ZONE_TEST]; if (!zone) { printp("ERROR: Could not find zone\n"); goto failed; } /* Lock the zone so we are sure the zone won't change */ spin_lock_irqsave(&zone->lock, flags); /* Calculate watermark for test */ switch (procentry) { case TEST_FAST: /* * Watermark is pages_high so as to be sure kswapd is * not involved */ freelimit = zone->pages_high; break; case TEST_LOW: /* * Watermark is half way between low and min so that * kswapd will be woken up to do work */ freelimit = zone->pages_min + ( (zone->pages_low - zone->pages_min) / 2); break; case TEST_MIN: /* * Watermark is half way between 0 pages and pages_min * so that kswapd will have to work heavily */ freelimit = zone->pages_min / 2; break; case TEST_ZERO: freelimit = 0; break; default: printp("Test %d does not exist\n", procentry); spin_unlock_irqrestore(&zone->lock, flags); goto failed; break; } /* Check it is possible to even start the test */ if (zone->free_pages <= freelimit) { printp("ERROR: Only %lu pages free on zone with watermark of %lu\n", zone->free_pages, freelimit); spin_unlock_irqrestore(&zone->lock, flags); goto failed; } /* Calculate nopages */ if (nopages) { /* If a specfic page request was made, make sure it's ok */ if (procentry != TEST_ZERO && nopages > zone->free_pages - freelimit) { printp("Requested test of %lu pages where %lu is the limit\n", nopages, zone->free_pages - freelimit); spin_unlock_irqrestore(&zone->lock, flags); goto failed; } } else { nopages = zone->free_pages - freelimit; /* * TEST_ZERO is a special case for nopages because we are trying * to alloc all pages in the zone so the number of pages to * allocate is half way between zone->free_pages and the total * size of the zone. This will place the zone under extreme * pressure */ if (procentry == TEST_ZERO) nopages = zone->free_pages + ( (vmr_zone_size(zone) - zone->free_pages) / 2); } /* * Because we are deliberatly allocating memory that will * not be freed in the normal way, we block all signals * to reduce the chance we are killed */ sigfillset(¤t->blocked); /* Unlock zone */ spin_unlock_irqrestore(&zone->lock, flags); *rzone = zone; *rnopages = nopages; *rfreelimit = freelimit; return 0; failed: return -1; }