[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <26864.1165230869@redhat.com>
Date: Mon, 04 Dec 2006 11:14:29 +0000
From: David Howells <dhowells@...hat.com>
To: Russell King <rmk+lkml@....linux.org.uk>
Cc: Pavel Machek <pavel@....cz>, Roman Zippel <zippel@...ux-m68k.org>,
Al Viro <viro@....linux.org.uk>,
Thomas Gleixner <tglx@...utronix.de>,
Matthew Wilcox <matthew@....cx>,
Linus Torvalds <torvalds@...l.org>, linux-arch@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [RFC] timers, pointers to functions and type safety
Russell King <rmk+lkml@....linux.org.uk> wrote:
> There *are* times when having the additional space for storing a pointer
> is cheaper (in terms of number of bytes) than code to calculate an offset,
> and those who have read the assembly code probably know this all too well.
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;
};
void handler(struct timer_list *timer)
{
struct *foo = container_of(timer, struct foo, mytimer);
...
}
You are removing 4 or 8 bytes (an unsigned long) from each of two structures
and replacing them with a single ADD/SUB instruction, usually with a small
immediate value - which will be at most 4 bytes on most archs - and in some
cases it'll cost less than that because the compiler can use REG+offset
addressing and so avoid the adjustment entirely.
Another way to look at it is that timers aren't generally called all that
often, but that a fair number of structures in the kernel contain timers -
though maybe second or third hand. You can shrink all of these by one word
per timer, and that makes an immediate effect.
Furthermore, I have patches to shrink work_struct by (a) removing the timer
where it's not needed, (b) folding the single flag bit into one of the
pointers, and (c) dropping the data member in favour of using container_of()
in the handler.
In almost every case where a work_struct is used, the data argument is the
address of the structure containing the work_struct, so (c) gains.
The three reductions reduce the size of work_struct by two-thirds. The new
delayed_struct is only a reduction of one-sixth as it still carries a timer.
However, if that timer can be shrunk by one-sixth by removing that data
argument, then the delayed_struct can exhibit a one-quarter reduction instead.
David
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists