[coroutine] Assembler snippet for linux x86_64
Hi folks, First of all I'd like to thank Giovanni P. Deretta for the brilliant idea and implementation of courotines [1]. Unfortunately, coroutines haven't been reviewed and included into the official boost repository yet but I believe it's just a matter of time. I downloaded the latest version "boost-coroutine-2009-04-30.tar.gz" from the boost vault[2] and it seems to build/run just fine on linux x86. However trying to build it on x86_64 gave me a compile time error - "This file is for x86 CPUs only" in swapcontext.cpp, since there is a #if !defined(i386) guard which produces this error. I was naive and tried to change "#if !defined(i386)" to "if !defined(i386) && !defined(__x86_64__)" in hope it would "just work" for x86_64...well, it didn't ;) I'm not that good in assembler(I have only basic knowledge), maybe someone stumbled upon the same problem and has a working patch for x86_64? Or maybe someone can give some pointers on how to make couroutines x86_64 compatible? IMHO, it shouldn't be very hard and I can try to do it myself, I just don't know where to start :) Thanks a lot in advance. [1] http://www.crystalclearsoftware.com/soc/coroutine/index.html [2] http://www.boostpro.com/vault/index.php?direction=0&order=&directory=Concurrent%20Programming& -- Best regards, Pavel
However trying to build it on x86_64 gave me a compile time error - "This file is for x86 CPUs only" in swapcontext.cpp, since there is a #if !defined(i386) guard which produces this error.
Sorry, folks, I'm replying to myself - the problem was gone once I excluded swapcontext.cpp from my custom build process. Looks like coroutine cleverly fallbacks to POSIX makecontext and friends for anything non-linux-x86. Anyway, I believe it would be great to support linux x86_64 with a faster assembler implementation of swapcontext. I'll play around with the code and report back(if I'm lucky :) ) -- Best regards, Pavel
On Tue, Jul 21, 2009 at 03:57:33PM +0400, Pavel Shevaev wrote:
However trying to build it on x86_64 gave me a compile time error - "This file is for x86 CPUs only" in swapcontext.cpp, since there is a #if !defined(i386) guard which produces this error.
Sorry, folks, I'm replying to myself - the problem was gone once I excluded swapcontext.cpp from my custom build process. Looks like coroutine cleverly fallbacks to POSIX makecontext and friends for anything non-linux-x86. Anyway, I believe it would be great to support linux x86_64 with a faster assembler implementation of swapcontext. I'll play around with the code and report back(if I'm lucky :) )
Download this code: http://simula.no/research/networks/software/nornir.tar.bz2/view (all files are under the same license as written in the COPYRIGHT file in the top-level directory) The functions you're after are: ctx_init_internal() and ctx_swap_internal() in nornir/kahn/ctx_amd64.S. For each new coroutine, you have to manually allocate context and stack; for an example of how this is done, see the ctx_make() function in platform_ux.cc. The ''main'' coroutine needs just the space for saving the registers, as the OS takes care of allocating the stack. The *_internal() functions operate just on the regs field of the mctx_t structure defined in platform_ux.h. The ctx_init() function takes the TOP address of the stack, as it grows down on AMD64. This should be enough to get you started with integrating the code in boost.coroutine; if you have some questions, just ask.
However trying to build it on x86_64 gave me a compile time error - "This file is for x86 CPUs only" in swapcontext.cpp, since there is a #if !defined(i386) guard which produces this error.
Sorry, folks, I'm replying to myself - the problem was gone once I excluded swapcontext.cpp from my custom build process. Looks like coroutine cleverly fallbacks to POSIX makecontext and friends for anything non-linux-x86. Anyway, I believe it would be great to support linux x86_64 with a faster assembler implementation of swapcontext. I'll play around with the code and report back(if I'm lucky :) )
See attached the version of Linux64Bit support we're using in house. You'll need to do a bit of preprocessor fiddling to integrate that into your distribution, but that shouldn't be too difficult (I'm attaching my default_context_impl.hpp as a guideline). HTH Regards Hartmut
See attached the version of Linux64Bit support we're using in house. You'll need to do a bit of preprocessor fiddling to integrate that into your distribution, but that shouldn't be too difficult (I'm attaching my default_context_impl.hpp as a guideline).
Thanks a lot for the quick reply, however, I believe swapcontext64.cpp attachment with actual assembler snippet is missing :) -- Best regards, Pavel
See attached the version of Linux64Bit support we're using in house. You'll need to do a bit of preprocessor fiddling to integrate that into your distribution, but that shouldn't be too difficult (I'm attaching my default_context_impl.hpp as a guideline).
Thanks a lot for the quick reply, however, I believe swapcontext64.cpp attachment with actual assembler snippet is missing :)
I'm sorry, forgot about this. Attached now. Regards Hartmut
participants (3)
-
Hartmut Kaiser
-
Pavel Shevaev
-
Zeljko Vrba