Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Mar 2006 11:28:28 +0200
From:      Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
To:        Divacky Roman <xdivac02@stud.fit.vutbr.cz>
Cc:        hackers@freebsd.org
Subject:   Re: sched_newthread question
Message-ID:  <20060306092828.GA768@pm513-1.comsys.ntu-kpi.kiev.ua>
In-Reply-To: <20060304171123.GA37661@stud.fit.vutbr.cz>
References:  <20060304171123.GA37661@stud.fit.vutbr.cz>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Mar 04, 2006 at 06:11:24PM +0100, Divacky Roman wrote:
> hi,
> 
> sched_newthread(struct thread *td)
> {
>            struct td_sched *ke;
> 
> 	ke = (struct td_sched *) (td + 1);
> 	bzero(ke, sizeof(*ke));
> 	td->td_sched     = ke;
> 	ke->ke_thread   = td;
> 	ke->ke_state    = KES_THREAD;
> }
> 
> whats the logic behind:
> ke = (struct td_sched *) (td + 1); ? 
> 
> shouldnt it be:
> ke = td -> td_sched; ?
> 

This function does exactly as the comment for it describes.
When memory is allocated for struct thread{}, then this
memory consists of two parts, one part is for struct thread{}
and next part is scheduler specific structure for this thread.

To get pointer to that scheduler specific data it is necessary
to point to the next byte after struct thread{}.  For more
detail information see how thread_zone is created and what the
sched_sizeof_thread() function returns for each scheduler.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060306092828.GA768>