From owner-svn-src-stable@FreeBSD.ORG Mon Apr 5 13:33:55 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 20A271065694; Mon, 5 Apr 2010 13:33:55 +0000 (UTC) (envelope-from rrs@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0F1EA8FC16; Mon, 5 Apr 2010 13:33:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o35DXs2d042654; Mon, 5 Apr 2010 13:33:54 GMT (envelope-from rrs@svn.freebsd.org) Received: (from rrs@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o35DXs5X042651; Mon, 5 Apr 2010 13:33:54 GMT (envelope-from rrs@svn.freebsd.org) Message-Id: <201004051333.o35DXs5X042651@svn.freebsd.org> From: Randall Stewart Date: Mon, 5 Apr 2010 13:33:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r206180 - stable/8/sys/kern X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Apr 2010 13:33:55 -0000 Author: rrs Date: Mon Apr 5 13:33:54 2010 New Revision: 206180 URL: http://svn.freebsd.org/changeset/base/206180 Log: MFC of 204670: ------------------------- sched_getparam was just plain broke for time-share processes. It did not return an error but instead just let garbage be passed back. This I fix so it actually properly translates the priority the process is at to a posix's high means more priority. I also fix it so that if the ULE scheduler has bumped it up to a realtime process you get back a sane value i.e. the highest priority (63 for time-share). sched_setscheduler() had the setting of the timeshare class priority disabled. With some notes about rejecting the posix high numbers is greater priority and use nice instead. This fix also adjusts that to work, with the cavet that a t-s process may well get bumped up or down i.e. the setscheduler() will NOT change the nice value only the current priority. I think this is reasonable considering if the user wants to play with nice then he can. At least all the posix'ish interfaces now respond sanely. ----------------------- Modified: stable/8/sys/kern/kern_resource.c stable/8/sys/kern/ksched.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/kern/kern_resource.c ============================================================================== --- stable/8/sys/kern/kern_resource.c Mon Apr 5 11:00:21 2010 (r206179) +++ stable/8/sys/kern/kern_resource.c Mon Apr 5 13:33:54 2010 (r206180) @@ -471,14 +471,20 @@ rtp_to_pri(struct rtprio *rtp, struct th u_char newpri; u_char oldpri; - if (rtp->prio > RTP_PRIO_MAX) - return (EINVAL); thread_lock(td); switch (RTP_PRIO_BASE(rtp->type)) { case RTP_PRIO_REALTIME: + if (rtp->prio > RTP_PRIO_MAX) { + thread_unlock(td); + return (EINVAL); + } newpri = PRI_MIN_REALTIME + rtp->prio; break; case RTP_PRIO_NORMAL: + if (rtp->prio > (PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE)) { + thread_unlock(td); + return (EINVAL); + } newpri = PRI_MIN_TIMESHARE + rtp->prio; break; case RTP_PRIO_IDLE: Modified: stable/8/sys/kern/ksched.c ============================================================================== --- stable/8/sys/kern/ksched.c Mon Apr 5 11:00:21 2010 (r206179) +++ stable/8/sys/kern/ksched.c Mon Apr 5 13:33:54 2010 (r206180) @@ -81,9 +81,8 @@ ksched_detach(struct ksched *ks) * higher priority. It also permits sched_setparam to be * implementation defined for SCHED_OTHER. I don't like * the notion of inverted priorites for normal processes when - * you can use "setpriority" for that. + * you can use "setpriority" for that. * - * I'm rejecting sched_setparam for SCHED_OTHER with EINVAL. */ /* Macros to convert between the unix (lower numerically is higher priority) @@ -93,6 +92,9 @@ ksched_detach(struct ksched *ks) #define p4prio_to_rtpprio(P) (RTP_PRIO_MAX - (P)) #define rtpprio_to_p4prio(P) (RTP_PRIO_MAX - (P)) +#define p4prio_to_tsprio(P) ((PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE) - (P)) +#define tsprio_to_p4prio(P) ((PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE) - (P)) + /* These improve readability a bit for me: */ #define P1B_PRIO_MIN rtpprio_to_p4prio(RTP_PRIO_MAX) @@ -134,9 +136,6 @@ ksched_setparam(struct ksched *ksched, if (e == 0) { - if (policy == SCHED_OTHER) - e = EINVAL; - else e = ksched_setscheduler(ksched, td, policy, param); } @@ -152,7 +151,16 @@ ksched_getparam(struct ksched *ksched, pri_to_rtp(td, &rtp); if (RTP_PRIO_IS_REALTIME(rtp.type)) param->sched_priority = rtpprio_to_p4prio(rtp.prio); - + else { + if (PRI_MIN_TIMESHARE < rtp.prio) + /* + * The interactive score has it to min realtime + * so we must show max (64 most likely + */ + param->sched_priority = (PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE); + else + param->sched_priority = tsprio_to_p4prio(rtp.prio); + } return 0; } @@ -191,11 +199,14 @@ ksched_setscheduler(struct ksched *ksche break; case SCHED_OTHER: - { + if (param->sched_priority >= 0 && + param->sched_priority <= (PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE)) { rtp.type = RTP_PRIO_NORMAL; rtp.prio = p4prio_to_rtpprio(param->sched_priority); rtp_to_pri(&rtp, td); - } + } else + e = EINVAL; + break; default: