Skip to contentSkip to conversation

cobalt/sched: Use nr_cpumask_bits instead of BITS_PER_LONG

PATCH In review Richard Weinberger 3 participants 7 messages Mar 14, 2022 – Mar 15, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cobalt/sched: Use nr_cpumask_bits instead of BITS_PER_LONG

BITS_PER_LONG is too broad, the max number of usable bits is limited by nr_cpumask_bits.
Found while debugging a system with CONFIG_DEBUG_PER_CPU_MAPS enabled.

---
 kernel/cobalt/sched.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cobalt/sched.c +2 -2
index 88c4951ed814..aa65fd7f5d63 100644
@@ -1370,7 +1370,7 @@ static int affinity_vfile_show(struct xnvfile_regular_iterator *it,
 	unsigned long val = 0;
 	int cpu;
 
-	for (cpu = 0; cpu < BITS_PER_LONG; cpu++)
+	for (cpu = 0; cpu < nr_cpumask_bits; cpu++)
 		if (cpumask_test_cpu(cpu, &cobalt_cpu_affinity))
 			val |= (1UL << cpu);
 
@@ -1395,7 +1395,7 @@ static ssize_t affinity_vfile_store(struct xnvfile_input *input)
 		affinity = xnsched_realtime_cpus; /* Reset to default. */
 	else {
 		cpumask_clear(&affinity);
-		for (cpu = 0; cpu < BITS_PER_LONG; cpu++, val >>= 1) {
+		for (cpu = 0; cpu < nr_cpumask_bits; cpu++, val >>= 1) {
 			if (val & 1) {
 				/*
 				 * The new dynamic affinity must be a strict
Signature · 1 line
2.26.2
#1 lore raw

Hi Richard,

Quoted 2 lines · Richard Weinberger via Xenomai

BITS_PER_LONG is too broad, the max number of usable bits is limited by nr_cpumask_bits.

I agree, BITS_PER_LONG seems wrong. But couldn't it be too small as well? It depends on NR_CPUS which might be > BITS_PER_LONG.

Regards,
Florian

Quoted 29 lines

Found while debugging a system with CONFIG_DEBUG_PER_CPU_MAPS enabled.

---
 kernel/cobalt/sched.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cobalt/sched.c +2 -2
index 88c4951ed814..aa65fd7f5d63 100644
@@ -1370,7 +1370,7 @@ static int affinity_vfile_show(struct xnvfile_regular_iterator *it,
 	unsigned long val = 0;
 	int cpu;
 
-	for (cpu = 0; cpu < BITS_PER_LONG; cpu++)
+	for (cpu = 0; cpu < nr_cpumask_bits; cpu++)
 		if (cpumask_test_cpu(cpu, &cobalt_cpu_affinity))
 			val |= (1UL << cpu);
 
@@ -1395,7 +1395,7 @@ static ssize_t affinity_vfile_store(struct xnvfile_input *input)
 		affinity = xnsched_realtime_cpus; /* Reset to default. */
 	else {
 		cpumask_clear(&affinity);
-		for (cpu = 0; cpu < BITS_PER_LONG; cpu++, val >>= 1) {
+		for (cpu = 0; cpu < nr_cpumask_bits; cpu++, val >>= 1) {
 			if (val & 1) {
 				/*
 				 * The new dynamic affinity must be a strict
#2 lore raw

----- Ursprüngliche Mail -----

Quoted 3 lines

Von: "Florian Bezdeka" <[email protected]>
I agree, BITS_PER_LONG seems wrong. But couldn't it be too small as well? It depends on NR_CPUS which might be > BITS_PER_LONG.

Hmm, nr_cpumask_bits is defined as:

#ifdef CONFIG_CPUMASK_OFFSTACK
/* Assuming NR_CPUS is huge, a runtime limit is more efficient. Also,
* not all bits may be allocated. */
#define nr_cpumask_bits nr_cpu_ids
#else
#define nr_cpumask_bits ((unsigned int)NR_CPUS)
#endif

Where do you see a problem?

Thanks,
//richard

#3 lore raw
Quoted 15 lines · Richard Weinberger

----- Ursprüngliche Mail -----

Quoted 3 lines

Von: "Florian Bezdeka" <[email protected]>
I agree, BITS_PER_LONG seems wrong. But couldn't it be too small as well? It depends on NR_CPUS which might be > BITS_PER_LONG.

Hmm, nr_cpumask_bits is defined as:

#ifdef CONFIG_CPUMASK_OFFSTACK
/* Assuming NR_CPUS is huge, a runtime limit is more efficient. Also,
* not all bits may be allocated. */
#define nr_cpumask_bits nr_cpu_ids
#else
#define nr_cpumask_bits ((unsigned int)NR_CPUS)
#endif

Quoted 1 line

Where do you see a problem?

I'm fine with the implementation. Just struggled with the wording / commit message. Sorry for the race in the mail thread...

Quoted 3 lines

Thanks,
//richard

#4 lore raw

----- Ursprüngliche Mail -----

Quoted 5 lines

Von: "Florian Bezdeka" <[email protected]>

Quoted 1 line

Where do you see a problem?

I'm fine with the implementation. Just struggled with the wording / commit message. Sorry for the race in the mail thread...

No need to worry. :-)

Thanks,
//richard

#5 lore raw
In reply to Bezdeka, Florian
Quoted 9 lines · Florian via Xenomai

Hi Richard,

Quoted 2 lines · Richard Weinberger via Xenomai

BITS_PER_LONG is too broad, the max number of usable bits is limited by nr_cpumask_bits.

I agree, BITS_PER_LONG seems wrong. But couldn't it be too small as well? It depends on NR_CPUS which might be > BITS_PER_LONG.

Sorry that was unclear. I assume that the size of the cpumask depends somehow on NR_CPUS, which might be > BITS_PER_LONG. So BITS_PER_LONG might be too small AND might be too broad.

Quoted 34 lines

Regards,
Florian

Quoted 29 lines

Found while debugging a system with CONFIG_DEBUG_PER_CPU_MAPS enabled.

---
 kernel/cobalt/sched.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cobalt/sched.c +2 -2
index 88c4951ed814..aa65fd7f5d63 100644
@@ -1370,7 +1370,7 @@ static int affinity_vfile_show(struct xnvfile_regular_iterator *it,
 	unsigned long val = 0;
 	int cpu;
 
-	for (cpu = 0; cpu < BITS_PER_LONG; cpu++)
+	for (cpu = 0; cpu < nr_cpumask_bits; cpu++)
 		if (cpumask_test_cpu(cpu, &cobalt_cpu_affinity))
 			val |= (1UL << cpu);
 
@@ -1395,7 +1395,7 @@ static ssize_t affinity_vfile_store(struct xnvfile_input *input)
 		affinity = xnsched_realtime_cpus; /* Reset to default. */
 	else {
 		cpumask_clear(&affinity);
-		for (cpu = 0; cpu < BITS_PER_LONG; cpu++, val >>= 1) {
+		for (cpu = 0; cpu < nr_cpumask_bits; cpu++, val >>= 1) {
 			if (val & 1) {
 				/*
 				 * The new dynamic affinity must be a strict
#6 lore raw
Quoted 8 lines · Florian via Xenomai
Quoted 7 lines · Florian via Xenomai

Hi Richard,

Quoted 2 lines · Richard Weinberger via Xenomai

BITS_PER_LONG is too broad, the max number of usable bits is limited by nr_cpumask_bits.

Quoted 7 lines
Quoted 2 lines

I agree, BITS_PER_LONG seems wrong. But couldn't it be too small as well? It depends on NR_CPUS which might be > BITS_PER_LONG.

Sorry that was unclear. I assume that the size of the cpumask depends somehow on NR_CPUS, which might be > BITS_PER_LONG. So BITS_PER_LONG might be too small AND might be too broad.

Good hint, I've adjusted this on merge.

Thanks,
Jan

Quoted 35 lines
Quoted 34 lines

Regards,
Florian

Quoted 29 lines

Found while debugging a system with CONFIG_DEBUG_PER_CPU_MAPS enabled.

---
 kernel/cobalt/sched.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/cobalt/sched.c +2 -2
index 88c4951ed814..aa65fd7f5d63 100644
@@ -1370,7 +1370,7 @@ static int affinity_vfile_show(struct xnvfile_regular_iterator *it,
 	unsigned long val = 0;
 	int cpu;
 
-	for (cpu = 0; cpu < BITS_PER_LONG; cpu++)
+	for (cpu = 0; cpu < nr_cpumask_bits; cpu++)
 		if (cpumask_test_cpu(cpu, &cobalt_cpu_affinity))
 			val |= (1UL << cpu);
 
@@ -1395,7 +1395,7 @@ static ssize_t affinity_vfile_store(struct xnvfile_input *input)
 		affinity = xnsched_realtime_cpus; /* Reset to default. */
 	else {
 		cpumask_clear(&affinity);
-		for (cpu = 0; cpu < BITS_PER_LONG; cpu++, val >>= 1) {
+		for (cpu = 0; cpu < nr_cpumask_bits; cpu++, val >>= 1) {
 			if (val & 1) {
 				/*
 				 * The new dynamic affinity must be a strict
Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux