From owner-freebsd-current@FreeBSD.ORG Sat May 31 02:50:02 2014 Return-Path: Delivered-To: freebsd-current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 05FC2EA1 for ; Sat, 31 May 2014 02:50:02 +0000 (UTC) Received: from mho-02-ewr.mailhop.org (mho-02-ewr.mailhop.org [204.13.248.72]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CFC5128AB for ; Sat, 31 May 2014 02:50:01 +0000 (UTC) Received: from c-24-8-230-52.hsd1.co.comcast.net ([24.8.230.52] helo=damnhippie.dyndns.org) by mho-02-ewr.mailhop.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1WqZMn-000AEu-RZ; Sat, 31 May 2014 02:49:54 +0000 Received: from [172.22.42.240] (revolution.hippie.lan [172.22.42.240]) by damnhippie.dyndns.org (8.14.3/8.14.3) with ESMTP id s4V2npkZ004109; Fri, 30 May 2014 20:49:51 -0600 (MDT) (envelope-from ian@FreeBSD.org) X-Mail-Handler: Dyn Standard SMTP by Dyn X-Originating-IP: 24.8.230.52 X-Report-Abuse-To: abuse@dyndns.com (see http://www.dyndns.com/services/sendlabs/outbound_abuse.html for abuse reporting information) X-MHO-User: U2FsdGVkX19cy2PRXdcz7uH4uMKPChnL Subject: Re: Thread Scheduler Priority From: Ian Lepore To: Fred Pedrisa In-Reply-To: References: Content-Type: text/plain; charset="us-ascii" Date: Fri, 30 May 2014 20:49:51 -0600 Message-ID: <1401504591.20883.28.camel@revolution.hippie.lan> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit Cc: 'freebsd-current' X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18 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: Sat, 31 May 2014 02:50:02 -0000 On Thu, 2014-05-29 at 02:12 -0300, Fred Pedrisa wrote: > Hi, Guys. > > > > How can I adjust a certain thread to have the maximum system priority in the > scheduler ? > > > > I've tried doing it this way : > > > > /* Set thread priority. */ > > if > (pthread_getschedparam(ts[gnThreadID], &police, ¶m[gnThreadID]) != 0) > > { > > error > ("Unable to get priority"); > > return 1; > > } > > > param[gnThreadID].sched_priority = 99; > > if > (pthread_setschedparam(ts[gnThreadID], police, ¶m[gnThreadID]) != 0) > > { > > error("Unable to set priority"); > > return 1; > > } > > > > However, in 'top', I don't see the process threads switching to -92 > priority, like other threads in the system, is something I did wrong or > maybe I might be missing something ? You can't just set the priority to any number you want... per the man page for pthread_setschedparam() the value has to fall within the ranges returned by sched_get_priority_min() and sched_get_priority_max() for the given scheduling class. On freebsd those ranges are 0-31. I suspect from your statement of wanting "maximum system priority" maybe what you need to do is change the scheduling class from SCHED_OTHER to SCHED_RR, that should give you realtime priority. Be aware that a realtime thread that is compute-bound will take over the system (or one core on an SMP system); it will get all cycles if it is always runnable. If what you're looking for is the thread equivelent of using the nice command, so that you give a boost to a thread over other threads in the timeshare (SCHED_OTHER) scheduling class, there is currently no way to do that in freebsd. Last year for $work I about went crazy trying to figure out the mapping between pthread scheduling classes and priorities and freebsd's idea of thread prorities. I eventually gave up on the pthread API and used the freebsd native function rtprio_thread() instead. -- Ian