]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - include/linux/freezer.h
freezer: add missing mb's to freezer_count() and freezer_should_skip()
[karo-tx-linux.git] / include / linux / freezer.h
index d09af4b67cf121ad91fd4ca02bec01560b6110fd..ee899329e65a6e43320ddfbedd38f427f6d39125 100644 (file)
@@ -75,28 +75,62 @@ static inline bool cgroup_freezing(struct task_struct *task)
  */
 
 
-/* Tell the freezer not to count the current task as freezable. */
+/**
+ * freezer_do_not_count - tell freezer to ignore %current
+ *
+ * Tell freezers to ignore the current task when determining whether the
+ * target frozen state is reached.  IOW, the current task will be
+ * considered frozen enough by freezers.
+ *
+ * The caller shouldn't do anything which isn't allowed for a frozen task
+ * until freezer_cont() is called.  Usually, freezer[_do_not]_count() pair
+ * wrap a scheduling operation and nothing much else.
+ */
 static inline void freezer_do_not_count(void)
 {
        current->flags |= PF_FREEZER_SKIP;
 }
 
-/*
- * Tell the freezer to count the current task as freezable again and try to
- * freeze it.
+/**
+ * freezer_count - tell freezer to stop ignoring %current
+ *
+ * Undo freezer_do_not_count().  It tells freezers that %current should be
+ * considered again and tries to freeze if freezing condition is already in
+ * effect.
  */
 static inline void freezer_count(void)
 {
        current->flags &= ~PF_FREEZER_SKIP;
+       /*
+        * If freezing is in progress, the following paired with smp_mb()
+        * in freezer_should_skip() ensures that either we see %true
+        * freezing() or freezer_should_skip() sees !PF_FREEZER_SKIP.
+        */
+       smp_mb();
        try_to_freeze();
 }
 
-/*
- * Check if the task should be counted as freezable by the freezer
+/**
+ * freezer_should_skip - whether to skip a task when determining frozen
+ *                      state is reached
+ * @p: task in quesion
+ *
+ * This function is used by freezers after establishing %true freezing() to
+ * test whether a task should be skipped when determining the target frozen
+ * state is reached.  IOW, if this function returns %true, @p is considered
+ * frozen enough.
  */
-static inline int freezer_should_skip(struct task_struct *p)
+static inline bool freezer_should_skip(struct task_struct *p)
 {
-       return !!(p->flags & PF_FREEZER_SKIP);
+       /*
+        * The following smp_mb() paired with the one in freezer_count()
+        * ensures that either freezer_count() sees %true freezing() or we
+        * see cleared %PF_FREEZER_SKIP and return %false.  This makes it
+        * impossible for a task to slip frozen state testing after
+        * clearing %PF_FREEZER_SKIP.
+        */
+       smp_mb();
+       return p->flags & PF_FREEZER_SKIP;
 }
 
 /*