Rocket U2 | UniVerse & UniData

 View Only

 Unidata 7.2 on AIX - Is there a way to do a millisecond sleep?

Jump to Best Answer
Kevin King's profile image
Kevin King posted 04-20-2021 10:50
I have a need to do a 400ms sleep in a Unidata program.  Is it possible?
Steve Wingfield's profile image
ROCKETEER Steve Wingfield Best Answer
Hi Kevin,

You could also leverage openSocket's millisecond timeout parameter, and go to a non-listening address:


DESIRED.SLEEP.TIME = 400 ;* in milliseconds

* openSocket tries 3 times, so scale down
* the desired sleep time by 1/3...
SOCKET.TIMEOUT     = INT(DESIRED.SLEEP.TIME/3)
NON.LISTENING.IP   = "192.0.2.0" ; * see https://tools.ietf.org/html/rfc5737
NON.LISTENING.PORT = 0
BLOCKING           = 1
START.TIME = SYSTEM(12)
RET = openSocket(NON.LISTENING.IP, NON.LISTENING.PORT, BLOCKING, SOCKET.TIMEOUT, OUT.HANDLE)
END.TIME = SYSTEM(12)

PRINT "Elapsed Time: " : (END.TIME - START.TIME)
​
David Green's profile image
David Green
Try using SYSTEM(12)
David Green's profile image
David Green
or maybe you could shell out and do a Unix sleep 0.4 with PCPERFORM?
Kevin King's profile image
Kevin King
the problem with SYSTEM(12) is that to use this would require a tight loop and that's exactly what I'm trying to avoid.  Regarding shelling out, thought about that too but it's impossible to calculate the ms overhead of the shell execution to more precisely hit the delay time.
David Green's profile image
David Green
That's all true.  I believe the only method left is to use CALLC.
Kevin King's profile image
Kevin King
yeah, I was afraid of that.  No way I want to try to do a CALLC thing on an AIX box.
Stuart Boydell's profile image
Stuart Boydell
Can PAUSE accept a fraction?
If it was a later system then, callout to Python...
pytime = pyImport('time')
z  = pyCallMethod(pytime,'sleep',0.4)
Nik Kesic's profile image
Nik Kesic
Hello Kevin

the AIX freeware tools have a updated version of sleep. You can sleep milliseconds

AE BP WAIT
Top of "WAIT" in "BP", 4 lines, 90 characters.
001: CRT "START"
002: PCPERFORM "timex /opt/freeware/bin/sleep 0.5" CAPTURING NED
003: CRT NED
004: CRT "DONE"
Bottom.
*--: fibr
Filed "WAIT" in file "BP".

Compiling Unibasic: BP/WAIT in mode 'u'.
compilation finished
START
þreal 0.50þuser 0.00þsys 0.00þþ
DONE


Nik
Nik Kesic's profile image
Nik Kesic
Kevin,

You could do this
  sleep 0.001

And you can install the package "yum install AIX_Toolbox" if you don't have it.

Nik
Kevin King's profile image
Kevin King
That's great Nik, thanks.  What's the overhead of the PCPERFORM?  Any way to get a timing on that?
Nik Kesic's profile image
Nik Kesic
Hello Kevin

My gut feel tells me microseconds... or maybe worst case 10 mS.

I was trying to figure a good truss command to see how much... I will look deeper and see if I can find something

cheers

Nik
David Green's profile image
David Green
can you time like this:

START.TIME = SYSTEM(12)
PCPERFORM "echo Testing" CAPTURING BUFF
END.TIME = SYSTEM(12)
DURATION = END.TIME - START.TIME
PRINT DURATION
*
** Since PCPERFORM overhead and execution may vary from moment to moment do this:
*
Then take your 400 milliseconds - (Duration * 2) to come up with the sleep time you need.
Kevin King's profile image
Kevin King
That is SUPER clever David.  Good on ya, man.  

It does make an assumption that the overhead is going to be constant, but then again even if the timer were baked into Unidata, there would be some variability based on load.  But dang, a great idea!
Nik Kesic's profile image
Nik Kesic
Hi Kevin

I used system(12) as suggested by @David Green and it looks like the cost is 6-8mS 

​STIME=SYSTEM(12)
PCPERFORM "/opt/freeware/bin/sleep 0.5" CAPTURING NED
ETIME=SYSTEM(12)
TTIME=ETIME-STIME
CRT TTIME

My test ran on a IBM Power 924 
On a P980 with 4K users, the times were 10-15mS scewed

Nik
Kevin King's profile image
Kevin King
Wow, that is a great idea.  Thank you sir!