Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Call me bored, but don't call me boring. -- Larry Wall in <199705101952.MAA00756@wall.org>


devel / comp.arch / 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
Safepoints

<se1s18$sf$1@z-news.wcss.wroc.pl>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-01.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: Safepoints
Date: Fri, 30 Jul 2021 21:47:20 +0000 (UTC)
Organization: Politechnika Wroclawska
Lines: 68
Message-ID: <se1s18$sf$1@z-news.wcss.wroc.pl>
NNTP-Posting-Host: hera.math.uni.wroc.pl
X-Trace: z-news.wcss.wroc.pl 1627681640 911 156.17.86.1 (30 Jul 2021 21:47:20 GMT)
X-Complaints-To: abuse@news.pwr.wroc.pl
NNTP-Posting-Date: Fri, 30 Jul 2021 21:47:20 +0000 (UTC)
Cancel-Lock: sha1:dxn+VVySqVaTP+ZmvJzyHGa0yEQ=
User-Agent: tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-10-amd64 (x86_64))
X-Received-Bytes: 4287
 by: antis...@math.uni.wroc.pl - Fri, 30 Jul 2021 21:47 UTC

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?

--
Waldek Hebisch

Re: Safepoints

<954710b2-2516-49b1-9378-1bc9f82be013n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.arch
X-Received: by 2002:ac8:73c9:: with SMTP id v9mr4350744qtp.214.1627684051128;
Fri, 30 Jul 2021 15:27:31 -0700 (PDT)
X-Received: by 2002:a9d:7f14:: with SMTP id j20mr3675504otq.82.1627684050861;
Fri, 30 Jul 2021 15:27:30 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.arch
Date: Fri, 30 Jul 2021 15:27:30 -0700 (PDT)
In-Reply-To: <se1s18$sf$1@z-news.wcss.wroc.pl>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:291:29f0:918b:713a:6df:fda7;
posting-account=H_G_JQkAAADS6onOMb-dqvUozKse7mcM
NNTP-Posting-Host: 2600:1700:291:29f0:918b:713a:6df:fda7
References: <se1s18$sf$1@z-news.wcss.wroc.pl>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <954710b2-2516-49b1-9378-1bc9f82be013n@googlegroups.com>
Subject: Re: Safepoints
From: MitchAl...@aol.com (MitchAlsup)
Injection-Date: Fri, 30 Jul 2021 22:27:31 +0000
Content-Type: text/plain; charset="UTF-8"
 by: MitchAlsup - Fri, 30 Jul 2021 22:27 UTC

On Friday, July 30, 2021 at 4:47:22 PM UTC-5, anti...@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.
<
I might interject at this instant, that My 66000 has this kind of
behavior with its ATOMIC events (multiple word ATOMICs.)
If the ATOMIC event fails to complete, control is transferred
to a place where SW understands that it is no longer "IN" the
ATOMIC event. Exceptions and interrupts terminate the
ATOMIC event and perform said transfer of control, there are
branch instructions which can conditionally transfer control
out of the ATOMIC event and thus terminate it uncessfully.
<
One of the reason I inverted it was so that a concurrent data
structure could have an element moved from one location in
the CDS to another location without every being detected as
"NOT IN" the CDS. Normal ATOMIC events (such as Compare
double swap double) cannot perform this. This improves the
invariants while reducing the number of ATOMIC events.
<
What I don't understand about OP's statement is when we might
need such an invariant manifest when we are not also doing some-
thing that needs to smell ATOMIC. Can OP expand on this ?
<
> So, what is needed is transfer of control to handler at
> next safepoint, that is at next place where program may be
> safely interrupted.
<
An interrupt, be definition, is asynchronous to the program.
Indeed, it is foreign to the program, the program should know
nothing about it except that it happened and control has
returned.
<
Does OP really mean interrupt, here ?
<
Could OP mean exception instead ?
<
> 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:
<
From above to establish context::
> 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.
<
Why not have the asynchronous event create a worklist and when
the program gets around to checking for new elements on the
asynchronous work list, it devotes some resources to making that
work happen. Thus, the only thing the asynchronous handler would
be doing is to lob units of work on said worklist (probably ATOMICally.)
<
This is basically what interrupt handlers do today--the lob work onto
the worklist and dismiss the interrupt. then they schedule the OS
which looks at the worklist (job queue) which then context switches
into the real handler, and performs a unit or work; then it all unwinds
so control eventually returns to interrupted program.
>
> 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?
<
2 level interrupt handling:
<
First level creates a unit of work on the job queue and dismisses interrupt.
If work was put on job queue, then invoke OS scheduler, otherwise return
from interrupt. This level has to be short and fast doing as little as possible
to keep interrupt responsiveness high.
<
Second level takes unit of work off job queue and processes the unit of work.
When job queue is empty, return control back to interrupted program. This
level only has to methodologically work thought the job queue.
<
We have been doing it this way for at least 6 decades.
>
> --
> Waldek Hebisch

Re: Safepoints

<se22ph$ojf$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: iva...@millcomputing.com (Ivan Godard)
Newsgroups: comp.arch
Subject: Re: Safepoints
Date: Fri, 30 Jul 2021 16:42:41 -0700
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <se22ph$ojf$1@dont-email.me>
References: <se1s18$sf$1@z-news.wcss.wroc.pl>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 30 Jul 2021 23:42:41 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="656df2d4a36b93ade364e88462c7c58f";
logging-data="25199"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194iOgs8/B5nhLtpWDBIF0J"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.12.0
Cancel-Lock: sha1:u3GnxxfuR2imoxx40UimEqRNFcY=
In-Reply-To: <se1s18$sf$1@z-news.wcss.wroc.pl>
Content-Language: en-US
 by: Ivan Godard - Fri, 30 Jul 2021 23:42 UTC

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.

Re: Safepoints

<6l0NI.10262$yU3.3417@fx05.iad>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx05.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>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 72
Message-ID: <6l0NI.10262$yU3.3417@fx05.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Fri, 30 Jul 2021 23:56:50 UTC
Organization: usenet-news.net
Date: Fri, 30 Jul 2021 23:56:50 GMT
X-Received-Bytes: 4306
 by: Branimir Maksimovic - Fri, 30 Jul 2021 23:56 UTC

On 2021-07-30, antispam@math.uni.wroc.pl <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?
>
Signals are obsolete long ago. Now use threads and implement
user space scheduler.

--
bmaxa now listens Yammat FM

Re: Safepoints

<se266v$9aj$1@z-news.wcss.wroc.pl>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.swapon.de!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-01.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 00:41:03 +0000 (UTC)
Organization: Politechnika Wroclawska
Lines: 81
Message-ID: <se266v$9aj$1@z-news.wcss.wroc.pl>
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <se22ph$ojf$1@dont-email.me>
NNTP-Posting-Host: hera.math.uni.wroc.pl
X-Trace: z-news.wcss.wroc.pl 1627692063 9555 156.17.86.1 (31 Jul 2021 00:41:03 GMT)
X-Complaints-To: abuse@news.pwr.wroc.pl
NNTP-Posting-Date: Sat, 31 Jul 2021 00:41:03 +0000 (UTC)
Cancel-Lock: sha1:tJhhiPdbO6MFZK3RU0l4ye1JsQs=
User-Agent: tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-10-amd64 (x86_64))
X-Received-Bytes: 5281
 by: antis...@math.uni.wroc.pl - Sat, 31 Jul 2021 00:41 UTC

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.

Sorry, wont do. One problem is that I have native code compiler
with precise garbage collector. In C++ I would have to use
interpreter. There would be substantial slowdown. And going with
interpreter (not necesserly in C) implementing safepoints
is not a problem, except for performance hit...

--
Waldek Hebisch

Re: Safepoints

<R11NI.28056$7H7.18900@fx42.iad>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!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.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx42.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>
<se266v$9aj$1@z-news.wcss.wroc.pl>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 86
Message-ID: <R11NI.28056$7H7.18900@fx42.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sat, 31 Jul 2021 00:44:33 UTC
Organization: usenet-news.net
Date: Sat, 31 Jul 2021 00:44:33 GMT
X-Received-Bytes: 5186
 by: Branimir Maksimovic - Sat, 31 Jul 2021 00:44 UTC

On 2021-07-31, antispam@math.uni.wroc.pl <antispam@math.uni.wroc.pl> wrote:
> 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.
>
> Sorry, wont do. One problem is that I have native code compiler
> with precise garbage collector. In C++ I would have to use
> interpreter. There would be substantial slowdown. And going with
> interpreter (not necesserly in C) implementing safepoints
> is not a problem, except for performance hit...

Good luck with that :P
>

--
bmaxa now listens Yammat FM

Re: Safepoints

<O31NI.28057$7H7.8371@fx42.iad>

  copy mid

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

  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.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!fx42.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>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 77
Message-ID: <O31NI.28057$7H7.8371@fx42.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sat, 31 Jul 2021 00:46:38 UTC
Organization: usenet-news.net
Date: Sat, 31 Jul 2021 00:46:38 GMT
X-Received-Bytes: 4675
 by: Branimir Maksimovic - Sat, 31 Jul 2021 00:46 UTC

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

--
bmaxa now listens Yammat FM

Re: Safepoints

<se29sn$dtn$1@z-news.wcss.wroc.pl>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!border2.nntp.ams1.giganews.com!nntp.giganews.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 01:43:51 +0000 (UTC)
Organization: Politechnika Wroclawska
Lines: 206
Message-ID: <se29sn$dtn$1@z-news.wcss.wroc.pl>
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <954710b2-2516-49b1-9378-1bc9f82be013n@googlegroups.com>
NNTP-Posting-Host: hera.math.uni.wroc.pl
X-Trace: z-news.wcss.wroc.pl 1627695831 14263 156.17.86.1 (31 Jul 2021 01:43:51 GMT)
X-Complaints-To: abuse@news.pwr.wroc.pl
NNTP-Posting-Date: Sat, 31 Jul 2021 01:43:51 +0000 (UTC)
Cancel-Lock: sha1:sELa7S2ZqLv4YKCbqkovABDFf4o=
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 01:43 UTC

MitchAlsup <MitchAlsup@aol.com> wrote:
> On Friday, July 30, 2021 at 4:47:22 PM UTC-5, anti...@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.
> <
> I might interject at this instant, that My 66000 has this kind of
> behavior with its ATOMIC events (multiple word ATOMICs.)
> If the ATOMIC event fails to complete, control is transferred
> to a place where SW understands that it is no longer "IN" the
> ATOMIC event. Exceptions and interrupts terminate the
> ATOMIC event and perform said transfer of control, there are
> branch instructions which can conditionally transfer control
> out of the ATOMIC event and thus terminate it uncessfully.
> <
> One of the reason I inverted it was so that a concurrent data
> structure could have an element moved from one location in
> the CDS to another location without every being detected as
> "NOT IN" the CDS. Normal ATOMIC events (such as Compare
> double swap double) cannot perform this. This improves the
> invariants while reducing the number of ATOMIC events.
> <
> What I don't understand about OP's statement is when we might
> need such an invariant manifest when we are not also doing some-
> thing that needs to smell ATOMIC. Can OP expand on this ?

Main issue are invariants expected by garbage collector. Extreme,
but simple case is when garbage collector runs: this is "stop
the world" garbage collector, so no other high-level code can
run during garbage collection (garbage collector is in the
same language, but written only using constructs that do
not use normal memory allocation). Garbage collector
is simple, because when it finishes it checks flags for
deferred interrupts. More typical example are function
prologues and epilogues: garbage collector is looking at stack
and needs well-formed stack frames. Once function prologue
is done runtime system can call high-level signal handler
which will build its own stack frame. When high-level
signal handler returns interrupted routine may continue
its work. But if signal handler decides to throw exception,
it will properly unwind stack up to corresponding handler.

Another example is memory allocation: various data structurs
needs to be properly initilized before garbage collector
is allowed to see them.

Yet another (quit frequent) example are derived pointers.
When accessing arrays generated code normally uses base + index
addresing mode. But in many cases it must temporarly create
base+index in a register. Garbage collector can only handle
pointers to start of an object, so garbage collection is
allowed only when no register contains derived pointers
(like base + index form). Yet another thing are temporary
values in registers. Garbage collector deals with tagged values
and pointers. Due to low bit tags garbage collector sees that
tagged values are not pointers and skips them. But untagged
(machine) integer can not appear in place when pointer can
appear, because garbage collector would have no way to distinguish
such integer from a pointer. Currently there is fixed division,
some register contain tagged values, some untagged ones.
But there are also temporary (scratch) registers which
may contain both tagged and untagged values. Garbage
collection is not allowed when a scratch register may contain
a pointer. Scratch register are short lived and after
few instructions all scratch registers are dead.

Now, your ATIMIC construct could help, but it would be used
quite a lot. My guesstimate is that more than 50% of code
would end as member of ATIMIC section. Most section would
be quite short (2-5 instructions), but some would go into
hundreds of instructions. I a bit worried about performance
impact of so many ATIMICs, given that my use does not really
require special warranties with respect to memory (beyond
normal consistency between thread an interrupt handler).

> <
> > So, what is needed is transfer of control to handler at
> > next safepoint, that is at next place where program may be
> > safely interrupted.
> <
> An interrupt, be definition, is asynchronous to the program.
> Indeed, it is foreign to the program, the program should know
> nothing about it except that it happened and control has
> returned.
> <
> Does OP really mean interrupt, here ?
> <
> Could OP mean exception instead ?

Concretly, I have Linux signals. They are asynchonous, but
desired effect is that executing code sees data structures
modified by signal handler and signal handler may pass control
to different place. Signal handler is allowed to allocate
memory, so may trigger garbage collection. Conseqently, when
actual signal handler is allowed to run it must be at point
when garbage collection is safe. There may be other constraints,
for example related to hash tables, but garbage collection
is major issue and it is solved then other problems should be
solvable.

> <
> > 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:
> <
> From above to establish context::
> > 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.
> <
> Why not have the asynchronous event create a worklist and when
> the program gets around to checking for new elements on the
> asynchronous work list, it devotes some resources to making that
> work happen. Thus, the only thing the asynchronous handler would
> be doing is to lob units of work on said worklist (probably ATOMICally.)
> <
> This is basically what interrupt handlers do today--the lob work onto
> the worklist and dismiss the interrupt. then they schedule the OS
> which looks at the worklist (job queue) which then context switches
> into the real handler, and performs a unit or work; then it all unwinds
> so control eventually returns to interrupted program.

In a sense it is 1) below. Except for that I do not have scheduler,
so main thread must check for flags and run deferred handlers.
This works, but has major performance problem.

> > 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?
> <
> 2 level interrupt handling:
> <
> First level creates a unit of work on the job queue and dismisses interrupt.
> If work was put on job queue, then invoke OS scheduler, otherwise return
> from interrupt. This level has to be short and fast doing as little as possible
> to keep interrupt responsiveness high.
> <
> Second level takes unit of work off job queue and processes the unit of work.
> When job queue is empty, return control back to interrupted program. This
> level only has to methodologically work thought the job queue.
> <
> We have been doing it this way for at least 6 decades.


Click here to read the complete article
Re: Safepoints

<q52NI.91902$VU3.19281@fx46.iad>

  copy mid

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

  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!fdc2.netnews.com!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx46.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>
<954710b2-2516-49b1-9378-1bc9f82be013n@googlegroups.com>
<se29sn$dtn$1@z-news.wcss.wroc.pl>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 115
Message-ID: <q52NI.91902$VU3.19281@fx46.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sat, 31 Jul 2021 01:56:38 UTC
Organization: usenet-news.net
Date: Sat, 31 Jul 2021 01:56:38 GMT
X-Received-Bytes: 6362
 by: Branimir Maksimovic - Sat, 31 Jul 2021 01:56 UTC

On 2021-07-31, antispam@math.uni.wroc.pl <antispam@math.uni.wroc.pl> wrote:
> MitchAlsup <MitchAlsup@aol.com> wrote:
>> On Friday, July 30, 2021 at 4:47:22 PM UTC-5, anti...@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.
>> <
>> I might interject at this instant, that My 66000 has this kind of
>> behavior with its ATOMIC events (multiple word ATOMICs.)
>> If the ATOMIC event fails to complete, control is transferred
>> to a place where SW understands that it is no longer "IN" the
>> ATOMIC event. Exceptions and interrupts terminate the
>> ATOMIC event and perform said transfer of control, there are
>> branch instructions which can conditionally transfer control
>> out of the ATOMIC event and thus terminate it uncessfully.
>> <
>> One of the reason I inverted it was so that a concurrent data
>> structure could have an element moved from one location in
>> the CDS to another location without every being detected as
>> "NOT IN" the CDS. Normal ATOMIC events (such as Compare
>> double swap double) cannot perform this. This improves the
>> invariants while reducing the number of ATOMIC events.
>> <
>> What I don't understand about OP's statement is when we might
>> need such an invariant manifest when we are not also doing some-
>> thing that needs to smell ATOMIC. Can OP expand on this ?
>
> Main issue are invariants expected by garbage collector. Extreme,
> but simple case is when garbage collector runs: this is "stop
> the world" garbage collector, so no other high-level code can
> run during garbage collection (garbage collector is in the
> same language, but written only using constructs that do
> not use normal memory allocation). Garbage collector
> is simple, because when it finishes it checks flags for
> deferred interrupts. More typical example are function
> prologues and epilogues: garbage collector is looking at stack
> and needs well-formed stack frames. Once function prologue
> is done runtime system can call high-level signal handler
> which will build its own stack frame. When high-level
> signal handler returns interrupted routine may continue
> its work. But if signal handler decides to throw exception,
> it will properly unwind stack up to corresponding handler.
>
> Another example is memory allocation: various data structurs
> needs to be properly initilized before garbage collector
> is allowed to see them.
>
> Yet another (quit frequent) example are derived pointers.
> When accessing arrays generated code normally uses base + index
> addresing mode. But in many cases it must temporarly create
> base+index in a register. Garbage collector can only handle
> pointers to start of an object, so garbage collection is
> allowed only when no register contains derived pointers
> (like base + index form). Yet another thing are temporary
> values in registers. Garbage collector deals with tagged values
> and pointers. Due to low bit tags garbage collector sees that
> tagged values are not pointers and skips them. But untagged
> (machine) integer can not appear in place when pointer can
> appear, because garbage collector would have no way to distinguish
> such integer from a pointer. Currently there is fixed division,
> some register contain tagged values, some untagged ones.
> But there are also temporary (scratch) registers which
> may contain both tagged and untagged values. Garbage
> collection is not allowed when a scratch register may contain
> a pointer. Scratch register are short lived and after
> few instructions all scratch registers are dead.
>
> Now, your ATIMIC construct could help, but it would be used
> quite a lot. My guesstimate is that more than 50% of code
> would end as member of ATIMIC section. Most section would
> be quite short (2-5 instructions), but some would go into
> hundreds of instructions. I a bit worried about performance
> impact of so many ATIMICs, given that my use does not really
> require special warranties with respect to memory (beyond
> normal consistency between thread an interrupt handler).
>
>> <
>> > So, what is needed is transfer of control to handler at
>> > next safepoint, that is at next place where program may be
>> > safely interrupted.
>> <
>> An interrupt, be definition, is asynchronous to the program.
>> Indeed, it is foreign to the program, the program should know
>> nothing about it except that it happened and control has
>> returned.
>> <
>> Does OP really mean interrupt, here ?
>> <
>> Could OP mean exception instead ?
>
> Concretly, I have Linux signals. They are asynchonous, but
> desired effect is that executing code sees data structures
> modified by signal handler and signal handler may pass control
> to different place.

Signal handler is allowed to allocate
> memory, so may trigger garbage collection.

no it is not:
first read man page:
https://man7.org/linux/man-pages/man7/signal-safety.7.html

--
bmaxa now listens Yammat FM

Re: Safepoints

<xt3NI.20442$6U5.14847@fx02.iad>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!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!fx02.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>
<954710b2-2516-49b1-9378-1bc9f82be013n@googlegroups.com>
<se29sn$dtn$1@z-news.wcss.wroc.pl> <q52NI.91902$VU3.19281@fx46.iad>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 119
Message-ID: <xt3NI.20442$6U5.14847@fx02.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sat, 31 Jul 2021 03:30:37 UTC
Organization: usenet-news.net
Date: Sat, 31 Jul 2021 03:30:37 GMT
X-Received-Bytes: 6727
 by: Branimir Maksimovic - Sat, 31 Jul 2021 03:30 UTC

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:
>> MitchAlsup <MitchAlsup@aol.com> wrote:
>>> On Friday, July 30, 2021 at 4:47:22 PM UTC-5, anti...@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.
>>> <
>>> I might interject at this instant, that My 66000 has this kind of
>>> behavior with its ATOMIC events (multiple word ATOMICs.)
>>> If the ATOMIC event fails to complete, control is transferred
>>> to a place where SW understands that it is no longer "IN" the
>>> ATOMIC event. Exceptions and interrupts terminate the
>>> ATOMIC event and perform said transfer of control, there are
>>> branch instructions which can conditionally transfer control
>>> out of the ATOMIC event and thus terminate it uncessfully.
>>> <
>>> One of the reason I inverted it was so that a concurrent data
>>> structure could have an element moved from one location in
>>> the CDS to another location without every being detected as
>>> "NOT IN" the CDS. Normal ATOMIC events (such as Compare
>>> double swap double) cannot perform this. This improves the
>>> invariants while reducing the number of ATOMIC events.
>>> <
>>> What I don't understand about OP's statement is when we might
>>> need such an invariant manifest when we are not also doing some-
>>> thing that needs to smell ATOMIC. Can OP expand on this ?
>>
>> Main issue are invariants expected by garbage collector. Extreme,
>> but simple case is when garbage collector runs: this is "stop
>> the world" garbage collector, so no other high-level code can
>> run during garbage collection (garbage collector is in the
>> same language, but written only using constructs that do
>> not use normal memory allocation). Garbage collector
>> is simple, because when it finishes it checks flags for
>> deferred interrupts. More typical example are function
>> prologues and epilogues: garbage collector is looking at stack
>> and needs well-formed stack frames. Once function prologue
>> is done runtime system can call high-level signal handler
>> which will build its own stack frame. When high-level
>> signal handler returns interrupted routine may continue
>> its work. But if signal handler decides to throw exception,
>> it will properly unwind stack up to corresponding handler.
>>
>> Another example is memory allocation: various data structurs
>> needs to be properly initilized before garbage collector
>> is allowed to see them.
>>
>> Yet another (quit frequent) example are derived pointers.
>> When accessing arrays generated code normally uses base + index
>> addresing mode. But in many cases it must temporarly create
>> base+index in a register. Garbage collector can only handle
>> pointers to start of an object, so garbage collection is
>> allowed only when no register contains derived pointers
>> (like base + index form). Yet another thing are temporary
>> values in registers. Garbage collector deals with tagged values
>> and pointers. Due to low bit tags garbage collector sees that
>> tagged values are not pointers and skips them. But untagged
>> (machine) integer can not appear in place when pointer can
>> appear, because garbage collector would have no way to distinguish
>> such integer from a pointer. Currently there is fixed division,
>> some register contain tagged values, some untagged ones.
>> But there are also temporary (scratch) registers which
>> may contain both tagged and untagged values. Garbage
>> collection is not allowed when a scratch register may contain
>> a pointer. Scratch register are short lived and after
>> few instructions all scratch registers are dead.
>>
>> Now, your ATIMIC construct could help, but it would be used
>> quite a lot. My guesstimate is that more than 50% of code
>> would end as member of ATIMIC section. Most section would
>> be quite short (2-5 instructions), but some would go into
>> hundreds of instructions. I a bit worried about performance
>> impact of so many ATIMICs, given that my use does not really
>> require special warranties with respect to memory (beyond
>> normal consistency between thread an interrupt handler).
>>
>>> <
>>> > So, what is needed is transfer of control to handler at
>>> > next safepoint, that is at next place where program may be
>>> > safely interrupted.
>>> <
>>> An interrupt, be definition, is asynchronous to the program.
>>> Indeed, it is foreign to the program, the program should know
>>> nothing about it except that it happened and control has
>>> returned.
>>> <
>>> Does OP really mean interrupt, here ?
>>> <
>>> Could OP mean exception instead ?
>>
>> Concretly, I have Linux signals. They are asynchonous, but
>> desired effect is that executing code sees data structures
>> modified by signal handler and signal handler may pass control
>> to different place.
>
>
> Signal handler is allowed to allocate
>> memory, so may trigger garbage collection.
>
> no it is not:
> first read man page:
> https://man7.org/linux/man-pages/man7/signal-safety.7.html
>
>
BTW look up in GC implementation of "stop the world". It probably
uses signals. Use same tehcnique to implement user space scheduler.

--
bmaxa now listens Yammat FM

Re: Safepoints

<p%3NI.97196$Vv6.75172@fx45.iad>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc3.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>
<954710b2-2516-49b1-9378-1bc9f82be013n@googlegroups.com>
<se29sn$dtn$1@z-news.wcss.wroc.pl> <q52NI.91902$VU3.19281@fx46.iad>
<xt3NI.20442$6U5.14847@fx02.iad>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 126
Message-ID: <p%3NI.97196$Vv6.75172@fx45.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sat, 31 Jul 2021 04:06:45 UTC
Organization: usenet-news.net
Date: Sat, 31 Jul 2021 04:06:45 GMT
X-Received-Bytes: 7218
 by: Branimir Maksimovic - Sat, 31 Jul 2021 04:06 UTC

On 2021-07-31, 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:
>>> MitchAlsup <MitchAlsup@aol.com> wrote:
>>>> On Friday, July 30, 2021 at 4:47:22 PM UTC-5, anti...@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.
>>>> <
>>>> I might interject at this instant, that My 66000 has this kind of
>>>> behavior with its ATOMIC events (multiple word ATOMICs.)
>>>> If the ATOMIC event fails to complete, control is transferred
>>>> to a place where SW understands that it is no longer "IN" the
>>>> ATOMIC event. Exceptions and interrupts terminate the
>>>> ATOMIC event and perform said transfer of control, there are
>>>> branch instructions which can conditionally transfer control
>>>> out of the ATOMIC event and thus terminate it uncessfully.
>>>> <
>>>> One of the reason I inverted it was so that a concurrent data
>>>> structure could have an element moved from one location in
>>>> the CDS to another location without every being detected as
>>>> "NOT IN" the CDS. Normal ATOMIC events (such as Compare
>>>> double swap double) cannot perform this. This improves the
>>>> invariants while reducing the number of ATOMIC events.
>>>> <
>>>> What I don't understand about OP's statement is when we might
>>>> need such an invariant manifest when we are not also doing some-
>>>> thing that needs to smell ATOMIC. Can OP expand on this ?
>>>
>>> Main issue are invariants expected by garbage collector. Extreme,
>>> but simple case is when garbage collector runs: this is "stop
>>> the world" garbage collector, so no other high-level code can
>>> run during garbage collection (garbage collector is in the
>>> same language, but written only using constructs that do
>>> not use normal memory allocation). Garbage collector
>>> is simple, because when it finishes it checks flags for
>>> deferred interrupts. More typical example are function
>>> prologues and epilogues: garbage collector is looking at stack
>>> and needs well-formed stack frames. Once function prologue
>>> is done runtime system can call high-level signal handler
>>> which will build its own stack frame. When high-level
>>> signal handler returns interrupted routine may continue
>>> its work. But if signal handler decides to throw exception,
>>> it will properly unwind stack up to corresponding handler.
>>>
>>> Another example is memory allocation: various data structurs
>>> needs to be properly initilized before garbage collector
>>> is allowed to see them.
>>>
>>> Yet another (quit frequent) example are derived pointers.
>>> When accessing arrays generated code normally uses base + index
>>> addresing mode. But in many cases it must temporarly create
>>> base+index in a register. Garbage collector can only handle
>>> pointers to start of an object, so garbage collection is
>>> allowed only when no register contains derived pointers
>>> (like base + index form). Yet another thing are temporary
>>> values in registers. Garbage collector deals with tagged values
>>> and pointers. Due to low bit tags garbage collector sees that
>>> tagged values are not pointers and skips them. But untagged
>>> (machine) integer can not appear in place when pointer can
>>> appear, because garbage collector would have no way to distinguish
>>> such integer from a pointer. Currently there is fixed division,
>>> some register contain tagged values, some untagged ones.
>>> But there are also temporary (scratch) registers which
>>> may contain both tagged and untagged values. Garbage
>>> collection is not allowed when a scratch register may contain
>>> a pointer. Scratch register are short lived and after
>>> few instructions all scratch registers are dead.
>>>
>>> Now, your ATIMIC construct could help, but it would be used
>>> quite a lot. My guesstimate is that more than 50% of code
>>> would end as member of ATIMIC section. Most section would
>>> be quite short (2-5 instructions), but some would go into
>>> hundreds of instructions. I a bit worried about performance
>>> impact of so many ATIMICs, given that my use does not really
>>> require special warranties with respect to memory (beyond
>>> normal consistency between thread an interrupt handler).
>>>
>>>> <
>>>> > So, what is needed is transfer of control to handler at
>>>> > next safepoint, that is at next place where program may be
>>>> > safely interrupted.
>>>> <
>>>> An interrupt, be definition, is asynchronous to the program.
>>>> Indeed, it is foreign to the program, the program should know
>>>> nothing about it except that it happened and control has
>>>> returned.
>>>> <
>>>> Does OP really mean interrupt, here ?
>>>> <
>>>> Could OP mean exception instead ?
>>>
>>> Concretly, I have Linux signals. They are asynchonous, but
>>> desired effect is that executing code sees data structures
>>> modified by signal handler and signal handler may pass control
>>> to different place.
>>
>>
>> Signal handler is allowed to allocate
>>> memory, so may trigger garbage collection.
>>
>> no it is not:
>> first read man page:
>> https://man7.org/linux/man-pages/man7/signal-safety.7.html
>>
>>
> BTW look up in GC implementation of "stop the world". It probably
> uses signals. Use same tehcnique to implement user space scheduler.
>
Heh, on the second thought, perhaps you don't know that handling
of async events nowdays are done by starting thread or forking process?
Perhaps you don't even need userspace threads :P
Golang implements cooperative, Haskell I think real multi tasking.

--
bmaxa now listens Yammat FM

Re: Safepoints

<se32gk$jri$1@newsreader4.netcologne.de>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd7-c228-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoe...@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: Re: Safepoints
Date: Sat, 31 Jul 2021 08:44:04 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <se32gk$jri$1@newsreader4.netcologne.de>
References: <se1s18$sf$1@z-news.wcss.wroc.pl>
Injection-Date: Sat, 31 Jul 2021 08:44:04 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-c228-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd7:c228:0:7285:c2ff:fe6c:992d";
logging-data="20338"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Sat, 31 Jul 2021 08:44 UTC

antispam@math.uni.wroc.pl <antispam@math.uni.wroc.pl> schrieb:

> Problem: We want to code in high-level language and we want
> to respond to asynchronous events.

Have you looked at the way Ada handles interrupts?
https://www.adacore.com/gems/ada-gem-13 looks like a good first
read, but of course assumes some familiarity with Ada which I
don't have at that level.

Re: Safepoints

<Ze8NI.28063$7H7.19450@fx42.iad>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx42.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>
<se32gk$jri$1@newsreader4.netcologne.de>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 16
Message-ID: <Ze8NI.28063$7H7.19450@fx42.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sat, 31 Jul 2021 08:56:25 UTC
Organization: usenet-news.net
Date: Sat, 31 Jul 2021 08:56:25 GMT
X-Received-Bytes: 1229
 by: Branimir Maksimovic - Sat, 31 Jul 2021 08:56 UTC

On 2021-07-31, Thomas Koenig <tkoenig@netcologne.de> wrote:
> antispam@math.uni.wroc.pl <antispam@math.uni.wroc.pl> schrieb:
>
>> Problem: We want to code in high-level language and we want
>> to respond to asynchronous events.
>
> Have you looked at the way Ada handles interrupts?
> https://www.adacore.com/gems/ada-gem-13 looks like a good first
> read, but of course assumes some familiarity with Ada which I
> don't have at that level.
He uses OS, that is Linux, this is for working wihout OS....
Besides, nobody here can figure out that he doesn;'t know
what is he talking about :P

--
bmaxa now listens Ob-Neob Radio

Re: Safepoints

<se36el$en5$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.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: Sat, 31 Jul 2021 11:51:16 +0200
Organization: A noiseless patient Spider
Lines: 84
Message-ID: <se36el$en5$1@dont-email.me>
References: <se1s18$sf$1@z-news.wcss.wroc.pl>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 31 Jul 2021 09:51:17 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ca90cae15aadd9a377054eb8e02f1b14";
logging-data="15077"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/OwwYvx0UA9yWAMdO1P76eyWUkbN9qkWg="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:rYl8yWPgihbGXlo/WSoa8doWtSo=
In-Reply-To: <se1s18$sf$1@z-news.wcss.wroc.pl>
Content-Language: en-GB
 by: David Brown - Sat, 31 Jul 2021 09:51 UTC

On 30/07/2021 23:47, 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?
>

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.

Re: Safepoints

<3a9NI.51400$Yv3.14029@fx41.iad>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx41.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> <se36el$en5$1@dont-email.me>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 91
Message-ID: <3a9NI.51400$Yv3.14029@fx41.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sat, 31 Jul 2021 09:59:27 UTC
Organization: usenet-news.net
Date: Sat, 31 Jul 2021 09:59:27 GMT
X-Received-Bytes: 5461
 by: Branimir Maksimovic - Sat, 31 Jul 2021 09:59 UTC

On 2021-07-31, David Brown <david.brown@hesbynett.no> wrote:
> On 30/07/2021 23:47, 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?
>>
>
> 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....

--
bmaxa now listens Ob-Neob Radio

Re: Safepoints

<OX9NI.48204$UR4.47953@fx37.iad>

  copy mid

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

  copy link   Newsgroups: comp.arch
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!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx37.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> <se36el$en5$1@dont-email.me>
<3a9NI.51400$Yv3.14029@fx41.iad>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 102
Message-ID: <OX9NI.48204$UR4.47953@fx37.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sat, 31 Jul 2021 10:52:30 UTC
Organization: usenet-news.net
Date: Sat, 31 Jul 2021 10:52:30 GMT
X-Received-Bytes: 6055
 by: Branimir Maksimovic - Sat, 31 Jul 2021 10:52 UTC

On 2021-07-31, Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> On 2021-07-31, David Brown <david.brown@hesbynett.no> wrote:
>> On 30/07/2021 23:47, 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?
>>>
>>
>> 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....
>

Problem is that signal handler is equivalent of interrupt service routine.
It can be interupted by same interrupt/signal and called again. If you disable
interrupts for longer time (than necessary to service whatever in driver under
Linux),
it won't be called and may break OS.
Also he is mentioning GC in this story :P
Without OS no problem, but he is also mentioning Linux.

--
bmaxa now listens Ob-Neob Radio

Re: Safepoints

<7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!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: Sat, 31 Jul 2021 06:04:08 -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>
User-Agent: tin/1.9.2-20070201 ("Dalaruan") (UNIX) (Linux/4.18.0-240.8.1.el8_3.x86_64 (x86_64))
Message-ID: <7oOdnX04-by1s5j8nZ2dnUU7-QnNnZ2d@supernews.com>
Date: Sat, 31 Jul 2021 06:04:08 -0500
Lines: 38
X-Trace: sv3-TDlyKXXkPD9F7cdqQduall5u2AxwX9xcHFgeAkpkpBfTSQ0ZLQxskTj2oFwNYS/XMA1QmZuxNaLgP4o!qisB+kl9wQfCW+WdKVMM5/9bgH5YX2lHUDB8TJaTjpRH7mY/JZc7IKYf/n62Ias1ReEXvqGd7Cbs!LtB6+Bow
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: 2912
 by: aph...@littlepinkcloud.invalid - Sat, 31 Jul 2021 11:04 UTC

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.

Re: Safepoints

<GvaNI.128355$h8.72917@fx47.iad>

  copy mid

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

  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!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx47.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>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 46
Message-ID: <GvaNI.128355$h8.72917@fx47.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sat, 31 Jul 2021 11:30:46 UTC
Organization: usenet-news.net
Date: Sat, 31 Jul 2021 11:30:46 GMT
X-Received-Bytes: 2853
 by: Branimir Maksimovic - Sat, 31 Jul 2021 11:30 UTC

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.
Isn't it simpler just to start another thread which will wait on events? :P
With GC, JIT and all that :P
He is also mentioning memory allocation from signal handler...

--
bmaxa now listens Ob-Neob Radio

Re: Safepoints

<se3epi$itv$1@z-news.wcss.wroc.pl>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!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 12:13:38 +0000 (UTC)
Organization: Politechnika Wroclawska
Lines: 127
Message-ID: <se3epi$itv$1@z-news.wcss.wroc.pl>
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <954710b2-2516-49b1-9378-1bc9f82be013n@googlegroups.com> <se29sn$dtn$1@z-news.wcss.wroc.pl> <q52NI.91902$VU3.19281@fx46.iad>
NNTP-Posting-Host: hera.math.uni.wroc.pl
X-Trace: z-news.wcss.wroc.pl 1627733618 19391 156.17.86.1 (31 Jul 2021 12:13:38 GMT)
X-Complaints-To: abuse@news.pwr.wroc.pl
NNTP-Posting-Date: Sat, 31 Jul 2021 12:13:38 +0000 (UTC)
Cancel-Lock: sha1:mjKggqf9CBY5FFcvwa7SBSATT8s=
User-Agent: tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-10-amd64 (x86_64))
X-Received-Bytes: 7635
 by: antis...@math.uni.wroc.pl - Sat, 31 Jul 2021 12:13 UTC

Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> On 2021-07-31, antispam@math.uni.wroc.pl <antispam@math.uni.wroc.pl> wrote:
> > MitchAlsup <MitchAlsup@aol.com> wrote:
> >> On Friday, July 30, 2021 at 4:47:22 PM UTC-5, anti...@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.
> >> <
> >> I might interject at this instant, that My 66000 has this kind of
> >> behavior with its ATOMIC events (multiple word ATOMICs.)
> >> If the ATOMIC event fails to complete, control is transferred
> >> to a place where SW understands that it is no longer "IN" the
> >> ATOMIC event. Exceptions and interrupts terminate the
> >> ATOMIC event and perform said transfer of control, there are
> >> branch instructions which can conditionally transfer control
> >> out of the ATOMIC event and thus terminate it uncessfully.
> >> <
> >> One of the reason I inverted it was so that a concurrent data
> >> structure could have an element moved from one location in
> >> the CDS to another location without every being detected as
> >> "NOT IN" the CDS. Normal ATOMIC events (such as Compare
> >> double swap double) cannot perform this. This improves the
> >> invariants while reducing the number of ATOMIC events.
> >> <
> >> What I don't understand about OP's statement is when we might
> >> need such an invariant manifest when we are not also doing some-
> >> thing that needs to smell ATOMIC. Can OP expand on this ?
> >
> > Main issue are invariants expected by garbage collector. Extreme,
> > but simple case is when garbage collector runs: this is "stop
> > the world" garbage collector, so no other high-level code can
> > run during garbage collection (garbage collector is in the
> > same language, but written only using constructs that do
> > not use normal memory allocation). Garbage collector
> > is simple, because when it finishes it checks flags for
> > deferred interrupts. More typical example are function
> > prologues and epilogues: garbage collector is looking at stack
> > and needs well-formed stack frames. Once function prologue
> > is done runtime system can call high-level signal handler
> > which will build its own stack frame. When high-level
> > signal handler returns interrupted routine may continue
> > its work. But if signal handler decides to throw exception,
> > it will properly unwind stack up to corresponding handler.
> >
> > Another example is memory allocation: various data structurs
> > needs to be properly initilized before garbage collector
> > is allowed to see them.
> >
> > Yet another (quit frequent) example are derived pointers.
> > When accessing arrays generated code normally uses base + index
> > addresing mode. But in many cases it must temporarly create
> > base+index in a register. Garbage collector can only handle
> > pointers to start of an object, so garbage collection is
> > allowed only when no register contains derived pointers
> > (like base + index form). Yet another thing are temporary
> > values in registers. Garbage collector deals with tagged values
> > and pointers. Due to low bit tags garbage collector sees that
> > tagged values are not pointers and skips them. But untagged
> > (machine) integer can not appear in place when pointer can
> > appear, because garbage collector would have no way to distinguish
> > such integer from a pointer. Currently there is fixed division,
> > some register contain tagged values, some untagged ones.
> > But there are also temporary (scratch) registers which
> > may contain both tagged and untagged values. Garbage
> > collection is not allowed when a scratch register may contain
> > a pointer. Scratch register are short lived and after
> > few instructions all scratch registers are dead.
> >
> > Now, your ATIMIC construct could help, but it would be used
> > quite a lot. My guesstimate is that more than 50% of code
> > would end as member of ATIMIC section. Most section would
> > be quite short (2-5 instructions), but some would go into
> > hundreds of instructions. I a bit worried about performance
> > impact of so many ATIMICs, given that my use does not really
> > require special warranties with respect to memory (beyond
> > normal consistency between thread an interrupt handler).
> >
> >> <
> >> > So, what is needed is transfer of control to handler at
> >> > next safepoint, that is at next place where program may be
> >> > safely interrupted.
> >> <
> >> An interrupt, be definition, is asynchronous to the program.
> >> Indeed, it is foreign to the program, the program should know
> >> nothing about it except that it happened and control has
> >> returned.
> >> <
> >> Does OP really mean interrupt, here ?
> >> <
> >> Could OP mean exception instead ?
> >
> > Concretly, I have Linux signals. They are asynchonous, but
> > desired effect is that executing code sees data structures
> > modified by signal handler and signal handler may pass control
> > to different place.
>
>
> Signal handler is allowed to allocate
> > memory, so may trigger garbage collection.
>
> no it is not:
> first read man page:
> https://man7.org/linux/man-pages/man7/signal-safety.7.html

Sorry, this is irrelevant for me. This page talks about C
library but I am fine with restriction "you can not call
C library from signal handler". But you can make arbitrary
system calls, if needed making sure to bypass possible breakage
due to C library wrapping system calls. So you can call
'mmap' or 'sbrk' to allocate memory. I am talking
about signal handler in high-level language which has
its own memory allocator, using system calls if needed
but independent of C library. And the thing works now
using strategy 1) above. But the drawback is that all
code pays cost of polling and it this cost is substantial.

--
Waldek Hebisch

Re: Safepoints

<ukbNI.93033$VU3.42038@fx46.iad>

  copy mid

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

  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!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx46.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>
<954710b2-2516-49b1-9378-1bc9f82be013n@googlegroups.com>
<se29sn$dtn$1@z-news.wcss.wroc.pl> <q52NI.91902$VU3.19281@fx46.iad>
<se3epi$itv$1@z-news.wcss.wroc.pl>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 133
Message-ID: <ukbNI.93033$VU3.42038@fx46.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sat, 31 Jul 2021 12:27:06 UTC
Organization: usenet-news.net
Date: Sat, 31 Jul 2021 12:27:06 GMT
X-Received-Bytes: 7756
 by: Branimir Maksimovic - Sat, 31 Jul 2021 12:27 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, antispam@math.uni.wroc.pl <antispam@math.uni.wroc.pl> wrote:
>> > MitchAlsup <MitchAlsup@aol.com> wrote:
>> >> On Friday, July 30, 2021 at 4:47:22 PM UTC-5, anti...@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.
>> >> <
>> >> I might interject at this instant, that My 66000 has this kind of
>> >> behavior with its ATOMIC events (multiple word ATOMICs.)
>> >> If the ATOMIC event fails to complete, control is transferred
>> >> to a place where SW understands that it is no longer "IN" the
>> >> ATOMIC event. Exceptions and interrupts terminate the
>> >> ATOMIC event and perform said transfer of control, there are
>> >> branch instructions which can conditionally transfer control
>> >> out of the ATOMIC event and thus terminate it uncessfully.
>> >> <
>> >> One of the reason I inverted it was so that a concurrent data
>> >> structure could have an element moved from one location in
>> >> the CDS to another location without every being detected as
>> >> "NOT IN" the CDS. Normal ATOMIC events (such as Compare
>> >> double swap double) cannot perform this. This improves the
>> >> invariants while reducing the number of ATOMIC events.
>> >> <
>> >> What I don't understand about OP's statement is when we might
>> >> need such an invariant manifest when we are not also doing some-
>> >> thing that needs to smell ATOMIC. Can OP expand on this ?
>> >
>> > Main issue are invariants expected by garbage collector. Extreme,
>> > but simple case is when garbage collector runs: this is "stop
>> > the world" garbage collector, so no other high-level code can
>> > run during garbage collection (garbage collector is in the
>> > same language, but written only using constructs that do
>> > not use normal memory allocation). Garbage collector
>> > is simple, because when it finishes it checks flags for
>> > deferred interrupts. More typical example are function
>> > prologues and epilogues: garbage collector is looking at stack
>> > and needs well-formed stack frames. Once function prologue
>> > is done runtime system can call high-level signal handler
>> > which will build its own stack frame. When high-level
>> > signal handler returns interrupted routine may continue
>> > its work. But if signal handler decides to throw exception,
>> > it will properly unwind stack up to corresponding handler.
>> >
>> > Another example is memory allocation: various data structurs
>> > needs to be properly initilized before garbage collector
>> > is allowed to see them.
>> >
>> > Yet another (quit frequent) example are derived pointers.
>> > When accessing arrays generated code normally uses base + index
>> > addresing mode. But in many cases it must temporarly create
>> > base+index in a register. Garbage collector can only handle
>> > pointers to start of an object, so garbage collection is
>> > allowed only when no register contains derived pointers
>> > (like base + index form). Yet another thing are temporary
>> > values in registers. Garbage collector deals with tagged values
>> > and pointers. Due to low bit tags garbage collector sees that
>> > tagged values are not pointers and skips them. But untagged
>> > (machine) integer can not appear in place when pointer can
>> > appear, because garbage collector would have no way to distinguish
>> > such integer from a pointer. Currently there is fixed division,
>> > some register contain tagged values, some untagged ones.
>> > But there are also temporary (scratch) registers which
>> > may contain both tagged and untagged values. Garbage
>> > collection is not allowed when a scratch register may contain
>> > a pointer. Scratch register are short lived and after
>> > few instructions all scratch registers are dead.
>> >
>> > Now, your ATIMIC construct could help, but it would be used
>> > quite a lot. My guesstimate is that more than 50% of code
>> > would end as member of ATIMIC section. Most section would
>> > be quite short (2-5 instructions), but some would go into
>> > hundreds of instructions. I a bit worried about performance
>> > impact of so many ATIMICs, given that my use does not really
>> > require special warranties with respect to memory (beyond
>> > normal consistency between thread an interrupt handler).
>> >
>> >> <
>> >> > So, what is needed is transfer of control to handler at
>> >> > next safepoint, that is at next place where program may be
>> >> > safely interrupted.
>> >> <
>> >> An interrupt, be definition, is asynchronous to the program.
>> >> Indeed, it is foreign to the program, the program should know
>> >> nothing about it except that it happened and control has
>> >> returned.
>> >> <
>> >> Does OP really mean interrupt, here ?
>> >> <
>> >> Could OP mean exception instead ?
>> >
>> > Concretly, I have Linux signals. They are asynchonous, but
>> > desired effect is that executing code sees data structures
>> > modified by signal handler and signal handler may pass control
>> > to different place.
>>
>>
>> Signal handler is allowed to allocate
>> > memory, so may trigger garbage collection.
>>
>> no it is not:
>> first read man page:
>> https://man7.org/linux/man-pages/man7/signal-safety.7.html
>
> Sorry, this is irrelevant for me. This page talks about C
> library but I am fine with restriction "you can not call
> C library from signal handler". But you can make arbitrary
> system calls, if needed making sure to bypass possible breakage
> due to C library wrapping system calls. So you can call
> 'mmap' or 'sbrk' to allocate memory. I am talking
> about signal handler in high-level language which has
> its own memory allocator, using system calls if needed
> but independent of C library. And the thing works now
> using strategy 1) above. But the drawback is that all
> code pays cost of polling and it this cost is substantial.
>
signals and threads doesn't like each other.
If you are talking about Linux signals, that is.if you are talking
about your implementation of signals then this is misunderstanding.

--
bmaxa now listens Ob-Neob Radio

Re: Safepoints

<se3fk4$itv$2@z-news.wcss.wroc.pl>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!wsisiz.edu.pl!news.icm.edu.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 12:27:48 +0000 (UTC)
Organization: Politechnika Wroclawska
Lines: 95
Message-ID: <se3fk4$itv$2@z-news.wcss.wroc.pl>
References: <se1s18$sf$1@z-news.wcss.wroc.pl> <6l0NI.10262$yU3.3417@fx05.iad>
NNTP-Posting-Host: hera.math.uni.wroc.pl
X-Trace: z-news.wcss.wroc.pl 1627734468 19391 156.17.86.1 (31 Jul 2021 12:27:48 GMT)
X-Complaints-To: abuse@news.pwr.wroc.pl
NNTP-Posting-Date: Sat, 31 Jul 2021 12:27:48 +0000 (UTC)
Cancel-Lock: sha1:FMRVVj5n5Q0hAycQAdF+czjIzvw=
User-Agent: tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-10-amd64 (x86_64))
X-Received-Bytes: 5948
 by: antis...@math.uni.wroc.pl - Sat, 31 Jul 2021 12:27 UTC

Branimir Maksimovic <branimir.maksimovic@gmail.com> wrote:
> On 2021-07-30, antispam@math.uni.wroc.pl <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?
> >
> Signals are obsolete long ago. Now use threads and implement
> user space scheduler.

Thread does not solve core problem here, only replace one
problem by different one: how to timely exchange information
between threads.

Threads would be attractive as they open possibilty to utilize
multiple cores, but they also open big can of worms. Namely,
I deal with "interesting" mutable data structures richly
interconnected via pointers. Tracking what is thread-local
and what is (potentially) shared looks like a nightmare.
Various languages tried to offer "safe" data structures
so that one can modify them from arbitrary thread. AFAICS
there is huge performace penalty and in many cases single
threaded program runs faster than multithread one, because
single thread does not pay synchronization costs needed
for safe multithreaded use. Silly but illustrative example
is C 'getchar()': when I benchmarked it thread-safe
'getchar()' it needed something like 500 clocks per characters,
while old classic getchar can be done in about 10 clocks
(or down to 2-3 instructions if compiler optimizations
work as intended).

--
Waldek Hebisch

Re: Safepoints

<se3frm$itv$3@z-news.wcss.wroc.pl>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!fdc2.netnews.com!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!wsisiz.edu.pl!news.icm.edu.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 12:31:50 +0000 (UTC)
Organization: Politechnika Wroclawska
Lines: 84
Message-ID: <se3frm$itv$3@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>
NNTP-Posting-Host: hera.math.uni.wroc.pl
X-Trace: z-news.wcss.wroc.pl 1627734710 19391 156.17.86.1 (31 Jul 2021 12:31:50 GMT)
X-Complaints-To: abuse@news.pwr.wroc.pl
NNTP-Posting-Date: Sat, 31 Jul 2021 12:31:50 +0000 (UTC)
Cancel-Lock: sha1:eikPcOnJwm8Rq6itDzhpzcG+IbY=
User-Agent: tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-10-amd64 (x86_64))
X-Received-Bytes: 5464
 by: antis...@math.uni.wroc.pl - Sat, 31 Jul 2021 12:31 UTC

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?

--
Waldek Hebisch

Re: Safepoints

<xubNI.11311$wG6.8319@fx18.iad>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!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!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx18.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>
<6l0NI.10262$yU3.3417@fx05.iad> <se3fk4$itv$2@z-news.wcss.wroc.pl>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 116
Message-ID: <xubNI.11311$wG6.8319@fx18.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sat, 31 Jul 2021 12:37:49 UTC
Organization: usenet-news.net
Date: Sat, 31 Jul 2021 12:37:49 GMT
X-Received-Bytes: 6319
 by: Branimir Maksimovic - Sat, 31 Jul 2021 12:37 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-30, antispam@math.uni.wroc.pl <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?
>> >
>> Signals are obsolete long ago. Now use threads and implement
>> user space scheduler.
>
> Thread does not solve core problem here, only replace one
> problem by different one: how to timely exchange information
> between threads.
>
> Threads would be attractive as they open possibilty to utilize
> multiple cores, but they also open big can of worms. Namely,
> I deal with "interesting" mutable data structures richly
> interconnected via pointers. Tracking what is thread-local
> and what is (potentially) shared looks like a nightmare.
> Various languages tried to offer "safe" data structures
> so that one can modify them from arbitrary thread. AFAICS
> there is huge performace penalty and in many cases single
> threaded program runs faster than multithread one,
that is usually case with GC. forking is faster then using
threads. GC per process is faster then single GC per several
threads.

because
> single thread does not pay synchronization costs needed
> for safe multithreaded use.

ditto

Silly but illustrative example
> is C 'getchar()': when I benchmarked it thread-safe
> 'getchar()' it needed something like 500 clocks per characters,
> while old classic getchar can be done in about 10 clocks
> (or down to 2-3 instructions if compiler optimizations
> work as intended).

of course. single threaded getchar reads from stdio without
synchronization.
If you are concerned with thread performance try with forking?
Then, you don't need synchronization and can communicate by IPC.
Nowdays that is popular as they does all sort of things
to prevent threads to access shared mutable state.

>
>
Greetings, Branimir.

--
bmaxa now listens Ob-Neob Radio

Re: Safepoints

<pybNI.11312$wG6.4141@fx18.iad>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx18.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>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 90
Message-ID: <pybNI.11312$wG6.4141@fx18.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sat, 31 Jul 2021 12:41:57 UTC
Organization: usenet-news.net
Date: Sat, 31 Jul 2021 12:41:57 GMT
X-Received-Bytes: 5482
 by: Branimir Maksimovic - Sat, 31 Jul 2021 12:41 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-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.

--
bmaxa now listens Ob-Neob Radio

Re: Safepoints

<JBbNI.11313$wG6.7904@fx18.iad>

  copy mid

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

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx18.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>
User-Agent: slrn/1.0.3 (Darwin)
Lines: 93
Message-ID: <JBbNI.11313$wG6.7904@fx18.iad>
X-Complaints-To: abuse@usenet-news.net
NNTP-Posting-Date: Sat, 31 Jul 2021 12:45:29 UTC
Organization: usenet-news.net
Date: Sat, 31 Jul 2021 12:45:29 GMT
X-Received-Bytes: 5756
 by: Branimir Maksimovic - Sat, 31 Jul 2021 12:45 UTC

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.

--
bmaxa now listens Ob-Neob Radio

Pages:1234
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor