Skip to contentSkip to conversation

Removing call to function pointer in inner loop of copy_from_user()

uml-devel Blaisorblade 2 participants 5 messages May 16, 2005 User-mode Linux (UML)

lore
Share & tools
lore
#0 lore raw

copy_from_user() loops, in SKAS mode, calls do_op inside the inner loop; do_op acts on 4k at once, so with modern pipelines, the potential cost of the function call can be very big.

Beyond that, we also call setjmp_wrapper, which simply puts a sigjmp_buf on the stack.

Wouldn't the code be cleaner if we rip that out, together with the va_arg() calls, and do everything inside do_buffer_op? Doh, those are from userspace headers. However it looks they would be includable from kernel code (no reference to kernel headers), by adding them at the end of the include search path.

Also, could I then turn it into a macro taking a param, and then inline the do_op calls (which are very little ones), or at least turn them into normal calls (i.e. faster ones). I feel like the resulting code could even be cleaner to read. Yes, more wasted space, but I think we win in the trade-off.

What's your opinion? I'm ready to work on this.

Signature · 17 lines
Paolo Giarrusso, aka Blaisorblade
Skype user "PaoloGiarrusso"
Linux registered user n. 292729
http://www.user-mode-linux.org/~blaisorblade




-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7393&alloc_id=16281&op=click
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#1 lore raw
Quoted 7 lines · Blaisorblade

copy_from_user() loops, in SKAS mode, calls do_op inside the inner loop; do_op acts on 4k at once, so with modern pipelines, the potential cost of the function call can be very big.

Beyond that, we also call setjmp_wrapper, which simply puts a sigjmp_buf on the stack.

Quoted 7 lines

Wouldn't the code be cleaner if we rip that out, together with the va_arg() calls, and do everything inside do_buffer_op? Doh, those are from userspace headers. However it looks they would be includable from kernel code (no reference to kernel headers), by adding them at the end of the include search path.

What's your opinion? I'm ready to work on this.

I was unhappy about adding the setjmp there, but it turns out that the kernel data might not be present and so can segfault. So, when that happens, we need to get out of there and return an error, and the way that's done is by the page fault handler longjmping back out.

If you can think of a better way to do it, go ahead.

Jeff

-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes Want to be the first software developer in space? Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7393&alloc_id=16281&op=click
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#2 lore raw
Quoted 14 lines · Jeff Dike
Quoted 12 lines · Blaisorblade

copy_from_user() loops, in SKAS mode, calls do_op inside the inner loop; do_op acts on 4k at once, so with modern pipelines, the potential cost of the function call can be very big.

Beyond that, we also call setjmp_wrapper, which simply puts a sigjmp_buf on the stack.

Wouldn't the code be cleaner if we rip that out, together with the va_arg() calls, and do everything inside do_buffer_op? Doh, those are from userspace headers. However it looks they would be includable from kernel code (no reference to kernel headers), by adding them at the end of the include search path.

Quoted 6 lines
Quoted 1 line

What's your opinion? I'm ready to work on this.

I was unhappy about adding the setjmp there, but it turns out that the kernel data might not be present and so can segfault. So, when that happens, we need to get out of there and return an error, and the way that's done is by the page fault handler longjmping back out.

Yes, I remember it, I worked with you on diagnosing the /dev/kmem crash.

Quoted 1 line

If you can think of a better way to do it, go ahead.

I could move maybe move sigsetjmp to kernelspace code; however, another possibility would be to use the exception handler tables we've always supported without using them (only drawback is that the code *must* be inlined, and possibly the need for some assembler code, which however is probably avoidable).

Signature · 17 lines
Paolo Giarrusso, aka Blaisorblade
Skype user "PaoloGiarrusso"
Linux registered user n. 292729
http://www.user-mode-linux.org/~blaisorblade




-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7412&alloc_id=16344&op=click
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#3 lore raw
Quoted 1 line · Blaisorblade

I could move maybe move sigsetjmp to kernelspace code;

How are you going to get a definition of jmp_buf in there?

Quoted 5 lines

however, another
possibility would be to use the exception handler tables we've always supported without using them (only drawback is that the code *must* be inlined, and possibly the need for some assembler code, which however is probably avoidable).

Maybe. That's worth looking in to. I've used the setjmp scheme in preference to that because it's portable, but maybe we should switch back in some places.

Jeff

-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes Want to be the first software developer in space? Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7412&alloc_id=16344&op=click
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#4 lore raw
Quoted 4 lines · Jeff Dike
Quoted 1 line · Blaisorblade

I could move maybe move sigsetjmp to kernelspace code;

How are you going to get a definition of jmp_buf in there?

I actually want to include the headers. Not that I would refuse to copy verbatim from headers (binary compatibility allows that to work as long we use the same host OS / libc combination).

Quoted 9 lines
Quoted 5 lines

however, another
possibility would be to use the exception handler tables we've always supported without using them (only drawback is that the code *must* be inlined, and possibly the need for some assembler code, which however is probably avoidable).

Maybe. That's worth looking in to. I've used the setjmp scheme in preference to that because it's portable, but maybe we should switch back in some places.

Yes, more portable but slightly slower. Also, if you get the compiler to inline the code anyway, you only write pseudo-ops in assembler, so that's no problem.

Signature · 17 lines
Paolo Giarrusso, aka Blaisorblade
Skype user "PaoloGiarrusso"
Linux registered user n. 292729
http://www.user-mode-linux.org/~blaisorblade




-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7412&alloc_id=16344&op=click
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel