From patchwork Sat Jul 29 12:35:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Plotnikov X-Patchwork-Id: 9869927 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 724E26038F for ; Sat, 29 Jul 2017 12:36:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B6FE28879 for ; Sat, 29 Jul 2017 12:36:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50657288B5; Sat, 29 Jul 2017 12:36:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2998628885 for ; Sat, 29 Jul 2017 12:36:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753754AbdG2Mf6 (ORCPT ); Sat, 29 Jul 2017 08:35:58 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:33657 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753720AbdG2Mf5 (ORCPT ); Sat, 29 Jul 2017 08:35:57 -0400 Received: from dptest2.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v6TCZfRr013516; Sat, 29 Jul 2017 15:35:42 +0300 (MSK) From: Denis Plotnikov To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: rkagan@virtuozzo.com, den@virtuozzo.com, svt-core@lists.sw.ru Subject: [PATCH v3 3/6] timekeeper: add clocksource change notifier Date: Sat, 29 Jul 2017 15:35:08 +0300 Message-Id: <1501331711-12961-4-git-send-email-dplotnikov@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1501331711-12961-1-git-send-email-dplotnikov@virtuozzo.com> References: <1501331711-12961-1-git-send-email-dplotnikov@virtuozzo.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 part of work aiming to switch the KVM to use the timekeeper functionality instead of pvclock_gtod_copy. 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 a2bfc12..ef608f0 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 */ @@ -1367,6 +1416,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); @@ -1544,6 +1594,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);