Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Love may fail, but courtesy will previal." -- A Kurt Vonnegut fan


devel / comp.lang.forth / GForth on Raspi OS Using PThreads - stick-to-core

SubjectAuthor
* GForth on Raspi OS Using PThreads - stick-to-coreChristof Eberspaecher
+* Re: GForth on Raspi OS Using PThreads - stick-to-coreAnton Ertl
|`- Re: GForth on Raspi OS Using PThreads - stick-to-coreChristof Eberspaecher
`* Re: GForth on Raspi OS Using PThreads - stick-to-corenone
 +* Re: GForth on Raspi OS Using PThreads - stick-to-coreChristof Eberspaecher
 |`* Re: GForth on Raspi OS Using PThreads - stick-to-coreChristof Eberspaecher
 | `- Re: GForth on Raspi OS Using PThreads - stick-to-coreAnton Ertl
 `* Re: GForth on Raspi OS Using PThreads - stick-to-coreChristof Eberspaecher
  `- Re: GForth on Raspi OS Using PThreads - stick-to-coreChristof Eberspaecher

1
GForth on Raspi OS Using PThreads - stick-to-core

<aff8f55b-e72e-4cc5-a99d-45b91e55874cn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19330&group=comp.lang.forth#19330

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:4546:b0:6b5:f144:68bb with SMTP id u6-20020a05620a454600b006b5f14468bbmr6393213qkp.253.1658678018693;
Sun, 24 Jul 2022 08:53:38 -0700 (PDT)
X-Received: by 2002:a05:6214:dcb:b0:474:23c7:475 with SMTP id
11-20020a0562140dcb00b0047423c70475mr7464243qvt.68.1658678018489; Sun, 24 Jul
2022 08:53:38 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sun, 24 Jul 2022 08:53:38 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=77.190.172.10; posting-account=qjKo8woAAADX2G4lnOrWMOI0EutZnVRt
NNTP-Posting-Host: 77.190.172.10
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <aff8f55b-e72e-4cc5-a99d-45b91e55874cn@googlegroups.com>
Subject: GForth on Raspi OS Using PThreads - stick-to-core
From: chwebe...@gmail.com (Christof Eberspaecher)
Injection-Date: Sun, 24 Jul 2022 15:53:38 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2606
 by: Christof Eberspaeche - Sun, 24 Jul 2022 15:53 UTC

Hi,
background: The goal is to control a small lathe with a Raspberry Pi using GForth 0-7-9. The axis are moved by step motors. The idea is to use a maximum step frequency, that always allows to stop within one full step. So if there is a time lag, steps should not be lost. Linear motion is done by a separate pthread.

I have reserved core 3 using isolcpus=3. I can start GForth with all it's tasks on core 3 with "taskset". But this is not what I want to do, as only the stepper-thread shall use this CPU for best performance. So I try to use " 3 stick-to-core" but it does not seem to work. Is this tested on a raspi?
( I use "def" instead of ":" to get a function list with Geany as a Python file. "pStat addStat" is used to calculate average and standard deviation of the lag. )

....
def usTDelay ( usecs ) 1000 * stop-ns ;

0 value stepperTask
0 value tMax#
0 value core#

def startStep \ Test Timing
stacksize4 NewTask4 dup to stepperTask
activate decimal
1000 usTDelay
0 to core#
3 stick-to-core to core# \ <<<<<<<<<<<<<<< ???
100000 usTDelay
begin
utime
\ 100000 stop-ns
100 usTDelay
utime 2swap d-
d>s 100 -
dup tMax# max to tMax#
pStat addStat
pause
pStat @ 9999 > until
begin 1000 usTDelay pause again
; ....
The 22decimal is written to core#. As far as I understand, this should be 0.. The code/thread is running but not with improved performance.

Thanks for some hints!
Christof

Re: GForth on Raspi OS Using PThreads - stick-to-core

<2022Jul24.184524@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19334&group=comp.lang.forth#19334

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: GForth on Raspi OS Using PThreads - stick-to-core
Date: Sun, 24 Jul 2022 16:45:24 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 28
Message-ID: <2022Jul24.184524@mips.complang.tuwien.ac.at>
References: <aff8f55b-e72e-4cc5-a99d-45b91e55874cn@googlegroups.com>
Injection-Info: reader01.eternal-september.org; posting-host="80828522b5a55344739309f76d137e47";
logging-data="778282"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/0ai0XHp+2NtOl9Do36Omt"
Cancel-Lock: sha1:qcfs+ckfbgqdQYGr3GjToRsJNLE=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Sun, 24 Jul 2022 16:45 UTC

Christof Eberspaecher <chwebersp@gmail.com> writes:
>I have reserved core 3 using isolcpus=3D3. I can start GForth with all it's=
> tasks on core 3 with "taskset". But this is not what I want to do, as only=
> the stepper-thread shall use this CPU for best performance. So I try to us=
>e " 3 stick-to-core" but it does not seem to work. Is this tested on a rasp=
>i?

Apparently not tested at all, because it always returns EINVAL before
setting thread affinity. I have now fixed this:

<http://git.savannah.gnu.org/cgit/gforth.git/commit/?id=c6e54a12ad1a68e2353284df9c5caf0cbdab749b>

I have tested the result on a PC, and it now works. I would be very
surprised if it did not on a Raspi.

What I used for fixing this bug:
<https://stackoverflow.com/questions/1407786/how-to-set-cpu-affinity-of-a-particular-pthread>,

>The 22decimal is written to core#. As far as I understand, this should be 0=

22 as return value is EINVAL; it should be 0.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: https://forth-standard.org/
EuroForth 2022: http://www.euroforth.org/ef22/cfp.html

Re: GForth on Raspi OS Using PThreads - stick-to-core

<224a2714-7076-424b-bc16-d380b270119fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19342&group=comp.lang.forth#19342

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:f12:b0:6b6:64e9:260c with SMTP id v18-20020a05620a0f1200b006b664e9260cmr491934qkl.538.1658738089369;
Mon, 25 Jul 2022 01:34:49 -0700 (PDT)
X-Received: by 2002:a37:42d6:0:b0:6b5:7da4:4cb2 with SMTP id
p205-20020a3742d6000000b006b57da44cb2mr8334044qka.588.1658738089128; Mon, 25
Jul 2022 01:34:49 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 25 Jul 2022 01:34:48 -0700 (PDT)
In-Reply-To: <2022Jul24.184524@mips.complang.tuwien.ac.at>
Injection-Info: google-groups.googlegroups.com; posting-host=77.185.57.196; posting-account=qjKo8woAAADX2G4lnOrWMOI0EutZnVRt
NNTP-Posting-Host: 77.185.57.196
References: <aff8f55b-e72e-4cc5-a99d-45b91e55874cn@googlegroups.com> <2022Jul24.184524@mips.complang.tuwien.ac.at>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <224a2714-7076-424b-bc16-d380b270119fn@googlegroups.com>
Subject: Re: GForth on Raspi OS Using PThreads - stick-to-core
From: chwebe...@gmail.com (Christof Eberspaecher)
Injection-Date: Mon, 25 Jul 2022 08:34:49 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3500
 by: Christof Eberspaeche - Mon, 25 Jul 2022 08:34 UTC

Anton Ertl schrieb am Sonntag, 24. Juli 2022 um 19:19:25 UTC+2:
> Christof Eberspaecher <chwe...@gmail.com> writes:
> >I have reserved core 3 using isolcpus=3D3. I can start GForth with all it's=
> > tasks on core 3 with "taskset". But this is not what I want to do, as only=
> > the stepper-thread shall use this CPU for best performance. So I try to us=
> >e " 3 stick-to-core" but it does not seem to work. Is this tested on a rasp=
> >i?
>
> Apparently not tested at all, because it always returns EINVAL before
> setting thread affinity. I have now fixed this:
>
> <http://git.savannah.gnu.org/cgit/gforth.git/commit/?id=c6e54a12ad1a68e2353284df9c5caf0cbdab749b>
>
> I have tested the result on a PC, and it now works. I would be very
> surprised if it did not on a Raspi.
>
> What I used for fixing this bug:
> <https://stackoverflow.com/questions/1407786/how-to-set-cpu-affinity-of-a-particular-pthread>,
>
> >The 22decimal is written to core#. As far as I understand, this should be 0=
>
> 22 as return value is EINVAL; it should be 0.
>
> - anton
> --
> M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
> comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
> New standard: https://forth-standard.org/
> EuroForth 2022: http://www.euroforth.org/ef22/cfp.html

Thank you very much, Anton, for the very fast action. It now returns 0.

Unfortunately the effect is still not good. Numbers for latency in µs:
standard deviation, average, max of 10000 samples
2 59 226 if I start GForth with all it's processes on reserved core 3 using taskset, no stick-to core
same if I use "3 stick-to-core" on the GForth prompt before starting the test

8 62 up to 26.000, if I start GForth just normally, no stick-to-core
319 71 up to 21.000, if I start GForth just normally, 3 stick-to-core for the testthread
0 stick-to-core for the testthread gives the same numbers.

So stick-to-core seems to work now for GForth including a sub-thread but not for a sub-thread only.
I experimented with "sched_setaffinity(" but the results have been the same..

Re: GForth on Raspi OS Using PThreads - stick-to-core

<nnd$46402dd4$2c7462db@f752040070f4ac81>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19346&group=comp.lang.forth#19346

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
References: <aff8f55b-e72e-4cc5-a99d-45b91e55874cn@googlegroups.com>
Subject: Re: GForth on Raspi OS Using PThreads - stick-to-core
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: alb...@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$46402dd4$2c7462db@f752040070f4ac81>
Organization: KPN B.V.
Date: Mon, 25 Jul 2022 11:05:29 +0200
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!news.freedyn.de!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 46
Injection-Date: Mon, 25 Jul 2022 11:05:29 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2951
 by: none - Mon, 25 Jul 2022 09:05 UTC

In article <aff8f55b-e72e-4cc5-a99d-45b91e55874cn@googlegroups.com>,
Christof Eberspaecher <chwebersp@gmail.com> wrote:
>Hi,
>background: The goal is to control a small lathe with a Raspberry Pi
>using GForth 0-7-9. The axis are moved by step motors. The idea is to
>use a maximum step frequency, that always allows to stop within one full
>step. So if there is a time lag, steps should not be lost. Linear motion
>is done by a separate pthread.
>
>I have reserved core 3 using isolcpus=3. I can start GForth with all
>it's tasks on core 3 with "taskset". But this is not what I want to do,
>as only the stepper-thread shall use this CPU for best performance. So I
>try to use " 3 stick-to-core" but it does not seem to work. Is this
>tested on a raspi?

I had some bad experience with isolating CPU's. I have an 8 bit core AMD
and I tried to isolate a CPU for midi bitbanging (midi is a asynchronous
serial signal of 31.25 kHz). This works as far as the software is concerned
with 320 us for 10 bits, e.g. generating a 16 us high 16 us low signal,
up till the 50 ns resolution of the logical analyser.
You have to do other things, such as manipulating the boot up.
I run mprime on the background, and mprime run as if there 8 cores
available, trying to interfere with my midi. So it tried to
run an 8the mprime on the "isolated" core. Of course I killed mprime,
but this is a cludge.
Furthermore, in inspecting a 32 us square wave, it was obvious that
there are numerous interruptions with different time intervals.
midi is robust that it doesn't care to miss-present an event from time
to time, but there was no way I get a scale out of this.

I managed to control mechanical instruments up till mS precision
or better (in Forth) , the isolcpu/taskset is no good for what
we have in mind.
It is interesting to see whether actual examples exists for isolcpu
that accomplishes something useful. Then start from there.

>Thanks for some hints!
>Christof

Groetjes Albert
--
"in our communism country Viet Nam, people are forced to be
alive and in the western country like US, people are free to
die from Covid 19 lol" duc ha
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

Re: GForth on Raspi OS Using PThreads - stick-to-core

<0f084e0e-b3d2-4f9a-8578-7647fcf60a63n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19351&group=comp.lang.forth#19351

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:4726:b0:6b6:2239:f5f7 with SMTP id bs38-20020a05620a472600b006b62239f5f7mr8634320qkb.96.1658748365736;
Mon, 25 Jul 2022 04:26:05 -0700 (PDT)
X-Received: by 2002:a05:6214:dcb:b0:474:23c7:475 with SMTP id
11-20020a0562140dcb00b0047423c70475mr9963720qvt.68.1658748365503; Mon, 25 Jul
2022 04:26:05 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 25 Jul 2022 04:26:05 -0700 (PDT)
In-Reply-To: <nnd$46402dd4$2c7462db@f752040070f4ac81>
Injection-Info: google-groups.googlegroups.com; posting-host=77.185.57.196; posting-account=qjKo8woAAADX2G4lnOrWMOI0EutZnVRt
NNTP-Posting-Host: 77.185.57.196
References: <aff8f55b-e72e-4cc5-a99d-45b91e55874cn@googlegroups.com> <nnd$46402dd4$2c7462db@f752040070f4ac81>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0f084e0e-b3d2-4f9a-8578-7647fcf60a63n@googlegroups.com>
Subject: Re: GForth on Raspi OS Using PThreads - stick-to-core
From: chwebe...@gmail.com (Christof Eberspaecher)
Injection-Date: Mon, 25 Jul 2022 11:26:05 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4729
 by: Christof Eberspaeche - Mon, 25 Jul 2022 11:26 UTC

none albert schrieb am Montag, 25. Juli 2022 um 11:05:32 UTC+2:
> In article <aff8f55b-e72e-4cc5...@googlegroups.com>,
> Christof Eberspaecher <chwe...@gmail.com> wrote:
> >Hi,
> >background: The goal is to control a small lathe with a Raspberry Pi
> >using GForth 0-7-9. The axis are moved by step motors. The idea is to
> >use a maximum step frequency, that always allows to stop within one full
> >step. So if there is a time lag, steps should not be lost. Linear motion
> >is done by a separate pthread.
> >
> >I have reserved core 3 using isolcpus=3. I can start GForth with all
> >it's tasks on core 3 with "taskset". But this is not what I want to do,
> >as only the stepper-thread shall use this CPU for best performance. So I
> >try to use " 3 stick-to-core" but it does not seem to work. Is this
> >tested on a raspi?
> I had some bad experience with isolating CPU's. I have an 8 bit core AMD
> and I tried to isolate a CPU for midi bitbanging (midi is a asynchronous
> serial signal of 31.25 kHz). This works as far as the software is concerned
> with 320 us for 10 bits, e.g. generating a 16 us high 16 us low signal,
> up till the 50 ns resolution of the logical analyser.
> You have to do other things, such as manipulating the boot up.
> I run mprime on the background, and mprime run as if there 8 cores
> available, trying to interfere with my midi. So it tried to
> run an 8the mprime on the "isolated" core. Of course I killed mprime,
> but this is a cludge.
> Furthermore, in inspecting a 32 us square wave, it was obvious that
> there are numerous interruptions with different time intervals.
> midi is robust that it doesn't care to miss-present an event from time
> to time, but there was no way I get a scale out of this.
>
> I managed to control mechanical instruments up till mS precision
> or better (in Forth) , the isolcpu/taskset is no good for what
> we have in mind.
> It is interesting to see whether actual examples exists for isolcpu
> that accomplishes something useful. Then start from there.
> >Thanks for some hints!
> >Christof
> Groetjes Albert
> --
> "in our communism country Viet Nam, people are forced to be
> alive and in the western country like US, people are free to
> die from Covid 19 lol" duc ha
> albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

Thanks, Albert, for sharing your findings!
At the moment using Raspi4b @ 4*1.8GHz average latency with GForth seems to be about 60 µs with seldom peaks up to 1500µs with isolcpus. If you switch windows of Chromium browser in parallel, you can produce additional large latency.

With Preempt-RT kernel 100µs seems to be a possible limit:
https://lemariva.com/blog/2019/09/raspberry-pi-4b-preempt-rt-kernel-419y-performance-test

My hitherto existing solution for the lathe is a combination of Python on Raspi together with a Parallax Propeller 1 running Tachyon Forth for the stepping linear interpolation. I have used that with down to 500µs per 1/4 microstep. The speed limit is given by decreasing torque against friction.. At this moment I still think/hope, that this speed can be done with GForth without RT-kernel too, if you don't do too much with the LAN in parallel. There will be some jitter though.

Gruß Christof

Re: GForth on Raspi OS Using PThreads - stick-to-core

<f90992d4-2244-4c19-af09-45cf0d41653en@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19354&group=comp.lang.forth#19354

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:c25:b0:474:5427:e8cb with SMTP id a5-20020a0562140c2500b004745427e8cbmr2029342qvd.3.1658759417896;
Mon, 25 Jul 2022 07:30:17 -0700 (PDT)
X-Received: by 2002:ac8:5993:0:b0:31f:6a2:872a with SMTP id
e19-20020ac85993000000b0031f06a2872amr10697228qte.663.1658759417676; Mon, 25
Jul 2022 07:30:17 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 25 Jul 2022 07:30:17 -0700 (PDT)
In-Reply-To: <0f084e0e-b3d2-4f9a-8578-7647fcf60a63n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.185.57.196; posting-account=qjKo8woAAADX2G4lnOrWMOI0EutZnVRt
NNTP-Posting-Host: 77.185.57.196
References: <aff8f55b-e72e-4cc5-a99d-45b91e55874cn@googlegroups.com>
<nnd$46402dd4$2c7462db@f752040070f4ac81> <0f084e0e-b3d2-4f9a-8578-7647fcf60a63n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f90992d4-2244-4c19-af09-45cf0d41653en@googlegroups.com>
Subject: Re: GForth on Raspi OS Using PThreads - stick-to-core
From: chwebe...@gmail.com (Christof Eberspaecher)
Injection-Date: Mon, 25 Jul 2022 14:30:17 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5300
 by: Christof Eberspaeche - Mon, 25 Jul 2022 14:30 UTC

Christof Eberspaecher schrieb am Montag, 25. Juli 2022 um 13:26:06 UTC+2:
> none albert schrieb am Montag, 25. Juli 2022 um 11:05:32 UTC+2:
> > In article <aff8f55b-e72e-4cc5...@googlegroups.com>,
> > Christof Eberspaecher <chwe...@gmail.com> wrote:
> > >Hi,
> > >background: The goal is to control a small lathe with a Raspberry Pi
> > >using GForth 0-7-9. The axis are moved by step motors. The idea is to
> > >use a maximum step frequency, that always allows to stop within one full
> > >step. So if there is a time lag, steps should not be lost. Linear motion
> > >is done by a separate pthread.
> > >
> > >I have reserved core 3 using isolcpus=3. I can start GForth with all
> > >it's tasks on core 3 with "taskset". But this is not what I want to do,
> > >as only the stepper-thread shall use this CPU for best performance. So I
> > >try to use " 3 stick-to-core" but it does not seem to work. Is this
> > >tested on a raspi?
> > I had some bad experience with isolating CPU's. I have an 8 bit core AMD
> > and I tried to isolate a CPU for midi bitbanging (midi is a asynchronous
> > serial signal of 31.25 kHz). This works as far as the software is concerned
> > with 320 us for 10 bits, e.g. generating a 16 us high 16 us low signal,
> > up till the 50 ns resolution of the logical analyser.
> > You have to do other things, such as manipulating the boot up.
> > I run mprime on the background, and mprime run as if there 8 cores
> > available, trying to interfere with my midi. So it tried to
> > run an 8the mprime on the "isolated" core. Of course I killed mprime,
> > but this is a cludge.
> > Furthermore, in inspecting a 32 us square wave, it was obvious that
> > there are numerous interruptions with different time intervals.
> > midi is robust that it doesn't care to miss-present an event from time
> > to time, but there was no way I get a scale out of this.
> >
> > I managed to control mechanical instruments up till mS precision
> > or better (in Forth) , the isolcpu/taskset is no good for what
> > we have in mind.
> > It is interesting to see whether actual examples exists for isolcpu
> > that accomplishes something useful. Then start from there.
> > >Thanks for some hints!
> > >Christof
> > Groetjes Albert
> > --
> > "in our communism country Viet Nam, people are forced to be
> > alive and in the western country like US, people are free to
> > die from Covid 19 lol" duc ha
> > albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
> Thanks, Albert, for sharing your findings!
> At the moment using Raspi4b @ 4*1.8GHz average latency with GForth seems to be about 60 µs with seldom peaks up to 1500µs with isolcpus. If you switch windows of Chromium browser in parallel, you can produce additional large latency.
>
> With Preempt-RT kernel 100µs seems to be a possible limit:
> https://lemariva.com/blog/2019/09/raspberry-pi-4b-preempt-rt-kernel-419y-performance-test
>
> My hitherto existing solution for the lathe is a combination of Python on Raspi together with a Parallax Propeller 1 running Tachyon Forth for the stepping linear interpolation. I have used that with down to 500µs per 1/4 microstep. The speed limit is given by decreasing torque against friction. At this moment I still think/hope, that this speed can be done with GForth without RT-kernel too, if you don't do too much with the LAN in parallel. There will be some jitter though.
>
> Gruß Christof

Ha, EDIT: I had done wrong the part of inserting isolcpus=3 into cmdline.txt. It must be inserted into the one and only line! I have had it in a second line.
Now it is possible to start only one pthread in core 3 and maximum latency is <150µs. :-)

Christof

Re: GForth on Raspi OS Using PThreads - stick-to-core

<2022Jul25.170339@mips.complang.tuwien.ac.at>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19357&group=comp.lang.forth#19357

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: GForth on Raspi OS Using PThreads - stick-to-core
Date: Mon, 25 Jul 2022 15:03:39 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 15
Message-ID: <2022Jul25.170339@mips.complang.tuwien.ac.at>
References: <aff8f55b-e72e-4cc5-a99d-45b91e55874cn@googlegroups.com> <nnd$46402dd4$2c7462db@f752040070f4ac81> <0f084e0e-b3d2-4f9a-8578-7647fcf60a63n@googlegroups.com> <f90992d4-2244-4c19-af09-45cf0d41653en@googlegroups.com>
Injection-Info: reader01.eternal-september.org; posting-host="75e1eab1069421daf389743353948dee";
logging-data="1364319"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19xyE+ElkhUXOLH0uYacCio"
Cancel-Lock: sha1:KoliBDobF3X6TN6FZ8G+HprcCR8=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Mon, 25 Jul 2022 15:03 UTC

Christof Eberspaecher <chwebersp@gmail.com> writes:
>Ha, EDIT: I had done wrong the part of inserting isolcpus=3D3 into cmdline.=
>txt. It must be inserted into the one and only line! I have had it in a sec=
>ond line.
>Now it is possible to start only one pthread in core 3 and maximum latency =
>is <150=C2=B5s. :-)

Congratulations!

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: https://forth-standard.org/
EuroForth 2022: http://www.euroforth.org/ef22/cfp.html

Re: GForth on Raspi OS Using PThreads - stick-to-core

<841c7510-fe31-44d3-b88c-e113c11a9ac6n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19379&group=comp.lang.forth#19379

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a37:a54:0:b0:6b5:ccf3:a0ad with SMTP id 81-20020a370a54000000b006b5ccf3a0admr11966104qkk.612.1658830428174;
Tue, 26 Jul 2022 03:13:48 -0700 (PDT)
X-Received: by 2002:ac8:5dcf:0:b0:31e:e3b2:ed2a with SMTP id
e15-20020ac85dcf000000b0031ee3b2ed2amr13592691qtx.546.1658830427927; Tue, 26
Jul 2022 03:13:47 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Tue, 26 Jul 2022 03:13:47 -0700 (PDT)
In-Reply-To: <nnd$46402dd4$2c7462db@f752040070f4ac81>
Injection-Info: google-groups.googlegroups.com; posting-host=77.181.84.223; posting-account=qjKo8woAAADX2G4lnOrWMOI0EutZnVRt
NNTP-Posting-Host: 77.181.84.223
References: <aff8f55b-e72e-4cc5-a99d-45b91e55874cn@googlegroups.com> <nnd$46402dd4$2c7462db@f752040070f4ac81>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <841c7510-fe31-44d3-b88c-e113c11a9ac6n@googlegroups.com>
Subject: Re: GForth on Raspi OS Using PThreads - stick-to-core
From: chwebe...@gmail.com (Christof Eberspaecher)
Injection-Date: Tue, 26 Jul 2022 10:13:48 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 4886
 by: Christof Eberspaeche - Tue, 26 Jul 2022 10:13 UTC

none albert schrieb am Montag, 25. Juli 2022 um 11:05:32 UTC+2:
> In article <aff8f55b-e72e-4cc5...@googlegroups.com>,
> Christof Eberspaecher <chwe...@gmail.com> wrote:
> >Hi,
> >background: The goal is to control a small lathe with a Raspberry Pi
> >using GForth 0-7-9. The axis are moved by step motors. The idea is to
> >use a maximum step frequency, that always allows to stop within one full
> >step. So if there is a time lag, steps should not be lost. Linear motion
> >is done by a separate pthread.
> >
> >I have reserved core 3 using isolcpus=3. I can start GForth with all
> >it's tasks on core 3 with "taskset". But this is not what I want to do,
> >as only the stepper-thread shall use this CPU for best performance. So I
> >try to use " 3 stick-to-core" but it does not seem to work. Is this
> >tested on a raspi?
> I had some bad experience with isolating CPU's. I have an 8 bit core AMD
> and I tried to isolate a CPU for midi bitbanging (midi is a asynchronous
> serial signal of 31.25 kHz). This works as far as the software is concerned
> with 320 us for 10 bits, e.g. generating a 16 us high 16 us low signal,
> up till the 50 ns resolution of the logical analyser.
> You have to do other things, such as manipulating the boot up.
> I run mprime on the background, and mprime run as if there 8 cores
> available, trying to interfere with my midi. So it tried to
> run an 8the mprime on the "isolated" core. Of course I killed mprime,
> but this is a cludge.
> Furthermore, in inspecting a 32 us square wave, it was obvious that
> there are numerous interruptions with different time intervals.
> midi is robust that it doesn't care to miss-present an event from time
> to time, but there was no way I get a scale out of this.
>
> I managed to control mechanical instruments up till mS precision
> or better (in Forth) , the isolcpu/taskset is no good for what
> we have in mind.
> It is interesting to see whether actual examples exists for isolcpu
> that accomplishes something useful. Then start from there.
> >Thanks for some hints!
> >Christof
> Groetjes Albert
> --
> "in our communism country Viet Nam, people are forced to be
> alive and in the western country like US, people are free to
> die from Covid 19 lol" duc ha
> albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

Hi Albert,
Perhaps some findings about latency with isolated core are interesting. This s ferquency distribution of latencies. "56" means, that a delay, which should be 100microsecs was actually 156microseconds.
44 0
50 0
56 22184148
63 2200279
70 72041
79 98707
89 13951
100 4009
112 1472
125 186
141 69
158 21
177 2
199 1
223 0
251 0
Maximum latency of this measurement was 214 microseconds.
Raspi4b @1.8GHz with one isolated core, which was exclusively used to run the testthread. To use GForth-fast has no significant effect.
So, yes, 32kbaud midi serial, which needs resultion better than 16us would clearly not be possible.
If I think, that a resolution of 250us should be possible then a step frequency of 2000Hz will be possible.

The motor winding inductance is relatively high with 7mH and my motor driver has only 24V. For full torque the motor is rated for 1.4A R=3.1Ohm.
So 20V/1.4A= 14Ohms inductive resistance. 14/(2*pi*0.007)= 100Hz full step frequency for max torque. I do not have the data of the motor to calculate counter-emf. So all-in-all 2000Hz seems not to be the show stopper.

It is also interesting, that in this environment of linux, using GForth seems not to be the speed limiting factor for this application. :-)
Christof

Re: GForth on Raspi OS Using PThreads - stick-to-core

<f84da7bb-70cc-481e-9bdb-34dfcf6fd687n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19390&group=comp.lang.forth#19390

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:6214:23cb:b0:472:f1a5:5cea with SMTP id hr11-20020a05621423cb00b00472f1a55ceamr15035155qvb.13.1658849150192;
Tue, 26 Jul 2022 08:25:50 -0700 (PDT)
X-Received: by 2002:ad4:5de4:0:b0:474:2384:a0e9 with SMTP id
jn4-20020ad45de4000000b004742384a0e9mr15538071qvb.79.1658849149949; Tue, 26
Jul 2022 08:25:49 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Tue, 26 Jul 2022 08:25:49 -0700 (PDT)
In-Reply-To: <841c7510-fe31-44d3-b88c-e113c11a9ac6n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.181.84.223; posting-account=qjKo8woAAADX2G4lnOrWMOI0EutZnVRt
NNTP-Posting-Host: 77.181.84.223
References: <aff8f55b-e72e-4cc5-a99d-45b91e55874cn@googlegroups.com>
<nnd$46402dd4$2c7462db@f752040070f4ac81> <841c7510-fe31-44d3-b88c-e113c11a9ac6n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f84da7bb-70cc-481e-9bdb-34dfcf6fd687n@googlegroups.com>
Subject: Re: GForth on Raspi OS Using PThreads - stick-to-core
From: chwebe...@gmail.com (Christof Eberspaecher)
Injection-Date: Tue, 26 Jul 2022 15:25:50 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 6900
 by: Christof Eberspaeche - Tue, 26 Jul 2022 15:25 UTC

Christof Eberspaecher schrieb am Dienstag, 26. Juli 2022 um 12:13:49 UTC+2:
> none albert schrieb am Montag, 25. Juli 2022 um 11:05:32 UTC+2:
> > In article <aff8f55b-e72e-4cc5...@googlegroups.com>,
> > Christof Eberspaecher <chwe...@gmail.com> wrote:
> > >Hi,
> > >background: The goal is to control a small lathe with a Raspberry Pi
> > >using GForth 0-7-9. The axis are moved by step motors. The idea is to
> > >use a maximum step frequency, that always allows to stop within one full
> > >step. So if there is a time lag, steps should not be lost. Linear motion
> > >is done by a separate pthread.
> > >
> > >I have reserved core 3 using isolcpus=3. I can start GForth with all
> > >it's tasks on core 3 with "taskset". But this is not what I want to do,
> > >as only the stepper-thread shall use this CPU for best performance. So I
> > >try to use " 3 stick-to-core" but it does not seem to work. Is this
> > >tested on a raspi?
> > I had some bad experience with isolating CPU's. I have an 8 bit core AMD
> > and I tried to isolate a CPU for midi bitbanging (midi is a asynchronous
> > serial signal of 31.25 kHz). This works as far as the software is concerned
> > with 320 us for 10 bits, e.g. generating a 16 us high 16 us low signal,
> > up till the 50 ns resolution of the logical analyser.
> > You have to do other things, such as manipulating the boot up.
> > I run mprime on the background, and mprime run as if there 8 cores
> > available, trying to interfere with my midi. So it tried to
> > run an 8the mprime on the "isolated" core. Of course I killed mprime,
> > but this is a cludge.
> > Furthermore, in inspecting a 32 us square wave, it was obvious that
> > there are numerous interruptions with different time intervals.
> > midi is robust that it doesn't care to miss-present an event from time
> > to time, but there was no way I get a scale out of this.
> >
> > I managed to control mechanical instruments up till mS precision
> > or better (in Forth) , the isolcpu/taskset is no good for what
> > we have in mind.
> > It is interesting to see whether actual examples exists for isolcpu
> > that accomplishes something useful. Then start from there.
> > >Thanks for some hints!
> > >Christof
> > Groetjes Albert
> > --
> > "in our communism country Viet Nam, people are forced to be
> > alive and in the western country like US, people are free to
> > die from Covid 19 lol" duc ha
> > albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
> Hi Albert,
> Perhaps some findings about latency with isolated core are interesting. This s ferquency distribution of latencies. "56" means, that a delay, which should be 100microsecs was actually 156microseconds.
> 44 0
> 50 0
> 56 22184148
> 63 2200279
> 70 72041
> 79 98707
> 89 13951
> 100 4009
> 112 1472
> 125 186
> 141 69
> 158 21
> 177 2
> 199 1
> 223 0
> 251 0
> Maximum latency of this measurement was 214 microseconds.
> Raspi4b @1.8GHz with one isolated core, which was exclusively used to run the testthread. To use GForth-fast has no significant effect.
> So, yes, 32kbaud midi serial, which needs resultion better than 16us would clearly not be possible.
> If I think, that a resolution of 250us should be possible then a step frequency of 2000Hz will be possible.
>
> The motor winding inductance is relatively high with 7mH and my motor driver has only 24V. For full torque the motor is rated for 1.4A R=3.1Ohm.
> So 20V/1.4A= 14Ohms inductive resistance. 14/(2*pi*0.007)= 100Hz full step frequency for max torque. I do not have the data of the motor to calculate counter-emf. So all-in-all 2000Hz seems not to be the show stopper.
>
> It is also interesting, that in this environment of linux, using GForth seems not to be the speed limiting factor for this application. :-)
> Christof

And one additional finding:
If a very dumb delay routine is used, which does not involve the task sceduler:

def usIdDelay ( us -- )
s>d utime d+
begin
2dup utime d-
d0<= until
2drop
;

Then latency is reduced to <=110us and most times latency is <10µs.

1. 3105238
1.12201845430196 2246084
1.25892541179417 0
1.41253754462275 0
1.58489319246111 0
1.77827941003892 0
1.99526231496888 285790
2.23872113856834 0
2.51188643150958 0
2.81838293126445 10043
3.16227766016838 0
3.54813389233576 0
3.98107170553497 8904
4.46683592150963 1572
5.01187233627272 0
5.62341325190349 998
6.30957344480193 662
7.07945784384138 0
7.94328234724282 493
8.91250938133745 382
10. 576
11.2201845430196 273
12.5892541179417 453
14.1253754462275 174
15.8489319246111 321
17.7827941003892 294
19.9526231496888 330
22.3872113856834 255
25.1188643150958 212
28.1838293126445 138
31.6227766016838 187
35.4813389233575 121
39.8107170553497 80
44.6683592150963 57
50.1187233627272 32
56.2341325190349 17
63.0957344480193 10
70.7945784384138 10
79.4328234724281 6
89.1250938133745 4
100. 5
112.201845430196 0

So the pthreads sceduler seems to be responsible for about 55us latency.
(Downside: you can't kill the thread anymore from outside.....)

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor