public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 2/3] Get pending events in random
  2016-09-26  2:25 [PATCH 0/3] Support range stepping on software single-step target Yao Qi
  2016-09-26  2:25 ` [PATCH 3/3] Enable range stepping if software single step is supported Yao Qi
@ 2016-09-26  2:25 ` Yao Qi
  2016-09-26  2:47 ` [PATCH 1/3] Remove single-step breakpoint for GDBserver internal event Yao Qi
  2016-10-10  8:43 ` [PATCH 0/3] Support range stepping on software single-step target Yao Qi
  3 siblings, 0 replies; 13+ messages in thread
From: Yao Qi @ 2016-09-26  2:25 UTC (permalink / raw)
  To: gdb-patches

Nowadays, we select events to be reported to GDB in random, however
that is not enough when many GDBserver internal events (not reported
to GDB) are generated.

GDBserver pulls all events out of kernel via waitpid, and leave them
pending.  When goes through threads which have pending events,
GDBserver uses find_inferior to find the first thread which has
pending event, and consumes it.  Note that find_inferior always
iterate threads in a fixed order.  If multiple threads keep hitting
GDBserver breakpoints, range stepping with single-step breakpoint for
example, threads in the head of the thread list are more likely to be
processed and threads in the tail are starved.  This causes some timeout
fails in gdb.threads/non-stop-fair-events.exp when range stepping is
enabled on arm-linux.

This patch fixes this issue by randomly selecting pending events.  It
adds a new function find_inferior_in_random, which iterates threads
which have pending events randomly.

gdb/gdbserver:

2016-09-25  Yao Qi  <yao.qi@linaro.org>

	* inferiors.c (find_inferior_in_random): New function.
	* inferiors.h (find_inferior_in_random): Declare.
	* linux-low.c (linux_wait_for_event_filtered): Call
	find_inferior_in_random instead of find_inferior.
---
 gdb/gdbserver/inferiors.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 gdb/gdbserver/inferiors.h |  5 +++++
 gdb/gdbserver/linux-low.c |  6 ++++--
 3 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c
index 7888f3c..574a7ba 100644
--- a/gdb/gdbserver/inferiors.c
+++ b/gdb/gdbserver/inferiors.c
@@ -248,6 +248,51 @@ find_inferior (struct inferior_list *list,
   return NULL;
 }
 
+/* Find the random inferior_list_entry E in LIST for which FUNC (E, ARG)
+   returns non-zero.  If no entry is found then return NULL.  */
+
+struct inferior_list_entry *
+find_inferior_in_random (struct inferior_list *list,
+			 int (*func) (struct inferior_list_entry *, void *),
+			 void *arg)
+{
+  struct inferior_list_entry *inf = list->head;
+  int count = 0;
+  int random_selector;
+
+  /* First count how many interesting entries we have.  */
+  while (inf != NULL)
+    {
+      struct inferior_list_entry *next;
+
+      next = inf->next;
+      if ((*func) (inf, arg))
+	count++;
+      inf = next;
+    }
+
+  if (count == 0)
+    return NULL;
+
+  /* Now randomly pick an entry out of those.  */
+  random_selector = (int)
+    ((count * (double) rand ()) / (RAND_MAX + 1.0));
+
+  inf = list->head;
+  while (inf != NULL)
+    {
+      struct inferior_list_entry *next;
+
+      next = inf->next;
+      if ((*func) (inf, arg) && (random_selector-- == 0))
+	return inf;
+      inf = next;
+    }
+
+  gdb_assert_not_reached ("failed to find an inferior in random.");
+  return NULL;
+}
+
 struct inferior_list_entry *
 find_inferior_id (struct inferior_list *list, ptid_t id)
 {
diff --git a/gdb/gdbserver/inferiors.h b/gdb/gdbserver/inferiors.h
index 65ab1c6..6ea7a99 100644
--- a/gdb/gdbserver/inferiors.h
+++ b/gdb/gdbserver/inferiors.h
@@ -154,6 +154,11 @@ struct inferior_list_entry *find_inferior
       void *arg);
 struct inferior_list_entry *find_inferior_id (struct inferior_list *list,
 					      ptid_t id);
+struct inferior_list_entry *
+  find_inferior_in_random (struct inferior_list *,
+			   int (*func) (struct inferior_list_entry *,
+					void *),
+			   void *arg);
 
 void *inferior_target_data (struct thread_info *);
 void set_inferior_target_data (struct thread_info *, void *);
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index fd3cd5a..25dd60c 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -2695,7 +2695,8 @@ linux_wait_for_event_filtered (ptid_t wait_ptid, ptid_t filter_ptid,
   if (ptid_equal (filter_ptid, minus_one_ptid) || ptid_is_pid (filter_ptid))
     {
       event_thread = (struct thread_info *)
-	find_inferior (&all_threads, status_pending_p_callback, &filter_ptid);
+	find_inferior_in_random (&all_threads, status_pending_p_callback,
+				 &filter_ptid);
       if (event_thread != NULL)
 	event_child = get_thread_lwp (event_thread);
       if (debug_threads && event_thread)
@@ -2806,7 +2807,8 @@ linux_wait_for_event_filtered (ptid_t wait_ptid, ptid_t filter_ptid,
       /* ... and find an LWP with a status to report to the core, if
 	 any.  */
       event_thread = (struct thread_info *)
-	find_inferior (&all_threads, status_pending_p_callback, &filter_ptid);
+	find_inferior_in_random (&all_threads, status_pending_p_callback,
+				 &filter_ptid);
       if (event_thread != NULL)
 	{
 	  event_child = get_thread_lwp (event_thread);
-- 
1.9.1

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

* [PATCH 0/3] Support range stepping on software single-step target
@ 2016-09-26  2:25 Yao Qi
  2016-09-26  2:25 ` [PATCH 3/3] Enable range stepping if software single step is supported Yao Qi
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Yao Qi @ 2016-09-26  2:25 UTC (permalink / raw)
  To: gdb-patches

This patch series enables the range stepping on targets support software
single-step, although arm-linux is the only target nowadays.

Patch 1 is to remove single-step breakpoints for GDBserver internal
events.  Patch 2 teaches GDBserver to gen pending events from threads
in random to avoid starvation.  Patch 3 is to enable range stepping
if software single-step is supported.

Regression tested arm-linux and x86_64-linux.

*** BLURB HERE ***

Yao Qi (3):
  Remove single-step breakpoint for GDBserver internal event
  Get pending events in random
  Enable range stepping if software single step is supported

 gdb/gdbserver/inferiors.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 gdb/gdbserver/inferiors.h |  5 +++++
 gdb/gdbserver/linux-low.c | 40 +++++++++++++++++++++++++++++-----------
 3 files changed, 79 insertions(+), 11 deletions(-)

-- 
1.9.1

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

* [PATCH 3/3] Enable range stepping if software single step is supported
  2016-09-26  2:25 [PATCH 0/3] Support range stepping on software single-step target Yao Qi
@ 2016-09-26  2:25 ` Yao Qi
  2016-09-26  2:25 ` [PATCH 2/3] Get pending events in random Yao Qi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 13+ messages in thread
From: Yao Qi @ 2016-09-26  2:25 UTC (permalink / raw)
  To: gdb-patches

If the target can do software single step, it can do range
stepping.

gdb/gdbserver:

2016-09-15  Yao Qi  <yao.qi@linaro.org>

	* linux-low.c (linux_supports_agent): Return true if
	can_software_single_step return true.
---
 gdb/gdbserver/linux-low.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 25dd60c..56178c5 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -6447,6 +6447,8 @@ linux_supports_agent (void)
 static int
 linux_supports_range_stepping (void)
 {
+  if (can_software_single_step ())
+    return 1;
   if (*the_low_target.supports_range_stepping == NULL)
     return 0;
 
-- 
1.9.1

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

* [PATCH 1/3] Remove single-step breakpoint for GDBserver internal event
  2016-09-26  2:25 [PATCH 0/3] Support range stepping on software single-step target Yao Qi
  2016-09-26  2:25 ` [PATCH 3/3] Enable range stepping if software single step is supported Yao Qi
  2016-09-26  2:25 ` [PATCH 2/3] Get pending events in random Yao Qi
@ 2016-09-26  2:47 ` Yao Qi
  2016-10-26 17:45   ` Pedro Alves
  2016-10-10  8:43 ` [PATCH 0/3] Support range stepping on software single-step target Yao Qi
  3 siblings, 1 reply; 13+ messages in thread
From: Yao Qi @ 2016-09-26  2:47 UTC (permalink / raw)
  To: gdb-patches

This patch removes single-step breakpoints if the event is only
GDBserver internal, IOW, isn't reported back to GDB.

gdb/gdbserver:

2016-09-25  Yao Qi  <yao.qi@linaro.org>

	* linux-low.c (linux_wait_1): If single-step breakpoints are
	inserted, remove them.
---
 gdb/gdbserver/linux-low.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 4203b92..fd3cd5a 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -3670,17 +3670,31 @@ linux_wait_1 (ptid_t ptid,
 	  (*the_low_target.set_pc) (regcache, event_child->stop_pc);
 	}
 
-      /* We may have finished stepping over a breakpoint.  If so,
-	 we've stopped and suspended all LWPs momentarily except the
-	 stepping one.  This is where we resume them all again.  We're
-	 going to keep waiting, so use proceed, which handles stepping
-	 over the next breakpoint.  */
-      if (debug_threads)
-	debug_printf ("proceeding all threads.\n");
-
       if (step_over_finished)
-	unsuspend_all_lwps (event_child);
+	{
+	  /* If we have finished stepping over a breakpoint, we've
+	     stopped and suspended all LWPs momentarily except the
+	     stepping one.  This is where we resume them all again.
+	     We're going to keep waiting, so use proceed, which
+	     handles stepping over the next breakpoint.  */
+	  unsuspend_all_lwps (event_child);
+	}
+      else
+	{
+	  /* Remove the single-step breakpoints if any.  Note that
+	     there isn't single-step breakpoint if we finished stepping
+	     over.  */
+	  if (can_software_single_step ()
+	      && has_single_step_breakpoints (current_thread))
+	    {
+	      stop_all_lwps (0, event_child);
+	      delete_single_step_breakpoints (current_thread);
+	      unstop_all_lwps (0, event_child);
+	    }
+	}
 
+      if (debug_threads)
+	debug_printf ("proceeding all threads.\n");
       proceed_all_lwps ();
       return ignore_event (ourstatus);
     }
-- 
1.9.1

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

* Re: [PATCH 0/3] Support range stepping on software single-step target
  2016-09-26  2:25 [PATCH 0/3] Support range stepping on software single-step target Yao Qi
                   ` (2 preceding siblings ...)
  2016-09-26  2:47 ` [PATCH 1/3] Remove single-step breakpoint for GDBserver internal event Yao Qi
@ 2016-10-10  8:43 ` Yao Qi
  2016-10-26 15:39   ` Yao Qi
  3 siblings, 1 reply; 13+ messages in thread
From: Yao Qi @ 2016-10-10  8:43 UTC (permalink / raw)
  To: gdb-patches

Yao Qi <qiyaoltc@gmail.com> writes:

> This patch series enables the range stepping on targets support software
> single-step, although arm-linux is the only target nowadays.
>
> Patch 1 is to remove single-step breakpoints for GDBserver internal
> events.  Patch 2 teaches GDBserver to gen pending events from threads
> in random to avoid starvation.  Patch 3 is to enable range stepping
> if software single-step is supported.
>
> Regression tested arm-linux and x86_64-linux.

Ping.

-- 
Yao (齐尧)

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

* Re: [PATCH 0/3] Support range stepping on software single-step target
  2016-10-10  8:43 ` [PATCH 0/3] Support range stepping on software single-step target Yao Qi
@ 2016-10-26 15:39   ` Yao Qi
  2016-10-26 17:34     ` Antoine Tremblay
  0 siblings, 1 reply; 13+ messages in thread
From: Yao Qi @ 2016-10-26 15:39 UTC (permalink / raw)
  To: gdb-patches

On Mon, Oct 10, 2016 at 9:43 AM, Yao Qi <qiyaoltc@gmail.com> wrote:
> Yao Qi <qiyaoltc@gmail.com> writes:
>
>> This patch series enables the range stepping on targets support software
>> single-step, although arm-linux is the only target nowadays.
>>
>> Patch 1 is to remove single-step breakpoints for GDBserver internal
>> events.  Patch 2 teaches GDBserver to gen pending events from threads
>> in random to avoid starvation.  Patch 3 is to enable range stepping
>> if software single-step is supported.
>>
>> Regression tested arm-linux and x86_64-linux.
>
> Ping.
>

Ping.

-- 
Yao (齐尧)

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

* Re: [PATCH 0/3] Support range stepping on software single-step target
  2016-10-26 15:39   ` Yao Qi
@ 2016-10-26 17:34     ` Antoine Tremblay
  2016-10-27 15:07       ` Yao Qi
  0 siblings, 1 reply; 13+ messages in thread
From: Antoine Tremblay @ 2016-10-26 17:34 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches


Yao Qi writes:

> On Mon, Oct 10, 2016 at 9:43 AM, Yao Qi <qiyaoltc@gmail.com> wrote:
>> Yao Qi <qiyaoltc@gmail.com> writes:
>>
>>> This patch series enables the range stepping on targets support software
>>> single-step, although arm-linux is the only target nowadays.
>>>
>>> Patch 1 is to remove single-step breakpoints for GDBserver internal
>>> events.  Patch 2 teaches GDBserver to gen pending events from threads
>>> in random to avoid starvation.  Patch 3 is to enable range stepping
>>> if software single-step is supported.
>>>
>>> Regression tested arm-linux and x86_64-linux.
>>
>> Ping.
>>
>
> Ping.

Hi, series LGTM.

I tested on my boards and non-stop-fair-events is now working fine,
thanks for this work!! Sorry for the review delay.

Regards,
Antoine

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

* Re: [PATCH 1/3] Remove single-step breakpoint for GDBserver internal event
  2016-09-26  2:47 ` [PATCH 1/3] Remove single-step breakpoint for GDBserver internal event Yao Qi
@ 2016-10-26 17:45   ` Pedro Alves
  2016-10-26 20:14     ` Yao Qi
  0 siblings, 1 reply; 13+ messages in thread
From: Pedro Alves @ 2016-10-26 17:45 UTC (permalink / raw)
  To: Yao Qi, gdb-patches

On 09/26/2016 03:25 AM, Yao Qi wrote:
> This patch removes single-step breakpoints if the event is only
> GDBserver internal, IOW, isn't reported back to GDB.

Can you expand on rationale?  Why does being internal matter?

The rest of the series looks fine to me.

Thanks,
Pedro Alves

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

* Re: [PATCH 1/3] Remove single-step breakpoint for GDBserver internal event
  2016-10-26 17:45   ` Pedro Alves
@ 2016-10-26 20:14     ` Yao Qi
  2016-10-27 13:16       ` Pedro Alves
  0 siblings, 1 reply; 13+ messages in thread
From: Yao Qi @ 2016-10-26 20:14 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Wed, Oct 26, 2016 at 1:45 PM, Pedro Alves <palves@redhat.com> wrote:
> On 09/26/2016 03:25 AM, Yao Qi wrote:
>> This patch removes single-step breakpoints if the event is only
>> GDBserver internal, IOW, isn't reported back to GDB.
>
> Can you expand on rationale?  Why does being internal matter?

We remove single-step breakpoints on the moment we report event
back to GDB.  However, if we use single-step breakpoints and get
some events, we don't report them back to GDB and keep controlling
the inferior, we need to remove single-step breakpoints.  For
example, in range stepping, until the program goes out of the range,
we keep doing single step (by software), in a loop of insert single-step
breakpoints, resume, remove them.

-- 
Yao (齐尧)

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

* Re: [PATCH 1/3] Remove single-step breakpoint for GDBserver internal event
  2016-10-26 20:14     ` Yao Qi
@ 2016-10-27 13:16       ` Pedro Alves
  2016-10-27 14:14         ` Yao Qi
  0 siblings, 1 reply; 13+ messages in thread
From: Pedro Alves @ 2016-10-27 13:16 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 10/26/2016 09:14 PM, Yao Qi wrote:
> On Wed, Oct 26, 2016 at 1:45 PM, Pedro Alves <palves@redhat.com> wrote:
>> On 09/26/2016 03:25 AM, Yao Qi wrote:
>>> This patch removes single-step breakpoints if the event is only
>>> GDBserver internal, IOW, isn't reported back to GDB.
>>
>> Can you expand on rationale?  Why does being internal matter?
> 
> We remove single-step breakpoints on the moment we report event
> back to GDB.  However, if we use single-step breakpoints and get
> some events, we don't report them back to GDB and keep controlling
> the inferior, we need to remove single-step breakpoints.  For
> example, in range stepping, until the program goes out of the range,
> we keep doing single step (by software), in a loop of insert single-step
> breakpoints, resume, remove them.
> 

Ah yes, sorry, I should have read the code in more detail.
I agree, totally makes sense to do this here.

Thanks,
Pedro Alves

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

* Re: [PATCH 1/3] Remove single-step breakpoint for GDBserver internal event
  2016-10-27 14:14         ` Yao Qi
@ 2016-10-27 14:14           ` Pedro Alves
  0 siblings, 0 replies; 13+ messages in thread
From: Pedro Alves @ 2016-10-27 14:14 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

On 10/27/2016 03:14 PM, Yao Qi wrote:
> On Thu, Oct 27, 2016 at 2:16 PM, Pedro Alves <palves@redhat.com> wrote:
>>
>> Ah yes, sorry, I should have read the code in more detail.
>> I agree, totally makes sense to do this here.
>>
> 
> So, the patch is OK to commit? :-)

OK with me.

Thanks,
Pedro Alves

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

* Re: [PATCH 1/3] Remove single-step breakpoint for GDBserver internal event
  2016-10-27 13:16       ` Pedro Alves
@ 2016-10-27 14:14         ` Yao Qi
  2016-10-27 14:14           ` Pedro Alves
  0 siblings, 1 reply; 13+ messages in thread
From: Yao Qi @ 2016-10-27 14:14 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On Thu, Oct 27, 2016 at 2:16 PM, Pedro Alves <palves@redhat.com> wrote:
>
> Ah yes, sorry, I should have read the code in more detail.
> I agree, totally makes sense to do this here.
>

So, the patch is OK to commit? :-)

-- 
Yao (齐尧)

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

* Re: [PATCH 0/3] Support range stepping on software single-step target
  2016-10-26 17:34     ` Antoine Tremblay
@ 2016-10-27 15:07       ` Yao Qi
  0 siblings, 0 replies; 13+ messages in thread
From: Yao Qi @ 2016-10-27 15:07 UTC (permalink / raw)
  To: Antoine Tremblay; +Cc: gdb-patches

On Wed, Oct 26, 2016 at 6:34 PM, Antoine Tremblay
<antoine.tremblay@ericsson.com> wrote:
>
> I tested on my boards and non-stop-fair-events is now working fine,
> thanks for this work!! Sorry for the review delay.
>

Thanks for giving a try...  I pushed them in.

-- 
Yao (齐尧)

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

end of thread, other threads:[~2016-10-27 15:07 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-26  2:25 [PATCH 0/3] Support range stepping on software single-step target Yao Qi
2016-09-26  2:25 ` [PATCH 3/3] Enable range stepping if software single step is supported Yao Qi
2016-09-26  2:25 ` [PATCH 2/3] Get pending events in random Yao Qi
2016-09-26  2:47 ` [PATCH 1/3] Remove single-step breakpoint for GDBserver internal event Yao Qi
2016-10-26 17:45   ` Pedro Alves
2016-10-26 20:14     ` Yao Qi
2016-10-27 13:16       ` Pedro Alves
2016-10-27 14:14         ` Yao Qi
2016-10-27 14:14           ` Pedro Alves
2016-10-10  8:43 ` [PATCH 0/3] Support range stepping on software single-step target Yao Qi
2016-10-26 15:39   ` Yao Qi
2016-10-26 17:34     ` Antoine Tremblay
2016-10-27 15:07       ` Yao Qi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).