Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753936Ab0HDPcZ (ORCPT ); Wed, 4 Aug 2010 11:32:25 -0400 Received: from shutemov.name ([188.40.19.243]:38768 "EHLO shutemov.name" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751998Ab0HDPcX (ORCPT ); Wed, 4 Aug 2010 11:32:23 -0400 Date: Wed, 4 Aug 2010 18:32:21 +0300 From: "Kirill A. Shutemov" To: Alexander Shishkin Cc: lkml@vger.kernel.org, Thomas Gleixner , John Stultz , Martin Schwidefsky , Andrew Morton , Jon Hunter , Ingo Molnar , Peter Zijlstra , "Paul E. McKenney" , David Howells , Avi Kivity , "H. Peter Anvin" , John Kacur , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org Subject: Re: [PATCH] [RFC] notify userspace about time changes Message-ID: <20100804153221.GA29109@shutemov.name> References: <1280926108-24668-1-git-send-email-virtuoso@slind.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1280926108-24668-1-git-send-email-virtuoso@slind.org> User-Agent: Mutt/1.5.20 (2009-12-10) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3853 Lines: 99 On Wed, Aug 04, 2010 at 03:48:28PM +0300, Alexander Shishkin wrote: > Certain userspace applications (like "clock" desktop applets or ntpd) might > want to be notified when some other application changes the system time. It > might also be important for an application to be able to distinguish between > its own and somebody else's time changes. > > This patch implements a notification interface via eventfd mechanism. Proccess > wishing to be notified about time changes should create an eventfd and echo > its file descriptor to /sys/kernel/time_notify. After that, any calls to > settimeofday()/stime()/adjtimex() made by other processes will be signalled > to this eventfd. Credits for suggesting the eventfd mechanism for this > purpose go te Kirill Shutemov. > > So far, this implementation can only filter out notifications caused by > time change calls made by the process that wrote the eventfd descriptor to > sysfs, but not its children which (might) have inherited the eventfd. It > is so far not clear to me whether this is bad and more confusing than > excluding such children as well. I think it's a bad idea to filter notifications. Let's leave it for userspace. Userspace always can check eventfd counter and understand who touch time based on its own activity. > Similar mechanism can also be used for signalling other (all?) system calls > made by certain (all?) processes without resorting to ptrace (which won't > help if you don't know what processes you'd like to look after), given > proper permission checks etc. > > Signed-off-by: Alexander Shishkin > CC: Kirill A. Shutemov > CC: Thomas Gleixner > CC: John Stultz > CC: Martin Schwidefsky > CC: Andrew Morton > CC: Jon Hunter > CC: Ingo Molnar > CC: Peter Zijlstra > CC: "Paul E. McKenney" > CC: David Howells > CC: Avi Kivity > CC: "H. Peter Anvin" > CC: John Kacur > CC: Alexander Shishkin > CC: linux-kernel@vger.kernel.org > --- > include/linux/time.h | 7 ++ > init/Kconfig | 7 ++ > kernel/Makefile | 1 + > kernel/time.c | 11 +++- > kernel/time_notify.c | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++ > 5 files changed, 182 insertions(+), 2 deletions(-) > create mode 100644 kernel/time_notify.c > > diff --git a/include/linux/time.h b/include/linux/time.h > index ea3559f..9fca62b 100644 > --- a/include/linux/time.h > +++ b/include/linux/time.h > @@ -237,6 +237,13 @@ static __always_inline void timespec_add_ns(struct timespec *a, u64 ns) > a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns); > a->tv_nsec = ns; > } > + > +#ifdef CONFIG_TIME_NOTIFY > +void time_notify_all(void); > +#else > +#define time_notify_all() do {} while (0) > +#endif > + > #endif /* __KERNEL__ */ > > #define NFDBITS __NFDBITS > diff --git a/init/Kconfig b/init/Kconfig > index 5cff9a9..f7271f8 100644 > --- a/init/Kconfig > +++ b/init/Kconfig > @@ -976,6 +976,13 @@ config PERF_USE_VMALLOC > help > See tools/perf/design.txt for details > > +config TIME_NOTIFY > + bool > + depends on EVENTFD > + help > + Enable time change notification events to userspace via > + eventfd. > + Do we really need config option? I think better just use CONFIG_EVENTFD. linux-api@vger.kernel.org added to CC list. -- Kirill A. Shutemov -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/