From: Eli Zaretskii <eliz@gnu.org>
To: "Gerd Möllmann" <gerd.moellmann@gmail.com>
Cc: eller.helmut@gmail.com, emacs-devel@gnu.org
Subject: Re: MPS: w32 threads
Date: Sun, 05 May 2024 17:39:06 +0300 [thread overview]
Message-ID: <86y18ocohh.fsf@gnu.org> (raw)
In-Reply-To: <m2jzk88vqj.fsf@pro2.fritz.box> (message from Gerd Möllmann on Sun, 05 May 2024 11:16:04 +0200)
> From: Gerd Möllmann <gerd.moellmann@gmail.com>
> Cc: eller.helmut@gmail.com, emacs-devel@gnu.org
> Date: Sun, 05 May 2024 11:16:04 +0200
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> Let's say we made a thread_state for GUI thread. If we had that, you
> could simply call this:
>
> static struct igc_thread_list *
> thread_add (struct thread_state *ts)
> {
> mps_thr_t thr;
> mps_res_t res = mps_thread_reg (&thr, global_igc->arena);
> IGC_CHECK_RES (res);
> struct igc_thread_list *t = register_thread (global_igc, thr, ts);
> root_create_thread (t);
> create_thread_aps (&t->d);
> return t;
> }
thread_state is HUGE! Almost everything there is unneeded for the
other threads, which are not Lisp threads, they run straightforward
and quite simple C code. So I'd like to avoid that if possible, which
is why I asked all those questions.
> > While trying to think about the need for an additional arena, I took a
> > look at the relevant APIs, and became confused with what we do (or
> > don't do) in make_arena. All the keywords we add with MPS_ARGS_ADD
> > and the magic constants there -- what do they mean and what were the
> > considerations to choose them and not the others? Can some commentary
> > be added there to explain what we need to know, and maybe even mention
> > optional features we might consider in the future?
>
> What's currently there is simply the result of me reading the docs, and
> picking what I thought would be needed. I guess there are a lot of knobs
> that could be tried... That is also the case for pools, generations....
I'd appreciate if you could add at least some comments about why you
thought this stuff and not the rest.
> > Assuming we can do with the single global arena already defined,
>
> There is no need for an additional arena.
OK, thanks.
> > the MPS documentation next says that every thread's registers and
> > stack should be registered using mps_root_create_thread. But the code
> > in igc.c uses mps_root_create_thread_scanned instead, whose
> > documentation is obscure, and I cannot figure out whether to copycat
> > or do something else.
>
> The _scanned variant allows us to use our own scan method, which is
> necessary because how we represent symbols in Lisp_Objects (the NULL ==
> nil thing.)
Got it, thanks.
> > The MPS’s stack scanner needs to know how to find the cold end of the
> > part of the stack to scan. The cold end of the relevant part of the
> > stack can be found by taking the address of a local variable in the
> > function that calls the main work function of your thread. You should
> > take care to ensure that the work function is not inlined so that the
> > address is definitely in the stack frame below any potential roots.
> >
> > But in our case, the thread function is run directly by the MS-Windows
> > CreateThread API, not via an intermediate function, so the worker
> > function is effectively "inlined". So is it okay to have the cold end
> > marker be a local variable in the same thread-worker function? In
> > another place of the MPS documentation there's an example which seems
> > to answer in the positive:
> >
> > void *marker = ▮
> > mps_root_t stack_root;
> > res = mps_root_create_thread(&stack_root, arena, thread, marker);
> > if (res != MPS_RES_OK) error("Couldn't create stack root");
> >
> > Am I missing something, or could the above be at the very beginning of
> > a thread's worker function? Or do we have to define intermediary
> > functions for each thread worker?
>
> I'm not sure I have understood how that works. Is it like in pthread
> that you create a thread specifying a thread_main? And when you return
> from thread_main the thread is over?
Yes. Example:
cp->thrd = CreateThread (NULL, 64 * 1024, reader_thread, cp,
0x00010000, &id);
where reader_thread is the thread worker function. When the thread's
work is done, that function exits, and the thread exits as well.
My question is whether I can make the mps_root_create_thread call from
inside reader_thread and other similar worker functions, or do I need
to go through an intermediary, like so:
static int
worker (...)
{
void *marker = ▮
mps_root_t stack_root;
res = mps_root_create_thread(&stack_root, arena, thread, marker);
if (res != MPS_RES_OK) error("Couldn't create stack root");
return real_worker ();
}
CreateThread (..., worker, ...);
> > . igc_thread_list_push (what is it? and where defined?)
> > . igc_root_list_push (where is it defined and what does it do?)
>
> It's a very ppor man's alternative to C++ std::list, implemented with
> abominable macros, see IGC_DEFINE_LIS.
I reckon we don't need to keep the threads I'm talking about on a
list, since they don't have any specpdl pointers?
> > . create_thread_aps (what is it for?)
>
> These are allocation points for allocating from MPS. Each thread needs
> its own aps. (It wouldn't hurt to have aps, even if they are not used.)
OK, but what is each of those 4 aps for? are all of them needed for a
thread that doesn't run Lisp? I see these aps are stored in struct
igc_thread, which seems to be for Lisp threads?
> In summary, I would really recommend, if technically possible on Window,
> to set up a thread_state and use what's there in igc.c.
I'd like to avoid that, for reasons explained above.
Thanks.
next prev parent reply other threads:[~2024-05-05 14:39 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-03 8:53 MPS image cache Gerd Möllmann
2024-05-03 10:58 ` Helmut Eller
2024-05-03 11:05 ` Po Lu
2024-05-03 11:22 ` Gerd Möllmann
2024-05-03 11:43 ` Gerd Möllmann
2024-05-03 13:24 ` Gerd Möllmann
2024-05-03 17:02 ` Gerd Möllmann
2024-05-04 4:38 ` MPS: scroll-bars (was: MPS image cache) Helmut Eller
2024-05-04 5:22 ` MPS: scroll-bars Gerd Möllmann
2024-05-04 5:29 ` Gerd Möllmann
2024-05-04 5:50 ` Po Lu
2024-05-04 6:27 ` Helmut Eller
2024-05-04 6:45 ` Gerd Möllmann
2024-05-04 7:05 ` Helmut Eller
2024-05-04 7:13 ` Gerd Möllmann
2024-05-04 7:48 ` Gerd Möllmann
2024-05-04 7:09 ` Gerd Möllmann
2024-05-04 8:47 ` Eli Zaretskii
2024-05-04 9:13 ` Gerd Möllmann
2024-05-04 9:29 ` Eli Zaretskii
2024-05-04 10:04 ` Gerd Möllmann
2024-05-04 13:59 ` MPS: w32 threads Eli Zaretskii
2024-05-04 14:20 ` Gerd Möllmann
2024-05-05 8:27 ` Eli Zaretskii
2024-05-05 9:16 ` Gerd Möllmann
2024-05-05 14:39 ` Eli Zaretskii [this message]
2024-05-05 15:23 ` Gerd Möllmann
2024-05-05 15:26 ` Gerd Möllmann
2024-05-04 8:29 ` MPS: scroll-bars Po Lu
2024-05-05 4:52 ` Gerd Möllmann
2024-05-05 7:53 ` Helmut Eller
2024-05-05 8:01 ` Gerd Möllmann
2024-05-05 8:08 ` Helmut Eller
2024-05-05 16:43 ` Eli Zaretskii
2024-05-05 18:02 ` Helmut Eller
2024-05-05 18:09 ` Eli Zaretskii
2024-05-06 15:05 ` Eli Zaretskii
2024-05-06 15:53 ` Gerd Möllmann
2024-05-06 18:25 ` Eli Zaretskii
2024-05-07 6:07 ` Helmut Eller
2024-05-07 12:56 ` Eli Zaretskii
2024-05-07 16:27 ` Helmut Eller
2024-05-03 14:59 ` MPS image cache Helmut Eller
2024-05-03 15:11 ` Gerd Möllmann
2024-05-05 6:45 ` Gerd Möllmann
2024-05-05 7:02 ` Gerd Möllmann
2024-05-05 9:00 ` Eli Zaretskii
2024-05-05 9:31 ` Gerd Möllmann
2024-05-05 10:24 ` Eli Zaretskii
2024-05-05 10:36 ` Gerd Möllmann
2024-05-05 11:01 ` Eli Zaretskii
2024-05-05 12:55 ` Gerd Möllmann
2024-05-05 14:07 ` Eli Zaretskii
2024-05-05 14:32 ` Gerd Möllmann
2024-05-05 15:49 ` Eli Zaretskii
2024-05-05 16:19 ` Gerd Möllmann
2024-05-05 17:45 ` Gerd Möllmann
2024-05-05 18:04 ` Eli Zaretskii
2024-05-05 18:13 ` Eli Zaretskii
2024-05-05 18:35 ` Gerd Möllmann
2024-05-05 19:18 ` Eli Zaretskii
2024-05-05 19:57 ` Gerd Möllmann
2024-05-05 8:16 ` Helmut Eller
2024-05-05 8:42 ` Gerd Möllmann
2024-05-06 14:16 ` Helmut Eller
2024-05-06 14:28 ` Gerd Möllmann
2024-05-03 15:02 ` Helmut Eller
2024-05-04 17:51 ` Gerd Möllmann
2024-05-03 11:04 ` Eli Zaretskii
2024-05-03 11:08 ` Gerd Möllmann
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86y18ocohh.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=eller.helmut@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=gerd.moellmann@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).