* [PATCH] Avoid use of the old CPU macros
@ 2018-05-09 16:08 Stanislav Brabec
2018-05-09 16:16 ` Michael Matz
2018-05-10 9:44 ` Karel Zak
0 siblings, 2 replies; 6+ messages in thread
From: Stanislav Brabec @ 2018-05-09 16:08 UTC (permalink / raw)
To: util-linux; +Cc: Michael Matz
The old CPU macros are limited to 1024 cores. As a result, lscpu cannot
count sockets on large systems. Use new scalable macros.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Cc: Michael Matz <matz@suse.de>
---
sys-utils/chcpu.c | 6 +++---
sys-utils/lscpu.c | 13 +++++++++----
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/sys-utils/chcpu.c b/sys-utils/chcpu.c
index 12e52d887..f32b7a6fc 100644
--- a/sys-utils/chcpu.c
+++ b/sys-utils/chcpu.c
@@ -81,7 +81,7 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
size_t fails = 0;
for (cpu = 0; cpu < setsize; cpu++) {
- if (!CPU_ISSET(cpu, cpu_set))
+ if (!CPU_ISSET_S(cpu, setsize, cpu_set))
continue;
if (!path_exist(_PATH_SYS_CPU "/cpu%d", cpu)) {
warnx(_("CPU %u does not exist"), cpu);
@@ -127,7 +127,7 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
} else {
printf(_("CPU %u disabled\n"), cpu);
if (onlinecpus)
- CPU_CLR(cpu, onlinecpus);
+ CPU_CLR_S(cpu, setsize, onlinecpus);
}
}
}
@@ -173,7 +173,7 @@ static int cpu_configure(cpu_set_t *cpu_set, size_t setsize, int configure)
size_t fails = 0;
for (cpu = 0; cpu < setsize; cpu++) {
- if (!CPU_ISSET(cpu, cpu_set))
+ if (!CPU_ISSET_S(cpu, setsize, cpu_set))
continue;
if (!path_exist(_PATH_SYS_CPU "/cpu%d", cpu)) {
warnx(_("CPU %u does not exist"), cpu);
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 2132511a5..fd6d63bbf 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -478,7 +478,7 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod)
desc->idx2cpunum = xcalloc(desc->ncpuspos, sizeof(int));
for (num = 0, idx = 0; num < maxcpus; num++) {
- if (CPU_ISSET(num, tmp))
+ if (CPU_ISSET_S(num, setsize, tmp))
desc->idx2cpunum[idx++] = num;
}
cpuset_free(tmp);
@@ -1109,10 +1109,11 @@ cpu_max_mhz(struct lscpu_desc *desc, char *buf, size_t bufsz)
{
int i;
float cpu_freq = 0.0;
+ size_t setsize = CPU_ALLOC_SIZE(maxcpus);
if (desc->present) {
for (i = 0; i < desc->ncpuspos; i++) {
- if (CPU_ISSET(real_cpu_num(desc, i), desc->present)
+ if (CPU_ISSET_S(real_cpu_num(desc, i), setsize, desc->present)
&& desc->maxmhz[i]) {
float freq = atof(desc->maxmhz[i]);
@@ -1131,10 +1132,11 @@ cpu_min_mhz(struct lscpu_desc *desc, char *buf, size_t bufsz)
{
int i;
float cpu_freq = -1.0;
+ size_t setsize = CPU_ALLOC_SIZE(maxcpus);
if (desc->present) {
for (i = 0; i < desc->ncpuspos; i++) {
- if (CPU_ISSET(real_cpu_num(desc, i), desc->present)
+ if (CPU_ISSET_S(real_cpu_num(desc, i), setsize, desc->present)
&& desc->minmhz[i]) {
float freq = atof(desc->minmhz[i]);
@@ -1931,6 +1933,7 @@ int main(int argc, char *argv[])
int c, i;
int columns[ARRAY_SIZE(coldescs)], ncolumns = 0;
int cpu_modifier_specified = 0;
+ size_t setsize;
static const struct option longopts[] = {
{ "all", no_argument, NULL, 'a' },
@@ -2034,10 +2037,12 @@ int main(int argc, char *argv[])
read_basicinfo(desc, mod);
+ setsize = CPU_ALLOC_SIZE(maxcpus);
+
for (i = 0; i < desc->ncpuspos; i++) {
/* only consider present CPUs */
if (desc->present &&
- !CPU_ISSET(real_cpu_num(desc, i), desc->present))
+ !CPU_ISSET_S(real_cpu_num(desc, i), setsize, desc->present))
continue;
read_topology(desc, i);
read_cache(desc, i);
--
2.16.3
--
Best Regards / S pozdravem,
Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o. e-mail: sbrabec@suse.com
Křižíkova 148/34 (Corso IIa) tel: +49 911 7405384547
186 00 Praha 8-Karlín fax: +420 284 084 001
Czech Republic http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Avoid use of the old CPU macros
2018-05-09 16:08 [PATCH] Avoid use of the old CPU macros Stanislav Brabec
@ 2018-05-09 16:16 ` Michael Matz
2018-05-09 16:26 ` Stanislav Brabec
2018-05-10 9:44 ` Karel Zak
1 sibling, 1 reply; 6+ messages in thread
From: Michael Matz @ 2018-05-09 16:16 UTC (permalink / raw)
To: Stanislav Brabec; +Cc: util-linux
Hi,
On Wed, 9 May 2018, Stanislav Brabec wrote:
> diff --git a/sys-utils/chcpu.c b/sys-utils/chcpu.c
> index 12e52d887..f32b7a6fc 100644
> --- a/sys-utils/chcpu.c
> +++ b/sys-utils/chcpu.c
> @@ -81,7 +81,7 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
> size_t fails = 0;
>
> for (cpu = 0; cpu < setsize; cpu++) {
> - if (!CPU_ISSET(cpu, cpu_set))
> + if (!CPU_ISSET_S(cpu, setsize, cpu_set))
Careful, the _S macros count the size in _bytes_, the above loop iterates
in nr-of-cpus (i.e. bits), or alternatively if the caller really gives a
byte size then the loop iterations don't catch all CPUs. More instances
follow.
> diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
> index 2132511a5..fd6d63bbf 100644
> --- a/sys-utils/lscpu.c
> +++ b/sys-utils/lscpu.c
> @@ -478,7 +478,7 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod)
> desc->idx2cpunum = xcalloc(desc->ncpuspos, sizeof(int));
>
> for (num = 0, idx = 0; num < maxcpus; num++) {
> - if (CPU_ISSET(num, tmp))
> + if (CPU_ISSET_S(num, setsize, tmp))
> desc->idx2cpunum[idx++] = num;
> }
> cpuset_free(tmp);
> @@ -1109,10 +1109,11 @@ cpu_max_mhz(struct lscpu_desc *desc, char *buf, size_t bufsz)
> {
> int i;
> float cpu_freq = 0.0;
> + size_t setsize = CPU_ALLOC_SIZE(maxcpus);
>
> if (desc->present) {
> for (i = 0; i < desc->ncpuspos; i++) {
> - if (CPU_ISSET(real_cpu_num(desc, i), desc->present)
> + if (CPU_ISSET_S(real_cpu_num(desc, i), setsize, desc->present)
This here is okay, though, CPU_ALLOC_SIZE also counts in bytes.
Ciao,
Michael.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Avoid use of the old CPU macros
2018-05-09 16:16 ` Michael Matz
@ 2018-05-09 16:26 ` Stanislav Brabec
2018-05-09 20:13 ` [PATCH] chcpu: Fix maximal number of CPUs Stanislav Brabec
2018-05-10 9:38 ` [PATCH] Avoid use of the old CPU macros Karel Zak
0 siblings, 2 replies; 6+ messages in thread
From: Stanislav Brabec @ 2018-05-09 16:26 UTC (permalink / raw)
To: Michael Matz; +Cc: util-linux
Michael Matz wrote:
> On Wed, 9 May 2018, Stanislav Brabec wrote:
>> for (cpu = 0; cpu < setsize; cpu++) {
>> - if (!CPU_ISSET(cpu, cpu_set))
>> + if (!CPU_ISSET_S(cpu, setsize, cpu_set))
>
> Careful, the _S macros count the size in _bytes_, the above loop iterates
> in nr-of-cpus (i.e. bits), or alternatively if the caller really gives a
> byte size then the loop iterations don't catch all CPUs. More instances
> follow.
setsize passed to the function is CPU_ALLOC_SIZE(maxcpus).
Do I understand correctly that the new !CPU_ISSET_S is correct, but the
loop limit should be maxcpus?
--
Best Regards / S pozdravem,
Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o. e-mail: sbrabec@suse.com
Křižíkova 148/34 (Corso IIa) tel: +49 911 7405384547
186 00 Praha 8-Karlín fax: +420 284 084 001
Czech Republic http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] chcpu: Fix maximal number of CPUs
2018-05-09 16:26 ` Stanislav Brabec
@ 2018-05-09 20:13 ` Stanislav Brabec
2018-05-10 9:38 ` [PATCH] Avoid use of the old CPU macros Karel Zak
1 sibling, 0 replies; 6+ messages in thread
From: Stanislav Brabec @ 2018-05-09 20:13 UTC (permalink / raw)
To: util-linux; +Cc: Michael Matz, Heiko Carstens
chcpu.c mixed maxcpus (number of cpus) and setsize (size of CPU bit
mask). It effectively limits number of CPUs to 1/8 of the supported
amount.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Cc: Michael Matz <matz@suse.de>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
---
sys-utils/chcpu.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/sys-utils/chcpu.c b/sys-utils/chcpu.c
index f32b7a6fc..4b5c7579a 100644
--- a/sys-utils/chcpu.c
+++ b/sys-utils/chcpu.c
@@ -75,12 +75,12 @@ enum {
*/
static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
{
- unsigned int cpu;
+ int cpu;
int online, rc;
int configured = -1;
- size_t fails = 0;
+ int fails = 0;
- for (cpu = 0; cpu < setsize; cpu++) {
+ for (cpu = 0; cpu < maxcpus; cpu++) {
if (!CPU_ISSET_S(cpu, setsize, cpu_set))
continue;
if (!path_exist(_PATH_SYS_CPU "/cpu%d", cpu)) {
@@ -132,7 +132,7 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable)
}
}
- return fails == 0 ? 0 : fails == setsize ? -1 : 1;
+ return fails == 0 ? 0 : fails == maxcpus ? -1 : 1;
}
static int cpu_rescan(void)
@@ -168,11 +168,11 @@ static int cpu_set_dispatch(int mode)
*/
static int cpu_configure(cpu_set_t *cpu_set, size_t setsize, int configure)
{
- unsigned int cpu;
+ int cpu;
int rc, current;
- size_t fails = 0;
+ int fails = 0;
- for (cpu = 0; cpu < setsize; cpu++) {
+ for (cpu = 0; cpu < maxcpus; cpu++) {
if (!CPU_ISSET_S(cpu, setsize, cpu_set))
continue;
if (!path_exist(_PATH_SYS_CPU "/cpu%d", cpu)) {
@@ -217,7 +217,7 @@ static int cpu_configure(cpu_set_t *cpu_set, size_t setsize, int configure)
}
}
- return fails == 0 ? 0 : fails == setsize ? -1 : 1;
+ return fails == 0 ? 0 : fails == maxcpus ? -1 : 1;
}
static void cpu_parse(char *cpu_string, cpu_set_t *cpu_set, size_t setsize)
--
2.16.3
--
Best Regards / S pozdravem,
Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o. e-mail: sbrabec@suse.com
Křižíkova 148/34 (Corso IIa) tel: +49 911 7405384547
186 00 Praha 8-Karlín fax: +420 284 084 001
Czech Republic http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Avoid use of the old CPU macros
2018-05-09 16:26 ` Stanislav Brabec
2018-05-09 20:13 ` [PATCH] chcpu: Fix maximal number of CPUs Stanislav Brabec
@ 2018-05-10 9:38 ` Karel Zak
1 sibling, 0 replies; 6+ messages in thread
From: Karel Zak @ 2018-05-10 9:38 UTC (permalink / raw)
To: Stanislav Brabec; +Cc: Michael Matz, util-linux
On Wed, May 09, 2018 at 06:26:16PM +0200, Stanislav Brabec wrote:
> Michael Matz wrote:
> > On Wed, 9 May 2018, Stanislav Brabec wrote:
> >> for (cpu = 0; cpu < setsize; cpu++) {
> >> - if (!CPU_ISSET(cpu, cpu_set))
> >> + if (!CPU_ISSET_S(cpu, setsize, cpu_set))
> >
> > Careful, the _S macros count the size in _bytes_, the above loop iterates
> > in nr-of-cpus (i.e. bits), or alternatively if the caller really gives a
> > byte size then the loop iterations don't catch all CPUs. More instances
> > follow.
>
> setsize passed to the function is CPU_ALLOC_SIZE(maxcpus).
>
> Do I understand correctly that the new !CPU_ISSET_S is correct, but the
> loop limit should be maxcpus?
I think so, setsize is aligned (in bytes) to handle maxsize (bits).
The loop is incorrect, should be maxcpus. I'll fix.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Avoid use of the old CPU macros
2018-05-09 16:08 [PATCH] Avoid use of the old CPU macros Stanislav Brabec
2018-05-09 16:16 ` Michael Matz
@ 2018-05-10 9:44 ` Karel Zak
1 sibling, 0 replies; 6+ messages in thread
From: Karel Zak @ 2018-05-10 9:44 UTC (permalink / raw)
To: Stanislav Brabec; +Cc: util-linux, Michael Matz
On Wed, May 09, 2018 at 06:08:32PM +0200, Stanislav Brabec wrote:
> sys-utils/chcpu.c | 6 +++---
> sys-utils/lscpu.c | 13 +++++++++----
> 2 files changed, 12 insertions(+), 7 deletions(-)
All the patches applied. Thanks (and thanks to Michael for review).
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-05-10 9:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-09 16:08 [PATCH] Avoid use of the old CPU macros Stanislav Brabec
2018-05-09 16:16 ` Michael Matz
2018-05-09 16:26 ` Stanislav Brabec
2018-05-09 20:13 ` [PATCH] chcpu: Fix maximal number of CPUs Stanislav Brabec
2018-05-10 9:38 ` [PATCH] Avoid use of the old CPU macros Karel Zak
2018-05-10 9:44 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).