aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/sched.h
diff options
context:
space:
mode:
authorAttilio Rao <attilio@FreeBSD.org>2012-10-29 01:35:17 +0000
committerAttilio Rao <attilio@FreeBSD.org>2012-10-29 01:35:17 +0000
commitd6073f06270244e1297d75296876449972e219c7 (patch)
tree7150f24090cbf237b554cb551a0613d376ae789b /sys/sys/sched.h
parent1f51baaa92071c58c85b858b384e8bcb2ae23285 (diff)
downloadsrc-d6073f06270244e1297d75296876449972e219c7.tar.gz
src-d6073f06270244e1297d75296876449972e219c7.zip
Compiler have a precise knowledge of the content of sched_pin() and
sched_unpin() as they are functions static and inline. This way it can do two dangerous things: - Reorder instructions around both of them, taking out from the safe path operations that are supposed to be (ie. per-cpu accesses) - Cache the value of td_pinned in CPU registers not making visible in kernel context to the scheduler once it is scanning the runqueue, as td_pinned is not marked volatile. In order to avoid both possible bugs explicitly, protect the safe path with compiler memory barriers. This will prevent reordering and caching by the compiler about td_pinned operations. Generally this could lead to suboptimal code traversing the pinnings but this is not the case as can be easilly verified: http://lists.freebsd.org/pipermail/svn-src-projects/2012-October/005797.html Discussed with: jeff, jhb MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=242274
Diffstat (limited to 'sys/sys/sched.h')
-rw-r--r--sys/sys/sched.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/sys/sys/sched.h b/sys/sys/sched.h
index b15104eae032..bfd8522cedc0 100644
--- a/sys/sys/sched.h
+++ b/sys/sys/sched.h
@@ -151,11 +151,13 @@ static __inline void
sched_pin(void)
{
curthread->td_pinned++;
+ __compiler_membar();
}
static __inline void
sched_unpin(void)
{
+ __compiler_membar();
curthread->td_pinned--;
}