LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Manfred Spraul <manfred@colorfullife.com>
To: Bill Davidsen <davidsen@tmr.com>
Cc: Mike Galbraith <efault@gmx.de>,
paulmck@linux.vnet.ibm.com, Nadia Derbey <Nadia.Derbey@bull.net>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: Scalability requirements for sysv ipc
Date: Fri, 28 Mar 2008 10:49:14 +0100 [thread overview]
Message-ID: <47ECBF1A.2080300@colorfullife.com> (raw)
In-Reply-To: <47EC1FC0.7040405@tmr.com>
[-- Attachment #1: Type: text/plain, Size: 1179 bytes --]
Bill Davidsen wrote:
>
> I never tried binding the process to a CPU, in general the affinity
> code puts one process per CPU under light load, and limits the context
> switch overhead. It looks as if you are testing only the single CPU
> (or core) case.
>
Attached is a patch that I wrote that adds cpu binding. Feel free to add
it to your sources. It's not that usefull, recent linux distros include
a "taskset" command that can bind a task to a given cpu. I needed it for
an older distro.
With regards to the multi-core case: I've always ignored them, I
couldn't find a good/realistic test case.
Thundering herds (i.e.: one task wakes up lots of waiting tasks) is at
least for sysv msg and sysv sem lockless: the woken up tasks do not take
any locks, they return immediately to user space.
Additionally, I don't know if the test case is realistic: at least
postgres uses one semaphore for each process/thread, thus waking up
multiple tasks never happens.
Another case would be to bind both tasks to different cpus. I'm not sure
if this happens in real life. Anyone around who knows how other
databases implement locking? Is sysv sem still used?
--
Manfred
[-- Attachment #2: patch-cpubind --]
[-- Type: text/plain, Size: 4313 bytes --]
diff -ur ctxbench-1.9.orig/ctxbench.c ctxbench-1.9/ctxbench.c
--- ctxbench-1.9.orig/ctxbench.c 2002-12-09 22:41:59.000000000 +0100
+++ ctxbench-1.9/ctxbench.c 2008-03-28 10:30:55.000000000 +0100
@@ -1,19 +1,28 @@
+#include <sched.h>
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
-#include <sched.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <sys/msg.h>
#include <sys/stat.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/wait.h>
/* this should be in unistd.h!! */
/* #include <getopt.h> */
+/**************** Prototypes */
+
+void shmchild(int shm, int semid);
+void shmparent(int shm, int semid, pid_t child);
+void do_cpubind(int cpu);
+
/**************** General internal procs and flags here */
/* help/usage */
static void usage(void);
@@ -25,7 +34,6 @@
int Niter = 0;
/* Use signals rather than semiphores */
static void sig_NOP();
-static void wait_sig();
int OkayToRun = 0;
int ParentPID, ChildPID;
/* pipe vectors for -p option */
@@ -79,19 +87,20 @@
int msgqid;
int do_yield = 0;
-\f
-main(int argc, char *argv[])
+
+int main(int argc, char *argv[])
{
int shm;
struct shmid_ds buf;
int semid = -1;
- int child, stat;
+ int cpubind = -1;
+ int child;
int RunTime = 10;
union semun pvt_semun;
pvt_semun.val = 0;
- while ((shm = getopt(argc, argv, "sSLYmpn:t:")) != EOF) {
+ while ((shm = getopt(argc, argv, "sSLYmpn:t:c:")) != EOF) {
switch (shm) {
/* these are IPC types */
case 's': /* use semiphore */
@@ -124,11 +133,14 @@
case 't': /* give time to run */
RunTime = atoi(optarg);
break;
+ case 'c': /* bind to a specific cpu */
+ cpubind = atoi(optarg);
+ break;
default: /* typo */
usage();
}
}
-\f
+
signal(SIGALRM, timeout);
if (RunTime) alarm(RunTime);
@@ -164,7 +176,7 @@
}
/* identify version and method */
- printf("\n\nContext switching benchmark v1.17\n");
+ printf("\n\nContext switching benchmark v1.17-cpubind\n");
printf(" Using %s for IPC control\n", IPCname[IPCtype]);
printf(" Max iterations: %8d (zero = no limit)\n", Iterations);
@@ -174,13 +186,14 @@
ParentPID = getpid();
if ((child = fork()) == 0) {
+ do_cpubind(cpubind);
ChildPID = getpid();
shmchild(shm, semid);
} else {
+ do_cpubind(cpubind);
ChildPID = child;
shmparent(shm, semid, child);
}
-
wait(NULL);
if (shmctl(shm, IPC_RMID, &buf) != 0) {
perror("Error removing shared memory");
@@ -215,14 +228,13 @@
break;
}
- exit(0);
+ return 0;
}
-\f
/*******************************/
/* child using IPC method */
-int shmchild(int shm, int semid)
+void shmchild(int shm, int semid)
{
volatile char *mem;
int num = 0;
@@ -313,7 +325,7 @@
/********************************/
/* parent using shared memory */
-int shmparent(int shm, int semid, pid_t child)
+void shmparent(int shm, int semid, pid_t child)
{
volatile char *mem;
int num = 0;
@@ -328,7 +340,7 @@
if (!(mem = shmat(shm, 0, 0))) {
- perror("shmchild: Error attaching shared memory");
+ perror("shmparent: Error attaching shared memory");
exit(2);
}
@@ -439,7 +451,7 @@
exit(3);
}
}
-\f
+
/*****************************************************************
| usage - give the user a clue
****************************************************************/
@@ -458,6 +470,7 @@
" -p use pipes for IPC\n"
" -L spinLock in shared memory\n"
" -Y spinlock with sched_yield (for UP)\n"
+ " -cN bind to cpu N\n"
"\nRun limit options:\n"
" -nN limit loops to N (default via timeout)\n"
" -tN run for N sec, default 10\n\n"
@@ -490,3 +503,22 @@
signal(SIGUSR1, sig_NOP);
return;
}
+
+/*****************************************************************
+ | cpu_bind - bind all tasks to a given cpu
+ ****************************************************************/
+
+void do_cpubind(int cpubind)
+{
+ if (cpubind >= 0) {
+ cpu_set_t d;
+ int ret;
+
+ CPU_ZERO(&d);
+ CPU_SET(cpubind, &d);
+ ret = sched_setaffinity(0, sizeof(d), &d);
+ printf("%d: sched_setaffinity %d: %lxh\n",getpid(), ret, *((int*)&d));
+ ret = sched_getaffinity(0, sizeof(d), &d);
+ printf("%d: sched_getaffinity %d: %lxh\n",getpid(), ret, *((int*)&d));
+ }
+}
next prev parent reply other threads:[~2008-03-28 9:49 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-21 9:41 Scalability requirements for sysv ipc (was: ipc: store ipcs into IDRs) Manfred Spraul
2008-03-21 12:45 ` Nadia Derbey
2008-03-21 13:33 ` Scalability requirements for sysv ipc Manfred Spraul
2008-03-21 14:13 ` Paul E. McKenney
2008-03-21 16:08 ` Manfred Spraul
2008-03-22 5:43 ` Mike Galbraith
2008-03-22 10:10 ` Manfred Spraul
2008-03-22 11:53 ` Mike Galbraith
2008-03-22 14:22 ` Manfred Spraul
2008-03-22 19:08 ` Manfred Spraul
2008-03-25 15:50 ` Mike Galbraith
2008-03-25 16:13 ` Peter Zijlstra
2008-03-25 18:31 ` Mike Galbraith
2008-03-26 6:18 ` Mike Galbraith
2008-03-30 14:12 ` Scalability requirements for sysv ipc (+namespaces broken with SEM_UNDO) Manfred Spraul
2008-03-30 15:21 ` David Newall
2008-03-30 17:18 ` Mike Galbraith
2008-04-04 14:59 ` Nadia Derbey
2008-04-04 15:03 ` Nadia Derbey
2008-03-22 19:35 ` Scalability requirements for sysv ipc Mike Galbraith
2008-03-23 6:38 ` Manfred Spraul
2008-03-23 7:15 ` Mike Galbraith
2008-03-23 7:08 ` Mike Galbraith
2008-03-23 7:20 ` Mike Galbraith
2008-03-27 22:29 ` Bill Davidsen
2008-03-28 9:49 ` Manfred Spraul [this message]
2008-03-25 16:00 ` Nadia Derbey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47ECBF1A.2080300@colorfullife.com \
--to=manfred@colorfullife.com \
--cc=Nadia.Derbey@bull.net \
--cc=akpm@linux-foundation.org \
--cc=davidsen@tmr.com \
--cc=efault@gmx.de \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--subject='Re: Scalability requirements for sysv ipc' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).