Skip to main content

phoneME Advanced Multicore question(s)

4 replies [Last post]
lamsap
Offline
Joined: 2004-11-09

A question about multicores/SMP for you.

phoneME Advanced mr2 is what we use on a linux 2.6/uclibc/x86 environment on a single core cpu. We're now looking at using a dual-core cpu (1 physical CPU) x86.

In mr2 I see it has a CVM_MP_SAFE flag, which looking at the code looks like it makes cvm multiprocessor (and multicore?) safe, and allows cvm to use any/all logical cpus on the system? Is this correct?

Looking at phoneme_advanced_mr2/cdc/src/linux/javavm/runtime/globals_md.c method CVMinitStaticState I see it tries to set affinity to a single CPU if CVM_MP_SAFE not set.

So this to me says that CVM_MP_SAFE=false will still let phoneME work on a multicore/multiprocessor system without issue. Although it will only ever use a specific CPU.

Is what I've said so far correct?

In svn, I see LINUX_ENABLE_SET_AFFINITY=true|false can also be specified, and globals_md.c CVMinitStaticState will thus only set affinity if both CVM_MP_SAFE == false, and LINUX_ENABLE_SET_AFFINITY == true.

I guess this is to support systems that have CVM_MP_SAFE == false, but the underlying system doesn't support cpu affinity? It wasn't put in to solve any SMP issues during runtime?

Is there anything else I need to be aware of when compiling - and running - phoneME for a SMP environment?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jiangli_zhou
Offline
Joined: 2006-10-16

Hi,

The current phoneme_advanced_mr2 does not have multicore support for x86. The needed memory barriers are not added in places. So you would run into problems on a multicore x86 machine. There is a way to bound the VM processes to single CPU. You can enable that by building with LINUX_ENABLE_SET_AFFINITY=true, so only one CPU is used.

If you are a licensee, you can talk to our marketing about getting the full multcore support for x86.

Thanks.

cjplummer
Offline
Joined: 2006-10-16

LINUX_ENABLE_SET_AFFINITY=true forces the process onto one CPU, so you don't run into SMP synchronization issues.

CVM_MP_SAFE=true enables the extra code in CVM to make it work properly when running on multiple CPUs (basically adding membars in many places). However, most ports don't support it at all, and it has not been fully tested with any of the existing ports.

If you have an SMP machine, I'd suggest just building with LINUX_ENABLE_SET_AFFINITY=true. CVM_MP_SAFE=true would only benefit you if your app is multithreaded, since there is no way for one thread to leverage more than one CPU at a time.

lamsap
Offline
Joined: 2004-11-09

Ok, thanks for clarifying CVM_MP_SAFE. I am using mr2 b97 at the moment (as a general preference to using a specific release rather than a svn snapshot), which doesn't have LINUX_ENABLE_SET_AFFINITY, but the CVMinitStaticState still tries to set affinity (or at least I think it does). Would I be correct in saying that all I need to do is remove the #if 0 (and #endif) and it will set the affinity? Or was this code commented out for some other reason?

CVMBool CVMinitStaticState(CVMpathInfo *pathInfo)
{
#if 0
#if !defined(CVM_MP_SAFE) && defined(__cpu_set_t_defined)
/* If we don't have MP-safe support built in, then make sure
that we don't run on more than one processor. */
{
pid_t pid = getpid();
cpu_set_t mask;
unsigned int len = sizeof mask;
int r = sched_getaffinity(pid, len, &mask);
if (r == -1) {
return CVM_FALSE;
}
/*
Just pick the first processor we find. We should probably
pick the current processor (how?) or a random processor
instead.
*/
{
int cpu = -1;
int i;
for (i = 0; i < CPU_SETSIZE; ++i) {
if (CPU_ISSET(i, &mask)) {
cpu = i;
break;
}
}
assert(cpu != -1);
CPU_ZERO(&mask);
CPU_SET(i, &mask);
}

r = sched_setaffinity(pid, len, &mask);
if (r == -1) {
return CVM_FALSE;
}
}
#endif
#endif

cjplummer
Offline
Joined: 2006-10-16

You can try that. You might also want to try grabbing the latest code related to this from the turnk.