void SharedMemoryRepo::allocate_one_node( uint64_t upid, Eid eid, uint16_t node, uint64_t node_memory_size, uint64_t volatile_pool_size, ErrorStack* alloc_result, SharedMemoryRepo* repo) { // NEVER do COERCE_ERROR here. We must responsibly release shared memory even on errors. std::string node_memory_path = get_self_path(upid, eid) + std::string("_node_") + std::to_string(node); *alloc_result = repo->node_memories_[node].alloc(node_memory_path, node_memory_size, node); if (alloc_result->is_error()) { repo->node_memories_[node].release_block(); return; } std::string volatile_pool_path = get_self_path(upid, eid) + std::string("_vpool_") + std::to_string(node); *alloc_result = repo->volatile_pools_[node].alloc(volatile_pool_path, volatile_pool_size, node); if (alloc_result->is_error()) { repo->node_memories_[node].release_block(); repo->volatile_pools_[node].release_block(); } }
int bproc_currnode(void) { char *p; int r; char tmp[INT_LEN]; get_self_path(p); r = readlink(p, tmp, INT_LEN-1); if (r < 0) return -1; tmp[r] = 0; /* null terminate */ return strtol(tmp, 0, 10); }
ErrorStack SharedMemoryRepo::allocate_shared_memories( uint64_t upid, Eid eid, const EngineOptions& options) { deallocate_shared_memories(); init_empty(options); // We place a serialized EngineOptions in the beginning of shared memory. std::stringstream options_stream; options.save_to_stream(&options_stream); std::string xml(options_stream.str()); uint64_t xml_size = xml.size(); // construct unique meta files using PID. uint64_t global_memory_size = align_2mb(calculate_global_memory_size(xml_size, options)); std::string global_memory_path = get_self_path(upid, eid) + std::string("_global"); CHECK_ERROR(global_memory_.alloc(global_memory_path, global_memory_size, 0)); // from now on, be very careful to not exit without releasing this shared memory. set_global_memory_anchors(xml_size, options, true); global_memory_anchors_.master_status_memory_->status_code_ = MasterEngineStatus::kInitial; // copy the EngineOptions string into the beginning of the global memory std::memcpy(global_memory_.get_block(), &xml_size, sizeof(xml_size)); std::memcpy(global_memory_.get_block() + sizeof(xml_size), xml.data(), xml_size); // the following is parallelized uint64_t node_memory_size = align_2mb(calculate_node_memory_size(options)); uint64_t volatile_pool_size = static_cast<uint64_t>(options.memory_.page_pool_size_mb_per_node_) << 20; ErrorStack alloc_results[kMaxSocs]; std::vector< std::thread > alloc_threads; for (uint16_t node = 0; node < soc_count_; ++node) { alloc_threads.emplace_back(std::thread( SharedMemoryRepo::allocate_one_node, upid, eid, node, node_memory_size, volatile_pool_size, alloc_results + node, this)); } ErrorStack last_error; bool failed = false; for (uint16_t node = 0; node < soc_count_; ++node) { alloc_threads[node].join(); if (alloc_results[node].is_error()) { std::cerr << "[FOEDUS] Failed to allocate node shared memory for node-" << node << ". " << alloc_results[node] << std::endl; last_error = alloc_results[node]; failed = true; } } if (failed) { deallocate_shared_memories(); return last_error; } for (uint16_t node = 0; node < soc_count_; ++node) { set_node_memory_anchors(node, options, true); } return kRetOk; }
} if (!probe_cache__find_by_name(cache, group, event)) { pr_debug("Failed to find %s:%s in the cache\n", group, event); ret = -ENOENT; } probe_cache__delete(cache); return ret; } int test__sdt_event(struct test *test __maybe_unused, int subtests __maybe_unused) { int ret = TEST_FAIL; char __tempdir[] = "./test-buildid-XXXXXX"; char *tempdir = NULL, *myself = get_self_path(); if (myself == NULL || mkdtemp(__tempdir) == NULL) { pr_debug("Failed to make a tempdir for build-id cache\n"); goto error; } /* Note that buildid_dir must be an absolute path */ tempdir = realpath(__tempdir, NULL); if (tempdir == NULL) goto error_rmdir; /* At first, scan itself */ set_buildid_dir(tempdir); if (build_id_cache__add_file(myself) < 0) goto error_rmdir;
bool address_to_line(void* call_addr, char* buffer, size_t size_of_buffer) { if(!call_addr) return false; char buff[1024]; ssize_t len; if(!get_self_path(buff,sizeof(buff),len)) return false; const char addr2line_cmd[] = "addr2line -e"; const char postfix_cmd[] = ""; // convert address to char array char addr[32]; sprintf(addr,"%p",call_addr); size_t addr_len = strlen(addr); addr[addr_len] = '\0'; // allocate memory for command char* cmd = (char*)(malloc)(sizeof(addr2line_cmd) // command length + NULL termination + len // main path + sizeof(postfix_cmd) // postfix length + extra space + addr_len); // address length // make command strcpy(cmd,addr2line_cmd); strcat(cmd+sizeof(addr2line_cmd)-1,buff); sprintf(cmd+strlen(cmd)," %s",addr); strcat(cmd,postfix_cmd); size_t cmd_len = strlen(cmd); cmd[cmd_len]='\0'; // run command FILE* fp = popen(cmd,"r"); if(fp) { //char buffer[1024]; if(fgets(buffer, size_of_buffer, fp)!=NULL) { if(buffer[0] == '?') { size_t buffer_len = strlen(buffer); buffer[buffer_len-1] = '\0'; pclose(fp); free(cmd); return false; } } else { size_t buffer_len = strlen(buffer); buffer[buffer_len-1] = '\0'; pclose(fp); free(cmd); return false; } } size_t buffer_len = strlen(buffer); buffer[buffer_len-1] = '\0'; pclose(fp); free(cmd); return true; }