> On Jan 17, 2016, at 8:53 AM, Eliot Miranda <[hidden email]> wrote: > > Hi Levente, > >>> On Jan 17, 2016, at 7:30 AM, Levente Uzonyi <[hidden email]> wrote: >>> >>> On Sat, 16 Jan 2016, Eliot Miranda wrote: >>> >>> On Sat, Jan 16, 2016 at 4:37 PM, Levente Uzonyi <[hidden email]> wrote: >>> >>> On Sat, 16 Jan 2016, Mariano Martinez Peck wrote: >>> >>> (Still no quote.) >>> >>> How will you read the output of the process without having your image's process blocked in the FFI callout? >>> How will you make sure that writes to input of the process won't block the FFI callout? >>> This presupposes the threaded FFI. The threaded FFI allows the VM to make any number of blocking calls, adding a new thread to run the VM whenever the VM is stalled when the heartbeat beats. hence one can freely read and write to/from i/o blocking i/o streams >>> (including pipes and sockets) or blocking database connexions, etc, all without stating that the FFI call must be done in a special way, since all calls through the FFI can block without blocking the VM. >> >> I think it was you who said (in a discussion with Craig) that the threaded FFI was not production ready. Is it ready for produciton now? > > No, but I expect this is the year it will be. Spur provides pinning, so the VM infrastructure is there. The Pharo community plus some commercial relationships that have developed are providing funding. Esteban Lorenzano and I want to collaborate on this and I hope to get help from some other people, such as Ronie Salgado. And Mariano is working on an important part of the problem. So I feel there's sufficient momentum for us to realize the threaded FFI this year. and when Craig Latta tried to use it late last year it worked up to a point. The thing that didn't work was callbacks from foreign threads. So it looks like the core threading code is not too far away from working. Another really important part, bigger than threading, is marshaling. Being able to handle the full x85_64 abi requires a better approach than interpreting tops signatures. Igor's NativeBoost gave an example of how to generate marshaling machine code, but alas only for x86. But Sista includes an extensible bytecode set for arbitrary instructions. Sista is close to production, and we know the bytecode set works. So the plan is to use these bytecodes to do the marshaling. That neatly solves the problems of a) associating marshaling machine code with a method and b) marshaling in an interpreted stack VM, since the bytecode set works in any Cog VM. So the plan is to write an ABI compiler from C signatures to marshaling code to replace the interpreted FFI plugin. So this year I hope we will have an excellent high performance FFI. >> Levente > > _,,,^..^,,,_ (phone) > >>> Note that the scheme is also amenable to plugins, but the plugins must be rewritten to include the release vm/acquire vm calls around a blocking call. With the threaded VM the FFI includes these calls around every FFI call. >>> HTH >>> _,,,^..^,,,_ >>> best, Eliot |
In reply to this post by Levente Uzonyi
On Sun, Jan 17, 2016 at 12:28 PM, Levente Uzonyi <[hidden email]> wrote:
Well, the discussion of FFI vs Plugin, is what Git vs MC is in Pharo mailing list. It has been discussed a million times and both approaches have pros and cons. If you want, Google a bit, but I won't loose my energy yet again in such discussion. Based on your answers, I assume that Yes, and this has nothing to do wether it is FFI or plugin. OSProcess dose use dup2 too. - You have the drawbacks of non-blocking streams: polling, repeated write attempts. Yes, but it even seems it's not a big deal for most users having non-blocking streams with image-based polling. This is confirmed but the survey I made weeks ago (40 answers so far). In any case, thanks to Eliot, Esteban, and many others, we are hoping to have threaded FFI callout soon. So that will allow blocking threaded callouts. And I wonder...wouldn't be even easier this with FFI rather than plugin? Once the threaded FFI callouts are done, then I have nothing special to do. Contrary, OSProcess plugin should understand and know how to mange the threads I imagine for that, right? - You have to solve the problem of different platforms (constant values, library names and paths, etc), something that OSProcess handles by default. Sure, and that was the whole point of my answer to Eliot proposal. But you are missing something. If we can make such a solution, that would be general, for every possible FFI tool. NOT ONLY for my OSProcess alternative. All this makes me wonder: Already answered. - If you decide to make a plugin as well to tackle some of the problems, why make it a mixed solution instead of plugin-only? If we can make this tool for the constants, the only thing I would need from a custom plugin or OSProcess is the custom handler (semaphore) to receive signals. And that's only if you want to catch SIGCHLD in order to collect exit status. If the user chooses to do a polling wait, then that's not even necessary. |
In reply to this post by Eliot Miranda-2
On 17 Jan 2016, at 18:04, Eliot Miranda <[hidden email]> wrote: So this year I hope we will have an excellent high performance FFI. this will be an exciting year. BTW when ronie will arrive here we will plan some skype session with you. Stef |
On Sun, Jan 17, 2016 at 12:13 PM, stephane ducasse <[hidden email]> wrote:
Yes, if we're to pull this off we have all to be working with a coherent shared plan and to keep in communication. This is exciting. I've been dreaming of this FFI for a while now :-). _,,,^..^,,,_ best, Eliot |
In reply to this post by Eliot Miranda-2
> ...when Craig Latta tried to use [Alien FFI] late last year it worked > up to a point. The thing that didn't work was callbacks from foreign > threads. So it looks like the core threading code is not too far > away from working. (Yes, it seemed close enough that I spent several hours debugging, trying to get it the rest of the way. I ran out of time, so I wrote a wrapper C library around the one I wanted to use, with threaded C callback functions that signalled Smalltalk semaphores on which my synchronous-FFI Smalltalk process waited. A hack, but it worked fine and was simple.) -C -- Craig Latta netjam.org +31 6 2757 7177 (SMS ok) + 1 415 287 3547 (no SMS) |
so I assume that means callbacks from inside C threads works fine which make it more than enough at least for now. Does that mean that the VM will implement a real threading mechanism ? On Mon, Jan 18, 2016 at 1:11 PM Craig Latta <[hidden email]> wrote:
|
Hi Dimitris,
|
AFAIK OS thread are capable of being assigned to multiple cores thus offering real concurency, thus I presume your native threads are not OS threads. So the VM run on one thread but can communicate with other threads ? Does that apply to multithreaded VM ? On Mon, Jan 18, 2016 at 2:02 PM Eliot Miranda <[hidden email]> wrote:
|
Hi Dimitris,
So this is real multi threading without concurrency as I said.
|
ah ok now its crystal clear thanks for the explanation. On Mon, Jan 18, 2016 at 3:11 PM Eliot Miranda <[hidden email]> wrote:
|
Hi Eliot, Ok, I started from the first step and I am able to type a C program that would export the STON I need. This is all hardcoded for the moment and not autogenerated. The question I have now is....do you think I should use "cmake" for managing the compilation of this C program (later to be autogenerated) ??? If not, what other choice I have? Thanks! On Mon, Jan 18, 2016 at 10:16 AM, Dimitris Chloupis <[hidden email]> wrote:
|
On Wed, Jan 20, 2016 at 10:55 AM, Mariano Martinez Peck <[hidden email]> wrote:
Cmake is overkill. You only have to compile one file with very simple flags. So for now use the old OSProcess (or compile manually) but... once you have your own OSProcess then the right way is to compile it using your new OSProcess. You have to require that the user put the C compiler in their path, but everything else you have in the pragmas. e.g. you're only doing cc -m32 -o MYSQLInterface.mac32 MYSQLInterface.mac32.c ./MYSQLInterface.mac32
_,,,^..^,,,_ best, Eliot |
On Wed, Jan 20, 2016 at 5:33 PM, Eliot Miranda <[hidden email]> wrote:
Thanks Eliot, I had the same feeling. Thanks for confirming. BTW, let me ask...I have already starting coding this so I have to give a name to the project so that I can create a repo and start committing :) (even if at the end this is merged in FFI package or whatever) Do you have a good name in mind? I would like FFI in it's name, but not SharedPool (that's a low level impl detail). I don't want to couple with "Constants" either as it may help us with other stuff like sizeof() etc. I guess it should be something related to FFIPreprocessorInfoExtractor or something like that. BTW2: Yes, I have my own "OSProcess" working, called OSSubprocess: https://github.com/marianopeck/OSSubprocess/ Thanks!!
|
In reply to this post by Eliot Miranda-2
Hi Eliot, OK, I have currently a very first prototype where I can autogenerate the C file from a FFISharedPool subclass, compile it, run it and get the ston file output. Please, read below.
I was thinking the following. Having to distribute the FFI wrapper (take as an example the myself wrapper) with the .ston files is a bit of a pain with MC. So I was thinking...what if FFISharedPool has all the machinery to allow FFI lib wrapper developer (the developer of the MySQL wrapper), to autogenerate the ston file as we said, BUT, the ston file is stored as methods in the MYSQLInterface subclass? Probably under a "autogenerated" protocol. That way, it's very easy to distribute and in addition, at system startup it's easier to "search" for the "ston files". The only drawback is the for very large ston files MC will suffer a bit.. but.. Thoughts?
|
In reply to this post by Mariano Martinez Peck
On Thu, Jan 21, 2016 at 9:07 AM, Mariano Martinez Peck <[hidden email]> wrote: > On Wed, Jan 20, 2016 at 5:33 PM, Eliot Miranda <[hidden email]> wrote: >> >> >> >> >> On Wed, Jan 20, 2016 at 10:55 AM, Mariano Martinez Peck <[hidden email]> wrote: >>> >>> >>> Hi Eliot, >>> >>> Ok, I started from the first step and I am able to type a C program that would export the STON I need. >>> This is all hardcoded for the moment and not autogenerated. >>> The question I have now is....do you think I should use "cmake" for managing the compilation of this C program (later to be autogenerated) ??? >>> If not, what other choice I have? >> >> >> Cmake is overkill. You only have to compile one file with very simple flags. So for now use the old OSProcess (or compile manually) but... once you have your own OSProcess then the right way is to compile it using your new OSProcess. You have to require that the user put the C compiler in their path, but everything else you have in the pragmas. e.g. you're only doing >> >> cc -m32 -o MYSQLInterface.mac32 MYSQLInterface.mac32.c >> ./MYSQLInterface.mac32 >> > > > Thanks Eliot, > > I had the same feeling. Thanks for confirming. > > BTW, let me ask...I have already starting coding this so I have to give a name to the project so that I can create a repo and start committing :) > (even if at the end this is merged in FFI package or whatever) > Do you have a good name in mind? I would like FFI in it's name, but not SharedPool (that's a low level impl detail). I don't want to couple with "Constants" either as it may help us with other stuff like sizeof() etc. I guess it should be something related to FFIPreprocessorInfoExtractor or something like that. How about: * FFIDefines * FFIHeaders * FFIDefs * FFIDecl * FFIDeclarations or do like other language FFIs and distinguish that this is a "C" interface... * CDeclaration * FFICDecl btw, only slightly off topic... I just read something very interesting about using the host** finalization and garbage collector to free guest** malloc'd memory to reduce memory leak. Scroll down to "Memory management: let the garbage collector do the work" http://book.realworldhaskell.org/read/interfacing-with-c-the-ffi.html (**are these reaonble terms to use here?) Note: I don't actually know Haskell. I only got distracted and bumped into this while looking for other info. Lua seems to have something similar... cdata = ffi.gc(cdata, finalizer) http://luajit.org/ext_ffi_api.html https://wiki.haskell.org/HSFFIG/Tutorial * 4.1 Naming conventions https://wiki.haskell.org/GHC/Using_the_FFI http://luajit.org/ext_ffi_api.html https://colberg.org/gcc-lua-cdecl/ffi-cdecl.html |
NB-FFI does this too, see NBExternalResourceExecutor. Cheers, Henry signature.asc (859 bytes) Download Attachment |
In reply to this post by Mariano Martinez Peck
Hi 2016-01-21 13:43 GMT+01:00 Mariano Martinez Peck <[hidden email]>:
After reading this thread I have no understanding why "platform constants" information should be distributed as ston files? Why not generate smalltalk classes or methods for each platform? They will initialize pool variables directly when platform change happens. And no problems with there distribution |
2016-01-21 15:18 GMT+01:00 Denis Kudriashov <[hidden email]>:
In your example it can be methods on MYSQLInterface class side like: MYSQLInterface>>initWindows64Declarations
MYSQLInterface>>initWindows32Declarations
MYSQLInterface>>initUnix32Declarations
And this methods can be published in separate packages if needed |
In reply to this post by Denis Kudriashov
On Thu, Jan 21, 2016 at 6:18 AM, Denis Kudriashov <[hidden email]> wrote:
Because one doesn't need the methods that initialize them, one only needs the values. The initialization methods are overhead. We discussed the issue earlier in the thread. See Thierry's message and my response. _,,,^..^,,,_ best, Eliot |
In reply to this post by Denis Kudriashov
On Thu, Jan 21, 2016 at 6:24 AM, Denis Kudriashov <[hidden email]> wrote:
Let's measure this. Let's say we have 8 platforms (that's an underestimate, because different Linux distributions may have different values for certain constants), but 8, which is 4 basic platforms times 32- & 64-bits. We have Mac x86 32-bit, Mac x64 64-bit, Windows x86 32-bit, Windows x64 64-bit, Linux x86 32-bit, Linux ARM 32-bit, Linux x64 64-bit, and soon enough there will be more. Further, there may be different versions over time. So each of those initialization methods has - 1 slot for the global variable to be assigned - 1 slot for the literal value to assign to it - 3 bytes of bytecode per initialization for small methods, 4 for large methods. Let's say 4. So the overhead in 32-bits is 12 bytes per constant, and in 64-bits is 20 bytes. So the overhead per constant for all platforms is 96 bytes per constant in 32-bits and 160 bytes per constant for 64-bits. A full system with sockets, files, a database connexion etc could easily exceed 100 constants. I think it would be nearer 1000. So the overheads are in the 10- to 100-k byte range (100k ~= 0.5% of the image) on 32-bits. That's low but it's also pure overhead. Every GC has to visit them. Every senders and implementors has to visit them, but they offer nothing of value. Whereas the small parser for whatever notation is used to store the constants externally (if they are needed in a given deployment) has a small constant overhead; its simple code. Further, you still need the machinery to export the constants to be able to generate these initialization methods. If you've got the machinery and you don't need the methods why bother to generate the methods? _,,,^..^,,,_ best, Eliot |
Free forum by Nabble | Edit this page |