How to use C-land variable from Cmm-land?
Simon Marlow
marlowsd at gmail.com
Tue Dec 11 09:43:52 CET 2012
On 10/12/12 12:46, Yuras Shumovich wrote:
> On Mon, 2012-12-10 at 10:58 +0000, Simon Marlow wrote:
>> On 08/12/12 23:12, Yuras Shumovich wrote:
>>> I tried to hack stg_putMVarzh directly:
>>>
>>> if (enabled_capabilities == 1) {
>>> info = GET_INFO(mvar);
>>> } else {
>>> ("ptr" info) = ccall lockClosure(mvar "ptr");
>>> }
>>
>> You should use n_capabilities, not enabled_capabilities. The latter
>> might be 1, even when there are multiple capabilities actually in use,
>> while the RTS is in the process of migrating threads.
>
> Could you please elaborate? setNumCapabilities is guarded with
> asquireAllCapabilities, so all threads are in scheduler. And threads
> will be migrated from disabled capabilities before they get a chance to
> put/take mvar.
> I changed my mind re enabled_capabilities/n_capabilities a number of
> times during the weekend. Most likely you are right, and I should use
> n_capabilities. But I'll appreciate if you find time to explain it for
> me.
n_capabilities is the actual number of capabilities, and can only
increase, never decrease. enabled_capabilities is the number of
capabilities we are currently aiming to use, which might be less than
n_capabilities. If enabled_capabilities is less than n_capabilities,
there might still be activity on the other capabilities, but the idea is
that threads get migrated away from the inactive capabilities as quickly
as possible. It's hard to do this immediately, which is why we have
enabled_capabilities and we don't just change n_capabilities.
> The problem was that "movl $enabled_capabilities,%eax" loaded the
> address of enabled_capabilities, not a value.
Yes, sorry, you are right.
> (Again, why does it use
> 32bit register? The value is 32bit on linux, but the address is 64bit,
> isn't it?) So the correct way to use C-land variable is:
>
> if (CInt[enabled_capabilities]) {...}
>
> Not very intuitive, but at least it works.
That's C-- syntax for a memory load of a CInt value (CInt is a CPP
symbol that expands to a real C-- type, like bits32). Unlike in C,
memory loads are explicit in C--.
Cheers,
Simon
More information about the Glasgow-haskell-users
mailing list