本文整理汇总了C++中pthread_setaffinity_np函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_setaffinity_np函数的具体用法?C++ pthread_setaffinity_np怎么用?C++ pthread_setaffinity_np使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_setaffinity_np函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: __sync_fetch_and_add
void ObMergeServer::on_ioth_start()
{
int64_t affinity_start_cpu = ms_config_.io_thread_start_cpu;
int64_t affinity_end_cpu = ms_config_.io_thread_end_cpu;
if (0 <= affinity_start_cpu
&& affinity_start_cpu <= affinity_end_cpu)
{
static volatile int64_t cpu = 0;
int64_t local_cpu = __sync_fetch_and_add(&cpu, 1) % (affinity_end_cpu - affinity_start_cpu + 1) + affinity_start_cpu;
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(local_cpu, &cpuset);
int ret = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
TBSYS_LOG(INFO, "io thread setaffinity tid=%ld ret=%d cpu=%ld start=%ld end=%ld",
GETTID(), ret, local_cpu, affinity_start_cpu, affinity_end_cpu);
}
}
开发者ID:Alibaba-boonya,项目名称:oceanbase,代码行数:17,代码来源:ob_merge_server.cpp
示例2: set_cpu
static void set_cpu(void)
{
pthread_mutex_lock(&cpu_affinity_mutex);
static int core=0;
int num_cores = sysconf(_SC_NPROCESSORS_ONLN);
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(core, &cpuset);
if (pthread_setaffinity_np(pthread_self(),
sizeof(cpu_set_t), &cpuset) != 0) {
log_error("zmap", "can't set thread CPU affinity");
}
log_trace("zmap", "set thread %u affinity to core %d",
pthread_self(), core);
core = (core + 1) % num_cores;
pthread_mutex_unlock(&cpu_affinity_mutex);
}
开发者ID:jacobgardiner,项目名称:zmap,代码行数:17,代码来源:zmap.c
示例3: vm_loop
static void
vm_loop(struct vmctx *ctx, int vcpu, uint64_t startrip)
{
int error, rc, prevcpu;
enum vm_exitcode exitcode;
cpuset_t active_cpus;
if (vcpumap[vcpu] != NULL) {
error = pthread_setaffinity_np(pthread_self(),
sizeof(cpuset_t), vcpumap[vcpu]);
assert(error == 0);
}
error = vm_active_cpus(ctx, &active_cpus);
assert(CPU_ISSET(vcpu, &active_cpus));
error = vm_set_register(ctx, vcpu, VM_REG_GUEST_RIP, startrip);
assert(error == 0);
while (1) {
error = vm_run(ctx, vcpu, &vmexit[vcpu]);
if (error != 0)
break;
prevcpu = vcpu;
exitcode = vmexit[vcpu].exitcode;
if (exitcode >= VM_EXITCODE_MAX || handler[exitcode] == NULL) {
fprintf(stderr, "vm_loop: unexpected exitcode 0x%x\n",
exitcode);
exit(1);
}
rc = (*handler[exitcode])(ctx, &vmexit[vcpu], &vcpu);
switch (rc) {
case VMEXIT_CONTINUE:
break;
case VMEXIT_ABORT:
abort();
default:
exit(1);
}
}
fprintf(stderr, "vm_run error %d, errno %d\n", error, errno);
}
开发者ID:moscaliucpaulandrei,项目名称:freebsd,代码行数:46,代码来源:bhyverun.c
示例4: vm_loop
static void
vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip)
{
cpuset_t mask;
int error, rc, prevcpu;
enum vm_exitcode exitcode;
if (pincpu >= 0) {
CPU_ZERO(&mask);
CPU_SET(pincpu + vcpu, &mask);
error = pthread_setaffinity_np(pthread_self(),
sizeof(mask), &mask);
assert(error == 0);
}
while (1) {
error = vm_run(ctx, vcpu, rip, &vmexit[vcpu]);
if (error != 0)
break;
prevcpu = vcpu;
exitcode = vmexit[vcpu].exitcode;
if (exitcode >= VM_EXITCODE_MAX || handler[exitcode] == NULL) {
fprintf(stderr, "vm_loop: unexpected exitcode 0x%x\n",
exitcode);
exit(1);
}
rc = (*handler[exitcode])(ctx, &vmexit[vcpu], &vcpu);
switch (rc) {
case VMEXIT_CONTINUE:
rip = vmexit[vcpu].rip + vmexit[vcpu].inst_length;
break;
case VMEXIT_RESTART:
rip = vmexit[vcpu].rip;
break;
case VMEXIT_RESET:
exit(0);
default:
exit(1);
}
}
fprintf(stderr, "vm_run error %d, errno %d\n", error, errno);
}
开发者ID:andrewbates09,项目名称:numa,代码行数:46,代码来源:bhyverun.c
示例5: setaffinity
/* set the thread affinity. */
static int setaffinity(pthread_t me, int i)
{
cpu_set_t cpumask;
if (i == -1)
return 0;
/* Set thread affinity affinity.*/
CPU_ZERO(&cpumask);
CPU_SET(i, &cpumask);
if (pthread_setaffinity_np(me, sizeof(cpu_set_t), &cpumask) != 0) {
D("Unable to set affinity: %s", strerror(errno));
return 1;
}
return 0;
}
开发者ID:juneman,项目名称:netmap,代码行数:18,代码来源:testrangenic.c
示例6: perror
void AExecutable::SetThreadAffinity(boost::thread* daThread, int threadPriority, std::vector<short> CPUsToBind, int scheduler) {
#ifndef __APPLE__
int policy;
pthread_t threadID = (pthread_t) (daThread->native_handle());
if (scheduler > 0) {
sched_param param;
if (pthread_getschedparam(threadID, &policy, ¶m) != 0) {
perror("pthread_getschedparam");
exit(EXIT_FAILURE);
}
//LOG_ERROR("Policy " << policy << ", priority " << param.sched_priority);
/**
* Set scheduling algorithm
* Possible values: SCHED_FIFO(1), SCHED_RR(2), SCHED_OTHER(0)
*/
policy = scheduler;
param.__sched_priority = threadPriority;
if (pthread_setschedparam(threadID, policy, ¶m) != 0) {
perror("pthread_setschedparam");
exit(EXIT_FAILURE);
}
}
if (CPUsToBind.size() > 0) {
/**
* Bind the thread to CPUs from CPUsToBind
*/
cpu_set_t mask;
CPU_ZERO(&mask);
for (unsigned int i = 0; i < CPUsToBind.size(); i++) {
if (CPUsToBind[i] == -1) {
CPU_ZERO(&mask);
break;
}
CPU_SET(CPUsToBind[i], &mask);
}
if (pthread_setaffinity_np(threadID, sizeof(mask), &mask) < 0) {
throw NA62Error("Unable to bind threads to specific CPUs!");
}
}
#endif
}
开发者ID:MBoretto,项目名称:NA62_Toy,代码行数:45,代码来源:AExecutable.cpp
示例7: fvl_ssd_write_t
static void fvl_ssd_write_t(void *arg)
{
fvl_ssd_arg_t *priv=arg;
fvl_queue_t *fqueue=priv->fqueue;
int rvl;
int fd ;
uint32_t index = priv->index;
uint8_t count=0;
char path1[20];
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(priv->cpu,&cpuset);
rvl = pthread_setaffinity_np(pthread_self(),sizeof(cpu_set_t),&cpuset);
if(rvl){
printf("(%d)fail:pthread_setaffinity_np()\n",priv->cpu);
return;
}
sprintf(path1,"/mnt/test%d",index);
fd=fvl_ssd_open(path1);
int dequeue_num=-1;
void *buf=NULL;
/* uint32_t test_data=0+index*0x1000000;
uint32_t times=0,error_count=0;
*/
while(1)
{
dequeue_num=fvl_dequeue(fqueue,4);
if(dequeue_num != -1)
{
buf = fqueue->buf+dequeue_num*FVL_SRIO_DMA_BLKBYTES;
fvl_ssd_write(fd,buf,4*FVL_SRIO_DMA_BLKBYTES);
fvl_dequeue_complete(fqueue,4);
count++;
if(count == 16)
{
fvl_ssd_close(fd);
index=index+4;
sprintf(path1,"/mnt/test%d",index);
fd=fvl_ssd_open(path1);
count = 0;
}
}
}
}
开发者ID:Cai900205,项目名称:test,代码行数:45,代码来源:fvl_main.c
示例8: thread_channel_recv
void thread_channel_recv(void *arg)
{
struct timeval tm_start,tm_end;
fvl_read_rvl_t rlen;
uint8_t i=0;
int rvl=0;
uint64_t total_count=0;
gettimeofday(&tm_start,NULL);
int fd=0;
int *j=(int *)arg;
fd=*j;
printf("j:%d\n",*j);
int cpu=*j+11;
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(cpu,&cpuset);
rvl = pthread_setaffinity_np(pthread_self(),sizeof(cpu_set_t),&cpuset);
if(rvl){
printf("(%d)fail:pthread_setaffinity_np()\n",cpu);
return;
}
while(1)
{
rlen.len=0x100000;
rvl=fvl_srio_read(fd,&rlen);
if(rlen.len!=0)
{
test_data(i,rlen.buf_virt,10485,0);
i++;
// printf("##########:%d\n",i);
gettimeofday(&tm_end,NULL);
total_count++;
double diff=(tm_end.tv_sec-tm_start.tv_sec)+(tm_end.tv_usec-tm_start.tv_usec)/1000000.0;
if(diff>5)
{
double da_lu=total_count/diff;
printf("receive fd: %d length(byte): %-15u time(s): %-15f avg MB/s: %-15f total_count:%lld \n",fd,rlen.len,diff,da_lu,total_count);
fflush(stdout);
total_count=0;
gettimeofday(&tm_start,NULL);
}
}
fvl_srio_read_feedback(fd,rlen.num);
}
}
开发者ID:Cai900205,项目名称:test,代码行数:45,代码来源:main.c
示例9: CPU_ZERO
void *t_send(void *arg)
{
int z=0;
char buf[40000];
struct task_type *send=arg;
int sockfd=send->fd;
struct sockaddr_in adr_srvr=send->adr;
int opt=1;
int size = send->len;
cpu_set_t cpuset;
struct timeval tm_start,tm_end;
CPU_ZERO(&cpuset);
CPU_SET(send->cpu,&cpuset);
if((z=pthread_setaffinity_np(pthread_self(),sizeof(cpu_set_t),&cpuset))>0)
{
printf("cpu error!\n");
exit(1);
}
gettimeofday(&tm_start,NULL);
uint64_t total_count=0;
while(1)
{
// memset(buf,1,size);
z=sendto(sockfd,buf,size,0,(struct sockaddr *)&adr_srvr,sizeof(adr_srvr));
if(z<0)
{
printf("send error!\n");
exit(1);
}
total_count++;
gettimeofday(&tm_end,NULL);
double diff = (tm_end.tv_sec-tm_start.tv_sec)+((tm_end.tv_usec-tm_start.tv_usec)/1000000.0);
if(diff>5)
{
double du_la=((total_count*size)/diff)/1024/1024;
printf("thread: %d length(byte):%-15u time(s):%-15f avg MB/s %-15f total_count:%lld\n",send->cpu,size,diff,du_la,total_count);
total_count=0;
gettimeofday(&tm_start,NULL);
}
}
pthread_exit(NULL);
}
开发者ID:Cai900205,项目名称:test,代码行数:45,代码来源:udp-send.c
示例10: CPU_ZERO
bool SkThread::setProcessorAffinity(unsigned int processor) {
SkThread_PThreadData* pthreadData = static_cast<SkThread_PThreadData*>(fData);
if (!pthreadData->fValidPThread) {
return false;
}
cpu_set_t parentCpuset;
if (0 != pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &parentCpuset)) {
return false;
}
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(nth_set_cpu(processor, &parentCpuset), &cpuset);
return 0 == pthread_setaffinity_np(pthreadData->fPThread,
sizeof(cpu_set_t),
&cpuset);
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:18,代码来源:SkThreadUtils_pthread_linux.cpp
示例11: write_affinity
void write_affinity(cpus_t *p) {
cpu_set_t mask;
int exists_pos = 0 ;
CPU_ZERO(&mask) ;
for (int k = 0 ; k < p->sz ; k++) {
if (p->cpu[k] >= 0) {
CPU_SET(p->cpu[k],&mask) ;
exists_pos = 1 ;
}
}
if (exists_pos) {
int r = pthread_setaffinity_np(pthread_self(),sizeof(mask),&mask) ;
if (r != 0) {
errexit("pthread_setaffinity_np",r) ;
}
}
}
开发者ID:herd,项目名称:herdtools,代码行数:18,代码来源:_linux_affinity.c
示例12: bindthread2core
int bindthread2core(pthread_t thread_id, u_int core_id) {
#ifdef HAVE_PTHREAD_SETAFFINITY_NP
cpu_set_t cpuset;
int s;
CPU_ZERO(&cpuset);
CPU_SET(core_id, &cpuset);
if((s = pthread_setaffinity_np(thread_id, sizeof(cpu_set_t), &cpuset)) != 0) {
fprintf(stderr, "Error while binding to core %u: errno=%i\n", core_id, s);
return(-1);
} else {
return(0);
}
#else
fprintf(stderr, "WARNING: your system lacks of pthread_setaffinity_np() (not core binding)\n");
return(0);
#endif
}
开发者ID:GreggIndustries,项目名称:PF_RING,代码行数:18,代码来源:pfutils.c
示例13: bar
void bar(int x)
{
cpu_set_t cpuset;
pthread_t tid = pthread_self();
CPU_ZERO(&cpuset);
CPU_SET(2, &cpuset);
pthread_setaffinity_np(tid, sizeof(cpuset), &cpuset);
timespec time_val{};
//time_val.tv_nsec = sleep_ns; // 10 micro sec
// do stuff...
for(int i = 0 ; !signal_received; i++)
{
std::cout << " bar: "<< tid << std::endl;
//nanosleep( &time_val, NULL);
}
}
开发者ID:jazaman,项目名称:private_cpp_practice,代码行数:18,代码来源:affinity_test.cpp
示例14: bind_cpu
static int bind_cpu(thread_t *thread) {
size_t setsize;
cpu_set_t *cur_cpuset;
cpu_set_t *new_cpuset;
int ncpus = max_number_of_cpus();
if (thread == NULL) {
// if thread is NULL it means the emulator is disabled, return without setting CPU affinity
//printf("thread self is null");
return 0;
}
if (ncpus == 0) {
return 1;
}
setsize = CPU_ALLOC_SIZE(ncpus);
cur_cpuset = CPU_ALLOC(ncpus);
new_cpuset = CPU_ALLOC(ncpus);
CPU_ZERO_S(setsize, cur_cpuset);
CPU_ZERO_S(setsize, new_cpuset);
CPU_SET_S(thread->cpu_id, setsize, new_cpuset);
if (pthread_getaffinity_np(thread->pthread, setsize, cur_cpuset) != 0) {
DBG_LOG(ERROR, "Cannot get thread tid [%d] affinity, pthread: 0x%lx on processor %d\n",
thread->tid, thread->pthread, thread->cpu_id);
return 1;
}
if (CPU_EQUAL(cur_cpuset, new_cpuset)) {
//printf("No need to bind CPU\n");
return 0;
}
DBG_LOG(INFO, "Binding thread tid [%d] pthread: 0x%lx on processor %d\n", thread->tid, thread->pthread, thread->cpu_id);
if (pthread_setaffinity_np(thread->pthread, setsize, new_cpuset) != 0) {
DBG_LOG(ERROR, "Cannot bind thread tid [%d] pthread: 0x%lx on processor %d\n", thread->tid, thread->pthread, thread->cpu_id);
return 1;
}
return 0;
}
开发者ID:HewlettPackard,项目名称:quartz,代码行数:44,代码来源:multilat.c
示例15: main
int
main(int argc, char *argv[])
{
int s, j, nprocs;
cpu_set_t cpuset;
pthread_t thread;
thread = pthread_self();
nprocs = sysconf(_SC_NPROCESSORS_ONLN);
/* Set affinity mask to include CPUs 0 to 7 */
CPU_ZERO(&cpuset);
for (j = 0; j < nprocs; j++)
CPU_SET(j, &cpuset);
CPU_CLR(1, &cpuset);
CPU_CLR(2, &cpuset);
CPU_CLR(3, &cpuset);
CPU_CLR(4, &cpuset);
CPU_CLR(5, &cpuset);
/* check if the cpu's have actually been set */
for (j = 0; j < nprocs; j++)
fprintf(stdout, "CPU: %d, status: %d\n", j, CPU_ISSET(j, &cpuset));
s = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
if (s != 0)
handle_error_en(s, "pthread_setaffinity_np");
/* Check the actual affinity mask assigned to the thread */
s = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
if (s != 0)
handle_error_en(s, "pthread_getaffinity_np");
printf("Set returned by pthread_getaffinity_np() contained:\n");
for (j = 0; j < CPU_SETSIZE; j++)
if (CPU_ISSET(j, &cpuset))
printf(" CPU %d\n", j);
exit(EXIT_SUCCESS);
}
开发者ID:fortsage,项目名称:nio,代码行数:44,代码来源:pthread_affinity.c
示例16: viterbi_stream_create_threads
void viterbi_stream_create_threads(DATA_STREAM* dstream)
{
int i;
pthread_barrier_init(&dstream->barrier, NULL, NTHREADS);
for (i = 0; i < NTHREADS-1; i++)
sem_init(&semsynch[i], 0, 0);
if(NTHREADS == 1)
return;
pthread_t threads[NTHREADS];
pthr_info_t args;
args.dstream = dstream; args.thrid = 0;
#ifdef _GNU_SOURCE
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(MAPIDCPU(NTHREADS-1), &cpuset);
threads[NTHREADS-1] = pthread_self();
pthread_setaffinity_np(threads[NTHREADS-1], sizeof(cpu_set_t), &cpuset);
#endif
for (i = 0; i < NTHREADS-1; i++)
{
pthr_info_t *argscopy = calloc(1, sizeof(pthr_info_t));
memcpy(argscopy, &args, sizeof(pthr_info_t));
argscopy->thrid = i;
pthread_attr_t attr;
pthread_attr_init(&attr);
#ifdef _GNU_SOURCE
CPU_ZERO(&cpuset);
CPU_SET(MAPIDCPU(i), &cpuset);
pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cpuset);
#endif
if (pthread_create(&threads[i], &attr, viterbi_stream_thread_loop, argscopy))
exit(fprintf(stderr, "ERROR could not create worker thread\n"));
}
#ifdef _GNU_SOURCE
printf("THR %d running on cpu %d\n", NTHREADS-1, sched_getcpu());
#endif
}
开发者ID:ParaSky,项目名称:cops,代码行数:44,代码来源:viterbi_stream-counter.c
示例17: bindThread
void bindThread(uint32_t threadId, uint32_t procGroupId = 0, bool bindProcGroup=false)
{
// Only bind threads when MAX_WORKER_THREADS isn't set.
if (KNOB_MAX_WORKER_THREADS && bindProcGroup == false)
{
return;
}
#if defined(_WIN32)
{
GROUP_AFFINITY affinity = {};
affinity.Group = procGroupId;
#if !defined(_WIN64)
if (threadId >= 32)
{
// In a 32-bit process on Windows it is impossible to bind
// to logical processors 32-63 within a processor group.
// In this case set the mask to 0 and let the system assign
// the processor. Hopefully it will make smart choices.
affinity.Mask = 0;
}
else
#endif
{
// If KNOB_MAX_WORKER_THREADS is set, only bind to the proc group,
// Not the individual HW thread.
if (!KNOB_MAX_WORKER_THREADS)
{
affinity.Mask = KAFFINITY(1) << threadId;
}
}
SetThreadGroupAffinity(GetCurrentThread(), &affinity, nullptr);
}
#else
cpu_set_t cpuset;
pthread_t thread = pthread_self();
CPU_ZERO(&cpuset);
CPU_SET(threadId, &cpuset);
pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
#endif
}
开发者ID:notaz,项目名称:mesa,代码行数:44,代码来源:threads.cpp
示例18: fvl_srio_recv_ctl
//need change
void fvl_srio_recv_ctl(void *arg)
{
fvl_ctl_thread_t *priv=arg;
volatile fvl_srio_ctl_info_t *pcnt;
uint16_t ctl_count=0;
pcnt = (fvl_srio_ctl_info_t *)(priv->buf_virt);
FVL_LOG("channel:%d Slave recv ctl !\n",priv->fd);
int rvl=0;
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(priv->cpu,&cpuset);
rvl = pthread_setaffinity_np(pthread_self(),sizeof(cpu_set_t),&cpuset);
if(rvl)
{
FVL_LOG("(%d)fail:pthread_setaffinity_np()\n",priv->cpu);
return;
}
while(1)
{
uint32_t count=0;
count=pcnt->com;
if(pcnt->fla==1)
{
pcnt->fla=0;
// FVL_LOG("recv buffer full!\n");
continue;
}
else
{
if(count < ctl_count)
{
receive_num[priv->fd]=receive_num[priv->fd]+(head_port[priv->port_num].data_re_cluster[(priv->fd%FVL_PORT_CHAN_NUM_MAX)].buf_num -ctl_count);
ctl_count=0;
}
else if(count >ctl_count)
{
receive_num[priv->fd]=receive_num[priv->fd]+(count-ctl_count);
ctl_count=count;
}
}
}
pthread_exit(NULL);
return;
}
开发者ID:Cai900205,项目名称:test,代码行数:45,代码来源:fvl_srio.c
示例19: thread_channel_send
void thread_channel_send(void *arg)
{
chan_send_t *param=(chan_send_t *)arg;
fvl_dma_pool_t *port_data=param->port_data;
int rvl=0;
uint8_t i=0;
int j=param->fd;
int fd= j;
struct timeval tm_start,tm_end;
int cpu=j+14;
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(cpu,&cpuset);
rvl = pthread_setaffinity_np(pthread_self(),sizeof(cpu_set_t),&cpuset);
if(rvl){
printf("(%d)fail:pthread_setaffinity_np()\n",cpu);
return;
}
sleep(10);
uint64_t total_count=0;
gettimeofday(&tm_start,NULL);
i=0;
while(1)
{
memset(port_data->dma_virt_base,i,Buf_size);
rvl=fvl_srio_write(fd,port_data->dma_phys_base,Buf_size);
if(rvl!=0)
{
continue;
}
gettimeofday(&tm_end,NULL);
i++;
total_count++;
double diff=(tm_end.tv_sec-tm_start.tv_sec)+(tm_end.tv_usec-tm_start.tv_usec)/1000000.0;
if(diff>5)
{
double da_lu=total_count*Buf_size/1048576/diff;
printf("fd: %d length(byte): %-15u time(s): %-15f avg MB/s: %-15f total_count:%lld \n",fd,Buf_size,diff,da_lu,total_count);
fflush(stdout);
total_count=0;
gettimeofday(&tm_start,NULL);
}
}
}
开发者ID:Cai900205,项目名称:test,代码行数:44,代码来源:main.c
示例20: m_stopped
ThreadPool::ThreadPool(size_t numThreads, int cpuAffinityOffset,
int cpuAffinityIncr) :
m_stopped(false), m_stopping(false), m_queueLimit(0)
{
size_t numCPU = sysconf(_SC_NPROCESSORS_ONLN);
int cpuInd = cpuAffinityOffset % numCPU;
for (size_t i = 0; i < numThreads; ++i) {
boost::thread *thread = m_threads.create_thread(
boost::bind(&ThreadPool::Execute, this));
#ifdef __linux
if (cpuAffinityOffset >= 0) {
int s;
boost::thread::native_handle_type handle = thread->native_handle();
//cerr << "numCPU=" << numCPU << endl;
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(cpuInd, &cpuset);
cpuInd += cpuAffinityIncr;
cpuInd = cpuInd % numCPU;
s = pthread_setaffinity_np(handle, sizeof(cpu_set_t), &cpuset);
if (s != 0) {
handle_error_en(s, "pthread_setaffinity_np");
//cerr << "affinity error with thread " << i << endl;
}
// get affinity
CPU_ZERO(&cpuset);
s = pthread_getaffinity_np(handle, sizeof(cpu_set_t), &cpuset);
cerr << "Set returned by pthread_getaffinity_np() contained:\n";
for (int j = 0; j < CPU_SETSIZE; j++) {
if (CPU_ISSET(j, &cpuset)) {
cerr << " CPU " << j << "\n";
}
}
}
#endif
}
}
开发者ID:ebay-hlt,项目名称:mosesdecoder,代码行数:44,代码来源:ThreadPool.cpp
注:本文中的pthread_setaffinity_np函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论