linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Richard Cochran <richardcochran@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: John Stultz <johnstul@us.ibm.com>,
	Rodolfo Giometti <giometti@linux.it>,
	Arnd Bergmann <arnd@arndb.de>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-api@vger.kernel.org, devicetree-discuss@lists.ozlabs.org,
	Thomas Gleixner <tglx@linutronix.de>,
	netdev@vger.kernel.org, Christoph Lameter <cl@linux.com>,
	linuxppc-dev@lists.ozlabs.org, David Miller <davem@davemloft.net>,
	linux-arm-kernel@lists.infradead.org,
	Krzysztof Halasa <khc@pm.waw.pl>
Subject: [PATCH 2/8] posix clocks: dynamic clock ids.
Date: Thu, 23 Sep 2010 19:31:33 +0200	[thread overview]
Message-ID: <c234c15972e000eb1fd3e9e0e298130df23948c9.1285261534.git.richard.cochran@omicron.at> (raw)
In-Reply-To: <cover.1285261533.git.richard.cochran@omicron.at>

This patch augments the POSIX clock code to offer a dynamic clock
creation method. Instead of registering a hard coded clock ID, modules
may call create_posix_clock(), which returns a new clock ID.

Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
---
 include/linux/posix-timers.h |    7 ++++++-
 include/linux/time.h         |    2 ++
 kernel/posix-timers.c        |   41 ++++++++++++++++++++++++++++++++++-------
 3 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
index abf61cc..08aa4da 100644
--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -68,6 +68,7 @@ struct k_itimer {
 };
 
 struct k_clock {
+	clockid_t id;
 	int res;		/* in nanoseconds */
 	int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
 	int (*clock_set) (const clockid_t which_clock, struct timespec * tp);
@@ -86,7 +87,11 @@ struct k_clock {
 			   struct itimerspec * cur_setting);
 };
 
-void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock);
+/* Regsiter a posix clock with a "well known" clock id. */
+int register_posix_clock(const clockid_t id, struct k_clock *clock);
+
+/* Create a new posix clock with a dynamic clock id. */
+clockid_t create_posix_clock(struct k_clock *clock);
 
 /* error handlers for timer_create, nanosleep and settime */
 int do_posix_clock_nonanosleep(const clockid_t, int flags, struct timespec *,
diff --git a/include/linux/time.h b/include/linux/time.h
index 9f15ac7..914c48d 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -299,6 +299,8 @@ struct itimerval {
 #define CLOCKS_MASK			(CLOCK_REALTIME | CLOCK_MONOTONIC)
 #define CLOCKS_MONO			CLOCK_MONOTONIC
 
+#define CLOCK_INVALID			-1
+
 /*
  * The various flags for setting POSIX.1b interval timers:
  */
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 446b566..67fba5c 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -132,6 +132,8 @@ static DEFINE_SPINLOCK(idr_lock);
  */
 
 static struct k_clock posix_clocks[MAX_CLOCKS];
+static DECLARE_BITMAP(clocks_map, MAX_CLOCKS);
+static DEFINE_MUTEX(clocks_mux); /* protects 'posix_clocks' and 'clocks_map' */
 
 /*
  * These ones are defined below.
@@ -484,18 +486,43 @@ static struct pid *good_sigevent(sigevent_t * event)
 	return task_pid(rtn);
 }
 
-void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock)
+int register_posix_clock(const clockid_t id, struct k_clock *clock)
 {
-	if ((unsigned) clock_id >= MAX_CLOCKS) {
-		printk("POSIX clock register failed for clock_id %d\n",
-		       clock_id);
-		return;
-	}
+	struct k_clock *kc;
+	int err = 0;
 
-	posix_clocks[clock_id] = *new_clock;
+	mutex_lock(&clocks_mux);
+	if (test_bit(id, clocks_map)) {
+		pr_err("clock_id %d already registered\n", id);
+		err = -EBUSY;
+		goto out;
+	}
+	kc = &posix_clocks[id];
+	*kc = *clock;
+	kc->id = id;
+	set_bit(id, clocks_map);
+out:
+	mutex_unlock(&clocks_mux);
+	return err;
 }
 EXPORT_SYMBOL_GPL(register_posix_clock);
 
+clockid_t create_posix_clock(struct k_clock *clock)
+{
+	clockid_t id;
+
+	mutex_lock(&clocks_mux);
+	id = find_first_zero_bit(clocks_map, MAX_CLOCKS);
+	mutex_unlock(&clocks_mux);
+
+	if (id < MAX_CLOCKS) {
+		register_posix_clock(id, clock);
+		return id;
+	}
+	return CLOCK_INVALID;
+}
+EXPORT_SYMBOL_GPL(create_posix_clock);
+
 static struct k_itimer * alloc_posix_timer(void)
 {
 	struct k_itimer *tmr;
-- 
1.7.0.4

  parent reply	other threads:[~2010-09-23 17:31 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-23 17:30 [PATCH v6 0/8] ptp: IEEE 1588 hardware clock support Richard Cochran
2010-09-23 17:31 ` [PATCH 1/8] posix clocks: introduce a syscall for clock tuning Richard Cochran
2010-09-23 19:48   ` john stultz
2010-09-24  7:29     ` Richard Cochran
2010-09-24 17:55       ` john stultz
2010-09-23 22:03   ` Benjamin Herrenschmidt
2010-09-23 22:12     ` Thomas Gleixner
2010-09-24  1:20       ` Benjamin Herrenschmidt
2010-09-24  7:55     ` Richard Cochran
2010-09-24 22:12       ` Benjamin Herrenschmidt
2010-09-23 17:31 ` Richard Cochran [this message]
2010-09-23 17:31 ` [PATCH 3/8] posix clocks: introduce a sysfs presence Richard Cochran
2010-09-23 17:32 ` [PATCH 4/8] ptp: Added a brand new class driver for ptp clocks Richard Cochran
2010-09-23 17:32 ` [PATCH 5/8] ptp: Added a simulated PTP hardware clock Richard Cochran
2010-09-23 17:33 ` [PATCH 6/8] ptp: Added a clock that uses the eTSEC found on the MPC85xx Richard Cochran
2010-09-23 19:17   ` Christoph Lameter
2010-09-23 20:43     ` Alan Cox
2010-09-23 20:32       ` Christoph Lameter
2010-09-23 21:26       ` Christian Riesch
2010-09-24 11:52         ` Alan Cox
2010-09-24  8:49     ` Richard Cochran
2010-09-23 17:33 ` [PATCH 7/8] ptp: Added a clock driver for the IXP46x Richard Cochran
2010-09-23 17:34 ` [PATCH 8/8] ptp: Added a clock driver for the National Semiconductor PHYTER Richard Cochran
2010-09-23 17:53 ` [PATCH v6 0/8] ptp: IEEE 1588 hardware clock support Christoph Lameter
2010-09-23 18:21   ` Jacob Keller
2010-09-23 18:36     ` Christoph Lameter
2010-09-23 18:59   ` john stultz
2010-09-23 19:15     ` Christoph Lameter
2010-09-23 20:28       ` john stultz
2010-09-23 20:49         ` Christoph Lameter
2010-09-23 21:34           ` Alan Cox
2010-09-23 21:34             ` Christian Riesch
2010-09-27 15:37               ` Christoph Lameter
2010-09-30  3:50                 ` Christian Riesch
2010-10-02  1:44                 ` M. Warner Losh
2010-09-23 21:42           ` john stultz
2010-09-27 15:52             ` Christoph Lameter
2010-09-27 16:14               ` M. Warner Losh
2010-09-28  6:34                 ` Richard Cochran
2010-09-24  8:33   ` Richard Cochran
2010-09-23 19:38 ` john stultz
2010-09-24 13:50   ` Richard Cochran
2010-09-24 14:57     ` Alan Cox
2010-09-23 20:36 ` Alan Cox
2010-09-23 20:49   ` john stultz
2010-09-23 21:30     ` Alan Cox
2010-09-23 22:03       ` john stultz
2010-09-24 13:14   ` Richard Cochran
2010-09-24 14:02     ` Alan Cox
2010-09-24 14:07       ` Alan Cox
2010-09-27 15:56       ` Christoph Lameter
2010-09-27 17:05         ` Alan Cox
2010-09-28  6:47           ` Richard Cochran

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c234c15972e000eb1fd3e9e0e298130df23948c9.1285261534.git.richard.cochran@omicron.at \
    --to=richardcochran@gmail.com \
    --cc=arnd@arndb.de \
    --cc=cl@linux.com \
    --cc=davem@davemloft.net \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=giometti@linux.it \
    --cc=johnstul@us.ibm.com \
    --cc=khc@pm.waw.pl \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).