Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The moon may be smaller than Earth, but it's further away.


devel / comp.arch / Re: Safepoints

SubjectAuthor
* Safepointsantispam
+* Re: SafepointsMitchAlsup
|`* Re: Safepointsantispam
| `* Re: SafepointsBranimir Maksimovic
|  +* Re: SafepointsBranimir Maksimovic
|  |`- Re: SafepointsBranimir Maksimovic
|  `* Re: Safepointsantispam
|   `- Re: SafepointsBranimir Maksimovic
+* Re: SafepointsIvan Godard
|+* Re: Safepointsantispam
||`- Re: SafepointsBranimir Maksimovic
|`* Re: SafepointsBranimir Maksimovic
| +* Re: Safepointsantispam
| |`* Re: SafepointsBranimir Maksimovic
| | `* Re: SafepointsBranimir Maksimovic
| |  `* Re: Safepointsantispam
| |   `- Re: SafepointsBranimir Maksimovic
| `- Re: SafepointsMitchAlsup
+* Re: SafepointsBranimir Maksimovic
|`* Re: Safepointsantispam
| `- Re: SafepointsBranimir Maksimovic
+* Re: SafepointsThomas Koenig
|`- Re: SafepointsBranimir Maksimovic
+* Re: SafepointsDavid Brown
|+* Re: SafepointsBranimir Maksimovic
||+- Re: SafepointsBranimir Maksimovic
||+* Re: SafepointsAndy Valencia
|||`- Re: SafepointsBranimir Maksimovic
||`- Re: SafepointsDavid Brown
|+* Re: SafepointsStephen Fuld
||+* Re: SafepointsMitchAlsup
|||+- Re: SafepointsStephen Fuld
|||`* Re: SafepointsDavid Brown
||| +- Re: Safepointsrobf...@gmail.com
||| `* Re: SafepointsBranimir Maksimovic
|||  `* Re: SafepointsDavid Brown
|||   `* Re: SafepointsEricP
|||    +- Re: SafepointsDavid Brown
|||    `- Re: SafepointsEricP
||`* Re: SafepointsDavid Brown
|| +* Re: SafepointsStephen Fuld
|| |`* Re: SafepointsEricP
|| | `* Re: SafepointsStephen Fuld
|| |  +* Re: SafepointsDavid Brown
|| |  |`* Re: SafepointsEricP
|| |  | `* Re: SafepointsDavid Brown
|| |  |  `* Re: SafepointsEricP
|| |  |   `* Re: SafepointsDavid Brown
|| |  |    +* Re: SafepointsStephen Fuld
|| |  |    |`- Re: SafepointsDavid Brown
|| |  |    `* Re: SafepointsEricP
|| |  |     +- Re: SafepointsMitchAlsup
|| |  |     +- Re: SafepointsDavid Brown
|| |  |     `* Re: SafepointsPaul A. Clayton
|| |  |      +* Re: SafepointsMitchAlsup
|| |  |      |+* Re: SafepointsTerje Mathisen
|| |  |      ||`- Re: SafepointsMitchAlsup
|| |  |      |`* Re: SafepointsPaul A. Clayton
|| |  |      | `* Re: SafepointsMitchAlsup
|| |  |      |  +* Re: SafepointsEricP
|| |  |      |  |`* Re: SafepointsMitchAlsup
|| |  |      |  | `* Re: SafepointsEricP
|| |  |      |  |  `* Re: SafepointsMitchAlsup
|| |  |      |  |   `* Re: SafepointsEricP
|| |  |      |  |    `- Re: SafepointsMitchAlsup
|| |  |      |  `* Re: SafepointsPaul A. Clayton
|| |  |      |   `- Re: SafepointsMitchAlsup
|| |  |      `* Re: SafepointsEricP
|| |  |       `* Re: SafepointsChris M. Thomasson
|| |  |        `* Re: SafepointsEricP
|| |  |         `* Re: SafepointsChris M. Thomasson
|| |  |          +- Re: SafepointsMitchAlsup
|| |  |          `* Re: SafepointsEricP
|| |  |           `* Re: SafepointsChris M. Thomasson
|| |  |            `- Re: SafepointsChris M. Thomasson
|| |  `* Re: SafepointsEricP
|| |   `* Re: SafepointsDavid Brown
|| |    `* Re: SafepointsEricP
|| |     `* Re: SafepointsDavid Brown
|| |      `* Re: SafepointsEricP
|| |       +- Re: SafepointsMitchAlsup
|| |       `- Re: SafepointsDavid Brown
|| `- Re: SafepointsMitchAlsup
|`- Re: everything old is new again, SafepointsJohn Levine
`* Re: Safepointsaph
 `* Re: SafepointsBranimir Maksimovic
  +* Re: Safepointsantispam
  |`* Re: Safepointsaph
  | `* Re: Safepointsantispam
  |  `* Re: Safepointsaph
  |   +- Re: SafepointsBranimir Maksimovic
  |   `- Re: Safepointsantispam
  `* Re: Safepointsaph
   `* Re: SafepointsBranimir Maksimovic
    `* Re: Safepointsantispam
     `* Re: SafepointsBranimir Maksimovic
      +* Re: SafepointsBranimir Maksimovic
      |`- Re: SafepointsBranimir Maksimovic
      `* Re: Safepointsantispam
       `- Re: SafepointsBranimir Maksimovic

Pages:1234
Re: Safepoints

<162773914498.12156.17471372770330745234@media.vsta.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19410&group=comp.arch#19410

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: van...@vsta.org (Andy Valencia)
Newsgroups: comp.arch
Subject: Re: Safepoints
Date: Sat, 31 Jul 2021 06:45:44 -0700
Lines: 12
Message-ID: <162773914498.12156.17471372770330745234@media.vsta.org>
References: <OX9NI.48204$UR4.47953@fx37.iad> <se1s18$sf$1@z-news.wcss.wroc.pl> <se36el$en5$1@dont-email.me> <3a9NI.51400$Yv3.14029@fx41.iad>
X-Trace: individual.net rCsIl00Kse3XbeM7yAbAggKFl7gM3fDeL/Y8JLH00wAnXRZ5ES
X-Orig-Path: media
Cancel-Lock: sha1:/MmzuxnY8ClhqC2qNfQEehHYjmQ=
User-Agent: rn.py v0.0.1
 by: Andy Valencia - Sat, 31 Jul 2021 13:45 UTC

Branimir Maksimovic <branimir.maksimovic@gmail.com> writes:
> Problem is that signal handler is equivalent of interrupt service routine.
> It can be interupted by same interrupt/signal and called again.

sigaction lets you establish a mask in the signal handler; by default the
signal which caused the entry is blocked as well. This is much like
interrupt entry on pretty much every CPU I've used; you enter with interrupts
disabled, thus by default no reentry.

Andy Valencia
Home page: https://www.vsta.org/andy/
To contact me: https://www.vsta.org/contact/andy.html

Re: Safepoints

<B_dNI.23682$rl3.11713@fx26.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19412&group=comp.arch#19412

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx26.iad.POSTED!not-for-mail
Newsgroups: comp.arch
From: branimir...@gmail.com (Branimir Maksimovic)
Subject: Re: Safepoints
References: <OX9NI.48204$UR4.47953@fx37.iad>
<se1s18$sf$1@z-news.wcss.wroc.pl> <se36el$en5$1@dont-email.me>
<3a9NI.51400$Yv3.14029@fx41.iad>
<162773914498.12156.17471372770330745234@media.vsta.org>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 18
Message-ID: <B_dNI.23682$rl3.11713@fx26.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sat, 31 Jul 2021 15:28:33 UTC
Organization: usenet-news.net
Date: Sat, 31 Jul 2021 15:28:33 GMT
X-Received-Bytes: 1441
 by: Branimir Maksimovic - Sat, 31 Jul 2021 15:28 UTC

On 2021-07-31, Andy Valencia <vandys@vsta.org> wrote:
> Branimir Maksimovic <branimir.maksimovic@gmail.com> writes:
>> Problem is that signal handler is equivalent of interrupt service routine.
>> It can be interupted by same interrupt/signal and called again.
>
> sigaction lets you establish a mask in the signal handler; by default the
> signal which caused the entry is blocked as well. This is much like
> interrupt entry on pretty much every CPU I've used; you enter with interrupts
> disabled, thus by default no reentry.
>
> Andy Valencia
> Home page: https://www.vsta.org/andy/
> To contact me: https://www.vsta.org/contact/andy.html
Honestly, I didn't know that :P
Thanks!

--
bmaxa now listens Ob-Neob Radio

Re: Safepoints

<se3qce$qcq$1@z-news.wcss.wroc.pl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19413&group=comp.arch#19413

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!feeder1.feed.usenet.farm!feed.usenet.farm!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!newsfeed.pionier.net.pl!pwr.wroc.pl!news.wcss.wroc.pl!not-for-mail
From: antis...@math.uni.wroc.pl
Newsgroups: comp.arch
Subject: Re: Safepoints
Date: Sat, 31 Jul 2021 15:31:26 +0000 (UTC)
Organization: Politechnika Wroclawska
Lines: 103
Message-ID: <se3qce$qcq$1@z-news.wcss.wroc.pl>
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <se22ph$ojf$1@dont-email.me> <O31NI.28057$7H7.8371@fx42.iad> <se3frm$itv$3@z-news.wcss.wroc.pl> <pybNI.11312$wG6.4141@fx18.iad> <JBbNI.11313$wG6.7904@fx18.iad>
NNTP-Posting-Host: hera.math.uni.wroc.pl
X-Trace: z-news.wcss.wroc.pl 1627745486 27034 156.17.86.1 (31 Jul 2021 15:31:26 GMT)
X-Complaints-To: abuse@news.pwr.wroc.pl
NNTP-Posting-Date: Sat, 31 Jul 2021 15:31:26 +0000 (UTC)
Cancel-Lock: sha1:PZLijbbntvbxeQHZbbX0LSSjN60=
User-Agent: tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-10-amd64 (x86_64))
X-Received-Bytes: 6802
 by: antis...@math.uni.wroc.pl - Sat, 31 Jul 2021 15:31 UTC

Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> On 2021-07-31, Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> > On 2021-07-31, antispam@math.uni.wroc.pl <antispam@math.uni.wroc.pl> wrote:
> >> Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> >>> On 2021-07-30, Ivan Godard <ivan@millcomputing.com> wrote:
> >>> > On 7/30/2021 2:47 PM, antispam@math.uni.wroc.pl wrote:
> >>> >> This is more question of implementating high-level languages,
> >>> >> but possible answers depend on computer architecture.
> >>> >>
> >>> >> Problem: We want to code in high-level language and we want
> >>> >> to respond to asynchronous events. Simplest example may
> >>> >> by timeout (response to timer interrupt). Or we may wish
> >>> >> to change what the program is doing in response to external
> >>> >> event. At hardware level there are interrupt, at operating
> >>> >> system level we may get signals, so no problem at low level.
> >>> >> However, high-level language may have data structures with
> >>> >> non-trivial invariants. If we abort modification in the
> >>> >> middle data structures may be left in inconsistent state.
> >>> >> So, what is needed is transfer of control to handler at
> >>> >> next safepoint, that is at next place where program may be
> >>> >> safely interrupted. I assume that high-level language
> >>> >> compiler knows where safepoints are, so the only problem
> >>> >> is how to perform control transfer from safepoint to
> >>> >> handler. This is essentially what (in)famous "came from"
> >>> >> instruction is doing, but I am not aware of any real
> >>> >> hardware implementing "came from"...
> >>> >>
> >>> >> Possible solutions:
> >>> >>
> >>> >> 1) Set a flag in signal handler and check for the flag at
> >>> >> each safepoint. Low-level variant od this would keep
> >>> >> interrupts disabled most of the time and enable them
> >>> >> only at safepoints. This is problematic, because
> >>> >> checking inside tight loop may lead to significant
> >>> >> performance drop. Not checking inside loop may
> >>> >> lead to long delay before reaction to external signal.
> >>> >> Inserting checking code by hand could work, but is
> >>> >> error-prone and labor-intensive, so I want automatic
> >>> >> solution, that is compiler generated checks.
> >>> >> 2) Using debug registers: debug register causes transfer
> >>> >> to handler after arriving at designated address. This
> >>> >> is quite close to what "came from" should do and would
> >>> >> be a satisfactory solution. Unfortunately, debug
> >>> >> registers are not standard part of architecture and
> >>> >> access to debug registers may be restricted by operating
> >>> >> system.
> >>> >> 3) Separate cleanup routines: each instruction would have
> >>> >> associated cleanup routine which will continue computations
> >>> >> up to safepoint, but then transfer control to handler.
> >>> >> This may be quite satisfactory from performance point
> >>> >> of view, but require quite a lot of code.
> >>> >> 4) Modyfing code to replace instruction at safepoint
> >>> >> by jump. This has usual disadvantages of self-modyfying
> >>> >> code, but otherwise looks reasonable.
> >>> >> 5) Dynamicaly generating cleanup code: we could copy code
> >>> >> from current instruction pointer up to setpoint and add
> >>> >> jump to handler at the end. Assuming that code is position
> >>> >> independent this should work and is resonably simple. We
> >>> >> avoid modification of "normal code", but it is not clear
> >>> >> for me if modern CPU-s like it better than 4.
> >>> >> 6) Interpret machine instructions up to safepoint. Shuld work,
> >>> >> but is lot of code and potentialy slow.
> >>> >> 7) Modification of 3 and 6: generate cleanups as bytecode and
> >>> >> interpret it. IIUC this is essentially what DWARF is doing
> >>> >> to handle C++ exceptions. My impression is that this is
> >>> >> complicated to implement, requires a lot of code space and
> >>> >> is slow a runtime. OTOH less complicated than 6, probably
> >>> >> runs faster than 6 and needs less code space than 3.
> >>> >>
> >>> >> I wonder if there is other possible implementation that I
> >>> >> overlooked? And advantages/disadvantages that I overlooked?
> >>> >>
> >>> >
> >>> > Simplest to implement would be to throw a C++ exception in the signal
> >>> > handler and catch at the safepoint (catches are always safepoints in
> >>> > C++). That lets C++ do the dwarfing instead of you.
> >>> In signal handler you can't call printf let alone throw C++ exception :P
> >>
> >> Well, from 'g++' help:
> >>
> >> -fasynchronous-unwind-tables Generate unwind tables that are exact at each
> >> instruction boundary.
> >>
> >> What is intended use of this option?
> >>
> > intended use is that throwing exception from ordinary code will not
> > break if async signal happens. But, if you throw from signal handler
> > it will certainly break.
> >
> >
> Besides, throwing from C callback is no no, as Linux is written in C.

There is good chance that 'raise' inside signal handler would
fail. However, AFAIK C++ runtime is already converting
synchronous signals (like SIGSEGV) into exceptions. With
asynchronous unwind tables the same could be done for all signals.
So the plumbing is all there, if you connect right things
you can have _effect_ of throwing exceptions from signal
handler. I do not go in this direction because for me C++
it has other disadvantages.

--
Waldek Hebisch

Re: Safepoints

<YreNI.97765$sI4.88067@fx40.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19415&group=comp.arch#19415

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx40.iad.POSTED!not-for-mail
Newsgroups: comp.arch
From: branimir...@gmail.com (Branimir Maksimovic)
Subject: Re: Safepoints
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <se22ph$ojf$1@dont-email.me>
<O31NI.28057$7H7.8371@fx42.iad> <se3frm$itv$3@z-news.wcss.wroc.pl>
<pybNI.11312$wG6.4141@fx18.iad> <JBbNI.11313$wG6.7904@fx18.iad>
<se3qce$qcq$1@z-news.wcss.wroc.pl>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 111
Message-ID: <YreNI.97765$sI4.88067@fx40.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sat, 31 Jul 2021 15:59:52 UTC
Organization: usenet-news.net
Date: Sat, 31 Jul 2021 15:59:52 GMT
X-Received-Bytes: 7144
 by: Branimir Maksimovic - Sat, 31 Jul 2021 15:59 UTC

On 2021-07-31, antispam@math.uni.wroc.pl <antispam@math.uni.wroc.pl> wrote:
> Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
>> On 2021-07-31, Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
>> > On 2021-07-31, antispam@math.uni.wroc.pl <antispam@math.uni.wroc.pl> wrote:
>> >> Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
>> >>> On 2021-07-30, Ivan Godard <ivan@millcomputing.com> wrote:
>> >>> > On 7/30/2021 2:47 PM, antispam@math.uni.wroc.pl wrote:
>> >>> >> This is more question of implementating high-level languages,
>> >>> >> but possible answers depend on computer architecture.
>> >>> >>
>> >>> >> Problem: We want to code in high-level language and we want
>> >>> >> to respond to asynchronous events. Simplest example may
>> >>> >> by timeout (response to timer interrupt). Or we may wish
>> >>> >> to change what the program is doing in response to external
>> >>> >> event. At hardware level there are interrupt, at operating
>> >>> >> system level we may get signals, so no problem at low level.
>> >>> >> However, high-level language may have data structures with
>> >>> >> non-trivial invariants. If we abort modification in the
>> >>> >> middle data structures may be left in inconsistent state.
>> >>> >> So, what is needed is transfer of control to handler at
>> >>> >> next safepoint, that is at next place where program may be
>> >>> >> safely interrupted. I assume that high-level language
>> >>> >> compiler knows where safepoints are, so the only problem
>> >>> >> is how to perform control transfer from safepoint to
>> >>> >> handler. This is essentially what (in)famous "came from"
>> >>> >> instruction is doing, but I am not aware of any real
>> >>> >> hardware implementing "came from"...
>> >>> >>
>> >>> >> Possible solutions:
>> >>> >>
>> >>> >> 1) Set a flag in signal handler and check for the flag at
>> >>> >> each safepoint. Low-level variant od this would keep
>> >>> >> interrupts disabled most of the time and enable them
>> >>> >> only at safepoints. This is problematic, because
>> >>> >> checking inside tight loop may lead to significant
>> >>> >> performance drop. Not checking inside loop may
>> >>> >> lead to long delay before reaction to external signal.
>> >>> >> Inserting checking code by hand could work, but is
>> >>> >> error-prone and labor-intensive, so I want automatic
>> >>> >> solution, that is compiler generated checks.
>> >>> >> 2) Using debug registers: debug register causes transfer
>> >>> >> to handler after arriving at designated address. This
>> >>> >> is quite close to what "came from" should do and would
>> >>> >> be a satisfactory solution. Unfortunately, debug
>> >>> >> registers are not standard part of architecture and
>> >>> >> access to debug registers may be restricted by operating
>> >>> >> system.
>> >>> >> 3) Separate cleanup routines: each instruction would have
>> >>> >> associated cleanup routine which will continue computations
>> >>> >> up to safepoint, but then transfer control to handler.
>> >>> >> This may be quite satisfactory from performance point
>> >>> >> of view, but require quite a lot of code.
>> >>> >> 4) Modyfing code to replace instruction at safepoint
>> >>> >> by jump. This has usual disadvantages of self-modyfying
>> >>> >> code, but otherwise looks reasonable.
>> >>> >> 5) Dynamicaly generating cleanup code: we could copy code
>> >>> >> from current instruction pointer up to setpoint and add
>> >>> >> jump to handler at the end. Assuming that code is position
>> >>> >> independent this should work and is resonably simple. We
>> >>> >> avoid modification of "normal code", but it is not clear
>> >>> >> for me if modern CPU-s like it better than 4.
>> >>> >> 6) Interpret machine instructions up to safepoint. Shuld work,
>> >>> >> but is lot of code and potentialy slow.
>> >>> >> 7) Modification of 3 and 6: generate cleanups as bytecode and
>> >>> >> interpret it. IIUC this is essentially what DWARF is doing
>> >>> >> to handle C++ exceptions. My impression is that this is
>> >>> >> complicated to implement, requires a lot of code space and
>> >>> >> is slow a runtime. OTOH less complicated than 6, probably
>> >>> >> runs faster than 6 and needs less code space than 3.
>> >>> >>
>> >>> >> I wonder if there is other possible implementation that I
>> >>> >> overlooked? And advantages/disadvantages that I overlooked?
>> >>> >>
>> >>> >
>> >>> > Simplest to implement would be to throw a C++ exception in the signal
>> >>> > handler and catch at the safepoint (catches are always safepoints in
>> >>> > C++). That lets C++ do the dwarfing instead of you.
>> >>> In signal handler you can't call printf let alone throw C++ exception :P
>> >>
>> >> Well, from 'g++' help:
>> >>
>> >> -fasynchronous-unwind-tables Generate unwind tables that are exact at each
>> >> instruction boundary.
>> >>
>> >> What is intended use of this option?
>> >>
>> > intended use is that throwing exception from ordinary code will not
>> > break if async signal happens. But, if you throw from signal handler
>> > it will certainly break.
>> >
>> >
>> Besides, throwing from C callback is no no, as Linux is written in C.
>
> There is good chance that 'raise' inside signal handler would
> fail. However, AFAIK C++ runtime is already converting
> synchronous signals (like SIGSEGV) into exceptions. With
> asynchronous unwind tables the same could be done for all signals.
> So the plumbing is all there, if you connect right things
> you can have _effect_ of throwing exceptions from signal
> handler. I do not go in this direction because for me C++
> it has other disadvantages.
>
segfault cases program to be in inconsistent state. Kernel interrupts
program and dumps core usually. C++ exceptions are not implemented
same everywhere. There is space or runtime cost.
These with space(global tables of handlers) cost, can even work throwing from C callbacks :P
But catching signals and converting them to exceptions I never saw before :P
especially that C++ can't possibly know context where signal happened.

--
bmaxa now listens Ob-Neob Radio

Re: Safepoints

<1905339d-67be-4527-8f90-5719343b6c4fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19418&group=comp.arch#19418

  copy link   Newsgroups: comp.arch
X-Received: by 2002:a05:620a:1327:: with SMTP id p7mr7727336qkj.483.1627750197213; Sat, 31 Jul 2021 09:49:57 -0700 (PDT)
X-Received: by 2002:a05:6808:10d5:: with SMTP id s21mr5568504ois.7.1627750196969; Sat, 31 Jul 2021 09:49:56 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!tr3.eu1.usenetexpress.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Sat, 31 Jul 2021 09:49:56 -0700 (PDT)
In-Reply-To: <O31NI.28057$7H7.8371@fx42.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:288a:67f4:917d:3e7a; posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:288a:67f4:917d:3e7a
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <se22ph$ojf$1@dont-email.me> <O31NI.28057$7H7.8371@fx42.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1905339d-67be-4527-8f90-5719343b6c4fn@googlegroups.com>
Subject: Re: Safepoints
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Sat, 31 Jul 2021 16:49:57 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 14
 by: MitchAlsup - Sat, 31 Jul 2021 16:49 UTC

On Friday, July 30, 2021 at 7:46:41 PM UTC-5, Branimir Maksimovic wrote:
> On 2021-07-30, Ivan Godard <iv...@millcomputing.com> wrote:
> > On 7/30/2021 2:47 PM, anti...@math.uni.wroc.pl wrote:
> >> This is more question of implementating high-level languages,
> >> but possible answers depend on computer architecture.

> > Simplest to implement would be to throw a C++ exception in the signal
> > handler and catch at the safepoint (catches are always safepoints in
> > C++). That lets C++ do the dwarfing instead of you.
<
> In signal handler you can't call printf let alone throw C++ exception :P
<
But you can put said signal in a list and have non-handler code throw it.
> --
> bmaxa now listens Yammat FM

Re: Safepoints

<se4aae$qma$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19429&group=comp.arch#19429

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: sfu...@alumni.cmu.edu.invalid (Stephen Fuld)
Newsgroups: comp.arch
Subject: Re: Safepoints
Date: Sat, 31 Jul 2021 13:03:25 -0700
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <se4aae$qma$1@dont-email.me>
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <se36el$en5$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 31 Jul 2021 20:03:26 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ce907f427114b4735e9d2695fbd44a5a";
logging-data="27338"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18HO6bzm2oJeYfSZEaREmB9NX5w57WZq0g="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.12.0
Cancel-Lock: sha1:ETF5Q12R1sA68fCeeclHf3c913w=
In-Reply-To: <se36el$en5$1@dont-email.me>
Content-Language: en-US
 by: Stephen Fuld - Sat, 31 Jul 2021 20:03 UTC

On 7/31/2021 2:51 AM, David Brown wrote:

snip

> I've always thought a "disable interrupts for the next N instructions",
> with "N" being a small immediate constant, would be an extremely useful
> instruction on the kind of devices I use (single cpu microcontrollers).
> This instruction should work regardless of the current interrupt enable
> status, making it significantly more efficient than the usual store old
> status, disable interrupts, restore old status dance. It could also be
> allowable from user mode safely, unlike normal interrupt disable, since
> it is only temporary. And then you would have an easy and safe way to
> make short multi-instruction atomic sections, in a way that could be
> used by any language.
>
> That would not completely solve your complex invariant problem here, but
> it could be used to have atomic logs/trackers of the state of the
> object, allowing the program to identify and recover from inconsistent
> states.

I agree on its usefulness for your kind of application - those where you
control all the software. However on a general purpose system, I can
see lots of potential problems, mostly involving denial of service attacks.

--
- Stephen Fuld
(e-mail address disguised to prevent spam)

Re: Safepoints

<f1240d75-82d6-468e-bf51-c4e275e38a4an@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19430&group=comp.arch#19430

  copy link   Newsgroups: comp.arch
X-Received: by 2002:ac8:7207:: with SMTP id a7mr8000100qtp.32.1627765128604;
Sat, 31 Jul 2021 13:58:48 -0700 (PDT)
X-Received: by 2002:aca:3144:: with SMTP id x65mr5992952oix.157.1627765128374;
Sat, 31 Jul 2021 13:58:48 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.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.arch
Date: Sat, 31 Jul 2021 13:58:48 -0700 (PDT)
In-Reply-To: <se4aae$qma$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:288a:67f4:917d:3e7a;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:288a:67f4:917d:3e7a
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <se36el$en5$1@dont-email.me> <se4aae$qma$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f1240d75-82d6-468e-bf51-c4e275e38a4an@googlegroups.com>
Subject: Re: Safepoints
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Sat, 31 Jul 2021 20:58:48 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3664
 by: MitchAlsup - Sat, 31 Jul 2021 20:58 UTC

On Saturday, July 31, 2021 at 3:03:28 PM UTC-5, Stephen Fuld wrote:
> On 7/31/2021 2:51 AM, David Brown wrote:
>
> snip
> > I've always thought a "disable interrupts for the next N instructions",
> > with "N" being a small immediate constant, would be an extremely useful
> > instruction on the kind of devices I use (single cpu microcontrollers).
<
I can see utility here, but you need not only N as the number of instructions,
but also P the priority level below which you suppress interrupts and above
which you still allow interrupts.
<
In the realm of real CPUs (not microcontrollers) P is variable and the task/
thread might not know what privilege level is appropriate. In a hypervisor/
supervisor system, you might not be allowed to even know what level is
appropriate.
<
> > This instruction should work regardless of the current interrupt enable
> > status, making it significantly more efficient than the usual store old
> > status, disable interrupts, restore old status dance. It could also be
> > allowable from user mode safely, unlike normal interrupt disable, since
> > it is only temporary. And then you would have an easy and safe way to
> > make short multi-instruction atomic sections, in a way that could be
> > used by any language.
<
ASF (the AMD version of my ATOMIC stuff) had defined a watchdog
timeout that also suppressed interrupts for a short duration to enhance
the performance of ATOMICs without degrading interrupt responsiveness.
> >
> > That would not completely solve your complex invariant problem here, but
> > it could be used to have atomic logs/trackers of the state of the
> > object, allowing the program to identify and recover from inconsistent
> > states.
<
> I agree on its usefulness for your kind of application - those where you
> control all the software. However on a general purpose system, I can
> see lots of potential problems, mostly involving denial of service attacks.
>
The problem I see is that OP is desirous of something that smells ATOMIC
(his invariants) that are in no way surrounded by anything even remotely
smelling like an ATOMIC. Don't get me wrong, I think this brings up an
important point we may have missed in that:: in the presence of certain
invariants, one cannot prove a program to be in compliance at all points
between instructions, only at certain points where the invariants are known
to hold.
>
>
> --
> - Stephen Fuld
> (e-mail address disguised to prevent spam)

Re: Safepoints

<se4dlb$hda$2@z-news.wcss.wroc.pl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19431&group=comp.arch#19431

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!newsfeed.pionier.net.pl!pwr.wroc.pl!news.wcss.wroc.pl!not-for-mail
From: antis...@math.uni.wroc.pl
Newsgroups: comp.arch
Subject: Re: Safepoints
Date: Sat, 31 Jul 2021 21:00:27 +0000 (UTC)
Organization: Politechnika Wroclawska
Lines: 53
Message-ID: <se4dlb$hda$2@z-news.wcss.wroc.pl>
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com> <GvaNI.128355$h8.72917@fx47.iad>
NNTP-Posting-Host: hera.math.uni.wroc.pl
X-Trace: z-news.wcss.wroc.pl 1627765227 17834 156.17.86.1 (31 Jul 2021 21:00:27 GMT)
X-Complaints-To: abuse@news.pwr.wroc.pl
NNTP-Posting-Date: Sat, 31 Jul 2021 21:00:27 +0000 (UTC)
Cancel-Lock: sha1:sT/SunMfIH1enLG5dMqNuCpkLgY=
User-Agent: tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-10-amd64 (x86_64))
 by: antis...@math.uni.wroc.pl - Sat, 31 Jul 2021 21:00 UTC

Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> On 2021-07-31, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
> > antispam@math.uni.wroc.pl wrote:
> >> This is more question of implementating high-level languages,
> >> but possible answers depend on computer architecture.
> >>
> >> Problem: We want to code in high-level language and we want
> >> to respond to asynchronous events. Simplest example may
> >> by timeout (response to timer interrupt). Or we may wish
> >> to change what the program is doing in response to external
> >> event. At hardware level there are interrupt, at operating
> >> system level we may get signals, so no problem at low level.
> >> However, high-level language may have data structures with
> >> non-trivial invariants. If we abort modification in the
> >> middle data structures may be left in inconsistent state.
> >> So, what is needed is transfer of control to handler at
> >> next safepoint, that is at next place where program may be
> >> safely interrupted. I assume that high-level language
> >> compiler knows where safepoints are, so the only problem
> >> is how to perform control transfer from safepoint to
> >> handler. This is essentially what (in)famous "came from"
> >> instruction is doing, but I am not aware of any real
> >> hardware implementing "came from"...
> >>
> > ...
> >> I wonder if there is other possible implementation that I
> >> overlooked? And advantages/disadvantages that I overlooked?
> >
> > Insert a load from a fixed address (thread specific, if you like) at
> > your safepoint. When you want to stop some thread, disable read
> > permissions for that address, and let the thread take a trap. In
> > practice the overhead in the common case is negligible because the
> > load is speculated and its value is never used.
> >
> > There is some overhead (on the order of a microsecond) though, from
> > the trip through the kernel when the trap actually happens, but it's
> > usually rare enough that this overhead doesn't matter. It would be
> > nice to have user-space fault handlers to make this overhead go away.
> >
> > Andrew.

I am not seeing orginal post by Andrew, so I am replying here.

This is interesting trick. On x86 it reduces overhead of common case
to single instruction. However, on ARM (at least version 5) it
seems that I need two instructions to pefrom load from constant
address: one instruction to load address to register (using PC
relative mode) and second for the load itself.

I admit that my hope is for zero runtime overhead in common case.

--
Waldek Hebisch

Re: Safepoints

<se5dlc$35m$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19440&group=comp.arch#19440

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: sfu...@alumni.cmu.edu.invalid (Stephen Fuld)
Newsgroups: comp.arch
Subject: Re: Safepoints
Date: Sat, 31 Jul 2021 23:06:34 -0700
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <se5dlc$35m$1@dont-email.me>
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <se36el$en5$1@dont-email.me>
<se4aae$qma$1@dont-email.me>
<f1240d75-82d6-468e-bf51-c4e275e38a4an@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 1 Aug 2021 06:06:36 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9e3fff4d148443ce4c255fb954165b4f";
logging-data="3254"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ew9XEB/ALvaG9scx+0WONjYqto6UioBc="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.12.0
Cancel-Lock: sha1:sdPhPPJ0y13IVH7c5Q/Jb+XtZME=
In-Reply-To: <f1240d75-82d6-468e-bf51-c4e275e38a4an@googlegroups.com>
Content-Language: en-US
 by: Stephen Fuld - Sun, 1 Aug 2021 06:06 UTC

On 7/31/2021 1:58 PM, MitchAlsup wrote:
> On Saturday, July 31, 2021 at 3:03:28 PM UTC-5, Stephen Fuld wrote:
>> On 7/31/2021 2:51 AM, David Brown wrote:
>>
>> snip
>>> I've always thought a "disable interrupts for the next N instructions",
>>> with "N" being a small immediate constant, would be an extremely useful
>>> instruction on the kind of devices I use (single cpu microcontrollers).
> <
> I can see utility here, but you need not only N as the number of instructions,
> but also P the priority level below which you suppress interrupts and above
> which you still allow interrupts.
> <
> In the realm of real CPUs (not microcontrollers) P is variable and the task/
> thread might not know what privilege level is appropriate. In a hypervisor/
> supervisor system, you might not be allowed to even know what level is
> appropriate.

It isn't clear, at least to me, in a hypervisor system, whether
interrupts should be "locked out" for just the OS, or for other OSs
running under the hypervisor, or for the hypervisor itself.

>>> This instruction should work regardless of the current interrupt enable
>>> status, making it significantly more efficient than the usual store old
>>> status, disable interrupts, restore old status dance. It could also be
>>> allowable from user mode safely, unlike normal interrupt disable, since
>>> it is only temporary. And then you would have an easy and safe way to
>>> make short multi-instruction atomic sections, in a way that could be
>>> used by any language.

But simply locking out interrupts on the executing CPU doesn't force
atomic semantics on memory for multicore or multi processor systems.

> <
> ASF (the AMD version of my ATOMIC stuff) had defined a watchdog
> timeout that also suppressed interrupts for a short duration to enhance
> the performance of ATOMICs without degrading interrupt responsiveness.
>>>
>>> That would not completely solve your complex invariant problem here, but
>>> it could be used to have atomic logs/trackers of the state of the
>>> object, allowing the program to identify and recover from inconsistent
>>> states.
> <
>> I agree on its usefulness for your kind of application - those where you
>> control all the software. However on a general purpose system, I can
>> see lots of potential problems, mostly involving denial of service attacks.
>>
> The problem I see is that OP is desirous of something that smells ATOMIC
> (his invariants) that are in no way surrounded by anything even remotely
> smelling like an ATOMIC. Don't get me wrong, I think this brings up an
> important point we may have missed in that:: in the presence of certain
> invariants, one cannot prove a program to be in compliance at all points
> between instructions, only at certain points where the invariants are known
> to hold.
>>
>>
>> --
>> - Stephen Fuld
>> (e-mail address disguised to prevent spam)

--
- Stephen Fuld
(e-mail address disguised to prevent spam)

Re: Safepoints

<wtudneJXeqYA4Jv8nZ2dnUU7-bWdnZ2d@supernews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19444&group=comp.arch#19444

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!tr3.eu1.usenetexpress.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!buffer1.nntp.dca1.giganews.com!buffer2.nntp.dca1.giganews.com!nntp.supernews.com!news.supernews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 01 Aug 2021 05:55:25 -0500
Sender: Andrew Haley <aph@zarquon.pink>
From: aph...@littlepinkcloud.invalid
Subject: Re: Safepoints
Newsgroups: comp.arch
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com> <GvaNI.128355$h8.72917@fx47.iad>
User-Agent: tin/1.9.2-20070201 ("Dalaruan") (UNIX) (Linux/4.18.0-240.8.1.el8_3.x86_64 (x86_64))
Message-ID: <wtudneJXeqYA4Jv8nZ2dnUU7-bWdnZ2d@supernews.com>
Date: Sun, 01 Aug 2021 05:55:25 -0500
Lines: 21
X-Trace: sv3-ErEY72LDKr6cFEkj5S/h5xokxYw65Jfrx81oNOeuXqFWNWqh5D8H6LXEz0vy6HOxLo0GHHUNjqcvuCS!pnZQua1PDSrOMGFII1TeTAyFEzyMvtrVnhAnN+DVZXoMjdmRnix2EKhiWB4yJSZm8InO75yIfksO!Mu7VmjHC
X-Complaints-To: www.supernews.com/docs/abuse.html
X-DMCA-Complaints-To: www.supernews.com/docs/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2105
 by: aph...@littlepinkcloud.invalid - Sun, 1 Aug 2021 10:55 UTC

Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> On 2021-07-31, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
>>
>> Insert a load from a fixed address (thread specific, if you like) at
>> your safepoint. When you want to stop some thread, disable read
>> permissions for that address, and let the thread take a trap. In
>> practice the overhead in the common case is negligible because the
>> load is speculated and its value is never used.
>>
>> There is some overhead (on the order of a microsecond) though, from
>> the trip through the kernel when the trap actually happens, but it's
>> usually rare enough that this overhead doesn't matter. It would be
>> nice to have user-space fault handlers to make this overhead go away.
>>
> Isn't it simpler just to start another thread which will wait on events? :P

Um, what? The point is to interrupt a thread, in order to do stuff
like tracing its stack to do GC. You really have to stop the active
stack to do htat.

Andrew.

Re: Safepoints

<htednUoLx-xS4pv8nZ2dnUU7-WHNnZ2d@supernews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19446&group=comp.arch#19446

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!tr3.eu1.usenetexpress.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!buffer1.nntp.dca1.giganews.com!nntp.supernews.com!news.supernews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 01 Aug 2021 06:04:47 -0500
Sender: Andrew Haley <aph@zarquon.pink>
From: aph...@littlepinkcloud.invalid
Subject: Re: Safepoints
Newsgroups: comp.arch
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com> <GvaNI.128355$h8.72917@fx47.iad> <se4dlb$hda$2@z-news.wcss.wroc.pl>
User-Agent: tin/1.9.2-20070201 ("Dalaruan") (UNIX) (Linux/4.18.0-240.8.1.el8_3.x86_64 (x86_64))
Message-ID: <htednUoLx-xS4pv8nZ2dnUU7-WHNnZ2d@supernews.com>
Date: Sun, 01 Aug 2021 06:04:47 -0500
Lines: 37
X-Trace: sv3-enjPXSBxRZ2yIDNTj1Gk6pLoZJHi02HHSIc//NUSNiihHhv3kJUvj+X0tDW0cMjqYxBfNhglwLkDOCQ!LZGNfYbOAfh26qoa+CqSAAvE5but9MWOrcokdqBIdyBt1PsABv7LPbVaqpgPF4VnpAf0TaeejY7V!uqTYXv3s
X-Complaints-To: www.supernews.com/docs/abuse.html
X-DMCA-Complaints-To: www.supernews.com/docs/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2943
 by: aph...@littlepinkcloud.invalid - Sun, 1 Aug 2021 11:04 UTC

antispam@math.uni.wroc.pl wrote:
> Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
>> > ...
>> >> I wonder if there is other possible implementation that I
>> >> overlooked? And advantages/disadvantages that I overlooked?
>> >
>> > Insert a load from a fixed address (thread specific, if you like) at
>> > your safepoint. When you want to stop some thread, disable read
>> > permissions for that address, and let the thread take a trap. In
>> > practice the overhead in the common case is negligible because the
>> > load is speculated and its value is never used.
>> >
>> > There is some overhead (on the order of a microsecond) though, from
>> > the trip through the kernel when the trap actually happens, but it's
>> > usually rare enough that this overhead doesn't matter. It would be
>> > nice to have user-space fault handlers to make this overhead go away.
>
> I am not seeing orginal post by Andrew, so I am replying here.
>
> This is interesting trick. On x86 it reduces overhead of common case
> to single instruction. However, on ARM (at least version 5) it
> seems that I need two instructions to pefrom load from constant
> address: one instruction to load address to register (using PC
> relative mode) and second for the load itself.

It depends on whether you're looking to stop individual threads or all
of them. For individual threads, if you have a thread pointer in a
register you can put a page just before the thread and make the poll a
load with a negative offset. But the cost of a single immediate move
to set up the polling page address isn't very important.

> I admit that my hope is for zero runtime overhead in common case.

The greatest cost of the safepoint is setting everything up so that it
really is safe; a load doesn't add much.

Andrew.

Re: Safepoints

<AhxNI.99232$Vv6.46864@fx45.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19449&group=comp.arch#19449

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx45.iad.POSTED!not-for-mail
Newsgroups: comp.arch
From: branimir...@gmail.com (Branimir Maksimovic)
Subject: Re: Safepoints
References: <se1s18$sf$1@z-news.wcss.wroc.pl>
<7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com>
<GvaNI.128355$h8.72917@fx47.iad>
<wtudneJXeqYA4Jv8nZ2dnUU7-bWdnZ2d@supernews.com>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 27
Message-ID: <AhxNI.99232$Vv6.46864@fx45.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sun, 01 Aug 2021 13:25:52 UTC
Organization: usenet-news.net
Date: Sun, 01 Aug 2021 13:25:52 GMT
X-Received-Bytes: 1975
 by: Branimir Maksimovic - Sun, 1 Aug 2021 13:25 UTC

On 2021-08-01, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
> Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
>> On 2021-07-31, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
>>>
>>> Insert a load from a fixed address (thread specific, if you like) at
>>> your safepoint. When you want to stop some thread, disable read
>>> permissions for that address, and let the thread take a trap. In
>>> practice the overhead in the common case is negligible because the
>>> load is speculated and its value is never used.
>>>
>>> There is some overhead (on the order of a microsecond) though, from
>>> the trip through the kernel when the trap actually happens, but it's
>>> usually rare enough that this overhead doesn't matter. It would be
>>> nice to have user-space fault handlers to make this overhead go away.
>>>
>> Isn't it simpler just to start another thread which will wait on events? :P
>
> Um, what? The point is to interrupt a thread, in order to do stuff
> like tracing its stack to do GC. You really have to stop the active
> stack to do htat.
>
> Andrew.
I think that he mentioned handling async events, while GC is already done,
which already have "stop the world implemented"....

--
bmaxa now listens rts_4

Re: Safepoints

<se67u4$d9h$1@z-news.wcss.wroc.pl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19450&group=comp.arch#19450

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!newsfeed.pionier.net.pl!pwr.wroc.pl!news.wcss.wroc.pl!not-for-mail
From: antis...@math.uni.wroc.pl
Newsgroups: comp.arch
Subject: Re: Safepoints
Date: Sun, 1 Aug 2021 13:35:00 +0000 (UTC)
Organization: Politechnika Wroclawska
Lines: 86
Message-ID: <se67u4$d9h$1@z-news.wcss.wroc.pl>
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com> <GvaNI.128355$h8.72917@fx47.iad> <se4dlb$hda$2@z-news.wcss.wroc.pl> <htednUoLx-xS4pv8nZ2dnUU7-WHNnZ2d@supernews.com>
NNTP-Posting-Host: hera.math.uni.wroc.pl
X-Trace: z-news.wcss.wroc.pl 1627824900 13617 156.17.86.1 (1 Aug 2021 13:35:00 GMT)
X-Complaints-To: abuse@news.pwr.wroc.pl
NNTP-Posting-Date: Sun, 1 Aug 2021 13:35:00 +0000 (UTC)
Cancel-Lock: sha1:JejvNKAXC9CfE59sUVFxZwlEk7o=
User-Agent: tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-10-amd64 (x86_64))
X-Received-Bytes: 4761
 by: antis...@math.uni.wroc.pl - Sun, 1 Aug 2021 13:35 UTC

aph@littlepinkcloud.invalid wrote:
> antispam@math.uni.wroc.pl wrote:
> > Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> >> > ...
> >> >> I wonder if there is other possible implementation that I
> >> >> overlooked? And advantages/disadvantages that I overlooked?
> >> >
> >> > Insert a load from a fixed address (thread specific, if you like) at
> >> > your safepoint. When you want to stop some thread, disable read
> >> > permissions for that address, and let the thread take a trap. In
> >> > practice the overhead in the common case is negligible because the
> >> > load is speculated and its value is never used.
> >> >
> >> > There is some overhead (on the order of a microsecond) though, from
> >> > the trip through the kernel when the trap actually happens, but it's
> >> > usually rare enough that this overhead doesn't matter. It would be
> >> > nice to have user-space fault handlers to make this overhead go away.
> >
> > I am not seeing orginal post by Andrew, so I am replying here.
> >
> > This is interesting trick. On x86 it reduces overhead of common case
> > to single instruction. However, on ARM (at least version 5) it
> > seems that I need two instructions to pefrom load from constant
> > address: one instruction to load address to register (using PC
> > relative mode) and second for the load itself.
>
> It depends on whether you're looking to stop individual threads or all
> of them. For individual threads, if you have a thread pointer in a
> register you can put a page just before the thread and make the poll a
> load with a negative offset. But the cost of a single immediate move
> to set up the polling page address isn't very important.
>
> > I admit that my hope is for zero runtime overhead in common case.
>
> The greatest cost of the safepoint is setting everything up so that it
> really is safe; a load doesn't add much.

Let me give an example. Today a loop generates the following
code (I skipped surrounding part, entry is via _L1):

_L2:
cmpq $0, i__031trap
jne _L5
cmpq %rbx, i__031userlim
jbe _L6
_L5:
call c__031checkall
_L6:
movq %r14, -8(%rbx)
movq 8(%rsp), %rsi
addq %rsi, %rsi
addq %r15, %rsi
movq -14(%rsi), %rax
subq $3, %rax
movq -8(%rbx), %r9
addq %rax, %r9
movq %r9, %r14
addq $4, %r15
_L1:
cmpq %r15, %r13
jge _L2

This is not great code, computational part can be improved
by standard compiler techniques. Comparison with
i__031userlim can be removed and equivalent check done
by setting a guard page. i__031trap is set to nonzero value
by signal handler. Already with this code checking for
for i__031trap adds notrivial overhead. And there is
also space overhead: compiler inserts checks at targets
of all backward branches (otherwise a loop could interate
for minutes without anybody looking for signals).

Several places in the loop are "unsafe", they use temporary
registers in way not understood by garbage collector.
Place at _L2 is safe. Indeally, after signal I would like
execution to continue to _L2, then low level signal handler
could simply transfer control to high-level handler
(currently high-level handler is called via c__031checkall).
To put is differently, I would like to get rid of code
between _L2 and _L6. Collapsing this to single instruction
would be an improvement. However, having _no_ extra
instructions would be better, and alternative methods
that I outlined in original post should allow this.

--
Waldek Hebisch

Re: Safepoints

<se691i$d9h$2@z-news.wcss.wroc.pl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19452&group=comp.arch#19452

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!newsfeed.pionier.net.pl!pwr.wroc.pl!news.wcss.wroc.pl!not-for-mail
From: antis...@math.uni.wroc.pl
Newsgroups: comp.arch
Subject: Re: Safepoints
Date: Sun, 1 Aug 2021 13:53:54 +0000 (UTC)
Organization: Politechnika Wroclawska
Lines: 41
Message-ID: <se691i$d9h$2@z-news.wcss.wroc.pl>
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com> <GvaNI.128355$h8.72917@fx47.iad> <wtudneJXeqYA4Jv8nZ2dnUU7-bWdnZ2d@supernews.com> <AhxNI.99232$Vv6.46864@fx45.iad>
NNTP-Posting-Host: hera.math.uni.wroc.pl
X-Trace: z-news.wcss.wroc.pl 1627826034 13617 156.17.86.1 (1 Aug 2021 13:53:54 GMT)
X-Complaints-To: abuse@news.pwr.wroc.pl
NNTP-Posting-Date: Sun, 1 Aug 2021 13:53:54 +0000 (UTC)
Cancel-Lock: sha1:oOPBb7JrFB16dFIsCB17WKPoOCA=
User-Agent: tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-10-amd64 (x86_64))
X-Received-Bytes: 3130
 by: antis...@math.uni.wroc.pl - Sun, 1 Aug 2021 13:53 UTC

Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> On 2021-08-01, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
> > Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> >> On 2021-07-31, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
> >>>
> >>> Insert a load from a fixed address (thread specific, if you like) at
> >>> your safepoint. When you want to stop some thread, disable read
> >>> permissions for that address, and let the thread take a trap. In
> >>> practice the overhead in the common case is negligible because the
> >>> load is speculated and its value is never used.
> >>>
> >>> There is some overhead (on the order of a microsecond) though, from
> >>> the trip through the kernel when the trap actually happens, but it's
> >>> usually rare enough that this overhead doesn't matter. It would be
> >>> nice to have user-space fault handlers to make this overhead go away.
> >>>
> >> Isn't it simpler just to start another thread which will wait on events? :P
> >
> > Um, what? The point is to interrupt a thread, in order to do stuff
> > like tracing its stack to do GC. You really have to stop the active
> > stack to do htat.
> >
> > Andrew.
> I think that he mentioned handling async events, while GC is already done,
> which already have "stop the world implemented"....

Sorry for possible confusion. Currently there is single thread,
so to "stop" other things is easy: garbage collector is simply
not looking at flag set by low-level signal handler. To
have multiple threads I would have to implement stopping other
threads, which is possible using flags in shared memory and
checking for flags in other threads. But I would like to
save cost of flag checking, while shared memory would make
cheking much more expensive than it is now.

To put this differently: before going to multiple theads I
need efficient way to comunicate with asynchronous thread.
And implementing such efficient comunication is the whole
point of this (discussion) thread.
--
Waldek Hebisch

Re: Safepoints

<9VxNI.79740$dp5.47340@fx48.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19453&group=comp.arch#19453

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx48.iad.POSTED!not-for-mail
Newsgroups: comp.arch
From: branimir...@gmail.com (Branimir Maksimovic)
Subject: Re: Safepoints
References: <se1s18$sf$1@z-news.wcss.wroc.pl>
<7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com>
<GvaNI.128355$h8.72917@fx47.iad>
<wtudneJXeqYA4Jv8nZ2dnUU7-bWdnZ2d@supernews.com>
<AhxNI.99232$Vv6.46864@fx45.iad> <se691i$d9h$2@z-news.wcss.wroc.pl>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 71
Message-ID: <9VxNI.79740$dp5.47340@fx48.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sun, 01 Aug 2021 14:08:05 UTC
Organization: usenet-news.net
Date: Sun, 01 Aug 2021 14:08:05 GMT
X-Received-Bytes: 3836
 by: Branimir Maksimovic - Sun, 1 Aug 2021 14:08 UTC

On 2021-08-01, antispam@math.uni.wroc.pl <antispam@math.uni.wroc.pl> wrote:
> Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
>> On 2021-08-01, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
>> > Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
>> >> On 2021-07-31, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
>> >>>
>> >>> Insert a load from a fixed address (thread specific, if you like) at
>> >>> your safepoint. When you want to stop some thread, disable read
>> >>> permissions for that address, and let the thread take a trap. In
>> >>> practice the overhead in the common case is negligible because the
>> >>> load is speculated and its value is never used.
>> >>>
>> >>> There is some overhead (on the order of a microsecond) though, from
>> >>> the trip through the kernel when the trap actually happens, but it's
>> >>> usually rare enough that this overhead doesn't matter. It would be
>> >>> nice to have user-space fault handlers to make this overhead go away.
>> >>>
>> >> Isn't it simpler just to start another thread which will wait on events? :P
>> >
>> > Um, what? The point is to interrupt a thread, in order to do stuff
>> > like tracing its stack to do GC. You really have to stop the active
>> > stack to do htat.
>> >
>> > Andrew.
>> I think that he mentioned handling async events, while GC is already done,
>> which already have "stop the world implemented"....
>
> Sorry for possible confusion. Currently there is single thread,
> so to "stop" other things is easy: garbage collector is simply
> not looking at flag set by low-level signal handler. To
> have multiple threads I would have to implement stopping other
> threads, which is possible using flags in shared memory and
> checking for flags in other threads. But I would like to
> save cost of flag checking, while shared memory would make
> cheking much more expensive than it is now.
>
> To put this differently: before going to multiple theads I
> need efficient way to comunicate with asynchronous thread.
> And implementing such efficient comunication is the whole
> point of this (discussion) thread.
This is from Hans's Boehm implementation:
to stop thread:
result = pthread_kill(p -> id, SIG_SUSPEND);
switch(result) {
case ESRCH:
/* Not really there anymore. Possible? */
n_live_threads--;
break;
case 0:
break;
default:
ABORT("pthread_kill failed");
}

to restart thread:
result = pthread_kill(p -> id, SIG_SUSPEND);
switch(result) {
case ESRCH:
/* Not really there anymore. Possible? */
n_live_threads--;
break;
case 0:
break;
default:
ABORT("pthread_kill failed");
}

--
bmaxa now listens rts_4

Re: Safepoints

<XYxNI.99238$Vv6.50887@fx45.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19454&group=comp.arch#19454

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!feeder.usenetexpress.com!tr1.eu1.usenetexpress.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!feeder1.feed.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx45.iad.POSTED!not-for-mail
Newsgroups: comp.arch
From: branimir...@gmail.com (Branimir Maksimovic)
Subject: Re: Safepoints
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com> <GvaNI.128355$h8.72917@fx47.iad> <wtudneJXeqYA4Jv8nZ2dnUU7-bWdnZ2d@supernews.com> <AhxNI.99232$Vv6.46864@fx45.iad> <se691i$d9h$2@z-news.wcss.wroc.pl> <9VxNI.79740$dp5.47340@fx48.iad>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 86
Message-ID: <XYxNI.99238$Vv6.50887@fx45.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sun, 01 Aug 2021 14:12:07 UTC
Organization: usenet-news.net
Date: Sun, 01 Aug 2021 14:12:07 GMT
X-Received-Bytes: 4430
 by: Branimir Maksimovic - Sun, 1 Aug 2021 14:12 UTC

On 2021-08-01, Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> On 2021-08-01, antispam@math.uni.wroc.pl <antispam@math.uni.wroc.pl> wrote:
>> Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
>>> On 2021-08-01, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
>>> > Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
>>> >> On 2021-07-31, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
>>> >>>
>>> >>> Insert a load from a fixed address (thread specific, if you like) at
>>> >>> your safepoint. When you want to stop some thread, disable read
>>> >>> permissions for that address, and let the thread take a trap. In
>>> >>> practice the overhead in the common case is negligible because the
>>> >>> load is speculated and its value is never used.
>>> >>>
>>> >>> There is some overhead (on the order of a microsecond) though, from
>>> >>> the trip through the kernel when the trap actually happens, but it's
>>> >>> usually rare enough that this overhead doesn't matter. It would be
>>> >>> nice to have user-space fault handlers to make this overhead go away.
>>> >>>
>>> >> Isn't it simpler just to start another thread which will wait on events? :P
>>> >
>>> > Um, what? The point is to interrupt a thread, in order to do stuff
>>> > like tracing its stack to do GC. You really have to stop the active
>>> > stack to do htat.
>>> >
>>> > Andrew.
>>> I think that he mentioned handling async events, while GC is already done,
>>> which already have "stop the world implemented"....
>>
>> Sorry for possible confusion. Currently there is single thread,
>> so to "stop" other things is easy: garbage collector is simply
>> not looking at flag set by low-level signal handler. To
>> have multiple threads I would have to implement stopping other
>> threads, which is possible using flags in shared memory and
>> checking for flags in other threads. But I would like to
>> save cost of flag checking, while shared memory would make
>> cheking much more expensive than it is now.
>>
>> To put this differently: before going to multiple theads I
>> need efficient way to comunicate with asynchronous thread.
>> And implementing such efficient comunication is the whole
>> point of this (discussion) thread.
> This is from Hans's Boehm implementation:
> to stop thread:
> result = pthread_kill(p -> id, SIG_SUSPEND);
> switch(result) {
> case ESRCH:
> /* Not really there anymore. Possible? */
> n_live_threads--;
> break;
> case 0:
> break;
> default:
> ABORT("pthread_kill failed");
> }
>
> to restart thread:
> result = pthread_kill(p -> id, SIG_SUSPEND);
> switch(result) {
> case ESRCH:
> /* Not really there anymore. Possible? */
> n_live_threads--;
> break;
> case 0:
> break;
> default:
> ABORT("pthread_kill failed");
> }
>
>
>

--
bmaxa nult = pthread_kill(p -> id, SIG_THR_RESTART);
switch(result) {
case ESRCH:
/* Not really there anymore. Possible? */
n_live_threads--;
break;
case 0:
break;
default:
ABORT("pthread_kill failed");
}
}
w listens rts_4

Re: Safepoints

<i5yNI.99241$Vv6.29010@fx45.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19455&group=comp.arch#19455

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx45.iad.POSTED!not-for-mail
Newsgroups: comp.arch
From: branimir...@gmail.com (Branimir Maksimovic)
Subject: Re: Safepoints
References: <se1s18$sf$1@z-news.wcss.wroc.pl>
<7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com>
<GvaNI.128355$h8.72917@fx47.iad>
<wtudneJXeqYA4Jv8nZ2dnUU7-bWdnZ2d@supernews.com>
<AhxNI.99232$Vv6.46864@fx45.iad> <se691i$d9h$2@z-news.wcss.wroc.pl>
<9VxNI.79740$dp5.47340@fx48.iad> <XYxNI.99238$Vv6.50887@fx45.iad>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 122
Message-ID: <i5yNI.99241$Vv6.29010@fx45.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sun, 01 Aug 2021 14:21:02 UTC
Organization: usenet-news.net
Date: Sun, 01 Aug 2021 14:21:02 GMT
X-Received-Bytes: 5803
 by: Branimir Maksimovic - Sun, 1 Aug 2021 14:21 UTC

On 2021-08-01, Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> On 2021-08-01, Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
>> On 2021-08-01, antispam@math.uni.wroc.pl <antispam@math.uni.wroc.pl> wrote:
>>> Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
>>>> On 2021-08-01, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
>>>> > Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
>>>> >> On 2021-07-31, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
>>>> >>>
>>>> >>> Insert a load from a fixed address (thread specific, if you like) at
>>>> >>> your safepoint. When you want to stop some thread, disable read
>>>> >>> permissions for that address, and let the thread take a trap. In
>>>> >>> practice the overhead in the common case is negligible because the
>>>> >>> load is speculated and its value is never used.
>>>> >>>
>>>> >>> There is some overhead (on the order of a microsecond) though, from
>>>> >>> the trip through the kernel when the trap actually happens, but it's
>>>> >>> usually rare enough that this overhead doesn't matter. It would be
>>>> >>> nice to have user-space fault handlers to make this overhead go away.
>>>> >>>
>>>> >> Isn't it simpler just to start another thread which will wait on events? :P
>>>> >
>>>> > Um, what? The point is to interrupt a thread, in order to do stuff
>>>> > like tracing its stack to do GC. You really have to stop the active
>>>> > stack to do htat.
>>>> >
>>>> > Andrew.
>>>> I think that he mentioned handling async events, while GC is already done,
>>>> which already have "stop the world implemented"....
>>>
>>> Sorry for possible confusion. Currently there is single thread,
>>> so to "stop" other things is easy: garbage collector is simply
>>> not looking at flag set by low-level signal handler. To
>>> have multiple threads I would have to implement stopping other
>>> threads, which is possible using flags in shared memory and
>>> checking for flags in other threads. But I would like to
>>> save cost of flag checking, while shared memory would make
>>> cheking much more expensive than it is now.
>>>
>>> To put this differently: before going to multiple theads I
>>> need efficient way to comunicate with asynchronous thread.
>>> And implementing such efficient comunication is the whole
>>> point of this (discussion) thread.
>> This is from Hans's Boehm implementation:
>> to stop thread:
>> result = pthread_kill(p -> id, SIG_SUSPEND);
>> switch(result) {
>> case ESRCH:
>> /* Not really there anymore. Possible? */
>> n_live_threads--;
>> break;
>> case 0:
>> break;
>> default:
>> ABORT("pthread_kill failed");
>> }
>>
>> to restart thread:
>> result = pthread_kill(p -> id, SIG_SUSPEND);
>> switch(result) {
>> case ESRCH:
>> /* Not really there anymore. Possible? */
>> n_live_threads--;
>> break;
>> case 0:
>> break;
>> default:
>> ABORT("pthread_kill failed");
>> }
>>
>>
>>
>
>
void GC_stop_init() {
struct sigaction act;

if (sem_init(&GC_suspend_ack_sem, 0, 0) != 0)
ABORT("sem_init failed");
# ifdef GC_NETBSD_THREADS_WORKAROUND
if (sem_init(&GC_restart_ack_sem, 0, 0) != 0)
ABORT("sem_init failed");
# endif

act.sa_flags = SA_RESTART | SA_SIGINFO;
if (sigfillset(&act.sa_mask) != 0) {
ABORT("sigfillset() failed");
}
GC_remove_allowed_signals(&act.sa_mask);
/* SIG_THR_RESTART is set in the resulting mask. */
/* It is unmasked by the handler when necessary. */
act.sa_sigaction = GC_suspend_handler;
if (sigaction(SIG_SUSPEND, &act, NULL) != 0) {
ABORT("Cannot set SIG_SUSPEND handler");
}

act.sa_flags &= ~ SA_SIGINFO;
act.sa_handler = GC_restart_handler;
if (sigaction(SIG_THR_RESTART, &act, NULL) != 0) {
ABORT("Cannot set SIG_THR_RESTART handler");
}

/* Inititialize suspend_handler_mask. It excludes SIG_THR_RESTART. */
if (sigfillset(&suspend_handler_mask) != 0) ABORT("sigfillset() failed");
GC_remove_allowed_signals(&suspend_handler_mask);
if (sigdelset(&suspend_handler_mask, SIG_THR_RESTART) != 0)
ABORT("sigdelset() failed");

/* Check for GC_RETRY_SIGNALS. */
if (0 != GETENV("GC_RETRY_SIGNALS")) {
GC_retry_signals = TRUE;
}
if (0 != GETENV("GC_NO_RETRY_SIGNALS")) {
GC_retry_signals = FALSE;
}
if (GC_print_stats && GC_retry_signals) {
GC_log_printf("Will retry suspend signal if necessary.\n");
}
}

--
bmaxa now listens rts_4

Re: Safepoints

<se6cn9$gr0$2@z-news.wcss.wroc.pl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19456&group=comp.arch#19456

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!4.us.feeder.erje.net!feeder.erje.net!newsfeed.pionier.net.pl!pwr.wroc.pl!news.wcss.wroc.pl!not-for-mail
From: antis...@math.uni.wroc.pl
Newsgroups: comp.arch
Subject: Re: Safepoints
Date: Sun, 1 Aug 2021 14:56:41 +0000 (UTC)
Organization: Politechnika Wroclawska
Lines: 57
Message-ID: <se6cn9$gr0$2@z-news.wcss.wroc.pl>
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com> <GvaNI.128355$h8.72917@fx47.iad> <wtudneJXeqYA4Jv8nZ2dnUU7-bWdnZ2d@supernews.com> <AhxNI.99232$Vv6.46864@fx45.iad> <se691i$d9h$2@z-news.wcss.wroc.pl> <9VxNI.79740$dp5.47340@fx48.iad>
NNTP-Posting-Host: hera.math.uni.wroc.pl
X-Trace: z-news.wcss.wroc.pl 1627829801 17248 156.17.86.1 (1 Aug 2021 14:56:41 GMT)
X-Complaints-To: abuse@news.pwr.wroc.pl
NNTP-Posting-Date: Sun, 1 Aug 2021 14:56:41 +0000 (UTC)
Cancel-Lock: sha1:i1YITPRq56Vxkjt4MbcPrjjWprc=
User-Agent: tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-10-amd64 (x86_64))
 by: antis...@math.uni.wroc.pl - Sun, 1 Aug 2021 14:56 UTC

Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> On 2021-08-01, antispam@math.uni.wroc.pl <antispam@math.uni.wroc.pl> wrote:
> > Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> >> On 2021-08-01, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
> >> > Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> >> >> On 2021-07-31, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
> >> >>>
> >> >>> Insert a load from a fixed address (thread specific, if you like) at
> >> >>> your safepoint. When you want to stop some thread, disable read
> >> >>> permissions for that address, and let the thread take a trap. In
> >> >>> practice the overhead in the common case is negligible because the
> >> >>> load is speculated and its value is never used.
> >> >>>
> >> >>> There is some overhead (on the order of a microsecond) though, from
> >> >>> the trip through the kernel when the trap actually happens, but it's
> >> >>> usually rare enough that this overhead doesn't matter. It would be
> >> >>> nice to have user-space fault handlers to make this overhead go away.
> >> >>>
> >> >> Isn't it simpler just to start another thread which will wait on events? :P
> >> >
> >> > Um, what? The point is to interrupt a thread, in order to do stuff
> >> > like tracing its stack to do GC. You really have to stop the active
> >> > stack to do htat.
> >> >
> >> > Andrew.
> >> I think that he mentioned handling async events, while GC is already done,
> >> which already have "stop the world implemented"....
> >
> > Sorry for possible confusion. Currently there is single thread,
> > so to "stop" other things is easy: garbage collector is simply
> > not looking at flag set by low-level signal handler. To
> > have multiple threads I would have to implement stopping other
> > threads, which is possible using flags in shared memory and
> > checking for flags in other threads. But I would like to
> > save cost of flag checking, while shared memory would make
> > cheking much more expensive than it is now.
> >
> > To put this differently: before going to multiple theads I
> > need efficient way to comunicate with asynchronous thread.
> > And implementing such efficient comunication is the whole
> > point of this (discussion) thread.
> This is from Hans's Boehm implementation:

Boehm garbage collector is conservative. What he is doing
does not work with precise collector (and much of complexity
that Boehm has is not needed in precise collector).

> to stop thread:
> result = pthread_kill(p -> id, SIG_SUSPEND);

This sends signal. Without handler SIG_SUSPEND it will
stop thread in some random place, must likely wrong one.
I need to continue execution up to next safepoint, which
is _not_ handled by this code.

--
Waldek Hebisch

Re: Safepoints

<_WyNI.51152$qk6.8339@fx36.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19457&group=comp.arch#19457

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx36.iad.POSTED!not-for-mail
Newsgroups: comp.arch
From: branimir...@gmail.com (Branimir Maksimovic)
Subject: Re: Safepoints
References: <se1s18$sf$1@z-news.wcss.wroc.pl>
<7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com>
<GvaNI.128355$h8.72917@fx47.iad>
<wtudneJXeqYA4Jv8nZ2dnUU7-bWdnZ2d@supernews.com>
<AhxNI.99232$Vv6.46864@fx45.iad> <se691i$d9h$2@z-news.wcss.wroc.pl>
<9VxNI.79740$dp5.47340@fx48.iad> <se6cn9$gr0$2@z-news.wcss.wroc.pl>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 60
Message-ID: <_WyNI.51152$qk6.8339@fx36.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sun, 01 Aug 2021 15:18:18 UTC
Organization: usenet-news.net
Date: Sun, 01 Aug 2021 15:18:18 GMT
X-Received-Bytes: 3866
 by: Branimir Maksimovic - Sun, 1 Aug 2021 15:18 UTC

On 2021-08-01, antispam@math.uni.wroc.pl <antispam@math.uni.wroc.pl> wrote:
> Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
>> On 2021-08-01, antispam@math.uni.wroc.pl <antispam@math.uni.wroc.pl> wrote:
>> > Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
>> >> On 2021-08-01, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
>> >> > Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
>> >> >> On 2021-07-31, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
>> >> >>>
>> >> >>> Insert a load from a fixed address (thread specific, if you like) at
>> >> >>> your safepoint. When you want to stop some thread, disable read
>> >> >>> permissions for that address, and let the thread take a trap. In
>> >> >>> practice the overhead in the common case is negligible because the
>> >> >>> load is speculated and its value is never used.
>> >> >>>
>> >> >>> There is some overhead (on the order of a microsecond) though, from
>> >> >>> the trip through the kernel when the trap actually happens, but it's
>> >> >>> usually rare enough that this overhead doesn't matter. It would be
>> >> >>> nice to have user-space fault handlers to make this overhead go away.
>> >> >>>
>> >> >> Isn't it simpler just to start another thread which will wait on events? :P
>> >> >
>> >> > Um, what? The point is to interrupt a thread, in order to do stuff
>> >> > like tracing its stack to do GC. You really have to stop the active
>> >> > stack to do htat.
>> >> >
>> >> > Andrew.
>> >> I think that he mentioned handling async events, while GC is already done,
>> >> which already have "stop the world implemented"....
>> >
>> > Sorry for possible confusion. Currently there is single thread,
>> > so to "stop" other things is easy: garbage collector is simply
>> > not looking at flag set by low-level signal handler. To
>> > have multiple threads I would have to implement stopping other
>> > threads, which is possible using flags in shared memory and
>> > checking for flags in other threads. But I would like to
>> > save cost of flag checking, while shared memory would make
>> > cheking much more expensive than it is now.
>> >
>> > To put this differently: before going to multiple theads I
>> > need efficient way to comunicate with asynchronous thread.
>> > And implementing such efficient comunication is the whole
>> > point of this (discussion) thread.
>> This is from Hans's Boehm implementation:
>
> Boehm garbage collector is conservative. What he is doing
> does not work with precise collector (and much of complexity
> that Boehm has is not needed in precise collector).
>
>> to stop thread:
>> result = pthread_kill(p -> id, SIG_SUSPEND);
>
> This sends signal. Without handler SIG_SUSPEND it will
> stop thread in some random place, must likely wrong one.
> I need to continue execution up to next safepoint, which
> is _not_ handled by this code.
>
Look following two posts.

--
bmaxa now listens rts_4

Re: Safepoints

<6cGdnbZDq4I6Wpv8nZ2dnUU7-eHNnZ2d@supernews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19460&group=comp.arch#19460

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!tr3.eu1.usenetexpress.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!buffer1.nntp.dca1.giganews.com!buffer2.nntp.dca1.giganews.com!nntp.supernews.com!news.supernews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 01 Aug 2021 11:11:18 -0500
Sender: Andrew Haley <aph@zarquon.pink>
From: aph...@littlepinkcloud.invalid
Subject: Re: Safepoints
Newsgroups: comp.arch
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com> <GvaNI.128355$h8.72917@fx47.iad> <se4dlb$hda$2@z-news.wcss.wroc.pl> <htednUoLx-xS4pv8nZ2dnUU7-WHNnZ2d@supernews.com> <se67u4$d9h$1@z-news.wcss.wroc.pl>
User-Agent: tin/1.9.2-20070201 ("Dalaruan") (UNIX) (Linux/4.18.0-240.8.1.el8_3.x86_64 (x86_64))
Message-ID: <6cGdnbZDq4I6Wpv8nZ2dnUU7-eHNnZ2d@supernews.com>
Date: Sun, 01 Aug 2021 11:11:19 -0500
Lines: 53
X-Trace: sv3-ksm4JGxsQyFO0T9D9NULfbOv7x2i09frtQiekg/YJbWRHZ+8ky9Mb1QzNztUydsUueaALkE+4V1mhE9!P1lMVhNPsHeJtO5BhVxE5XQG3+TK5FNxoXJuJt4tX4+dOTpSqPQb4OzXOl0vlau/JYExymQ0iWsW!dQ7sxXmZ
X-Complaints-To: www.supernews.com/docs/abuse.html
X-DMCA-Complaints-To: www.supernews.com/docs/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 3382
 by: aph...@littlepinkcloud.invalid - Sun, 1 Aug 2021 16:11 UTC

antispam@math.uni.wroc.pl wrote:

> Several places in the loop are "unsafe", they use temporary
> registers in way not understood by garbage collector. Place at _L2
> is safe. Indeally, after signal I would like execution to continue
> to _L2, then low level signal handler could simply transfer control
> to high-level handler (currently high-level handler is called via
> c__031checkall). To put is differently, I would like to get rid of
> code between _L2 and _L6. Collapsing this to single instruction
> would be an improvement. However, having _no_ extra instructions
> would be better, and alternative methods that I outlined in original
> post should allow this.

I wonder which ones you have in mind? Here's my take:

1) Checking a flag at a safepoint is expensive.

2) Debug registers might work, but there are a limited number of
those, and potentially thousands of safepoints. I guess you could
interrupt the thread, look at its PC, then find its nearby safepoint
by disassembling, but it looks complex.

But that won't work if you want to stop a single thread.

3) The cleanup routines looks quite entertaining, but costly in other
ways.

4) Modifying code doesn't help, because how many loops are in a
program? You'd have to modify them all. I guess you could interrupt
the program, disassemble it to find the next nearby safepoint, patch
that and restart, but eww. But again, that won't work if you want to
stop a single thread.

Instead, you could stop a thread and single-step it by patching
instructions one at a time until it hits a safepoint. You can do that
by modifying code: you don't need debug registers.

5) Dynamically generating cleanup code from an arbitrary point looks
fun, if rather fiddly.

6) Is definitely do-able, but again rather fiddly.

7) is Hell's own complicated.

In contrast, a load at a safepoint costs very little to nothing (at
least on a Great-Big- out-of-order processor) and it's easy to
implement. But if you do manage to get one of these to work, I'd be
very interested to hear about it.

I think that trying to make the runtime code zero is something of a
mistake

Andrew.

Re: Safepoints

<ecANI.79925$dp5.27012@fx48.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19463&group=comp.arch#19463

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx48.iad.POSTED!not-for-mail
Newsgroups: comp.arch
From: branimir...@gmail.com (Branimir Maksimovic)
Subject: Re: Safepoints
References: <se1s18$sf$1@z-news.wcss.wroc.pl>
<7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com>
<GvaNI.128355$h8.72917@fx47.iad> <se4dlb$hda$2@z-news.wcss.wroc.pl>
<htednUoLx-xS4pv8nZ2dnUU7-WHNnZ2d@supernews.com>
<se67u4$d9h$1@z-news.wcss.wroc.pl>
<6cGdnbZDq4I6Wpv8nZ2dnUU7-eHNnZ2d@supernews.com>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 161
Message-ID: <ecANI.79925$dp5.27012@fx48.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sun, 01 Aug 2021 16:44:58 UTC
Organization: usenet-news.net
Date: Sun, 01 Aug 2021 16:44:58 GMT
X-Received-Bytes: 6920
 by: Branimir Maksimovic - Sun, 1 Aug 2021 16:44 UTC

On 2021-08-01, aph@littlepinkcloud.invalid <aph@littlepinkcloud.invalid> wrote:
> antispam@math.uni.wroc.pl wrote:
>
>> Several places in the loop are "unsafe", they use temporary
>> registers in way not understood by garbage collector. Place at _L2
>> is safe. Indeally, after signal I would like execution to continue
>> to _L2, then low level signal handler could simply transfer control
>> to high-level handler (currently high-level handler is called via
>> c__031checkall). To put is differently, I would like to get rid of
>> code between _L2 and _L6. Collapsing this to single instruction
>> would be an improvement. However, having _no_ extra instructions
>> would be better, and alternative methods that I outlined in original
>> post should allow this.
>
> I wonder which ones you have in mind? Here's my take:
>
> 1) Checking a flag at a safepoint is expensive.
>
> 2) Debug registers might work, but there are a limited number of
> those, and potentially thousands of safepoints. I guess you could
> interrupt the thread, look at its PC, then find its nearby safepoint
> by disassembling, but it looks complex.
>
> But that won't work if you want to stop a single thread.
>
> 3) The cleanup routines looks quite entertaining, but costly in other
> ways.
>
> 4) Modifying code doesn't help, because how many loops are in a
> program? You'd have to modify them all. I guess you could interrupt
> the program, disassemble it to find the next nearby safepoint, patch
> that and restart, but eww. But again, that won't work if you want to
> stop a single thread.
>
> Instead, you could stop a thread and single-step it by patching
> instructions one at a time until it hits a safepoint. You can do that
> by modifying code: you don't need debug registers.
>
> 5) Dynamically generating cleanup code from an arbitrary point looks
> fun, if rather fiddly.
>
> 6) Is definitely do-able, but again rather fiddly.
>
> 7) is Hell's own complicated.
>
> In contrast, a load at a safepoint costs very little to nothing (at
> least on a Great-Big- out-of-order processor) and it's easy to
> implement. But if you do manage to get one of these to work, I'd be
> very interested to hear about it.
>
> I think that trying to make the runtime code zero is something of a
> mistake
>
> Andrew.
_suspend_handler(int sig, siginfo_t *info, void *context)
{ int old_errno = errno;
GC_suspend_handler_inner((ptr_t)(word)sig, context);
errno = old_errno;
} #endif

void GC_suspend_handler_inner(ptr_t sig_arg, void *context)
{ int sig = (int)(word)sig_arg;
int dummy;
pthread_t my_thread = pthread_self();
GC_thread me;
# ifdef PARALLEL_MARK
word my_mark_no = GC_mark_no;
/* Marker can't proceed until we acknowledge. Thus this is */
/* guaranteed to be the mark_no correspending to our */
/* suspension, i.e. the marker can't have incremented it yet. */
# endif
AO_t my_stop_count = AO_load(&GC_stop_count);

if (sig != SIG_SUSPEND) ABORT("Bad signal in suspend_handler");

# if DEBUG_THREADS
GC_printf("Suspending 0x%x\n", (unsigned)my_thread);
# endif

me = GC_lookup_thread(my_thread);
/* The lookup here is safe, since I'm doing this on behalf */
/* of a thread which holds the allocation lock in order */
/* to stop the world. Thus concurrent modification of the */
/* data structure is impossible. */
if (me -> stop_info.last_stop_count == my_stop_count) {
/* Duplicate signal. OK if we are retrying. */
if (!GC_retry_signals) {
WARN("Duplicate suspend signal in thread %lx\n",
pthread_self());
}
return;
}
# ifdef SPARC
me -> stop_info.stack_ptr = GC_save_regs_in_stack();
# else
me -> stop_info.stack_ptr = (ptr_t)(&dummy);
# endif
# ifdef IA64
me -> backing_store_ptr = GC_save_regs_in_stack();
# endif

/* Tell the thread that wants to stop the world that this */
/* thread has been stopped. Note that sem_post() is */
/* the only async-signal-safe primitive in LinuxThreads. */
sem_post(&GC_suspend_ack_sem);
me -> stop_info.last_stop_count = my_stop_count;

/* Wait until that thread tells us to restart by sending */
/* this thread a SIG_THR_RESTART signal. */
/* SIG_THR_RESTART should be masked at this point. Thus there */
/* is no race. */
/* We do not continue until we receive a SIG_THR_RESTART, */
/* but we do not take that as authoritative. (We may be */
/* accidentally restarted by one of the user signals we */
/* don't block.) After we receive the signal, we use a */
/* primitive and expensive mechanism to wait until it's */
/* really safe to proceed. Under normal circumstances, */
/* this code should not be executed. */
do {
sigsuspend (&suspend_handler_mask);
} while (AO_load_acquire(&GC_world_is_stopped)
&& AO_load(&GC_stop_count) == my_stop_count);
/* If the RESTART signal gets lost, we can still lose. That should be */
/* less likely than losing the SUSPEND signal, since we don't do much */
/* between the sem_post and sigsuspend. */
/* We'd need more handshaking to work around that. */
/* Simply dropping the sigsuspend call should be safe, but is unlikely */
/* to be efficient. */

# if DEBUG_THREADS
GC_printf("Continuing 0x%x\n", (unsigned)my_thread);
# endif
}

void GC_restart_handler(int sig)
{ pthread_t my_thread = pthread_self();
GC_thread me;

if (sig != SIG_THR_RESTART) ABORT("Bad signal in suspend_handler");

# ifdef GC_NETBSD_THREADS_WORKAROUND
sem_post(&GC_restart_ack_sem);
# endif

/*
** Note: even if we don't do anything useful here,
** it would still be necessary to have a signal handler,
** rather than ignoring the signals, otherwise
** the signals will not be delivered at all, and
** will thus not interrupt the sigsuspend() above.
*/

# if DEBUG_THREADS
GC_printf("In GC_restart_handler for 0x%x\n", (unsigned)pthread_self());
# endif
}

Re: Safepoints

<se6pin$t7f$1@z-news.wcss.wroc.pl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19467&group=comp.arch#19467

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!4.us.feeder.erje.net!feeder.erje.net!newsfeed.pionier.net.pl!pwr.wroc.pl!news.wcss.wroc.pl!not-for-mail
From: antis...@math.uni.wroc.pl
Newsgroups: comp.arch
Subject: Re: Safepoints
Date: Sun, 1 Aug 2021 18:36:07 +0000 (UTC)
Organization: Politechnika Wroclawska
Lines: 108
Message-ID: <se6pin$t7f$1@z-news.wcss.wroc.pl>
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com> <GvaNI.128355$h8.72917@fx47.iad> <se4dlb$hda$2@z-news.wcss.wroc.pl> <htednUoLx-xS4pv8nZ2dnUU7-WHNnZ2d@supernews.com> <se67u4$d9h$1@z-news.wcss.wroc.pl> <6cGdnbZDq4I6Wpv8nZ2dnUU7-eHNnZ2d@supernews.com>
NNTP-Posting-Host: hera.math.uni.wroc.pl
X-Trace: z-news.wcss.wroc.pl 1627842967 29935 156.17.86.1 (1 Aug 2021 18:36:07 GMT)
X-Complaints-To: abuse@news.pwr.wroc.pl
NNTP-Posting-Date: Sun, 1 Aug 2021 18:36:07 +0000 (UTC)
Cancel-Lock: sha1:6lH+UvJeuirGWKqW3ss4xWcjt0I=
User-Agent: tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-10-amd64 (x86_64))
 by: antis...@math.uni.wroc.pl - Sun, 1 Aug 2021 18:36 UTC

aph@littlepinkcloud.invalid wrote:
> antispam@math.uni.wroc.pl wrote:
>
> > Several places in the loop are "unsafe", they use temporary
> > registers in way not understood by garbage collector. Place at _L2
> > is safe. Indeally, after signal I would like execution to continue
> > to _L2, then low level signal handler could simply transfer control
> > to high-level handler (currently high-level handler is called via
> > c__031checkall). To put is differently, I would like to get rid of
> > code between _L2 and _L6. Collapsing this to single instruction
> > would be an improvement. However, having _no_ extra instructions
> > would be better, and alternative methods that I outlined in original
> > post should allow this.
>
> I wonder which ones you have in mind? Here's my take:
>
> 1) Checking a flag at a safepoint is expensive.

Yes.
> 2) Debug registers might work, but there are a limited number of
> those, and potentially thousands of safepoints. I guess you could
> interrupt the thread, look at its PC, then find its nearby safepoint
> by disassembling, but it looks complex.

Well, in my case almost all control transfers are safepoints.
So basically I have linear piece of code and at the end there
is desired safepoint. Assuming that I keep table of addresses
of safepoints I can simply take next safepoint after current PC.
This is compiler generated code, and while compiler is not very
inteligent, it knows where safepoints are and can generate
appropriate table. Bottom line is that there is single
safepoint where code should arrive and its address is easy
to find. So single debug registe would do.

> But that won't work if you want to stop a single thread.

ATM I do not know what OS allows me to do with debug registers.
IIUC each core has its own debug registers. I hope that OS
ensures that each thread has its values of debug registers
(but I did not check). Assuming that OS works as I hope
there should be no problem with stopping single thread
without affecting other ones.

> 3) The cleanup routines looks quite entertaining, but costly in other
> ways.

Yes, there is significant space cost. Due to linearity of control
flow to the safepoints I could probably manage to do this in
double of current size (basically one copy doing normal work
and second copy transferring control to handler at safepoint.

> 4) Modifying code doesn't help, because how many loops are in a
> program? You'd have to modify them all.

As I wrote control should go to single safepoint which I can
easily find, so single place to modify.

> I guess you could interrupt
> the program, disassemble it to find the next nearby safepoint, patch
> that and restart, but eww. But again, that won't work if you want to
> stop a single thread.

Yes, self-modyfing code and multiple threads should not happen
together... One could probably stop all other threads (in this
case it does not matter if they are at safepoint or not), modify
code, run single thread, when it arrives at sefepoint restre code
and restart other threads.

> Instead, you could stop a thread and single-step it by patching
> instructions one at a time until it hits a safepoint. You can do that
> by modifying code: you don't need debug registers.

Repeated trips via signal handling machinery do not look very
attractive. In most cases there is only handful of instructions
to next safepoint, but 100 may happen.

> 5) Dynamically generating cleanup code from an arbitrary point looks
> fun, if rather fiddly.

As I wrote, I have linear block of code. And this code is
position-independent, so simple copy should do. Currently
it looks like best solution.
> 6) Is definitely do-able, but again rather fiddly.
>
> 7) is Hell's own complicated.

I would probably reverse order of descriptions, but neither
look very attractive due to amount of work needed for
implementation.

> In contrast, a load at a safepoint costs very little to nothing (at
> least on a Great-Big- out-of-order processor) and it's easy to
> implement.

Yes, much easier than my ideas.

> But if you do manage to get one of these to work, I'd be
> very interested to hear about it.
>
> I think that trying to make the runtime code zero is something of a
> mistake
>
> Andrew.

--
Waldek Hebisch

Re: Safepoints

<sediq4$8of$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19540&group=comp.arch#19540

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.arch
Subject: Re: Safepoints
Date: Wed, 4 Aug 2021 10:23:32 +0200
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <sediq4$8of$1@dont-email.me>
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <se36el$en5$1@dont-email.me>
<3a9NI.51400$Yv3.14029@fx41.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 4 Aug 2021 08:23:32 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5c84e891ee178787f1df57542d7264bc";
logging-data="8975"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/QWjHA0cwlDqBdyOqkXZhqfJdIwok8V7k="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:0AvJe7X7vLzm/pLGp4/d0xZva1s=
In-Reply-To: <3a9NI.51400$Yv3.14029@fx41.iad>
Content-Language: en-GB
 by: David Brown - Wed, 4 Aug 2021 08:23 UTC

On 31/07/2021 11:59, Branimir Maksimovic wrote:
> On 2021-07-31, David Brown <david.brown@hesbynett.no> wrote:

>>
>> I've always thought a "disable interrupts for the next N instructions",
>> with "N" being a small immediate constant, would be an extremely useful
>> instruction on the kind of devices I use (single cpu microcontrollers).
>> This instruction should work regardless of the current interrupt enable
>> status, making it significantly more efficient than the usual store old
>> status, disable interrupts, restore old status dance. It could also be
>> allowable from user mode safely, unlike normal interrupt disable, since
>> it is only temporary. And then you would have an easy and safe way to
>> make short multi-instruction atomic sections, in a way that could be
>> used by any language.
>>
>> That would not completely solve your complex invariant problem here, but
>> it could be used to have atomic logs/trackers of the state of the
>> object, allowing the program to identify and recover from inconsistent
>> states.
>>
> Except that you cannot disable interupts in signal handler, neither
> touch (because of that) any global variable/flag, nor call any
> sideffect function....
>

I don't particularly care about signal handlers - they are not relevant
to the kind of programming I do.

But regardless - the point of such a limited and controlled instruction
is that it /would/ be safe even from signal handlers.

(There are still complications for multiple cores, of course.)

Re: Safepoints

<sedj2d$b0l$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19541&group=comp.arch#19541

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.arch
Subject: Re: Safepoints
Date: Wed, 4 Aug 2021 10:27:56 +0200
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <sedj2d$b0l$1@dont-email.me>
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <se36el$en5$1@dont-email.me>
<se4aae$qma$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 4 Aug 2021 08:27:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5c84e891ee178787f1df57542d7264bc";
logging-data="11285"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19yva/w6odFTkZK2SZ/ZbggftKEqXKkqoA="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:24wiWYs3AQ1LYJyN5KKokDuQ04w=
In-Reply-To: <se4aae$qma$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Wed, 4 Aug 2021 08:27 UTC

On 31/07/2021 22:03, Stephen Fuld wrote:
> On 7/31/2021 2:51 AM, David Brown wrote:
>
> snip
>
>> I've always thought a "disable interrupts for the next N instructions",
>> with "N" being a small immediate constant, would be an extremely useful
>> instruction on the kind of devices I use (single cpu microcontrollers).
>>   This instruction should work regardless of the current interrupt enable
>> status, making it significantly more efficient than the usual store old
>> status, disable interrupts, restore old status dance.  It could also be
>> allowable from user mode safely, unlike normal interrupt disable, since
>> it is only temporary.  And then you would have an easy and safe way to
>> make short multi-instruction atomic sections, in a way that could be
>> used by any language.
>>
>> That would not completely solve your complex invariant problem here, but
>> it could be used to have atomic logs/trackers of the state of the
>> object, allowing the program to identify and recover from inconsistent
>> states.
>
> I agree on its usefulness for your kind of application - those where you
> control all the software.  However on a general purpose system, I can
> see lots of potential problems, mostly involving denial of service attacks.
>

That is the point of having it limited - it would block interrupts for
up to N instructions (where N is a small constant), and then even if
followed by another "disable interrupts for the next N instructions",
interrupts could be handled between them.

I agree that on a bigger system, there are complications that would need
to be considered - multiple cores, long delays for memory, fault
handling, etc. Those would likely make it useless for such systems.
(On bigger systems, I would prefer to see dedicated hardware to handle
things like locks - it is insane that locks are slow, pageable
general-purpose memory instead of a small block of dedicated
core-coordinated locks.)

Re: Safepoints

<sedj5r$b0l$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19542&group=comp.arch#19542

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.arch
Subject: Re: Safepoints
Date: Wed, 4 Aug 2021 10:29:47 +0200
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <sedj5r$b0l$2@dont-email.me>
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <se36el$en5$1@dont-email.me>
<se4aae$qma$1@dont-email.me>
<f1240d75-82d6-468e-bf51-c4e275e38a4an@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 4 Aug 2021 08:29:47 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5c84e891ee178787f1df57542d7264bc";
logging-data="11285"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jk1+mYBXidrNbAlnsAGE/kP3cIr77ex0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:V1/8SaceCm18jLjNT6fOjTBgusI=
In-Reply-To: <f1240d75-82d6-468e-bf51-c4e275e38a4an@googlegroups.com>
Content-Language: en-GB
 by: David Brown - Wed, 4 Aug 2021 08:29 UTC

On 31/07/2021 22:58, MitchAlsup wrote:
> On Saturday, July 31, 2021 at 3:03:28 PM UTC-5, Stephen Fuld wrote:
>> On 7/31/2021 2:51 AM, David Brown wrote:
>>
>> snip
>>> I've always thought a "disable interrupts for the next N instructions",
>>> with "N" being a small immediate constant, would be an extremely useful
>>> instruction on the kind of devices I use (single cpu microcontrollers).
> <
> I can see utility here, but you need not only N as the number of instructions,
> but also P the priority level below which you suppress interrupts and above
> which you still allow interrupts.
> <

No - you block /all/ interrupts, of /all/ priorities. That's key to
such an instruction.

> In the realm of real CPUs (not microcontrollers) P is variable and the task/
> thread might not know what privilege level is appropriate. In a hypervisor/
> supervisor system, you might not be allowed to even know what level is
> appropriate.

Pages:1234
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor