netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
To: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Cc: David Miller <davem@davemloft.net>,
	Ulrich Drepper <drepper@redhat.com>,
	Andrew Morton <akpm@osdl.org>,
	Evgeniy Polyakov <johnpol@2ka.mipt.ru>,
	netdev <netdev@vger.kernel.org>,
	Zach Brown <zach.brown@oracle.com>,
	Christoph Hellwig <hch@infradead.org>,
	Chase Venters <chase.venters@clientec.com>,
	Johann Borck <johann.borck@densedata.com>,
	linux-kernel@vger.kernel.org, Jeff Garzik <jeff@garzik.org>
Subject: [take27 5/8] kevent: Timer notifications.
Date: Tue, 12 Dec 2006 10:03:09 +0300	[thread overview]
Message-ID: <1165906989601@2ka.mipt.ru> (raw)
In-Reply-To: <11659069892270@2ka.mipt.ru>


Timer notifications.

Timer notifications can be used for fine grained per-process time 
management, since interval timers are very inconvenient to use, 
and they are limited.

This subsystem uses high-resolution timers.
id.raw[0] is used as number of seconds
id.raw[1] is used as number of nanoseconds

Signed-off-by: Evgeniy Polyakov <johnpol@2ka.mipt.ru>

diff --git a/kernel/kevent/kevent_timer.c b/kernel/kevent/kevent_timer.c
new file mode 100644
index 0000000..df93049
--- /dev/null
+++ b/kernel/kevent/kevent_timer.c
@@ -0,0 +1,112 @@
+/*
+ * 2006 Copyright (c) Evgeniy Polyakov <johnpol@2ka.mipt.ru>
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/list.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/hrtimer.h>
+#include <linux/jiffies.h>
+#include <linux/kevent.h>
+
+struct kevent_timer
+{
+	struct hrtimer		ktimer;
+	struct kevent_storage	ktimer_storage;
+	struct kevent		*ktimer_event;
+};
+
+static int kevent_timer_func(struct hrtimer *timer)
+{
+	struct kevent_timer *t = container_of(timer, struct kevent_timer, ktimer);
+	struct kevent *k = t->ktimer_event;
+
+	kevent_storage_ready(&t->ktimer_storage, NULL, KEVENT_MASK_ALL);
+	hrtimer_forward(timer, timer->base->softirq_time,
+			ktime_set(k->event.id.raw[0], k->event.id.raw[1]));
+	return HRTIMER_RESTART;
+}
+
+static struct lock_class_key kevent_timer_key;
+
+static int kevent_timer_enqueue(struct kevent *k)
+{
+	int err;
+	struct kevent_timer *t;
+
+	t = kmalloc(sizeof(struct kevent_timer), GFP_KERNEL);
+	if (!t)
+		return -ENOMEM;
+
+	hrtimer_init(&t->ktimer, CLOCK_MONOTONIC, HRTIMER_REL);
+	t->ktimer.expires = ktime_set(k->event.id.raw[0], k->event.id.raw[1]);
+	t->ktimer.function = kevent_timer_func;
+	t->ktimer_event = k;
+
+	err = kevent_storage_init(&t->ktimer, &t->ktimer_storage);
+	if (err)
+		goto err_out_free;
+	lockdep_set_class(&t->ktimer_storage.lock, &kevent_timer_key);
+
+	err = kevent_storage_enqueue(&t->ktimer_storage, k);
+	if (err)
+		goto err_out_st_fini;
+
+	hrtimer_start(&t->ktimer, t->ktimer.expires, HRTIMER_REL);
+
+	return 0;
+
+err_out_st_fini:
+	kevent_storage_fini(&t->ktimer_storage);
+err_out_free:
+	kfree(t);
+
+	return err;
+}
+
+static int kevent_timer_dequeue(struct kevent *k)
+{
+	struct kevent_storage *st = k->st;
+	struct kevent_timer *t = container_of(st, struct kevent_timer, ktimer_storage);
+
+	hrtimer_cancel(&t->ktimer);
+	kevent_storage_dequeue(st, k);
+	kfree(t);
+
+	return 0;
+}
+
+static int kevent_timer_callback(struct kevent *k)
+{
+	k->event.ret_data[0] = jiffies_to_msecs(jiffies);
+	return 1;
+}
+
+static int __init kevent_init_timer(void)
+{
+	struct kevent_callbacks tc = {
+		.callback = &kevent_timer_callback,
+		.enqueue = &kevent_timer_enqueue,
+		.dequeue = &kevent_timer_dequeue};
+
+	return kevent_add_callbacks(&tc, KEVENT_TIMER);
+}
+module_init(kevent_init_timer);
+


  reply	other threads:[~2006-12-12  7:03 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <2154985aa0591036@2ka.mipt.ru>
2006-12-11 14:50 ` [take26-resend1 0/8] kevent: Generic event handling mechanism Evgeniy Polyakov
2006-12-11 14:50   ` [take26-resend1 1/8] kevent: Description Evgeniy Polyakov
2006-12-11 14:50     ` [take26-resend1 2/8] kevent: Core files Evgeniy Polyakov
2006-12-11 14:50       ` [take26-resend1 3/8] kevent: poll/select() notifications Evgeniy Polyakov
2006-12-11 14:50         ` [take26-resend1 4/8] kevent: Socket notifications Evgeniy Polyakov
2006-12-11 14:50           ` [take26-resend1 5/8] kevent: Timer notifications Evgeniy Polyakov
2006-12-11 14:50             ` [take26-resend1 6/8] kevent: Pipe notifications Evgeniy Polyakov
2006-12-11 14:50               ` [take26-resend1 7/8] kevent: Signal notifications Evgeniy Polyakov
2006-12-11 14:50                 ` [take26-resend1 8/8] kevent: Kevent posix timer notifications Evgeniy Polyakov
2006-12-11 16:32                 ` [take26-resend1 7/8] kevent: Signal notifications Mauricio Lin
2006-12-12  5:45                   ` Evgeniy Polyakov
2006-12-11 15:16   ` [take26-resend1 0/8] kevent: Generic event handling mechanism Jeff Garzik
2006-12-12  5:39     ` Evgeniy Polyakov
2006-12-12 13:39       ` Jeff Garzik
2006-12-12  7:03 ` [take27 " Evgeniy Polyakov
2006-12-12  7:03   ` [take27 1/8] kevent: Description Evgeniy Polyakov
2006-12-12  7:03     ` [take27 2/8] kevent: Core files Evgeniy Polyakov
2006-12-12  7:03       ` [take27 3/8] kevent: poll/select() notifications Evgeniy Polyakov
2006-12-12  7:03         ` [take27 4/8] kevent: Socket notifications Evgeniy Polyakov
2006-12-12  7:03           ` Evgeniy Polyakov [this message]
2006-12-12  7:03             ` [take27 6/8] kevent: Pipe notifications Evgeniy Polyakov
2006-12-12  7:03               ` [take27 7/8] kevent: Signal notifications Evgeniy Polyakov
2006-12-12  7:03                 ` [take27 8/8] kevent: Kevent posix timer notifications Evgeniy Polyakov
2006-12-14  7:12 ` [take28 0/8] kevent: Generic event handling mechanism Evgeniy Polyakov
2006-12-14  7:12   ` [take28 1/8] kevent: Description Evgeniy Polyakov
2006-12-14  7:12     ` [take28 2/8] kevent: Core files Evgeniy Polyakov
2006-12-14  7:12       ` [take28 3/8] kevent: poll/select() notifications Evgeniy Polyakov
2006-12-14  7:12         ` [take28 4/8] kevent: Socket notifications Evgeniy Polyakov
2006-12-14  7:12           ` [take28 5/8] kevent: Timer notifications Evgeniy Polyakov
2006-12-14  7:12             ` [take28 6/8] kevent: Pipe notifications Evgeniy Polyakov
2006-12-14  7:12               ` [take28 7/8] kevent: Signal notifications Evgeniy Polyakov
2006-12-14  7:12                 ` [take28 8/8] kevent: Kevent posix timer notifications Evgeniy Polyakov

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=1165906989601@2ka.mipt.ru \
    --to=johnpol@2ka.mipt.ru \
    --cc=akpm@osdl.org \
    --cc=chase.venters@clientec.com \
    --cc=davem@davemloft.net \
    --cc=drepper@redhat.com \
    --cc=hch@infradead.org \
    --cc=jeff@garzik.org \
    --cc=johann.borck@densedata.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=zach.brown@oracle.com \
    /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).