static int addc (int argc,char **argv, void *data) { Node *pos = (Node *) data; Node *tnode; if(argc==1){ cli_outfunf("usage: %s <entry> [new subentry]",argv[0]); return 0; } tnode = node_exact_match (argv[1], pos); if (!tnode) { cli_outfun ("specified parent not found"); return (int) pos; } if (node_right (tnode)) { tnode=node_bottom(tnode); } else { tnode=node_insert_right(tnode); } if(argc==2) node_set (tnode, TEXT, ""); else node_set (tnode, TEXT, argv[2]); return (int) pos; }
static int toggle_todo_cmd (int argc, char **argv, void *data) { Node *pos = (Node *) data; if (strcmp(fixnullstring(node_get(pos,"type")),"todo")) { /* bail out if not todo info set */ node_set(pos,"type","todo"); node_set(pos,"done","no"); } else { node_unset(pos,"type"); } return (int) pos; }
/* Callback for Proximity Domain -> x2APIC mapping */ void __init acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa) { int pxm, node; int apic_id; if (srat_disabled()) return; if (pa->header.length < sizeof(struct acpi_srat_x2apic_cpu_affinity)) { bad_srat(); return; } if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0) return; pxm = pa->proximity_domain; node = setup_node(pxm); if (node < 0) { printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm); bad_srat(); return; } apic_id = pa->apic_id; if (apic_id >= MAX_LOCAL_APIC) { printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node); return; } set_apicid_to_node(apic_id, node); node_set(node, numa_nodes_parsed); acpi_numa = 1; printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u\n", pxm, apic_id, node); }
unsigned int __init dom0_max_vcpus(void) { unsigned int i, max_vcpus, limit; nodeid_t node; for ( i = 0; i < dom0_nr_pxms; ++i ) if ( (node = pxm_to_node(dom0_pxms[i])) != NUMA_NO_NODE ) node_set(node, dom0_nodes); nodes_and(dom0_nodes, dom0_nodes, node_online_map); if ( nodes_empty(dom0_nodes) ) dom0_nodes = node_online_map; for_each_node_mask ( node, dom0_nodes ) cpumask_or(&dom0_cpus, &dom0_cpus, &node_to_cpumask(node)); cpumask_and(&dom0_cpus, &dom0_cpus, cpupool0->cpu_valid); if ( cpumask_empty(&dom0_cpus) ) cpumask_copy(&dom0_cpus, cpupool0->cpu_valid); max_vcpus = cpumask_weight(&dom0_cpus); if ( opt_dom0_max_vcpus_min > max_vcpus ) max_vcpus = opt_dom0_max_vcpus_min; if ( opt_dom0_max_vcpus_max < max_vcpus ) max_vcpus = opt_dom0_max_vcpus_max; limit = dom0_pvh ? HVM_MAX_VCPUS : MAX_VIRT_CPUS; if ( max_vcpus > limit ) max_vcpus = limit; return max_vcpus; }
/* Callback for Proximity Domain -> ACPI processor UID mapping */ void __init acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { int pxm, node; if (srat_disabled()) return; if (pa->header.length < sizeof(struct acpi_srat_gicc_affinity)) { pr_err("SRAT: Invalid SRAT header length: %d\n", pa->header.length); bad_srat(); return; } if (!(pa->flags & ACPI_SRAT_GICC_ENABLED)) return; pxm = pa->proximity_domain; node = acpi_map_pxm_to_node(pxm); if (node == NUMA_NO_NODE || node >= MAX_NUMNODES) { pr_err("SRAT: Too many proximity domains %d\n", pxm); bad_srat(); return; } node_set(node, numa_nodes_parsed); }
/* Callback for Proximity Domain -> LAPIC mapping */ void __init acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa) { int pxm, node; int apic_id; if (srat_disabled()) return; if (pa->header.length != sizeof(struct acpi_srat_cpu_affinity)) { bad_srat(); return; } if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0) return; pxm = pa->proximity_domain_lo; node = setup_node(pxm); if (node < 0) { printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm); bad_srat(); return; } if (get_uv_system_type() >= UV_X2APIC) apic_id = (pa->apic_id << 8) | pa->local_sapic_eid; else apic_id = pa->apic_id; apicid_to_node[apic_id] = node; node_set(node, cpu_nodes_parsed); acpi_numa = 1; printk(KERN_INFO "SRAT: PXM %u -> APIC %u -> Node %u\n", pxm, apic_id, node); }
void sn2_global_tlb_purge(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long nbits) { int i, ibegin, shub1, cnode, mynasid, cpu, lcpu = 0, nasid; int mymm = (mm == current->active_mm && mm == current->mm); int use_cpu_ptcga; volatile unsigned long *ptc0, *ptc1; unsigned long itc, itc2, flags, data0 = 0, data1 = 0, rr_value, old_rr = 0; short nasids[MAX_NUMNODES], nix; nodemask_t nodes_flushed; int active, max_active, deadlock, flush_opt = sn2_flush_opt; if (flush_opt > 2) { sn2_ipi_flush_all_tlb(mm); return; } nodes_clear(nodes_flushed); i = 0; for_each_cpu(cpu, mm_cpumask(mm)) { cnode = cpu_to_node(cpu); node_set(cnode, nodes_flushed); lcpu = cpu; i++; }
/* * Set nodes, which have memory in @mi, in *@nodemask. */ static void __init numa_nodemask_from_meminfo(nodemask_t *nodemask, const struct numa_meminfo *mi) { int i; for (i = 0; i < ARRAY_SIZE(mi->blk); i++) if (mi->blk[i].start != mi->blk[i].end && mi->blk[i].nid != NUMA_NO_NODE) node_set(mi->blk[i].nid, *nodemask); }
static inline void numaq_register_node(int node, struct sys_cfg_data *scd) { struct eachquadmem *eq = scd->eq + node; u64 start = (u64)(eq->hi_shrd_mem_start - eq->priv_mem_size) << 20; u64 end = (u64)(eq->hi_shrd_mem_start + eq->hi_shrd_mem_size) << 20; int ret; node_set(node, numa_nodes_parsed); ret = numa_add_memblk(node, start, end); BUG_ON(ret < 0); }
static __init int setup_node(int pxm) { unsigned node = pxm2node[pxm]; if (node == 0xff) { if (nodes_weight(nodes_found) >= MAX_NUMNODES) return -1; node = first_unset_node(nodes_found); node_set(node, nodes_found); pxm2node[pxm] = node; } return pxm2node[pxm]; }
void *cmd_att_set (int argc, char **argv, void *data) { Node *pos = (Node *) data; if(argc!=3){ cli_outfunf("usage: %s <attribute> <value>",argv[0]); return pos; } node_set (pos, argv[1], argv[2]); return pos; }
/* Callback for parsing of the Proximity Domain <-> Memory Area mappings */ int __init acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma) { u64 start, end; u32 hotpluggable; int node, pxm; if (srat_disabled()) goto out_err; if (ma->header.length != sizeof(struct acpi_srat_mem_affinity)) goto out_err_bad_srat; if ((ma->flags & ACPI_SRAT_MEM_ENABLED) == 0) goto out_err; hotpluggable = ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE; if (hotpluggable && !save_add_info()) goto out_err; start = ma->base_address; end = start + ma->length; pxm = ma->proximity_domain; if (acpi_srat_revision <= 1) pxm &= 0xff; node = setup_node(pxm); if (node < 0) { printk(KERN_ERR "SRAT: Too many proximity domains.\n"); goto out_err_bad_srat; } if (numa_add_memblk(node, start, end) < 0) goto out_err_bad_srat; node_set(node, numa_nodes_parsed); pr_info("SRAT: Node %u PXM %u [mem %#010Lx-%#010Lx]%s%s\n", node, pxm, (unsigned long long) start, (unsigned long long) end - 1, hotpluggable ? " hotplug" : "", ma->flags & ACPI_SRAT_MEM_NON_VOLATILE ? " non-volatile" : ""); /* Mark hotplug range in memblock. */ if (hotpluggable && memblock_mark_hotplug(start, ma->length)) pr_warn("SRAT: Failed to mark hotplug range [mem %#010Lx-%#010Lx] in memblock\n", (unsigned long long)start, (unsigned long long)end - 1); max_possible_pfn = max(max_possible_pfn, PFN_UP(end - 1)); return 0; out_err_bad_srat: bad_srat(); out_err: return -1; }
/* * Update nodes_add[] * This code supports one contiguous hot add area per node */ static void __init update_nodes_add(int node, unsigned long start, unsigned long end) { unsigned long s_pfn = start >> PAGE_SHIFT; unsigned long e_pfn = end >> PAGE_SHIFT; int changed = 0; struct bootnode *nd = &nodes_add[node]; /* I had some trouble with strange memory hotadd regions breaking the boot. Be very strict here and reject anything unexpected. If you want working memory hotadd write correct SRATs. The node size check is a basic sanity check to guard against mistakes */ if ((signed long)(end - start) < NODE_MIN_SIZE) { printk(KERN_ERR "SRAT: Hotplug area too small\n"); return; } /* This check might be a bit too strict, but I'm keeping it for now. */ if (absent_pages_in_range(s_pfn, e_pfn) != e_pfn - s_pfn) { printk(KERN_ERR "SRAT: Hotplug area %lu -> %lu has existing memory\n", s_pfn, e_pfn); return; } /* Looks good */ if (nd->start == nd->end) { nd->start = start; nd->end = end; changed = 1; } else { if (nd->start == end) { nd->start = start; changed = 1; } if (nd->end == start) { nd->end = end; changed = 1; } if (!changed) printk(KERN_ERR "SRAT: Hotplug zone not continuous. Partly ignored\n"); } if (changed) { node_set(node, numa_nodes_parsed); printk(KERN_INFO "SRAT: hot plug zone found %Lx - %Lx\n", nd->start, nd->end); } }
/** * numa_add_memblk - Set node id to memblk * @nid: NUMA node ID of the new memblk * @start: Start address of the new memblk * @end: End address of the new memblk * * RETURNS: * 0 on success, -errno on failure. */ int __init numa_add_memblk(int nid, u64 start, u64 end) { int ret; ret = memblock_set_node(start, (end - start), &memblock.memory, nid); if (ret < 0) { pr_err("memblock [0x%llx - 0x%llx] failed to add on node %d\n", start, (end - 1), nid); return ret; } node_set(nid, numa_nodes_parsed); return ret; }
int acpi_map_pxm_to_node(int pxm) { int node = pxm_to_node_map[pxm]; if (node < 0) { if (nodes_weight(nodes_found_map) >= MAX_NUMNODES) return NUMA_NO_NODE; node = first_unset_node(nodes_found_map); __acpi_map_pxm_to_node(pxm, node); node_set(node, nodes_found_map); } return node; }
/* * * @return the node inserted * */ Node *import_node_text (import_state_t * is, int level, char *data) { int node_level; level += is->startlevel; while ((node_level = nodes_left (is->npos)) > level) is->npos = node_left (is->npos); if (node_level == level) is->npos = node_insert_down (is->npos); if (node_level < level) is->npos = node_insert_right (is->npos); node_set (is->npos, TEXT, data); return is->npos; }
int __cpuinit acpi_map_pxm_to_node(int pxm) { int node = pxm_to_node_map[pxm]; if (node < 0){ if (nodes_weight(nodes_found_map) >= MAX_NUMNODES) return NID_INVAL; node = first_unset_node(nodes_found_map); pxm_to_node_map[pxm] = node; node_to_pxm_map[node] = pxm; node_set(node, nodes_found_map); } return node; }
/* Callback for parsing of the Proximity Domain <-> Memory Area mappings */ int __init acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma) { u64 start, end; int node, pxm; if (srat_disabled()) return -1; if (ma->header.length != sizeof(struct acpi_srat_mem_affinity)) { bad_srat(); return -1; } /* Memory Affinity (SRAT) 정보를 사용하지 않음 */ if ((ma->flags & ACPI_SRAT_MEM_ENABLED) == 0) return -1; /* Memory Hot Pluggable 이사용되지만, CONFIG 에 설정되어 있지 않은 경우 */ if ((ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) && !save_add_info()) return -1; /* ACPI(SRAT)로 얻어온 Memory Affinity 정보를 설정 */ start = ma->base_address; end = start + ma->length; pxm = ma->proximity_domain; if (acpi_srat_revision <= 1) pxm &= 0xff; /* pxm 으로 node id를 가져옮 */ node = setup_node(pxm); if (node < 0) { printk(KERN_ERR "SRAT: Too many proximity domains.\n"); bad_srat(); return -1; } /* node에 memory block을 추가 */ if (numa_add_memblk(node, start, end) < 0) { bad_srat(); return -1; } node_set(node, numa_nodes_parsed); printk(KERN_INFO "SRAT: Node %u PXM %u [mem %#010Lx-%#010Lx]\n", node, pxm, (unsigned long long) start, (unsigned long long) end - 1); return 0; }
static int add (int argc,char **argv, void *data) { Node *pos = (Node *) data; Node *tnode; if(argc==1){ cli_outfunf("usage: %s <new entry>",argv[0]); return 0; } if (argc==2) { cli_outfun ("empty node added\n"); } tnode = node_insert_down (node_bottom (pos)); node_set (tnode, TEXT, argv[1]); return (int) pos; }
/* Callback for Proximity Domain -> LAPIC mapping */ void __init acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa) { int pxm, node; int apic_id; if (srat_disabled()) return; /* 헤더 크기가 일치하지 않으면 에러출력, disable, 리턴 */ if (pa->header.length != sizeof(struct acpi_srat_cpu_affinity)) { bad_srat(); return; } if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0) return; pxm = pa->proximity_domain_lo; if (acpi_srat_revision >= 2) pxm |= *((unsigned int*)pa->proximity_domain_hi) << 8; /* ACPI로 부터 얻어온 pxm으로부터 node를 얻어온다 */ node = setup_node(pxm); if (node < 0) { printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm); bad_srat(); return; } /* ACPI로 부터 얻어온 apic id 설정 */ if (get_uv_system_type() >= UV_X2APIC) apic_id = (pa->apic_id << 8) | pa->local_sapic_eid; else apic_id = pa->apic_id; if (apic_id >= MAX_LOCAL_APIC) { printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node); return; } /* node에 apic id 설정 */ set_apicid_to_node(apic_id, node); node_set(node, numa_nodes_parsed); acpi_numa = 1; printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%02x -> Node %u\n", pxm, apic_id, node); }
struct cfs_cpt_table * cfs_cpt_table_alloc(unsigned int ncpt) { struct cfs_cpt_table *cptab; if (ncpt != 1) { CERROR("Can't support cpu partition number %d\n", ncpt); return NULL; } cptab = kzalloc(sizeof(*cptab), GFP_NOFS); if (cptab) { cptab->ctb_version = CFS_CPU_VERSION_MAGIC; node_set(0, cptab->ctb_nodemask); cptab->ctb_nparts = ncpt; } return cptab; }
void domain_update_node_affinity(struct domain *d) { cpumask_t cpumask = CPU_MASK_NONE; nodemask_t nodemask = NODE_MASK_NONE; struct vcpu *v; unsigned int node; spin_lock(&d->node_affinity_lock); for_each_vcpu ( d, v ) cpus_or(cpumask, cpumask, v->cpu_affinity); for_each_online_node ( node ) if ( cpus_intersects(node_to_cpumask(node), cpumask) ) node_set(node, nodemask); d->node_affinity = nodemask; spin_unlock(&d->node_affinity_lock); }
/* Callback for Proximity Domain -> x2APIC mapping */ void __init acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa) { int pxm, node; int apic_id; if (srat_disabled()) return; if (pa->header.length < sizeof(struct acpi_srat_x2apic_cpu_affinity)) { bad_srat(); return; } if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0) return; pxm = pa->proximity_domain; apic_id = pa->apic_id; if (!apic->apic_id_valid(apic_id)) { printk(KERN_INFO "SRAT: PXM %u -> X2APIC 0x%04x ignored\n", pxm, apic_id); return; } node = setup_node(pxm); if (node < 0) { printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm); bad_srat(); return; } if (apic_id >= MAX_LOCAL_APIC) { printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u skipped apicid that is too big\n", pxm, apic_id, node); return; } /* ACPI ID와 node id를 1대1 매핑. numa_emulation시에 사용 */ set_apicid_to_node(apic_id, node); /* 파싱이 완료된(APIC로부터 찾아낸) node 설정 */ node_set(node, numa_nodes_parsed); /* numa 완료 상태 설정 (-1일 경우 실패) */ acpi_numa = 1; printk(KERN_INFO "SRAT: PXM %u -> APIC 0x%04x -> Node %u\n", pxm, apic_id, node); }
Node *node_duplicate (Node *node) { Node *newnode; Node_AttItem *att; assert (node); if (!node) return NULL; newnode = (Node *) malloc (sizeof (Node)); if (!newnode) return NULL; memcpy (newnode, node, sizeof (Node)); newnode->attrib = NULL; att = node->attrib; while (att) { node_set (newnode, att->name, att->data); att = att->next; } return newnode; }
std::vector<c_vector<unsigned, 5> > MutableMesh<ELEMENT_DIM, SPACE_DIM>::SplitLongEdges(double cutoffLength) { assert(ELEMENT_DIM == 2); assert(SPACE_DIM == 3); std::vector<c_vector<unsigned, 5> > history; bool long_edge_exists = true; while(long_edge_exists) { std::set<std::pair<unsigned, unsigned> > long_edges; // Loop over elements to check for Long edges for (typename AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::ElementIterator elem_iter = this->GetElementIteratorBegin(); elem_iter != this->GetElementIteratorEnd(); ++elem_iter) { unsigned num_nodes = ELEMENT_DIM+1; // Loop over element vertices for (unsigned local_index=0; local_index<num_nodes; local_index++) { // Find locations of current node (node a) and anticlockwise node (node b) Node<SPACE_DIM>* p_node_a = elem_iter->GetNode(local_index); unsigned local_index_plus_one = (local_index+1)%num_nodes; /// \todo use iterators to tidy this up Node<SPACE_DIM>* p_node_b = elem_iter->GetNode(local_index_plus_one); // Find distance between nodes double distance_between_nodes = this->GetDistanceBetweenNodes(p_node_a->GetIndex(), p_node_b->GetIndex()); if (distance_between_nodes > cutoffLength) { if (p_node_a->GetIndex() < p_node_b->GetIndex()) { std::pair<unsigned, unsigned> long_edge(p_node_a->GetIndex(),p_node_b->GetIndex()); long_edges.insert(long_edge); } else { std::pair<unsigned, unsigned> long_edge(p_node_b->GetIndex(),p_node_a->GetIndex()); long_edges.insert(long_edge); } } } } if (long_edges.size() > 0) //Split the edges in decreasing order. { while (long_edges.size() > 0) { double longest_edge = 0.0; std::set<std::pair<unsigned, unsigned> >::iterator longest_edge_iter; //Find the longest edge in the set and split it for (std::set<std::pair<unsigned, unsigned> >::iterator edge_iter = long_edges.begin(); edge_iter != long_edges.end(); ++edge_iter) { unsigned node_a_global_index = edge_iter->first; unsigned node_b_global_index = edge_iter->second; double distance_between_nodes = this->GetDistanceBetweenNodes(node_a_global_index, node_b_global_index); if (distance_between_nodes > longest_edge) { longest_edge = distance_between_nodes; longest_edge_iter = edge_iter; } } assert(longest_edge >0); c_vector<unsigned, 3> new_node_index = SplitEdge(this->GetNode(longest_edge_iter->first), this->GetNode(longest_edge_iter->second)); c_vector<unsigned, 5> node_set; node_set(0) = new_node_index[0]; node_set(1) = longest_edge_iter->first; node_set(2) = longest_edge_iter->second; node_set(3) = new_node_index[1]; node_set(4) = new_node_index[2]; history.push_back(node_set); // Delete pair from set long_edges.erase(*longest_edge_iter); } } else { long_edge_exists = false; } } return history; }
/* * Sets up nr_nodes fake nodes interleaved over physical nodes ranging from addr * to max_addr. The return value is the number of nodes allocated. */ static int __init split_nodes_interleave(struct numa_meminfo *ei, struct numa_meminfo *pi, u64 addr, u64 max_addr, int nr_nodes) { nodemask_t physnode_mask = NODE_MASK_NONE; u64 size; int big; int nid = 0; int i, ret; if (nr_nodes <= 0) return -1; if (nr_nodes > MAX_NUMNODES) { pr_info("numa=fake=%d too large, reducing to %d\n", nr_nodes, MAX_NUMNODES); nr_nodes = MAX_NUMNODES; } #ifdef XEN_HETEROMEM_FAKENUMA printk(KERN_ALERT "Trying to emualte nr_nodes %d \n",nr_nodes); #endif /* * Calculate target node size. x86_32 freaks on __udivdi3() so do * the division in ulong number of pages and convert back. */ size = max_addr - addr - mem_hole_size(addr, max_addr); #ifdef XEN_HETEROMEM_FAKENUMA printk(KERN_ALERT "max_addr %lu, " "addr %lu, " "mem_hole_size(addr, max_addr) %lu, " "size %lu, \n", max_addr, addr, mem_hole_size(addr, max_addr), size); #endif size = PFN_PHYS((unsigned long)(size >> PAGE_SHIFT) / nr_nodes); #ifdef XEN_HETEROMEM_FAKENUMA printk(KERN_ALERT "size %lu, " "(unsigned long)(size >> PAGE_SHIFT) %lu, " "PFN_PHYS((unsigned long)(size >> PAGE_SHIFT)/nr_nodes) %lu \n ", size, (unsigned long)(size >> PAGE_SHIFT), PFN_PHYS((unsigned long)(size >> PAGE_SHIFT)/nr_nodes)); #endif /* * Calculate the number of big nodes that can be allocated as a result * of consolidating the remainder. */ big = ((size & ~FAKE_NODE_MIN_HASH_MASK) * nr_nodes) / FAKE_NODE_MIN_SIZE; #ifdef XEN_HETEROMEM_FAKENUMA printk(KERN_ALERT "Trying to emualte big nodes %d, " "Pages %lu, " "FAKE_NODE_MIN_HASH_MASK %u, " "size & ~FAKE_NODE_MIN_HASH_MASK %u, " "FAKE_NODE_MIN_SIZE %u ," "nr_nodes %u \n", big, size, FAKE_NODE_MIN_HASH_MASK, size & ~FAKE_NODE_MIN_HASH_MASK, FAKE_NODE_MIN_SIZE, nr_nodes); #endif size &= FAKE_NODE_MIN_HASH_MASK; if (!size) { pr_err("Not enough memory for each node. " "NUMA emulation disabled.\n"); return -1; } for (i = 0; i < pi->nr_blks; i++) node_set(pi->blk[i].nid, physnode_mask); /* * Continue to fill physical nodes with fake nodes until there is no * memory left on any of them. */ while (nodes_weight(physnode_mask)) { for_each_node_mask(i, physnode_mask) { u64 dma32_end = PFN_PHYS(MAX_DMA32_PFN); u64 start, limit, end; int phys_blk; phys_blk = emu_find_memblk_by_nid(i, pi); if (phys_blk < 0) { node_clear(i, physnode_mask); continue; } start = pi->blk[phys_blk].start; limit = pi->blk[phys_blk].end; end = start + size; if (nid < big) end += FAKE_NODE_MIN_SIZE; /* * Continue to add memory to this fake node if its * non-reserved memory is less than the per-node size. */ while (end - start - mem_hole_size(start, end) < size) { end += FAKE_NODE_MIN_SIZE; if (end > limit) { end = limit; break; } } /* * If there won't be at least FAKE_NODE_MIN_SIZE of * non-reserved memory in ZONE_DMA32 for the next node, * this one must extend to the boundary. */ if (end < dma32_end && dma32_end - end - mem_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE) end = dma32_end; /* * If there won't be enough non-reserved memory for the * next node, this one must extend to the end of the * physical node. */ if (limit - end - mem_hole_size(end, limit) < size) end = limit; ret = emu_setup_memblk(ei, pi, nid++ % nr_nodes, phys_blk, min(end, limit) - start); if (ret < 0) return ret; } }
Node *evilloop (Node *pos) { cli_outfun = set_status; while (!quit_tines) { Tbinding *binding; ui_draw (pos, inputbuf, 0); binding = parsekey (ui_input (), ui_current_scope); do { switch (binding->action) { case ui_action_quit: remove_temp (&pos); quit_tines = 1; break; case ui_action_command: if(!string_isoneof(binding->action_param, no_remove_temp_commands)) remove_temp (&pos); pos = docmd (pos, binding->action_param); if(!string_isoneof(binding->action_param,keep_inputbuf)) inputbuf[0] = 0; break; case ui_action_top: remove_temp (&pos); inputbuf[0] = 0; pos = node_top (pos); break; case ui_action_bottom: remove_temp (&pos); inputbuf[0] = 0; pos = node_bottom (pos); break; case ui_action_up: if (!remove_temp (&pos)) { if(forced_up){ if (node_forced_up (pos)){ pos = node_forced_up (pos); } } else { if (node_up (pos)){ pos = node_up (pos); } } } inputbuf[0] = 0; break; case ui_action_down: if (!remove_temp (&pos)) { if(forced_down){ if(node_forced_down(pos)) pos = node_forced_down (pos); } else { if(node_down(pos)) pos = node_down (pos); } inputbuf[0] = 0; break; } case ui_action_pagedown: remove_temp (&pos); inputbuf[0] = 0; { int n; for (n = 0; n < tines_nodes_down; n++) if (node_down (pos)) { pos = node_down (pos); } } break; case ui_action_pageup: remove_temp (&pos); inputbuf[0] = 0; { int n; for (n = 0; n < tines_nodes_up; n++) if (node_up (pos)) pos = node_up (pos); } break; case ui_action_left: if (!remove_temp (&pos)) { if (node_left (pos)) pos = node_left (pos); } inputbuf[0] = 0; break; case ui_action_right: if (node_right (pos)) { pos = node_right (pos); } else { if (fixnullstring (node_get (pos, TEXT))[0]) { node_insert_right (pos); if (node_getflag (pos, F_temp)) node_setflag (pos, F_temp, 0); if (!strcmp(fixnullstring(node_get(pos,"type")),"todo")){ node_set (node_right (pos), "type","todo"); node_set (node_right (pos), "done","no"); } node_setflag (node_right (pos), F_temp, 1); pos = node_right (pos); } } inputbuf[0] = 0; break; case ui_action_complete: if (strcmp (inputbuf, fixnullstring (node_get (pos, TEXT))) == 0) { if (node_right (pos)) { pos = node_right (pos); } else { if (fixnullstring (node_get (pos, TEXT))[0]) { node_insert_right (pos); if (node_getflag (pos, F_temp)) node_setflag (pos, F_temp, 0); if (!strcmp(fixnullstring(node_get(pos,"type")),"todo")){ node_set (node_right (pos), "type","todo"); node_set (node_right (pos), "done","no"); } node_setflag (node_right (pos), F_temp, 1); pos = node_right (pos); } } inputbuf[0] = 0; } else { strcpy (inputbuf, fixnullstring (node_get (pos, TEXT))); } break; case ui_action_cancel: if (node_getflag (pos, F_temp)) { pos = node_remove (pos); } else { /*stop = ui_quit (pos); */ } inputbuf[0] = 0; break; case ui_action_backspace: if (!strlen (inputbuf)) { /*pos = ui_remove (pos); */ } else { inputbuf[strlen (inputbuf) - 1] = 0; if (node_getflag (pos, F_temp)) if (node_up (pos)) pos = node_remove (pos); } break; case ui_action_unbound: undefined_key (ui_scope_names[ui_current_scope], binding->key != 1000 ? binding->key : *((int *) &binding-> action_param[0])); case ui_action_ignore: break; default: if (binding->action > 31 && binding->action < 255) { /* input for buffer */ inputbuf[strlen (inputbuf) + 1] = 0; inputbuf[strlen (inputbuf)] = binding->action; } else undefined_key (ui_scope_names[ui_current_scope], binding->key != 1000 ? binding-> key : *((int *) &binding-> action_param[0])); break; } } while ((++binding)->key == 999); if (strlen (inputbuf)) { if (node_getflag (pos, F_temp)) { node_set (pos, TEXT, inputbuf); } else { if (node_match (inputbuf, pos)) { pos = node_match (inputbuf, pos); } else { if (add_at_top) { pos = node_insert_up (node_top (pos)); } else { pos = node_insert_down (node_bottom (pos)); } node_setflag (pos, F_temp, 1); node_set (pos, TEXT, inputbuf); if (node_left (pos)) if (!strcmp(fixnullstring(node_get(node_left(pos),"type")),"todo")){ node_set (pos, "type","todo"); node_set (pos, "done","no"); } } } } else { docmd(pos, "autosave_check_timeout"); } } return pos; }
static void* import_binary (int argc, char **argv, void *data) { Node *node = (Node *) data; char *filename = argc==2?argv[1]:""; import_state_t ist; int moredata=1; FILE *file; file = fopen (filename, "r"); if (!file) { cli_outfunf ("binary import, unable to open \"%s\"", filename); return node; } {int header,version; fread(&header, sizeof(int), 1, file); fread(&version, sizeof(int), 1, file); if(header!=hnb_binary_header || version!=hnb_binary_version){ cli_outfunf("binary import, header mismatch"); } } init_import(&ist, node); while(moredata){ int attributes; int level; moredata=fread(&level, sizeof(int), 1, file); if(!moredata) break; fread(&attributes, sizeof(int),1,file); if(!moredata) break; if(level || attributes){ Node *temp_node=node_new(); while(attributes){ int len; char *att_name; char *att_data; fread(&len, sizeof(int),1,file); att_name=malloc(len+1); fread(att_name,1,len,file); att_name[len]='\0'; fread(&len, sizeof(int),1,file); att_data=malloc(len+1); fread(att_data,1,len,file); att_data[len]='\0'; node_set(temp_node, att_name, att_data); free(att_name); free(att_data); attributes--; } import_node(&ist,level,temp_node); temp_node=NULL; } } if(node_getflag(node,F_temp)) node=node_remove(node); cli_outfunf("binary import - imported \"%s\"",filename); return node; }