Skip to contentSkip to conversation

x86/ipipe: restore warning with AMD erratum

PATCH Jan Kiszka 2 participants 10 messages Jan 11, 2013 – Jan 13, 2013

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw
Quoted 25 lines

From acc3c57390d275a1b28d66f1ec88c85e0f8c0890 Mon Sep 17 00:00:00 2001
From: Gilles Chanteperdrix <[email protected]>
Date: Sat, 29 Dec 2012 17:48:20 +0100
Subject: [PATCH] x86/ipipe: restore warning with AMD erratum

---
 arch/x86/kernel/apic/apic.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
arch/x86/kernel/apic/apic.c +2 -4
index 7f07610..91531bb 100644
@@ -545,14 +545,18 @@ static void __cpuinit setup_APIC_timer(void)
 	memcpy(levt, &lapic_clockevent, sizeof(*levt));
 	levt->cpumask = cpumask_of(smp_processor_id());
 #ifdef CONFIG_IPIPE
-	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY))
+	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY)
+	    && !cpu_has_amd_erratum(amd_erratum_400))
 		levt->ipipe_timer = &__get_cpu_var(lapic_itimer);
 	else {
-	       printk(KERN_INFO
-		      "I-pipe: cannot use LAPIC as a tick device\n");
-	       if (cpu_has_amd_erratum(amd_erratum_400))

arch/x86/kernel/apic/apic.c static void __cpuinit setup_APIC_timer(void) · line 559

Quoted 10 lines
arch/x86/kernel/apic/apic.c +8 -2
-		       printk(KERN_INFO
-			      "I-pipe: disable C1E power state in your BIOS\n");
+		static atomic_t printed = ATOMIC_INIT(-1);
+		printk(KERN_INFO
+		       "I-pipe: cannot use LAPIC on cpu #%d as a tick device\n",
+		       smp_processor_id());
+		if (cpu_has_amd_erratum(amd_erratum_400)
+		    && atomic_inc_and_test(&printed))
+			printk(KERN_INFO
+			       "I-pipe: disable C1E power state in your BIOS\n");

printk_once should do the trick as well.

Quoted 5 lines
arch/x86/kernel/apic/apic.c +0 -0
 	}
 #endif /* CONFIG_IPIPE */
 
Signature · 1 line
1.7.3.4

I can also carry an updated version in my queue if you like. Did you already request a merge of your queue? Then I would rebase mine on top these days.

Jan

PS: ipipe-jki.git works now, thanks again.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20130111/6d1ee428/attachment.pgp>

author
#1 lore raw
Quoted 29 lines · Jan Kiszka
Quoted 29 lines

From acc3c57390d275a1b28d66f1ec88c85e0f8c0890 Mon Sep 17 00:00:00 2001
From: Gilles Chanteperdrix <[email protected]>
Date: Sat, 29 Dec 2012 17:48:20 +0100
Subject: [PATCH] x86/ipipe: restore warning with AMD erratum

---
 arch/x86/kernel/apic/apic.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
arch/x86/kernel/apic/apic.c +4 -6
index 7f07610..91531bb 100644
@@ -545,14 +545,18 @@ static void __cpuinit setup_APIC_timer(void)
 	memcpy(levt, &lapic_clockevent, sizeof(*levt));
 	levt->cpumask = cpumask_of(smp_processor_id());
 #ifdef CONFIG_IPIPE
-	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY))
+	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY)
+	    && !cpu_has_amd_erratum(amd_erratum_400))
 		levt->ipipe_timer = &__get_cpu_var(lapic_itimer);
 	else {
-	       printk(KERN_INFO
-		      "I-pipe: cannot use LAPIC as a tick device\n");
-	       if (cpu_has_amd_erratum(amd_erratum_400))
-		       printk(KERN_INFO
-			      "I-pipe: disable C1E power state in your BIOS\n");
+		static atomic_t printed = ATOMIC_INIT(-1);
+		printk(KERN_INFO
Quoted 8 lines

arch/x86/kernel/apic/apic.c static void __cpuinit setup_APIC_timer(void) · line 559

Quoted 6 lines
arch/x86/kernel/apic/apic.c +6 -0
+		       "I-pipe: cannot use LAPIC on cpu #%d as a tick device\n",
+		       smp_processor_id());
+		if (cpu_has_amd_erratum(amd_erratum_400)
+		    && atomic_inc_and_test(&printed))
+			printk(KERN_INFO
+			       "I-pipe: disable C1E power state in your BIOS\n");

printk_once should do the trick as well.

In fact, it should actually do what you likely intended: print on first occurrence, not on second or later. ;)

Jan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20130111/0c53e5cc/attachment.pgp>

#2 lore raw
Quoted 39 lines · Jan Kiszka
Quoted 29 lines · Jan Kiszka
Quoted 29 lines

From acc3c57390d275a1b28d66f1ec88c85e0f8c0890 Mon Sep 17 00:00:00 2001
From: Gilles Chanteperdrix <[email protected]>
Date: Sat, 29 Dec 2012 17:48:20 +0100
Subject: [PATCH] x86/ipipe: restore warning with AMD erratum

---
 arch/x86/kernel/apic/apic.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
arch/x86/kernel/apic/apic.c +4 -6
index 7f07610..91531bb 100644
@@ -545,14 +545,18 @@ static void __cpuinit setup_APIC_timer(void)
 	memcpy(levt, &lapic_clockevent, sizeof(*levt));
 	levt->cpumask = cpumask_of(smp_processor_id());
 #ifdef CONFIG_IPIPE
-	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY))
+	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY)
+	    && !cpu_has_amd_erratum(amd_erratum_400))
 		levt->ipipe_timer = &__get_cpu_var(lapic_itimer);
 	else {
-	       printk(KERN_INFO
-		      "I-pipe: cannot use LAPIC as a tick device\n");
-	       if (cpu_has_amd_erratum(amd_erratum_400))
-		       printk(KERN_INFO
-			      "I-pipe: disable C1E power state in your BIOS\n");
+		static atomic_t printed = ATOMIC_INIT(-1);
+		printk(KERN_INFO
Quoted 8 lines

arch/x86/kernel/apic/apic.c static void __cpuinit setup_APIC_timer(void) · line 559

Quoted 6 lines
arch/x86/kernel/apic/apic.c +6 -0
+		       "I-pipe: cannot use LAPIC on cpu #%d as a tick device\n",
+		       smp_processor_id());
+		if (cpu_has_amd_erratum(amd_erratum_400)
+		    && atomic_inc_and_test(&printed))
+			printk(KERN_INFO
+			       "I-pipe: disable C1E power state in your BIOS\n");

printk_once should do the trick as well.

Quoted 2 lines

In fact, it should actually do what you likely intended: print on first occurrence, not on second or later. ;)

printed is initialized at -1, so, the printk happens on first occurence, but yes printk_once is good, and we can use printk_once for the first printk too, these two tests (feat_dummy and amd_erratum_400) will be true for all cpus, so, printing the message for all cpus has no added value.

Quoted 3 lines

Jan

Signature · 1 line
                                                                Gilles.
author
#3 lore raw
Quoted 41 lines · Gilles Chanteperdrix
Quoted 39 lines · Jan Kiszka
Quoted 37 lines · Jan Kiszka
Quoted 25 lines

From acc3c57390d275a1b28d66f1ec88c85e0f8c0890 Mon Sep 17 00:00:00 2001
From: Gilles Chanteperdrix <[email protected]>
Date: Sat, 29 Dec 2012 17:48:20 +0100
Subject: [PATCH] x86/ipipe: restore warning with AMD erratum

---
 arch/x86/kernel/apic/apic.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
arch/x86/kernel/apic/apic.c +2 -4
index 7f07610..91531bb 100644
@@ -545,14 +545,18 @@ static void __cpuinit setup_APIC_timer(void)
 	memcpy(levt, &lapic_clockevent, sizeof(*levt));
 	levt->cpumask = cpumask_of(smp_processor_id());
 #ifdef CONFIG_IPIPE
-	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY))
+	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY)
+	    && !cpu_has_amd_erratum(amd_erratum_400))
 		levt->ipipe_timer = &__get_cpu_var(lapic_itimer);
 	else {
-	       printk(KERN_INFO
-		      "I-pipe: cannot use LAPIC as a tick device\n");
-	       if (cpu_has_amd_erratum(amd_erratum_400))

arch/x86/kernel/apic/apic.c static void __cpuinit setup_APIC_timer(void) · line 559

Quoted 10 lines
arch/x86/kernel/apic/apic.c +8 -2
-		       printk(KERN_INFO
-			      "I-pipe: disable C1E power state in your BIOS\n");
+		static atomic_t printed = ATOMIC_INIT(-1);
+		printk(KERN_INFO
+		       "I-pipe: cannot use LAPIC on cpu #%d as a tick device\n",
+		       smp_processor_id());
+		if (cpu_has_amd_erratum(amd_erratum_400)
+		    && atomic_inc_and_test(&printed))
+			printk(KERN_INFO
+			       "I-pipe: disable C1E power state in your BIOS\n");

printk_once should do the trick as well.

Quoted 5 lines
Quoted 2 lines

In fact, it should actually do what you likely intended: print on first occurrence, not on second or later. ;)

printed is initialized at -1, so, the printk happens on first occurence,

inc_and_test increments first and then returns the result.

Quoted 3 lines

but yes printk_once is good, and we can use printk_once for the first printk too, these two tests (feat_dummy and amd_erratum_400) will be true for all cpus, so, printing the message for all cpus has no added value.

Perfect.

Jan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20130111/320ba77b/attachment.pgp>

#4 lore raw
Quoted 42 lines · Jan Kiszka
Quoted 41 lines · Gilles Chanteperdrix
Quoted 39 lines · Jan Kiszka
Quoted 37 lines · Jan Kiszka
Quoted 25 lines

From acc3c57390d275a1b28d66f1ec88c85e0f8c0890 Mon Sep 17 00:00:00 2001
From: Gilles Chanteperdrix <[email protected]>
Date: Sat, 29 Dec 2012 17:48:20 +0100
Subject: [PATCH] x86/ipipe: restore warning with AMD erratum

---
 arch/x86/kernel/apic/apic.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
arch/x86/kernel/apic/apic.c +2 -4
index 7f07610..91531bb 100644
@@ -545,14 +545,18 @@ static void __cpuinit setup_APIC_timer(void)
 	memcpy(levt, &lapic_clockevent, sizeof(*levt));
 	levt->cpumask = cpumask_of(smp_processor_id());
 #ifdef CONFIG_IPIPE
-	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY))
+	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY)
+	    && !cpu_has_amd_erratum(amd_erratum_400))
 		levt->ipipe_timer = &__get_cpu_var(lapic_itimer);
 	else {
-	       printk(KERN_INFO
-		      "I-pipe: cannot use LAPIC as a tick device\n");
-	       if (cpu_has_amd_erratum(amd_erratum_400))

arch/x86/kernel/apic/apic.c static void __cpuinit setup_APIC_timer(void) · line 559

Quoted 10 lines
arch/x86/kernel/apic/apic.c +8 -2
-		       printk(KERN_INFO
-			      "I-pipe: disable C1E power state in your BIOS\n");
+		static atomic_t printed = ATOMIC_INIT(-1);
+		printk(KERN_INFO
+		       "I-pipe: cannot use LAPIC on cpu #%d as a tick device\n",
+		       smp_processor_id());
+		if (cpu_has_amd_erratum(amd_erratum_400)
+		    && atomic_inc_and_test(&printed))
+			printk(KERN_INFO
+			       "I-pipe: disable C1E power state in your BIOS\n");

printk_once should do the trick as well.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

In fact, it should actually do what you likely intended: print on first occurrence, not on second or later. ;)

printed is initialized at -1, so, the printk happens on first occurence,

inc_and_test increments first and then returns the result.

Yes, the other way around, the result used is the value before incrementation, so printed should be initialized to 0, right...

Signature · 1 line
                                                                Gilles.
#5 lore raw
In reply to Jan Kiszka
Quoted 39 lines · Jan Kiszka
Quoted 29 lines · Jan Kiszka
Quoted 29 lines

From acc3c57390d275a1b28d66f1ec88c85e0f8c0890 Mon Sep 17 00:00:00 2001
From: Gilles Chanteperdrix <[email protected]>
Date: Sat, 29 Dec 2012 17:48:20 +0100
Subject: [PATCH] x86/ipipe: restore warning with AMD erratum

---
 arch/x86/kernel/apic/apic.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
arch/x86/kernel/apic/apic.c +4 -6
index 7f07610..91531bb 100644
@@ -545,14 +545,18 @@ static void __cpuinit setup_APIC_timer(void)
 	memcpy(levt, &lapic_clockevent, sizeof(*levt));
 	levt->cpumask = cpumask_of(smp_processor_id());
 #ifdef CONFIG_IPIPE
-	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY))
+	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY)
+	    && !cpu_has_amd_erratum(amd_erratum_400))
 		levt->ipipe_timer = &__get_cpu_var(lapic_itimer);
 	else {
-	       printk(KERN_INFO
-		      "I-pipe: cannot use LAPIC as a tick device\n");
-	       if (cpu_has_amd_erratum(amd_erratum_400))
-		       printk(KERN_INFO
-			      "I-pipe: disable C1E power state in your BIOS\n");
+		static atomic_t printed = ATOMIC_INIT(-1);
+		printk(KERN_INFO
Quoted 8 lines

arch/x86/kernel/apic/apic.c static void __cpuinit setup_APIC_timer(void) · line 559

Quoted 6 lines
arch/x86/kernel/apic/apic.c +6 -0
+		       "I-pipe: cannot use LAPIC on cpu #%d as a tick device\n",
+		       smp_processor_id());
+		if (cpu_has_amd_erratum(amd_erratum_400)
+		    && atomic_inc_and_test(&printed))
+			printk(KERN_INFO
+			       "I-pipe: disable C1E power state in your BIOS\n");

printk_once should do the trick as well.

Quoted 2 lines

In fact, it should actually do what you likely intended: print on first occurrence, not on second or later. ;)

Not quite, printk_once is not protected from the code running concurrently on multiple cpus. So, atomic_inc_and_test is better, except the ATOMIC_INIT needs to be set to 0.

Quoted 3 lines

Jan

Signature · 1 line
                                                                Gilles.
author
#6 lore raw
Quoted 41 lines · Gilles Chanteperdrix
Quoted 39 lines · Jan Kiszka
Quoted 37 lines · Jan Kiszka
Quoted 25 lines

From acc3c57390d275a1b28d66f1ec88c85e0f8c0890 Mon Sep 17 00:00:00 2001
From: Gilles Chanteperdrix <[email protected]>
Date: Sat, 29 Dec 2012 17:48:20 +0100
Subject: [PATCH] x86/ipipe: restore warning with AMD erratum

---
 arch/x86/kernel/apic/apic.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
arch/x86/kernel/apic/apic.c +2 -4
index 7f07610..91531bb 100644
@@ -545,14 +545,18 @@ static void __cpuinit setup_APIC_timer(void)
 	memcpy(levt, &lapic_clockevent, sizeof(*levt));
 	levt->cpumask = cpumask_of(smp_processor_id());
 #ifdef CONFIG_IPIPE
-	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY))
+	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY)
+	    && !cpu_has_amd_erratum(amd_erratum_400))
 		levt->ipipe_timer = &__get_cpu_var(lapic_itimer);
 	else {
-	       printk(KERN_INFO
-		      "I-pipe: cannot use LAPIC as a tick device\n");
-	       if (cpu_has_amd_erratum(amd_erratum_400))

arch/x86/kernel/apic/apic.c static void __cpuinit setup_APIC_timer(void) · line 559

Quoted 10 lines
arch/x86/kernel/apic/apic.c +8 -2
-		       printk(KERN_INFO
-			      "I-pipe: disable C1E power state in your BIOS\n");
+		static atomic_t printed = ATOMIC_INIT(-1);
+		printk(KERN_INFO
+		       "I-pipe: cannot use LAPIC on cpu #%d as a tick device\n",
+		       smp_processor_id());
+		if (cpu_has_amd_erratum(amd_erratum_400)
+		    && atomic_inc_and_test(&printed))
+			printk(KERN_INFO
+			       "I-pipe: disable C1E power state in your BIOS\n");

printk_once should do the trick as well.

Quoted 6 lines
Quoted 2 lines

In fact, it should actually do what you likely intended: print on first occurrence, not on second or later. ;)

Not quite, printk_once is not protected from the code running concurrently on multiple cpus.

OK.

Quoted 2 lines

So, atomic_inc_and_test is better, except
the ATOMIC_INIT needs to be set to 0.

Nope, -1 is correct. atomic_inc_and_test first increments, then tests. I missed that it checks against 0, not != 0. So the logic is fine, you should just include the first printk as well.

Jan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20130112/9e2ee820/attachment.pgp>

#7 lore raw
Quoted 49 lines · Jan Kiszka
Quoted 41 lines · Gilles Chanteperdrix
Quoted 39 lines · Jan Kiszka
Quoted 37 lines · Jan Kiszka
Quoted 25 lines

From acc3c57390d275a1b28d66f1ec88c85e0f8c0890 Mon Sep 17 00:00:00 2001
From: Gilles Chanteperdrix <[email protected]>
Date: Sat, 29 Dec 2012 17:48:20 +0100
Subject: [PATCH] x86/ipipe: restore warning with AMD erratum

---
 arch/x86/kernel/apic/apic.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
arch/x86/kernel/apic/apic.c +2 -4
index 7f07610..91531bb 100644
@@ -545,14 +545,18 @@ static void __cpuinit setup_APIC_timer(void)
 	memcpy(levt, &lapic_clockevent, sizeof(*levt));
 	levt->cpumask = cpumask_of(smp_processor_id());
 #ifdef CONFIG_IPIPE
-	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY))
+	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY)
+	    && !cpu_has_amd_erratum(amd_erratum_400))
 		levt->ipipe_timer = &__get_cpu_var(lapic_itimer);
 	else {
-	       printk(KERN_INFO
-		      "I-pipe: cannot use LAPIC as a tick device\n");
-	       if (cpu_has_amd_erratum(amd_erratum_400))

arch/x86/kernel/apic/apic.c static void __cpuinit setup_APIC_timer(void) · line 559

Quoted 10 lines
arch/x86/kernel/apic/apic.c +8 -2
-		       printk(KERN_INFO
-			      "I-pipe: disable C1E power state in your BIOS\n");
+		static atomic_t printed = ATOMIC_INIT(-1);
+		printk(KERN_INFO
+		       "I-pipe: cannot use LAPIC on cpu #%d as a tick device\n",
+		       smp_processor_id());
+		if (cpu_has_amd_erratum(amd_erratum_400)
+		    && atomic_inc_and_test(&printed))
+			printk(KERN_INFO
+			       "I-pipe: disable C1E power state in your BIOS\n");

printk_once should do the trick as well.

Quoted 6 lines
Quoted 2 lines

In fact, it should actually do what you likely intended: print on first occurrence, not on second or later. ;)

Not quite, printk_once is not protected from the code running concurrently on multiple cpus.

Quoted 8 lines

OK.

Quoted 2 lines

So, atomic_inc_and_test is better, except
the ATOMIC_INIT needs to be set to 0.

Nope, -1 is correct. atomic_inc_and_test first increments, then tests. I missed that it checks against 0, not != 0. So the logic is fine, you should just include the first printk as well.

Yes, I have just realized that looking at the x86 version of atomic_inc_and_test, only the asm-generic version is broken, but I guess nobody uses it:

static inline int atomic_add_return(int i, atomic_t *v)

{
	unsigned long flags;
	int temp;

	flags = hard_local_irq_save(); /* Don't trace it in an irqsoff handler */
	temp = v->counter;
	temp += i;
	v->counter = temp;
	hard_local_irq_restore(flags);

	return temp;
}

#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)

Signature · 1 line
                                                                Gilles.
author
#8 lore raw
Quoted 79 lines · Gilles Chanteperdrix
Quoted 49 lines · Jan Kiszka
Quoted 41 lines · Gilles Chanteperdrix
Quoted 39 lines · Jan Kiszka
Quoted 37 lines · Jan Kiszka
Quoted 25 lines

From acc3c57390d275a1b28d66f1ec88c85e0f8c0890 Mon Sep 17 00:00:00 2001
From: Gilles Chanteperdrix <[email protected]>
Date: Sat, 29 Dec 2012 17:48:20 +0100
Subject: [PATCH] x86/ipipe: restore warning with AMD erratum

---
 arch/x86/kernel/apic/apic.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
arch/x86/kernel/apic/apic.c +2 -4
index 7f07610..91531bb 100644
@@ -545,14 +545,18 @@ static void __cpuinit setup_APIC_timer(void)
 	memcpy(levt, &lapic_clockevent, sizeof(*levt));
 	levt->cpumask = cpumask_of(smp_processor_id());
 #ifdef CONFIG_IPIPE
-	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY))
+	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY)
+	    && !cpu_has_amd_erratum(amd_erratum_400))
 		levt->ipipe_timer = &__get_cpu_var(lapic_itimer);
 	else {
-	       printk(KERN_INFO
-		      "I-pipe: cannot use LAPIC as a tick device\n");
-	       if (cpu_has_amd_erratum(amd_erratum_400))

arch/x86/kernel/apic/apic.c static void __cpuinit setup_APIC_timer(void) · line 559

Quoted 10 lines
arch/x86/kernel/apic/apic.c +8 -2
-		       printk(KERN_INFO
-			      "I-pipe: disable C1E power state in your BIOS\n");
+		static atomic_t printed = ATOMIC_INIT(-1);
+		printk(KERN_INFO
+		       "I-pipe: cannot use LAPIC on cpu #%d as a tick device\n",
+		       smp_processor_id());
+		if (cpu_has_amd_erratum(amd_erratum_400)
+		    && atomic_inc_and_test(&printed))
+			printk(KERN_INFO
+			       "I-pipe: disable C1E power state in your BIOS\n");

printk_once should do the trick as well.

Quoted 6 lines
Quoted 2 lines

In fact, it should actually do what you likely intended: print on first occurrence, not on second or later. ;)

Not quite, printk_once is not protected from the code running concurrently on multiple cpus.

Quoted 8 lines

OK.

Quoted 2 lines

So, atomic_inc_and_test is better, except
the ATOMIC_INIT needs to be set to 0.

Nope, -1 is correct. atomic_inc_and_test first increments, then tests. I missed that it checks against 0, not != 0. So the logic is fine, you should just include the first printk as well.

Yes, I have just realized that looking at the x86 version of atomic_inc_and_test, only the asm-generic version is broken, but I guess nobody uses it:

static inline int atomic_add_return(int i, atomic_t *v)

{
	unsigned long flags;
	int temp;

	flags = hard_local_irq_save(); /* Don't trace it in an irqsoff handler */
	temp = v->counter;
	temp += i;
	v->counter = temp;
	hard_local_irq_restore(flags);

	return temp;
}
Quoted 2 lines

#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)

Are you referring to lacking SMP support of this version? I guess that's intentional (no SMP arch should lack atomic ops).

It is otherwise functionally identical to the x86 code, i.e. it *first* increments and *then* tests. Your new version of this patch will therefore never print anything due to the 0 initialization - well, until the counter overflows. Probably it's better to use test_and_set_bit here to avoid all these confusions.

Jan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20130113/09252461/attachment.pgp>

#9 lore raw
Quoted 83 lines · Jan Kiszka
Quoted 79 lines · Gilles Chanteperdrix
Quoted 49 lines · Jan Kiszka
Quoted 41 lines · Gilles Chanteperdrix
Quoted 39 lines · Jan Kiszka
Quoted 37 lines · Jan Kiszka
Quoted 25 lines

From acc3c57390d275a1b28d66f1ec88c85e0f8c0890 Mon Sep 17 00:00:00 2001
From: Gilles Chanteperdrix <[email protected]>
Date: Sat, 29 Dec 2012 17:48:20 +0100
Subject: [PATCH] x86/ipipe: restore warning with AMD erratum

---
 arch/x86/kernel/apic/apic.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
arch/x86/kernel/apic/apic.c +2 -4
index 7f07610..91531bb 100644
@@ -545,14 +545,18 @@ static void __cpuinit setup_APIC_timer(void)
 	memcpy(levt, &lapic_clockevent, sizeof(*levt));
 	levt->cpumask = cpumask_of(smp_processor_id());
 #ifdef CONFIG_IPIPE
-	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY))
+	if (!(lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY)
+	    && !cpu_has_amd_erratum(amd_erratum_400))
 		levt->ipipe_timer = &__get_cpu_var(lapic_itimer);
 	else {
-	       printk(KERN_INFO
-		      "I-pipe: cannot use LAPIC as a tick device\n");
-	       if (cpu_has_amd_erratum(amd_erratum_400))

arch/x86/kernel/apic/apic.c static void __cpuinit setup_APIC_timer(void) · line 559

Quoted 10 lines
arch/x86/kernel/apic/apic.c +8 -2
-		       printk(KERN_INFO
-			      "I-pipe: disable C1E power state in your BIOS\n");
+		static atomic_t printed = ATOMIC_INIT(-1);
+		printk(KERN_INFO
+		       "I-pipe: cannot use LAPIC on cpu #%d as a tick device\n",
+		       smp_processor_id());
+		if (cpu_has_amd_erratum(amd_erratum_400)
+		    && atomic_inc_and_test(&printed))
+			printk(KERN_INFO
+			       "I-pipe: disable C1E power state in your BIOS\n");

printk_once should do the trick as well.

Quoted 6 lines
Quoted 2 lines

In fact, it should actually do what you likely intended: print on first occurrence, not on second or later. ;)

Not quite, printk_once is not protected from the code running concurrently on multiple cpus.

Quoted 8 lines

OK.

Quoted 2 lines

So, atomic_inc_and_test is better, except
the ATOMIC_INIT needs to be set to 0.

Nope, -1 is correct. atomic_inc_and_test first increments, then tests. I missed that it checks against 0, not != 0. So the logic is fine, you should just include the first printk as well.

Yes, I have just realized that looking at the x86 version of atomic_inc_and_test, only the asm-generic version is broken, but I guess nobody uses it:

static inline int atomic_add_return(int i, atomic_t *v)

{
	unsigned long flags;
	int temp;

	flags = hard_local_irq_save(); /* Don't trace it in an irqsoff handler */
	temp = v->counter;
	temp += i;
	v->counter = temp;
	hard_local_irq_restore(flags);

	return temp;
}
Quoted 2 lines

#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)

Quoted 8 lines

Are you referring to lacking SMP support of this version? I guess that's intentional (no SMP arch should lack atomic ops).

It is otherwise functionally identical to the x86 code, i.e. it *first* increments and *then* tests. Your new version of this patch will therefore never print anything due to the 0 initialization - well, until the counter overflows. Probably it's better to use test_and_set_bit here to avoid all these confusions.

Sorry, fixed, thanks.

Signature · 1 line
                                                                Gilles.