sched_newthread question
Andrey Simonenko
simon at comsys.ntu-kpi.kiev.ua
Mon Mar 6 01:28:52 PST 2006
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.
More information about the freebsd-hackers
mailing list