Skip to content

Instantly share code, notes, and snippets.

@Albert26193
Created January 12, 2026 10:25
Show Gist options
  • Select an option

  • Save Albert26193/b1f244358e451bb6bdd5384a6b44d45d to your computer and use it in GitHub Desktop.

Select an option

Save Albert26193/b1f244358e451bb6bdd5384a6b44d45d to your computer and use it in GitHub Desktop.
makefile for cpu in k8s
# Get cpu info for docker/k8s container env
BUILD_JOBS ?=
ifeq ($(BUILD_JOBS),)
BUILD_JOBS := $(shell nproc)
ifeq ($(shell test -d /sys/fs/cgroup/cpu && echo 1),1)
CPU_QUOTA := $(shell cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us)
CPU_PERIOD := $(shell cat /sys/fs/cgroup/cpu/cpu.cfs_period_us)
ifneq ($(CPU_QUOTA),-1)
BUILD_JOBS := $(shell expr $(CPU_QUOTA) / $(CPU_PERIOD))
endif
endif
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment