[Cbe-oss-dev] [PATCH 07/11 v3]MARS: Remove api argument params structs

Kazunori Asayama asayama at sm.sony.co.jp
Thu Sep 18 12:22:34 EST 2008


Yuji Mano wrote:
> Yuji Mano wrote:
>> Kazunori Asayama wrote:
>>> Yuji Mano wrote:
>>>> --- a/src/host/lib/mars_context.c
>>>> +++ b/src/host/lib/mars_context.c
>>>> @@ -48,9 +48,17 @@
>>>>  
>>>>  extern struct spe_program_handle mars_kernel_entry;
>>>>  
>>>> -static int num_mpus_max(void)
>>>> +static uint32_t num_mpus_max(void)
>>>>  {
>>>> -	return spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1);
>>>> +	static int count = -1;
>>>> +
>>>> +	if (count < 0) {
>>>> +		count = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1);
>>>> +		if (count < 0)
>>>> +			count = 0;
>>>> +	}
>>>> +
>>>> +	return count;
>>>>  }
>>> This doesn't seem to be thread-safe?
>>>
>> Yes it is not thread-safe. This fix allows spe_cpu_info_get() to be called only once,
>> even after we allow for shared contexts and mars_initialize() may be called multiple
>> times.
>>
>> I can fix this so that spe_cpu_info_get() gets called once per each mars_initialize()
>> call, but I think once we have the global shared context we still have the same
>> problem?
> 
> Sorry. What I meant was I think we can deal with making mars_initialize() thread-safe
> once we implement the shared contexts. Or we can protect mars_initialize with a pthread
> mutex now.

I think an easy solution at this point is to store the return value of
num_mpu_max() in a local auto variable (not a static variable) of
mars_initialize() and reuse it during each mars_initialize() call.

-- 
(ASAYAMA Kazunori
  (asayama at sm.sony.co.jp))
t



More information about the cbe-oss-dev mailing list