Re: [PATCH net-next] net: rename low latency sockets functions tobusy poll

From: Linus Torvalds
Date: Mon Jul 08 2013 - 16:10:56 EST


On Mon, Jul 8, 2013 at 1:05 PM, Stephen Hemminger
<stephen@xxxxxxxxxxxxxxxxxx> wrote:
>> >
>> > unsigned long start_time = 0;
>> > ...
>> > if (want_busy_poll && !need_resched()) {
>> > unsigned long now = busy_poll_sched_clock();
>> > if (!start_time) {
>> > start_time = now + sysctl.busypoll;
>> > continue;
>> > }
>> > if (time_before(start_time, now))
>> > continue;
>> > }
>> >
>>
>
> Since this code is in hot path, and a special case, looks like a good
> candidate for static branch.

No, it's not static. It's an initializer, yes, but it's not a static
one, and it gets run on every single select()/poll(). Well, every
single one that goes through the loop more than once.

So it's very much a dynamic condition. It's just placed that way to
avoid doing the (relatively expensive) time read for the case where
data is available immediately.

And the "data is available immediately" case is actually fairly
common. Sometimes it's because the producer/network is faster than the
consumer. And sometimes it's because you get big chunks at a time, but
the reader/writer ends up always going through a select() loop without
actually reading/writing everything in a loop until it gets a
full/empty error.

And I bet that both of those cases happen even with programs/networks
that end up using the magic low-latency/busyloop polling flags. So
avoiding the timer read if at all possible is definitely a good idea.

Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/