Skip to contentSkip to conversation

: rt_check_expire() can take a long time, add a cond_resched()

NET Arjan van de Ven 5 participants 8 messages Nov 16, 2007 – Nov 18, 2007 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 16 lines · On Thu, 15 Nov 2007 04:01:48 GMT Linux Kernel Mailing List…

Gitweb:
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=d90bf5a976793edfa88d3bb2393f0231eb8ce1e5
Commit: d90bf5a976793edfa88d3bb2393f0231eb8ce1e5 Parent:
66ba886254edbbd9442d30f1eef6f6fb0145027d Author: Eric Dumazet
<[email protected]> AuthorDate: Wed Nov 14 16:14:05 2007 -0800

Committer:  David S. Miller <[email protected]>
CommitDate: Wed Nov 14 16:14:05 2007 -0800

[NET]: rt_check_expire() can take a long time, add a
cond_resched()
On commit 39c90ece7565f5c47110c2fa77409d7a9478bd5b:

When the IP route cache is big, rt_check_expire() can take a long
time to run. (default settings : 20% of the hash table is scanned at each invocation)

Quoted 6 lines

Adding cond_resched() helps giving cpu to higher priority tasks if necessary.

Using a "if (need_resched())" test before calling
"cond_resched();" is necessary to avoid spending too much time doing the resched check.

int __sched cond_resched(void)

{
        if (need_resched() &&  .....

somehow I wonder why the second if() is useful at all; it's another spot for a branch predictor to miss... and a void function call is really really cheap...

Signature · 3 lines
If you want to reach me at my work email, use [email protected]
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#2 lore raw
Quoted 26 lines · Arjan van de Ven
Quoted 16 lines · On Thu, 15 Nov 2007 04:01:48 GMT Linux Kernel Mailing List…

Gitweb:
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=d90bf5a976793edfa88d3bb2393f0231eb8ce1e5
Commit: d90bf5a976793edfa88d3bb2393f0231eb8ce1e5 Parent:
66ba886254edbbd9442d30f1eef6f6fb0145027d Author: Eric Dumazet
<[email protected]> AuthorDate: Wed Nov 14 16:14:05 2007 -0800

Committer:  David S. Miller <[email protected]>
CommitDate: Wed Nov 14 16:14:05 2007 -0800

[NET]: rt_check_expire() can take a long time, add a
cond_resched()
On commit 39c90ece7565f5c47110c2fa77409d7a9478bd5b:

When the IP route cache is big, rt_check_expire() can take a long
time to run. (default settings : 20% of the hash table is scanned at each invocation)

Quoted 6 lines

Adding cond_resched() helps giving cpu to higher priority tasks if necessary.

Using a "if (need_resched())" test before calling
"cond_resched();" is necessary to avoid spending too much time doing the resched check.

Quoted 7 lines

int __sched cond_resched(void)

{
        if (need_resched() &&  .....

somehow I wonder why the second if() is useful at all; it's another spot for a branch predictor to miss... and a void function call is really really cheap...

Its not that cheap. The ChangeLog included my own numbers, on a Pentium M machine. (i686, 1.6 GHz, 1.5 GB ram)

Without "if (need_resched())" (so calling need_resched() X.XXX.XXX times), each run takes 88ms

With the extra check (and *much* less function calls), each run takes 25ms

#3 lore raw
Quoted 34 lines · Eric Dumazet
Quoted 25 lines · Arjan van de Ven
Quoted 12 lines · On Thu, 15 Nov 2007 04:01:48 GMT Linux Kernel Mailing List…

Gitweb:
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=d90bf5a976793edfa88d3bb2393f0231eb8ce1e5

Commit: d90bf5a976793edfa88d3bb2393f0231eb8ce1e5 Parent:
66ba886254edbbd9442d30f1eef6f6fb0145027d Author: Eric Dumazet
<[email protected]> AuthorDate: Wed Nov 14 16:14:05 2007 -0800

Committer:  David S. Miller <[email protected]>
CommitDate: Wed Nov 14 16:14:05 2007 -0800

[NET]: rt_check_expire() can take a long time, add a
cond_resched() On commit 39c90ece7565f5c47110c2fa77409d7a9478bd5b:

Quoted 9 lines

When the IP route cache is big, rt_check_expire() can take a long
time to run. (default settings : 20% of the hash table is scanned at each invocation)
Adding cond_resched() helps giving cpu to higher priority
tasks if
necessary.
Using a "if (need_resched())" test before calling
"cond_resched();" is necessary to avoid spending too much time doing the resched check.

Quoted 7 lines

int __sched cond_resched(void)

{
        if (need_resched() &&  .....

somehow I wonder why the second if() is useful at all; it's another spot for a branch predictor to miss... and a void function call is really really cheap...

Quoted 6 lines

Its not that cheap. The ChangeLog included my own numbers, on a Pentium M machine. (i686, 1.6 GHz, 1.5 GB ram)

Without "if (need_resched())" (so calling need_resched() X.XXX.XXX times), each run takes 88ms

With the extra check (and *much* less function calls), each run takes 25ms

Looking at cond_resched(), I think the extra cost comes from "mov %esp,%edx ; and $0xffffe000,%edx" (current_thread_info())

I dont have oprofile numbers yet, but I suspect CPU may have some delays to compute this pointer value, since %esp is probably 'busy' because of the preceding "call"

(In the case the "if (need_resched())" is done in rt_check_expire(), compiler moves this pointer computation (current_thread_info()) out of the loop)

c055f926 <cond_resched>:

c055f926:       89 e2                   mov    %esp,%edx
c055f928:       81 e2 00 e0 ff ff       and    $0xffffe000,%edx
c055f92e:       8b 42 08                mov    0x8(%edx),%eax
c055f931:       a8 04                   test   $0x4,%al
c055f933:       74 1a                   je     c055f94f <cond_resched+0x29>
c055f935:       f6 42 17 10             testb  $0x10,0x17(%edx)
c055f939:       75 14                   jne    c055f94f <cond_resched+0x29>
c055f93b:       83 3d 00 80 7c c0 01    cmpl   $0x1,0xc07c8000
c055f942:       75 0b                   jne    c055f94f <cond_resched+0x29>
c055f944:       e8 2b 80 bb ff          call   c0117974 <__cond_resched>
c055f949:       b8 01 00 00 00          mov    $0x1,%eax
c055f94e:       c3                      ret
c055f94f:       31 c0                   xor    %eax,%eax
c055f951:       c3                      ret
#4 lore raw
Quoted 46 lines · On Fri, 16 Nov 2007 05:12:21 +0100 Eric Dumazet <[email protected]> wrote:
Quoted 35 lines · Eric Dumazet
Quoted 26 lines · Arjan van de Ven
Quoted 13 lines · On Thu, 15 Nov 2007 04:01:48 GMT Linux Kernel Mailing List…

Gitweb:
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=d90bf5a976793edfa88d3bb2393f0231eb8ce1e5

Commit: d90bf5a976793edfa88d3bb2393f0231eb8ce1e5 Parent:
66ba886254edbbd9442d30f1eef6f6fb0145027d Author: Eric Dumazet
<[email protected]> AuthorDate: Wed Nov 14 16:14:05 2007 -0800

Committer:  David S. Miller <[email protected]>
CommitDate: Wed Nov 14 16:14:05 2007 -0800

[NET]: rt_check_expire() can take a long time, add a
cond_resched() On commit
39c90ece7565f5c47110c2fa77409d7a9478bd5b:

Quoted 9 lines

When the IP route cache is big, rt_check_expire() can take a
long time to run. (default settings : 20% of the hash table is scanned at each invocation)
Adding cond_resched() helps giving cpu to higher priority
tasks if
necessary.
Using a "if (need_resched())" test before calling
"cond_resched();" is necessary to avoid spending too much time doing the resched check.

Quoted 7 lines

int __sched cond_resched(void)

{
        if (need_resched() &&  .....

somehow I wonder why the second if() is useful at all; it's another spot for a branch predictor to miss... and a void function call is really really cheap...

Quoted 9 lines

Its not that cheap. The ChangeLog included my own numbers, on a Pentium M machine. (i686, 1.6 GHz, 1.5 GB ram)

Without "if (need_resched())" (so calling need_resched() X.XXX.XXX times), each run takes 88ms

With the extra check (and *much* less function calls), each run takes 25ms

Quoted 6 lines

Looking at cond_resched(), I think the extra cost comes from "mov %esp,%edx ; and $0xffffe000,%edx" (current_thread_info())

I dont have oprofile numbers yet, but I suspect CPU may have some delays to compute this pointer value, since %esp is probably 'busy' because of the preceding "call"

yeah the explicit reference makes the stack pointer tracking engine do a commit I suspect which then also creates a data dependency in the code flow.

however... this is likely a good argument for making cond_resched() as a whole a #define (or inline) that does this test and then calls the out of line code (which then doesn't need to retest, so it avoids the double test)...

Signature · 3 lines
If you want to reach me at my work email, use [email protected]
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#5 lore raw
Quoted 9 lines · Arjan van de Ven
Quoted 9 lines
Quoted 9 lines

Its not that cheap. The ChangeLog included my own numbers, on a Pentium M machine. (i686, 1.6 GHz, 1.5 GB ram)

Without "if (need_resched())" (so calling need_resched() X.XXX.XXX times), each run takes 88ms

With the extra check (and *much* less function calls), each run takes 25ms

ms?!? The numbers sound wrong. Wrong unit?

Quoted 9 lines
Quoted 8 lines
Quoted 1 line

Looking at cond_resched(), I think the extra cost comes from "mov %esp,%edx ; and $0xffffe000,%edx" (current_thread_info())

I dont have oprofile numbers yet, but I suspect CPU may have some delays to compute this pointer value, since %esp is probably 'busy' because of the preceding "call"

Quoted 8 lines

yeah the explicit reference makes the stack pointer tracking engine do a commit I suspect which then also creates a data dependency in the code flow.

however... this is likely a good argument for making cond_resched() as a whole a #define (or inline) that does this test and then calls the out of line code (which then doesn't need to retest, so it avoids the double test)...

Disadvantage would be that might_sleep would be commonly skipped then (unless you actually need to reschedule)
But perhaps that's not a big issue.

-Andi

#6 lore raw
Quoted 5 lines · Andi Kleen
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

With the extra check (and *much* less function calls), each run takes 25ms

ms?!? The numbers sound wrong. Wrong unit?

That's quite possible with a huge routing cache. I think that's the reason Eric is doing this in the first place.

Quoted 8 lines
Quoted 4 lines

however... this is likely a good argument for making cond_resched() as a whole a #define (or inline) that does this test and then calls the out of line code (which then doesn't need to retest, so it avoids the double test)...

Disadvantage would be that might_sleep would be commonly skipped then (unless you actually need to reschedule)
But perhaps that's not a big issue.

On a related note, would it be possible for cond_resched() to be compiled out completely if we're doing real preemption as opposed to voluntary preemption?

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer
#7 lore raw
In reply to Andi Kleen

From: Andi Kleen <[email protected]>
Date: Sat, 17 Nov 2007 13:56:08 +0100

Quoted 5 lines
Quoted 4 lines · Arjan van de Ven
Quoted 4 lines
Quoted 4 lines

Its not that cheap. The ChangeLog included my own numbers, on a Pentium M machine. (i686, 1.6 GHz, 1.5 GB ram)

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Without "if (need_resched())" (so calling need_resched() X.XXX.XXX times), each run takes 88ms

With the extra check (and *much* less function calls), each run takes 25ms

ms?!? The numbers sound wrong. Wrong unit?

Read what Eric is saying. He is saying "any entire run" purging the routing cache takes that long, not just one call.

maintainer
#8 lore raw
In reply to Arjan van de Ven

From: Arjan van de Ven <[email protected]>
Date: Thu, 15 Nov 2007 19:38:02 -0800

Quoted 7 lines
Quoted 3 lines · On Thu, 15 Nov 2007 04:01:48 GMT Linux Kernel Mailing List…

Using a "if (need_resched())" test before calling
"cond_resched();" is necessary to avoid spending too much time doing the resched check.

Quoted 7 lines

int __sched cond_resched(void)

{
        if (need_resched() &&  .....

somehow I wonder why the second if() is useful at all; it's another spot for a branch predictor to miss... and a void function call is really really cheap...

Not by Eric's tests. Please read the thread, he checked and it's 50ms more expensive to make the function call.

Please, when you notice something interesting in something flying by on git-web, go check thing out we probably discussed the thing you're interested in.

And please at least CC: netdev about networking patches, and also the patch author, which I've corrected in this reply.