From: "Αλέξανδρος Παπαδογιαννάκης" <psxlover@hotmail.com>
To: <peterz@infradead.org>
Subject: RE: sched_setaffinity not working with kernel 2.6.32.15
Date: Fri, 25 Jun 2010 13:19:04 +0300 [thread overview]
Message-ID: <COL124-W12DF71EA7EFE8265E7410CD6C70@phx.gbl> (raw)
In-Reply-To: <1277277558.1875.745.camel@laptop>
[-- Attachment #1: Type: text/plain, Size: 258 bytes --]
Here's the correct testcase
_________________________________________________________________
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free.
https://signup.live.com/signup.aspx?id=60969
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: sched_check.c --]
[-- Type: text/x-csrc, Size: 2273 bytes --]
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
#include <stdio.h>
//#include <sched.h>
//#include <hwloc.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/syscall.h>
#define NR_CPUS 8
#define NR_THREADS 5
#define USE_THREADAFFINITY 1
pid_t tid[NR_THREADS];
pthread_barrier_t init_start, barrier2;
void print_affinity(pthread_t pid, int threadno) {
int i;
cpu_set_t set;
CPU_ZERO(&set);
sched_getaffinity( pid, sizeof(set), &set);
for( i = 0; i < NR_CPUS; i++) {
if (CPU_ISSET(i, &set))
printf("Cpu #%d is in %d thread's affinity\n", i, threadno);
}
}
void set_schedaffinity(pthread_t pid, int cpu) {
cpu_set_t set;
CPU_ZERO(&set);
CPU_SET(cpu, &set);
sched_setaffinity(pid, sizeof(set), &set);
}
void set_threadaffinity(pthread_t pid, int cpu) {
cpu_set_t set;
CPU_ZERO(&set);
CPU_SET(cpu, &set);
pthread_setaffinity_np(pid, sizeof(set), &set);
}
void * threadCode(void * threadNo) {
long int thread = (long int) threadNo;
if (!USE_THREADAFFINITY) {
//Set current thread id
tid[thread] = (pid_t) syscall (SYS_gettid);
//Wait for all the threads to set their thread id
pthread_barrier_wait(&init_start);
}
//Wait for main to set the affinity
pthread_barrier_wait(&barrier2);
//sleep(1);
//Print affinity
print_affinity(0,thread);
//Do something so that we can see cpu being used
while (1);
pthread_exit(0);
}
int main(int argc , char *argv[]) {
long int i;
pthread_t pid[NR_THREADS];
// Initialize barriers
if(pthread_barrier_init(&init_start, NULL, NR_THREADS+1)) {
printf("Could not create a barrier\n");
exit(1);
}
if(pthread_barrier_init(&barrier2, NULL, NR_THREADS+1)) {
printf("Could not create a barrier\n");
exit(1);
}
//Create threads
for (i = 0; i < NR_THREADS; i++)
pthread_create(&pid[i], NULL, threadCode, (void *) i);
//Wait for threads to set their thread id
if (!USE_THREADAFFINITY)
pthread_barrier_wait(&init_start);
//Set affinity
for (i = 0; i < NR_THREADS; i++) {
if (USE_THREADAFFINITY)
set_threadaffinity(pid[i],0);
else
set_schedaffinity(tid[i],0);
}
//Tell the threads to continue after setting affinity
pthread_barrier_wait(&barrier2);
getchar();
return 0;
}
next prev parent reply other threads:[~2010-06-25 10:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-20 19:10 FW: " Αλέξανδρος Παπαδογιαννάκης
2010-06-23 0:16 ` Andrew Morton
2010-06-23 7:19 ` Peter Zijlstra
2010-06-25 10:19 ` Αλέξανδρος Παπαδογιαννάκης [this message]
2010-06-23 7:20 ` Αλέξανδρος Παπαδογιαννάκης
2010-06-23 7:25 ` Αλέξανδρος Παπαδογιαννάκης
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=COL124-W12DF71EA7EFE8265E7410CD6C70@phx.gbl \
--to=psxlover@hotmail.com \
--cc=peterz@infradead.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®