Skip to content

Commit

Permalink
Type ioUTCMicroseconds et at consistently with sqVirtualMachine's utc…
Browse files Browse the repository at this point in the history
…Microseconds.

Recent versions of clang protest, refusing to find type compatible unsigned
long and unsigned long long on 64 bits.

Alas this means that sqaio.h has to pull in sqMemoryAccess.h for the usqLong &
sqLong definitions. But it's a price we have to pay.
  • Loading branch information
eliotmiranda committed Jun 7, 2023
1 parent 576d383 commit f237888
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 103 deletions.
10 changes: 5 additions & 5 deletions platforms/Cross/vm/sq.h
Expand Up @@ -129,11 +129,11 @@ unsigned int ioMicroMSecs(void);
/* Time API, Cog uses 64-bit microseconds fron 1901 as much as possible */
void forceInterruptCheckFromHeartbeat(void);
void ioInitTime(void);
unsigned long long ioUTCMicrosecondsNow(void);
unsigned long long ioUTCMicroseconds(void);
unsigned long long ioLocalMicrosecondsNow(void);
unsigned long long ioLocalMicroseconds(void);
unsigned long long ioUTCStartMicroseconds(void);
usqLong ioUTCMicrosecondsNow(void);
usqLong ioUTCMicroseconds(void);
usqLong ioLocalMicrosecondsNow(void);
usqLong ioLocalMicroseconds(void);
usqLong ioUTCStartMicroseconds(void);
sqInt ioLocalSecondsOffset(void);
void ioUpdateVMTimezone(void);
void ioSynchronousCheckForEvents(void);
Expand Down
4 changes: 2 additions & 2 deletions platforms/Cross/vm/sqVirtualMachine.h
Expand Up @@ -526,8 +526,8 @@ sqInt signalSemaphoreWithIndex(sqInt semaIndex);
sqInt success(sqInt aBoolean);
sqInt superclassOf(sqInt classPointer);
unsigned int ioMicroMSecs(void);
unsigned long long ioUTCMicroseconds(void);
unsigned long long ioUTCMicrosecondsNow(void);
usqLong ioUTCMicroseconds(void);
usqLong ioUTCMicrosecondsNow(void);
void forceInterruptCheck(void);
sqInt getThisSessionID(void);
sqInt ioFilenamefromStringofLengthresolveAliases(char* aCharBuffer, char* filenameIndex, sqInt filenameLength, sqInt resolveFlag);
Expand Down
6 changes: 3 additions & 3 deletions platforms/Mac OS/vm/sqMacTime.c
Expand Up @@ -133,7 +133,7 @@ unsigned int ioMSecs() { return ioMicroMSecs(); }
#define MicrosecondsPerMillisecond 1000ULL
/* Compute the current VM time basis, the number of microseconds from 1901. */

static unsigned long long
static usqLong
currentUTCMicroseconds()
{
struct timeval utcNow;
Expand All @@ -143,13 +143,13 @@ currentUTCMicroseconds()
+ MicrosecondsFrom1901To1970;
}

unsigned long long
usqLong
ioUTCMicroseconds() { return currentUTCMicroseconds(); }

/* This is an expensive interface for use by profiling code that wants the time
* now rather than as of the last heartbeat.
*/
unsigned long long
usqLong
ioUTCMicrosecondsNow() { return currentUTCMicroseconds(); }
#endif /* STACKVM */

Expand Down
7 changes: 4 additions & 3 deletions platforms/minheadless/common/sqaio.h
Expand Up @@ -31,6 +31,7 @@
#ifndef __sqaio_h
#define __sqaio_h

#include "sqMemoryAccess.h" // for usqLong for ioUTCMicroseconds et al

#define AIO_X (1<<0) /* handle for exceptions */
#define AIO_R (1<<1) /* handle for read */
Expand Down Expand Up @@ -94,8 +95,8 @@ extern long aioPoll(long microSeconds);
*/
extern long aioSleepForUsecs(long microSeconds);

extern unsigned long long ioUTCMicroseconds(void);
extern unsigned long long ioUTCMicrosecondsNow(void);
extern usqLong ioUTCMicroseconds(void);
extern usqLong ioUTCMicrosecondsNow(void);

/* debugging stuff. */
#ifdef AIO_DEBUG
Expand All @@ -119,7 +120,7 @@ extern unsigned long long ioUTCMicrosecondsNow(void);
aioLastTick = aioThisTick; \
fprintf X; } while (0)
# endif /* ACORN */
#else /* !DEBUG */
#else /* AIO_DEBUG */
# define FPRINTF(X)
#endif

Expand Down
32 changes: 16 additions & 16 deletions platforms/minheadless/unix/sqUnixHeartbeat.c
Expand Up @@ -42,12 +42,12 @@

#define MicrosecondsPerMillisecond 1000LL

static unsigned volatile long long utcMicrosecondClock;
static unsigned volatile long long localMicrosecondClock;
static unsigned volatile long millisecondClock; /* for the ioMSecs clock. */
static unsigned long long utcStartMicroseconds; /* for the ioMSecs clock. */
static long long vmGMTOffset = 0;
static unsigned long long frequencyMeasureStart = 0;
static volatile usqLong utcMicrosecondClock;
static volatile usqLong localMicrosecondClock;
static volatile unsigned long millisecondClock; /* for the ioMSecs clock. */
static usqLong utcStartMicroseconds; /* for the ioMSecs clock. */
static sqLong vmGMTOffset = 0;
static usqLong frequencyMeasureStart = 0;
static unsigned long heartbeats;

#define microToMilliseconds(usecs) ((((usecs) - utcStartMicroseconds) \
Expand All @@ -58,7 +58,7 @@ static unsigned long heartbeats;

#if LOG_CLOCK
# define LOGSIZE 1024
static unsigned long long useclog[LOGSIZE];
static usqLong useclog[LOGSIZE];
static unsigned long mseclog[LOGSIZE];
static int logClock = 0;
static unsigned int ulogidx = (unsigned int)-1;
Expand Down Expand Up @@ -93,7 +93,7 @@ ioGetClockLogSizeUsecsIdxMsecsIdx(sqInt *np, void **usecsp, sqInt *uip, void **m

/* Compute the current VM time basis, the number of microseconds from 1901. */

static unsigned long long
static usqLong
currentUTCMicroseconds()
{
struct timeval utcNow;
Expand Down Expand Up @@ -121,8 +121,8 @@ currentUTCMicroseconds()
static void
updateMicrosecondClock()
{
unsigned long long newUtcMicrosecondClock;
unsigned long long newLocalMicrosecondClock;
usqLong newUtcMicrosecondClock;
usqLong newLocalMicrosecondClock;

newUtcMicrosecondClock = currentUTCMicroseconds();

Expand Down Expand Up @@ -182,10 +182,10 @@ ioHighResClock(void)
return value;
}

unsigned long long
usqLong
ioUTCMicroseconds() { return get64(utcMicrosecondClock); }

unsigned long long
usqLong
ioLocalMicroseconds() { return get64(localMicrosecondClock); }

sqInt
Expand All @@ -194,13 +194,13 @@ ioLocalSecondsOffset() { return vmGMTOffset / MicrosecondsPerSecond; }
/* This is an expensive interface for use by Smalltalk or vm profiling code that
* wants the time now rather than as of the last heartbeat.
*/
unsigned long long
usqLong
ioUTCMicrosecondsNow() { return currentUTCMicroseconds(); }

unsigned long long
usqLong
ioUTCStartMicroseconds() { return utcStartMicroseconds; }

unsigned long long
usqLong
ioLocalMicrosecondsNow() { return currentUTCMicroseconds() + vmGMTOffset; };

/* ioMSecs answers the millisecondClock as of the last tick. */
Expand Down Expand Up @@ -403,7 +403,7 @@ ioHeartbeatFrequency(int resetStats)
unsigned long frequency = duration ? heartbeats / duration : 0;

if (resetStats) {
unsigned long long zero = 0;
usqLong zero = 0;
set64(frequencyMeasureStart,zero);
}
return frequency;
Expand Down
10 changes: 5 additions & 5 deletions platforms/minheadless/windows/sqWin32Heartbeat.c
Expand Up @@ -235,10 +235,10 @@ ioInitTime(void)
utcStartMicroseconds = utcMicrosecondClock;
}

unsigned long long
usqLong
ioUTCMicroseconds() { return get64(utcMicrosecondClock); }

unsigned long long
usqLong
ioLocalMicroseconds() { return get64(localMicrosecondClock); }

sqInt
Expand All @@ -247,18 +247,18 @@ ioLocalSecondsOffset() { return vmGMTOffset / MicrosecondsPerSecond; }
/* This is an expensive interface for use by Smalltalk or vm profiling code that
* wants the time now rather than as of the last heartbeat.
*/
unsigned long long
usqLong
ioUTCMicrosecondsNow()
{
return currentUTCMicroseconds(&vmThreadUtcTickBaseMicroseconds,
&vmThreadLastTick,
&vmThreadBaseTick);
}

unsigned long long
usqLong
ioUTCStartMicroseconds() { return utcStartMicroseconds; }

unsigned long long
usqLong
ioLocalMicrosecondsNow() { return ioUTCMicrosecondsNow() + vmGMTOffset; };

/* ioMSecs answers the millisecondClock as of the last tick. */
Expand Down
34 changes: 29 additions & 5 deletions platforms/minheadless/windows/sqWin32Time.c
Expand Up @@ -4,7 +4,7 @@
* trunk sqWin32Window.c
*****************************************************************************/

#include <windows.h>
#include <Windows.h>

#include "sq.h"

Expand Down Expand Up @@ -43,7 +43,8 @@
#endif

/* returns the local wall clock time */
int ioSeconds(void)
int
ioSeconds(void)
{ SYSTEMTIME sysTime;
GetLocalTime(&sysTime);
return convertToSqueakTime(sysTime);
Expand All @@ -64,6 +65,28 @@ ioMicroMSecs(void)
return timeGetTime() & MillisecondClockMask;
}

#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)

/* Compute the current VM time basis, the number of microseconds from 1901.
*
* As of Windows 8 there is a FILETIME wall clock interface which is high
* precision and so does not have to be combined with the millisecond clock.
*/
# define currentUTCMicroseconds(a,b,c) currentUTCMicrosecondsImplementation()
static inline unsigned __int64
currentUTCMicrosecondsImplementation(void)
{
union { // got to love little-endian architectures...
FILETIME utcNowFiletime;
unsigned __int64 utcNow;
} un;

// cannot fail...
GetSystemTimePreciseAsFileTime(&un.utcNowFiletime);
return un.utcNow / TocksPerMicrosecond - MicrosecondsFrom1601To1901;
}
#else // _WIN32_WINNT >= _WIN32_WINNT_WIN8

/* Compute the current VM time basis, the number of microseconds from 1901.
*
* Alas Windows' system time functions GetSystemTime et al have low resolution;
Expand Down Expand Up @@ -107,14 +130,15 @@ currentUTCMicroseconds(unsigned __int64 *utcTickBaseUsecsp, DWORD *lastTickp, DW
return *utcTickBaseUsecsp
+ (currentTick - *baseTickp) * MicrosecondsPerMillisecond;
}
#endif // (_WIN32_WINNT >= _WIN32_WINNT_WIN8)

unsigned long long
usqLong
ioUTCMicroseconds() { return currentUTCMicroseconds(&utcTickBaseMicroseconds, &lastTick, &baseTick); }

/* This is an expensive interface for use by profiling code that wants the time
* now rather than as of the last heartbeat.
*/
unsigned long long
usqLong
ioUTCMicrosecondsNow() { return currentUTCMicroseconds(&utcTickBaseMicroseconds, &lastTick, &baseTick); }

static DWORD dwTimerPeriod;
Expand All @@ -125,7 +149,7 @@ ioInitTime()
TIMECAPS tCaps;

dwTimerPeriod = 0;
if(timeGetDevCaps(&tCaps,sizeof(tCaps)) != 0)
if (timeGetDevCaps(&tCaps,sizeof(tCaps)) != 0)
return;
dwTimerPeriod = tCaps.wPeriodMin;
if (timeBeginPeriod(dwTimerPeriod) != 0)
Expand Down
6 changes: 3 additions & 3 deletions platforms/unix/vm/aio.c
Expand Up @@ -393,7 +393,7 @@ aioPoll(long microSeconds)
return 0;

do {
const unsigned long long start = ioUTCMicroseconds();
const usqLong start = ioUTCMicroseconds();
const struct epoll_event events[128];
const int eventsTriggered = epoll_wait(epollFd, (struct epoll_event*)events, 128, (int)(microSeconds / 1000));
if (eventsTriggered == -1) {
Expand Down Expand Up @@ -444,7 +444,7 @@ aioPoll(long microSeconds)

int fd;
fd_set rd, wr, ex;
unsigned long long us;
usqLong us;
# if AIO_DEBUG
struct sigaction current_sigio_action;
extern void forceInterruptCheck(int); /* not really, but hey */
Expand Down Expand Up @@ -482,7 +482,7 @@ aioPoll(long microSeconds)
for (;;) {
struct timeval tv;
int n;
unsigned long long now;
usqLong now;

tv.tv_sec = microSeconds / 1000000;
tv.tv_usec = microSeconds % 1000000;
Expand Down
32 changes: 16 additions & 16 deletions platforms/unix/vm/sqUnixHeartbeat.c
Expand Up @@ -42,12 +42,12 @@

#define MicrosecondsPerMillisecond 1000LL

static unsigned volatile long long utcMicrosecondClock;
static unsigned volatile long long localMicrosecondClock;
static unsigned volatile long millisecondClock; /* for the ioMSecs clock. */
static unsigned long long utcStartMicroseconds; /* for the ioMSecs clock. */
static long long vmGMTOffset = 0;
static unsigned long long frequencyMeasureStart = 0;
static volatile usqLong utcMicrosecondClock;
static volatile usqLong localMicrosecondClock;
static volatile unsigned long millisecondClock; /* for the ioMSecs clock. */
static usqLong utcStartMicroseconds; /* for the ioMSecs clock. */
static sqLong vmGMTOffset = 0;
static usqLong frequencyMeasureStart = 0;
static unsigned long heartbeats;

#define microToMilliseconds(usecs) ((((usecs) - utcStartMicroseconds) \
Expand All @@ -58,7 +58,7 @@ static unsigned long heartbeats;

#if LOG_CLOCK
# define LOGSIZE 1024
static unsigned long long useclog[LOGSIZE];
static usqLong useclog[LOGSIZE];
static unsigned long mseclog[LOGSIZE];
static int logClock = 0;
static unsigned int ulogidx = (unsigned int)-1;
Expand Down Expand Up @@ -93,7 +93,7 @@ ioGetClockLogSizeUsecsIdxMsecsIdx(sqInt *np, void **usecsp, sqInt *uip, void **m

/* Compute the current VM time basis, the number of microseconds from 1901. */

static unsigned long long
static usqLong
currentUTCMicroseconds()
{
struct timeval utcNow;
Expand Down Expand Up @@ -121,8 +121,8 @@ currentUTCMicroseconds()
static void
updateMicrosecondClock()
{
unsigned long long newUtcMicrosecondClock;
unsigned long long newLocalMicrosecondClock;
usqLong newUtcMicrosecondClock;
usqLong newLocalMicrosecondClock;

newUtcMicrosecondClock = currentUTCMicroseconds();

Expand Down Expand Up @@ -196,10 +196,10 @@ ioHighResClock(void)
return value;
}

unsigned long long
usqLong
ioUTCMicroseconds() { return get64(utcMicrosecondClock); }

unsigned long long
usqLong
ioLocalMicroseconds() { return get64(localMicrosecondClock); }

sqInt
Expand All @@ -208,13 +208,13 @@ ioLocalSecondsOffset() { return vmGMTOffset / MicrosecondsPerSecond; }
/* This is an expensive interface for use by Smalltalk or vm profiling code that
* wants the time now rather than as of the last heartbeat.
*/
unsigned long long
usqLong
ioUTCMicrosecondsNow() { return currentUTCMicroseconds(); }

unsigned long long
usqLong
ioUTCStartMicroseconds() { return utcStartMicroseconds; }

unsigned long long
usqLong
ioLocalMicrosecondsNow() { return currentUTCMicroseconds() + vmGMTOffset; };

/* ioMSecs answers the millisecondClock as of the last tick. */
Expand Down Expand Up @@ -440,7 +440,7 @@ ioHeartbeatFrequency(int resetStats)
unsigned long frequency = duration ? heartbeats / duration : 0;

if (resetStats) {
unsigned long long zero = 0;
usqLong zero = 0;
set64(frequencyMeasureStart,zero);
}
return frequency;
Expand Down

0 comments on commit f237888

Please sign in to comment.