11/*
22 * Copyright (c) 2024, 2025, Red Hat, Inc.
3+ * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
34 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45 *
56 * This code is free software; you can redistribute it and/or modify it
2526#include " cgroupUtil_linux.hpp"
2627#include " os_linux.hpp"
2728
28- bool CgroupUtil::processor_count (CgroupCpuController* cpu_ctrl, int upper_bound, int & value) {
29+ bool CgroupUtil::processor_count (CgroupCpuController* cpu_ctrl, int upper_bound, double & value) {
2930 assert (upper_bound > 0 , " upper bound of cpus must be positive" );
30- int limit_count = upper_bound;
3131 int quota = -1 ;
3232 int period = -1 ;
3333 if (!cpu_ctrl->cpu_quota (quota)) {
@@ -37,20 +37,15 @@ bool CgroupUtil::processor_count(CgroupCpuController* cpu_ctrl, int upper_bound,
3737 return false ;
3838 }
3939 int quota_count = 0 ;
40- int result = upper_bound;
40+ double result = upper_bound;
4141
42- if (quota > -1 && period > 0 ) {
43- quota_count = ceilf ((float )quota / (float )period);
44- log_trace (os, container)(" CPU Quota count based on quota/period: %d" , quota_count);
42+ if (quota > 0 && period > 0 ) { // Use quotas
43+ double cpu_quota = static_cast <double >(quota) / period;
44+ log_trace (os, container)(" CPU Quota based on quota/period: %.2f" , cpu_quota);
45+ result = MIN2 (result, cpu_quota);
4546 }
4647
47- // Use quotas
48- if (quota_count != 0 ) {
49- limit_count = quota_count;
50- }
51-
52- result = MIN2 (upper_bound, limit_count);
53- log_trace (os, container)(" OSContainer::active_processor_count: %d" , result);
48+ log_trace (os, container)(" OSContainer::active_processor_count: %.2f" , result);
5449 value = result;
5550 return true ;
5651}
@@ -73,11 +68,11 @@ physical_memory_size_type CgroupUtil::get_updated_mem_limit(CgroupMemoryControll
7368
7469// Get an updated cpu limit. The return value is strictly less than or equal to the
7570// passed in 'lowest' value.
76- int CgroupUtil::get_updated_cpu_limit (CgroupCpuController* cpu,
71+ double CgroupUtil::get_updated_cpu_limit (CgroupCpuController* cpu,
7772 int lowest,
7873 int upper_bound) {
7974 assert (lowest > 0 && lowest <= upper_bound, " invariant" );
80- int cpu_limit_val = -1 ;
75+ double cpu_limit_val = -1 ;
8176 if (CgroupUtil::processor_count (cpu, upper_bound, cpu_limit_val) && cpu_limit_val != upper_bound) {
8277 assert (cpu_limit_val <= upper_bound, " invariant" );
8378 if (lowest > cpu_limit_val) {
@@ -172,7 +167,7 @@ void CgroupUtil::adjust_controller(CgroupCpuController* cpu) {
172167 assert (cg_path[0 ] == ' /' , " cgroup path must start with '/'" );
173168 int host_cpus = os::Linux::active_processor_count ();
174169 int lowest_limit = host_cpus;
175- int cpus = get_updated_cpu_limit (cpu, lowest_limit, host_cpus);
170+ double cpus = get_updated_cpu_limit (cpu, lowest_limit, host_cpus);
176171 int orig_limit = lowest_limit != host_cpus ? lowest_limit : host_cpus;
177172 char * limit_cg_path = nullptr ;
178173 while ((last_slash = strrchr (cg_path, ' /' )) != cg_path) {
0 commit comments