Re: sched_userret priority adjustment patch for sched_4bsd

From: John Baldwin (jhb_at_FreeBSD.org)
Date: 09/27/04

  • Next message: Stephan Uphoff: "Re: sched_userret priority adjustment patch for sched_4bsd"
    To: freebsd-arch@FreeBSD.org
    Date: Mon, 27 Sep 2004 10:16:13 -0400
    
    

    On Saturday 25 September 2004 01:29 pm, Stephan Uphoff wrote:
    > When a thread is about to return to user space it resets its priority to
    > the user level priority.
    > However after lowering the permission its priority it needs to check if
    > its priority is still better than all other runable threads.
    > This is currently not implemented.
    > Without the check the thread can block kernel or user threads with
    > better priority until a switch is forced by by an interrupt.
    >
    > The attached patch checks the relevant runqueues and threads without
    > slots in the same ksegrp and forces a thread switch if the currently
    > running thread is no longer the best thread to run after it changed its
    > priority.
    >
    > The patch should improve interactive response under heavy load somewhat.
    > It needs a lot of testing.

    Perhaps the better fix is to teach the schedulers to set TDF_NEEDRESCHED based
    on on a comparison against user_pri rather than td_priority inside of
    sched_add()? Having the flag set by sched_add() is supposed to make this
    sort of check unnecessary. Even 4.x has the same bug I think as a process
    can make another process runnable after it's priority has been boosted by a
    tsleep() and need_resched() is only called based on a comparison of p_pri.
    Ah, 4.x doesn't have the bug because it caches the priority of curproc when
    it enters the kernel and compares against that. Thus, I think the correct
    fix is more like this:

    Index: sched_4bsd.c
    ===================================================================
    RCS file: /usr/cvs/src/sys/kern/sched_4bsd.c,v
    retrieving revision 1.63
    diff -u -r1.63 sched_4bsd.c
    --- sched_4bsd.c 11 Sep 2004 10:07:22 -0000 1.63
    +++ sched_4bsd.c 27 Sep 2004 14:12:03 -0000
    @@ -272,7 +272,7 @@
     {

            mtx_assert(&sched_lock, MA_OWNED);
    - if (td->td_priority < curthread->td_priority)
    + if (td->td_priority < curthread->td_ksegrp->kg_user_pri)
                    curthread->td_flags |= TDF_NEEDRESCHED;
     }

    Index: sched_ule.c
    ===================================================================
    RCS file: /usr/cvs/src/sys/kern/sched_ule.c,v
    retrieving revision 1.129
    diff -u -r1.129 sched_ule.c
    --- sched_ule.c 11 Sep 2004 10:07:22 -0000 1.129
    +++ sched_ule.c 27 Sep 2004 14:13:01 -0000
    @@ -723,7 +723,7 @@
             */
            pcpu = pcpu_find(cpu);
            td = pcpu->pc_curthread;
    - if (ke->ke_thread->td_priority < td->td_priority ||
    + if (ke->ke_thread->td_priority < td->td_ksegrp->kg_user_pri ||
                td == pcpu->pc_idlethread) {
                    td->td_flags |= TDF_NEEDRESCHED;
                    ipi_selected(1 << cpu, IPI_AST);

    An even better fix might be to fix td_base_pri by having it be set on kernel
    entry similar to how 4.x sets curpriority. The above fix should be
    sufficient for now, however.

    -- 
    John Baldwin <jhb@FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
    "Power Users Use the Power to Serve"  =  http://www.FreeBSD.org
    _______________________________________________
    freebsd-arch@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-arch
    To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
    

  • Next message: Stephan Uphoff: "Re: sched_userret priority adjustment patch for sched_4bsd"

    Relevant Pages

    • Re: Barclays doesnt accept spaces in surnames; which banks do?
      ... You should budget on six months to never for, what will be a low priority, software change, like this. ... There are risks involved with software changes that mean that people prefer to batch updates, to minimise the number of different versions, and there are costs, which mean only medium and high priority changes get done. ... That has violated BCP for years and I'm sure hits a lot more people than spaces in surnames, but seems to have zero priority on their fix list. ... It will be a user interface issue, rather than a deep infrastructure one, but the basic problem is that these people try to de-skill their programming staff to minimise costs, so they use relatively inexperienced people, who are not aware of all the real world gotchas and good usability practice. ...
      (uk.finance)
    • Re: NexusDB Memory Manager version 2 released
      ... Unfortunately a fix is not possible as it's a limitation in the initial design. ... The problem occures if a low priority thread is in the memory manager spinlock ...
      (borland.public.delphi.thirdpartytools.general)
    • Re: OT: Time to fix bugs?
      ... seem to fit pretty much every software project I've ever been involved ... I know where I would put the "desirable" fix times for these ... right this problem is Priority 1 so we ... bugs and create workarounds in it and access and priority to upstream ...
      (uk.rec.motorcycles)
    • Re: Compiler vs. machine issue
      ... Hey Brent relax..all the threading is coded ok. ... Just I seemed to fix the ... issue assigning different parameters (I am not talking about thread ... priority) into my code that are related to synchronization part: ...
      (borland.public.delphi.non-technical)
    • Re: [PATCH] sched: implement staircase deadline scheduler further improvements-1
      ... Fix that. ... Task expiration of higher priority tasks was not being taken into account ... #ifdef CONFIG_SMP ... priority slots from their static_prio and above. ...
      (Linux-Kernel)