From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alan Jenkins Date: Tue, 21 Oct 2008 21:41:02 +0000 Subject: Re: [PATCH] util: Optimize path_encode Message-Id: <48FE4C6E.2050607@tuffmail.co.uk> List-Id: References: <48FDAB29.9090401@tuffmail.co.uk> In-Reply-To: <48FDAB29.9090401@tuffmail.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-hotplug@vger.kernel.org Kay Sievers wrote: > On Tue, Oct 21, 2008 at 12:12, Alan Jenkins wrote: > >> strncpy() shows up in profiling. >> Since we already know the length, use memcpy() instead. >> >> Measured 2% _user_ cpu time reduction on EeePC coldplug >> > > Applied. > > Thanks, > Kay > Ah... just realised it wasn't the normal C string length inefficiency. The problem was strncpy() doesn't stop after writing the terminating NUL; by definition it goes on to zero the entire buffer. I spy another use of strncpy in udev_device_add_property_from_string(), which is responsible for another ~1% user cpu time... BTW I'm still polishing threaded udevd in my spare time. It has 4 TODOs; I will post it soon anyway, but I need to write a few explanatory words first. I have coarse-grained patch descriptions, but there are a couple of obvious questions I would like to pre-answer :).