Bug 192926 - [patch] sched_yield is a no-op
Summary: [patch] sched_yield is a no-op
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 10.0-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-22 18:24 UTC by eric
Modified: 2014-09-06 15:31 UTC (History)
2 users (show)

See Also:


Attachments
proposed patch (716 bytes, patch)
2014-08-22 18:24 UTC, eric
no flags Details | Diff
test case (1.97 KB, text/x-c)
2014-08-22 18:24 UTC, eric
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description eric 2014-08-22 18:24:00 UTC
Created attachment 146161 [details]
proposed patch

sched_yield() is a no-op.  The thread is put back on the CPU immediately, preventing other threads from running.  ru_nvcsw gets incremented, but ktrace does not show a context switch.

This was introduced by r239157:

    http://svnweb.freebsd.org/base?view=revision&revision=r239157

I found this on 10.0-RELEASE-p7, but the same code exists in head.

I will attach a test case and patch against releng/10.0.
Comment 1 eric 2014-08-22 18:24:46 UTC
Created attachment 146162 [details]
test case
Comment 2 eric 2014-08-22 18:34:43 UTC
sched_4bsd.c would need a similar change.
Comment 3 commit-hook freebsd_committer 2014-08-23 17:32:29 UTC
A commit references this bug:

Author: mav
Date: Sat Aug 23 17:31:56 UTC 2014
New revision: 270423
URL: http://svnweb.freebsd.org/changeset/base/270423

Log:
  Restore pre-r239157 handling of sched_yield(), when thread time slice was
  aborted, allowing other threads to run.  Without this change thread is just
  rescheduled again, that was illustrated by provided test tool.

  PR:		192926
  Submitted by:	eric@vangyzen.net
  MFC after:	2 weeks

Changes:
  head/sys/kern/sched_4bsd.c
  head/sys/kern/sched_ule.c
Comment 4 Alexander Motin freebsd_committer 2014-08-23 17:34:19 UTC
I've confirmed the issue with provided test tool, and committed the proposed patch and its SCHED_4BSD counterpart to FreeBSD HEAD branch.
Comment 5 commit-hook freebsd_committer 2014-09-06 15:26:48 UTC
A commit references this bug:

Author: mav
Date: Sat Sep  6 15:26:39 UTC 2014
New revision: 271194
URL: http://svnweb.freebsd.org/changeset/base/271194

Log:
  MFC r270423:
  Restore pre-r239157 handling of sched_yield(), when thread time slice
  was aborted, allowing other threads to run.  Without this change thread
  is just rescheduled again, that was illustrated by provided test tool.

  PR:		192926
  Submitted by:	eric@vangyzen.net
  Approved by:	re (marius)

Changes:
_U  stable/10/
  stable/10/sys/kern/sched_4bsd.c
  stable/10/sys/kern/sched_ule.c
Comment 6 commit-hook freebsd_committer 2014-09-06 15:31:50 UTC
A commit references this bug:

Author: mav
Date: Sat Sep  6 15:30:58 UTC 2014
New revision: 271195
URL: http://svnweb.freebsd.org/changeset/base/271195

Log:
  MFC r270423:
  Restore pre-r239157 handling of sched_yield(), when thread time slice
  was aborted, allowing other threads to run.  Without this change thread
  is just rescheduled again, that was illustrated by provided test tool.

  PR:		192926
  Submitted by:	eric@vangyzen.net

Changes:
_U  stable/9/
_U  stable/9/sys/
  stable/9/sys/kern/sched_4bsd.c
  stable/9/sys/kern/sched_ule.c