linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] x86: io-apic - convert DO_ACTION macro into function
@ 2008-09-07 19:26 Cyrill Gorcunov
  2008-09-08 14:33 ` Ingo Molnar
  0 siblings, 1 reply; 3+ messages in thread
From: Cyrill Gorcunov @ 2008-09-07 19:26 UTC (permalink / raw)
  To: Ingo Molnar, Maciej W. Rozycki; +Cc: H. Peter Anvin, LKML, Thomas Gleixner

Convert DO_ACTION macro into more obvious io_apic_modify_irq
function with callers
---

 I found it more readable then original was. Especialy we could grep
the callers in normal way. It's just an attempt - free to drop this
patch. I hope I don't messed with all these masks :) So the question
is rather NOT about details but idea in general.

 io_apic.c |  102 ++++++++++++++++++++++++++++++--------------------------------
 1 file changed, 50 insertions(+), 52 deletions(-)

Index: linux-2.6.git/arch/x86/kernel/io_apic.c
===================================================================
--- linux-2.6.git.orig/arch/x86/kernel/io_apic.c	2008-09-07 22:18:55.000000000 +0400
+++ linux-2.6.git/arch/x86/kernel/io_apic.c	2008-09-07 23:17:31.000000000 +0400
@@ -641,65 +641,63 @@ static void __init replace_pin_at_irq(un
 		add_pin_to_irq(irq, newapic, newpin);
 }
 
-#define __DO_ACTION(R, ACTION_ENABLE, ACTION_DISABLE, FINAL)		\
-									\
-{									\
-	int pin;							\
-	struct irq_cfg *cfg;						\
-	struct irq_pin_list *entry;					\
-									\
-	cfg = irq_cfg(irq);						\
-	entry = cfg->irq_2_pin;						\
-	for (;;) {							\
-		unsigned int reg;					\
-		if (!entry)						\
-			break;						\
-		pin = entry->pin;					\
-		reg = io_apic_read(entry->apic, 0x10 + R + pin*2);	\
-		reg ACTION_DISABLE;					\
-		reg ACTION_ENABLE;					\
-		io_apic_modify(entry->apic, 0x10 + R + pin*2, reg);	\
-		FINAL;							\
-		if (!entry->next)					\
-			break;						\
-		entry = entry->next;					\
-	}								\
-}
-
-#define DO_ACTION(name,R, ACTION_ENABLE, ACTION_DISABLE, FINAL)		\
-									\
-	static void name##_IO_APIC_irq (unsigned int irq)		\
-	__DO_ACTION(R, ACTION_ENABLE, ACTION_DISABLE, FINAL)
+/* modify chained irqs */
+static void io_apic_modify_irq(unsigned int irq, int io_reg,
+				int mask_and, int mask_or,
+				int mask_and_not, int read_after_mod)
+{
+	int pin;
+	struct irq_cfg *cfg;
+	struct irq_pin_list *entry;
 
-/* mask = 0 */
-DO_ACTION(__unmask,	0, |= 0, &= ~IO_APIC_REDIR_MASKED, )
+	cfg = irq_cfg(irq);
+	for (entry = cfg->irq_2_pin; entry != NULL; entry = entry->next) {
+		unsigned int reg;
+		pin = entry->pin;
+		reg = io_apic_read(entry->apic, 0x10 + io_reg + pin * 2);
+		if (mask_and)
+			reg &= mask_and;
+		if (mask_or)
+			reg |= mask_or;
+		if (mask_and_not)
+			reg &= !mask_and_not;
+		io_apic_modify(entry->apic, 0x10 + io_reg + pin * 2, reg);
+		if (read_after_mod) {
+			/* dummy read to sync IO-APIC and CPU */
+			struct io_apic __iomem *p = io_apic_base(entry->apic);
+			readl(&p->data);
+		}
+	}
+}
 
-#ifdef CONFIG_X86_64
-/*
- * Synchronize the IO-APIC and the CPU by doing
- * a dummy read from the IO-APIC
- */
-static inline void io_apic_sync(unsigned int apic)
+static void __unmask_IO_APIC_irq(unsigned int irq)
 {
-	struct io_apic __iomem *io_apic = io_apic_base(apic);
-	readl(&io_apic->data);
+	io_apic_modify_irq(irq, 0, ~IO_APIC_REDIR_MASKED, 0, 0, 0);
 }
 
-/* mask = 1 */
-DO_ACTION(__mask,	0, |= IO_APIC_REDIR_MASKED, &= ~0, io_apic_sync(entry->apic))
-
-#else
-
-/* mask = 1 */
-DO_ACTION(__mask,	0, |= IO_APIC_REDIR_MASKED, &= ~0, )
-
-/* mask = 1, trigger = 0 */
-DO_ACTION(__mask_and_edge, 0, |= IO_APIC_REDIR_MASKED, &= ~IO_APIC_REDIR_LEVEL_TRIGGER, )
+#ifdef CONFIG_X86_64
+static void __mask_IO_APIC_irq(unsigned int irq)
+{
+	io_apic_modify_irq(irq, 0, ~0, IO_APIC_REDIR_MASKED, 0, 1);
+}
+#else /* CONFIG_X86_32 */
+static void __mask_IO_APIC_irq(unsigned int irq)
+{
+	io_apic_modify_irq(irq, 0, ~0, IO_APIC_REDIR_MASKED, 0, 0);
+}
 
-/* mask = 0, trigger = 1 */
-DO_ACTION(__unmask_and_level, 0, |= IO_APIC_REDIR_LEVEL_TRIGGER, &= ~IO_APIC_REDIR_MASKED, )
+static void __mask_and_edge_IO_APIC_irq(unsigned int irq)
+{
+	io_apic_modify_irq(irq, 0, ~IO_APIC_REDIR_LEVEL_TRIGGER,
+			IO_APIC_REDIR_MASKED, 0, 0);
+}
 
-#endif
+static void __unmask_and_level_IO_APIC_irq(unsigned int irq)
+{
+	io_apic_modify_irq(irq, 0, ~IO_APIC_REDIR_MASKED,
+			IO_APIC_REDIR_LEVEL_TRIGGER, 0, 0);
+}
+#endif /* CONFIG_X86_32 */
 
 static void mask_IO_APIC_irq (unsigned int irq)
 {

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC] x86: io-apic - convert DO_ACTION macro into function
  2008-09-07 19:26 [RFC] x86: io-apic - convert DO_ACTION macro into function Cyrill Gorcunov
@ 2008-09-08 14:33 ` Ingo Molnar
  2008-09-08 14:42   ` Cyrill Gorcunov
  0 siblings, 1 reply; 3+ messages in thread
From: Ingo Molnar @ 2008-09-08 14:33 UTC (permalink / raw)
  To: Cyrill Gorcunov; +Cc: Maciej W. Rozycki, H. Peter Anvin, LKML, Thomas Gleixner


* Cyrill Gorcunov <gorcunov@gmail.com> wrote:

> Convert DO_ACTION macro into more obvious io_apic_modify_irq
> function with callers
> ---
> 
>  I found it more readable then original was. Especialy we could grep 
> the callers in normal way. It's just an attempt - free to drop this 
> patch. I hope I don't messed with all these masks :) So the question 
> is rather NOT about details but idea in general.

yeah - getting rid of such macros is a very good idea in general.

>  io_apic.c |  102 ++++++++++++++++++++++++++++++--------------------------------
>  1 file changed, 50 insertions(+), 52 deletions(-)

that's non-trivial impact. Did the .o md5sum survive this transformation 
just fine? (in theory gcc should generate the same code - but it doesnt 
always do that across macro->inline function changes, so it's hard to 
validate these kinds of changes.)

	Ingo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC] x86: io-apic - convert DO_ACTION macro into function
  2008-09-08 14:33 ` Ingo Molnar
@ 2008-09-08 14:42   ` Cyrill Gorcunov
  0 siblings, 0 replies; 3+ messages in thread
From: Cyrill Gorcunov @ 2008-09-08 14:42 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Maciej W. Rozycki, H. Peter Anvin, LKML, Thomas Gleixner

[Ingo Molnar - Mon, Sep 08, 2008 at 04:33:35PM +0200]
| 
| * Cyrill Gorcunov <gorcunov@gmail.com> wrote:
| 
| > Convert DO_ACTION macro into more obvious io_apic_modify_irq
| > function with callers
| > ---
| > 
| >  I found it more readable then original was. Especialy we could grep 
| > the callers in normal way. It's just an attempt - free to drop this 
| > patch. I hope I don't messed with all these masks :) So the question 
| > is rather NOT about details but idea in general.
| 
| yeah - getting rid of such macros is a very good idea in general.
| 
| >  io_apic.c |  102 ++++++++++++++++++++++++++++++--------------------------------
| >  1 file changed, 50 insertions(+), 52 deletions(-)
| 
| that's non-trivial impact. Did the .o md5sum survive this transformation 
| just fine? (in theory gcc should generate the same code - but it doesnt 
| always do that across macro->inline function changes, so it's hard to 
| validate these kinds of changes.)
| 
| 	Ingo
| 

ok, then I continue to work on this. I think I better check assembly code
to remain the same (in general since for example new for(;;) form is
completely different - in old code is inspired by the macroses who
could change 'entry' variable in theory - but now it will not be possible
and not needed so we could use more 'eye-candy' for(;;) form). Thanks
for comments.

		- Cyrill -

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-09-08 14:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-07 19:26 [RFC] x86: io-apic - convert DO_ACTION macro into function Cyrill Gorcunov
2008-09-08 14:33 ` Ingo Molnar
2008-09-08 14:42   ` Cyrill Gorcunov

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).