diff --git a/providers/docker/run.sh b/providers/docker/run.sh index d00eb230da847a06a7f2878e85f95cbd9a32d741..0ffd37060d40143fb37c9f1ea0fbd1b9f30c42ae 100755 --- a/providers/docker/run.sh +++ b/providers/docker/run.sh @@ -34,7 +34,6 @@ parse_host_metadata() { # Set host parameters nr_cpu=${nr_cpu:-$(grep '^nr_cpu: ' "${host_file}" | cut -f2 -d' ')} memory=${memory:-$(grep '^memory: ' "${host_file}" | cut -f2 -d' ')} - create_yaml_variables "${host_file}" } determine_host_group() { @@ -59,13 +58,15 @@ check_container_runtime() { export container_runtime } -configure_ccache() { - [[ "${ccache_enable}" != "True" ]] && return 0 - +set_resource_limits() { # Set default resource limits memory_minimum=${memory_minimum:-8} - memory="${memory_minimum}g" + memory="${memory}g" nr_cpu=${cpu_minimum:-${nr_cpu}} +} + +configure_ccache() { + [[ "${ccache_enable}" != "True" ]] && return 0 local ccache_container ccache_container=$($container_runtime ps --format '{{.Names}}' | grep -m1 'k8s_ccache_ccache' || true) @@ -100,7 +101,7 @@ build_base_command() { --oom-score-adj="-1000" ) - [[ -n "${nr_cpu}" ]] && container_cmd+=(--cpus "${nr_cpu}") + [[ -n "${nr_cpu}" && "$nr_cpu" -ne 0 ]] && container_cmd+=(--cpus "${nr_cpu}") } add_volume_mounts() { @@ -281,6 +282,7 @@ main() { parse_host_metadata check_container_runtime configure_ccache + set_resource_limits setup_file_paths configure_networking diff --git a/providers/qemu/kvm.sh b/providers/qemu/kvm.sh index 45b36eaee465e86b69b6373a0d5b61ee07754986..dd0a32ad2ec5d94ced61acf5ee93a9f62317821b 100755 --- a/providers/qemu/kvm.sh +++ b/providers/qemu/kvm.sh @@ -329,6 +329,15 @@ show_kernel_info() [ -z "$DEBUG" ] && log_info less $log_file } +set_nr_cpu() +{ + if [[ -n "${nr_cpu}" && "$nr_cpu" -ne 0 ]]; then + smp="-smp ${nr_cpu}" + else + smp="-smp $(nproc)" + fi +} + common_option() { kvm=( @@ -338,7 +347,7 @@ common_option() -name guest=$hostname,process=$job_id -kernel $kernel -initrd concatenated-initrd.cgz - -smp $nr_cpu + $smp -m $memory -rtc base=localtime -k en-us @@ -501,6 +510,7 @@ set_options() set_nr_nic # set_nic # disable for now: this caused ping_check fail set_qemu + set_nr_cpu } write_dmesg_flag() diff --git a/src/job.cr b/src/job.cr index 54d3e5f41854ac50dbd856dd1e61daf38c4a790e..d562197e40e2468643d788548ac03734f86c6433 100644 --- a/src/job.cr +++ b/src/job.cr @@ -343,6 +343,7 @@ class JobHash category os + arch os_arch os_version os_variant @@ -452,6 +453,7 @@ class JobHash emsx nickname host_machine + nr_cpu tbox_type branch job_origin @@ -803,6 +805,7 @@ class JobHash if self.tbox_group =~ /^(vm|dc)-(\d+)p(\d+)g$/ mb = [mb, $3.to_u32].max end + @schedule_memmb = mb end @@ -976,12 +979,12 @@ class JobHash if host = Sched.instance.hosts_cache.get_host(self.testbox) # Assign number values - hi["nr_node"] = host.nr_node.to_s if host.hash_uint32.has_key?("nr_node") - hi["nr_cpu"] = host.nr_cpu.to_s if host.hash_uint32.has_key?("nr_cpu") - hi["memory"] = host.memory.to_s if host.hash_uint32.has_key?("memory") - hi["nr_disks"] = host.nr_disks.to_s if host.hash_uint32.has_key?("nr_disks") - hi["nr_hdd_partitions"] = host.nr_hdd_partitions.to_s if host.hash_uint32.has_key?("nr_hdd_partitions") - hi["nr_ssd_partitions"] = host.nr_ssd_partitions.to_s if host.hash_uint32.has_key?("nr_ssd_partitions") + hi["nr_node"] ||= host.nr_node.to_s if host.hash_uint32.has_key?("nr_node") + hi["nr_cpu"] ||= host.nr_cpu.to_s if host.hash_uint32.has_key?("nr_cpu") + hi["memory"] ||= host.memory.to_s if host.hash_uint32.has_key?("memory") + hi["nr_disks"] ||= host.nr_disks.to_s if host.hash_uint32.has_key?("nr_disks") + hi["nr_hdd_partitions"] ||= host.nr_hdd_partitions.to_s if host.hash_uint32.has_key?("nr_hdd_partitions") + hi["nr_ssd_partitions"] ||= host.nr_ssd_partitions.to_s if host.hash_uint32.has_key?("nr_ssd_partitions") # Assign string values hi["rootfs_disk"] = host.rootfs_disk.to_s if host.hash_str.has_key?("rootfs_disk") @@ -990,15 +993,14 @@ class JobHash hi["mac_addr"] = host.mac_addr.join(" ") if host.hash_str_array.has_key?("mac_addr") end + hi["memory"] ||= self.schedule_memmb.to_s + if self.testbox =~ /-(\d+)p(\d+)g/ hi["nr_cpu"] = $1 hi["memory"] = ($2.to_i32 * 1024).to_s end - # Don't limit CPU by default - hi["memory"] ||= self.schedule_memmb.to_s - - self.hw = hi unless self.hash_hh.has_key? "hw" + hi["memory"] = ($2.to_i32 * 1024).to_s if testbox =~ /(dc|vm)-(\d+)g/ end # pending jobs are in Sched @jobs_cache_in_submit @@ -1150,6 +1152,8 @@ class Job < JobHash if @hash_hh.has_key?("hw") _hw = @hash_hh["hw"].as(Hash) + return unless _hw.has_key?("memory") + _memory = _hw["memory"].to_s.match(/\d+/) if _memory self.memory_minimum = _memory[0] diff --git a/src/pkgbuild.cr b/src/pkgbuild.cr index 1fe925a492e3a392834efcdcfe62d455e050eec4..e75d44acf941cab325022cbe822fa93521b9f424 100644 --- a/src/pkgbuild.cr +++ b/src/pkgbuild.cr @@ -108,7 +108,7 @@ class PkgBuild < PluginsCommon configure_os_and_arch(build_job, job, params) # Set runtime and resource requirements - configure_runtime_and_resources(build_job) + configure_runtime_and_resources(build_job, params) # Copy relevant file store paths copy_file_store_paths(build_job, job) @@ -163,13 +163,21 @@ class PkgBuild < PluginsCommon private def configure_environment(build_job, job, params) testbox = params.delete("testbox") if testbox + hw = Hash(String, String).new build_job.testbox = testbox if testbox.starts_with?("dc") build_job.docker_image = params.delete("docker_image") || "openeuler/openeuler:24.03" build_job.os_mount = "container" + nr_cpu = params.delete("nr_cpu") || "1" + memory = params.delete("memory") || "8g" else build_job.os_mount = params.delete("os_mount") || "initramfs" + nr_cpu = params.delete("nr_cpu") + memory = params.delete("memory") end + hw["nr_cpu"] = nr_cpu if nr_cpu + hw["memory"] = memory if memory + build_job.hash_hh["hw"] = hw unless hw.empty? else docker_image = params.delete("docker_image") || job.docker_image? if docker_image @@ -195,9 +203,8 @@ class PkgBuild < PluginsCommon end # Set runtime and resource requirements - private def configure_runtime_and_resources(build_job) - build_job.runtime = "36000" - build_job.need_memory = "8g" + private def configure_runtime_and_resources(build_job, params) + build_job.runtime = params.delete("runtime") || "36000" build_job.install_os_packages_all = "ruby cpio gzip wget curl git fakeroot coreutils file findutils grep sed bzip2 gcc autoconf automake make patch" end