* [9fans] Is POSIX:clock_gettime(2) in APE somewhere/anywhere?
@ 2021-10-11 18:39 tlaronde
2021-10-11 19:12 ` ori
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: tlaronde @ 2021-10-11 18:39 UTC (permalink / raw)
To: 9fans
Hello,
LaTeX now requires primitives (extensions) that are not provided by TeX
nor e-TeX.
I have hence developed a new engine: Prote, that adds the required
extensions and that will be the main target for the future enhancements.
(The main purpose is to have one and only one engine, TeX compatible,
e-TeX compatible and LaTeX compatible, with only libc requirements and
BSD like licence, in order to set TeX as the OSes typographical engine.)
Amongst the extensions I had to add, there are two bits that go beyond
ISO C libc. One is a way to get elapsed time and unfortunately clock(3)
is not the answer. I then used POSIX.1:clock_gettime(2) with CLOCK_MONOTONIC
or CLOCK_REALTIME if the previous is not defined.
But is clock_gettime(2) available in APE in any instance of Plan9 or is
there a routine achieving the same purpose?
TIA,
--
Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
http://www.kergis.com/
http://kertex.kergis.com/
http://www.sbfa.fr/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89 250D 52B1 AE95 6006 F40C
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T1992d89fd8b382c7-M8861017ed3da89d5efd38e78
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [9fans] Is POSIX:clock_gettime(2) in APE somewhere/anywhere?
2021-10-11 18:39 [9fans] Is POSIX:clock_gettime(2) in APE somewhere/anywhere? tlaronde
@ 2021-10-11 19:12 ` ori
2021-10-12 7:04 ` tlaronde
2021-10-11 19:20 ` Sigrid Solveig Haflínudóttir
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: ori @ 2021-10-11 19:12 UTC (permalink / raw)
To: 9fans
Quoth tlaronde@polynum.com:
> Hello,
>
> LaTeX now requires primitives (extensions) that are not provided by TeX
> nor e-TeX.
>
> I have hence developed a new engine: Prote, that adds the required
> extensions and that will be the main target for the future enhancements.
>
> (The main purpose is to have one and only one engine, TeX compatible,
> e-TeX compatible and LaTeX compatible, with only libc requirements and
> BSD like licence, in order to set TeX as the OSes typographical engine.)
>
> Amongst the extensions I had to add, there are two bits that go beyond
> ISO C libc. One is a way to get elapsed time and unfortunately clock(3)
> is not the answer. I then used POSIX.1:clock_gettime(2) with CLOCK_MONOTONIC
> or CLOCK_REALTIME if the previous is not defined.
>
> But is clock_gettime(2) available in APE in any instance of Plan9 or is
> there a routine achieving the same purpose?
>
Currently, no. It can be added without too much
trouble, though we'd need to create /dev/monotime
to get properly monotonic time.
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T1992d89fd8b382c7-M180ef7ef96fa06ad00c452eb
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [9fans] Is POSIX:clock_gettime(2) in APE somewhere/anywhere?
2021-10-11 18:39 [9fans] Is POSIX:clock_gettime(2) in APE somewhere/anywhere? tlaronde
2021-10-11 19:12 ` ori
@ 2021-10-11 19:20 ` Sigrid Solveig Haflínudóttir
2021-10-12 7:05 ` tlaronde
2021-10-12 18:05 ` tlaronde
2021-10-14 21:54 ` ori
3 siblings, 1 reply; 9+ messages in thread
From: Sigrid Solveig Haflínudóttir @ 2021-10-11 19:20 UTC (permalink / raw)
To: 9fans
I've been using cycles() with _tos on amd64/arm64 with 9front for my
porting needs, specifically to get monotonic time:
https://git.sr.ht/~ft/npe/tree/master/item/libnpe/_npe.c#L15
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T1992d89fd8b382c7-M6470aec9234ed1849753fcd8
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [9fans] Is POSIX:clock_gettime(2) in APE somewhere/anywhere?
2021-10-11 19:12 ` ori
@ 2021-10-12 7:04 ` tlaronde
0 siblings, 0 replies; 9+ messages in thread
From: tlaronde @ 2021-10-12 7:04 UTC (permalink / raw)
To: 9fans
Le Mon, Oct 11, 2021 at 03:12:11PM -0400, ori@eigenstate.org a écrit :
> Quoth tlaronde@polynum.com:
> > Hello,
> >
> > LaTeX now requires primitives (extensions) that are not provided by TeX
> > nor e-TeX.
> >
> > I have hence developed a new engine: Prote, that adds the required
> > extensions and that will be the main target for the future enhancements.
> >
> > (The main purpose is to have one and only one engine, TeX compatible,
> > e-TeX compatible and LaTeX compatible, with only libc requirements and
> > BSD like licence, in order to set TeX as the OSes typographical engine.)
> >
> > Amongst the extensions I had to add, there are two bits that go beyond
> > ISO C libc. One is a way to get elapsed time and unfortunately clock(3)
> > is not the answer. I then used POSIX.1:clock_gettime(2) with CLOCK_MONOTONIC
> > or CLOCK_REALTIME if the previous is not defined.
> >
> > But is clock_gettime(2) available in APE in any instance of Plan9 or is
> > there a routine achieving the same purpose?
> >
>
> Currently, no. It can be added without too much
> trouble, though we'd need to create /dev/monotime
> to get properly monotonic time.
Thanks for the answer;
For the time being, I will then simply make the "timer" with a
granularity of 1 second only simply diffing times on plan9.
--
Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
http://www.kergis.com/
http://kertex.kergis.com/
http://www.sbfa.fr/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89 250D 52B1 AE95 6006 F40C
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T1992d89fd8b382c7-M4dd508f8a596794104d451af
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [9fans] Is POSIX:clock_gettime(2) in APE somewhere/anywhere?
2021-10-11 19:20 ` Sigrid Solveig Haflínudóttir
@ 2021-10-12 7:05 ` tlaronde
0 siblings, 0 replies; 9+ messages in thread
From: tlaronde @ 2021-10-12 7:05 UTC (permalink / raw)
To: 9fans
Le Mon, Oct 11, 2021 at 09:20:31PM +0200, Sigrid Solveig Haflínudóttir a écrit :
> I've been using cycles() with _tos on amd64/arm64 with 9front for my
> porting needs, specifically to get monotonic time:
> https://git.sr.ht/~ft/npe/tree/master/item/libnpe/_npe.c#L15
Thank you for the hint. I will take a look.
--
Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
http://www.kergis.com/
http://kertex.kergis.com/
http://www.sbfa.fr/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89 250D 52B1 AE95 6006 F40C
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T1992d89fd8b382c7-M46eab90c250799d3e308a8b9
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [9fans] Is POSIX:clock_gettime(2) in APE somewhere/anywhere?
2021-10-11 18:39 [9fans] Is POSIX:clock_gettime(2) in APE somewhere/anywhere? tlaronde
2021-10-11 19:12 ` ori
2021-10-11 19:20 ` Sigrid Solveig Haflínudóttir
@ 2021-10-12 18:05 ` tlaronde
2021-10-14 19:58 ` Thaddeus Woskowiak
2021-10-14 21:54 ` ori
3 siblings, 1 reply; 9+ messages in thread
From: tlaronde @ 2021-10-12 18:05 UTC (permalink / raw)
To: 9fans
Le Mon, Oct 11, 2021 at 08:39:31PM +0200, tlaronde@polynum.com a écrit :
>[...]
> Amongst the extensions I had to add, there are two bits that go beyond
> ISO C libc. One is a way to get elapsed time and unfortunately clock(3)
> is not the answer. I then used POSIX.1:clock_gettime(2) with CLOCK_MONOTONIC
> or CLOCK_REALTIME if the previous is not defined.
>
> But is clock_gettime(2) available in APE in any instance of Plan9 or is
> there a routine achieving the same purpose?
For what I need, in fact I can simply use nsec(2), diffing nanoseconds
times! (I have the printed manuals from Vita Nuova, I should remember
to read the man pages first in printed form at leisure...)
--
Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
http://www.kergis.com/
http://kertex.kergis.com/
http://www.sbfa.fr/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89 250D 52B1 AE95 6006 F40C
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T1992d89fd8b382c7-M7450a2a55a3baa87b5a2f993
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [9fans] Is POSIX:clock_gettime(2) in APE somewhere/anywhere?
2021-10-12 18:05 ` tlaronde
@ 2021-10-14 19:58 ` Thaddeus Woskowiak
0 siblings, 0 replies; 9+ messages in thread
From: Thaddeus Woskowiak @ 2021-10-14 19:58 UTC (permalink / raw)
To: 9fans
[-- Attachment #1: Type: text/plain, Size: 682 bytes --]
The Vita Nuova man pages are woefully outdated. You might want to consider
purchasing the printed 9front man pages. http://9front.org/propaganda/books
Of course the most up-to-date man pages are available via man after a
sysupdate.
> For what I need, in fact I can simply use nsec(2), diffing nanoseconds
> times! (I have the printed manuals from Vita Nuova, I should remember
> to read the man pages first in printed form at leisure...)
>
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T1992d89fd8b382c7-M396f6268e903dd155be665ea
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
[-- Attachment #2: Type: text/html, Size: 1449 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [9fans] Is POSIX:clock_gettime(2) in APE somewhere/anywhere?
2021-10-11 18:39 [9fans] Is POSIX:clock_gettime(2) in APE somewhere/anywhere? tlaronde
` (2 preceding siblings ...)
2021-10-12 18:05 ` tlaronde
@ 2021-10-14 21:54 ` ori
2021-10-15 11:15 ` tlaronde
3 siblings, 1 reply; 9+ messages in thread
From: ori @ 2021-10-14 21:54 UTC (permalink / raw)
To: 9fans
Quoth tlaronde@polynum.com:
> But is clock_gettime(2) available in APE in any instance of Plan9 or is
> there a routine achieving the same purpose?
Here's a quick sketch of something that we could add; note
that the implemented monotonicity is really crude.
diff 03d870e0283299404b0eb46689d13f8538e83a2f uncommitted
--- a//sys/include/ape/time.h
+++ b//sys/include/ape/time.h
@@ -53,15 +53,20 @@
#ifdef _POSIX_SOURCE
extern void tzset(void);
+#define CLOCK_REALTIME 1
+#define CLOCK_MONOTONIC 2
+
+typedef int clockid_t;
+
struct timespec {
time_t tv_sec;
long tv_nsec;
};
extern int nanosleep(const struct timespec *req, struct timespec *rem);
-#endif
-#ifdef __cplusplus
-}
+extern int clock_getres(clockid_t, struct timespec*);
+extern int clock_gettime(clockid_t, struct timespec*);
+extern int clock_settime(clockid_t, struct timespec*);
#endif
#ifdef _POSIX_SOURCE
@@ -69,6 +74,10 @@
extern long timezone;
extern long altzone;
extern int daylight;
+#endif
+
+#ifdef __cplusplus
+}
#endif
#endif /* __TIME_H */
--- /tmp/diff100001791256
+++ b/sys/src/ape/lib/bsd/clock.c
@@ -1,0 +1,60 @@
+#include <sys/types.h>
+#include <time.h>
+#include <errno.h>
+#include <lock.h>
+
+/* ap/plan9/9nsec.c */
+extern long long _NSEC(void);
+
+#define Ns2sec (1000*1000*1000)
+
+int
+clock_getres(clockid_t id, struct timespec *ts)
+{
+ if(id != CLOCK_REALTIME && id != CLOCK_MONOTONIC){
+ errno = EINVAL;
+ return -1;
+ }
+ ts->tv_sec = 0;
+ ts->tv_nsec = 1;
+ return 0;
+}
+
+int
+clock_settime(clockid_t, struct timespec *)
+{
+ errno = EPERM;
+ return -1;
+}
+
+int
+clock_gettime(clockid_t clk, struct timespec *ts)
+{
+ static Lock maxlk;
+ static long long max;
+ long long t;
+
+ t = _NSEC();
+ switch(clk){
+ case CLOCK_REALTIME:
+ /* nothing */
+ break;
+ case CLOCK_MONOTONIC:
+ /* Bug: we should support a real monotonic clock */
+ lock(&maxlk);
+ if(t < max)
+ t = max;
+ else
+ max = t;
+ unlock(&maxlk);
+ break;
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+
+ ts->tv_sec = t/Ns2sec;
+ ts->tv_nsec = t%Ns2sec;
+
+ return 0;
+}
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T1992d89fd8b382c7-Mf08f6aaf225fc08a5763ecb2
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [9fans] Is POSIX:clock_gettime(2) in APE somewhere/anywhere?
2021-10-14 21:54 ` ori
@ 2021-10-15 11:15 ` tlaronde
0 siblings, 0 replies; 9+ messages in thread
From: tlaronde @ 2021-10-15 11:15 UTC (permalink / raw)
To: 9fans
Le Thu, Oct 14, 2021 at 05:54:44PM -0400, ori@eigenstate.org a écrit :
> Quoth tlaronde@polynum.com:
> > But is clock_gettime(2) available in APE in any instance of Plan9 or is
> > there a routine achieving the same purpose?
>
> Here's a quick sketch of something that we could add; note
> that the implemented monotonicity is really crude.
>
> diff 03d870e0283299404b0eb46689d13f8538e83a2f uncommitted
> --- a//sys/include/ape/time.h
> +++ b//sys/include/ape/time.h
> @@ -53,15 +53,20 @@
> #ifdef _POSIX_SOURCE
> extern void tzset(void);
>
> +#define CLOCK_REALTIME 1
> +#define CLOCK_MONOTONIC 2
> +
> +typedef int clockid_t;
> +
> struct timespec {
> time_t tv_sec;
> long tv_nsec;
> };
> extern int nanosleep(const struct timespec *req, struct timespec *rem);
> -#endif
>
> -#ifdef __cplusplus
> -}
> +extern int clock_getres(clockid_t, struct timespec*);
> +extern int clock_gettime(clockid_t, struct timespec*);
> +extern int clock_settime(clockid_t, struct timespec*);
> #endif
>
> #ifdef _POSIX_SOURCE
> @@ -69,6 +74,10 @@
> extern long timezone;
> extern long altzone;
> extern int daylight;
> +#endif
> +
> +#ifdef __cplusplus
> +}
> #endif
>
> #endif /* __TIME_H */
> --- /tmp/diff100001791256
> +++ b/sys/src/ape/lib/bsd/clock.c
> @@ -1,0 +1,60 @@
> +#include <sys/types.h>
> +#include <time.h>
> +#include <errno.h>
> +#include <lock.h>
> +
> +/* ap/plan9/9nsec.c */
> +extern long long _NSEC(void);
> +
> +#define Ns2sec (1000*1000*1000)
> +
> +int
> +clock_getres(clockid_t id, struct timespec *ts)
> +{
> + if(id != CLOCK_REALTIME && id != CLOCK_MONOTONIC){
> + errno = EINVAL;
> + return -1;
> + }
> + ts->tv_sec = 0;
> + ts->tv_nsec = 1;
> + return 0;
> +}
> +
> +int
> +clock_settime(clockid_t, struct timespec *)
> +{
> + errno = EPERM;
> + return -1;
> +}
> +
> +int
> +clock_gettime(clockid_t clk, struct timespec *ts)
> +{
> + static Lock maxlk;
> + static long long max;
> + long long t;
> +
> + t = _NSEC();
> + switch(clk){
> + case CLOCK_REALTIME:
> + /* nothing */
> + break;
> + case CLOCK_MONOTONIC:
> + /* Bug: we should support a real monotonic clock */
> + lock(&maxlk);
> + if(t < max)
> + t = max;
> + else
> + max = t;
> + unlock(&maxlk);
> + break;
> + default:
> + errno = EINVAL;
> + return -1;
> + }
> +
> + ts->tv_sec = t/Ns2sec;
> + ts->tv_nsec = t%Ns2sec;
> +
> + return 0;
> +}
Since only CLOCK_REALTIME is mandatory (up to current POSIX 7), you could drop the MONOTONIC
variant. And nsec(2) is good enough for REALTIME.
Thanks for working on this!
Best,
--
Thierry Laronde <tlaronde +AT+ polynum +dot+ com>
http://www.kergis.com/
http://kertex.kergis.com/
http://www.sbfa.fr/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89 250D 52B1 AE95 6006 F40C
------------------------------------------
9fans: 9fans
Permalink: https://9fans.topicbox.com/groups/9fans/T1992d89fd8b382c7-Me0d4b6affdd5977cbe6d2c8b
Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-10-15 11:15 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-11 18:39 [9fans] Is POSIX:clock_gettime(2) in APE somewhere/anywhere? tlaronde
2021-10-11 19:12 ` ori
2021-10-12 7:04 ` tlaronde
2021-10-11 19:20 ` Sigrid Solveig Haflínudóttir
2021-10-12 7:05 ` tlaronde
2021-10-12 18:05 ` tlaronde
2021-10-14 19:58 ` Thaddeus Woskowiak
2021-10-14 21:54 ` ori
2021-10-15 11:15 ` tlaronde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).