From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753271AbdHBO7P (ORCPT ); Wed, 2 Aug 2017 10:59:15 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:48873 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752433AbdHBO7N (ORCPT ); Wed, 2 Aug 2017 10:59:13 -0400 From: Denis Plotnikov To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org, john.stultz@linaro.org, tglx@linutronix.de Cc: mingo@redhat.com, hpa@zytor.com, linux-kernel@vger.kernel.org, x86@kernel.org, rkagan@virtuozzo.com, den@virtuozzo.com Subject: [PATCH v4 06/10] timekeeper: add clocksource change notifier Date: Wed, 2 Aug 2017 17:38:06 +0300 Message-Id: <1501684690-211093-7-git-send-email-dplotnikov@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1501684690-211093-1-git-send-email-dplotnikov@virtuozzo.com> References: <1501684690-211093-1-git-send-email-dplotnikov@virtuozzo.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This notifier will fire when clocksource is changed or any properties of the clocksource are changed which alter the clocksource critical properties, e.g clocksource stability. It will be used in updating the KVM masterclock with the help of timekeeper because it's the very moment to notify KVM about critical changes happened in the underlying timekeeper. This is a final related to the timekeeper patch of the work aiming to move to a more simple scheme of masterclock related values calculation in KVM. Signed-off-by: Denis Plotnikov --- include/linux/cs_notifier.h | 17 +++++++++++++++ kernel/time/timekeeping.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 include/linux/cs_notifier.h diff --git a/include/linux/cs_notifier.h b/include/linux/cs_notifier.h new file mode 100644 index 0000000..2b1b4e6 --- /dev/null +++ b/include/linux/cs_notifier.h @@ -0,0 +1,17 @@ +#ifndef _CS_CHANGES_H +#define _CS_CHANGES_H + +#include + +/* + * The clocksource changes notifier is called when the system + * clocksource is changed or some properties of the current + * system clocksource is changed that can affect other parts of the system, + * for example KVM guests + */ + +extern void clocksource_changes_notify(void); +extern int clocksource_changes_register_notifier(struct notifier_block *nb); +extern int clocksource_changes_unregister_notifier(struct notifier_block *nb); + +#endif /* _CS_CHANGES_H */ diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index d1aa575..c9dad8a 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -596,6 +596,55 @@ int pvclock_gtod_unregister_notifier(struct notifier_block *nb) } EXPORT_SYMBOL_GPL(pvclock_gtod_unregister_notifier); +/* notification chain when there is some changes in the clocksource */ +static RAW_NOTIFIER_HEAD(clocksource_changes_chain); + +/** + * notify_clocksource_changing - notify all the listeners about changes + * happened in the clocksource: changing a clocksource, changing the sensitive + * parameters of the clocksource, e.g. stability flag for kvmclock + */ +void clocksource_changes_notify(void) +{ + raw_notifier_call_chain(&clocksource_changes_chain, 0L, NULL); +} +EXPORT_SYMBOL_GPL(clocksource_changes_notify); + +/** + * clocksource_changes_register_notifier - register + * a clocksource changes listener + */ +int clocksource_changes_register_notifier(struct notifier_block *nb) +{ + unsigned long flags; + int ret; + + raw_spin_lock_irqsave(&timekeeper_lock, flags); + ret = raw_notifier_chain_register(&clocksource_changes_chain, nb); + clocksource_changes_notify(); + raw_spin_unlock_irqrestore(&timekeeper_lock, flags); + + return ret; +} +EXPORT_SYMBOL_GPL(clocksource_changes_register_notifier); + +/** + * clocksource_changes_unregister_notifier - unregister + * a clocksource changes listener + */ +int clocksource_changes_unregister_notifier(struct notifier_block *nb) +{ + unsigned long flags; + int ret; + + raw_spin_lock_irqsave(&timekeeper_lock, flags); + ret = raw_notifier_chain_unregister(&clocksource_changes_chain, nb); + raw_spin_unlock_irqrestore(&timekeeper_lock, flags); + + return ret; +} +EXPORT_SYMBOL_GPL(clocksource_changes_unregister_notifier); + /* * tk_update_leap_state - helper to update the next_leap_ktime */ @@ -1363,6 +1412,7 @@ static int change_clocksource(void *data) } } timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET); + clocksource_changes_notify(); write_seqcount_end(&tk_core.seq); raw_spin_unlock_irqrestore(&timekeeper_lock, flags); @@ -1540,6 +1590,7 @@ void __init timekeeping_init(void) tk_set_wall_to_mono(tk, tmp); timekeeping_update(tk, TK_MIRROR | TK_CLOCK_WAS_SET); + clocksource_changes_notify(); write_seqcount_end(&tk_core.seq); raw_spin_unlock_irqrestore(&timekeeper_lock, flags); -- 2.7.4