From 306913b991c02ebc7a9ff2e9a00e24345e0b49f1 Mon Sep 17 00:00:00 2001 From: Marty Kraimer Date: Fri, 7 Jan 2000 13:36:51 +0000 Subject: [PATCH] replace osiClock calls with tsStamp calls --- src/rsrv/camessage.c | 4 ++-- src/rsrv/camsgtask.c | 4 ++-- src/rsrv/caserverio.c | 5 ++--- src/rsrv/caservertask.c | 41 ++++++++++------------------------------ src/rsrv/cast_server.c | 35 +++++++++++++++------------------- src/rsrv/online_notify.c | 25 +++++++++++++++--------- src/rsrv/server.h | 6 +++--- 7 files changed, 50 insertions(+), 70 deletions(-) diff --git a/src/rsrv/camessage.c b/src/rsrv/camessage.c index 12ff64b33..cd1653f57 100644 --- a/src/rsrv/camessage.c +++ b/src/rsrv/camessage.c @@ -62,7 +62,7 @@ static char *sccsId = "%W% %G%"; #include "osiSock.h" #include "osiThread.h" -#include "osiClock.h" +#include "tsStamp.h" #include "errlog.h" #include "db_access.h" #include "special.h" @@ -923,7 +923,7 @@ unsigned cid return NULL; } ellInit(&pchannel->eventq); - pchannel->ticks_at_creation = clockGetRate(); + tsStampGetCurrent(&pchannel->time_at_creation); pchannel->addr = *pAddr; pchannel->client = client; /* diff --git a/src/rsrv/camsgtask.c b/src/rsrv/camsgtask.c index eba30a6ab..e17408ee9 100644 --- a/src/rsrv/camsgtask.c +++ b/src/rsrv/camsgtask.c @@ -53,7 +53,7 @@ static char *sccsId = "@(#) $Id$"; #include #include "osiSock.h" -#include "osiClock.h" +#include "tsStamp.h" #include "os_depen.h" #include "osiThread.h" #include "errlog.h" @@ -246,7 +246,7 @@ SOCKET sock; break; } - client->ticks_at_last_recv = clockGetRate(); + tsStampGetCurrent(&client->time_at_last_recv); client->recv.cnt += (unsigned long) nchars; status = camessage(client, &client->recv); diff --git a/src/rsrv/caserverio.c b/src/rsrv/caserverio.c index 0a13cf934..56d48f2dc 100644 --- a/src/rsrv/caserverio.c +++ b/src/rsrv/caserverio.c @@ -46,7 +46,7 @@ static char *sccsId = "@(#) $Id$"; #include #include "osiSock.h" -#include "osiClock.h" +#include "tsStamp.h" #include "ellLib.h" #include "errlog.h" #include "server.h" @@ -172,8 +172,7 @@ int lock_needed; } pclient->send.stk = 0; - - pclient->ticks_at_last_send = clockGetRate(); + tsStampGetCurrent(&pclient->time_at_last_send); } diff --git a/src/rsrv/caservertask.c b/src/rsrv/caservertask.c index 6b1fff14d..55d8cbfb2 100644 --- a/src/rsrv/caservertask.c +++ b/src/rsrv/caservertask.c @@ -58,7 +58,7 @@ static char *sccsId = "@(#) $Id$"; #include #include "osiSock.h" -#include "osiClock.h" +#include "tsStamp.h" #include "errlog.h" #include "ellLib.h" #include "taskwd.h" @@ -72,7 +72,6 @@ static char *sccsId = "@(#) $Id$"; LOCAL int terminate_one_client(struct client *client); LOCAL void log_one_client(struct client *client, unsigned level); -LOCAL unsigned long delay_in_ticks(unsigned long prev); /* @@ -391,11 +390,12 @@ LOCAL void log_one_client(struct client *client, unsigned level) int i; struct channel_in_use *pciu; char *pproto; - float send_delay; - float recv_delay; + double send_delay; + double recv_delay; unsigned long bytes_reserved; char *state[] = {"up", "down"}; - char clientHostName[256]; + TS_STAMP current; + char clientHostName[256]; ipAddrToA (&client->addr, clientHostName, sizeof(clientHostName)); @@ -409,8 +409,10 @@ LOCAL void log_one_client(struct client *client, unsigned level) pproto = "UKN"; } - send_delay = delay_in_ticks(client->ticks_at_last_send); - recv_delay = delay_in_ticks(client->ticks_at_last_recv); + + tsStampGetCurrent(¤t); + send_delay = tsStampDiffInSeconds(¤t,&client->time_at_last_send); + recv_delay = tsStampDiffInSeconds(¤t,&client->time_at_last_recv); printf( "%s(%s): User=\"%s\", V%d.%u, Channel Count=%d\n", @@ -427,8 +429,7 @@ LOCAL void log_one_client(struct client *client, unsigned level) client->sock); printf( "\tSecs since last send %6.2f, Secs since last receive %6.2f\n", - send_delay/clockGetRate(), - recv_delay/clockGetRate()); + send_delay, recv_delay); printf( "\tUnprocessed request bytes=%lu, Undelivered response bytes=%lu, State=%s\n", client->send.stk, @@ -488,25 +489,3 @@ LOCAL void log_one_client(struct client *client, unsigned level) semBinaryShow (client->blockSem); } } - - -/* - * delay_in_ticks() - */ -unsigned long delay_in_ticks(unsigned long prev) -{ - unsigned long delay; - unsigned long current; - - current = clockGetCurrentTick(); - if (current >= prev) { - delay = current - prev; - } - else { - delay = 1 + current + (ULONG_MAX - prev); - } - - return delay; -} - - diff --git a/src/rsrv/cast_server.c b/src/rsrv/cast_server.c index 72a55a7db..bf9dee0e2 100644 --- a/src/rsrv/cast_server.c +++ b/src/rsrv/cast_server.c @@ -67,7 +67,7 @@ static char *sccsId = "@(#) $Id$"; #include #include "osiSock.h" -#include "osiClock.h" +#include "tsStamp.h" #include "os_depen.h" #include "osiThread.h" #include "errlog.h" @@ -200,7 +200,7 @@ int cast_server(void) else { prsrv_cast_client->recv.cnt = (unsigned long) status; prsrv_cast_client->recv.stk = 0ul; - prsrv_cast_client->ticks_at_last_recv = clockGetRate(); + tsStampGetCurrent(&prsrv_cast_client->time_at_last_recv); /* * If we are talking to a new client flush to the old one @@ -283,20 +283,20 @@ int cast_server(void) * * */ -#define TIMEOUT 60 /* sec */ +#define TIMEOUT 60.0 /* sec */ LOCAL void clean_addrq() { struct channel_in_use *pciu; struct channel_in_use *pnextciu; - unsigned long current; - unsigned long delay; - unsigned long maxdelay = 0; + TS_STAMP current; + double delay; + double maxdelay = 0; unsigned ndelete=0; - unsigned long timeout = TIMEOUT*clockGetRate(); + double timeout = TIMEOUT; int s; - current = clockGetRate(); + tsStampGetCurrent(¤t); semMutexMustTake(prsrv_cast_client->addrqLock); pnextciu = (struct channel_in_use *) @@ -305,13 +305,8 @@ LOCAL void clean_addrq() while( (pciu = pnextciu) ) { pnextciu = (struct channel_in_use *)pciu->node.next; - if (current >= pciu->ticks_at_creation) { - delay = current - pciu->ticks_at_creation; - } - else { - delay = current + (~0L - pciu->ticks_at_creation); - } - + delay = tsStampDiffInSeconds(&pciu->time_at_creation, + ¤t); if (delay > timeout) { ellDelete(&prsrv_cast_client->addrq, &pciu->node); @@ -325,15 +320,15 @@ LOCAL void clean_addrq() UNLOCK_CLIENTQ; freeListFree(rsrvChanFreeList, pciu); ndelete++; - maxdelay = max(delay, maxdelay); + if(delay>maxdelay) maxdelay = delay; } } semMutexGive(prsrv_cast_client->addrqLock); # ifdef DEBUG if(ndelete){ - epicsPrintf ("CAS: %d CA channels have expired after %d sec\n", - ndelete, maxdelay / clockGetRate()); + epicsPrintf ("CAS: %d CA channels have expired after %f sec\n", + ndelete, maxdelay); } # endif @@ -404,8 +399,8 @@ struct client *create_udp_client(SOCKET sock) client->recv.cnt = 0ul; client->evuser = NULL; client->disconnect = FALSE; /* for TCP only */ - client->ticks_at_last_send = clockGetRate(); - client->ticks_at_last_recv = clockGetRate(); + tsStampGetCurrent(&client->time_at_last_send); + tsStampGetCurrent(&client->time_at_last_recv); client->proto = IPPROTO_UDP; client->sock = sock; client->minor_version_number = CA_UKN_MINOR_VERSION; diff --git a/src/rsrv/online_notify.c b/src/rsrv/online_notify.c index 7678c8e8a..f954e0bc1 100644 --- a/src/rsrv/online_notify.c +++ b/src/rsrv/online_notify.c @@ -49,19 +49,25 @@ static char *sccsId = "@(#) $Id$"; */ #include "osiSock.h" #include "osiThread.h" -#include "osiClock.h" +#include "tsStamp.h" #include "errlog.h" #include "envDefs.h" #include "server.h" +LOCAL powerOfTwo[10] = { +2.0,4.0,8.0,16.0,32.0,64.0,128.0,256.0,512.0,1024.0 +}; + /* * RSRV_ONLINE_NOTIFY_TASK */ + + int rsrv_online_notify_task() { caAddrNode *pNode; - unsigned long delay; - unsigned long maxdelay; + double delay; + double maxdelay; long longStatus; double maxPeriod; caHdr msg; @@ -70,6 +76,7 @@ int rsrv_online_notify_task() SOCKET sock; int true = TRUE; unsigned short port; + int indPowerofTwo = 0; taskwdInsert(threadGetIdSelf(),NULL,NULL); @@ -88,11 +95,10 @@ int rsrv_online_notify_task() } /* - * 1 tick initial delay between beacons, but max of 1/60 sec + * 1/50 second initial delay between beacons */ - delay = 1ul; - if(clockGetRate() > 60.0) delay = clockGetRate()/60.0; - maxdelay = (unsigned long) maxPeriod*sysClkRateGet(); + delay = .02; + maxdelay = maxPeriod; /* * Open the socket. @@ -174,8 +180,9 @@ int rsrv_online_notify_task() pNode = (caAddrNode *)pNode->node.next; } - threadSleep(delay/(double)clockGetRate()); - delay = min(delay << 1, maxdelay); + threadSleep(delay); + delay = delay + powerOfTwo[indPowerofTwo++]; + if(delay>=maxdelay) delay = maxdelay; } } diff --git a/src/rsrv/server.h b/src/rsrv/server.h index 4b8a1210f..83679d25d 100644 --- a/src/rsrv/server.h +++ b/src/rsrv/server.h @@ -125,8 +125,8 @@ struct client{ ELLLIST putNotifyQue; struct sockaddr_in addr; - unsigned long ticks_at_last_send; - unsigned long ticks_at_last_recv; + TS_STAMP time_at_last_send; + TS_STAMP time_at_last_recv; void *evuser; char *pUserName; char *pHostName; @@ -162,7 +162,7 @@ struct channel_in_use{ RSRVPUTNOTIFY *pPutNotify; /* potential active put notify */ const unsigned cid; /* client id */ const unsigned sid; /* server id */ - unsigned long ticks_at_creation; /* for UDP timeout */ + TS_STAMP time_at_creation; /* for UDP timeout */ struct dbAddr addr; ASCLIENTPVT asClientPVT; };