Re: [take8 2/2] kevent: poll/select() notifications. Timer notifications.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Aug 11, 2006 at 08:45:31AM -0700, Andrew Morton ([email protected]) wrote:
> > +static struct lock_class_key kevent_poll_key;
> > +
> > +void kevent_poll_reinit(struct file *file)
> > +{
> > +	lockdep_set_class(&file->st.lock, &kevent_poll_key);
> > +}
> 
> Why is this necessary?

Locks for all storages are initialized in the same function, so lockdep thinks 
they are the same, so when later one lock is being held in proces
context and other in BH or IRQ lockdep screams, so I reinitialize locks
after spin_lock_init().

> > +#include <linux/kernel.h>
> > +#include <linux/types.h>
> > +#include <linux/list.h>
> > +#include <linux/slab.h>
> > +#include <linux/spinlock.h>
> > +#include <linux/timer.h>
> > +#include <linux/jiffies.h>
> > +#include <linux/kevent.h>
> > +
> > +static void kevent_timer_func(unsigned long data)
> > +{
> > +	struct kevent *k = (struct kevent *)data;
> > +	struct timer_list *t = k->st->origin;
> > +
> > +	kevent_storage_ready(k->st, NULL, KEVENT_MASK_ALL);
> > +	mod_timer(t, jiffies + msecs_to_jiffies(k->event.id.raw[0]));
> > +}
> > +
> > +static struct lock_class_key kevent_timer_key;
> > +
> > +static int kevent_timer_enqueue(struct kevent *k)
> > +{
> > +	struct timer_list *t;
> > +	struct kevent_storage *st;
> > +	int err;
> > +
> > +	t = kmalloc(sizeof(struct timer_list) + sizeof(struct kevent_storage), 
> > +			GFP_KERNEL);
> > +	if (!t)
> > +		return -ENOMEM;
> > +
> > +	init_timer(t);
> > +	t->function = kevent_timer_func;
> > +	t->expires = jiffies + msecs_to_jiffies(k->event.id.raw[0]);
> > +	t->data = (unsigned long)k;
> 
> setup_timer().

I know about it's existens now...

> > +	st = (struct kevent_storage *)(t+1);
> 
> It would be cleaner to create
> 
> 	struct <something> {
> 		struct timer_list timer;
> 		struct kevent_storage storage;
> 	};
> 
> > +	err = kevent_storage_init(t, st);
> > +	if (err)
> > +		goto err_out_free;
> > +	lockdep_set_class(&st->lock, &kevent_timer_key);
> 
> Why is this necesary?

As I said above kevent_storage_init() initializes locks for all known
storages (inode, socket, file and so on), when later those locks are
called from different contexts (obviously timer callback can not use the
same lock as for example socket one) lockdep screams.

> > +	
> > +	kevent_storage_dequeue(st, k);
> > +	
> > +	kfree(t);
> > +
> > +	return 0;
> > +}
> > +
> > +static int kevent_timer_callback(struct kevent *k)
> > +{
> > +	struct kevent_storage *st = k->st;
> > +	struct timer_list *t = st->origin;
> > +
> > +	if (!t)
> > +		return -ENODEV;
> > +	
> > +	k->event.ret_data[0] = (__u32)jiffies;
> 
> What does this do?
> 
> Does it expose jiffies to userspace?
> 
> It truncates jiffies on 64-bit machines.

It is a hint when timer was stopped.

> > +late_initcall(kevent_init_timer);
> 
> module_init() would be more typical.  If there was a reason for using
> late_initcall(), that reason should be commented.

No, there are no reasons to use late_initcall() in any kevent
initialization function, I do not use module_init() since kevent can not
be modular. It can be replaced with pure __init function.
Should it?

-- 
	Evgeniy Polyakov
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux