这篇教程C++ CPU_ISSET函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中CPU_ISSET函数的典型用法代码示例。如果您正苦于以下问题:C++ CPU_ISSET函数的具体用法?C++ CPU_ISSET怎么用?C++ CPU_ISSET使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了CPU_ISSET函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: pmc_cpu_is_primaryintpmc_cpu_is_primary(int cpu){#ifdef SMP return (!CPU_ISSET(cpu, &logical_cpus_mask));#else return (1);#endif}
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:9,
示例2: cpu_set_copy/** * @brief Copy a Linux cpu_set_t. * * @param dst Will be the copy. * * @param src The source (will be copied). * * @return void */static void cpu_set_copy( os_cpu_set_t* dst, os_cpu_set_t* src ){ int i; CPU_ZERO( dst ); for (i = 0; i < CPU_SETSIZE; i++) if ( CPU_ISSET(i, src) ) CPU_SET(i, dst);}
开发者ID:glycerine,项目名称:shore-mt,代码行数:18,
示例3: _mask_to_intstatic int _mask_to_int(cpu_set_t *mask){ int i, rc = 0; for (i=0; i<CPU_SETSIZE; i++) { if (CPU_ISSET(i, mask)) rc += (1 << i); } return rc;}
开发者ID:IFCA,项目名称:slurm,代码行数:9,
示例4: __cpu_countstatic inline unsigned int__cpu_count(const rte_cpuset_t *cpuset){ unsigned int i, count = 0; for (i = 0; i < RTE_MAX_LCORE; i++) if (CPU_ISSET(i, cpuset)) count++; return count;}
开发者ID:DrenfongWong,项目名称:dpdk,代码行数:9,
示例5: GetFullAffinityMask// Get affinity mask of the current process// Parameters:// processMask - affinity mask for the specified process// systemMask - affinity mask for the system// Return:// true if it has succeeded, false if it has failed// Remarks:// A process affinity mask is a bit vector in which each bit represents the processors that// a process is allowed to run on. A system affinity mask is a bit vector in which each bit// represents the processors that are configured into a system.// A process affinity mask is a subset of the system affinity mask. A process is only allowed// to run on the processors configured into a system. Therefore, the process affinity mask cannot// specify a 1 bit for a processor when the system affinity mask specifies a 0 bit for that processor.bool GCToOSInterface::GetCurrentProcessAffinityMask(uintptr_t* processAffinityMask, uintptr_t* systemAffinityMask){ if (g_logicalCpuCount > 64) { *processAffinityMask = 0; *systemAffinityMask = 0; return true; } uintptr_t systemMask = GetFullAffinityMask(g_logicalCpuCount);#if HAVE_SCHED_GETAFFINITY int pid = getpid(); cpu_set_t cpuSet; int st = sched_getaffinity(pid, sizeof(cpu_set_t), &cpuSet); if (st == 0) { uintptr_t processMask = 0; for (int i = 0; i < g_logicalCpuCount; i++) { if (CPU_ISSET(i, &cpuSet)) { processMask |= ((uintptr_t)1) << i; } } *processAffinityMask = processMask; *systemAffinityMask = systemMask; return true; } else if (errno == EINVAL) { // There are more processors than can fit in a cpu_set_t // return zero in both masks. *processAffinityMask = 0; *systemAffinityMask = 0; return true; } else { // We should not get any of the errors that the sched_getaffinity can return since none // of them applies for the current thread, so this is an unexpected kind of failure. return false; }#else // HAVE_SCHED_GETAFFINITY // There is no API to manage thread affinity, so let's return both affinity masks // with all the CPUs on the system set. *systemAffinityMask = systemMask; *processAffinityMask = systemMask; return true;#endif // HAVE_SCHED_GETAFFINITY}
开发者ID:KevinRansom,项目名称:coreclr,代码行数:70,
示例6: pthread_getaffinity_npcpus_t *read_affinity(void) { cpu_set_t mask; int sz = 0 ; int res = pthread_getaffinity_np(pthread_self(), sizeof(mask), &mask) ; if (res != 0) { errexit("pthread_getaffinity_np",res); } for (int p=0 ; p < CPU_SETSIZE ; p++) { if (CPU_ISSET(p,&mask)) sz++ ; } cpus_t *r = cpus_create(sz) ; for (int p=0, *q=r->cpu ; p < CPU_SETSIZE ; p++) { if (CPU_ISSET(p,&mask)) *q++ = p ; } return r ;}
开发者ID:herd,项目名称:herdtools,代码行数:18,
示例7: mainintmain(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,
示例8: defined void Component_exec_i::ccm_activate (void) {#if defined (ACE_HAS_SCHED_GETAFFINITY) if (ACE_OS::num_processors () < 2) { ACE_DEBUG ((LM_DEBUG, "This machine only has a single processor, aborting/n")); return; } cpu_set_t mask; CPU_ZERO (&mask); int retval = sched_getaffinity (0, sizeof (cpu_set_t), &mask); if (retval != 0) { ACE_ERROR ((LM_ERROR, "Error: Non-zero return value from sched_getaffinity %p/n")); return; } int z_set = CPU_ISSET (0, &mask); int o_set = CPU_ISSET (1, &mask); if (cpu_affinity_ == 0 && (!z_set || o_set)) { ACE_ERROR ((LM_ERROR, "Error: Expected to only be on processor zero./n")); return; } if (cpu_affinity_ == 1 && (z_set || !o_set)) { ACE_ERROR ((LM_ERROR, "Error: Expected to only be on processor one./n")); } if (cpu_affinity_ > 1) { ACE_ERROR ((LM_ERROR, "Error: Trying to test an affinity I don't support/n")); }#endif }
开发者ID:Yijtx,项目名称:ACE,代码行数:43,
示例9: test_cpu_clr_case_1static void test_cpu_clr_case_1(size_t cpu){ size_t i; /* * Set to all zeros and verify */ printf( "Exercise CPU_FILL, CPU_CLR(%u), and CPU_ISET/n", cpu ); CPU_FILL(&set1); CPU_CLR(cpu, &set1); /* test if all bits except 5 are set */ for (i=0 ; i<CPU_SETSIZE ; i++) { if (i==cpu) rtems_test_assert( CPU_ISSET(i, &set1) == 0 ); else rtems_test_assert( CPU_ISSET(i, &set1) == 1 ); }}
开发者ID:cloud-hot,项目名称:rtems,代码行数:19,
示例10: getcpu_fromsetint getcpu_fromset(cpu_set_t set, int max_cpus) { int j; for(j=0; j<max_cpus; j++) { if(CPU_ISSET(j,&set)) return j; } return -1;}
开发者ID:daniel-ortiz,项目名称:spm-vII,代码行数:10,
示例11: _cpu_countint_cpu_count(cpu_set_t *set){ int i, n = 0; for (i = 0; i < sizeof(*set) / sizeof(__cpu_mask); i++) if (CPU_ISSET(i, set)) n++; return (n);}
开发者ID:pscedu,项目名称:pfl,代码行数:10,
示例12: _my_cpu_count/* Old pthread implementations do not have the CPU_COUNT macro. */static inline int _my_cpu_count(cpu_set_t *set){ int count = 0; for (int i = 0; i < CPU_SETSIZE; ++i) { if (CPU_ISSET(i, set)) count++; } return count;}
开发者ID:knz,项目名称:snet-rts,代码行数:11,
示例13: ufo_cpu_node_equal_realstatic gbooleanufo_cpu_node_equal_real (UfoNode *n1, UfoNode *n2){ UfoCpuNodePrivate *priv1; UfoCpuNodePrivate *priv2; const gsize MAX_CPUS = MIN (16, CPU_SETSIZE); g_return_val_if_fail (UFO_IS_CPU_NODE (n1) && UFO_IS_CPU_NODE (n2), FALSE); priv1 = UFO_CPU_NODE_GET_PRIVATE (n1); priv2 = UFO_CPU_NODE_GET_PRIVATE (n2); for (gsize i = 0; i < MAX_CPUS; i++) { if (CPU_ISSET (i, priv1->mask) != CPU_ISSET (i, priv2->mask)) return FALSE; } return TRUE;}
开发者ID:Dynalon,项目名称:ufo-core,代码行数:19,
示例14: CPU_COUNTstatic intCPU_COUNT(cpu_set_t *set){ size_t i, count = 0; for (i = 0; i < CPU_SETSIZE; i++) if (CPU_ISSET(i, set)) count++; return count;}
开发者ID:heidsoft,项目名称:libvirt,代码行数:10,
示例15: pmc_cpu_is_activeintpmc_cpu_is_active(int cpu){#ifdef SMP return (pmc_cpu_is_present(cpu) && !CPU_ISSET(cpu, &hlt_cpus_mask));#else return (1);#endif}
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:10,
示例16: cpu_enablestatic int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable){ unsigned int cpu; int online, rc; int configured = -1; for (cpu = 0; cpu < setsize; cpu++) { if (!CPU_ISSET(cpu, cpu_set)) continue; if (!path_exist(_PATH_SYS_CPU "/cpu%d", cpu)) { printf(_("CPU %d does not exist/n"), cpu); continue; } if (!path_exist(_PATH_SYS_CPU "/cpu%d/online", cpu)) { printf(_("CPU %d is not hot pluggable/n"), cpu); continue; } online = path_getnum(_PATH_SYS_CPU "/cpu%d/online", cpu); if ((online == 1) && (enable == 1)) { printf(_("CPU %d is already enabled/n"), cpu); continue; } if ((online == 0) && (enable == 0)) { printf(_("CPU %d is already disabled/n"), cpu); continue; } if (path_exist(_PATH_SYS_CPU "/cpu%d/configure", cpu)) configured = path_getnum(_PATH_SYS_CPU "/cpu%d/configure", cpu); if (enable) { rc = path_writestr("1", _PATH_SYS_CPU "/cpu%d/online", cpu); if ((rc == -1) && (configured == 0)) printf(_("CPU %d enable failed " "(CPU is deconfigured)/n"), cpu); else if (rc == -1) printf(_("CPU %d enable failed (%m)/n"), cpu); else printf(_("CPU %d enabled/n"), cpu); } else { if (onlinecpus && num_online_cpus() == 1) { printf(_("CPU %d disable failed " "(last enabled CPU)/n"), cpu); continue; } rc = path_writestr("0", _PATH_SYS_CPU "/cpu%d/online", cpu); if (rc == -1) printf(_("CPU %d disable failed (%m)/n"), cpu); else { printf(_("CPU %d disabled/n"), cpu); if (onlinecpus) CPU_CLR(cpu, onlinecpus); } } } return EXIT_SUCCESS;}
开发者ID:rseabra,项目名称:util-linux,代码行数:55,
示例17: DetermineNumberOfProcessorsProcessorMap::ProcessorMap() { m_nProcs = 0; m_p_nProcessor_Ids = NULL; m_nProcs = DetermineNumberOfProcessors(); if( m_nProcs <= 0 ) {#ifdef OS_SOLARIS fatal("sysconf() reports %i processors online./n", m_nProcs );#endif#ifdef OS_LINUX fatal("sched_getaffinity() reports empty processor mask./n");#endif } m_p_nProcessor_Ids = new int[m_nProcs]; if(m_p_nProcessor_Ids == NULL ) { fatal("new int[%i] returned NULL -- out of memory?/n", m_nProcs ); } int i; int n = 0;#ifdef OS_SOLARIS int status; for(i=0;n<m_nProcs && i<4096 ;i++) { status = p_online(i,P_STATUS); if(status==-1 && errno==EINVAL) continue; m_p_nProcessor_Ids[n] = i; n++; }#endif#ifdef OS_LINUX cpu_set_t cpus; // Returns number of processors available to process (based on affinity mask) if( sched_getaffinity(0, sizeof(cpus), (cpu_set_t*) &cpus) < 0) { fatal("sched_getaffinity() reports empty processor mask./n" ); } for (i = 0; n<m_nProcs && i < sizeof(cpus)*8; i++) { if( CPU_ISSET( i, &cpus ) ) { m_p_nProcessor_Ids[n] = i; n++; } }#endif if( n != m_nProcs ) { fatal("Unable to find all processor numbers./n" ); }}
开发者ID:dfyer,项目名称:joins,代码行数:55,
|