Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-26 Thread stian
  nsecs = timer.it_value.tv_sec *
  UM_NSEC_PER_SEC +
  timer.it_value.tv_usec *
  UM_NSEC_PER_USEC;
  nsecs += os_nsecs();

Not looking at the rest of the code, the first thing that comes to my 
mind is that this very easy overflows if 32 bit multiplications are used 
(tv_sec is usually 32bit and dictates the first multiplication unless 
typecast is used).

Stian Skjelstad

--
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
___
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-11 Thread Anton Ivanov
Hurray, Houston we have ignition.

We now have working userspace timers.

It is still schizophrenic - userspace is HZ, kernel is NOHZ because the
userpace has to keep checking did the kernel timer fire yet at a HZ
interval. However, even that is a major progress compared to having
userspace timer behavior determined by the phase of the moon, the
position of a black goat relative to a silver knife, etc. It is now
spot on - you set HZ=100 in the .config, you get 100. Before you used
to get something... like 39-45 depending on the weather.

The userspace is now significantly more responsive and snappy (that is
expected as it now gets decent clock). Kernel behavior on timers in
first instance also looks correct and NOHZ-ish (traffic shapers work).

I am going to hit it with the torture suite now to see if there is
significant difference with relation to other known bugs like the ext4
writeout (my original patch versions seemed to aggravate it).

I will try to get around to restore my virtual desktop setup over X to
see what difference does it make. Judging by the way userspace behaves
after the changes it should be better than before.

A.


On 10/05/15 15:34, Thomas Meyer wrote:
 Am 10.05.2015 um 14:35 schrieb Richard Weinberger 
 richard.weinber...@gmail.com:

 On Sun, May 10, 2015 at 1:14 AM, Thomas Meyer tho...@m3y3r.de wrote:
 Hi,

 Changes:
 - also create posix timer in stub_clone_handler()
 - incorporated antons remarks
 Hm, this patch does a *lot* more than the changelog says.
 Hi, yes PATCH was probably the wrong keyword in the subject line. It should 
 have been RFC.
 I just wanted to have feedback of the current state of this patch/work.

 I'm currently working on cleaning up the patch and switch from SIGUSR2 to 
 SIGNALRM, which seems to be the natural thing for posix timers.
 I will send this next patch as something that should be includable into the 
 kernel, i.e. With correct description and signed off line and so on.

 But feel free to have a look at v6 and give feedback.

 With kind regards
 Thomas

 diff --git a/arch/um/Makefile b/arch/um/Makefile
 index 17d4460..a4a434f 100644
 --- a/arch/um/Makefile
 +++ b/arch/um/Makefile
 @@ -130,7 +130,7 @@ export LDS_ELF_FORMAT := $(ELF_FORMAT)
 # The wrappers will select whether using malloc or the kernel allocator.
 LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc

 -LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt))
 +LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt)) -lrt

 # Used by link-vmlinux.sh which has special support for um link
 export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE)
 diff --git a/arch/um/include/asm/irq.h b/arch/um/include/asm/irq.h
 index 4a2037f..0f2a5b1 100644
 --- a/arch/um/include/asm/irq.h
 +++ b/arch/um/include/asm/irq.h
 @@ -16,8 +16,9 @@
 #define TELNETD_IRQ12
 #define XTERM_IRQ  13
 #define RANDOM_IRQ 14
 +#define HRTIMER_IRQ15

 -#define LAST_IRQ RANDOM_IRQ
 +#define LAST_IRQ HRTIMER_IRQ
 #define NR_IRQS (LAST_IRQ + 1)

 #endif
 diff --git a/arch/um/include/shared/as-layout.h 
 b/arch/um/include/shared/as-layout.h
 index ca1843e..798aa6e 100644
 --- a/arch/um/include/shared/as-layout.h
 +++ b/arch/um/include/shared/as-layout.h
 @@ -17,7 +17,7 @@

 /* Some constant macros are used in both assembler and
   * C code.  Therefore we cannot annotate them always with
 - * 'UL' and other type specifiers unilaterally.  We
 + * 'UL' and other type specifiers unilaterally. We
   * use the following macros to deal with this.
   */

 @@ -28,6 +28,13 @@
 #define _UML_AC(X, Y)  __UML_AC(X, Y)
 #endif

 +/**
 + * userspace stub address space layout:
 + * Below macros define the layout of the stub code and data
 + * which are mapped in each userspace process:
 + *  - one page of code located at 0x10 followed by
 + *  - one page of data
 + */
 #define STUB_START _UML_AC(, 0x10)
 #define STUB_CODE _UML_AC((unsigned long), STUB_START)
 #define STUB_DATA _UML_AC((unsigned long), STUB_CODE + UM_KERN_PAGE_SIZE)
 diff --git a/arch/um/include/shared/kern_util.h 
 b/arch/um/include/shared/kern_util.h
 index 83a91f9..0282b36 100644
 --- a/arch/um/include/shared/kern_util.h
 +++ b/arch/um/include/shared/kern_util.h
 @@ -37,6 +37,7 @@ extern void initial_thread_cb(void (*proc)(void *), void 
 *arg);
 extern int is_syscall(unsigned long addr);

 extern void timer_handler(int sig, struct siginfo *unused_si, struct 
 uml_pt_regs *regs);
 +extern void hrtimer_handler(int sig, struct siginfo *unused_si, struct 
 uml_pt_regs *regs);

 extern int start_uml(void);
 extern void paging_init(void);
 diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
 index d824528..7f7368b 100644
 --- a/arch/um/include/shared/os.h
 +++ b/arch/um/include/shared/os.h
 @@ -217,7 +217,8 @@ extern int set_umid(char *name);
 extern char *get_umid(void);

 /* signal.c */
 -extern void timer_init(void);
 +extern void uml_timer_set_signal_handler(void);
 +extern 

Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-11 Thread Anton Ivanov
Hi Thomas, hi Richard,

It is now possible to reproducibly hang it. I have not been able to 
concoct a synthetic test (yet), but a non-synthetic one, namely 
installing an update to base-files on Debian is a guaranteed hang. So IO 
on itself does not hang it, CPU on itself does not, a mix of two does.

It hangs in userspace, spinning at 100% CPU on that thread. If you whack 
the offending thread with -11 from the host, UML recovers, killing the 
affected process. I cannot look at this in detail for a few days though 
- the earliest I can pick it up is on Sat (in my free time).

On the positive side - the behavior we are getting now is better, so we 
just need to figure out the root cause for the hang(s) and stabilize it.

A.


On 11/05/15 13:52, Anton Ivanov wrote:
 Hurray, Houston we have ignition.

 We now have working userspace timers.

 It is still schizophrenic - userspace is HZ, kernel is NOHZ because the
 userpace has to keep checking did the kernel timer fire yet at a HZ
 interval. However, even that is a major progress compared to having
 userspace timer behavior determined by the phase of the moon, the
 position of a black goat relative to a silver knife, etc. It is now
 spot on - you set HZ=100 in the .config, you get 100. Before you used
 to get something... like 39-45 depending on the weather.

 The userspace is now significantly more responsive and snappy (that is
 expected as it now gets decent clock). Kernel behavior on timers in
 first instance also looks correct and NOHZ-ish (traffic shapers work).

 I am going to hit it with the torture suite now to see if there is
 significant difference with relation to other known bugs like the ext4
 writeout (my original patch versions seemed to aggravate it).

 I will try to get around to restore my virtual desktop setup over X to
 see what difference does it make. Judging by the way userspace behaves
 after the changes it should be better than before.

 A.


 On 10/05/15 15:34, Thomas Meyer wrote:
 Am 10.05.2015 um 14:35 schrieb Richard Weinberger 
 richard.weinber...@gmail.com:

 On Sun, May 10, 2015 at 1:14 AM, Thomas Meyer tho...@m3y3r.de wrote:
 Hi,

 Changes:
 - also create posix timer in stub_clone_handler()
 - incorporated antons remarks
 Hm, this patch does a *lot* more than the changelog says.
 Hi, yes PATCH was probably the wrong keyword in the subject line. It should 
 have been RFC.
 I just wanted to have feedback of the current state of this patch/work.

 I'm currently working on cleaning up the patch and switch from SIGUSR2 to 
 SIGNALRM, which seems to be the natural thing for posix timers.
 I will send this next patch as something that should be includable into the 
 kernel, i.e. With correct description and signed off line and so on.

 But feel free to have a look at v6 and give feedback.

 With kind regards
 Thomas

 diff --git a/arch/um/Makefile b/arch/um/Makefile
 index 17d4460..a4a434f 100644
 --- a/arch/um/Makefile
 +++ b/arch/um/Makefile
 @@ -130,7 +130,7 @@ export LDS_ELF_FORMAT := $(ELF_FORMAT)
 # The wrappers will select whether using malloc or the kernel allocator.
 LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc

 -LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt))
 +LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt)) -lrt

 # Used by link-vmlinux.sh which has special support for um link
 export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE)
 diff --git a/arch/um/include/asm/irq.h b/arch/um/include/asm/irq.h
 index 4a2037f..0f2a5b1 100644
 --- a/arch/um/include/asm/irq.h
 +++ b/arch/um/include/asm/irq.h
 @@ -16,8 +16,9 @@
 #define TELNETD_IRQ12
 #define XTERM_IRQ  13
 #define RANDOM_IRQ 14
 +#define HRTIMER_IRQ15

 -#define LAST_IRQ RANDOM_IRQ
 +#define LAST_IRQ HRTIMER_IRQ
 #define NR_IRQS (LAST_IRQ + 1)

 #endif
 diff --git a/arch/um/include/shared/as-layout.h 
 b/arch/um/include/shared/as-layout.h
 index ca1843e..798aa6e 100644
 --- a/arch/um/include/shared/as-layout.h
 +++ b/arch/um/include/shared/as-layout.h
 @@ -17,7 +17,7 @@

 /* Some constant macros are used in both assembler and
* C code.  Therefore we cannot annotate them always with
 - * 'UL' and other type specifiers unilaterally.  We
 + * 'UL' and other type specifiers unilaterally. We
* use the following macros to deal with this.
*/

 @@ -28,6 +28,13 @@
 #define _UML_AC(X, Y)  __UML_AC(X, Y)
 #endif

 +/**
 + * userspace stub address space layout:
 + * Below macros define the layout of the stub code and data
 + * which are mapped in each userspace process:
 + *  - one page of code located at 0x10 followed by
 + *  - one page of data
 + */
 #define STUB_START _UML_AC(, 0x10)
 #define STUB_CODE _UML_AC((unsigned long), STUB_START)
 #define STUB_DATA _UML_AC((unsigned long), STUB_CODE + UM_KERN_PAGE_SIZE)
 diff --git a/arch/um/include/shared/kern_util.h 
 b/arch/um/include/shared/kern_util.h
 index 83a91f9..0282b36 100644
 --- 

Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-11 Thread Anton Ivanov
The likely suspect is arch/um/os-Linux/skas/process.c

It is spinning in the while(1) loop.

However, the current code looks correct and the original code does not 
make any sense at least to me:

Original code gets the _VALUE_ of the current userspace itimer() and it 
ensures that the signal is delivered the first time (only the first 
time) it skips vtalrm signals until that time has lapsed. So far so good 
- we are approximating real clock using a clock whose value depends on CPU.



 if (getitimer(ITIMER_VIRTUAL, timer))
 printk(UM_KERN_ERR Failed to get itimer, errno = %d\n, errno);
 nsecs = timer.it_value.tv_sec * UM_NSEC_PER_SEC +
 timer.it_value.tv_usec * UM_NSEC_PER_USEC;
 nsecs += os_nsecs();

However, instead of resetting the next check value to the _INTERVAL_ 
value which would have been the obvious thing to do in the check it 
resets it by incrementing it with the _VALUE_


 nsecs = timer.it_value.tv_sec *
 UM_NSEC_PER_SEC +
 timer.it_value.tv_usec *
 UM_NSEC_PER_USEC;
 nsecs += os_nsecs();

This is inside the while(1) loop so there is no re-adjustment of the 
values. So in fact, in the original code it fires at some feedback loop 
rate depending on CPU usage by this UML instance. Weird.

In any case, in order to figure out the correct replacement here, we 
need to understand the logic (or the bug) in the original. Quite clearly 
the logical replacement where the timer fires exactly when it is 
expected to fire does not quite work. So what is the idea here?

A.

On 11/05/15 16:05, Anton Ivanov wrote:
 Hi Thomas, hi Richard,

 It is now possible to reproducibly hang it. I have not been able to
 concoct a synthetic test (yet), but a non-synthetic one, namely
 installing an update to base-files on Debian is a guaranteed hang. So IO
 on itself does not hang it, CPU on itself does not, a mix of two does.

 It hangs in userspace, spinning at 100% CPU on that thread. If you whack
 the offending thread with -11 from the host, UML recovers, killing the
 affected process. I cannot look at this in detail for a few days though
 - the earliest I can pick it up is on Sat (in my free time).

 On the positive side - the behavior we are getting now is better, so we
 just need to figure out the root cause for the hang(s) and stabilize it.

 A.


 On 11/05/15 13:52, Anton Ivanov wrote:
 Hurray, Houston we have ignition.

 We now have working userspace timers.

 It is still schizophrenic - userspace is HZ, kernel is NOHZ because the
 userpace has to keep checking did the kernel timer fire yet at a HZ
 interval. However, even that is a major progress compared to having
 userspace timer behavior determined by the phase of the moon, the
 position of a black goat relative to a silver knife, etc. It is now
 spot on - you set HZ=100 in the .config, you get 100. Before you used
 to get something... like 39-45 depending on the weather.

 The userspace is now significantly more responsive and snappy (that is
 expected as it now gets decent clock). Kernel behavior on timers in
 first instance also looks correct and NOHZ-ish (traffic shapers work).

 I am going to hit it with the torture suite now to see if there is
 significant difference with relation to other known bugs like the ext4
 writeout (my original patch versions seemed to aggravate it).

 I will try to get around to restore my virtual desktop setup over X to
 see what difference does it make. Judging by the way userspace behaves
 after the changes it should be better than before.

 A.


 On 10/05/15 15:34, Thomas Meyer wrote:
 Am 10.05.2015 um 14:35 schrieb Richard Weinberger 
 richard.weinber...@gmail.com:

 On Sun, May 10, 2015 at 1:14 AM, Thomas Meyer tho...@m3y3r.de wrote:
 Hi,

 Changes:
 - also create posix timer in stub_clone_handler()
 - incorporated antons remarks
 Hm, this patch does a *lot* more than the changelog says.
 Hi, yes PATCH was probably the wrong keyword in the subject line. It should 
 have been RFC.
 I just wanted to have feedback of the current state of this patch/work.

 I'm currently working on cleaning up the patch and switch from SIGUSR2 to 
 SIGNALRM, which seems to be the natural thing for posix timers.
 I will send this next patch as something that should be includable into the 
 kernel, i.e. With correct description and signed off line and so on.

 But feel free to have a look at v6 and give feedback.

 With kind regards
 Thomas

 diff --git a/arch/um/Makefile b/arch/um/Makefile
 index 17d4460..a4a434f 100644
 --- a/arch/um/Makefile
 +++ b/arch/um/Makefile
 @@ -130,7 +130,7 @@ export LDS_ELF_FORMAT := $(ELF_FORMAT)
 # The wrappers will select whether using malloc or the kernel allocator.
 LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc

 -LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt))
 +LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt)) -lrt

 # Used by link-vmlinux.sh which has 

Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-11 Thread Anton Ivanov
On 11/05/15 18:00, Thomas Meyer wrote:
 Hi,

 maybe there is a bug in how the timers are created for all user space 
 processes.
 In the latest patch I use os__timer_remain for the initial interval.
 The idea was to launch all timers at the same time. But I now think this can 
 never work using relative times, especially when os__timer_remain returns 0, 
 then the new timer is never launched.

That is not a bad idea, just requires a more complex check in setting up 
interval so it is reset to default when a zero value or value  HZ is 
passed.



 That may explain the hangs you see.
   You could try to replace os__timer_remain with the current HZ value in 
 nanoseconds.

I am going to adjust time.c instead as above.

A.


 Kind regards
 Thomad

 A
[snip]

A.

--
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
___
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-11 Thread Thomas Meyer
Hi,

maybe there is a bug in how the timers are created for all user space processes.
In the latest patch I use os__timer_remain for the initial interval.
The idea was to launch all timers at the same time. But I now think this can 
never work using relative times, especially when os__timer_remain returns 0, 
then the new timer is never launched.

That may explain the hangs you see.
 You could try to replace os__timer_remain with the current HZ value in 
nanoseconds.

Kind regards
Thomad

Am 11.05.2015 5:43 nachm. schrieb Anton Ivanov anton.iva...@kot-begemot.co.uk:

 The likely suspect is arch/um/os-Linux/skas/process.c 

 It is spinning in the while(1) loop. 

 However, the current code looks correct and the original code does not 
 make any sense at least to me: 

 Original code gets the _VALUE_ of the current userspace itimer() and it 
 ensures that the signal is delivered the first time (only the first 
 time) it skips vtalrm signals until that time has lapsed. So far so good 
 - we are approximating real clock using a clock whose value depends on CPU. 



  if (getitimer(ITIMER_VIRTUAL, timer)) 
  printk(UM_KERN_ERR Failed to get itimer, errno = %d\n, errno); 
  nsecs = timer.it_value.tv_sec * UM_NSEC_PER_SEC + 
  timer.it_value.tv_usec * UM_NSEC_PER_USEC; 
  nsecs += os_nsecs(); 

 However, instead of resetting the next check value to the _INTERVAL_ 
 value which would have been the obvious thing to do in the check it 
 resets it by incrementing it with the _VALUE_ 


  nsecs = timer.it_value.tv_sec * 
  UM_NSEC_PER_SEC + 
  timer.it_value.tv_usec * 
  UM_NSEC_PER_USEC; 
  nsecs += os_nsecs(); 

 This is inside the while(1) loop so there is no re-adjustment of the 
 values. So in fact, in the original code it fires at some feedback loop 
 rate depending on CPU usage by this UML instance. Weird. 

 In any case, in order to figure out the correct replacement here, we 
 need to understand the logic (or the bug) in the original. Quite clearly 
 the logical replacement where the timer fires exactly when it is 
 expected to fire does not quite work. So what is the idea here? 

 A. 

 On 11/05/15 16:05, Anton Ivanov wrote: 
  Hi Thomas, hi Richard, 
  
  It is now possible to reproducibly hang it. I have not been able to 
  concoct a synthetic test (yet), but a non-synthetic one, namely 
  installing an update to base-files on Debian is a guaranteed hang. So IO 
  on itself does not hang it, CPU on itself does not, a mix of two does. 
  
  It hangs in userspace, spinning at 100% CPU on that thread. If you whack 
  the offending thread with -11 from the host, UML recovers, killing the 
  affected process. I cannot look at this in detail for a few days though 
  - the earliest I can pick it up is on Sat (in my free time). 
  
  On the positive side - the behavior we are getting now is better, so we 
  just need to figure out the root cause for the hang(s) and stabilize it. 
  
  A. 
  
  
  On 11/05/15 13:52, Anton Ivanov wrote: 
  Hurray, Houston we have ignition. 
  
  We now have working userspace timers. 
  
  It is still schizophrenic - userspace is HZ, kernel is NOHZ because the 
  userpace has to keep checking did the kernel timer fire yet at a HZ 
  interval. However, even that is a major progress compared to having 
  userspace timer behavior determined by the phase of the moon, the 
  position of a black goat relative to a silver knife, etc. It is now 
  spot on - you set HZ=100 in the .config, you get 100. Before you used 
  to get something... like 39-45 depending on the weather. 
  
  The userspace is now significantly more responsive and snappy (that is 
  expected as it now gets decent clock). Kernel behavior on timers in 
  first instance also looks correct and NOHZ-ish (traffic shapers work). 
  
  I am going to hit it with the torture suite now to see if there is 
  significant difference with relation to other known bugs like the ext4 
  writeout (my original patch versions seemed to aggravate it). 
  
  I will try to get around to restore my virtual desktop setup over X to 
  see what difference does it make. Judging by the way userspace behaves 
  after the changes it should be better than before. 
  
  A. 
  
  
  On 10/05/15 15:34, Thomas Meyer wrote: 
  Am 10.05.2015 um 14:35 schrieb Richard Weinberger 
  richard.weinber...@gmail.com: 
  
  On Sun, May 10, 2015 at 1:14 AM, Thomas Meyer tho...@m3y3r.de wrote: 
  Hi, 
  
  Changes: 
  - also create posix timer in stub_clone_handler() 
  - incorporated antons remarks 
  Hm, this patch does a *lot* more than the changelog says. 
  Hi, yes PATCH was probably the wrong keyword in the subject line. It 
  should have been RFC. 
  I just wanted to have feedback of the current state of this patch/work. 
  
  I'm currently working on cleaning up the patch and switch from SIGUSR2 to 
  SIGNALRM, which seems to be the natural 

Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-11 Thread Anton Ivanov
On 11/05/15 18:41, Thomas Meyer wrote:
 Am 11.05.2015 7:31 nachm. schrieb Anton Ivanov 
 anton.iva...@kot-begemot.co.uk:
 On 11/05/15 18:20, Anton Ivanov wrote:
 On 11/05/15 18:00, Thomas Meyer wrote:
 Hi,

 maybe there is a bug in how the timers are created for all user space 
 processes.
 In the latest patch I use os__timer_remain for the initial interval.
 The idea was to launch all timers at the same time. But I now think this 
 can never work using relative times, especially when os__timer_remain 
 returns 0, then the new timer is never launched.
 That is not a bad idea, just requires a more complex check in setting up
 interval so it is reset to default when a zero value or value  HZ is
 passed.


 That may explain the hangs you see.
  You could try to replace os__timer_remain with the current HZ value 
 in nanoseconds.
 I am going to adjust time.c instead as above.
 Both approaches fail - the check (that is expected actually, I did not
 think properly here - it does not cover the stub in kernel/skas) and the
 setting of data to the correct initial values.

 Also, if it was just not starting timers it would have been possible to
 beat the process with USR2 on the head until its morale improves. Well,
 while true; do kill -USR2 PID ; done does not change the behavior, it
 still hangs and is still possible to terminate the errant process by
 sending SIGSEGV to the UML thread which is shown as 100% CPU and in R state.
 Yes, sending USR2 should do the same. Correct.

 Problem is somewhere else. I am surprised it worked correctly in the
 original one as there for 100% flat CPU usage it should have converged
 to a behavior which is similar to what we have now.
 Mhh. Strange. Any hints how I can reproduce this?

 I need to see the same behaviour, i.e. the hang on my machine to begin to 
 understand what is going on here.

Start off with a Debian image of let's say wheezy and hit it with a 
dist-upgrade to the next release. This produces enough IO+CPU at the 
same time to trigger it. I get it 100% reproducible every time it tries 
to unpack the first couple of packages.

I tried to trigger backtraces but could not get anything informative. 
The old trick of hitting the kernel with SIGILL which worked very nicely 
in older kernel versions no longer works :(


 Thanks for testing Anton.

I wish I had more time at the moment to debug it and fix it :( We are 
nearly there and it is worth it.

A.



 A.

 A.

 Kind regards
 Thomad

 A
 [snip]

 A.

 --
 One dashboard for servers and applications across Physical-Virtual-Cloud
 Widest out-of-the-box monitoring support with 50+ applications
 Performance metrics, stats and reports that give you Actionable Insights
 Deep dive visibility with transaction tracing using APM Insight.
 http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
 ___
 User-mode-linux-devel mailing list
 User-mode-linux-devel@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


 --
 One dashboard for servers and applications across Physical-Virtual-Cloud
 Widest out-of-the-box monitoring support with 50+ applications
 Performance metrics, stats and reports that give you Actionable Insights
 Deep dive visibility with transaction tracing using APM Insight.
 http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
 ___
 User-mode-linux-devel mailing list
 User-mode-linux-devel@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


--
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
___
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-11 Thread Thomas Meyer
Am 11.05.2015 9:42 nachm. schrieb Anton Ivanov anton.iva...@kot-begemot.co.uk:

 On 11/05/15 18:41, Thomas Meyer wrote: 
  Am 11.05.2015 7:31 nachm. schrieb Anton Ivanov 
  anton.iva...@kot-begemot.co.uk: 
  On 11/05/15 18:20, Anton Ivanov wrote: 
  On 11/05/15 18:00, Thomas Meyer wrote: 
  Hi, 
  
  maybe there is a bug in how the timers are created for all user space 
  processes. 
  In the latest patch I use os__timer_remain for the initial interval. 
  The idea was to launch all timers at the same time. But I now think this 
  can never work using relative times, especially when os__timer_remain 
  returns 0, then the new timer is never launched. 
  That is not a bad idea, just requires a more complex check in setting up 
  interval so it is reset to default when a zero value or value  HZ is 
  passed. 
  
  
  That may explain the hangs you see. 
   You could try to replace os__timer_remain with the current HZ value 
 in nanoseconds. 
  I am going to adjust time.c instead as above. 
  Both approaches fail - the check (that is expected actually, I did not 
  think properly here - it does not cover the stub in kernel/skas) and the 
  setting of data to the correct initial values. 
  
  Also, if it was just not starting timers it would have been possible to 
  beat the process with USR2 on the head until its morale improves. Well, 
  while true; do kill -USR2 PID ; done does not change the behavior, it 
  still hangs and is still possible to terminate the errant process by 
  sending SIGSEGV to the UML thread which is shown as 100% CPU and in R 
  state. 
  Yes, sending USR2 should do the same. Correct. 
  
  Problem is somewhere else. I am surprised it worked correctly in the 
  original one as there for 100% flat CPU usage it should have converged 
  to a behavior which is similar to what we have now. 
  Mhh. Strange. Any hints how I can reproduce this? 
  
  I need to see the same behaviour, i.e. the hang on my machine to begin to 
  understand what is going on here. 

 Start off with a Debian image of let's say wheezy and hit it with a 
 dist-upgrade to the next release. This produces enough IO+CPU at the 
 same time to trigger it. I get it 100% reproducible every time it tries 
 to unpack the first couple of packages. 

Okay, I'll try that!


 I tried to trigger backtraces but could not get anything informative. 
 The old trick of hitting the kernel with SIGILL which worked very nicely 
 in older kernel versions no longer works :( 

You may can trigger an backtrace via uml_console.


  
  Thanks for testing Anton. 

 I wish I had more time at the moment to debug it and fix it :( We are 
 nearly there and it is worth it. 

Yes, same here.
But we will finish this!


 A. 

  
  
  A. 
  
  A. 
  
  Kind regards 
  Thomad 
  
  A 
  [snip] 
  
  A. 
  
  --
   
  One dashboard for servers and applications across Physical-Virtual-Cloud 
  Widest out-of-the-box monitoring support with 50+ applications 
  Performance metrics, stats and reports that give you Actionable Insights 
  Deep dive visibility with transaction tracing using APM Insight. 
  http://ad.doubleclick.net/ddm/clk/290420510;117567292;y 
  ___ 
  User-mode-linux-devel mailing list 
  User-mode-linux-devel@lists.sourceforge.net 
  https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel 
  
  
  --
   
  One dashboard for servers and applications across Physical-Virtual-Cloud 
  Widest out-of-the-box monitoring support with 50+ applications 
  Performance metrics, stats and reports that give you Actionable Insights 
  Deep dive visibility with transaction tracing using APM Insight. 
  http://ad.doubleclick.net/ddm/clk/290420510;117567292;y 
  ___ 
  User-mode-linux-devel mailing list 
  User-mode-linux-devel@lists.sourceforge.net 
  https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel 


 --
  
 One dashboard for servers and applications across Physical-Virtual-Cloud 
 Widest out-of-the-box monitoring support with 50+ applications 
 Performance metrics, stats and reports that give you Actionable Insights 
 Deep dive visibility with transaction tracing using APM Insight. 
 http://ad.doubleclick.net/ddm/clk/290420510;117567292;y 
 ___ 
 User-mode-linux-devel mailing list 
 User-mode-linux-devel@lists.sourceforge.net 
 https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel 
--
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable 

Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-11 Thread Richard Weinberger
Am 10.05.2015 um 16:34 schrieb Thomas Meyer:
 
 Am 10.05.2015 um 14:35 schrieb Richard Weinberger 
 richard.weinber...@gmail.com:

 On Sun, May 10, 2015 at 1:14 AM, Thomas Meyer tho...@m3y3r.de wrote:
 Hi,

 Changes:
 - also create posix timer in stub_clone_handler()
 - incorporated antons remarks

 Hm, this patch does a *lot* more than the changelog says.
 
 Hi, yes PATCH was probably the wrong keyword in the subject line. It should 
 have been RFC.
 I just wanted to have feedback of the current state of this patch/work.
 
 I'm currently working on cleaning up the patch and switch from SIGUSR2 to 
 SIGNALRM, which seems to be the natural thing for posix timers.
 I will send this next patch as something that should be includable into the 
 kernel, i.e. With correct description and signed off line and so on.
 
 But feel free to have a look at v6 and give feedback.

The timer stuff looks generally okay but please submit again as a clean patch 
series
with one logical change per patch such that I can review it in depth. :-)

Thanks,
//richard

--
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
___
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-11 Thread Anton Ivanov
On 11/05/15 18:20, Anton Ivanov wrote:
 On 11/05/15 18:00, Thomas Meyer wrote:
 Hi,

 maybe there is a bug in how the timers are created for all user space 
 processes.
 In the latest patch I use os__timer_remain for the initial interval.
 The idea was to launch all timers at the same time. But I now think this can 
 never work using relative times, especially when os__timer_remain returns 0, 
 then the new timer is never launched.
 That is not a bad idea, just requires a more complex check in setting up
 interval so it is reset to default when a zero value or value  HZ is
 passed.


 That may explain the hangs you see.
You could try to replace os__timer_remain with the current HZ value in 
 nanoseconds.
 I am going to adjust time.c instead as above.

Both approaches fail - the check (that is expected actually, I did not 
think properly here - it does not cover the stub in kernel/skas) and the 
setting of data to the correct initial values.

Also, if it was just not starting timers it would have been possible to 
beat the process with USR2 on the head until its morale improves. Well, 
while true; do kill -USR2 PID ; done does not change the behavior, it 
still hangs and is still possible to terminate the errant process by 
sending SIGSEGV to the UML thread which is shown as 100% CPU and in R state.

Problem is somewhere else. I am surprised it worked correctly in the 
original one as there for 100% flat CPU usage it should have converged 
to a behavior which is similar to what we have now.

A.


 A.

 Kind regards
 Thomad

 A
 [snip]

 A.

 --
 One dashboard for servers and applications across Physical-Virtual-Cloud
 Widest out-of-the-box monitoring support with 50+ applications
 Performance metrics, stats and reports that give you Actionable Insights
 Deep dive visibility with transaction tracing using APM Insight.
 http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
 ___
 User-mode-linux-devel mailing list
 User-mode-linux-devel@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel



--
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
___
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-11 Thread Thomas Meyer
Am 11.05.2015 7:31 nachm. schrieb Anton Ivanov anton.iva...@kot-begemot.co.uk:

 On 11/05/15 18:20, Anton Ivanov wrote: 
  On 11/05/15 18:00, Thomas Meyer wrote: 
  Hi, 
  
  maybe there is a bug in how the timers are created for all user space 
  processes. 
  In the latest patch I use os__timer_remain for the initial interval. 
  The idea was to launch all timers at the same time. But I now think this 
  can never work using relative times, especially when os__timer_remain 
  returns 0, then the new timer is never launched. 
  That is not a bad idea, just requires a more complex check in setting up 
  interval so it is reset to default when a zero value or value  HZ is 
  passed. 
  
  
  That may explain the hangs you see. 
     You could try to replace os__timer_remain with the current HZ value in 
 nanoseconds. 
  I am going to adjust time.c instead as above. 

 Both approaches fail - the check (that is expected actually, I did not 
 think properly here - it does not cover the stub in kernel/skas) and the 
 setting of data to the correct initial values. 

 Also, if it was just not starting timers it would have been possible to 
 beat the process with USR2 on the head until its morale improves. Well, 
 while true; do kill -USR2 PID ; done does not change the behavior, it 
 still hangs and is still possible to terminate the errant process by 
 sending SIGSEGV to the UML thread which is shown as 100% CPU and in R state. 

Yes, sending USR2 should do the same. Correct.


 Problem is somewhere else. I am surprised it worked correctly in the 
 original one as there for 100% flat CPU usage it should have converged 
 to a behavior which is similar to what we have now. 

Mhh. Strange. Any hints how I can reproduce this?

I need to see the same behaviour, i.e. the hang on my machine to begin to 
understand what is going on here.

Thanks for testing Anton.



 A. 

  
  A. 
  
  Kind regards 
  Thomad 
  
  A 
  [snip] 
  
  A. 
  
  --
   
  One dashboard for servers and applications across Physical-Virtual-Cloud 
  Widest out-of-the-box monitoring support with 50+ applications 
  Performance metrics, stats and reports that give you Actionable Insights 
  Deep dive visibility with transaction tracing using APM Insight. 
  http://ad.doubleclick.net/ddm/clk/290420510;117567292;y 
  ___ 
  User-mode-linux-devel mailing list 
  User-mode-linux-devel@lists.sourceforge.net 
  https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel 
  


 --
  
 One dashboard for servers and applications across Physical-Virtual-Cloud 
 Widest out-of-the-box monitoring support with 50+ applications 
 Performance metrics, stats and reports that give you Actionable Insights 
 Deep dive visibility with transaction tracing using APM Insight. 
 http://ad.doubleclick.net/ddm/clk/290420510;117567292;y 
 ___ 
 User-mode-linux-devel mailing list 
 User-mode-linux-devel@lists.sourceforge.net 
 https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel 
--
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
___
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-10 Thread Richard Weinberger
Am 10.05.2015 um 16:34 schrieb Thomas Meyer:
 
 Am 10.05.2015 um 14:35 schrieb Richard Weinberger 
 richard.weinber...@gmail.com:

 On Sun, May 10, 2015 at 1:14 AM, Thomas Meyer tho...@m3y3r.de wrote:
 Hi,

 Changes:
 - also create posix timer in stub_clone_handler()
 - incorporated antons remarks

 Hm, this patch does a *lot* more than the changelog says.
 
 Hi, yes PATCH was probably the wrong keyword in the subject line. It should 
 have been RFC.
 I just wanted to have feedback of the current state of this patch/work.

Ahh, ok!

I was a bit confused as it contains beside the new features also new comments 
to unrelated
code, changes coding style, etc...


 I'm currently working on cleaning up the patch and switch from SIGUSR2 to 
 SIGNALRM, which seems to be the natural thing for posix timers.
 I will send this next patch as something that should be includable into the 
 kernel, i.e. With correct description and signed off line and so on.
 
 But feel free to have a look at v6 and give feedback.

I will. :-)

Thanks,
//richard

--
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
___
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-10 Thread Richard Weinberger
On Sun, May 10, 2015 at 1:14 AM, Thomas Meyer tho...@m3y3r.de wrote:
 Hi,

 Changes:
 - also create posix timer in stub_clone_handler()
 - incorporated antons remarks

Hm, this patch does a *lot* more than the changelog says.


 diff --git a/arch/um/Makefile b/arch/um/Makefile
 index 17d4460..a4a434f 100644
 --- a/arch/um/Makefile
 +++ b/arch/um/Makefile
 @@ -130,7 +130,7 @@ export LDS_ELF_FORMAT := $(ELF_FORMAT)
  # The wrappers will select whether using malloc or the kernel allocator.
  LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc

 -LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt))
 +LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt)) -lrt

  # Used by link-vmlinux.sh which has special support for um link
  export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE)
 diff --git a/arch/um/include/asm/irq.h b/arch/um/include/asm/irq.h
 index 4a2037f..0f2a5b1 100644
 --- a/arch/um/include/asm/irq.h
 +++ b/arch/um/include/asm/irq.h
 @@ -16,8 +16,9 @@
  #define TELNETD_IRQ12
  #define XTERM_IRQ  13
  #define RANDOM_IRQ 14
 +#define HRTIMER_IRQ15

 -#define LAST_IRQ RANDOM_IRQ
 +#define LAST_IRQ HRTIMER_IRQ
  #define NR_IRQS (LAST_IRQ + 1)

  #endif
 diff --git a/arch/um/include/shared/as-layout.h 
 b/arch/um/include/shared/as-layout.h
 index ca1843e..798aa6e 100644
 --- a/arch/um/include/shared/as-layout.h
 +++ b/arch/um/include/shared/as-layout.h
 @@ -17,7 +17,7 @@

  /* Some constant macros are used in both assembler and
   * C code.  Therefore we cannot annotate them always with
 - * 'UL' and other type specifiers unilaterally.  We
 + * 'UL' and other type specifiers unilaterally. We
   * use the following macros to deal with this.
   */

 @@ -28,6 +28,13 @@
  #define _UML_AC(X, Y)  __UML_AC(X, Y)
  #endif

 +/**
 + * userspace stub address space layout:
 + * Below macros define the layout of the stub code and data
 + * which are mapped in each userspace process:
 + *  - one page of code located at 0x10 followed by
 + *  - one page of data
 + */
  #define STUB_START _UML_AC(, 0x10)
  #define STUB_CODE _UML_AC((unsigned long), STUB_START)
  #define STUB_DATA _UML_AC((unsigned long), STUB_CODE + UM_KERN_PAGE_SIZE)
 diff --git a/arch/um/include/shared/kern_util.h 
 b/arch/um/include/shared/kern_util.h
 index 83a91f9..0282b36 100644
 --- a/arch/um/include/shared/kern_util.h
 +++ b/arch/um/include/shared/kern_util.h
 @@ -37,6 +37,7 @@ extern void initial_thread_cb(void (*proc)(void *), void 
 *arg);
  extern int is_syscall(unsigned long addr);

  extern void timer_handler(int sig, struct siginfo *unused_si, struct 
 uml_pt_regs *regs);
 +extern void hrtimer_handler(int sig, struct siginfo *unused_si, struct 
 uml_pt_regs *regs);

  extern int start_uml(void);
  extern void paging_init(void);
 diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
 index d824528..7f7368b 100644
 --- a/arch/um/include/shared/os.h
 +++ b/arch/um/include/shared/os.h
 @@ -217,7 +217,8 @@ extern int set_umid(char *name);
  extern char *get_umid(void);

  /* signal.c */
 -extern void timer_init(void);
 +extern void uml_timer_set_signal_handler(void);
 +extern void uml_hrtimer_set_signal_handler(void);
  extern void set_sigstack(void *sig_stack, int size);
  extern void remove_sigstack(void);
  extern void set_handler(int sig);
 @@ -238,12 +239,16 @@ extern void um_early_printk(const char *s, unsigned int 
 n);
  extern void os_fix_helper_signals(void);

  /* time.c */
 -extern void idle_sleep(unsigned long long nsecs);
 -extern int set_interval(void);
 -extern int timer_one_shot(int ticks);
 -extern long long disable_timer(void);
 +extern void os_idle_sleep(unsigned long long nsecs);
 +extern int os_timer_create(void* timer);
 +extern int os_timer_set_interval(void* timer, void* its);
 +extern int os_timer_one_shot(int ticks);
 +extern long long os_timer_disable(void);
 +extern long os_timer_remain(void* timer);
  extern void uml_idle_timer(void);
 +extern long long os_persistent_clock_emulation(void);
  extern long long os_nsecs(void);
 +extern long long os_vnsecs(void);

  /* skas/mem.c */
  extern long run_syscall_stub(struct mm_id * mm_idp,
 diff --git a/arch/um/include/shared/skas/stub-data.h 
 b/arch/um/include/shared/skas/stub-data.h
 index f6ed92c..f98b9e2 100644
 --- a/arch/um/include/shared/skas/stub-data.h
 +++ b/arch/um/include/shared/skas/stub-data.h
 @@ -6,12 +6,12 @@
  #ifndef __STUB_DATA_H
  #define __STUB_DATA_H

 -#include sys/time.h
 +#include time.h

  struct stub_data {
 -   long offset;
 +   unsigned long offset;
 int fd;
 -   struct itimerval timer;
 +   struct itimerspec timer;
 long err;
  };

 diff --git a/arch/um/include/shared/timer-internal.h 
 b/arch/um/include/shared/timer-internal.h
 new file mode 100644
 index 000..afdc6dc
 --- /dev/null
 +++ b/arch/um/include/shared/timer-internal.h
 @@ -0,0 +1,18 @@
 +/*
 + * Copyright (C) 2012 - 2014 Cisco Systems
 + * 

Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-10 Thread Anton Ivanov
On 10/05/15 15:34, Thomas Meyer wrote:
 Am 10.05.2015 um 14:35 schrieb Richard Weinberger 
 richard.weinber...@gmail.com:

 On Sun, May 10, 2015 at 1:14 AM, Thomas Meyer tho...@m3y3r.de wrote:
 Hi,

 Changes:
 - also create posix timer in stub_clone_handler()
 - incorporated antons remarks
 Hm, this patch does a *lot* more than the changelog says.
 Hi, yes PATCH was probably the wrong keyword in the subject line. It should 
 have been RFC.
 I just wanted to have feedback of the current state of this patch/work.

Looks good, does it test out good - I will tell you during the week. I 
already have most of the testcases set up from the period when I did 
only the kernel part.

The best test is running any of the kernel queueing disciplines. Stock 
UML is completely unable to do any of them correctly. I can probably 
concoct something related to timers and timeouts in protocols too to 
demo the breakage with the current timer state in these.


 I'm currently working on cleaning up the patch and switch from SIGUSR2 to 
 SIGNALRM,

If you mean SIGALRM that had some issues. I tried that originally and 
gave up - that is why the patch uses SIGUSR2 - it is something nobody 
uses and it did not interfere with the existing use of ALRM and VTALRM.

A.

   which seems to be the natural thing for posix timers.
 I will send this next patch as something that should be includable into the 
 kernel, i.e. With correct description and signed off line and so on.

 But feel free to have a look at v6 and give feedback.

 With kind regards
 Thomas

 diff --git a/arch/um/Makefile b/arch/um/Makefile
 index 17d4460..a4a434f 100644
 --- a/arch/um/Makefile
 +++ b/arch/um/Makefile
 @@ -130,7 +130,7 @@ export LDS_ELF_FORMAT := $(ELF_FORMAT)
 # The wrappers will select whether using malloc or the kernel allocator.
 LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc

 -LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt))
 +LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt)) -lrt

 # Used by link-vmlinux.sh which has special support for um link
 export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE)
 diff --git a/arch/um/include/asm/irq.h b/arch/um/include/asm/irq.h
 index 4a2037f..0f2a5b1 100644
 --- a/arch/um/include/asm/irq.h
 +++ b/arch/um/include/asm/irq.h
 @@ -16,8 +16,9 @@
 #define TELNETD_IRQ12
 #define XTERM_IRQ  13
 #define RANDOM_IRQ 14
 +#define HRTIMER_IRQ15

 -#define LAST_IRQ RANDOM_IRQ
 +#define LAST_IRQ HRTIMER_IRQ
 #define NR_IRQS (LAST_IRQ + 1)

 #endif
 diff --git a/arch/um/include/shared/as-layout.h 
 b/arch/um/include/shared/as-layout.h
 index ca1843e..798aa6e 100644
 --- a/arch/um/include/shared/as-layout.h
 +++ b/arch/um/include/shared/as-layout.h
 @@ -17,7 +17,7 @@

 /* Some constant macros are used in both assembler and
   * C code.  Therefore we cannot annotate them always with
 - * 'UL' and other type specifiers unilaterally.  We
 + * 'UL' and other type specifiers unilaterally. We
   * use the following macros to deal with this.
   */

 @@ -28,6 +28,13 @@
 #define _UML_AC(X, Y)  __UML_AC(X, Y)
 #endif

 +/**
 + * userspace stub address space layout:
 + * Below macros define the layout of the stub code and data
 + * which are mapped in each userspace process:
 + *  - one page of code located at 0x10 followed by
 + *  - one page of data
 + */
 #define STUB_START _UML_AC(, 0x10)
 #define STUB_CODE _UML_AC((unsigned long), STUB_START)
 #define STUB_DATA _UML_AC((unsigned long), STUB_CODE + UM_KERN_PAGE_SIZE)
 diff --git a/arch/um/include/shared/kern_util.h 
 b/arch/um/include/shared/kern_util.h
 index 83a91f9..0282b36 100644
 --- a/arch/um/include/shared/kern_util.h
 +++ b/arch/um/include/shared/kern_util.h
 @@ -37,6 +37,7 @@ extern void initial_thread_cb(void (*proc)(void *), void 
 *arg);
 extern int is_syscall(unsigned long addr);

 extern void timer_handler(int sig, struct siginfo *unused_si, struct 
 uml_pt_regs *regs);
 +extern void hrtimer_handler(int sig, struct siginfo *unused_si, struct 
 uml_pt_regs *regs);

 extern int start_uml(void);
 extern void paging_init(void);
 diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
 index d824528..7f7368b 100644
 --- a/arch/um/include/shared/os.h
 +++ b/arch/um/include/shared/os.h
 @@ -217,7 +217,8 @@ extern int set_umid(char *name);
 extern char *get_umid(void);

 /* signal.c */
 -extern void timer_init(void);
 +extern void uml_timer_set_signal_handler(void);
 +extern void uml_hrtimer_set_signal_handler(void);
 extern void set_sigstack(void *sig_stack, int size);
 extern void remove_sigstack(void);
 extern void set_handler(int sig);
 @@ -238,12 +239,16 @@ extern void um_early_printk(const char *s, unsigned 
 int n);
 extern void os_fix_helper_signals(void);

 /* time.c */
 -extern void idle_sleep(unsigned long long nsecs);
 -extern int set_interval(void);
 -extern int timer_one_shot(int ticks);
 -extern long long disable_timer(void);
 +extern void 

Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-10 Thread Anton Ivanov
On 10/05/15 13:35, Richard Weinberger wrote:
 On Sun, May 10, 2015 at 1:14 AM, Thomas Meyer tho...@m3y3r.de wrote:
 Hi,

 Changes:
 - also create posix timer in stub_clone_handler()
 - incorporated antons remarks
 Hm, this patch does a *lot* more than the changelog says.

Richard, I think this is what it takes to fix the timer subsystem and 
the patch does all of it:

1. Replace kernel itimer source with posix timers:
 1.1 os portion (new timer routines and a sleep routine).
 1.2. kernel portion - new IRQ routines for the posix timer
 1.3. A sprinkle of changes to support the fact that we now have one 
more IRQ.
2. Changes to userspace to support new timer source
3. Changes to stub invocation (added by Thomas in most recent revision).
4. Changes to idle.

I would love it to be smaller so we could change just the timer source, 
but I do not think this is possible. There are lots of moving parts 
which setup timer intervals in UML directly and they all need to be 
fixed for a proper timer replacement.

The result is worth it though - lots of things that did not quite work 
in UML (f.e. network qos, etc) start working.

I am going to give it some more testing this week, though based on 
reading it, it should just work (I have ran the bits from 1.1-1.3 for 4 
years now so they have quite a bit of mileage).

A.


 diff --git a/arch/um/Makefile b/arch/um/Makefile
 index 17d4460..a4a434f 100644
 --- a/arch/um/Makefile
 +++ b/arch/um/Makefile
 @@ -130,7 +130,7 @@ export LDS_ELF_FORMAT := $(ELF_FORMAT)
   # The wrappers will select whether using malloc or the kernel allocator.
   LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc

 -LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt))
 +LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt)) -lrt

   # Used by link-vmlinux.sh which has special support for um link
   export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE)
 diff --git a/arch/um/include/asm/irq.h b/arch/um/include/asm/irq.h
 index 4a2037f..0f2a5b1 100644
 --- a/arch/um/include/asm/irq.h
 +++ b/arch/um/include/asm/irq.h
 @@ -16,8 +16,9 @@
   #define TELNETD_IRQ12
   #define XTERM_IRQ  13
   #define RANDOM_IRQ 14
 +#define HRTIMER_IRQ15

 -#define LAST_IRQ RANDOM_IRQ
 +#define LAST_IRQ HRTIMER_IRQ
   #define NR_IRQS (LAST_IRQ + 1)

   #endif
 diff --git a/arch/um/include/shared/as-layout.h 
 b/arch/um/include/shared/as-layout.h
 index ca1843e..798aa6e 100644
 --- a/arch/um/include/shared/as-layout.h
 +++ b/arch/um/include/shared/as-layout.h
 @@ -17,7 +17,7 @@

   /* Some constant macros are used in both assembler and
* C code.  Therefore we cannot annotate them always with
 - * 'UL' and other type specifiers unilaterally.  We
 + * 'UL' and other type specifiers unilaterally. We
* use the following macros to deal with this.
*/

 @@ -28,6 +28,13 @@
   #define _UML_AC(X, Y)  __UML_AC(X, Y)
   #endif

 +/**
 + * userspace stub address space layout:
 + * Below macros define the layout of the stub code and data
 + * which are mapped in each userspace process:
 + *  - one page of code located at 0x10 followed by
 + *  - one page of data
 + */
   #define STUB_START _UML_AC(, 0x10)
   #define STUB_CODE _UML_AC((unsigned long), STUB_START)
   #define STUB_DATA _UML_AC((unsigned long), STUB_CODE + UM_KERN_PAGE_SIZE)
 diff --git a/arch/um/include/shared/kern_util.h 
 b/arch/um/include/shared/kern_util.h
 index 83a91f9..0282b36 100644
 --- a/arch/um/include/shared/kern_util.h
 +++ b/arch/um/include/shared/kern_util.h
 @@ -37,6 +37,7 @@ extern void initial_thread_cb(void (*proc)(void *), void 
 *arg);
   extern int is_syscall(unsigned long addr);

   extern void timer_handler(int sig, struct siginfo *unused_si, struct 
 uml_pt_regs *regs);
 +extern void hrtimer_handler(int sig, struct siginfo *unused_si, struct 
 uml_pt_regs *regs);

   extern int start_uml(void);
   extern void paging_init(void);
 diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
 index d824528..7f7368b 100644
 --- a/arch/um/include/shared/os.h
 +++ b/arch/um/include/shared/os.h
 @@ -217,7 +217,8 @@ extern int set_umid(char *name);
   extern char *get_umid(void);

   /* signal.c */
 -extern void timer_init(void);
 +extern void uml_timer_set_signal_handler(void);
 +extern void uml_hrtimer_set_signal_handler(void);
   extern void set_sigstack(void *sig_stack, int size);
   extern void remove_sigstack(void);
   extern void set_handler(int sig);
 @@ -238,12 +239,16 @@ extern void um_early_printk(const char *s, unsigned 
 int n);
   extern void os_fix_helper_signals(void);

   /* time.c */
 -extern void idle_sleep(unsigned long long nsecs);
 -extern int set_interval(void);
 -extern int timer_one_shot(int ticks);
 -extern long long disable_timer(void);
 +extern void os_idle_sleep(unsigned long long nsecs);
 +extern int os_timer_create(void* timer);
 +extern int os_timer_set_interval(void* timer, void* its);
 +extern int 

Re: [uml-devel] [PATCH v6] um: Add a high resolution timer subsystem

2015-05-10 Thread Thomas Meyer

 Am 10.05.2015 um 14:35 schrieb Richard Weinberger 
 richard.weinber...@gmail.com:
 
 On Sun, May 10, 2015 at 1:14 AM, Thomas Meyer tho...@m3y3r.de wrote:
 Hi,
 
 Changes:
 - also create posix timer in stub_clone_handler()
 - incorporated antons remarks
 
 Hm, this patch does a *lot* more than the changelog says.

Hi, yes PATCH was probably the wrong keyword in the subject line. It should 
have been RFC.
I just wanted to have feedback of the current state of this patch/work.

I'm currently working on cleaning up the patch and switch from SIGUSR2 to 
SIGNALRM, which seems to be the natural thing for posix timers.
I will send this next patch as something that should be includable into the 
kernel, i.e. With correct description and signed off line and so on.

But feel free to have a look at v6 and give feedback.

With kind regards
Thomas

 
 
 diff --git a/arch/um/Makefile b/arch/um/Makefile
 index 17d4460..a4a434f 100644
 --- a/arch/um/Makefile
 +++ b/arch/um/Makefile
 @@ -130,7 +130,7 @@ export LDS_ELF_FORMAT := $(ELF_FORMAT)
 # The wrappers will select whether using malloc or the kernel allocator.
 LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
 
 -LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt))
 +LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt)) -lrt
 
 # Used by link-vmlinux.sh which has special support for um link
 export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE)
 diff --git a/arch/um/include/asm/irq.h b/arch/um/include/asm/irq.h
 index 4a2037f..0f2a5b1 100644
 --- a/arch/um/include/asm/irq.h
 +++ b/arch/um/include/asm/irq.h
 @@ -16,8 +16,9 @@
 #define TELNETD_IRQ12
 #define XTERM_IRQ  13
 #define RANDOM_IRQ 14
 +#define HRTIMER_IRQ15
 
 -#define LAST_IRQ RANDOM_IRQ
 +#define LAST_IRQ HRTIMER_IRQ
 #define NR_IRQS (LAST_IRQ + 1)
 
 #endif
 diff --git a/arch/um/include/shared/as-layout.h 
 b/arch/um/include/shared/as-layout.h
 index ca1843e..798aa6e 100644
 --- a/arch/um/include/shared/as-layout.h
 +++ b/arch/um/include/shared/as-layout.h
 @@ -17,7 +17,7 @@
 
 /* Some constant macros are used in both assembler and
  * C code.  Therefore we cannot annotate them always with
 - * 'UL' and other type specifiers unilaterally.  We
 + * 'UL' and other type specifiers unilaterally. We
  * use the following macros to deal with this.
  */
 
 @@ -28,6 +28,13 @@
 #define _UML_AC(X, Y)  __UML_AC(X, Y)
 #endif
 
 +/**
 + * userspace stub address space layout:
 + * Below macros define the layout of the stub code and data
 + * which are mapped in each userspace process:
 + *  - one page of code located at 0x10 followed by
 + *  - one page of data
 + */
 #define STUB_START _UML_AC(, 0x10)
 #define STUB_CODE _UML_AC((unsigned long), STUB_START)
 #define STUB_DATA _UML_AC((unsigned long), STUB_CODE + UM_KERN_PAGE_SIZE)
 diff --git a/arch/um/include/shared/kern_util.h 
 b/arch/um/include/shared/kern_util.h
 index 83a91f9..0282b36 100644
 --- a/arch/um/include/shared/kern_util.h
 +++ b/arch/um/include/shared/kern_util.h
 @@ -37,6 +37,7 @@ extern void initial_thread_cb(void (*proc)(void *), void 
 *arg);
 extern int is_syscall(unsigned long addr);
 
 extern void timer_handler(int sig, struct siginfo *unused_si, struct 
 uml_pt_regs *regs);
 +extern void hrtimer_handler(int sig, struct siginfo *unused_si, struct 
 uml_pt_regs *regs);
 
 extern int start_uml(void);
 extern void paging_init(void);
 diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
 index d824528..7f7368b 100644
 --- a/arch/um/include/shared/os.h
 +++ b/arch/um/include/shared/os.h
 @@ -217,7 +217,8 @@ extern int set_umid(char *name);
 extern char *get_umid(void);
 
 /* signal.c */
 -extern void timer_init(void);
 +extern void uml_timer_set_signal_handler(void);
 +extern void uml_hrtimer_set_signal_handler(void);
 extern void set_sigstack(void *sig_stack, int size);
 extern void remove_sigstack(void);
 extern void set_handler(int sig);
 @@ -238,12 +239,16 @@ extern void um_early_printk(const char *s, unsigned 
 int n);
 extern void os_fix_helper_signals(void);
 
 /* time.c */
 -extern void idle_sleep(unsigned long long nsecs);
 -extern int set_interval(void);
 -extern int timer_one_shot(int ticks);
 -extern long long disable_timer(void);
 +extern void os_idle_sleep(unsigned long long nsecs);
 +extern int os_timer_create(void* timer);
 +extern int os_timer_set_interval(void* timer, void* its);
 +extern int os_timer_one_shot(int ticks);
 +extern long long os_timer_disable(void);
 +extern long os_timer_remain(void* timer);
 extern void uml_idle_timer(void);
 +extern long long os_persistent_clock_emulation(void);
 extern long long os_nsecs(void);
 +extern long long os_vnsecs(void);
 
 /* skas/mem.c */
 extern long run_syscall_stub(struct mm_id * mm_idp,
 diff --git a/arch/um/include/shared/skas/stub-data.h 
 b/arch/um/include/shared/skas/stub-data.h
 index f6ed92c..f98b9e2 100644
 --- a/arch/um/include/shared/skas/stub-data.h
 +++