Skip to contentSkip to conversation

Userspace RCU (urcu) for Linux

RFC Mathieu Desnoyers 10 participants 116 messages Feb 6, 2009 – Feb 22, 2009 1 message not in the archive Page 2 of 2

lore
Share & tools
lore
#94 lore raw

Re: [ltt-dev] [RFC git tree] Userspace RCU (urcu) for Linux (repost)

In reply to Mathieu Desnoyers
Quoted 2 lines · Mathieu Desnoyers
Quoted 1 line · * Paul E. McKenney ([email protected]) wrote:

On Mon, Feb 09, 2009 at 12:17:37AM -0500, Mathieu Desnoyers wrote:

[ . . . ]

Quoted 10 lines
Quoted 7 lines
Quoted 2 lines

The new version is pushed into the repository. I changed you patch a bit. Flaming is welcome. :)

Looks reasonable at first glance. Just out of curiosity, why are urcu_gp_ctr and urcu_active_readers int rather than char? I guess that one reason would be that many architectures work better with int than with char...

Exactly. This is done to make sure we don't end up having false register dependencies causing stalls on such architectures. I'll add a comment.

Are there any 64-bit architectures that would prefer a long to an int? (Other than really old Alpha CPUs, that is.)

Quoted 5 lines
Quoted 1 line

So, how many cycles did this save? ;-)

On x86_64, it's pretty much the same as before. It just helps having the 32 and 64 bits algorithms being exactly the same, which I think is a very good thing.

Good point!

Quoted 7 lines

BTW, my tests were done without any CMOV instruction due to the standard gcc options I used. Given think past discussion about CMOV :

http://ondioline.org/mail/cmov-a-bad-idea-on-out-of-order-cpus

It does not seem like such a good idea to use it anyway, given it can take 10 cycles to run on a P4a

Fair enough!

Quoted 4 lines

BTW, do you think having the 256 nested rcu read locks limitation could become a problem ? I really think an application has recursion problem if it does, but this is not impossible, especially on a particularly badly designed tree-traversal algorithm on a 64-bits arch...

I don't know of any code in the Linux kernel that nests rcu_read_lock() anywhere near that deep. And if someone does find such a case, it is pretty easy to use 15 bits rather than 8 to hold the nesting depth, just by changing the definition of RCU_GP_CTR_BIT.

Thanx, Paul

Quoted 42 lines

Mathieu

Quoted 36 lines

Thanx, Paul

Quoted 33 lines

Mathieu

Quoted 27 lines

Mathieu

Quoted 15 lines
Quoted 10 lines
Quoted 5 lines

Again, looks interesting! Looks plausible, although I have not 100% convinced myself that it is perfectly bug-free. But I do maintain a healthy skepticism of purported RCU algorithms, especially ones that I have written. ;-)

That's always good. I also tend to always be very skeptical about what I write and review.

Thanks for the thorough review.

No problem -- it has been quite fun! ;-)

Thanx, Paul

Signature · 7 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

_______________________________________________
ltt-dev mailing list
[email protected]
http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
#95 lore raw

Re: [ltt-dev] [RFC git tree] Userspace RCU (urcu) for Linux (repost)

Quoted 14 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 2 lines · Mathieu Desnoyers
Quoted 1 line · * Paul E. McKenney ([email protected]) wrote:

On Mon, Feb 09, 2009 at 12:17:37AM -0500, Mathieu Desnoyers wrote:

[ . . . ]

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

The new version is pushed into the repository. I changed you patch a bit. Flaming is welcome. :)

Looks reasonable at first glance. Just out of curiosity, why are urcu_gp_ctr and urcu_active_readers int rather than char? I guess that one reason would be that many architectures work better with int than with char...

Quoted 6 lines
Quoted 2 lines

Exactly. This is done to make sure we don't end up having false register dependencies causing stalls on such architectures. I'll add a comment.

Are there any 64-bit architectures that would prefer a long to an int? (Other than really old Alpha CPUs, that is.)

None that I am aware of, but Christoph or Peter would probably know more than I do on this aspect.

Quoted 23 lines
Quoted 5 lines
Quoted 1 line

So, how many cycles did this save? ;-)

On x86_64, it's pretty much the same as before. It just helps having the 32 and 64 bits algorithms being exactly the same, which I think is a very good thing.

Good point!

Quoted 7 lines

BTW, my tests were done without any CMOV instruction due to the standard gcc options I used. Given think past discussion about CMOV :

http://ondioline.org/mail/cmov-a-bad-idea-on-out-of-order-cpus

It does not seem like such a good idea to use it anyway, given it can take 10 cycles to run on a P4a

Fair enough!

Quoted 4 lines

BTW, do you think having the 256 nested rcu read locks limitation could become a problem ? I really think an application has recursion problem if it does, but this is not impossible, especially on a particularly badly designed tree-traversal algorithm on a 64-bits arch...

Quoted 5 lines

I don't know of any code in the Linux kernel that nests rcu_read_lock() anywhere near that deep. And if someone does find such a case, it is pretty easy to use 15 bits rather than 8 to hold the nesting depth, just by changing the definition of RCU_GP_CTR_BIT.

You know what ? Changing RCU_GP_CTR_BIT to 16 uses a testw %ax, %ax instead of a testb %al, %al. The trick here is that RCU_GP_CTR_BIT must be a multiple of 8 so we can use a full 8-bits, 16-bits or 32-bits bitmask for the lower order bits.

On 64-bits, using a RCU_GP_CTR_BIT of 32 is also ok. It uses a testl.

To provide 32-bits compability and allow the deepest nesting possible, I think it makes sense to use

/* Use the amount of bits equal to half of the architecture long size */ #define RCU_GP_CTR_BIT (sizeof(long) << 2)

Mathieu

Quoted 45 lines

Thanx, Paul

Quoted 42 lines

Mathieu

Quoted 36 lines

Thanx, Paul

Quoted 33 lines

Mathieu

Quoted 27 lines

Mathieu

Quoted 15 lines
Quoted 10 lines
Quoted 5 lines

Again, looks interesting! Looks plausible, although I have not 100% convinced myself that it is perfectly bug-free. But I do maintain a healthy skepticism of purported RCU algorithms, especially ones that I have written. ;-)

That's always good. I also tend to always be very skeptical about what I write and review.

Thanks for the thorough review.

No problem -- it has been quite fun! ;-)

Thanx, Paul

Signature · 7 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

_______________________________________________
ltt-dev mailing list
[email protected]
http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
#96 lore raw

Re: [ltt-dev] [RFC git tree] Userspace RCU (urcu) for Linux (repost)

Quoted 18 lines · * Mathieu Desnoyers ([email protected]) wrote:
Quoted 17 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 2 lines · Mathieu Desnoyers
Quoted 1 line · * Paul E. McKenney ([email protected]) wrote:

On Mon, Feb 09, 2009 at 12:17:37AM -0500, Mathieu Desnoyers wrote:

[ . . . ]

Quoted 10 lines
Quoted 7 lines
Quoted 2 lines

The new version is pushed into the repository. I changed you patch a bit. Flaming is welcome. :)

Looks reasonable at first glance. Just out of curiosity, why are urcu_gp_ctr and urcu_active_readers int rather than char? I guess that one reason would be that many architectures work better with int than with char...

Exactly. This is done to make sure we don't end up having false register dependencies causing stalls on such architectures. I'll add a comment.

Quoted 7 lines
Quoted 3 lines

Are there any 64-bit architectures that would prefer a long to an int? (Other than really old Alpha CPUs, that is.)

None that I am aware of, but Christoph or Peter would probably know more than I do on this aspect.

Well, I had to put back a "long" rather than a "int" since we not support 2^32 nesting nevels on 64-bits. The following bit, used for quiescent state "parity", ends up being the 33rd bit, which needs a 64-bit long.

Mathieu

Quoted 100 lines
Quoted 23 lines
Quoted 5 lines
Quoted 1 line

So, how many cycles did this save? ;-)

On x86_64, it's pretty much the same as before. It just helps having the 32 and 64 bits algorithms being exactly the same, which I think is a very good thing.

Good point!

Quoted 7 lines

BTW, my tests were done without any CMOV instruction due to the standard gcc options I used. Given think past discussion about CMOV :

http://ondioline.org/mail/cmov-a-bad-idea-on-out-of-order-cpus

It does not seem like such a good idea to use it anyway, given it can take 10 cycles to run on a P4a

Fair enough!

Quoted 4 lines

BTW, do you think having the 256 nested rcu read locks limitation could become a problem ? I really think an application has recursion problem if it does, but this is not impossible, especially on a particularly badly designed tree-traversal algorithm on a 64-bits arch...

Quoted 5 lines

I don't know of any code in the Linux kernel that nests rcu_read_lock() anywhere near that deep. And if someone does find such a case, it is pretty easy to use 15 bits rather than 8 to hold the nesting depth, just by changing the definition of RCU_GP_CTR_BIT.

You know what ? Changing RCU_GP_CTR_BIT to 16 uses a testw %ax, %ax instead of a testb %al, %al. The trick here is that RCU_GP_CTR_BIT must be a multiple of 8 so we can use a full 8-bits, 16-bits or 32-bits bitmask for the lower order bits.

On 64-bits, using a RCU_GP_CTR_BIT of 32 is also ok. It uses a testl.

To provide 32-bits compability and allow the deepest nesting possible, I think it makes sense to use

/* Use the amount of bits equal to half of the architecture long size */ #define RCU_GP_CTR_BIT (sizeof(long) << 2)

Mathieu

Quoted 45 lines

Thanx, Paul

Quoted 42 lines

Mathieu

Quoted 36 lines

Thanx, Paul

Quoted 33 lines

Mathieu

Quoted 27 lines

Mathieu

Quoted 15 lines
Quoted 10 lines
Quoted 5 lines

Again, looks interesting! Looks plausible, although I have not 100% convinced myself that it is perfectly bug-free. But I do maintain a healthy skepticism of purported RCU algorithms, especially ones that I have written. ;-)

That's always good. I also tend to always be very skeptical about what I write and review.

Thanks for the thorough review.

No problem -- it has been quite fun! ;-)

Thanx, Paul

Signature · 7 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

_______________________________________________
ltt-dev mailing list
[email protected]
http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
Signature · 7 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

_______________________________________________
ltt-dev mailing list
[email protected]
http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
#97 lore raw

Re: [ltt-dev] [RFC git tree] Userspace RCU (urcu) for Linux (repost)

In reply to Mathieu Desnoyers
Quoted 58 lines · Mathieu Desnoyers
Quoted 14 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 2 lines · Mathieu Desnoyers
Quoted 1 line · * Paul E. McKenney ([email protected]) wrote:

On Mon, Feb 09, 2009 at 12:17:37AM -0500, Mathieu Desnoyers wrote:

[ . . . ]

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

The new version is pushed into the repository. I changed you patch a bit. Flaming is welcome. :)

Looks reasonable at first glance. Just out of curiosity, why are urcu_gp_ctr and urcu_active_readers int rather than char? I guess that one reason would be that many architectures work better with int than with char...

Quoted 5 lines
Quoted 2 lines

Exactly. This is done to make sure we don't end up having false register dependencies causing stalls on such architectures. I'll add a comment.

Are there any 64-bit architectures that would prefer a long to an int? (Other than really old Alpha CPUs, that is.)

None that I am aware of, but Christoph or Peter would probably know more than I do on this aspect.

Quoted 23 lines
Quoted 5 lines
Quoted 1 line

So, how many cycles did this save? ;-)

On x86_64, it's pretty much the same as before. It just helps having the 32 and 64 bits algorithms being exactly the same, which I think is a very good thing.

Good point!

Quoted 7 lines

BTW, my tests were done without any CMOV instruction due to the standard gcc options I used. Given think past discussion about CMOV :

http://ondioline.org/mail/cmov-a-bad-idea-on-out-of-order-cpus

It does not seem like such a good idea to use it anyway, given it can take 10 cycles to run on a P4a

Fair enough!

Quoted 4 lines

BTW, do you think having the 256 nested rcu read locks limitation could become a problem ? I really think an application has recursion problem if it does, but this is not impossible, especially on a particularly badly designed tree-traversal algorithm on a 64-bits arch...

Quoted 5 lines

I don't know of any code in the Linux kernel that nests rcu_read_lock() anywhere near that deep. And if someone does find such a case, it is pretty easy to use 15 bits rather than 8 to hold the nesting depth, just by changing the definition of RCU_GP_CTR_BIT.

You know what ? Changing RCU_GP_CTR_BIT to 16 uses a testw %ax, %ax instead of a testb %al, %al. The trick here is that RCU_GP_CTR_BIT must be a multiple of 8 so we can use a full 8-bits, 16-bits or 32-bits bitmask for the lower order bits.

Quoted 7 lines

On 64-bits, using a RCU_GP_CTR_BIT of 32 is also ok. It uses a testl.

To provide 32-bits compability and allow the deepest nesting possible, I think it makes sense to use

/* Use the amount of bits equal to half of the architecture long size */ #define RCU_GP_CTR_BIT (sizeof(long) << 2)

You lost me on this one:

	sizeof(long) << 2 = 0x10

I could believe the following (run on a 32-bit machine):

	1 << (sizeof(long) * 8 - 1) = 0x80000000

Or, if you were wanting to use a bit halfway up the word, perhaps this:

	1 << (sizeof(long) * 4 - 1) = 0x8000

Or am I confused?

Thanx, Paul

Quoted 52 lines

Mathieu

Quoted 45 lines

Thanx, Paul

Quoted 42 lines

Mathieu

Quoted 36 lines

Thanx, Paul

Quoted 33 lines

Mathieu

Quoted 27 lines

Mathieu

Quoted 15 lines
Quoted 10 lines
Quoted 5 lines

Again, looks interesting! Looks plausible, although I have not 100% convinced myself that it is perfectly bug-free. But I do maintain a healthy skepticism of purported RCU algorithms, especially ones that I have written. ;-)

That's always good. I also tend to always be very skeptical about what I write and review.

Thanks for the thorough review.

No problem -- it has been quite fun! ;-)

Thanx, Paul

Signature · 7 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

_______________________________________________
ltt-dev mailing list
[email protected]
http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
#98 lore raw

Re: [ltt-dev] [RFC git tree] Userspace RCU (urcu) for Linux (repost)

Quoted 2 lines · Paul E. McKenney
Quoted 1 line · Mathieu Desnoyers

* Paul E. McKenney ([email protected]) wrote:

[ . . . ]

Quoted 19 lines
Quoted 5 lines

You know what ? Changing RCU_GP_CTR_BIT to 16 uses a testw %ax, %ax instead of a testb %al, %al. The trick here is that RCU_GP_CTR_BIT must be a multiple of 8 so we can use a full 8-bits, 16-bits or 32-bits bitmask for the lower order bits.

Quoted 7 lines

On 64-bits, using a RCU_GP_CTR_BIT of 32 is also ok. It uses a testl.

To provide 32-bits compability and allow the deepest nesting possible, I think it makes sense to use

/* Use the amount of bits equal to half of the architecture long size */ #define RCU_GP_CTR_BIT (sizeof(long) << 2)

You lost me on this one:

	sizeof(long) << 2 = 0x10

I could believe the following (run on a 32-bit machine):

Quoted 7 lines
	1 << (sizeof(long) * 8 - 1) = 0x80000000

Or, if you were wanting to use a bit halfway up the word, perhaps this:

	1 << (sizeof(long) * 4 - 1) = 0x8000

Or am I confused?

Well, I am at least partly confused. You were wanting a low-order bit, so you want to lose the "- 1" above. Here are some of the possibilities:

	sizeof(long) = 0x4
	sizeof(long) << 2 = 0x10
	1 << (sizeof(long) * 8 - 1) = 0x80000000
	1 << (sizeof(long) * 4) = 0x10000
	1 << (sizeof(long) * 4 - 1) = 0x8000
	1 << (sizeof(long) * 2) = 0x100
	1 << (sizeof(long) * 2 - 1) = 0x80

My guess is that 1 << (sizeof(long) * 4) and 1 << (sizeof(long) * 2) are of the most interest.

Thanx, Paul

#99 lore raw

Re: [ltt-dev] [RFC git tree] Userspace RCU (urcu) for Linux (repost)

Quoted 44 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · Mathieu Desnoyers

* Paul E. McKenney ([email protected]) wrote:

[ . . . ]

Quoted 19 lines
Quoted 5 lines

You know what ? Changing RCU_GP_CTR_BIT to 16 uses a testw %ax, %ax instead of a testb %al, %al. The trick here is that RCU_GP_CTR_BIT must be a multiple of 8 so we can use a full 8-bits, 16-bits or 32-bits bitmask for the lower order bits.

Quoted 7 lines

On 64-bits, using a RCU_GP_CTR_BIT of 32 is also ok. It uses a testl.

To provide 32-bits compability and allow the deepest nesting possible, I think it makes sense to use

/* Use the amount of bits equal to half of the architecture long size */ #define RCU_GP_CTR_BIT (sizeof(long) << 2)

You lost me on this one:

	sizeof(long) << 2 = 0x10

I could believe the following (run on a 32-bit machine):

Quoted 7 lines
	1 << (sizeof(long) * 8 - 1) = 0x80000000

Or, if you were wanting to use a bit halfway up the word, perhaps this:

	1 << (sizeof(long) * 4 - 1) = 0x8000

Or am I confused?

Well, I am at least partly confused. You were wanting a low-order bit, so you want to lose the "- 1" above. Here are some of the possibilities:

	sizeof(long) = 0x4
	sizeof(long) << 2 = 0x10
	1 << (sizeof(long) * 8 - 1) = 0x80000000
	1 << (sizeof(long) * 4) = 0x10000
	1 << (sizeof(long) * 4 - 1) = 0x8000
	1 << (sizeof(long) * 2) = 0x100
	1 << (sizeof(long) * 2 - 1) = 0x80
Quoted 3 lines

My guess is that 1 << (sizeof(long) * 4) and 1 << (sizeof(long) * 2) are of the most interest.

Exactly. I'll change it to :

#define RCU_GP_CTR_BIT (1 << (sizeof(long) << 2))

I somehow thought this define was used as a bit number rather than the bit mask.

Thanks,

Mathieu

Quoted 2 lines

Thanx, Paul

Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
#100 lore raw

Re: [ltt-dev] [RFC git tree] Userspace RCU (urcu) for Linux (repost)

Quoted 51 lines · * Mathieu Desnoyers ([email protected]) wrote:
Quoted 44 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · Mathieu Desnoyers

* Paul E. McKenney ([email protected]) wrote:

[ . . . ]

Quoted 19 lines
Quoted 5 lines

You know what ? Changing RCU_GP_CTR_BIT to 16 uses a testw %ax, %ax instead of a testb %al, %al. The trick here is that RCU_GP_CTR_BIT must be a multiple of 8 so we can use a full 8-bits, 16-bits or 32-bits bitmask for the lower order bits.

Quoted 7 lines

On 64-bits, using a RCU_GP_CTR_BIT of 32 is also ok. It uses a testl.

To provide 32-bits compability and allow the deepest nesting possible, I think it makes sense to use

/* Use the amount of bits equal to half of the architecture long size */ #define RCU_GP_CTR_BIT (sizeof(long) << 2)

You lost me on this one:

	sizeof(long) << 2 = 0x10

I could believe the following (run on a 32-bit machine):

Quoted 7 lines
	1 << (sizeof(long) * 8 - 1) = 0x80000000

Or, if you were wanting to use a bit halfway up the word, perhaps this:

	1 << (sizeof(long) * 4 - 1) = 0x8000

Or am I confused?

Well, I am at least partly confused. You were wanting a low-order bit, so you want to lose the "- 1" above. Here are some of the possibilities:

	sizeof(long) = 0x4
	sizeof(long) << 2 = 0x10
	1 << (sizeof(long) * 8 - 1) = 0x80000000
	1 << (sizeof(long) * 4) = 0x10000
	1 << (sizeof(long) * 4 - 1) = 0x8000
	1 << (sizeof(long) * 2) = 0x100
	1 << (sizeof(long) * 2 - 1) = 0x80
Quoted 3 lines

My guess is that 1 << (sizeof(long) * 4) and 1 << (sizeof(long) * 2) are of the most interest.

Exactly. I'll change it to :

Quoted 9 lines

#define RCU_GP_CTR_BIT (1 << (sizeof(long) << 2))

I somehow thought this define was used as a bit number rather than the bit mask.

Thanks,

Mathieu

It's pushed in the git tree. I also removed an increment in the fast path by initializing urcu_gp_ctr to RCU_GP_COUNT.

It brings benchmarks to :

Time per read : 6.87183 to 7.25318 cycles

So we seem to save about half a cycle to a cycle with this.

Mathieu

Quoted 14 lines
Quoted 4 lines

Thanx, Paul

Signature · 7 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

_______________________________________________
ltt-dev mailing list
[email protected]
http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
#101 lore raw

Re: [ltt-dev] [RFC git tree] Userspace RCU (urcu) for Linux (repost)

Quoted 62 lines · Mathieu Desnoyers
Quoted 51 lines · * Mathieu Desnoyers ([email protected]) wrote:
Quoted 44 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · Mathieu Desnoyers

* Paul E. McKenney ([email protected]) wrote:

[ . . . ]

Quoted 19 lines
Quoted 5 lines

You know what ? Changing RCU_GP_CTR_BIT to 16 uses a testw %ax, %ax instead of a testb %al, %al. The trick here is that RCU_GP_CTR_BIT must be a multiple of 8 so we can use a full 8-bits, 16-bits or 32-bits bitmask for the lower order bits.

Quoted 7 lines

On 64-bits, using a RCU_GP_CTR_BIT of 32 is also ok. It uses a testl.

To provide 32-bits compability and allow the deepest nesting possible, I think it makes sense to use

/* Use the amount of bits equal to half of the architecture long size */ #define RCU_GP_CTR_BIT (sizeof(long) << 2)

You lost me on this one:

	sizeof(long) << 2 = 0x10

I could believe the following (run on a 32-bit machine):

Quoted 7 lines
	1 << (sizeof(long) * 8 - 1) = 0x80000000

Or, if you were wanting to use a bit halfway up the word, perhaps this:

	1 << (sizeof(long) * 4 - 1) = 0x8000

Or am I confused?

Well, I am at least partly confused. You were wanting a low-order bit, so you want to lose the "- 1" above. Here are some of the possibilities:

	sizeof(long) = 0x4
	sizeof(long) << 2 = 0x10
	1 << (sizeof(long) * 8 - 1) = 0x80000000
	1 << (sizeof(long) * 4) = 0x10000
	1 << (sizeof(long) * 4 - 1) = 0x8000
	1 << (sizeof(long) * 2) = 0x100
	1 << (sizeof(long) * 2 - 1) = 0x80
Quoted 3 lines

My guess is that 1 << (sizeof(long) * 4) and 1 << (sizeof(long) * 2) are of the most interest.

Exactly. I'll change it to :

Quoted 9 lines

#define RCU_GP_CTR_BIT (1 << (sizeof(long) << 2))

I somehow thought this define was used as a bit number rather than the bit mask.

Thanks,

Mathieu

Quoted 8 lines

It's pushed in the git tree. I also removed an increment in the fast path by initializing urcu_gp_ctr to RCU_GP_COUNT.

It brings benchmarks to :

Time per read : 6.87183 to 7.25318 cycles

So we seem to save about half a cycle to a cycle with this.

I like it!!! ;-)

Thanx, Paul

#102 lore raw

Re: [ltt-dev] [RFC git tree] Userspace RCU (urcu) for Linux (repost)

In reply to Mathieu Desnoyers
Quoted 49 lines · Mathieu Desnoyers
Quoted 44 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 2 lines · Paul E. McKenney
Quoted 1 line · Mathieu Desnoyers

* Paul E. McKenney ([email protected]) wrote:

[ . . . ]

Quoted 19 lines
Quoted 5 lines

You know what ? Changing RCU_GP_CTR_BIT to 16 uses a testw %ax, %ax instead of a testb %al, %al. The trick here is that RCU_GP_CTR_BIT must be a multiple of 8 so we can use a full 8-bits, 16-bits or 32-bits bitmask for the lower order bits.

Quoted 7 lines

On 64-bits, using a RCU_GP_CTR_BIT of 32 is also ok. It uses a testl.

To provide 32-bits compability and allow the deepest nesting possible, I think it makes sense to use

/* Use the amount of bits equal to half of the architecture long size */ #define RCU_GP_CTR_BIT (sizeof(long) << 2)

You lost me on this one:

	sizeof(long) << 2 = 0x10

I could believe the following (run on a 32-bit machine):

Quoted 7 lines
	1 << (sizeof(long) * 8 - 1) = 0x80000000

Or, if you were wanting to use a bit halfway up the word, perhaps this:

	1 << (sizeof(long) * 4 - 1) = 0x8000

Or am I confused?

Well, I am at least partly confused. You were wanting a low-order bit, so you want to lose the "- 1" above. Here are some of the possibilities:

	sizeof(long) = 0x4
	sizeof(long) << 2 = 0x10
	1 << (sizeof(long) * 8 - 1) = 0x80000000
	1 << (sizeof(long) * 4) = 0x10000
	1 << (sizeof(long) * 4 - 1) = 0x8000
	1 << (sizeof(long) * 2) = 0x100
	1 << (sizeof(long) * 2 - 1) = 0x80
Quoted 3 lines

My guess is that 1 << (sizeof(long) * 4) and 1 << (sizeof(long) * 2) are of the most interest.

Quoted 6 lines

Exactly. I'll change it to :

#define RCU_GP_CTR_BIT (1 << (sizeof(long) << 2))

I somehow thought this define was used as a bit number rather than the bit mask.

Ah! Been there, done that! ;-)

Thanx, Paul

#103 lore raw

Re: [RFC git tree] Userspace RCU (urcu) for Linux (repost)

In reply to Mathieu Desnoyers
Quoted 52 lines · Mathieu Desnoyers
Quoted 51 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 42 lines · Mathieu Desnoyers
Quoted 32 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 23 lines · Paul E. McKenney
Quoted 16 lines · Mathieu Desnoyers

(sorry for repost, I got the ltt-dev email wrong in the previous one)

Hi Paul,

I figured out I needed some userspace RCU for the userspace tracing part of LTTng (for quick read access to the control variables) to trace userspace pthread applications. So I've done a quick-and-dirty userspace RCU implementation.

It works so far, but I have not gone through any formal verification phase. It seems to work on paper, and the tests are also OK (so far), but I offer no guarantee for this 300-lines-ish 1-day hack. :-) If you want to comment on it, it would be welcome. It's a userland-only library. It's also currently x86-only, but only a few basic definitions must be adapted in urcu.h to port it.

Quoted 5 lines

Here is the link to my git tree :

git://lttng.org/userspace-rcu.git

http://lttng.org/cgi-bin/gitweb.cgi?p=userspace-rcu.git;a=summary

Quoted 7 lines

Very cool!!! I will take a look!

I will also point you at a few that I have put together:

git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/perfbook.git

(In the CodeSamples/defer directory.)

Quoted 8 lines

Interesting approach, using the signal to force memory-barrier execution!

o One possible optimization would be to avoid sending a signal to
a blocked thread, as the context switch leading to blocking will have implied a memory barrier -- otherwise it would not be safe to resume the thread on some other CPU. That said, not sure whether checking to see whether a thread is blocked is any faster than sending it a signal and forcing it to wake up.

Quoted 2 lines

I'm not sure it will be any faster, and it could be racy too. How would you envision querying the execution state of another thread ?

For my 64-bit implementation (or the old slow 32-bit version), the trick would be to observe that the thread didn't do an RCU read-side critical section during the past grace period. This observation would be by comparing counters.

Quoted 5 lines
Quoted 3 lines

For the new 32-bit implementation, the only way I know of is to grovel through /proc, which would probably be slower than just sending the signal.

Yes, I guess the signal is not so bad.

Now if there were a /proc entry that listed out the tids of the currently running threads, then it might be possible to do something, especially for applications with many more threads than CPUs.

Quoted 170 lines
Quoted 145 lines
Quoted 7 lines
Quoted 3 lines

Of course, this approach does require that the enclosing application be willing to give up a signal. I suspect that most applications would be OK with this, though some might not.

If we want to make this transparent to the application, we'll have to investigate further in sigaction() and signal() library override I guess.

Certainly seems like it is worth a try!

Quoted 18 lines
Quoted 6 lines

Of course, I cannot resist pointing to an old LKML thread:

http://lkml.org/lkml/2001/10/8/189

But I think that the time is now right. ;-)

Quoted 11 lines

o I don't understand the purpose of rcu_write_lock() and
rcu_write_unlock(). I am concerned that it will lead people to decide that a single global lock must protect RCU updates, which is of course absolutely not the case. I strongly suggest making these internal to the urcu.c file. Yes, uses of urcu_publish_content() would then hit two locks (the internal-to-urcu.c one and whatever they are using to protect their data structure), but let's face it, if you are sending a signal to each and every thread, the additional overhead of the extra lock is the least of your worries.

Quoted 1 line

Ok, just changed it.

Thank you!!!

Quoted 31 lines
Quoted 7 lines

If you really want to heavily optimize this, I would suggest setting up a state machine that permits multiple concurrent calls to urcu_publish_content() to share the same set of signal invocations. That way, if the caller has partitioned the data structure, global locking might be avoided completely (or at least greatly restricted in scope).

That brings an interesting question about urcu_publish_content :

void *urcu_publish_content(void **ptr, void *new)

{
        void *oldptr;

        internal_urcu_lock();
        oldptr = *ptr;
        *ptr = new;

        switch_qparity();
        switch_qparity();
        internal_urcu_unlock();

        return oldptr;
}

Given that we take a global lock around the pointer assignment, we can safely assume, from the caller's perspective, that the update will happen as an "xchg" operation. So if the caller does not have to copy the old data, it can simply publish the new data without taking any lock itself.

Quoted 7 lines

So the question that arises if we want to remove global locking is :
should we change this

        oldptr = *ptr;
        *ptr = new;

for an atomic xchg ?

Makes sense to me!

Quoted 6 lines
Quoted 3 lines

Of course, if updates are rare, the optimization would not help, but in that case, acquiring two locks would be even less of a problem.

I plan updates to be quite rare, but it's always good to foresee how that kind of infrastructure could be misused. :-)

;-) ;-) ;-)

Quoted 6 lines
Quoted 4 lines

o Is urcu_qparity relying on initialization to zero? Or on the

	fact that, for all x, 1-x!=x mod 2^32?  Ah, given that this is
	used to index urcu_active_readers[], you must be relying on
	initialization to zero.

Yes, starts at 0.

Whew! ;-)

Quoted 11 lines
Quoted 9 lines

o In rcu_read_lock(), why is a non-atomic increment of the
urcu_active_readers[urcu_parity] element safe? Are you relying on the compiler generating an x86 add-to-memory instruction?

Ditto for rcu_read_unlock().

Ah, never mind!!! I now see the __thread specification, and the keeping of references to it in the reader_data list.

Exactly :)

Getting old and blind, what can I say?

Quoted 11 lines
Quoted 8 lines

o Combining the equivalent of rcu_assign_pointer() and
synchronize_rcu() into urcu_publish_content() is an interesting approach. Not yet sure whether or not it is a good idea. I guess trying it out on several applications would be the way to find out. ;-)

That said, I suspect that it would be very convenient in a number of situations.

I thought so. It seemed to be a natural way to express it to me. Usage will tell.

;-)

Quoted 11 lines
Quoted 9 lines

o It would be good to avoid having to pass the return value
of rcu_read_lock() into rcu_read_unlock(). It should be possible to avoid this via counter value tricks, though this would add a bit more code in rcu_read_lock() on 32-bit machines. (64-bit machines don't have to worry about counter overflow.)

See the recently updated version of CodeSamples/defer/rcu_nest.[ch] in the aforementioned git archive for a way to do this. (And perhaps I should apply this change to SRCU...)

See my other mail about this.

And likewise!

Quoted 8 lines
Quoted 3 lines

o Your test looks a bit strange, not sure why you test all the
different variables. It would be nice to take a test duration as an argument and run the test for that time.

I made a smaller version which only reads a single variable. I agree that the initial test was a bit strange on that aspect.

I'll do a version which takes a duration as parameter.

I strongly recommend taking a look at my CodeSamples/defer/rcutorture.h file in my git archive:

Quoted 7 lines

git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/perfbook.git

This torture test detects the missing second flip 15 times during a 10-second test on a two-processor machine.

The first part of the rcutorture.h file is performance tests -- search for the string "Stress test" to find the torture test.

I will.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

I killed the test after better part of an hour on my laptop, will retry on a larger machine (after noting the 18 threads created!). (And yes, I first tried Power, which objected strenously to the "mfence" and "lock; incl" instructions, so getting an x86 machine to try on.)

Quoted 8 lines
Quoted 2 lines

That should be easy enough to fix. A bit of primitive cut'n'paste would do.

Yep. Actually, I was considering porting your code into my environment, which already has the Power primitives. Any objections? (This would have the side effect of making a version available via perfbook.git. I would of course add comments referencing your git archive as the official version.)

Quoted 3 lines

Yes, no objection. I am currently looking at your last patch, cleaning it up and making the 32 and 64-bit code the same. Also trying to save a few instructions. I'll keep you posted when it's ready and committed.

Sounds very good! I made absolutely no attempt to micro-optimize, so it would be no surprise to hear that you were able to shave a few more cycles off.

Thanx, Paul

Quoted 21 lines

Mathieu

Quoted 15 lines
Quoted 10 lines
Quoted 5 lines

Again, looks interesting! Looks plausible, although I have not 100% convinced myself that it is perfectly bug-free. But I do maintain a healthy skepticism of purported RCU algorithms, especially ones that I have written. ;-)

That's always good. I also tend to always be very skeptical about what I write and review.

Thanks for the thorough review.

No problem -- it has been quite fun! ;-)

Thanx, Paul

Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
#104 lore raw

Re: [RFC git tree] Userspace RCU (urcu) for Linux (repost)

Quoted 6 lines · Paul E. McKenney
Quoted 1 line · Mathieu Desnoyers

Yes, I guess the signal is not so bad.

Now if there were a /proc entry that listed out the tids of the currently running threads, then it might be possible to do something, especially for applications with many more threads than CPUs.

Do you mean something like: ls /proc/$pid/tasks/*? Or is this not atomic enough?

Bert

#105 lore raw

Re: [RFC git tree] Userspace RCU (urcu) for Linux (repost)

Quoted 11 lines · Bert Wesarg
Quoted 6 lines · Paul E. McKenney
Quoted 1 line · Mathieu Desnoyers

Yes, I guess the signal is not so bad.

Now if there were a /proc entry that listed out the tids of the currently running threads, then it might be possible to do something, especially for applications with many more threads than CPUs.

Do you mean something like: ls /proc/$pid/tasks/*? Or is this not atomic enough?

Won't that give me all the threads rather than only the ones currently running?

Thanx, Paul

#106 lore raw

Re: [RFC git tree] Userspace RCU (urcu) for Linux (repost)

Quoted 10 lines · Paul E. McKenney
Quoted 9 lines · Bert Wesarg
Quoted 6 lines · Paul E. McKenney
Quoted 1 line · Mathieu Desnoyers

Yes, I guess the signal is not so bad.

Now if there were a /proc entry that listed out the tids of the currently running threads, then it might be possible to do something, especially for applications with many more threads than CPUs.

Quoted 5 lines
Quoted 2 lines

Do you mean something like: ls /proc/$pid/tasks/*? Or is this not atomic enough?

Won't that give me all the threads rather than only the ones currently running?

What do you mean by 'running'?

Bert

Quoted 3 lines

Thanx, Paul

#107 lore raw

Re: [RFC git tree] Userspace RCU (urcu) for Linux (repost)

Quoted 12 lines · Bert Wesarg
Quoted 10 lines · Paul E. McKenney
Quoted 9 lines · Bert Wesarg
Quoted 6 lines · Paul E. McKenney
Quoted 1 line · Mathieu Desnoyers

Yes, I guess the signal is not so bad.

Now if there were a /proc entry that listed out the tids of the currently running threads, then it might be possible to do something, especially for applications with many more threads than CPUs.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Do you mean something like: ls /proc/$pid/tasks/*? Or is this not atomic enough?

Won't that give me all the threads rather than only the ones currently running?

What do you mean by 'running'?

Sitting on a CPU and executing, as opposed to blocked or preempted.

It is pretty easy to scan the running tasks within the kernel, but I don't know of an efficient way to do it from user mode. The only way I know of would be to cat out the /proc/$pid/tasks/*/status (IIRC) and look for the task state.

Thanx, Paul

#108 lore raw

Re: [RFC git tree] Userspace RCU (urcu) for Linux (repost)

Quoted 19 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 18 lines · Bert Wesarg
Quoted 15 lines · Paul E. McKenney
Quoted 11 lines · Bert Wesarg
Quoted 6 lines · Paul E. McKenney
Quoted 1 line · Mathieu Desnoyers

Yes, I guess the signal is not so bad.

Now if there were a /proc entry that listed out the tids of the currently running threads, then it might be possible to do something, especially for applications with many more threads than CPUs.

Do you mean something like: ls /proc/$pid/tasks/*? Or is this not atomic enough?

Won't that give me all the threads rather than only the ones currently running?

Quoted 9 lines
Quoted 1 line

What do you mean by 'running'?

Sitting on a CPU and executing, as opposed to blocked or preempted.

It is pretty easy to scan the running tasks within the kernel, but I don't know of an efficient way to do it from user mode. The only way I know of would be to cat out the /proc/$pid/tasks/*/status (IIRC) and look for the task state.

The thing I dislike about this approach is the non-portability. Ideally, if we want to integrate urcu to pthreads, we should also aim at BSD-based OSes.

Mathieu

Quoted 2 lines

Thanx, Paul

Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
#109 lore raw

Re: [RFC git tree] Userspace RCU (urcu) for Linux (repost)

Quoted 24 lines · Mathieu Desnoyers
Quoted 23 lines · * Paul E. McKenney ([email protected]) wrote:
Quoted 12 lines · Bert Wesarg
Quoted 10 lines · Paul E. McKenney
Quoted 9 lines · Bert Wesarg
Quoted 6 lines · Paul E. McKenney
Quoted 1 line · Mathieu Desnoyers

Yes, I guess the signal is not so bad.

Now if there were a /proc entry that listed out the tids of the currently running threads, then it might be possible to do something, especially for applications with many more threads than CPUs.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Do you mean something like: ls /proc/$pid/tasks/*? Or is this not atomic enough?

Won't that give me all the threads rather than only the ones currently running?

What do you mean by 'running'?

Sitting on a CPU and executing, as opposed to blocked or preempted.

Quoted 8 lines
Quoted 4 lines

It is pretty easy to scan the running tasks within the kernel, but I don't know of an efficient way to do it from user mode. The only way I know of would be to cat out the /proc/$pid/tasks/*/status (IIRC) and look for the task state.

The thing I dislike about this approach is the non-portability. Ideally, if we want to integrate urcu to pthreads, we should also aim at BSD-based OSes.

But it could be portable. If the /proc file in question could not be opened (as would be the case on BSDs), you just send the signal to all the tasks.

Thanx, Paul

#110 lore raw

Re: [RFC git tree] Userspace RCU (urcu) for Linux (repost)

In reply to Paul E. McKenney
Quoted 16 lines · Paul E. McKenney
Quoted 15 lines · Bert Wesarg
Quoted 13 lines · Paul E. McKenney
Quoted 11 lines · Bert Wesarg
Quoted 6 lines · Paul E. McKenney
Quoted 1 line · Mathieu Desnoyers

Yes, I guess the signal is not so bad.

Now if there were a /proc entry that listed out the tids of the currently running threads, then it might be possible to do something, especially for applications with many more threads than CPUs.

Do you mean something like: ls /proc/$pid/tasks/*? Or is this not atomic enough?

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Won't that give me all the threads rather than only the ones currently running?

What do you mean by 'running'?

Sitting on a CPU and executing, as opposed to blocked or preempted.

Ok, me too.

Quoted 5 lines

It is pretty easy to scan the running tasks within the kernel, but I don't know of an efficient way to do it from user mode. The only way I know of would be to cat out the /proc/$pid/tasks/*/status (IIRC) and look for the task state.

Yes, me too.

Bert

Quoted 3 lines

Thanx, Paul

#111 lore raw

Re: [RFC git tree] Userspace RCU (urcu) for Linux (repost)

Quoted 25 lines · Bert Wesarg
Quoted 16 lines · Paul E. McKenney
Quoted 15 lines · Bert Wesarg
Quoted 13 lines · Paul E. McKenney
Quoted 11 lines · Bert Wesarg
Quoted 6 lines · Paul E. McKenney
Quoted 1 line · Mathieu Desnoyers

Yes, I guess the signal is not so bad.

Now if there were a /proc entry that listed out the tids of the currently running threads, then it might be possible to do something, especially for applications with many more threads than CPUs.

Do you mean something like: ls /proc/$pid/tasks/*? Or is this not atomic enough?

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Won't that give me all the threads rather than only the ones currently running?

What do you mean by 'running'?

Sitting on a CPU and executing, as opposed to blocked or preempted.

Quoted 8 lines

Ok, me too.

Quoted 4 lines

It is pretty easy to scan the running tasks within the kernel, but I don't know of an efficient way to do it from user mode. The only way I know of would be to cat out the /proc/$pid/tasks/*/status (IIRC) and look for the task state.

Yes, me too.

I was afraid of that... ;-)

Do you believe that something like a /proc/runningtids that listsd currently running tasks be useful in general? Or just to this algorithm?

Thanx, Paul

#112 lore raw

Re: [RFC git tree] Userspace RCU (urcu) for Linux (repost)

In reply to Mathieu Desnoyers
Quoted 11 lines · Mathieu Desnoyers

I figured out I needed some userspace RCU for the userspace tracing part of LTTng (for quick read access to the control variables) to trace userspace pthread applications. So I've done a quick-and-dirty userspace RCU implementation.

It works so far, but I have not gone through any formal verification phase. It seems to work on paper, and the tests are also OK (so far), but I offer no guarantee for this 300-lines-ish 1-day hack. :-) If you want to comment on it, it would be welcome. It's a userland-only library. It's also currently x86-only, but only a few basic definitions must be adapted in urcu.h to port it.

I have actually been fiddling with an RCU-esque design for a multithreaded event-driven userspace server process. Essentially all threads using RCU-protected data run through a central event loop which drives my entirely-userspace RCU state machine. I actually have a cooperative scheduler for groups of events to allow me to load-balance a large number of clients without the full overhead of a kernel thread per client. This does rely on clock_gettime(CLOCK_THREAD_CPUTIME_ID) returning a useful monotonic value, however.

By building the whole internal system as an event-driven-state-machine, I don't need to keep a stack for blocked events. The events which do large amounts of work call a "need_resched()"-ish function every so often, and if it returns true they return up the stack. Relatively few threads (1 per physical CPU, plus a few for blocking event polling) are needed to completely saturate the system.

For RCU I simply treat event-handler threads the way the kernel treats CPUs, I report a Quiescent State every so often in-between processing events.

The event-handling mechanism is entirely agnostic to the way that events are generated. It has built-in mechanisms for FD, signal, and AIO-based events, and it's trivial to add another event-polling thread for GTK/Qt/etc.

I'm still only halfway through laying out the framework for this library, but once it's done I'll make sure to post it somewhere for those who are interested.

Cheers,
Kyle Moffett

#113 lore raw

Re: [RFC git tree] Userspace RCU (urcu) for Linux (repost)

Quoted 36 lines · * Kyle Moffett ([email protected]) wrote:
Quoted 11 lines · Mathieu Desnoyers

I figured out I needed some userspace RCU for the userspace tracing part of LTTng (for quick read access to the control variables) to trace userspace pthread applications. So I've done a quick-and-dirty userspace RCU implementation.

It works so far, but I have not gone through any formal verification phase. It seems to work on paper, and the tests are also OK (so far), but I offer no guarantee for this 300-lines-ish 1-day hack. :-) If you want to comment on it, it would be welcome. It's a userland-only library. It's also currently x86-only, but only a few basic definitions must be adapted in urcu.h to port it.

I have actually been fiddling with an RCU-esque design for a multithreaded event-driven userspace server process. Essentially all threads using RCU-protected data run through a central event loop which drives my entirely-userspace RCU state machine. I actually have a cooperative scheduler for groups of events to allow me to load-balance a large number of clients without the full overhead of a kernel thread per client. This does rely on clock_gettime(CLOCK_THREAD_CPUTIME_ID) returning a useful monotonic value, however.

By building the whole internal system as an event-driven-state-machine, I don't need to keep a stack for blocked events. The events which do large amounts of work call a "need_resched()"-ish function every so often, and if it returns true they return up the stack. Relatively few threads (1 per physical CPU, plus a few for blocking event polling) are needed to completely saturate the system.

For RCU I simply treat event-handler threads the way the kernel treats CPUs, I report a Quiescent State every so often in-between processing events.

Quoted 9 lines

The event-handling mechanism is entirely agnostic to the way that events are generated. It has built-in mechanisms for FD, signal, and AIO-based events, and it's trivial to add another event-polling thread for GTK/Qt/etc.

I'm still only halfway through laying out the framework for this library, but once it's done I'll make sure to post it somewhere for those who are interested.

That would be interesting to look at. It would indeed be very efficient at the reader site, because no barriers would be required. However, it might not be appropriate for use-cases like userspace tracing, where we ideally want to add tracing functionnality to applications as a library, without requiring to modify the application behavior (e.g. adding a "quiescent state" call into the application loop). I also think Paul already has such application quiescent state notification implementation in the links he gave us, we might want to compare those two.

Mathieu

Quoted 3 lines

Cheers,
Kyle Moffett

Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
#114 lore raw

Re: [RFC git tree] Userspace RCU (urcu) for Linux (repost)

In reply to Kyle Moffett
Quoted 36 lines · Kyle Moffett
Quoted 11 lines · Mathieu Desnoyers

I figured out I needed some userspace RCU for the userspace tracing part of LTTng (for quick read access to the control variables) to trace userspace pthread applications. So I've done a quick-and-dirty userspace RCU implementation.

It works so far, but I have not gone through any formal verification phase. It seems to work on paper, and the tests are also OK (so far), but I offer no guarantee for this 300-lines-ish 1-day hack. :-) If you want to comment on it, it would be welcome. It's a userland-only library. It's also currently x86-only, but only a few basic definitions must be adapted in urcu.h to port it.

I have actually been fiddling with an RCU-esque design for a multithreaded event-driven userspace server process. Essentially all threads using RCU-protected data run through a central event loop which drives my entirely-userspace RCU state machine. I actually have a cooperative scheduler for groups of events to allow me to load-balance a large number of clients without the full overhead of a kernel thread per client. This does rely on clock_gettime(CLOCK_THREAD_CPUTIME_ID) returning a useful monotonic value, however.

By building the whole internal system as an event-driven-state-machine, I don't need to keep a stack for blocked events. The events which do large amounts of work call a "need_resched()"-ish function every so often, and if it returns true they return up the stack. Relatively few threads (1 per physical CPU, plus a few for blocking event polling) are needed to completely saturate the system.

For RCU I simply treat event-handler threads the way the kernel treats CPUs, I report a Quiescent State every so often in-between processing events.

Quoted 8 lines

The event-handling mechanism is entirely agnostic to the way that events are generated. It has built-in mechanisms for FD, signal, and AIO-based events, and it's trivial to add another event-polling thread for GTK/Qt/etc.

I'm still only halfway through laying out the framework for this library, but once it's done I'll make sure to post it somewhere for those who are interested.

I look forward to seeing it! Perhaps user-level RCU is an idea whose time has come? ;-)

Thanx, Paul

#115 lore raw
In reply to Mathieu Desnoyers
Quoted 14 lines · Mathieu Desnoyers

Hi Paul,

I figured out I needed some userspace RCU for the userspace tracing part of LTTng (for quick read access to the control variables) to trace userspace pthread applications. So I've done a quick-and-dirty userspace RCU implementation.

It works so far, but I have not gone through any formal verification phase. It seems to work on paper, and the tests are also OK (so far), but I offer no guarantee for this 300-lines-ish 1-day hack. :-) If you want to comment on it, it would be welcome. It's a userland-only library. It's also currently x86-only, but only a few basic definitions must be adapted in urcu.h to port it.

Quoted 6 lines

Here is the link to my git tree :

git://lttng.org/userspace-rcu.git

http://lttng.org/cgi-bin/gitweb.cgi?p=userspace-rcu.git;a=summary

Really interesting, thanks.

But you should use pthread_equal() for you equality test of pthread_t.

Regards,
Bert

Quoted 3 lines

Thanks,

Mathieu

#116 lore raw
Quoted 18 lines · * Bert Wesarg ([email protected]) wrote:
Quoted 16 lines · Mathieu Desnoyers

Hi Paul,

I figured out I needed some userspace RCU for the userspace tracing part of LTTng (for quick read access to the control variables) to trace userspace pthread applications. So I've done a quick-and-dirty userspace RCU implementation.

It works so far, but I have not gone through any formal verification phase. It seems to work on paper, and the tests are also OK (so far), but I offer no guarantee for this 300-lines-ish 1-day hack. :-) If you want to comment on it, it would be welcome. It's a userland-only library. It's also currently x86-only, but only a few basic definitions must be adapted in urcu.h to port it.

Here is the link to my git tree :

Quoted 8 lines
Quoted 4 lines

git://lttng.org/userspace-rcu.git

http://lttng.org/cgi-bin/gitweb.cgi?p=userspace-rcu.git;a=summary

Really interesting, thanks.

But you should use pthread_equal() for you equality test of pthread_t.

It's merged, thanks !

Mathieu

Quoted 7 lines

Regards,
Bert

Quoted 3 lines

Thanks,

Mathieu

Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68