dual processors

Place to discuss Fedora and/or Red Hat

dual processors

Postby Stryker » Fri Apr 15, 2005 9:35 pm

It seems my hosting company gave me the wrong cpu in my dedicated server. I was supposed to get a 2.4ghz p4, and instead received a dual 2.8ghz p4. My life sucks! But I'm really wondering, can I configure an application to only use one of the processors? I have a game server I'd like to not interfere with other activities on the server. Can't seem to find much information on it, mostly because I dont know what I'm looking for (like... what would you call that?)

Just to show off:
Code: Select all
processor   : 0
vendor_id   : GenuineIntel
cpu family   : 15
model      : 3
model name   : Intel(R) Pentium(R) 4 CPU 2.80GHz
stepping   : 4
cpu MHz      : 2801.206
cache size   : 1024 KB
physical id   : 0
siblings   : 2
fdiv_bug   : no
hlt_bug      : no
f00f_bug   : no
coma_bug   : no
fpu      : yes
fpu_exception   : yes
cpuid level   : 5
wp      : yes
flags      : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe pni monitor ds_cpl cid xtpr
bogomips   : 5521.40

processor   : 1
vendor_id   : GenuineIntel
cpu family   : 15
model      : 3
model name   : Intel(R) Pentium(R) 4 CPU 2.80GHz
stepping   : 4
cpu MHz      : 2801.206
cache size   : 1024 KB
physical id   : 0
siblings   : 2
fdiv_bug   : no
hlt_bug      : no
f00f_bug   : no
coma_bug   : no
fpu      : yes
fpu_exception   : yes
cpuid level   : 5
wp      : yes
flags      : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe pni monitor ds_cpl cid xtpr
bogomips   : 5586.94


and uname -a gives me:
Code: Select all
Linux noobify.com 2.6.9-5.ELsmp #1 SMP Wed Jan 5 19:30:39 EST 2005 i686 i686 i386 GNU/Linux


Thanks
Stryker
scripter
scripter
 
Posts: 98
Joined: Thu Jan 23, 2003 8:50 pm

Postby Void Main » Fri Apr 15, 2005 9:48 pm

If your app is a single threaded process it will only run on one processor at a time anyway. Linux will run tasks on the least utilized processor so there really isn't any point in trying to bind it to one processor. You can use "top" to see which processor each process is running on but I don't believe there is a way to bind your app to a specific processor, although I have seen the question come up before for both Linux and Solaris. Threaded applications work the best on multi processor systems as they can utilize more than one processor. Even single threaded apps will run better on a multiprocessor box because some of the other processes will be running on the other CPU(s).
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Postby Stryker » Fri Apr 15, 2005 9:58 pm

You know how I can make top do that? Here's a sample of what i'm seeing:

Code: Select all
top - 20:58:30 up 1 day,  3:36,  2 users,  load average: 0.20, 0.24, 0.19
Tasks: 112 total,   1 running, 111 sleeping,   0 stopped,   0 zombie
Cpu(s):  2.5% us,  1.5% sy,  0.0% ni, 94.7% id,  0.7% wa,  0.2% hi,  0.5% si
Mem:    506036k total,   444220k used,    61816k free,    11008k buffers
Swap:  1015800k total,   259004k used,   756796k free,   105968k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 1045 kevin     16   0  6176 4212 1160 S  3.0  0.8   0:13.50 sld
24918 hlds      15   0 94892  62m 3336 S  0.3 12.7   0:39.26 hlds_i686
    1 root      16   0  3408  452  420 S  0.0  0.1   0:00.95 init
    2 root      RT   0     0    0    0 S  0.0  0.0   0:00.09 migration/0
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.29 ksoftirqd/0
    4 root      RT   0     0    0    0 S  0.0  0.0   0:00.10 migration/1
    5 root      34  19     0    0    0 S  0.0  0.0   0:00.03 ksoftirqd/1
    6 root       5 -10     0    0    0 S  0.0  0.0   0:00.00 events/0
    7 root       5 -10     0    0    0 S  0.0  0.0   0:00.00 events/1
    8 root       6 -10     0    0    0 S  0.0  0.0   0:00.00 khelper
    9 root      15 -10     0    0    0 S  0.0  0.0   0:00.00 kacpid
   36 root       5 -10     0    0    0 S  0.0  0.0   0:00.00 kblockd/0
   37 root       5 -10     0    0    0 S  0.0  0.0   0:00.00 kblockd/1
   50 root       7 -10     0    0    0 S  0.0  0.0   0:00.00 aio/0
   51 root       5 -10     0    0    0 S  0.0  0.0   0:00.00 aio/1
   38 root      15   0     0    0    0 S  0.0  0.0   0:00.00 khubd
   49 root      15   0     0    0    0 S  0.0  0.0   0:08.48 kswapd0


Or perhaps a way to set a process's priority?
Stryker
scripter
scripter
 
Posts: 98
Joined: Thu Jan 23, 2003 8:50 pm

Postby Void Main » Fri Apr 15, 2005 10:07 pm

You set a processes priority with "nice" and you can add more columns to top by pressing "f" to see the other fields and then "j" to turn on the #C field. You can also press the number "1" to see both processor stats instead of a combined stat.

I also may have spoke too soon on binding apps to a specific processor:
http://www.linuxjournal.com/article/6799

I have to dig into this a little more but I can't imagine that I can schedule apps better than Linux can do it. I know certain threaded apps are written to bind to a desired number of processors (Sybase database is one I can think of off the top of my head).
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Postby Stryker » Fri Apr 15, 2005 10:13 pm

one of my applications spikes up to 100% for several seconds, cripling the performance of all the others. I'm trying to avoid this.

Thanks for the information though, are you ever not helpful?
Stryker
scripter
scripter
 
Posts: 98
Joined: Thu Jan 23, 2003 8:50 pm

Postby Stryker » Fri Apr 15, 2005 10:19 pm

perfect! that link gave me the source code to a tool that can do it:

usage: ./bind <pid> <processor id + 1>

Code: Select all
/* bind - simple command-line tool to set CPU
 * affinity of a given task
 */

#define _GNU_SOURCE

#include <stdlib.h>
#include <stdio.h>
#include <sched.h>

int main(int argc, char *argv[])
{
    unsigned long new_mask;
    unsigned long cur_mask;
    unsigned int len = sizeof(new_mask);
    pid_t pid;

    if (argc != 3) {
   fprintf(stderr,
                "usage: %s [pid] [cpu_mask]\n",
                argv[0]);
   return -1;
    }

    pid = atol(argv[1]);
    sscanf(argv[2], "%08lx", &new_mask);

    if (sched_getaffinity(pid, len,
                          &cur_mask) < 0) {
   perror("sched_getaffinity");
   return -1;
    }

    printf("pid %d's old affinity: %08lx\n",
           pid, cur_mask);

    if (sched_setaffinity(pid, len, &new_mask)) {
   perror("sched_setaffinity");
   return -1;
    }

    if (sched_getaffinity(pid, len,
                          &cur_mask) < 0) {
   perror("sched_getaffinity");
   return -1;
    }

    printf(" pid %d's new affinity: %08lx\n",
           pid, cur_mask);

    return 0;
}



Excellent! thanks!
Stryker
scripter
scripter
 
Posts: 98
Joined: Thu Jan 23, 2003 8:50 pm

Postby Void Main » Fri Apr 15, 2005 10:36 pm

Cool!
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Postby worker201 » Sat Apr 16, 2005 12:35 am

Oddly, I just heard of nice yesterday. Tux and I were talking, and I had a number-cruncher that was sucking up resources. With a little playing, I was able to send a +3 command to the app, allowing gaim and firefox to function normally. I had never heard of it before, and I realized how little I truly know about Linux. I know some things, but there are some others that just baffle or escape me.

No point to that, just adding to the conversation.
worker201
guru
guru
 
Posts: 668
Joined: Sun Jun 13, 2004 6:38 pm
Location: Hawaii

Postby Void Main » Sat Apr 16, 2005 6:13 am

Yeah, I think "nice" is actually a POSIX standard command as it is in every version of UNIX I have ever used since before Linux was around. I have personally never found it overly useful to override the system in any of these areas.
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Re: dual processors

Postby Tux » Sat Apr 16, 2005 9:56 am

Stryker wrote:It seems my hosting company gave me the wrong cpu in my dedicated server. I was supposed to get a 2.4ghz p4, and instead received a dual 2.8ghz p4. My life sucks! But I'm really wondering, can I configure an application to only use one of the processors? I have a game server I'd like to not interfere with other activities on the server. Can't seem to find much information on it, mostly because I dont know what I'm looking for (like... what would you call that?)

Just to show off:

processor : 0
model name : Intel(R) Pentium(R) 4 CPU 2.80GHz
physical id : 0

processor : 1
model name : Intel(R) Pentium(R) 4 CPU 2.80GHz
physical id : 0

and uname -a gives me:
Code: Select all
Linux noobify.com 2.6.9-5.ELsmp #1 SMP Wed Jan 5 19:30:39 EST 2005 i686 i686 i386 GNU/Linux


Thanks


I hate to burst you bubble, I really do, but you only have a single processor. It is a P4 with Hyperthreading and using an SMP kernel, notice the same physical ID.
Tux
guru
guru
 
Posts: 689
Joined: Wed Jan 08, 2003 10:40 am

Postby Stryker » Sat Apr 16, 2005 9:54 pm

oh you're no fun :/

at least I learned something

*looks around* So what's hyperthreading?

edit: nevermind, found it. seems to have the same effect though... my spiking application isn't affecting overall performance.
Last edited by Stryker on Sat Apr 16, 2005 10:05 pm, edited 1 time in total.
Stryker
scripter
scripter
 
Posts: 98
Joined: Thu Jan 23, 2003 8:50 pm

Postby worker201 » Sat Apr 16, 2005 10:02 pm

Hyperthreading is dual processor simulation, right? Not exactly, but my understanding is that this is a good way to explain hyperthreading to idiots like me.
worker201
guru
guru
 
Posts: 668
Joined: Sun Jun 13, 2004 6:38 pm
Location: Hawaii


Return to Fedora/Red Hat

Who is online

Users browsing this forum: No registered users and 1 guest

cron