!31 [sync] PR-29: feature: add rfs and rps/xps=multi to [network]

From: @openeuler-sync-bot 
Reviewed-by: @hubin95 
Signed-off-by: @hubin95
This commit is contained in:
openeuler-ci-bot 2023-11-29 03:08:33 +00:00 committed by Gitee
commit 12c820734a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 238 additions and 1 deletions

View File

@ -2,7 +2,7 @@
Name: atune-collector
Version: 1.1.0
Release: 5
Release: 6
Summary: A-Tune-Collector is used to collect various system resources.
License: Mulan PSL v2
URL: https://gitee.com/openeuler/A-Tune-Collector
@ -21,6 +21,8 @@ Patch10: bugfix-create-file-only-if-setting-params.patch
Patch11: change-import-behavior.patch
Patch12: atune-collector-add-backup-for-apps.patch
Patch13: feature-add-network-CPI.patch
Patch14: feature-add-multi-for-rps-xps.patch
Patch15: feature-add-rfs-to-network.patch
BuildRequires: python3-setuptools
Requires: python3-dict2xml
@ -45,6 +47,9 @@ The A-Tune-Collector is used to collect various system resources and can also be
%attr(0600,root,root) %{_sysconfdir}/atune_collector/*
%changelog
* Wed Nov 29 2023 gaoruoshu <gaoruoshu@huawei.com> - 1.1.0-6
- feature: add rfs and rps/xps=multi to [network]
* Tue Aug 22 2023 gaoruoshu <gaoruoshu@huawei.com> - 1.1.0-5
- feature: add [network] to CPI

View File

@ -0,0 +1,100 @@
From c2df28764f159163233cdab4fb34f62efe888c4e Mon Sep 17 00:00:00 2001
From: gaoruoshu <gaoruoshu@huawei.com>
Date: Mon, 27 Nov 2023 12:56:09 +0000
Subject: [PATCH 1/2] feature: add 'multi' for rps/xps
Signed-off-by: gaoruoshu <gaoruoshu@huawei.com>
---
.../plugin/configurator/network/network.py | 55 ++++++++++++++++++-
1 file changed, 52 insertions(+), 3 deletions(-)
diff --git a/atune_collector/plugin/configurator/network/network.py b/atune_collector/plugin/configurator/network/network.py
index 977f29c..afc31f2 100644
--- a/atune_collector/plugin/configurator/network/network.py
+++ b/atune_collector/plugin/configurator/network/network.py
@@ -35,8 +35,8 @@ class Network(Configurator):
def __init__(self, user=None):
Configurator.__init__(self, user)
- self._cmd_map = {'xps': ['all', 'off', 'half', 'separate'],
- 'rps': ['all', 'off', 'half', 'separate']}
+ self._cmd_map = {'xps': ['all', 'off', 'half', 'separate', 'multi'],
+ 'rps': ['all', 'off', 'half', 'separate', 'multi']}
self._nic = self._get_nic()
self._queue_dir = '/sys/class/net/{}/queues'.format(self._nic)
@@ -52,6 +52,12 @@ class Network(Configurator):
'Failed to get dir under {}'.format(self._queue_dir))
dir_list = re.findall(pattern, dir_strs)
core_num = os.cpu_count()
+
+ multi_qs = len(dir_list)
+ stride = 1 if core_num // multi_qs == 0 else core_num // multi_qs
+ stragglers = 0 if core_num <= multi_qs else core_num % multi_qs
+ cur_cpu = 0
+ dir_list = sorted(dir_list, key=lambda x: int(x.split('-')[1]))
for index, dir_name in enumerate(dir_list):
file_path = '{}/{}/{}_cpus'.format(self._queue_dir, dir_name, key)
shell_cmd(['cat', file_path],
@@ -75,14 +81,57 @@ class Network(Configurator):
offset = index % half_num
val_format = 1 << (offset + half_num + core_num % 2)
set_value = f"{val_format:x}"
- else: # value == 'separate'
+ elif value == 'separate':
num = 1 << (index % core_num)
set_value = f"{num:x}"
+ else: # value = multi:
+ str_value = ''
+ gsize = stride if index >= stragglers else stride + 1
+ for _ in range(gsize):
+ str_value = str(cur_cpu) + ' ' + str_value
+ cur_cpu += 1
+ set_value = self._u32list(str_value)
shell_cmd(['sh', '-c', 'echo {} > {}'.format(set_value, file_path)],
'Failed to set {} to {}'.format(key, file_path))
return 0
+ @staticmethod
+ def _u32list(cpulist):
+ max_cpu = 0
+ ii = 0
+
+ for _cpu in cpulist.split():
+ if max_cpu < int(_cpu):
+ max_cpu = int(_cpu)
+
+ #init a bitmap
+ map = [0] * (max_cpu + 1)
+
+ # set bit map according to cpulist
+ for _cpu in cpulist.split():
+ map[int(_cpu)] = 1
+
+ #format a u32list
+ seg = 0
+ mask = ''
+ for ii in range(max_cpu + 1):
+ if ii % 4 == 0 and ii != 0:
+ seg = format(seg, 'x')
+ mask = seg + mask
+ seg = 0
+ if ii % 32 == 0 and ii != 0:
+ mask = ',' + mask
+ cur = map[ii]
+ if cur == 1:
+ val = 1 << (ii % 4)
+ seg += val
+
+ if seg != 0:
+ seg = format(seg, 'x')
+ mask = seg + mask
+ return mask
+
def _set(self, key, value):
if not key.lower() in self._cmd_map or not value.lower() in self._cmd_map[key.lower()]:
raise SetConfigError("Invalid value {}={}".format(key, value))
--
2.27.0

View File

@ -0,0 +1,132 @@
From abc01d60cc574b27b943f2d619f0b3cca8f6e1c6 Mon Sep 17 00:00:00 2001
From: gaoruoshu <gaoruoshu@huawei.com>
Date: Tue, 28 Nov 2023 03:35:26 +0000
Subject: [PATCH 2/2] feature: add rfs to network
Signed-off-by: gaoruoshu <gaoruoshu@huawei.com>
---
.../plugin/configurator/network/network.py | 56 +++++++++++++++----
1 file changed, 44 insertions(+), 12 deletions(-)
diff --git a/atune_collector/plugin/configurator/network/network.py b/atune_collector/plugin/configurator/network/network.py
index afc31f2..01e5640 100644
--- a/atune_collector/plugin/configurator/network/network.py
+++ b/atune_collector/plugin/configurator/network/network.py
@@ -36,7 +36,8 @@ class Network(Configurator):
def __init__(self, user=None):
Configurator.__init__(self, user)
self._cmd_map = {'xps': ['all', 'off', 'half', 'separate', 'multi'],
- 'rps': ['all', 'off', 'half', 'separate', 'multi']}
+ 'rps': ['all', 'off', 'half', 'separate', 'multi'],
+ 'rfs': ['on', 'off']}
self._nic = self._get_nic()
self._queue_dir = '/sys/class/net/{}/queues'.format(self._nic)
@@ -47,17 +48,21 @@ class Network(Configurator):
config.read('/etc/atuned/atuned.cnf')
return config.get('system', 'network')
- def _set_cpus(self, key, value, pattern):
+ def _get_init(self, pattern):
dir_strs = shell_cmd(['ls', self._queue_dir],
'Failed to get dir under {}'.format(self._queue_dir))
dir_list = re.findall(pattern, dir_strs)
+ dir_list = sorted(dir_list, key=lambda x: int(x.split('-')[1]))
core_num = os.cpu_count()
+ return dir_list, core_num
+
+ def _set_cpus(self, key, value, pattern):
+ dir_list, core_num = self._get_init(pattern)
multi_qs = len(dir_list)
stride = 1 if core_num // multi_qs == 0 else core_num // multi_qs
stragglers = 0 if core_num <= multi_qs else core_num % multi_qs
cur_cpu = 0
- dir_list = sorted(dir_list, key=lambda x: int(x.split('-')[1]))
for index, dir_name in enumerate(dir_list):
file_path = '{}/{}/{}_cpus'.format(self._queue_dir, dir_name, key)
shell_cmd(['cat', file_path],
@@ -84,13 +89,15 @@ class Network(Configurator):
elif value == 'separate':
num = 1 << (index % core_num)
set_value = f"{num:x}"
- else: # value = multi:
- str_value = ''
+ elif value == 'multi': # value = multi:
+ list_cpu = []
gsize = stride if index >= stragglers else stride + 1
for _ in range(gsize):
- str_value = str(cur_cpu) + ' ' + str_value
+ list_cpu.append(cur_cpu)
cur_cpu += 1
- set_value = self._u32list(str_value)
+ set_value = self._u32list(list_cpu)
+ else:
+ raise SetConfigError("cannot set {} to {}".format(key, value))
shell_cmd(['sh', '-c', 'echo {} > {}'.format(set_value, file_path)],
'Failed to set {} to {}'.format(key, file_path))
@@ -101,16 +108,15 @@ class Network(Configurator):
max_cpu = 0
ii = 0
- for _cpu in cpulist.split():
- if max_cpu < int(_cpu):
- max_cpu = int(_cpu)
+ for _cpu in cpulist:
+ max_cpu = max(max_cpu, _cpu)
#init a bitmap
map = [0] * (max_cpu + 1)
# set bit map according to cpulist
- for _cpu in cpulist.split():
- map[int(_cpu)] = 1
+ for _cpu in cpulist:
+ map[_cpu] = 1
#format a u32list
seg = 0
@@ -131,6 +137,30 @@ class Network(Configurator):
seg = format(seg, 'x')
mask = seg + mask
return mask
+
+ def _set_rfs(self, value, pattern):
+ dir_list, _ = self._get_init(pattern)
+ for dir_name in dir_list:
+ file_path = '{}/{}/rps_flow_cnt'.format(self._queue_dir, dir_name)
+ shell_cmd(['cat', file_path],
+ 'Failed to set rfs={}: does not support for rfs'.format(value))
+ if value == 'off':
+ set_value = 0
+ elif value == 'on':
+ set_value = 4096
+ else:
+ raise SetConfigError("cannot set rfs to {}".format(value))
+ shell_cmd(['sh', '-c', 'echo {} > {}'.format(set_value, file_path)],
+ 'Failed to set rfs to {}'.format(file_path))
+
+ if value == 'off':
+ entries = 0
+ elif value == 'on':
+ entries = 4096 * len(dir_list)
+ entries_path = '/proc/sys/net/core/rps_sock_flow_entries'
+ shell_cmd(['sh', '-c', 'echo {} > {}'.format(entries, entries_path)],
+ 'Failed to set rfs to {}'.format(entries_path))
+ return 0
def _set(self, key, value):
if not key.lower() in self._cmd_map or not value.lower() in self._cmd_map[key.lower()]:
@@ -140,6 +170,8 @@ class Network(Configurator):
self._set_cpus(key.lower(), value.lower(), r'tx-\d+')
elif key == 'rps':
self._set_cpus(key.lower(), value.lower(), r'rx-\d+')
+ elif key == 'rfs':
+ self._set_rfs(value.lower(), r'rx-\d+')
return 0
--
2.27.0