An objection of my own:

there are probably situations today when polling fail that we
don't think too much about. One situation I can think of is
power cycling the target.

It would be hard to map out these situations via testing and
add code to handle them.

Another "temporary" way to disable polling is to either
execute it manually from the command line or in the
startup config script.

Perhaps a better approach might be to have a back-off
algorithm where the time between polling is doubled
every time it fails up to e.g. 5 seconds and then
reset to default upon a successful poll. Written up
in attached patch. Not tested.

-- 
Øyvind Harboe
US toll free 1-866-980-3434 / International +47 51 63 25 00
http://www.zylin.com/zy1000.html
ARM7 ARM9 ARM11 XScale Cortex
JTAG debugger and flash programmer
From 9d90fe48be73b515b05b2b7e99abfe82bc8cf70b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=98yvind=20Harboe?= <oyvind.har...@zylin.com>
Date: Sun, 8 Aug 2010 09:14:54 +0200
Subject: [PATCH] target: if polling fails, back off
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

back-off algorithm for polling. Double polling
interval up to 5000ms when it fails.

when polling succeeds, reset backoff.

This avoids flooding logs(as much) when working
with conditions where the target polling will fail.

Signed-off-by: Øyvind Harboe <oyvind.har...@zylin.com>
---
 src/target/target.c |   31 ++++++++++++++++++++++++-------
 1 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/src/target/target.c b/src/target/target.c
index f178ae3..a58f343 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -1800,6 +1800,9 @@ static int sense_handler(void)
 	return ERROR_OK;
 }
 
+static int backoff_times = 0;
+static int backoff_count = 0;
+
 /* process target state changes */
 static int handle_target(void *priv)
 {
@@ -1862,6 +1865,14 @@ static int handle_target(void *priv)
 		recursive = 0;
 	}
 
+	if (backoff_times > backoff_count)
+	{
+		/* do not poll this time as we failed previously */
+		backoff_count++;
+		return ERROR_OK;
+	}
+	backoff_count = 0;
+
 	/* Poll targets for state changes unless that's globally disabled.
 	 * Skip targets that are currently disabled.
 	 */
@@ -1878,17 +1889,23 @@ static int handle_target(void *priv)
 			/* polling may fail silently until the target has been examined */
 			if ((retval = target_poll(target)) != ERROR_OK)
 			{
-				/* FIX!!!!! If we add a LOG_INFO() here to output a line in GDB
-				 * *why* we are aborting GDB, then we'll spam telnet when the
-				 * poll is failing persistently.
-				 *
-				 * If we could implement an event that detected the
-				 * target going from non-pollable to pollable, we could issue
-				 * an error only upon the transition.
+				LOG_USER("Polling target failed, GDB will be halted.");
+
+				/* 100ms polling interval. Increase interval between polling up to 5000ms */
+				if (backoff_times * 100 < 5000)
+				{
+					backoff_times *= 2;
+					backoff_times++;
+				}
+
+				/* Tell GDB to halt the debugger. This allows the user to
+				 * run monitor commands to handle the situation.
 				 */
 				target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT);
 				return retval;
 			}
+			/* Since we succeeded, we reset backoff count */
+			backoff_times = 0;
 		}
 	}
 
-- 
1.7.0.4

_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to