9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Aram Hăvărneanu" <aram.h@mgk.ro>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] extern register
Date: Sat, 19 Jul 2014 17:53:35 +0200	[thread overview]
Message-ID: <CAEAzY3-FGc0O1QZZLDd_EMWtALqtAmGLMX-0RvF=WyopHY+sSQ@mail.gmail.com> (raw)
In-Reply-To: <dd75a0ce30b5a07e1dde7c234ed8e4f8@ladd.quanstro.net>

On Sat, Jul 19, 2014 at 4:55 PM, erik quanstrom <quanstro@quanstro.net> wrote:
> does anyone have a use case for extern register in user space?

Well Go uses it, but the meaning is different than in the Plan 9
kernel; they reused it for a different storage class.

In Go, there were two external register variables, g and m (now
there is only one for reasons outside the scope of this discussion).
These variables are proc-local as oposed to mach-local. To make a
streched analogy, a proc is to Go as a mach is to the kernel. Both
are some "entities" which can "run" other schedulable entities (Go
now has g's, m's, and p's, so the analogy no longer holds, but that
was the original meaning).

On arm, these variables are kept in registers on all operating
systems. On 386 and amd64, non-Plan 9 systems use a form of TLS to
keep these variables. TLS usually requires libc.so and ld.so
interaction (ugh), so since Go doesn't usually use these, it usually
executes some system call which sets up the base segment registers
to some heap-allocated memory, and then accesses this space using
the segment registers.

On systems which don't have these special system calls, the base
registers are usually initialized by the kernel/libc.so/ld.so with
enough space for some slots, so the access is the same, only without
initialization.

Plan 9 has no such nonsense; the stack is at a fixed, and known
address, so these variables can be kept on the stack. I recently
simplified this for the plan9/386 Go port and made the plan9/amd64
Go port use the same mechanism.

-- 
Aram Hăvărneanu



  reply	other threads:[~2014-07-19 15:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-19  1:57 cinap_lenrek
2014-07-19  2:04 ` erik quanstrom
2014-07-19  2:19   ` erik quanstrom
2014-07-19  2:33     ` cinap_lenrek
2014-07-19  2:37       ` erik quanstrom
2014-07-19  2:27   ` cinap_lenrek
2014-07-19  2:41     ` erik quanstrom
2014-07-19 12:29 ` Aram Hăvărneanu
2014-07-19 12:42 ` Charles Forsyth
2014-07-19 14:38   ` Aram Hăvărneanu
2014-07-19 14:55     ` erik quanstrom
2014-07-19 15:53       ` Aram Hăvărneanu [this message]
2014-07-20  1:42   ` cinap_lenrek
2014-07-20 10:12     ` Aram Hăvărneanu
2014-07-20 16:35       ` cinap_lenrek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEAzY3-FGc0O1QZZLDd_EMWtALqtAmGLMX-0RvF=WyopHY+sSQ@mail.gmail.com' \
    --to=aram.h@mgk.ro \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).