From owner-freebsd-current@FreeBSD.ORG Wed Jan 20 02:52:33 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C6672106568B; Wed, 20 Jan 2010 02:52:33 +0000 (UTC) (envelope-from okuno.kohji@jp.panasonic.com) Received: from smtp.mei.co.jp (smtp.mei.co.jp [133.183.100.20]) by mx1.freebsd.org (Postfix) with ESMTP id 572958FC17; Wed, 20 Jan 2010 02:52:32 +0000 (UTC) Received: from mail-gw.jp.panasonic.com ([157.8.1.145]) by smtp.mei.co.jp (8.12.11.20060614/3.7W/kc-maile12) with ESMTP id o0K2qV3w020582; Wed, 20 Jan 2010 11:52:31 +0900 (JST) Received: from epochmail.jp.panasonic.com (localhost [127.0.0.1]) by mail.jp.panasonic.com (8.11.6p2/3.7W/kc-maili07) with ESMTP id o0K2qXa29730; Wed, 20 Jan 2010 11:52:33 +0900 (JST) Received: by epochmail.jp.panasonic.com (8.12.11.20060308/3.7W/somla6) id o0K2qV0M028857; Wed, 20 Jan 2010 11:52:31 +0900 (JST) Received: from localhost by somla6.jp.panasonic.com (8.12.11.20060308/3.7W) with ESMTP id o0K2qPLI028626; Wed, 20 Jan 2010 11:52:25 +0900 (JST) Date: Wed, 20 Jan 2010 11:52:18 +0900 (JST) Message-Id: <20100120.115218.999284356098982813.okuno.kohji@jp.panasonic.com> To: attilio@freebsd.org From: Kohji Okuno In-Reply-To: <3bbf2fe11001190152k15c24f70k876762817bf522c1@mail.gmail.com> References: <20100119.103858.29593248145858473.okuno.kohji@jp.panasonic.com> <3bbf2fe11001190152k15c24f70k876762817bf522c1@mail.gmail.com> Organization: Panasonic Corporation X-Mailer: Mew version 6.3 on Emacs 23.1 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Cc: okuno.kohji@jp.panasonic.com, freebsd-current@freebsd.org, jroberson@jroberson.net Subject: Re: Bug about sched_4bsd? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jan 2010 02:52:33 -0000 Hello, Attilio >>> I think setpriority() can set priority to sleeping threads. >>> Is it really safe? >> >> I agree, in this code path maybe_resched is not properly locking cur= thread. >> =A0curthread will be sched_lock and the sleeping thread will be a sl= eepq lock. >> =A0I believe that since &sched_lock is ordered after container locks= it would >> be sufficient to compare the two td_lock pointers and acquire sched_= lock if >> they are not equal. =A0Someone should look at other maybe_resched ca= llers or >> add an assert that curthread->td_lock is always &sched_lock in this >> function. > = > I'm not sure I understand you well here, but I generally don't agree,= > if we speak about the current code plus the patch I posted. I understood. If the current code plus your patch, meybe_resched() is no problem. I think, your patch is perfect if theare is no problem even if a sleeping thread sets &sched_lock to td->td_lock. Why do we call thread_lock_set() in sleepq_switch() and turnstile_wait(= )? = In case of sched_4bsd, is not thread_lock_set() needed? Thank you, Kohji Okuno. > Without the patch, there is a general problem of maybe_preempt() > because sched_switch() will handle TDF_NEEDRESCHED just in racy ways > (not ensuring atomicity of td_lock operations for sleeping threads). > That's, however, still not specific to maybe_preempt() only. However:= > * If you make a problem about the callers of maybe_resched() I agree.= > The callers should assert for sched_lock to be in place. But that is > not a general problem of maybe_resched(), it is on the callers > ballpark > * If you make a problem about the locking itself, the patch IMHO > should fix it or there is still something I can't see. > = > Thanks, > Attilio > = > = > -- = > Peace can only be achieved by understanding - A. Einstein > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd= .org"