static ssize_t memory_probe_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { u64 phys_addr; int nid; int i, ret; unsigned long pages_per_block = PAGES_PER_SECTION * sections_per_block; phys_addr = simple_strtoull(buf, NULL, 0); if (phys_addr & ((pages_per_block << PAGE_SHIFT) - 1)) return -EINVAL; for (i = 0; i < sections_per_block; i++) { nid = memory_add_physaddr_to_nid(phys_addr); ret = add_memory(nid, phys_addr, PAGES_PER_SECTION << PAGE_SHIFT); if (ret) goto out; phys_addr += MIN_MEMORY_BLOCK_SIZE; } ret = count; out: return ret; }
static ssize_t memory_probe_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { u64 phys_addr; int nid, ret; unsigned long pages_per_block = PAGES_PER_SECTION * sections_per_block; ret = kstrtoull(buf, 0, &phys_addr); if (ret) return ret; if (phys_addr & ((pages_per_block << PAGE_SHIFT) - 1)) return -EINVAL; nid = memory_add_physaddr_to_nid(phys_addr); ret = add_memory(nid, phys_addr, MIN_MEMORY_BLOCK_SIZE * sections_per_block); if (ret) goto out; ret = count; out: return ret; }
static int acpi_memory_enable_device(struct acpi_memory_device *mem_device) { int result; ACPI_FUNCTION_TRACE("acpi_memory_enable_device"); /* Get the range from the _CRS */ result = acpi_memory_get_device_resources(mem_device); if (result) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "\nget_device_resources failed\n")); mem_device->state = MEMORY_INVALID_STATE; return result; } /* * Tell the VM there is more memory here... * Note: Assume that this function returns zero on success */ result = add_memory(mem_device->start_addr, (mem_device->end_addr - mem_device->start_addr) + 1, mem_device->read_write_attribute); if (result) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "\nadd_memory failed\n")); mem_device->state = MEMORY_INVALID_STATE; return result; } return result; }
void Calculator::calculate() { double operand2 = m_stk.pop().toDouble(); QString strOperation = m_stk.pop(); double operand1 = m_stk.pop().toDouble(); double Result_d = 0; if (strOperation == "+") { Result_d = operand1+operand2; } if (strOperation == "-") { Result_d = operand1-operand2; } if (strOperation == "/") { Result_d = operand1 / operand2; } if (strOperation == "*") { Result_d = operand1 * operand2; } if (strOperation == "Pow") { Result_d=qPow(operand1,operand2); } if (strOperation == "M-") { subs_memory(operand1); } if (strOperation == "M+") { add_memory(operand1); } if (strOperation == "MS") { reset_memory(); } if (strOperation == "Sqrt") { Result_d=qSqrt(operand1); } if (strOperation == "ln") { Result_d=qLn(operand1); } if (strOperation == "MR") { Result_d=get_memory(); } if (strOperation == "abs") { Result_d=qAbs(operand1); } m_plcd->display(Result_d ); }
static void expand (struct mempool *pool) { size_t size; char *mem; size = pool->chunk_size; GET_MEMORY (mem, size); if (!mem) { size = UNW_ALIGN(pool->obj_size, pg_size); GET_MEMORY (mem, size); if (!mem) { /* last chance: try to allocate one object from the SOS memory */ size = pool->obj_size; mem = sos_alloc (size); } } add_memory (pool, mem, size, pool->obj_size); }
static int dlpar_add_lmb_memory(struct of_drconf_cell *lmb) { struct memory_block *mem_block; unsigned long block_sz; int nid, rc; block_sz = memory_block_size_bytes(); /* Find the node id for this address */ nid = memory_add_physaddr_to_nid(lmb->base_addr); /* Add the memory */ rc = add_memory(nid, lmb->base_addr, block_sz); if (rc) return rc; /* Register this block of memory */ rc = memblock_add(lmb->base_addr, block_sz); if (rc) { remove_memory(nid, lmb->base_addr, block_sz); return rc; } mem_block = lmb_to_memblock(lmb); if (!mem_block) { remove_memory(nid, lmb->base_addr, block_sz); return -EINVAL; } rc = device_online(&mem_block->dev); put_device(&mem_block->dev); if (rc) { remove_memory(nid, lmb->base_addr, block_sz); return rc; } lmb->flags |= DRCONF_MEM_ASSIGNED; return 0; }
static int dlpar_add_lmb(struct of_drconf_cell *lmb) { unsigned long block_sz; int nid, rc; if (lmb->flags & DRCONF_MEM_ASSIGNED) return -EINVAL; rc = dlpar_add_device_tree_lmb(lmb); if (rc) { pr_err("Couldn't update device tree for drc index %x\n", lmb->drc_index); dlpar_release_drc(lmb->drc_index); return rc; } block_sz = memory_block_size_bytes(); /* Find the node id for this address */ nid = memory_add_physaddr_to_nid(lmb->base_addr); /* Add the memory */ rc = add_memory(nid, lmb->base_addr, block_sz); if (rc) { dlpar_remove_device_tree_lmb(lmb); return rc; } rc = dlpar_online_lmb(lmb); if (rc) { remove_memory(nid, lmb->base_addr, block_sz); dlpar_remove_device_tree_lmb(lmb); } else { lmb->flags |= DRCONF_MEM_ASSIGNED; } return rc; }
int run(void) { xmlDocPtr doc; xmlNodePtr node; int ct = STACKCT_OPT(OUTPUT); char **output = (char **) &STACKLST_OPT(OUTPUT); GString *log; int i; int color; int highest_color = STAT_GREEN; char buf[24]; extern int forever; uw_setproctitle("sleeping"); for (i=0; i < OPT_VALUE_INTERVAL; i++) { // wait some minutes sleep(1); if (!forever) { return(0); } } uw_setproctitle("getting system statistics"); get_stats(); doc = UpwatchXmlDoc("result", NULL); xmlSetDocCompressMode(doc, OPT_VALUE_COMPRESS); // do the sysstat node = (xmlNodePtr) newnode(doc, "sysstat"); add_loadavg(node); add_cpu(node); add_paging(node); add_blockio(node); add_swap(node); add_memory(node); add_systemp(node); add_sysstat_info(node); color = xmlGetPropInt(node, "color"); if (color > highest_color) highest_color = color; #if USE_XMBMON|| defined (__OpenBSD__) if (OPT_VALUE_HWSTATS ) { // do the hwstat get_hwstats(); node = (xmlNodePtr) newnode(doc, "hwstat"); add_hwstat(node); color = xmlGetPropInt(node, "color"); if (color > highest_color) highest_color = color; } #endif if (OPT_VALUE_LOCALCHECKS ) { // do the local checks color = do_local((xmlNodePtr) doc); if (color > highest_color) highest_color = color; } #if HAVE_LIBPCRE // do the errlog node = (xmlNodePtr) newnode(doc, "errlog"); log = check_logs(&color); if (color > highest_color) highest_color = color; sprintf(buf, "%u", color); xmlSetProp(node, "color", buf); if (log) { if (log->str && strlen(log->str) > 0) { xmlNewTextChild(node, NULL, "info", log->str); } g_string_free(log, TRUE); } #endif // do the diskfree uw_setproctitle("checking diskspace"); node = (xmlNodePtr) newnode(doc, "diskfree"); add_diskfree_info(node); color = xmlGetPropInt(node, "color"); if (color > highest_color) highest_color = color; if (HAVE_OPT(HPQUEUE) && (highest_color != prv_highest_color)) { // if status changed, it needs to be sent immediately. So drop into // the high priority queue. Else just drop in the normal queue where // uw_send in batched mode will pick it up later spool_result(OPT_ARG(SPOOLDIR), OPT_ARG(HPQUEUE), doc, NULL); } else { for (i=0; i < ct; i++) { spool_result(OPT_ARG(SPOOLDIR), output[i], doc, NULL); } } prv_highest_color = highest_color; // remember for next time xmlFreeDoc(doc); return 0; }
int main(int argc, char **argv) { char scratch[128]; hcall_fd = hcall_init(); int ret = parse_args(argc, argv); if (ret < 0) return ret; uval total = 0; ASSERT(num_ranges > 0, "No memory ranges specified\n"); ret = get_file("state", scratch, sizeof(scratch)); if (ret <= 0 || strncmp(scratch, "READY", ret) != 0) { bailout("Partition not ready\n"); } uval rmo_start = lranges[0].lr_base; uval rmo_size = lranges[0].lr_size; uval laddr = 0; uval img_base = 0; uval img_offset = 0; int count = 0; while (count < 255) { char image[256]; char image_laddr[256]; char data[64]; struct stat sbuf; uval base; snprintf(image, sizeof(image), HYPE_ROOT "/%s/image%02x", oh_pname, count); snprintf(image_laddr, sizeof(image_laddr), "image%02x_load", count); ++count; ret = stat(image, &sbuf); if (ret < 0) continue; ret = get_file(image_laddr, data, sizeof(data)); if (ret >= 0) { uval64 l = strtoull(data, NULL, 0); ASSERT(errno != ERANGE, "Corrupted data %s\n", image_laddr); laddr = l; } int size = laddr_load(image, rmo_start + laddr, &base); if (0 == img_base) { img_base = base; img_offset = laddr; } laddr = ALIGN_UP(laddr + size, PGSIZE); } char pinfo_buf[64]; uval64 pinfo; ret = get_file("pinfo", pinfo_buf, sizeof(pinfo_buf)); if (ret <= 0 || (pinfo = strtoull(pinfo_buf, NULL, 0)) <= 0) { pinfo = (uval64)-1; } uval lpid; hargs.opcode = H_CREATE_PARTITION; hargs.args[0] = rmo_start; hargs.args[1] = rmo_size; hargs.args[2] = pinfo; ret = hcall(&hargs); ASSERT(ret >= 0 && hargs.retval == 0, "hcall failure: %d " UVAL_CHOOSE("0x%x", "0x%lx") "\n", ret, hargs.retval); lpid = hargs.args[0]; set_file_printf("of_tree/ibm,partition-no", "0x%llx", lpid); set_file_printf("lpid", "0x%llx", lpid); set_file("state", "CREATED", -1); clean_vdevices(); of_add_memory(0, rmo_size); total += rmo_size; int i = 1; while (i < num_ranges) { uval64 base = lranges[i].lr_base; uval64 size = lranges[i].lr_size; add_memory(lpid, base, size); total += size; ++i; } #ifdef __PPC__ add_htab(lpid, total); #endif if (get_file_numeric("res_console_srv", &console_ua) < 0) { console_ua = 0; } else { vtys = 1; } uval64 vty0 = 0; if (vtys == 0 && console_ua == 0) { add_vty(0); } else { if (vtys > 0) { /* add vty and force it to be vty@0 */ vty0 = add_vterm(0, lpid); --vtys; } while (vtys > 0) { /* add vty and let it be the proper liobn */ add_vterm(-1, lpid); } } if (crq > 0) { ret = add_vdev(lpid, crq); if (ret == -1) { fprintf(stderr, "vdev failed : 0x%lx\n", crq); return 1; } } if (console_ua) { printf("Registering console vterm: " UVAL_CHOOSE("0x%lx","0x%llx")" -> 0x%lx:0x%llx\n", console_ua, lpid, vty0); hargs.opcode = H_REGISTER_VTERM; hargs.args[0] = console_ua; hargs.args[1] = lpid; hargs.args[2] = vty0; ret = hcall(&hargs); ASSERT(ret >= 0 && hargs.retval == 0, "hcall failure: %d " UVAL_CHOOSE("0x%x", "0x%lx") "\n", ret, hargs.retval); } add_llan(lpid); #ifdef __PPC__ load_of(lranges[0].lr_base, lranges[0].lr_size); #endif #ifdef __i386__ if (0 != img_base) { static struct partition_info part_info[2]; fill_pinfo(&part_info[1], lpid, rmo_size); if (inject_pinfo(part_info, sizeof(part_info), img_base, img_offset)) { add_cmdlineargs(img_base, 0x1000, /* offset in image for data */ lpid); } } #endif hargs.opcode = H_SET_SCHED_PARAMS; hargs.args[0] = lpid; hargs.args[1] = 0; hargs.args[2] = 1; hargs.args[3] = 0; ret = hcall(&hargs); ASSERT(ret >= 0 && hargs.retval == 0, "hcall failure: %d " UVAL_CHOOSE("0x%x", "0x%lx") "\n", ret, hargs.retval); hargs.opcode = H_START; hargs.args[0] = lpid; char buf[64]; ret = get_file("pc", buf, sizeof(buf)); if (ret >= 0) { buf[ret] = 0; hargs.args[1] = strtoull(buf, NULL, 0); } else { hargs.args[1] = 0; } int x = 2; while (x < 8) { int y = 0; snprintf(buf, sizeof(buf), "r%d", x); y = get_file(buf, buf, sizeof(buf)); if (y >= 0) { buf[y] = 0; hargs.args[x] = strtoull(buf, NULL, 0); } else { hargs.args[x] = 0; } ++x; } if (wait_for_key) { printf("waiting for keypress:"); (void)fgetc(stdin); } printf("Starting...\n"); hcall(&hargs); ASSERT(ret >= 0 && hargs.retval == 0, "hcall failure: %d " UVAL_CHOOSE("0x%x", "0x%lx") "\n", ret, hargs.retval); set_file("state", "RUNNING", -1); return 0; }