1 Star 0 Fork 50

山竹/systemd

forked from src-anolis-os/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0287-cpu-set-util-use-d-d-format-in-cpu_set_to_range_stri.patch 4.36 KB
一键复制 编辑 原始数据 按行查看 历史
张彬琛 提交于 2021-01-20 13:59 . import systemd-239-29.el8.src.rpm
From 35894625624f0e8c7d3ca2c200861005c7ad4435 Mon Sep 17 00:00:00 2001
From: Michal Sekletar <msekleta@redhat.com>
Date: Mon, 3 Jun 2019 10:12:35 +0200
Subject: [PATCH] cpu-set-util: use %d-%d format in cpu_set_to_range_string()
only for actual ranges
(cherry picked from commit 71923237b18df35401626993d8a285cd998be78d)
Related: #1734787
---
src/basic/cpu-set-util.c | 4 ++--
src/test/test-cpu-set-util.c | 16 +++++++++-------
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/src/basic/cpu-set-util.c b/src/basic/cpu-set-util.c
index 5024290557..103b9703b3 100644
--- a/src/basic/cpu-set-util.c
+++ b/src/basic/cpu-set-util.c
@@ -58,7 +58,7 @@ char *cpu_set_to_range_string(const CPUSet *set) {
if (!GREEDY_REALLOC(str, allocated, len + 2 + 2 * DECIMAL_STR_MAX(unsigned)))
return NULL;
- if (range_end > range_start || len == 0)
+ if (range_end > range_start)
r = sprintf(str + len, len > 0 ? " %d-%d" : "%d-%d", range_start, range_end);
else
r = sprintf(str + len, len > 0 ? " %d" : "%d", range_start);
@@ -70,7 +70,7 @@ char *cpu_set_to_range_string(const CPUSet *set) {
if (!GREEDY_REALLOC(str, allocated, len + 2 + 2 * DECIMAL_STR_MAX(int)))
return NULL;
- if (range_end > range_start || len == 0)
+ if (range_end > range_start)
r = sprintf(str + len, len > 0 ? " %d-%d" : "%d-%d", range_start, range_end);
else
r = sprintf(str + len, len > 0 ? " %d" : "%d", range_start);
diff --git a/src/test/test-cpu-set-util.c b/src/test/test-cpu-set-util.c
index 995b981d25..9522582891 100644
--- a/src/test/test-cpu-set-util.c
+++ b/src/test/test-cpu-set-util.c
@@ -26,7 +26,7 @@ static void test_parse_cpu_set(void) {
str = mfree(str);
assert_se(str = cpu_set_to_range_string(&c));
log_info("cpu_set_to_range_string: %s", str);
- assert_se(streq(str, "0-0"));
+ assert_se(streq(str, "0"));
str = mfree(str);
cpu_set_reset(&c);
@@ -95,17 +95,19 @@ static void test_parse_cpu_set(void) {
cpu_set_reset(&c);
/* Commas with spaces (and trailing comma, space) */
- assert_se(parse_cpu_set_full("0, 1, 2, 3, 4, 5, 6, 7, ", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
+ assert_se(parse_cpu_set_full("0, 1, 2, 3, 4, 5, 6, 7, 63, ", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
- assert_se(CPU_COUNT_S(c.allocated, c.set) == 8);
+ assert_se(CPU_COUNT_S(c.allocated, c.set) == 9);
for (cpu = 0; cpu < 8; cpu++)
assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
+
+ assert_se(CPU_ISSET_S(63, c.allocated, c.set));
assert_se(str = cpu_set_to_string(&c));
log_info("cpu_set_to_string: %s", str);
str = mfree(str);
assert_se(str = cpu_set_to_range_string(&c));
log_info("cpu_set_to_range_string: %s", str);
- assert_se(streq(str, "0-7"));
+ assert_se(streq(str, "0-7 63"));
str = mfree(str);
cpu_set_reset(&c);
@@ -161,11 +163,11 @@ static void test_parse_cpu_set(void) {
cpu_set_reset(&c);
/* Mix ranges and individual CPUs */
- assert_se(parse_cpu_set_full("0,1 4-11", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
+ assert_se(parse_cpu_set_full("0,2 4-11", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
assert_se(CPU_COUNT_S(c.allocated, c.set) == 10);
assert_se(CPU_ISSET_S(0, c.allocated, c.set));
- assert_se(CPU_ISSET_S(1, c.allocated, c.set));
+ assert_se(CPU_ISSET_S(2, c.allocated, c.set));
for (cpu = 4; cpu < 12; cpu++)
assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
assert_se(str = cpu_set_to_string(&c));
@@ -173,7 +175,7 @@ static void test_parse_cpu_set(void) {
str = mfree(str);
assert_se(str = cpu_set_to_range_string(&c));
log_info("cpu_set_to_range_string: %s", str);
- assert_se(streq(str, "0-1 4-11"));
+ assert_se(streq(str, "0 2 4-11"));
str = mfree(str);
cpu_set_reset(&c);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wangpingping000/systemd.git
git@gitee.com:wangpingping000/systemd.git
wangpingping000
systemd
systemd
a8

搜索帮助