You are not logged in.

#1 2010-09-21 04:41:04

Rad3k
Member
From: Poland
Registered: 2009-05-09
Posts: 36

[SOLVED] Wine & cpu affinity

Hello there.

Simply put, my question is:
Is there a way of launching wine apps with restriction to one cpu core?

Background:
Recently I tried running Unreal Tournament with wine (funny thing is that it seems less painful than running the linux version natively), and there was a problem with game's speed being way too high. I figured out that to make it behave I just need to restrict the game process to one cpu core. Once the game is running, this is done easily by issuing

taskset -cp 0 [PID]

But when I try to run the game using taskset

taskset -c 0 wine UnrealTournament.exe

it has no effect at all. When I check the process' affinity, it turns out that it still uses both cores.
Further investigation shown that this problem seems to be related to wine in general, as even launching winecfg with takset doesn't work properly. Is this happening to someone else? Or, is it working correctly for anyone at all?

For now, the only way (known to me) of setting affinity in wine is to do it on already running process. Am I missing something?

Any help appreciated.

EDIT:
Solved, see #7

Last edited by Rad3k (2010-09-21 17:48:18)

Offline

#2 2010-09-21 06:17:10

Darksoul71
Member
Registered: 2010-04-12
Posts: 319

Re: [SOLVED] Wine & cpu affinity

Haha, another die hard UT99 gamer like me big_smile

Agreed, UT on wine is much less painful to run than the native Linux version. The same goes for UT2k4 (at least if you own the Unreal Anthology DVD).

In regard to your problem I think the answer is simply:
taskset assigns the affinity to the first process you start which is WINE in your case. Then WINE starts child processes including the one running UT.
Simply run "ps aux | grep wine" and you see what I mean. Usually you will see two processes running with wine in the "title" but no UT.
Then run "ps aux | grep unreal" and then you see that UT runs with a different PID than WINE.

I would try the following:

Launch UT inside a bash script in the background like this:

# Start UT99 in the background
wine unrealtournament.exe & 
# Get UT99s real PID
pid=${pgrep -x unrealtournament.exe}
# Set process affinity
taskset -cp 0 $pid

This is of course only a rough approach and I haven't tested this. After all it should work like this.

Last edited by Darksoul71 (2010-09-21 06:20:37)


My archlinux x86_64 host:
AMD E350 (2x1.6GHz) / 8GB DDR3 RAM / GeForce 9500GT (passive) / Arch running from 16GB USB Stick

Offline

#3 2010-09-21 07:49:22

Gusar
Member
Registered: 2009-08-25
Posts: 3,605

Re: [SOLVED] Wine & cpu affinity

Schedtool works:

$ schedtool -a 0 -e wine UnrealTournament.exe

Haven't tried on UT yet, but it works with some other games where wine would otherwise have problems. But this won't be enough, UT will still run crazy fast, you need an additional command:

$ schedtool -a 0 -e wine UnrealTournament.exe -CPUSPEED=3000

That's for 3GHz, adjust to what your cpu actually has. And I'd also turn off any freq scaling/switch to the performance governor.
Note, I haven't actually tried this yet. I only have the linux version of UT installed and I haven't played even that in ages, cos you're right, it's a pain to get working (there's no cpuspeed switch in the linux version for example, so you need other hacks). So please report if it works. Then I might actually play this game again.


Edit: Right after writing all that above, I find this: http://icculus.org/lgfaq/files/ut and got the linux version running perfectly. I replaced the ut script with the one from the link, switched to the performance governor and then ran

$ schedtool -a 0 -e ./ut

Last edited by Gusar (2010-09-21 08:18:26)

Offline

#4 2010-09-21 07:58:33

Darksoul71
Member
Registered: 2010-04-12
Posts: 319

Re: [SOLVED] Wine & cpu affinity

UT99 is well know for having problems with both multicore systems and dynamic CPU speed. smile
I think by turning off any dynamic speed of your CPU and assigning it fixed to one core it should run without any issues.

@Rad3k: Now you have two approaches to work with.....


My archlinux x86_64 host:
AMD E350 (2x1.6GHz) / 8GB DDR3 RAM / GeForce 9500GT (passive) / Arch running from 16GB USB Stick

Offline

#5 2010-09-21 13:17:42

Rad3k
Member
From: Poland
Registered: 2009-05-09
Posts: 36

Re: [SOLVED] Wine & cpu affinity

@Darksoul71
Heh, don't know if I'm so die hard UT99 player, but I like it very much, and I'm rather not interested in sequels. It just happens that most of the PC games I consider "best of the best" are those made in 90's. Later, most of the gaming industry gone too commercial, if you know what I mean. They just keep selling same old ideas in shiny new boxes.

Now, back to the topic.
Yeah, I know that I can just run the game, get it's PID and then set the affinity - now I'm doing it this way, by hand. And I'm too much of a perfectionist to let scripts operate on PIDs retrieved by name matching, so I'm searching for alternate solutions wink

I've tried three test cases, each involving running winecfg, setting it's affinity and checking if it's correct.
1. Run winecfg through taskset:

taskset -c 0 winecfg; sleep 1; taskset -cp $!

The last command shows the actual affinity of the process. I've check and confirmed that PID stored in "$!" is the actual PID of "winecfg.exe" process.
Output is:

[1] 20444
pid 20444's current affinity list: 0,1

What means - setting affinity had no apparent effect.

2. Run winecfg and then immediately set it's affinity:

winecfg& taskset -cp 0 $!; sleep 1; taskset -cp $!

Output:

[1] 20482
pid 20482's current affinity list: 0,1
pid 20482's new affinity list: 0
pid 20482's current affinity list: 0,1

So it seems like it's changing the affinity, but again, with no real effect.

3. Run winecfg, wait a second, and then set affinity:

winecfg& sleep 1; taskset -cp 0 $!; sleep 1; taskset -cp $!

Output:

[1] 20494
pid 20494's current affinity list: 0,1
pid 20494's new affinity list: 0
pid 20494's current affinity list: 0

Now it's working. It seems that somehow, wine is resetting its affinity during startup. Maybe I should ask on wine forums? Because I don't think that it should work like that.


@Gusar
I tried schedtool, but it gives me the same results as taskset. It seems that it's doing basically the same thing, the only difference being that taskset is meant specifically for this while schedtool does this and few other things.

And as for cpu frequency scaling - yes, I restrict it for almost every game I run on wine. Games on wine tend to always use 100% cpu, so I set the "powersave" governor, as 800MHz seems to be enough for most games I play, and it helps keep my laptop's fans quiet.

Offline

#6 2010-09-21 14:26:50

Darksoul71
Member
Registered: 2010-04-12
Posts: 319

Re: [SOLVED] Wine & cpu affinity

Heh, don't know if I'm so die hard UT99 player, but I like it very much, and I'm rather not interested in sequels. It just happens that most of the PC games I consider "best of the best" are those made in 90's. Later, most of the gaming industry gone too commercial, if you know what I mean. They just keep selling same old ideas in shiny new boxes.

Agreed ! Although I must admit that I like UT2k4 a bit over UT99 because of the weapons graphics and effects. On the other hand I still love to play Quake together with mods such as Kleshik or SDQuake. In general I have moved towards smaller independent games (e.g. Amnesia - The Dark Descent).

Yeah, I know that I can just run the game, get it's PID and then set the affinity - now I'm doing it this way, by hand. And I'm too much of a perfectionist to let scripts operate on PIDs retrieved by name matching, so I'm searching for alternate solutions

I think an "pgrep -x unrealtournament.exe" will not reveal pretty much possibilities on your system, wouldn't it ? smile

WINE might possible change the process to a default setup (No affinity, medium priority, etc). Being less of a perfectionist I would simply use a script similar to the one I posted above with a small pause (e.g. 2 sec) prior setting affinity.

UT99 takes a whole lot of time loading and I think you will not even notice a pause of 5 seconds.


My archlinux x86_64 host:
AMD E350 (2x1.6GHz) / 8GB DDR3 RAM / GeForce 9500GT (passive) / Arch running from 16GB USB Stick

Offline

#7 2010-09-21 17:45:38

Rad3k
Member
From: Poland
Registered: 2009-05-09
Posts: 36

Re: [SOLVED] Wine & cpu affinity

Well, it looks like I can just do

wine UnrealTournament.exe &
sleep 1
taskset -cp 0 $!

and everything works allright. That way I can do everything from script and avoid getting PIDs by name cool Not perfect solution, but an acceptable workaround wink
Though I'll still want to ask wine folks why it was necessary to insert that delay.

Darksoul71 wrote:

I think an "pgrep -x unrealtournament.exe" will not reveal pretty much possibilities on your system, wouldn't it ? smile

Well, I can imagine a situation where this could lead to a problem tongue For example, if I wanted to run more than one instance of game on one system. Actually it's a very real possibility that I expect to encounter soon. I've discovered a decent way to play LAN-enabled games, 2 players (and theoretically more) on a single laptop using external monitor (dual head) and additional set of mouse&keyboard. Maybe I'll post a thread about it when I'll finish writing scripts that automate the setup.

So I guess my main problem is [SOLVED]

Thanks for suggestions smile

Offline

#8 2010-09-21 19:40:50

Gusar
Member
Registered: 2009-08-25
Posts: 3,605

Re: [SOLVED] Wine & cpu affinity

With schedtool I don't need any sleep 1, it works directly. Doesn't matter though, what I want to say is, thank you for creating this thread. Thanks to this threadm I've been playing UT today for the first time since many months. What fun. This game really has that certain something. Anyway, back to playing smile

Offline

#9 2010-09-22 10:55:18

Darksoul71
Member
Registered: 2010-04-12
Posts: 319

Re: [SOLVED] Wine & cpu affinity

Rad3k wrote:

Well, I can imagine a situation where this could lead to a problem tongue For example, if I wanted to run more than one instance of game on one system. Actually it's a very real possibility that I expect to encounter soon. I've discovered a decent way to play LAN-enabled games, 2 players (and theoretically more) on a single laptop using external monitor (dual head) and additional set of mouse&keyboard. Maybe I'll post a thread about it when I'll finish writing scripts that automate the setup.

You've got my full attention:
Multiplayer on one single host with dualhead ?

Hmm..../me thinks of playing Diablo2 together with my wife on my arch64 dualhead host.

Could you please provide a bit more details ?

e.g. how to assign the input of a second keyboard & mouse to a second instance of a game (e.g. UT99)
e.g. how to start the "second game" on the second screen (separate x-server )
and so on.

A wiki entry might be a good starting point. I would be willing to help smile

Edit:
My guess is that this wiki entry is a good starting point, right ?
http://wiki.archlinux.org/index.php/Xorg_multiseat

Do you use Xephyr ?
http://freedesktop.org/wiki/Software/Xephyr

Last edited by Darksoul71 (2010-09-22 13:23:23)


My archlinux x86_64 host:
AMD E350 (2x1.6GHz) / 8GB DDR3 RAM / GeForce 9500GT (passive) / Arch running from 16GB USB Stick

Offline

#10 2010-09-22 18:18:21

Rad3k
Member
From: Poland
Registered: 2009-05-09
Posts: 36

Re: [SOLVED] Wine & cpu affinity

Darksoul71 wrote:

You've got my full attention:
Multiplayer on one single host with dualhead ?

Hmm..../me thinks of playing Diablo2 together with my wife on my arch64 dualhead host.

Could you please provide a bit more details ?

e.g. how to assign the input of a second keyboard & mouse to a second instance of a game (e.g. UT99)
e.g. how to start the "second game" on the second screen (separate x-server )
and so on.

A wiki entry might be a good starting point. I would be willing to help smile

Edit:
My guess is that this wiki entry is a good starting point, right ?
http://wiki.archlinux.org/index.php/Xorg_multiseat

Do you use Xephyr ?
http://freedesktop.org/wiki/Software/Xephyr

Well, this doesn't qualify as multiseat, as this technically does not require a second display - you could even play having two windows open on one screen. It's just more comfortable with an additional screen wink I use only one X server (no Xephyr) with a "multipointer" configuration - you get multiple mouse cursors on the screen. It's a quite recent and experimental feature of Xorg, so most window managers get confused about it (now I'm checking out TWM).

Wait patiently, soon I'll post a thread about it with instructions wink

Offline

#11 2010-09-22 18:54:47

Darksoul71
Member
Registered: 2010-04-12
Posts: 319

Re: [SOLVED] Wine & cpu affinity

Ok, I see...so we are actually more talking about two "dedicated" windows for each game with multipointer support from xorg, right ?
That is more the approach I prefer since running a dedicated xorg configuration for multiseat and single seat / dual head would be acceptable to me but not "perfectly". I prefer Gnome for the desktop (mostly because of my Ubuntu roots) but would be fine with another WM if it works better together with multipointer.

BTW: Is Xephyr capable of dealing with 3D accelerated graphics ?


My archlinux x86_64 host:
AMD E350 (2x1.6GHz) / 8GB DDR3 RAM / GeForce 9500GT (passive) / Arch running from 16GB USB Stick

Offline

#12 2010-09-24 17:41:37

Rad3k
Member
From: Poland
Registered: 2009-05-09
Posts: 36

Re: [SOLVED] Wine & cpu affinity

Darksoul71 wrote:

Ok, I see...so we are actually more talking about two "dedicated" windows for each game with multipointer support from xorg, right ?
That is more the approach I prefer since running a dedicated xorg configuration for multiseat and single seat / dual head would be acceptable to me but not "perfectly". I prefer Gnome for the desktop (mostly because of my Ubuntu roots) but would be fine with another WM if it works better together with multipointer.

BTW: Is Xephyr capable of dealing with 3D accelerated graphics ?

I've posted a topic about it here.

Well, I almost always use a separate X server for playing fullscreen games, to avoid them messing up my dekstop (when they change resolution or gamma). So I can still have xfce on my main desktop while using some lightweight WM for fullscreen games.

I haven't been able to use Xephyr with hardware acceleration.

Offline

Board footer

Powered by FluxBB