Skip to content

Commit

Permalink
Merge branch 'upstream-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Datadog Syncup Service committed Sep 11, 2024
2 parents 58103fe + 55a7cf1 commit 609ee68
Show file tree
Hide file tree
Showing 50 changed files with 1,148 additions and 568 deletions.
21 changes: 0 additions & 21 deletions src/hotspot/cpu/x86/assembler_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1405,12 +1405,6 @@ void Assembler::addb(Register dst, int imm8) {
emit_arith_b(0x80, 0xC0, dst, imm8);
}

void Assembler::addw(Register dst, Register src) {
emit_int8(0x66);
(void)prefix_and_encode(dst->encoding(), src->encoding());
emit_arith(0x03, 0xC0, dst, src);
}

void Assembler::addw(Address dst, int imm16) {
InstructionMark im(this);
emit_int8(0x66);
Expand Down Expand Up @@ -1632,11 +1626,6 @@ void Assembler::andb(Address dst, Register src) {
emit_operand(src, dst, 0);
}

void Assembler::andw(Register dst, Register src) {
(void)prefix_and_encode(dst->encoding(), src->encoding());
emit_arith(0x23, 0xC0, dst, src);
}

void Assembler::andl(Address dst, int32_t imm32) {
InstructionMark im(this);
prefix(dst);
Expand Down Expand Up @@ -4230,11 +4219,6 @@ void Assembler::notl(Register dst) {
emit_int16((unsigned char)0xF7, (0xD0 | encode));
}

void Assembler::orw(Register dst, Register src) {
(void)prefix_and_encode(dst->encoding(), src->encoding());
emit_arith(0x0B, 0xC0, dst, src);
}

void Assembler::orl(Address dst, int32_t imm32) {
InstructionMark im(this);
prefix(dst);
Expand Down Expand Up @@ -6803,11 +6787,6 @@ void Assembler::xorb(Address dst, Register src) {
emit_operand(src, dst, 0);
}

void Assembler::xorw(Register dst, Register src) {
(void)prefix_and_encode(dst->encoding(), src->encoding());
emit_arith(0x33, 0xC0, dst, src);
}

void Assembler::xorw(Register dst, Address src) {
InstructionMark im(this);
emit_int8(0x66);
Expand Down
5 changes: 0 additions & 5 deletions src/hotspot/cpu/x86/assembler_x86.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,6 @@ class Assembler : public AbstractAssembler {
void addb(Address dst, int imm8);
void addb(Address dst, Register src);
void addb(Register dst, int imm8);
void addw(Register dst, Register src);
void addw(Address dst, int imm16);
void addw(Address dst, Register src);

Expand Down Expand Up @@ -1120,7 +1119,6 @@ class Assembler : public AbstractAssembler {
void vaesdec(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len);
void vaesdeclast(XMMRegister dst, XMMRegister nds, XMMRegister src, int vector_len);

void andw(Register dst, Register src);
void andb(Address dst, Register src);

void andl(Address dst, int32_t imm32);
Expand Down Expand Up @@ -1824,8 +1822,6 @@ class Assembler : public AbstractAssembler {
#endif
void btq(Register dst, Register src);

void orw(Register dst, Register src);

void orl(Address dst, int32_t imm32);
void orl(Register dst, int32_t imm32);
void orl(Register dst, Address src);
Expand Down Expand Up @@ -2342,7 +2338,6 @@ class Assembler : public AbstractAssembler {

void xorb(Address dst, Register src);
void xorb(Register dst, Address src);
void xorw(Register dst, Register src);
void xorw(Register dst, Address src);

void xorq(Register dst, Address src);
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/os/linux/cgroupSubsystem_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ jlong CgroupSubsystem::memory_limit_in_bytes() {
bool CgroupController::read_string(const char* filename, char* buf, size_t buf_size) {
assert(buf != nullptr, "buffer must not be null");
assert(filename != nullptr, "filename must be given");
char* s_path = subsystem_path();
const char* s_path = subsystem_path();
if (s_path == nullptr) {
log_debug(os, container)("read_string: subsystem path is null");
return false;
Expand Down Expand Up @@ -679,7 +679,7 @@ bool CgroupController::read_numerical_key_value(const char* filename, const char
assert(key != nullptr, "key must be given");
assert(result != nullptr, "result pointer must not be null");
assert(filename != nullptr, "file to search in must be given");
char* s_path = subsystem_path();
const char* s_path = subsystem_path();
if (s_path == nullptr) {
log_debug(os, container)("read_numerical_key_value: subsystem path is null");
return false;
Expand Down
18 changes: 17 additions & 1 deletion src/hotspot/os/linux/cgroupSubsystem_linux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,15 @@
}

class CgroupController: public CHeapObj<mtInternal> {
protected:
char* _cgroup_path;
char* _mount_point;
public:
virtual char* subsystem_path() = 0;
virtual const char* subsystem_path() = 0;
virtual bool is_read_only() = 0;
const char* cgroup_path() { return _cgroup_path; }
const char* mount_point() { return _mount_point; }
virtual bool needs_hierarchy_adjustment() { return false; }

/* Read a numerical value as unsigned long
*
Expand Down Expand Up @@ -202,7 +208,12 @@ class CgroupCpuController: public CHeapObj<mtInternal> {
virtual int cpu_quota() = 0;
virtual int cpu_period() = 0;
virtual int cpu_shares() = 0;
virtual bool needs_hierarchy_adjustment() = 0;
virtual bool is_read_only() = 0;
virtual const char* subsystem_path() = 0;
virtual void set_subsystem_path(const char* cgroup_path) = 0;
virtual const char* mount_point() = 0;
virtual const char* cgroup_path() = 0;
};

// Pure virtual class representing version agnostic memory controllers
Expand All @@ -217,7 +228,12 @@ class CgroupMemoryController: public CHeapObj<mtInternal> {
virtual jlong rss_usage_in_bytes() = 0;
virtual jlong cache_usage_in_bytes() = 0;
virtual void print_version_specific_info(outputStream* st, julong host_mem) = 0;
virtual bool needs_hierarchy_adjustment() = 0;
virtual bool is_read_only() = 0;
virtual const char* subsystem_path() = 0;
virtual void set_subsystem_path(const char* cgroup_path) = 0;
virtual const char* mount_point() = 0;
virtual const char* cgroup_path() = 0;
};

class CgroupSubsystem: public CHeapObj<mtInternal> {
Expand Down
111 changes: 111 additions & 0 deletions src/hotspot/os/linux/cgroupUtil_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*
*/

#include "os_linux.hpp"
#include "cgroupUtil_linux.hpp"

int CgroupUtil::processor_count(CgroupCpuController* cpu_ctrl, int host_cpus) {
Expand All @@ -46,3 +47,113 @@ int CgroupUtil::processor_count(CgroupCpuController* cpu_ctrl, int host_cpus) {
log_trace(os, container)("OSContainer::active_processor_count: %d", result);
return result;
}

void CgroupUtil::adjust_controller(CgroupMemoryController* mem) {
if (!mem->needs_hierarchy_adjustment()) {
// nothing to do
return;
}
log_trace(os, container)("Adjusting controller path for memory: %s", mem->subsystem_path());
assert(mem->cgroup_path() != nullptr, "invariant");
char* orig = os::strdup(mem->cgroup_path());
char* cg_path = os::strdup(orig);
char* last_slash;
assert(cg_path[0] == '/', "cgroup path must start with '/'");
julong phys_mem = os::Linux::physical_memory();
char* limit_cg_path = nullptr;
jlong limit = mem->read_memory_limit_in_bytes(phys_mem);
jlong lowest_limit = phys_mem;
while ((last_slash = strrchr(cg_path, '/')) != cg_path) {
*last_slash = '\0'; // strip path
// update to shortened path and try again
mem->set_subsystem_path(cg_path);
limit = mem->read_memory_limit_in_bytes(phys_mem);
if (limit >= 0 && limit < lowest_limit) {
lowest_limit = limit;
os::free(limit_cg_path); // handles nullptr
limit_cg_path = os::strdup(cg_path);
}
}
// need to check limit at mount point
mem->set_subsystem_path("/");
limit = mem->read_memory_limit_in_bytes(phys_mem);
if (limit >= 0 && limit < lowest_limit) {
lowest_limit = limit;
os::free(limit_cg_path); // handles nullptr
limit_cg_path = os::strdup("/");
}
assert(lowest_limit >= 0, "limit must be positive");
if ((julong)lowest_limit != phys_mem) {
// we've found a lower limit anywhere in the hierarchy,
// set the path to the limit path
assert(limit_cg_path != nullptr, "limit path must be set");
mem->set_subsystem_path(limit_cg_path);
log_trace(os, container)("Adjusted controller path for memory to: %s. "
"Lowest limit was: " JLONG_FORMAT,
mem->subsystem_path(),
lowest_limit);
} else {
log_trace(os, container)("No lower limit found for memory in hierarchy %s, "
"adjusting to original path %s",
mem->mount_point(), orig);
mem->set_subsystem_path(orig);
}
os::free(cg_path);
os::free(orig);
os::free(limit_cg_path);
}

void CgroupUtil::adjust_controller(CgroupCpuController* cpu) {
if (!cpu->needs_hierarchy_adjustment()) {
// nothing to do
return;
}
log_trace(os, container)("Adjusting controller path for cpu: %s", cpu->subsystem_path());
assert(cpu->cgroup_path() != nullptr, "invariant");
char* orig = os::strdup(cpu->cgroup_path());
char* cg_path = os::strdup(orig);
char* last_slash;
assert(cg_path[0] == '/', "cgroup path must start with '/'");
int host_cpus = os::Linux::active_processor_count();
int cpus = CgroupUtil::processor_count(cpu, host_cpus);
int lowest_limit = host_cpus;
char* limit_cg_path = nullptr;
while ((last_slash = strrchr(cg_path, '/')) != cg_path) {
*last_slash = '\0'; // strip path
// update to shortened path and try again
cpu->set_subsystem_path(cg_path);
cpus = CgroupUtil::processor_count(cpu, host_cpus);
if (cpus != host_cpus && cpus < lowest_limit) {
lowest_limit = cpus;
os::free(limit_cg_path); // handles nullptr
limit_cg_path = os::strdup(cg_path);
}
}
// need to check limit at mount point
cpu->set_subsystem_path("/");
cpus = CgroupUtil::processor_count(cpu, host_cpus);
if (cpus != host_cpus && cpus < lowest_limit) {
lowest_limit = cpus;
os::free(limit_cg_path); // handles nullptr
limit_cg_path = os::strdup(cg_path);
}
assert(lowest_limit >= 0, "limit must be positive");
if (lowest_limit != host_cpus) {
// we've found a lower limit anywhere in the hierarchy,
// set the path to the limit path
assert(limit_cg_path != nullptr, "limit path must be set");
cpu->set_subsystem_path(limit_cg_path);
log_trace(os, container)("Adjusted controller path for cpu to: %s. "
"Lowest limit was: %d",
cpu->subsystem_path(),
lowest_limit);
} else {
log_trace(os, container)("No lower limit found for cpu in hierarchy %s, "
"adjusting to original path %s",
cpu->mount_point(), orig);
cpu->set_subsystem_path(orig);
}
os::free(cg_path);
os::free(orig);
os::free(limit_cg_path);
}
6 changes: 6 additions & 0 deletions src/hotspot/os/linux/cgroupUtil_linux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class CgroupUtil: AllStatic {

public:
static int processor_count(CgroupCpuController* cpu, int host_cpus);
// Given a memory controller, adjust its path to a point in the hierarchy
// that represents the closest memory limit.
static void adjust_controller(CgroupMemoryController* m);
// Given a cpu controller, adjust its path to a point in the hierarchy
// that represents the closest cpu limit.
static void adjust_controller(CgroupCpuController* c);
};

#endif // CGROUP_UTIL_LINUX_HPP
Loading

0 comments on commit 609ee68

Please sign in to comment.