From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 6 09:28:52 2006 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6CD6A16A420 for ; Mon, 6 Mar 2006 09:28:52 +0000 (GMT) (envelope-from simon@comsys.ntu-kpi.kiev.ua) Received: from comsys.ntu-kpi.kiev.ua (comsys.ntu-kpi.kiev.ua [195.245.194.142]) by mx1.FreeBSD.org (Postfix) with ESMTP id B01A043D48 for ; Mon, 6 Mar 2006 09:28:38 +0000 (GMT) (envelope-from simon@comsys.ntu-kpi.kiev.ua) Received: from pm513-1.comsys.ntu-kpi.kiev.ua (pm513-1.comsys.ntu-kpi.kiev.ua [10.18.52.101]) (authenticated bits=0) by comsys.ntu-kpi.kiev.ua (8.12.10/8.12.10) with ESMTP id k269fOVO040128 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 6 Mar 2006 11:41:28 +0200 (EET) Received: by pm513-1.comsys.ntu-kpi.kiev.ua (Postfix, from userid 1001) id EE4415C023; Mon, 6 Mar 2006 11:28:28 +0200 (EET) Date: Mon, 6 Mar 2006 11:28:28 +0200 From: Andrey Simonenko To: Divacky Roman Message-ID: <20060306092828.GA768@pm513-1.comsys.ntu-kpi.kiev.ua> References: <20060304171123.GA37661@stud.fit.vutbr.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060304171123.GA37661@stud.fit.vutbr.cz> User-Agent: Mutt/1.5.11 X-Spam-Status: No, score=-4.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.0.1 X-Spam-Checker-Version: SpamAssassin 3.0.1 (2004-10-22) on comsys.ntu-kpi.kiev.ua X-Virus-Scanned: ClamAV 0.82/1314/Sat Mar 4 15:39:05 2006 on comsys.ntu-kpi.kiev.ua X-Virus-Status: Clean Cc: hackers@freebsd.org Subject: Re: sched_newthread question X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Mar 2006 09:28:52 -0000 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.