Designating threads to specific cores?

Hey everyone,

My current project is a Minecraft server (as some of you know), and I’m trying to create the best thread pattern possible. I was wondering if there is a way for me to explicitly tell my system to plant a thread on a SPECIFIC core/processor thread. My system has 2 cores (2 threads each) and I know that the software will only every be run on rigs with 4+ available “processors” (as determined by Runtime#availableProcessors()). There are only four threads that I think I’ll need to run, so I figured that if I could have each thread run on each core, it would work the best.

So, is there a way to do this? Or am I thinking this completely wrong, and I should do it a different way?

Thanks :smiley:

All threads are distributed among cores automatically.

That’s what I thought. Sucks :confused: Hopefully my computer can designate it well enough, lol.

Why wouldn’t it be able to? Designating them yourself would be a bad idea, as the OS (and Java) can compensate for other programs. If you have another program running a single thread that suddenly starts hogging processing power, if both that program and your program had decided exactly what core to run on, one thread of your program would be severely slowed down. It’s better to let the OS handle it and get even performance, as a task split up between multiple threads is only complete when all threads finish, right?

It’s not as sucky as it sounds - by and large the OS will absolutely try its level best to keep any particular thread on the core in which it started life. If it can’t, for any reason, then it’s because it reckons it can do a better job by moving it. So relax and enjoy coding and sleep soundly at night :slight_smile:

Cas :slight_smile:

This is not my experience at all (on Windows). It will move all threads around, at an even pace. When running a single-threaded algorithm, all my 4 CPU cores are at 25% usage, not one at 100%.

Hm that is strange - mostly I get one core jammed at 100% in that situation.

Cas :slight_smile:

Relevant specs: Vista 64bit, Intel Q6600 stepping G.

Maybe it’s a setting, somewhere, too.

Vista64, i7 here. But I’ve had the same experience on every system I’ve used I think but haven’t really got any proof other than my extraordinarily unreliable memory. There are tweaks in the registry to alter this stuff but I’ve not meddled with them.

Cas :slight_smile:

Everyone complains about the PS3 architecture.
Admittedly much more complex with 7 async. cores or whatever, but I guess developers are very happy if they don’t have to do that kind of stuff.

I dunno, we’re already doing async core programming now using VBOs etc. in OpenGL. It all makes sense really. It’d be nice if you could specify the cores to form into pipelines and stuff a la Transputers. That’d be awesome! Imagine a grid of 8x8 cores or something and you could design algorithms that piped data through in various routes.

Cas :slight_smile:

WAIT…! Is it possible to do VBO uploads from different threads?!

I think so, using shared context stuff. But you wouldn’t want to, probably.

Cas :slight_smile:

Transputers: I actually did some programming on some T212 at uni…it was a heck of a lot of fun. (I’m totally not a geek or anything)

Laptop CPUs will typically bounce threads around between cores evenly as a heat management strategy. They should still respect processor affinity settings if you set them explicitly.

Ah, about 5 years ago I set PowerManagement to ‘minimal’.

The relevant part seems to be that CPU min=25% and max=100%.

That probably toggles the massive amount of bouncing (or shall we say cache trashing).

Context switch between threads trash caches anyway even on single core, so probably nothing to worry about. But on a dual core there’s definitely massive gains to be had when one busy thread hogs a core and all the other less busy threads just get the other core(s).

Cas :slight_smile: