diff options
author | Daniil Baturin <daniil@vyos.io> | 2025-05-20 15:54:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-20 15:54:33 +0100 |
commit | 22310904c95003585dd24f2d071458d598ce047d (patch) | |
tree | 8c994e6b2441808a0460dbfe12f517727996f6c1 /python | |
parent | 20ebbe36c3798383134854f3333bbbd2c2413043 (diff) | |
parent | 1f6939dae267e163faa591cb67004c237ad10e16 (diff) | |
download | vyos-1x-22310904c95003585dd24f2d071458d598ce047d.tar.gz vyos-1x-22310904c95003585dd24f2d071458d598ce047d.zip |
Merge pull request #4499 from sever-sever/T7348
T7348: Add config CPU thread-count for accel-ppp services
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/configdict.py | 12 | ||||
-rw-r--r-- | python/vyos/utils/cpu.py | 6 |
2 files changed, 17 insertions, 1 deletions
diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py index ff0a15933..a34b0176a 100644 --- a/python/vyos/configdict.py +++ b/python/vyos/configdict.py @@ -661,6 +661,7 @@ def get_accel_dict(config, base, chap_secrets, with_pki=False): Return a dictionary with the necessary interface config keys. """ from vyos.utils.cpu import get_core_count + from vyos.utils.cpu import get_half_cpus from vyos.template import is_ipv4 dict = config.get_config_dict(base, key_mangling=('-', '_'), @@ -670,7 +671,16 @@ def get_accel_dict(config, base, chap_secrets, with_pki=False): with_pki=with_pki) # set CPUs cores to process requests - dict.update({'thread_count' : get_core_count()}) + match dict.get('thread_count'): + case 'all': + dict['thread_count'] = get_core_count() + case 'half': + dict['thread_count'] = get_half_cpus() + case str(x) if x.isdigit(): + dict['thread_count'] = int(x) + case _: + dict['thread_count'] = get_core_count() + # we need to store the path to the secrets file dict.update({'chap_secrets_file' : chap_secrets}) diff --git a/python/vyos/utils/cpu.py b/python/vyos/utils/cpu.py index 8ace77d15..6f21eb526 100644 --- a/python/vyos/utils/cpu.py +++ b/python/vyos/utils/cpu.py @@ -26,6 +26,7 @@ It has special cases for x86_64 and MAY work correctly on other architectures, but nothing is certain. """ +import os import re def _read_cpuinfo(): @@ -114,3 +115,8 @@ def get_available_cpus(): out = json.loads(cmd('lscpu --extended -b --json')) return out['cpus'] + + +def get_half_cpus(): + """ return 1/2 of the numbers of available CPUs """ + return max(1, os.cpu_count() // 2) |