* [PATCH] tools: fix build after recent xenpaging changes
@ 2011-06-24 12:16 Tim Deegan
2011-06-24 12:24 ` Olaf Hering
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Tim Deegan @ 2011-06-24 12:16 UTC (permalink / raw)
To: xen-devel
tools: fix build after recent xenpaging changes
xenpaging now uses pthreads, so must link appropriately.
Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
diff -r 2633588c2427 tools/xenpaging/Makefile
--- a/tools/xenpaging/Makefile Fri Jun 24 13:03:38 2011 +0100
+++ b/tools/xenpaging/Makefile Fri Jun 24 13:10:34 2011 +0100
@@ -2,7 +2,7 @@ XEN_ROOT=$(CURDIR)/../..
include $(XEN_ROOT)/tools/Rules.mk
CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore)
-LDLIBS += $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore)
+LDLIBS += $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) -pthread
POLICY = default
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] tools: fix build after recent xenpaging changes
2011-06-24 12:16 [PATCH] tools: fix build after recent xenpaging changes Tim Deegan
@ 2011-06-24 12:24 ` Olaf Hering
2011-06-24 12:33 ` Ian Campbell
2011-06-27 13:50 ` Ian Jackson
2 siblings, 0 replies; 11+ messages in thread
From: Olaf Hering @ 2011-06-24 12:24 UTC (permalink / raw)
To: Tim Deegan; +Cc: xen-devel
On Fri, Jun 24, Tim Deegan wrote:
> tools: fix build after recent xenpaging changes
> xenpaging now uses pthreads, so must link appropriately.
>
> Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
Acked-by: Olaf Hering <olaf@aepfle.de>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] tools: fix build after recent xenpaging changes
2011-06-24 12:16 [PATCH] tools: fix build after recent xenpaging changes Tim Deegan
2011-06-24 12:24 ` Olaf Hering
@ 2011-06-24 12:33 ` Ian Campbell
2011-06-24 13:32 ` Olaf Hering
2011-06-27 13:50 ` Ian Jackson
2 siblings, 1 reply; 11+ messages in thread
From: Ian Campbell @ 2011-06-24 12:33 UTC (permalink / raw)
To: Tim Deegan, Olaf Hering; +Cc: xen-devel@lists.xensource.com
On Fri, 2011-06-24 at 13:16 +0100, Tim Deegan wrote:
> tools: fix build after recent xenpaging changes
> xenpaging now uses pthreads, so must link appropriately.
Why does 23625:c49e22648d0e need a new thread to do the page in on exit?
Can't it just signal the main loop to do it?
Also page_in_trigger doesn't seem safe to me:
+void page_in_trigger(unsigned long gfn)
+{
+ if (!page_in_possible)
+ return;
+
+ pthread_mutex_lock(&page_in_mutex);
+ page_in_gfn = gfn;
+ pthread_mutex_unlock(&page_in_mutex);
+ pthread_cond_signal(&page_in_cond);
+}
Two back to back calls to this function (which is what the caller will
do) will both update page_in_gfn without the page in thread necessarily
running in the interim. i.e. the first gfn may be missed. I don't think
pthread_cond_signal makes any guarantees about whether this thread or
the signalled thread will run afterwards. For this approach to woek
page_in_gfn really needs to remain locked until the page in thread has
finished with that particular entry, or you need s return signal, or a
queue, or whatever.
I suppose you could also push the "/* Write all pages back into the
guest */" loop down into the thread rather than feeding the thread mfns
one-by-one.
Ian.
>
> Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
>
> diff -r 2633588c2427 tools/xenpaging/Makefile
> --- a/tools/xenpaging/Makefile Fri Jun 24 13:03:38 2011 +0100
> +++ b/tools/xenpaging/Makefile Fri Jun 24 13:10:34 2011 +0100
> @@ -2,7 +2,7 @@ XEN_ROOT=$(CURDIR)/../..
> include $(XEN_ROOT)/tools/Rules.mk
>
> CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore)
> -LDLIBS += $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore)
> +LDLIBS += $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) -pthread
>
> POLICY = default
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] tools: fix build after recent xenpaging changes
2011-06-24 12:33 ` Ian Campbell
@ 2011-06-24 13:32 ` Olaf Hering
2011-06-24 13:48 ` Ian Campbell
0 siblings, 1 reply; 11+ messages in thread
From: Olaf Hering @ 2011-06-24 13:32 UTC (permalink / raw)
To: Ian Campbell; +Cc: xen-devel@lists.xensource.com, Tim Deegan
On Fri, Jun 24, Ian Campbell wrote:
> On Fri, 2011-06-24 at 13:16 +0100, Tim Deegan wrote:
> > tools: fix build after recent xenpaging changes
> > xenpaging now uses pthreads, so must link appropriately.
>
> Why does 23625:c49e22648d0e need a new thread to do the page in on exit?
> Can't it just signal the main loop to do it?
If the page is mappend and the gfn is not there, the attempt to map it
may block. I havent tried it, and I think the current code will not
block (linux_privcmd_map_foreign_bulk will just loop).
If it does block, the mainloop can not proceed and process the page-in
request.
> Also page_in_trigger doesn't seem safe to me:
> +void page_in_trigger(unsigned long gfn)
> +{
> + if (!page_in_possible)
> + return;
> +
> + pthread_mutex_lock(&page_in_mutex);
> + page_in_gfn = gfn;
> + pthread_mutex_unlock(&page_in_mutex);
> + pthread_cond_signal(&page_in_cond);
> +}
>
> Two back to back calls to this function (which is what the caller will
> do) will both update page_in_gfn without the page in thread necessarily
> running in the interim. i.e. the first gfn may be missed. I don't think
> pthread_cond_signal makes any guarantees about whether this thread or
> the signalled thread will run afterwards. For this approach to woek
> page_in_gfn really needs to remain locked until the page in thread has
> finished with that particular entry, or you need s return signal, or a
> queue, or whatever.
Its coded after an example in the APUE book. The page-in thread grabs a
copy of page_in_gfn. Are you saying page_in_trigger() can be called
more than once while xc_map_foreign_pages()/munmap() is being called?
If the caller of page_in_trigger will find the gfn is still in paging
state, it will just try again.
Olaf
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] tools: fix build after recent xenpaging changes
2011-06-24 13:32 ` Olaf Hering
@ 2011-06-24 13:48 ` Ian Campbell
2011-06-24 13:57 ` Olaf Hering
0 siblings, 1 reply; 11+ messages in thread
From: Ian Campbell @ 2011-06-24 13:48 UTC (permalink / raw)
To: Olaf Hering; +Cc: Tim Deegan, xen-devel@lists.xensource.com
On Fri, 2011-06-24 at 14:32 +0100, Olaf Hering wrote:
> On Fri, Jun 24, Ian Campbell wrote:
>
> > On Fri, 2011-06-24 at 13:16 +0100, Tim Deegan wrote:
> > > tools: fix build after recent xenpaging changes
> > > xenpaging now uses pthreads, so must link appropriately.
> >
> > Why does 23625:c49e22648d0e need a new thread to do the page in on exit?
> > Can't it just signal the main loop to do it?
>
> If the page is mappend and the gfn is not there, the attempt to map it
> may block. I havent tried it, and I think the current code will not
> block (linux_privcmd_map_foreign_bulk will just loop).
> If it does block, the mainloop can not proceed and process the page-in
> request.
It doesn't return EINTR due to the signal?
I wonder if it would be worth investigating setjmp here?
>
> > Also page_in_trigger doesn't seem safe to me:
> > +void page_in_trigger(unsigned long gfn)
> > +{
> > + if (!page_in_possible)
> > + return;
> > +
> > + pthread_mutex_lock(&page_in_mutex);
> > + page_in_gfn = gfn;
> > + pthread_mutex_unlock(&page_in_mutex);
> > + pthread_cond_signal(&page_in_cond);
> > +}
> >
> > Two back to back calls to this function (which is what the caller will
> > do) will both update page_in_gfn without the page in thread necessarily
> > running in the interim. i.e. the first gfn may be missed. I don't think
> > pthread_cond_signal makes any guarantees about whether this thread or
> > the signalled thread will run afterwards. For this approach to woek
> > page_in_gfn really needs to remain locked until the page in thread has
> > finished with that particular entry, or you need s return signal, or a
> > queue, or whatever.
>
> Its coded after an example in the APUE book. The page-in thread grabs a
> copy of page_in_gfn.
But there is no interlock between the page-in thread and page-in
trigger. IOW it is possible to do
>loop over pages
page_in_trigger(1)
lock
page_in_gfn = 1
unlock
signal page-in thread (but it doesn't get scheduled yet, for whatever reason)
>next iteration of loop
page_in_trigger(2)
lock
page_in_gfn = 2
unlock
>>> page-in thread (signalled above) finally gets to run and preempts us
page_in_thread
lock
read page_in_gfn ==> 2 *** we've missed page 1 ***
unlock
> Are you saying page_in_trigger() can be called
> more than once while xc_map_foreign_pages()/munmap() is being called?
The loop is:
for ( i = 0; i < paging->domain_info->max_pages; i++ )
{
if ( test_bit(i, paging->bitmap) )
{
page_in_trigger(i);
break;
}
}
There is nothing to stop it going round again as fast as it wants. The
xc_map_foreign_pages()/munmap() are in another thread and so can be
running in parallel and/or you don't control the preemption between the
two threads.
In fact since the page-in thread is doing relatively expensive work I'd
expect that the trigger loop would get to run several iterations for
each time the page-in loop ran..
>
> If the caller of page_in_trigger will find the gfn is still in paging
> state, it will just try again.
I don't see where it would go back and try page 1 again if it gets
missed (as in the above example)
Ian.
>
> Olaf
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] tools: fix build after recent xenpaging changes
2011-06-24 13:48 ` Ian Campbell
@ 2011-06-24 13:57 ` Olaf Hering
2011-06-24 14:30 ` Ian Campbell
0 siblings, 1 reply; 11+ messages in thread
From: Olaf Hering @ 2011-06-24 13:57 UTC (permalink / raw)
To: Ian Campbell; +Cc: Tim Deegan, xen-devel@lists.xensource.com
On Fri, Jun 24, Ian Campbell wrote:
> In fact since the page-in thread is doing relatively expensive work I'd
> expect that the trigger loop would get to run several iterations for
> each time the page-in loop ran..
That did not happen for me, I will think about it.
> > If the caller of page_in_trigger will find the gfn is still in paging
> > state, it will just try again.
>
> I don't see where it would go back and try page 1 again if it gets
> missed (as in the above example)
The break exits the for() loop, not the while(1). In the next iteration
page 1 may still be in paging->bitmap and tried again.
Olaf
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] tools: fix build after recent xenpaging changes
2011-06-24 13:57 ` Olaf Hering
@ 2011-06-24 14:30 ` Ian Campbell
2011-06-24 14:35 ` Olaf Hering
0 siblings, 1 reply; 11+ messages in thread
From: Ian Campbell @ 2011-06-24 14:30 UTC (permalink / raw)
To: Olaf Hering; +Cc: Tim Deegan, xen-devel@lists.xensource.com
On Fri, 2011-06-24 at 14:57 +0100, Olaf Hering wrote:
> On Fri, Jun 24, Ian Campbell wrote:
>
> > In fact since the page-in thread is doing relatively expensive work I'd
> > expect that the trigger loop would get to run several iterations for
> > each time the page-in loop ran..
>
> That did not happen for me, I will think about it.
It possibly doesn't matter, based on hat you said below, since you will
come back round and try again. It makes the existing locking a bit
pointless though I think, since you are in "fast-and-lose-mode" already.
> > > If the caller of page_in_trigger will find the gfn is still in paging
> > > state, it will just try again.
> >
> > I don't see where it would go back and try page 1 again if it gets
> > missed (as in the above example)
>
> The break exits the for() loop, not the while(1). In the next iteration
> page 1 may still be in paging->bitmap and tried again.
I'd missed the interrupted -> 1 in the while loop. I presume there is
some other exit condition which triggers once everything has been paged
back in and actually causes the daemon to exit?
Ian.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] tools: fix build after recent xenpaging changes
2011-06-24 14:30 ` Ian Campbell
@ 2011-06-24 14:35 ` Olaf Hering
2011-06-24 14:41 ` Ian Campbell
0 siblings, 1 reply; 11+ messages in thread
From: Olaf Hering @ 2011-06-24 14:35 UTC (permalink / raw)
To: Ian Campbell; +Cc: Tim Deegan, xen-devel@lists.xensource.com
On Fri, Jun 24, Ian Campbell wrote:
> > The break exits the for() loop, not the while(1). In the next iteration
> > page 1 may still be in paging->bitmap and tried again.
>
> I'd missed the interrupted -> 1 in the while loop. I presume there is
> some other exit condition which triggers once everything has been paged
> back in and actually causes the daemon to exit?
If the for() loop found nothing, then this triggers:
775 /* If no more pages to process, exit loop */
776 if ( i == paging->domain_info->max_pages )
777 break;
Olaf
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] tools: fix build after recent xenpaging changes
2011-06-24 14:35 ` Olaf Hering
@ 2011-06-24 14:41 ` Ian Campbell
2011-06-24 15:24 ` Olaf Hering
0 siblings, 1 reply; 11+ messages in thread
From: Ian Campbell @ 2011-06-24 14:41 UTC (permalink / raw)
To: Olaf Hering; +Cc: Tim Deegan, xen-devel@lists.xensource.com
On Fri, 2011-06-24 at 15:35 +0100, Olaf Hering wrote:
> On Fri, Jun 24, Ian Campbell wrote:
>
> > > The break exits the for() loop, not the while(1). In the next iteration
> > > page 1 may still be in paging->bitmap and tried again.
> >
> > I'd missed the interrupted -> 1 in the while loop. I presume there is
> > some other exit condition which triggers once everything has been paged
> > back in and actually causes the daemon to exit?
>
> If the for() loop found nothing, then this triggers:
>
> 775 /* If no more pages to process, exit loop */
> 776 if ( i == paging->domain_info->max_pages )
> 777 break;
Oh yes.
It's a bit counter intuitive to have a for loop which only processes the
first thing it finds and then relying on going round another outer loop
to pickup the second etc. It's at least O(N^2), isn't it?
Why not
count = 0;
for ( i = 0; i < paging->domain_info->max_pages; i++ )
{
if ( test_bit(i, paging->bitmap) )
{
page_in_trigger(i);
count++
}
}
/* If no more pages to process, exit loop */
if ( !count )
break;
That will at least process as many pages as it can on each iteration
through the outer loop. Although it will most likely exacerbate the
locking issue I pointed to earlier.
Ian.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] tools: fix build after recent xenpaging changes
2011-06-24 14:41 ` Ian Campbell
@ 2011-06-24 15:24 ` Olaf Hering
0 siblings, 0 replies; 11+ messages in thread
From: Olaf Hering @ 2011-06-24 15:24 UTC (permalink / raw)
To: Ian Campbell; +Cc: Tim Deegan, xen-devel@lists.xensource.com
On Fri, Jun 24, Ian Campbell wrote:
> On Fri, 2011-06-24 at 15:35 +0100, Olaf Hering wrote:
> > On Fri, Jun 24, Ian Campbell wrote:
> >
> > > > The break exits the for() loop, not the while(1). In the next iteration
> > > > page 1 may still be in paging->bitmap and tried again.
> > >
> > > I'd missed the interrupted -> 1 in the while loop. I presume there is
> > > some other exit condition which triggers once everything has been paged
> > > back in and actually causes the daemon to exit?
> >
> > If the for() loop found nothing, then this triggers:
> >
> > 775 /* If no more pages to process, exit loop */
> > 776 if ( i == paging->domain_info->max_pages )
> > 777 break;
>
> Oh yes.
>
> It's a bit counter intuitive to have a for loop which only processes the
> first thing it finds and then relying on going round another outer loop
> to pickup the second etc. It's at least O(N^2), isn't it?
>
> Why not
> count = 0;
> for ( i = 0; i < paging->domain_info->max_pages; i++ )
> {
> if ( test_bit(i, paging->bitmap) )
> {
> page_in_trigger(i);
> count++
> }
> }
> /* If no more pages to process, exit loop */
> if ( !count )
> break;
>
> That will at least process as many pages as it can on each iteration
> through the outer loop. Although it will most likely exacerbate the
> locking issue I pointed to earlier.
I think an early version of my change had something like that, but it
did not fillup the ringbuffer for some reason.
I will look at this change again and see what can be improved.
Olaf
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] tools: fix build after recent xenpaging changes
2011-06-24 12:16 [PATCH] tools: fix build after recent xenpaging changes Tim Deegan
2011-06-24 12:24 ` Olaf Hering
2011-06-24 12:33 ` Ian Campbell
@ 2011-06-27 13:50 ` Ian Jackson
2 siblings, 0 replies; 11+ messages in thread
From: Ian Jackson @ 2011-06-27 13:50 UTC (permalink / raw)
To: Tim Deegan; +Cc: xen-devel
Tim Deegan writes ("[Xen-devel] [PATCH] tools: fix build after recent xenpaging changes"):
> tools: fix build after recent xenpaging changes
> xenpaging now uses pthreads, so must link appropriately.
Thanks, I've applied this. Sorry, I got distracted by the huge
thread. We can fix the thread-safety problems in xenpaging at our
leisure.
> -LDLIBS += $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore)
> +LDLIBS += $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) -pthread
Arguably config/StdGNU.mk should say
PTHREAD_LIBS = -pthread
and we should use that here.
Ian.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2011-06-27 13:50 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-24 12:16 [PATCH] tools: fix build after recent xenpaging changes Tim Deegan
2011-06-24 12:24 ` Olaf Hering
2011-06-24 12:33 ` Ian Campbell
2011-06-24 13:32 ` Olaf Hering
2011-06-24 13:48 ` Ian Campbell
2011-06-24 13:57 ` Olaf Hering
2011-06-24 14:30 ` Ian Campbell
2011-06-24 14:35 ` Olaf Hering
2011-06-24 14:41 ` Ian Campbell
2011-06-24 15:24 ` Olaf Hering
2011-06-27 13:50 ` Ian Jackson
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.