Path: blob/master/src/hotspot/os/linux/gc/z/zNUMA_linux.cpp
40971 views
/*1* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "gc/z/zCPU.inline.hpp"24#include "gc/z/zErrno.hpp"25#include "gc/z/zNUMA.hpp"26#include "gc/z/zSyscall_linux.hpp"27#include "runtime/globals.hpp"28#include "runtime/os.hpp"29#include "utilities/debug.hpp"3031void ZNUMA::pd_initialize() {32_enabled = UseNUMA;33}3435uint32_t ZNUMA::count() {36if (!_enabled) {37// NUMA support not enabled38return 1;39}4041return os::Linux::numa_max_node() + 1;42}4344uint32_t ZNUMA::id() {45if (!_enabled) {46// NUMA support not enabled47return 0;48}4950return os::Linux::get_node_by_cpu(ZCPU::id());51}5253uint32_t ZNUMA::memory_id(uintptr_t addr) {54if (!_enabled) {55// NUMA support not enabled, assume everything belongs to node zero56return 0;57}5859uint32_t id = (uint32_t)-1;6061if (ZSyscall::get_mempolicy((int*)&id, NULL, 0, (void*)addr, MPOL_F_NODE | MPOL_F_ADDR) == -1) {62ZErrno err;63fatal("Failed to get NUMA id for memory at " PTR_FORMAT " (%s)", addr, err.to_string());64}6566assert(id < count(), "Invalid NUMA id");6768return id;69}707172