Send Linux-ha-cvs mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://lists.community.tummy.com/mailman/listinfo/linux-ha-cvs
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]
You can reach the person managing the list at
[EMAIL PROTECTED]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Linux-ha-cvs digest..."
Today's Topics:
1. Linux-HA CVS: lib by alan from ([email protected])
----------------------------------------------------------------------
Message: 1
Date: Sat, 4 Feb 2006 09:39:59 -0700 (MST)
From: [email protected]
Subject: [Linux-ha-cvs] Linux-HA CVS: lib by alan from
To: [EMAIL PROTECTED]
Message-ID: <[EMAIL PROTECTED]>
linux-ha CVS committal
Author : alan
Host :
Project : linux-ha
Module : lib
Dir : linux-ha/lib/clplumbing
Modified Files:
GSource.c longclock.c
Log Message:
Changed the code so that longclock_time() never gets called in a signal handler.
Changed longclock code so it detects improper clock setbacks and ignores them...
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/lib/clplumbing/GSource.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -3 -r1.65 -r1.66
--- GSource.c 3 Feb 2006 02:49:28 -0000 1.65
+++ GSource.c 4 Feb 2006 16:39:58 -0000 1.66
@@ -1,4 +1,4 @@
-/* $Id: GSource.c,v 1.65 2006/02/03 02:49:28 alan Exp $ */
+/* $Id: GSource.c,v 1.66 2006/02/04 16:39:58 alan Exp $ */
/*
* Copyright (c) 2002 Alan Robertson <[EMAIL PROTECTED]>
*
@@ -102,6 +102,7 @@
struct GSIGSource_s {
COMMON_STRUCTSTART;
+ clock_t sh_detecttime;
int signal;
gboolean signal_triggered;
gboolean (*dispatch)(int signal, gpointer user_data);
@@ -153,6 +154,7 @@
if ((i)->maxdispatchms > 0 && ms > (i)->maxdispatchms) { \
WARN_TOOLONG(ms, (i)); \
} \
+ (i)->detecttime = zero_longclock; \
}
#define WARN_TOOMUCH(ms, input) cl_log(LOG_WARNING
\
@@ -232,7 +234,7 @@
ret->gpfd.events = DEF_EVENTS;
ret->gpfd.revents = 0;
ret->dnotify = notify;
- ret->detecttime = time_longclock();
+ ret->detecttime = zero_longclock;
g_source_add_poll(source, &ret->gpfd);
@@ -304,8 +306,11 @@
{
GFDSource* fdp = (GFDSource*)source;
g_assert(IS_FDSOURCE(fdp));
- fdp->detecttime = time_longclock();
- return fdp->gpfd.revents != 0;
+ if (fdp->gpfd.revents) {
+ fdp->detecttime = time_longclock();
+ return TRUE;
+ }
+ return FALSE;
}
/*
@@ -323,7 +328,8 @@
CHECK_DISPATCH_DELAY(fdp);
- /* Is output now unblocked?
+ /*
+ * Is output now unblocked?
*
* If so, turn off OUTPUT_EVENTS to avoid going into
* a tight poll(2) loop.
@@ -412,7 +418,7 @@
chp->magno = MAG_GCHSOURCE;
chp->maxdispatchdelayms = DEFAULT_MAXDELAY;
chp->maxdispatchms = DEFAULT_MAXDISPATCH;
- chp->detecttime = time_longclock();
+ chp->detecttime = zero_longclock;
chp->ch = ch;
chp->dispatch = dispatch;
chp->udata=userdata;
@@ -536,11 +542,13 @@
chp->infd.events &= ~INPUT_EVENTS;
}
- chp->detecttime = time_longclock();
if (chp->dontread){
return FALSE;
}
ret = chp->ch->ops->is_message_pending(chp->ch);
+ if (ret) {
+ chp->detecttime = time_longclock();
+ }
CHECKEND(chp);
return ret;
}
@@ -570,7 +578,9 @@
ret = (chp->infd.revents != 0
|| (!chp->fd_fdx && chp->outfd.revents != 0)
|| chp->ch->ops->is_message_pending(chp->ch));
- chp->detecttime = time_longclock();
+ if (ret) {
+ chp->detecttime = time_longclock();
+ }
CHECKEND(chp);
return ret;
}
@@ -698,7 +708,7 @@
wcp->magno = MAG_GWCSOURCE;
wcp->maxdispatchdelayms = DEFAULT_MAXDELAY;
wcp->maxdispatchms = DEFAULT_MAXDISPATCH;
- wcp->detecttime = time_longclock();
+ wcp->detecttime = zero_longclock;
wcp->udata = userdata;
wcp->gpfd.fd = wch->ops->get_select_fd(wch);
wcp->gpfd.events = DEF_EVENTS;
@@ -773,8 +783,8 @@
GWCSource* wcp = (GWCSource*)source;
g_assert(IS_WCSOURCE(wcp));
- wcp->detecttime = time_longclock();
if (wcp->gpfd.revents != 0) {
+ wcp->detecttime = time_longclock();
return TRUE;
}
return FALSE;
@@ -968,10 +978,34 @@
g_assert(IS_SIGSOURCE(sig_src));
- /* Don't let a timing window keep us in poll() forever */
- *timeoutms = 1000;
- sig_src->detecttime = time_longclock();
- return sig_src->signal_triggered;
+ /* Don't let a timing window keep us in poll() forever
+ *
+ * The timing window in question looks like this:
+ * No signal has occurred up to the point of prepare being called.
+ * Signal comes in _after_ prepare was called, but _before_ poll.
+ * signal_detected gets set, but no one checks it before going into poll
+ * We wait in poll forever... It's not a pretty sight :-(.
+ */
+ *timeoutms = 1000; /* Sigh... */
+
+ if (sig_src->signal_triggered) {
+ static struct tms dummy_tms_struct;
+ clock_t now;
+ clock_t diff;
+
+ /* detecttime is reset in the dispatch function */
+ if (cmp_longclock(sig_src->detecttime, zero_longclock) != 0) {
+ cl_log(LOG_ERR, "%s: detecttime already set?",
__FUNCTION__);
+ return TRUE;
+ }
+ /* Otherwise, this is when it was first detected */
+ now = times(&dummy_tms_struct);
+ diff = now - sig_src->sh_detecttime; /* How long since
signal occurred? */
+ sig_src->detecttime
+ = sub_longclock(time_longclock(), (longclock_t)diff);
+ return TRUE;
+ }
+ return FALSE;
}
/*
@@ -986,7 +1020,21 @@
g_assert(IS_SIGSOURCE(sig_src));
- return sig_src->signal_triggered;
+ if (sig_src->signal_triggered) {
+ static struct tms dummy_tms_struct;
+ clock_t now;
+ clock_t diff;
+ if (cmp_longclock(sig_src->detecttime, zero_longclock) != 0){
+ return TRUE;
+ }
+ /* Otherwise, this is when it was first detected */
+ now = times(&dummy_tms_struct);
+ diff = now - sig_src->sh_detecttime;
+ sig_src->detecttime
+ = sub_longclock(time_longclock(), (longclock_t)diff);
+ return TRUE;
+ }
+ return FALSE;
}
/*
@@ -1003,6 +1051,7 @@
g_assert(IS_SIGSOURCE(sig_src));
CHECK_DISPATCH_DELAY(sig_src);
+ sig_src->sh_detecttime = 0UL;
sig_src->signal_triggered = FALSE;
if(sig_src->dispatch) {
@@ -1038,6 +1087,7 @@
static void
G_main_signal_handler(int nsig)
{
+ static struct tms dummy_tms_struct;
GSIGSource* sig_src = NULL;
g_assert(G_main_signal_list != NULL);
@@ -1045,14 +1095,17 @@
sig_src = G_main_signal_list[nsig];
-/* g_assert(sig_src != NULL); */
if(sig_src == NULL) {
/* cl_log(LOG_CRIT, "No handler for signal -%d", nsig); */
return;
}
g_assert(IS_SIGSOURCE(sig_src));
- sig_src->detecttime = time_longclock();
+ /* Time from first occurance of signal */
+ if (!sig_src->signal_triggered) {
+ /* Avoid calling longclock_time() on a signal */
+ sig_src->sh_detecttime=times(&dummy_tms_struct);
+ }
sig_src->signal_triggered = TRUE;
}
@@ -1224,6 +1277,7 @@
g_assert(IS_TRIGSOURCE(trig_src));
trig_src->manual_trigger = TRUE;
+ trig_src->detecttime = time_longclock();
}
@@ -1253,7 +1307,7 @@
g_assert(IS_TRIGSOURCE(trig_src));
- trig_src->detecttime = time_longclock();
+
return trig_src->manual_trigger;
}
@@ -1268,11 +1322,7 @@
GTRIGSource* trig_src = (GTRIGSource*)source;
g_assert(IS_TRIGSOURCE(trig_src));
- if (trig_src->manual_trigger) {
- trig_src->detecttime = time_longclock();
- return TRUE;
- }
- return FALSE;
+ return trig_src->manual_trigger;
}
/*
@@ -1383,7 +1433,7 @@
append->maxdispatchms = DEFAULT_MAXDISPATCH;
append->maxdispatchdelayms = DEFAULT_MAXDELAY;
append->description = "(timeout)";
- append->detecttime = time_longclock();
+ append->detecttime = zero_longclock;
append->udata = NULL;
append->nexttime = add_longclock(append->detecttime
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/lib/clplumbing/longclock.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -3 -r1.18 -r1.19
--- longclock.c 3 Feb 2006 15:47:17 -0000 1.18
+++ longclock.c 4 Feb 2006 16:39:58 -0000 1.19
@@ -1,4 +1,4 @@
-/* $Id: longclock.c,v 1.18 2006/02/03 15:47:17 alan Exp $ */
+/* $Id: longclock.c,v 1.19 2006/02/04 16:39:58 alan Exp $ */
/*
* Longclock operations
*
@@ -55,7 +55,7 @@
/* Compute various hz-related constants */
Hz = sysconf(_SC_CLK_TCK);
- Lc_Hz = Hz;
+ Lc_Hz = (longclock_t)Hz;
d_Hz = (double) Hz;
}
return Hz;
@@ -76,8 +76,7 @@
#define BITSPERBYTE 8
#define WRAPSHIFT (BITSPERBYTE*sizeof(clock_t))
#define MAXIMUMULONG ((unsigned long)~(0UL))
-#define ENDTIMES ((MAXIMUMULONG/100UL)*99UL)
-#define NEWERA (MAXIMUMULONG/100UL)
+#define MINJUMP ((MAXIMUMULONG/100UL)*99UL)
longclock_t
time_longclock(void)
@@ -104,32 +103,26 @@
timesval = (unsigned long) times(&longclock_dummy_tms_struct);
if (calledbefore && timesval < lasttimes) {
- if ((lasttimes - timesval) <= 2UL) {
- /* Some kind of (SMP) kernel weirdness */
+ clock_t jumpbackby = lasttimes - timesval;
+
+ if (jumpbackby < MINJUMP) {
+ /* Kernel weirdness */
cl_log(LOG_CRIT
, "%s: clock_t from times(2) appears to"
- " have jumped backwards just a few ticks!"
+ " have jumped backwards (in error)!"
, __FUNCTION__);
cl_log(LOG_CRIT
, "%s: old value was %lu"
- ", new value is %lu, callcount %lu"
- , __FUNCTION__, lasttimes, timesval, callcount);
+ ", new value is %lu, diff is %lu, callcount %lu"
+ , __FUNCTION__, lasttimes, timesval
+ , jumpbackby, callcount);
+ /* Assume jump back was the error and ignore it */
+ /* (i.e., hope it goes away) */
timesval = lasttimes;
}else{
+ /* Normal looking wraparound */
++wrapcount;
lc_wrapcount = ((longclock_t)wrapcount) << WRAPSHIFT;
- if (lasttimes < ENDTIMES || timesval >= NEWERA) {
- /* Clock jumped a long way(!) */
- cl_log(LOG_CRIT
- , "%s: clock_t from times(2) appears to"
- " have jumped backwards!"
- , __FUNCTION__);
- cl_log(LOG_CRIT
- , "%s: old value was %lu"
- ", new value is %lu, callcount %lu"
- , __FUNCTION__, lasttimes, timesval
- , callcount);
- }
}
}
lasttimes = timesval;
------------------------------
_______________________________________________
Linux-ha-cvs mailing list
[email protected]
http://lists.community.tummy.com/mailman/listinfo/linux-ha-cvs
End of Linux-ha-cvs Digest, Vol 27, Issue 23
********************************************