]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - kernel/time/timekeeping.c
Merge tag 'kvm-3.8-1' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[karo-tx-linux.git] / kernel / time / timekeeping.c
index 4c7de02eacdce9875cefb7598d5047b95f235770..cbc6acb0db3fafbaa4830da34cdb22e538892764 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/time.h>
 #include <linux/tick.h>
 #include <linux/stop_machine.h>
+#include <linux/pvclock_gtod.h>
 
 
 static struct timekeeper timekeeper;
@@ -174,6 +175,54 @@ static inline s64 timekeeping_get_ns_raw(struct timekeeper *tk)
        return nsec + arch_gettimeoffset();
 }
 
+static RAW_NOTIFIER_HEAD(pvclock_gtod_chain);
+
+static void update_pvclock_gtod(struct timekeeper *tk)
+{
+       raw_notifier_call_chain(&pvclock_gtod_chain, 0, tk);
+}
+
+/**
+ * pvclock_gtod_register_notifier - register a pvclock timedata update listener
+ *
+ * Must hold write on timekeeper.lock
+ */
+int pvclock_gtod_register_notifier(struct notifier_block *nb)
+{
+       struct timekeeper *tk = &timekeeper;
+       unsigned long flags;
+       int ret;
+
+       write_seqlock_irqsave(&tk->lock, flags);
+       ret = raw_notifier_chain_register(&pvclock_gtod_chain, nb);
+       /* update timekeeping data */
+       update_pvclock_gtod(tk);
+       write_sequnlock_irqrestore(&tk->lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(pvclock_gtod_register_notifier);
+
+/**
+ * pvclock_gtod_unregister_notifier - unregister a pvclock
+ * timedata update listener
+ *
+ * Must hold write on timekeeper.lock
+ */
+int pvclock_gtod_unregister_notifier(struct notifier_block *nb)
+{
+       struct timekeeper *tk = &timekeeper;
+       unsigned long flags;
+       int ret;
+
+       write_seqlock_irqsave(&tk->lock, flags);
+       ret = raw_notifier_chain_unregister(&pvclock_gtod_chain, nb);
+       write_sequnlock_irqrestore(&tk->lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(pvclock_gtod_unregister_notifier);
+
 /* must hold write on timekeeper.lock */
 static void timekeeping_update(struct timekeeper *tk, bool clearntp)
 {
@@ -182,6 +231,7 @@ static void timekeeping_update(struct timekeeper *tk, bool clearntp)
                ntp_clear();
        }
        update_vsyscall(tk);
+       update_pvclock_gtod(tk);
 }
 
 /**