Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752768Ab0HWM5i (ORCPT ); Mon, 23 Aug 2010 08:57:38 -0400 Received: from moutng.kundenserver.de ([212.227.17.8]:53553 "EHLO moutng.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751993Ab0HWM5f (ORCPT ); Mon, 23 Aug 2010 08:57:35 -0400 From: Arnd Bergmann To: Richard Cochran , john stultz , linux-api@vger.kernel.org Subject: Re: [PATCH 1/1] posix clocks: introduce syscall for clock tuning. Date: Mon, 23 Aug 2010 14:57:26 +0200 User-Agent: KMail/1.12.2 (Linux/2.6.35-16-generic; KDE/4.3.2; x86_64; ; ) Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201008231457.26690.arnd@arndb.de> X-Provags-ID: V02:K0:u0zi1mzPzHU387xVW9NztyOMahSC/zOOAWumQsH0mhG zX+PuVWb7EdS24xB+Kbsygvgs5LIVyO4J3lPvX+6mZRxyH8QuM IloSJxtOGNFiQgLz6ojUk0CvDXFuL5/XXKLePrXz1OkQcxh9D2 ddjjjxelNS2ZE6t5kKX7nwCQWjyXXcTMzNwZoP+ktP2BEtimn8 smZxwHpSzdbCRm4GT45EQ== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3524 Lines: 99 On Monday 23 August 2010, Richard Cochran wrote: > A new syscall is introduced that allows tuning of a POSIX clock. The > syscall is implemented for four architectures: arm, blackfin, powerpc, > and x86. > > The new syscall, clock_adjtime, takes two parameters, a frequency > adjustment in parts per billion, and a pointer to a struct timespec > containing the clock offset. If the pointer is NULL, a frequency > adjustment is performed. Otherwise, the clock offset is immediately > corrected by skipping to the new time value. It looks well-implemented, and seems to be a reasonable extension to the clock API. I'm looking forward to your ptp patches on top of this to see how it all fits together. For new syscalls, it's best to take linux-api on Cc. I also added John, since he participated in the discussion. > In addtion, the patch provides way to unregister a posix clock. This > function is need to support posix clocks implemented as modules. This part should probably be a separate patch, and you need to add some form of serialization here to avoid races between the clock system calls and the unregistration. > diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c > index 9829646..5843f5a 100644 > --- a/kernel/posix-cpu-timers.c > +++ b/kernel/posix-cpu-timers.c > @@ -207,6 +207,11 @@ int posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp) > return error; > } > > +int posix_cpu_clock_adj(const clockid_t which_clock, int ppb, > + struct timespec *tp) > +{ > + return -EOPNOTSUPP; > +} EOPNOTSUPP is specific to sockets, better use -EINVAL here. Where do you use this function? > /* > * Sample a per-thread clock for the given task. > diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c > index ad72342..089b0d1 100644 > --- a/kernel/posix-timers.c > +++ b/kernel/posix-timers.c > @@ -197,6 +197,12 @@ static int common_timer_create(struct k_itimer *new_timer) > return 0; > } > > +static inline int common_clock_adj(const clockid_t which_clock, int ppb, > + struct timespec *tp) > +{ > + return -EOPNOTSUPP; > +} > + > static int no_timer_create(struct k_itimer *new_timer) > { > return -EOPNOTSUPP; So we already return -EOPNOTSUPP in some cases? The man page does not document this. I wonder if we should change that to -EINVAL as well. > @@ -488,6 +494,21 @@ void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock) > } > EXPORT_SYMBOL_GPL(register_posix_clock); > > +void unregister_posix_clock(const clockid_t clock_id) > +{ > + struct k_clock *clock; > + > + if ((unsigned) clock_id >= MAX_CLOCKS) { > + pr_err("POSIX clock unregister failed for clock_id %d\n", > + clock_id); > + return; > + } > + > + clock = &posix_clocks[clock_id]; > + memset(clock, 0, sizeof(*clock)); > +} > +EXPORT_SYMBOL_GPL(unregister_posix_clock); > + It would be possible to add locks here to serialize unregistration of a clock against dereferencing members of posix_clocks[], but that would cause noticable overhead. A better alternative might be to make it an RCU-protected array of pointers, and use a rcu_assign_pointer/rcu_syncronize/kfree or call_rcu sequence in unregister_posix_clock. Or you just live with not being able to unload this module. Arnd -- 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/