Skip to contentSkip to conversation

EPOLL Interrupt Controller V2.0

PATCH Superseded Anton Ivanov 5 participants 14 messages Nov 9, 2015 – Nov 18, 2015 User-mode Linux (UML)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 EPOLL Interrupt Controller V2.0

Epoll based interrupt controller.

IMPROVES: IO loop performance - no per fd lookups, allowing for 15% IO speedup in minimal config going to 100s of % with many devices - a N^N lookup is now replaced by a log(N)

ADDS: True Write IRQ functionality

OBSOLETES: The need to call reactivate_fd() in any driver which has only read IRQ semantics. Write IRQs work, but will need to be updated to use this fully.

Potentially (with a change in API) will allow both edge and level IRQ semantics.

Pre-requisite for using packet mmap and multipacket read/write which do not get along with poll() very well.

---
 arch/um/drivers/line.c            |   5 +-
 arch/um/drivers/mconsole_kern.c   |   2 -
 arch/um/drivers/net_kern.c        |   1 -
 arch/um/drivers/port_kern.c       |   1 -
 arch/um/drivers/random.c          |   1 -
 arch/um/drivers/ubd_kern.c        |   1 -
 arch/um/include/shared/irq_user.h |  24 ++-
 arch/um/include/shared/os.h       |  14 +-
 arch/um/kernel/irq.c              | 412 ++++++++++++++++++++++----------------
 arch/um/os-Linux/irq.c            | 150 ++++++--------
 10 files changed, 329 insertions(+), 282 deletions(-)
arch/um/drivers/line.c +2 -3
index 6208702..84384c8 100644
@@ -1,4 +1,5 @@
 /*
+ * Copyright (C) 2012 - 2014 Cisco Systems
  * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
@@ -283,7 +284,7 @@ int line_setup_irq(int fd, int input, int output, struct line *line, void *data)
 	if (err)
 		return err;
 	if (output)
-		err = um_request_irq(driver->write_irq, fd, IRQ_WRITE,
+		err = um_request_irq(driver->write_irq, fd, IRQ_NONE,
 				     line_write_interrupt, IRQF_SHARED,
 				     driver->write_irq_name, data);
 	return err;
@@ -666,8 +667,6 @@ static irqreturn_t winch_interrupt(int irq, void *data)
 		tty_kref_put(tty);
 	}
  out:
-	if (winch->fd != -1)
-		reactivate_fd(winch->fd, WINCH_IRQ);
 	return IRQ_HANDLED;
 }
 
arch/um/drivers/mconsole_kern.c +0 -2
index 29880c9..5e8881c 100644
@@ -95,7 +95,6 @@ static irqreturn_t mconsole_interrupt(int irq, void *dev_id)
 	}
 	if (!list_empty(&mc_requests))
 		schedule_work(&mconsole_work);
-	reactivate_fd(fd, MCONSOLE_IRQ);
 	return IRQ_HANDLED;
 }
 
@@ -243,7 +242,6 @@ void mconsole_stop(struct mc_request *req)
 		(*req->cmd->handler)(req);
 	}
 	os_set_fd_block(req->originating_fd, 0);
-	reactivate_fd(req->originating_fd, MCONSOLE_IRQ);
 	mconsole_reply(req, "", 0, 0);
 }
 
arch/um/drivers/net_kern.c +0 -1
index f70dd54..82ea3a2 100644
@@ -137,7 +137,6 @@ static irqreturn_t uml_net_interrupt(int irq, void *dev_id)
 		schedule_work(&lp->work);
 		goto out;
 	}
-	reactivate_fd(lp->fd, UM_ETH_IRQ);
 
 out:
 	spin_unlock(&lp->lock);
arch/um/drivers/port_kern.c +0 -1
index 40ca5cc..b0e9ff3 100644
@@ -137,7 +137,6 @@ static void port_work_proc(struct work_struct *unused)
 		if (!port->has_connection)
 			continue;
 
-		reactivate_fd(port->fd, ACCEPT_IRQ);
 		while (port_accept(port))
 			;
 		port->has_connection = 0;
arch/um/drivers/random.c +0 -1
index dd16c90..a392828 100644
@@ -72,7 +72,6 @@ static ssize_t rng_dev_read (struct file *filp, char __user *buf, size_t size,
 				return ret ? : -EAGAIN;
 
 			atomic_inc(&host_sleep_count);
-			reactivate_fd(random_fd, RANDOM_IRQ);
 			add_sigio_fd(random_fd);
 
 			add_wait_queue(&host_read_wait, &wait);
arch/um/drivers/ubd_kern.c +0 -1
index e8ab93c..731982c 100644
@@ -466,7 +466,6 @@ static void ubd_handler(void)
 		blk_end_request(req->req, 0, req->length);
 		kfree(req);
 	}
-	reactivate_fd(thread_fd, UBD_IRQ);
 
 	list_for_each_safe(list, next_ele, &restart){
 		ubd = container_of(list, struct ubd, restart);
arch/um/include/shared/irq_user.h +16 -8
index df56330..0eca64c 100644
@@ -1,4 +1,5 @@
 /*
+ * Copyright (C) 2012 - 2014 Cisco Systems
  * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
@@ -9,16 +10,23 @@
 #include <sysdep/ptrace.h>
 
 struct irq_fd {
-	struct irq_fd *next;
-	void *id;
-	int fd;
-	int type;
-	int irq;
-	int events;
-	int current_events;
+        void *id;
+        int irq;
+        int events;
+};
+
+
+#define IRQ_READ  0
+#define IRQ_WRITE 1 
+#define IRQ_NONE 2
+#define MAX_IRQ_TYPE (IRQ_NONE + 1)
+
+struct irq_entry {
+        struct irq_entry *next;
+        int fd;
+	struct irq_fd * irq_array[MAX_IRQ_TYPE + 1];
 };
 
-enum { IRQ_READ, IRQ_WRITE };
 
 struct siginfo;
 extern void sigio_handler(int sig, struct siginfo *unused_si, struct uml_pt_regs *regs);
arch/um/include/shared/os.h +9 -5
index 21d704b..c449839 100644
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015 Anton Ivanov (aivanov@{brocade.com,kot-begemot.co.uk})
+ * Copyright (C) 2012 - 2014 Cisco Systems
  * Copyright (C) 2015 Thomas Meyer ([email protected])
  * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
@@ -284,15 +285,18 @@ extern void halt_skas(void);
 extern void reboot_skas(void);
 
 /* irq.c */
-extern int os_waiting_for_events(struct irq_fd *active_fds);
-extern int os_create_pollfd(int fd, int events, void *tmp_pfd, int size_tmpfds);
+
+extern int os_setup_epoll(int maxevents);
+extern int os_waiting_for_events_epoll(void *kernel_events, int maxevents);
+extern int os_add_epoll_fd (int events, int fd, void * data);
+extern int os_mod_epoll_fd (int events, int fd, void * data);
+extern int os_del_epoll_fd (int fd);
+
 extern void os_free_irq_by_cb(int (*test)(struct irq_fd *, void *), void *arg,
 		struct irq_fd *active_fds, struct irq_fd ***last_irq_ptr2);
 extern void os_free_irq_later(struct irq_fd *active_fds,
 		int irq, void *dev_id);
-extern int os_get_pollfd(int i);
-extern void os_set_pollfd(int i, int fd);
-extern void os_set_ioignore(void);
+extern void os_close_epoll(void);
 
 /* sigio.c */
 extern int add_sigio_fd(int fd);
arch/um/kernel/irq.c +242 -170

532 lines not on this page · raw message

arch/um/os-Linux/irq.c +60 -90

190 lines not on this page · raw message

Signature · 13 lines
2.1.4


------------------------------------------------------------------------------
Presto, an open source distributed SQL query engine for big data, initially
developed by Facebook, enables you to easily query your data on Hadoop in a 
more interactive manner. Teradata is also now providing full enterprise
support for Presto. Download a free open source copy now.
http://pubads.g.doubleclick.net/gampad/clk?id=250295911&iu=/4140
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#1 lore raw

It throws a couple of harmless "epoll del fd" warnings on reboot which result the fact that disable_fd/enable_fd are not removed in the terminal/line code.

These are harmless and will go away once the term/line code gets support for real write IRQs in addition to read at some point in the future.

I have fixed the file descriptor leak in the reboot case.

A.

Quoted 12 lines · Anton Ivanov

Epoll based interrupt controller.

IMPROVES: IO loop performance - no per fd lookups, allowing for 15% IO speedup in minimal config going to 100s of % with many devices - a N^N lookup is now replaced by a log(N)

ADDS: True Write IRQ functionality

OBSOLETES: The need to call reactivate_fd() in any driver which has only read IRQ semantics. Write IRQs work, but will need to be updated to use this fully.

Quoted 7 lines

Potentially (with a change in API) will allow both edge and level IRQ semantics.

Pre-requisite for using packet mmap and multipacket read/write which do not get along with poll() very well.

------------------------------------------------------------------------------
Presto, an open source distributed SQL query engine for big data, initially developed by Facebook, enables you to easily query your data on Hadoop in a more interactive manner. Teradata is also now providing full enterprise support for Presto. Download a free open source copy now.
http://pubads.g.doubleclick.net/gampad/clk?id=250295911&iu=/4140
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#2 lore raw

Thomas Mayer found a couple of issues which crept up when porting v1 to the newer kernels.

It also crashes with his config - I am analyzing the differences between that and mine to find the culrpit.

Once I have fixed both I will resubmit v3. So for now this is just "subject for discussion", do not use yet.

A

Quoted 8 lines · Anton Ivanov

It throws a couple of harmless "epoll del fd" warnings on reboot which result the fact that disable_fd/enable_fd are not removed in the terminal/line code.

These are harmless and will go away once the term/line code gets support for real write IRQs in addition to read at some point in the future.

Quoted 25 lines

I have fixed the file descriptor leak in the reboot case.

A.

Quoted 19 lines · Anton Ivanov

Epoll based interrupt controller.

IMPROVES: IO loop performance - no per fd lookups, allowing for 15% IO speedup in minimal config going to 100s of % with many devices - a N^N lookup is now replaced by a log(N)

ADDS: True Write IRQ functionality

OBSOLETES: The need to call reactivate_fd() in any driver which has only read IRQ semantics. Write IRQs work, but will need to be updated to use this fully.

Potentially (with a change in API) will allow both edge and level IRQ semantics.

Pre-requisite for using packet mmap and multipacket read/write which do not get along with poll() very well.

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#3 lore raw
Quoted 8 lines · Anton Ivanov

Thomas Mayer found a couple of issues which crept up when porting v1 to the newer kernels.

It also crashes with his config - I am analyzing the differences between that and mine to find the culrpit.

Once I have fixed both I will resubmit v3. So for now this is just "subject for discussion", do not use yet.

There is no need to hurry. :-)
This is 4.5 material.

Signature · 8 lines
Thanks,
//richard

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#4 lore raw
In reply to Anton Ivanov

Am Montag, den 09.11.2015, 15:03 +0000 schrieb Anton Ivanov:

Quoted 10 lines

It throws a couple of harmless "epoll del fd" warnings on reboot which
result the fact that disable_fd/enable_fd are not removed in the terminal/line code.

These are harmless and will go away once the term/line code gets support
for real write IRQs in addition to read at some point in the future.

I have fixed the file descriptor leak in the reboot case.

Hi,

now with the list on copy!

Richard: can you make some sense out of these stack traces? I can provide the config if you want!

I see a lot of bugs of type "BUG: spinlock recursion on CPU#0" with this patch:

I did look over your patch and found two errors in the irq_lock spinlock handling:

http://m3y3r.dyndns.org:9100/gerrit/#/c/2/1..2/arch/um/kernel/irq.c

But it still seems to miss something as above bugs still occurs, but now the system boots up a bit more at least.

Example:
 [  225.570000] BUG: spinlock lockup suspected on CPU#0, chmod/516 [  225.570000]  lock: irq_lock+0x0/0x18, .magic: dead4ead, .owner:
 [  225.570000] CPU: 0 PID: 516 Comm: chmod Not tainted 4.3.0-00010- g96b3e9d #100
 [  225.570000] Stack:
 [  225.570000]  69323490 6008bbd2 00000000 6b0fd580
 [  225.570000]  6083c440 600d191a 693234a0 603b8701
 [  225.570000]  693234e0 60085773 00000000 00000000
 [  225.570000] Call Trace:
 [  225.570000]  [<600d191a>] ? printk+0x0/0x94
 [  225.570000]  [<60047cc0>] ? __delay+0x0/0x30
 [  225.570000]  [<6002d84b>] show_stack+0xdb/0x1a0
 [  225.570000]  [<6008bbd2>] ? dump_stack_print_info+0xd2/0xf0 [  225.570000]  [<600d191a>] ? printk+0x0/0x94
 [  225.570000]  [<603b8701>] dump_stack+0x2a/0x39
 [  225.570000]  [<60085773>] spin_dump+0xa3/0xd0
 [  225.570000]  [<600859ba>] do_raw_spin_lock+0x18a/0x1a0 [  225.570000]  [<6063e443>] _raw_spin_lock_irqsave+0x33/0x40 [  225.570000]  [<6002b7a0>] ? do_IRQ+0x0/0x60
 [  225.570000]  [<6002b836>] sigio_handler+0x36/0x120
 [  225.570000]  [<60043db1>] sig_handler_common+0x71/0xe0 [  225.570000]  [<6063e566>] ? _raw_spin_unlock_irqrestore+0x26/0x30 [  225.570000]  [<603d2a2b>] ? debug_check_no_obj_freed+0x28b/0x2a0 [  225.570000]  [<6011e8bc>] ? cache_free_debugcheck+0x17c/0x470 [  225.570000]  [<6011f520>] ? kfree+0x0/0x170
 [  225.570000]  [<60398377>] ? blk_update_bidi_request+0x27/0x90 [  225.570000]  [<6003c41e>] ? ubd_intr+0x4e/0x140
 [  225.570000]  [<6011f629>] ? kfree+0x109/0x170
 [  225.570000]  [<60040d10>] ? os_read_file+0x0/0x30
 [  225.570000]  [<6011f520>] ? kfree+0x0/0x170
 [  225.570000]  [<60040d10>] ? os_read_file+0x0/0x30
 [  225.570000]  [<6011f520>] ? kfree+0x0/0x170
 [  225.570000]  [<60398790>] ? blk_end_request+0x0/0x20
 [  225.570000]  [<60043f60>] ? get_signals+0x0/0x10
 [  225.570000]  [<60040d35>] ? os_read_file+0x25/0x30
 [  225.570000]  [<6003c435>] ? ubd_intr+0x65/0x140
 [  225.570000]  [<60043d40>] ? sig_handler_common+0x0/0xe0 [  225.570000]  [<600438c0>] ? timer_real_alarm_handler+0x0/0x50 [  225.570000]  [<60043d1c>] unblock_signals+0x8c/0xb0
 [  225.570000]  [<60052c2c>] __do_softirq+0x9c/0x2a0
 [  225.570000]  [<6008c63f>] ? handle_irq_event+0x5f/0x80 [  225.570000]  [<6005313c>] irq_exit+0xac/0xb0
 [  225.570000]  [<6008bcd3>] ? generic_handle_irq+0x33/0x40 [  225.570000]  [<6002b7e7>] do_IRQ+0x47/0x60
 [  225.570000]  [<6002b7a0>] ? do_IRQ+0x0/0x60
 [  225.570000]  [<6002b8da>] sigio_handler+0xda/0x120
 [  225.570000]  [<60043db1>] sig_handler_common+0x71/0xe0 [  225.570000]  [<6004691a>] ? unmap+0x4a/0x50
 [  225.570000]  [<60074ff6>] ? __might_sleep+0x66/0xf0
 [  225.570000]  [<600dcc90>] ? get_page_from_freelist+0x0/0xa80 [  225.570000]  [<600f2440>] ? next_zones_zonelist+0x0/0x40 [  225.570000]  [<600dda67>] ? __alloc_pages_nodemask+0x177/0xb10 [  225.570000]  [<600ffa96>] ? do_set_pte+0xa6/0xc0
 [  225.570000]  [<600d2781>] ? unlock_page+0x31/0xa0
 [  225.570000]  [<600d3d64>] ? filemap_map_pages+0x324/0x340 [  225.570000]  [<60046ce2>] ? wait_stub_done+0x62/0x140 [  225.570000]  [<600462d0>] ? run_syscall_stub+0xf0/0x350 [  225.570000]  [<60043f70>] ? set_signals+0x0/0x50
 [  225.570000]  [<600468ca>] ? map+0x4a/0x50
 [  225.570000]  [<6002e724>] ? flush_tlb_page+0x134/0x240 [  225.570000]  [<601011b0>] ? handle_mm_fault+0x0/0x1620 [  225.570000]  [<6002ed35>] ? handle_page_fault+0x265/0x350 [  225.570000]  [<60043d40>] ? sig_handler_common+0x0/0xe0 [  225.570000]  [<600438c0>] ? timer_real_alarm_handler+0x0/0x50 [  225.570000]  [<60043d1c>] unblock_signals+0x8c/0xb0
 [  225.570000]  [<6063e53c>] _raw_spin_unlock_irq+0x1c/0x20 [  225.570000]  [<60074999>] finish_task_switch+0x59/0xe0 [  225.570000]  [<6004a88b>] ? arch_switch_to+0x2b/0x30
 [  225.570000]  [<60639141>] __schedule+0x1e1/0x5b0
 [  225.570000]  [<60638f60>] ? __schedule+0x0/0x5b0
 [  225.570000]  [<60639544>] schedule+0x34/0x90
 [  225.570000]  [<6002f426>] ? segv_handler+0x46/0x90
 [  225.570000]  [<6002c374>] interrupt_end+0xa4/0xb0
 [  225.570000]  [<60047373>] userspace+0x253/0x4e0
 [  225.570000]  [<60030303>] ? do_op_one_page+0x153/0x240 [  225.570000]  [<600429af>] ? save_registers+0x1f/0x40
 [  225.570000]  [<6004a806>] ? arch_prctl+0x1f6/0x220
 [  225.570000]  [<6002c055>] fork_handler+0x85/0x90
 [  225.570000]

with kind regards
thomas

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#5 lore raw
Quoted 25 lines · Thomas Meyer

Am Montag, den 09.11.2015, 15:03 +0000 schrieb Anton Ivanov:

Quoted 10 lines

It throws a couple of harmless "epoll del fd" warnings on reboot which
result the fact that disable_fd/enable_fd are not removed in the terminal/line code.

These are harmless and will go away once the term/line code gets support
for real write IRQs in addition to read at some point in the future.

I have fixed the file descriptor leak in the reboot case.

Hi,

now with the list on copy!

Richard: can you make some sense out of these stack traces? I can provide the config if you want!

I see a lot of bugs of type "BUG: spinlock recursion on CPU#0" with this patch:

I did look over your patch and found two errors in the irq_lock spinlock handling:

Quoted 8 lines

http://m3y3r.dyndns.org:9100/gerrit/#/c/2/1..2/arch/um/kernel/irq.c

But it still seems to miss something as above bugs still occurs, but now the system boots up a bit more at least.

Example:

 [  225.570000] BUG: spinlock lockup suspected on CPU#0, chmod/516
 [  225.570000]  lock: irq_lock+0x0/0x18, .magic: dead4ead, .owner:

Hmmm, UML is UP and does not support PREEMPT, so all spinlocks should be a no-op.
Do you have lock debugging enabled?

I this case I'd start gdb and inspect the memory. Maybe a stack corruption.

Signature · 8 lines
Thanks,
//richard

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#6 lore raw

I do not see it with my config. I have cleaned up a few things and can send an updated version.

At the same time it is 100% reproducible using the config I got from Thomas. So this is somehow config dependent.

I have compared the configs and the biggest difference I can see is that Thomas has most of the debug options enabled.

Everything else is the same or not relevant (nat, etc - module options).

In any case - I cannot make sense of the traces - they show nested invocation of the sigio handler and nested interrupt invocation. If there is no stack corruption there should be no way to get that - the enable/disable and hard handler code in signal.c ensures that.

I will probably add some "manual" debug code to check if the nested invocation happens with the debug options off.

A.

Quoted 30 lines · Richard Weinberger
Quoted 29 lines · Thomas Meyer

Am Montag, den 09.11.2015, 15:03 +0000 schrieb Anton Ivanov:

Quoted 10 lines

It throws a couple of harmless "epoll del fd" warnings on reboot which
result the fact that disable_fd/enable_fd are not removed in the terminal/line code.

These are harmless and will go away once the term/line code gets support
for real write IRQs in addition to read at some point in the future.

I have fixed the file descriptor leak in the reboot case.

Hi,

now with the list on copy!

Richard: can you make some sense out of these stack traces? I can provide the config if you want!

I see a lot of bugs of type "BUG: spinlock recursion on CPU#0" with this patch:

I did look over your patch and found two errors in the irq_lock spinlock handling:

http://m3y3r.dyndns.org:9100/gerrit/#/c/2/1..2/arch/um/kernel/irq.c

But it still seems to miss something as above bugs still occurs, but now the system boots up a bit more at least.

Quoted 9 lines
Quoted 3 lines

Example:

  [  225.570000] BUG: spinlock lockup suspected on CPU#0, chmod/516
  [  225.570000]  lock: irq_lock+0x0/0x18, .magic: dead4ead, .owner:

Hmmm, UML is UP and does not support PREEMPT, so all spinlocks should be a no-op.
Do you have lock debugging enabled?

I this case I'd start gdb and inspect the memory. Maybe a stack corruption.

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#7 lore raw
Quoted 2 lines

I will probably add some "manual" debug code to check if the nested invocation happens with the debug options off.

Might be timing dependent and/or issue with nested blocking/unblocking of signals.
Or debug printing when it should not.

Just my two cents

Stian Skjelstad

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#8 lore raw

There is for some reason IRQ/sigio handler reentrancy.

Both the debug "by hand" I stuck into irq.c and Thomas traces confirm it.

I have no clue how this is possible as the code in signal.c should guard against that.

I will sleep on it and try to tackle this tomorrow - no idea what is going on, but this is what is happening here.

A.

Quoted 8 lines · On 11/11/15 21:49, [email protected] wrote:
Quoted 2 lines

I will probably add some "manual" debug code to check if the nested invocation happens with the debug options off.

Might be timing dependent and/or issue with nested blocking/unblocking of signals.
Or debug printing when it should not.

Just my two cents

Quoted 9 lines

Stian Skjelstad

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#9 lore raw
In reply to Richard Weinberger
Quoted 27 lines · Richard Weinberger
Quoted 26 lines · Thomas Meyer

Am Montag, den 09.11.2015, 15:03 +0000 schrieb Anton Ivanov:

Quoted 10 lines

It throws a couple of harmless "epoll del fd" warnings on reboot which
result the fact that disable_fd/enable_fd are not removed in the terminal/line code.

These are harmless and will go away once the term/line code gets support
for real write IRQs in addition to read at some point in the future.

I have fixed the file descriptor leak in the reboot case.

Hi,

now with the list on copy!

Richard: can you make some sense out of these stack traces? I can provide the config if you want!

I see a lot of bugs of type "BUG: spinlock recursion on CPU#0" with this patch:

I did look over your patch and found two errors in the irq_lock spinlock handling:

http://m3y3r.dyndns.org:9100/gerrit/#/c/2/1..2/arch/um/kernel/irq.c

Quoted 8 lines
Quoted 6 lines

But it still seems to miss something as above bugs still occurs, but now the system boots up a bit more at least.

Example:

  [  225.570000] BUG: spinlock lockup suspected on CPU#0, chmod/516
  [  225.570000]  lock: irq_lock+0x0/0x18, .magic: dead4ead, .owner:

Hmmm, UML is UP and does not support PREEMPT, so all spinlocks should be a no-op.

In that case, if I understand correctly what is going on, there are a couple of places - the free_irqs(), activate_fd and the sigio handler itself, where it should not be a mutex, not a spinlock. It is there to ensure that you cannot use it in an interrupt context while it is being modified.

If spinlock is a NOP it fails to perform this duty. The code should also be different - it should return on try_lock so it does not deadlock so spinlock_irqsave is the wrong locking primitive as it does not have this functionality.

That is an issue both with this patch and with the original poll based controller - there free_irq, add_fd, reactivate_fd can all theoretically produce a race if you are adding/removing devices while under high IO load.

A.

Quoted 4 lines

Do you have lock debugging enabled?

I this case I'd start gdb and inspect the memory. Maybe a stack corruption.

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#10 lore raw

[snip]

Quoted 8 lines
Quoted 2 lines

Hmmm, UML is UP and does not support PREEMPT, so all spinlocks should be a no-op.

In that case, if I understand correctly what is going on, there are a couple of places - the free_irqs(), activate_fd and the sigio handler itself, where it should not be a mutex, not a spinlock. It is there to ensure that you cannot use it in an interrupt context while it is being modified.

Quoted 8 lines

If spinlock is a NOP it fails to perform this duty. The code should also be different - it should return on try_lock so it does not deadlock so spinlock_irqsave is the wrong locking primitive as it does not have this functionality.

That is an issue both with this patch and with the original poll based controller - there free_irq, add_fd, reactivate_fd can all theoretically produce a race if you are adding/removing devices while under high IO load.

We, however cannot use mutex here as it is interrupt.

I tried with spin_trylock and finally got the correct behaviour. It throws an occasional warning here and there while inserting/removing devices, but works correctly with either config. No more BUGs.

A bare (not try) spinlock with UP/PREEMPT set as they are in UML actually does not guard anything effectively - it is a NOP. The try form is an exemption - if you look at spinlock.h it is actually "viable" even on UP. It will however throw a warning that it is activated in an inappropriate context if it hits an existing lock.

In theory - the code in signal.c should guard against nested interrupt invocation. I am still struggling to understand why it fails to work in practice.

This also leaves open the question on how to add/remove interrupts. If the spinlock does not actually guard the irq data structures properly modifying them in a safe manner becomes a very interesting exercise. I have it working with the try form, but that throws the occasional warning.

I am going to clean it up and re-submit so we have a "working version" which people can comment on.

A.

Quoted 5 lines

A.

Quoted 2 lines

Do you have lock debugging enabled?

Quoted 8 lines
Quoted 2 lines

I this case I'd start gdb and inspect the memory. Maybe a stack corruption.

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#11 lore raw
Quoted 34 lines · Anton Ivanov

[snip]

Quoted 8 lines
Quoted 2 lines

Hmmm, UML is UP and does not support PREEMPT, so all spinlocks should be a no-op.

In that case, if I understand correctly what is going on, there are a couple of places - the free_irqs(), activate_fd and the sigio handler itself, where it should not be a mutex, not a spinlock. It is there to ensure that you cannot use it in an interrupt context while it is being modified.

Quoted 8 lines

If spinlock is a NOP it fails to perform this duty. The code should also be different - it should return on try_lock so it does not deadlock so spinlock_irqsave is the wrong locking primitive as it does not have this functionality.

That is an issue both with this patch and with the original poll based controller - there free_irq, add_fd, reactivate_fd can all theoretically produce a race if you are adding/removing devices while under high IO load.

We, however cannot use mutex here as it is interrupt.

I tried with spin_trylock and finally got the correct behaviour. It throws an occasional warning here and there while inserting/removing devices, but works correctly with either config. No more BUGs.

A bare (not try) spinlock with UP/PREEMPT set as they are in UML actually does not guard anything effectively - it is a NOP. The try form is an exemption - if you look at spinlock.h it is actually "viable" even on UP. It will however throw a warning that it is activated in an inappropriate context if it hits an existing lock.

In theory - the code in signal.c should guard against nested interrupt invocation. I am still struggling to understand why it fails to work in practice.

Quoted 7 lines

This also leaves open the question on how to add/remove interrupts. If the spinlock does not actually guard the irq data structures properly modifying them in a safe manner becomes a very interesting exercise. I have it working with the try form, but that throws the occasional warning.

I am going to clean it up and re-submit so we have a "working version" which people can comment on.

Putting an extra guard around the signal handler in signal.c which prevents recursive invocation solves it completely.

I am going to clean it up, see if we need a similar guard around the timer interrupt and re-submit tomorrow morning.

Quoted 16 lines

A.

Quoted 4 lines

A.

Quoted 2 lines

Do you have lock debugging enabled?

Quoted 8 lines
Quoted 2 lines

I this case I'd start gdb and inspect the memory. Maybe a stack corruption.

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

Quoted 6 lines

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#12 lore raw
Quoted 40 lines · Anton Ivanov
Quoted 39 lines · Anton Ivanov

[snip]

Quoted 8 lines
Quoted 2 lines

Hmmm, UML is UP and does not support PREEMPT, so all spinlocks should be a no-op.

In that case, if I understand correctly what is going on, there are a couple of places - the free_irqs(), activate_fd and the sigio handler itself, where it should not be a mutex, not a spinlock. It is there to ensure that you cannot use it in an interrupt context while it is being modified.

Quoted 8 lines

If spinlock is a NOP it fails to perform this duty. The code should also be different - it should return on try_lock so it does not deadlock so spinlock_irqsave is the wrong locking primitive as it does not have this functionality.

That is an issue both with this patch and with the original poll based controller - there free_irq, add_fd, reactivate_fd can all theoretically produce a race if you are adding/removing devices while under high IO load.

We, however cannot use mutex here as it is interrupt.

I tried with spin_trylock and finally got the correct behaviour. It throws an occasional warning here and there while inserting/removing devices, but works correctly with either config. No more BUGs.

A bare (not try) spinlock with UP/PREEMPT set as they are in UML actually does not guard anything effectively - it is a NOP. The try form is an exemption - if you look at spinlock.h it is actually "viable" even on UP. It will however throw a warning that it is activated in an inappropriate context if it hits an existing lock.

In theory - the code in signal.c should guard against nested interrupt invocation. I am still struggling to understand why it fails to work in practice.

This also leaves open the question on how to add/remove interrupts. If the spinlock does not actually guard the irq data structures properly modifying them in a safe manner becomes a very interesting exercise. I have it working with the try form, but that throws the occasional warning.

Quoted 7 lines
Quoted 2 lines

I am going to clean it up and re-submit so we have a "working version" which people can comment on.

Putting an extra guard around the signal handler in signal.c which prevents recursive invocation solves it completely.

I am going to clean it up, see if we need a similar guard around the timer interrupt and re-submit tomorrow morning.

That worked. So in principle the proposed IRQ semantics are sound.

However, in practice forcing the re-invocation of IRQs and returing up the IRQ chain resulted in a significant performance drop - from 15% above the original to 15% below the original. By using a guard we also lose the possibility to have edge triggers in the future so overall this is a no-go.

I am going to "sleep on it" and come back to it later in the week to figure out why we do not see recursive invocation with the original and see it with the epoll one.

Once I get to the bottom of that, I will resubmit a fixed version.

A.

Quoted 21 lines
Quoted 15 lines

A.

Quoted 4 lines

A.

Quoted 2 lines

Do you have lock debugging enabled?

Quoted 8 lines
Quoted 2 lines

I this case I'd start gdb and inspect the memory. Maybe a stack corruption.

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

Quoted 6 lines

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

Quoted 6 lines

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

------------------------------------------------------------------------------
Presto, an open source distributed SQL query engine for big data, initially developed by Facebook, enables you to easily query your data on Hadoop in a more interactive manner. Teradata is also now providing full enterprise support for Presto. Download a free open source copy now.
http://pubads.g.doubleclick.net/gampad/clk?id=250295911&iu=/4140
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#13 lore raw

Hi all,

I have looked through this and I still have not figured it out completely. Moving from the old poll controller to the new epoll one triggers deep recursive invocations of the interrupt handlers. I still do not understand why it does it so I will park it for now and come back to it next week.

I did, however, find a number of small issues. Namely, various patches and fixes over the years have used calls to block/unblock signals and block/unblock irqs in a few places where these can create a recursion race (even with the old controller).

If I understand os-Linux/irq.c correctly, block/unblock in UML does not block or unblock the signals. It blocks/unblocks the processing of them and unblock can (and will) result in the immediate processing any pending signals. So in most places, that should not be block/unblock (and respectively local_irq_enable/local_irq_disable which invoke that). It should be save+block and restore. Otherwise you recurse by invoking the IRQ handler the moment you unblock_signals().

Additionally, if you want just to wait and be interrupted by a signal, you do not need to enable/disable IRQs - signals are always received at present. If I understand the situation correctly, irq on/off only changes if they are processed or not.

I am going to roll my tree back to the timer patch now and go through the ones I found so far one by one and submit them separately. Once that is out of the way we can look again at the epoll controller patch. It has potential, but it makes all gremlins come out of the woodwork so we might as well get the gremlins out of the way first.

[snip]

A.

------------------------------------------------------------------------------
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel