Author: markj
Date: Thu Jan 23 16:24:51 2020
New Revision: 357050
URL: https://svnweb.freebsd.org/changeset/base/357050

Log:
  Set td_oncpu before dropping the thread lock during a switch.
  
  After r355784 we no longer hold a thread's thread lock when switching it
  out.  Preserve the previous synchronization protocol for td_oncpu by
  setting it together with td_state, before dropping the thread lock
  during a switch.
  
  Reported and tested by:       pho
  Reviewed by:  kib
  Discussed with:       jeff
  Differential Revision:        https://reviews.freebsd.org/D23270

Modified:
  head/sys/kern/sched_ule.c

Modified: head/sys/kern/sched_ule.c
==============================================================================
--- head/sys/kern/sched_ule.c   Thu Jan 23 16:10:38 2020        (r357049)
+++ head/sys/kern/sched_ule.c   Thu Jan 23 16:24:51 2020        (r357050)
@@ -2121,6 +2121,7 @@ sched_switch(struct thread *td, int flags)
         */
        TDQ_LOCK_ASSERT(tdq, MA_OWNED | MA_NOTRECURSED);
        newtd = choosethread();
+       newtd->td_oncpu = cpuid;
        sched_pctcpu_update(td_get_sched(newtd), 0);
        TDQ_UNLOCK(tdq);
 
@@ -2145,7 +2146,6 @@ sched_switch(struct thread *td, int flags)
 #endif
                td->td_oncpu = NOCPU;
                cpu_switch(td, newtd, mtx);
-               cpuid = td->td_oncpu = PCPU_GET(cpuid);
 
                SDT_PROBE0(sched, , , on__cpu);
 #ifdef HWPMC_HOOKS
@@ -2915,6 +2915,7 @@ sched_throw(struct thread *td)
                thread_lock_block(td);
        }
        newtd = choosethread();
+       newtd->td_oncpu = PCPU_GET(cpuid);
        spinlock_enter();
        TDQ_UNLOCK(tdq);
        KASSERT(curthread->td_md.md_spinlock_count == 1,
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to