9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Creating a custom jmp_buf; libthread implementation question
@ 2006-11-14  3:23 Joel Salomon
  2006-11-14  3:33 ` Joel Salomon
  2006-11-14  5:44 ` [9fans] Skip Tavakkolian
  0 siblings, 2 replies; 13+ messages in thread
From: Joel Salomon @ 2006-11-14  3:23 UTC (permalink / raw)
  To: 9fans

For my next homework in my Operating Systems class, the professor has
assigned the equivalent of a simple libthread.  I’ve been looking
through the libthread code and getting lost ☹.  I don’t need procs,
only threads (except for the oh-so-fun complication of user-level
pre-emptive scheduling, but I can worry about that mañana).  I do,
however, need to create per-thread stacks, probably by massaging
jmp_bufs in malloc()ed memory.

Where in libthread does the stack get set up, and could somebody
please give me a high-level overview of what the code is doing?

Thanks, --Joel



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Creating a custom jmp_buf; libthread implementation question
  2006-11-14  3:23 [9fans] Creating a custom jmp_buf; libthread implementation question Joel Salomon
@ 2006-11-14  3:33 ` Joel Salomon
  2006-11-14  9:39   ` Bruce Ellis
  2006-11-14  9:58   ` Gorka guardiola
  2006-11-14  5:44 ` [9fans] Skip Tavakkolian
  1 sibling, 2 replies; 13+ messages in thread
From: Joel Salomon @ 2006-11-14  3:33 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> Where in libthread does the stack get set up, and could somebody
> please give me a high-level overview of what the code is doing?

Specifically, in create.c, what is newthread doing—and how?  Unless
that is the wrong place to look, in which case I really am lost.

--Joel

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans]
  2006-11-14  3:23 [9fans] Creating a custom jmp_buf; libthread implementation question Joel Salomon
  2006-11-14  3:33 ` Joel Salomon
@ 2006-11-14  5:44 ` Skip Tavakkolian
  1 sibling, 0 replies; 13+ messages in thread
From: Skip Tavakkolian @ 2006-11-14  5:44 UTC (permalink / raw)
  To: 9fans

> I’ve been looking
> through the libthread code and getting lost ☹.

might want to also checkout Russ' libtask (at swtch.com).



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Creating a custom jmp_buf; libthread implementation question
  2006-11-14  3:33 ` Joel Salomon
@ 2006-11-14  9:39   ` Bruce Ellis
  2006-11-14 12:34     ` Russ Cox
  2006-11-14  9:58   ` Gorka guardiola
  1 sibling, 1 reply; 13+ messages in thread
From: Bruce Ellis @ 2006-11-14  9:39 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

I think you are lost, and not many people want to do your homework.

brucee

On 11/14/06, Joel Salomon <joelcsalomon@gmail.com> wrote:
> > Where in libthread does the stack get set up, and could somebody
> > please give me a high-level overview of what the code is doing?
>
> Specifically, in create.c, what is newthread doing—and how?  Unless
> that is the wrong place to look, in which case I really am lost.
>
> --Joel
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Creating a custom jmp_buf; libthread implementation question
  2006-11-14  3:33 ` Joel Salomon
  2006-11-14  9:39   ` Bruce Ellis
@ 2006-11-14  9:58   ` Gorka guardiola
  2006-11-14 16:25     ` Joel Salomon
  1 sibling, 1 reply; 13+ messages in thread
From: Gorka guardiola @ 2006-11-14  9:58 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Take a look at the implementation of set_jmp and long_jmp in assembler.
Take a look also at the messages about the stack I originated in
9fans not very long (a year?) ago. Once you understand how the stack
works, things should be smoother.

On 11/14/06, Joel Salomon <joelcsalomon@gmail.com> wrote:
> > Where in libthread does the stack get set up, and could somebody
> > please give me a high-level overview of what the code is doing?
>
> Specifically, in create.c, what is newthread doing—and how?  Unless
> that is the wrong place to look, in which case I really am lost.
>
> --Joel
>


-- 
- curiosity sKilled the cat


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Creating a custom jmp_buf; libthread implementation question
  2006-11-14  9:39   ` Bruce Ellis
@ 2006-11-14 12:34     ` Russ Cox
  2006-11-14 16:15       ` Joel Salomon
  2006-11-21  3:03       ` Joel Salomon
  0 siblings, 2 replies; 13+ messages in thread
From: Russ Cox @ 2006-11-14 12:34 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Newthread is creating a bunch of data structures.
You really care about _threadinitstack (386.c) and setjmp(2).
"tos" means top of stack.

Russ


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Creating a custom jmp_buf; libthread implementation question
  2006-11-14 12:34     ` Russ Cox
@ 2006-11-14 16:15       ` Joel Salomon
  2006-11-21  3:03       ` Joel Salomon
  1 sibling, 0 replies; 13+ messages in thread
From: Joel Salomon @ 2006-11-14 16:15 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> You really care about _threadinitstack (386.c) and setjmp(2).
> "tos" means top of stack.

That's what I was looking for; thanks.

--Joel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Creating a custom jmp_buf; libthread implementation question
  2006-11-14  9:58   ` Gorka guardiola
@ 2006-11-14 16:25     ` Joel Salomon
  2006-11-14 16:38       ` Joel Salomon
  0 siblings, 1 reply; 13+ messages in thread
From: Joel Salomon @ 2006-11-14 16:25 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 11/14/06, Gorka guardiola <paurea@gmail.com> wrote:
> Take a look also at the messages about the stack I originated in
> 9fans not very long (a year?) ago. Once you understand how the stack
> works, things should be smoother.

Found it: <http://9fans.net/archive/2006/03/75>, and am printing the
thread for reference.

Reminder to self: reread /sys/doc/compiler.ps regarding stack growth direction.

--Joel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Creating a custom jmp_buf; libthread implementation question
  2006-11-14 16:25     ` Joel Salomon
@ 2006-11-14 16:38       ` Joel Salomon
  2006-11-14 19:44         ` Taj Khattra
  0 siblings, 1 reply; 13+ messages in thread
From: Joel Salomon @ 2006-11-14 16:38 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 11/14/06, Skip Tavakkolian <9nut@9netics.com> wrote:
> might want to also checkout Russ' libtask (at swtch.com).

That'll be more useful later, when I'm working on the scheduling.  I
was asking about stack creation though; my professor gave us sample
code for use under Linux (very similar to libtask's) and I wanted
pointers on how to translate that to Plan 9.

The final project won't much look like a back-ported libtask, though;
it'll be a bastardized uniprocessor kernel.  Good learning project,
but not of general use.

Thanks for the pointers,
--Joel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Creating a custom jmp_buf; libthread implementation question
  2006-11-14 16:38       ` Joel Salomon
@ 2006-11-14 19:44         ` Taj Khattra
  0 siblings, 0 replies; 13+ messages in thread
From: Taj Khattra @ 2006-11-14 19:44 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> might want to also checkout Russ' libtask (at swtch.com).

another one is the implementation of the Thread, Sem and Chan
interfaces in dave hanson's cii
(http://www.cs.princeton.edu/software/cii/).  chapter 20 has the gory
details.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Creating a custom jmp_buf; libthread implementation question
  2006-11-21  3:03       ` Joel Salomon
@ 2006-11-21  3:03         ` William Josephson
  2006-11-21  3:08         ` Russ Cox
  1 sibling, 0 replies; 13+ messages in thread
From: William Josephson @ 2006-11-21  3:03 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Mon, Nov 20, 2006 at 10:03:09PM -0500, Joel Salomon wrote:
> On 11/14/06, Russ Cox <rsc@swtch.com> wrote:
> >You really care about _threadinitstack (386.c) and setjmp(2).
> >"tos" means top of stack.
>
> What does the line
>        tos = (ulong*)&t->stk[t->stksize&~7];
> specifically stksize&~7, mean?

Um.  It means just what it says :-) I.e. round
down to the nearest multiple of 8 by clearing
the low three bits.  Recall which way the stack
grows on IA-32...


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Creating a custom jmp_buf; libthread implementation question
  2006-11-14 12:34     ` Russ Cox
  2006-11-14 16:15       ` Joel Salomon
@ 2006-11-21  3:03       ` Joel Salomon
  2006-11-21  3:03         ` William Josephson
  2006-11-21  3:08         ` Russ Cox
  1 sibling, 2 replies; 13+ messages in thread
From: Joel Salomon @ 2006-11-21  3:03 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 11/14/06, Russ Cox <rsc@swtch.com> wrote:
> You really care about _threadinitstack (386.c) and setjmp(2).
> "tos" means top of stack.

What does the line
        tos = (ulong*)&t->stk[t->stksize&~7];
specifically stksize&~7, mean?

--Joel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Creating a custom jmp_buf; libthread implementation question
  2006-11-21  3:03       ` Joel Salomon
  2006-11-21  3:03         ` William Josephson
@ 2006-11-21  3:08         ` Russ Cox
  1 sibling, 0 replies; 13+ messages in thread
From: Russ Cox @ 2006-11-21  3:08 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

>         tos = (ulong*)&t->stk[t->stksize&~7];

t->stksize&~7 is the bit-fiddly yet idiomatic way
to round stksize down to a multiple of 8.
Since t->stk is 8-aligned already, this makes
sure that tos is 8-aligned.

Russ


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2006-11-21  3:08 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-14  3:23 [9fans] Creating a custom jmp_buf; libthread implementation question Joel Salomon
2006-11-14  3:33 ` Joel Salomon
2006-11-14  9:39   ` Bruce Ellis
2006-11-14 12:34     ` Russ Cox
2006-11-14 16:15       ` Joel Salomon
2006-11-21  3:03       ` Joel Salomon
2006-11-21  3:03         ` William Josephson
2006-11-21  3:08         ` Russ Cox
2006-11-14  9:58   ` Gorka guardiola
2006-11-14 16:25     ` Joel Salomon
2006-11-14 16:38       ` Joel Salomon
2006-11-14 19:44         ` Taj Khattra
2006-11-14  5:44 ` [9fans] Skip Tavakkolian

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).