Re: [RFC] timers, pointers to functions and type safety

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

 



On Mon, Dec 04, 2006 at 11:14:29AM +0000, David Howells wrote:
> All it generally takes is two instances of a timer_list struct that use one
> common handler function for the removal of the data member from the timer_list
> to be a win on pretty much every platform.
> 
> Consider: you replace:
> 
> 	struct timer_list {
> 		void (*func)(unsigned long data);
> 		unsigned long data;
> 	};
> 
> 	void handler(unsigned long data)
> 	{
> 		struct *foo = (struct foo *) data;
> 		...
> 	}
> 
> with:
> 
> 	struct timer_list {
> 		void (*func)(struct timer_list *timer);
> 		unsigned long data;

I assume you wanted to delete "data" ?

> 	};
> 
> 	void handler(struct timer_list *timer)
> 	{
> 		struct *foo = container_of(timer, struct foo, mytimer);
> 		...
> 	}

Your premise is two timer_lists which use one common handler.

	struct foo {
		struct timer_list timer1;
		strucr timer_list timer2;
	};

would preclude using a common handler for both timers.  You need two
separate handlers, one which knows the offset of timer1 and the other
the offset of timer2.

In this case, you are removing 2 * sizeof(unsigned long) from struct
foo, but you're adding a two add/sub instructions to each handler,
but worse than that, this would force two veneer handlers to call the
common handler.

The point here is that we can all dream up cases where some particular
way is a win or not.  Whether it really _is_ a win depends on the uses
in the kernel.

The only real way to find that out is to try it.  Generate a patch.
Build it.  See what happens to the kernel code and data sizes.

I strongly suggest that we do that rather than speculating. 8)  Words
(and emails) are cheap but in the end are not really constructive.

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:
-
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