当前位置: 首页>>代码示例>>C++>>正文


C++ CPU_ISSET函数代码示例

本文整理汇总了C++中CPU_ISSET函数的典型用法代码示例。如果您正苦于以下问题:C++ CPU_ISSET函数的具体用法?C++ CPU_ISSET怎么用?C++ CPU_ISSET使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CPU_ISSET函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: pmc_cpu_is_primary

int
pmc_cpu_is_primary(int cpu)
{
#ifdef	SMP
	return (!CPU_ISSET(cpu, &logical_cpus_mask));
#else
	return (1);
#endif
}
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:9,代码来源:kern_pmc.c

示例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,代码来源:cpu_set.cpp

示例3: _mask_to_int

static 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,代码来源:test1.89.prog.c

示例4: __cpu_count

static 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,代码来源:pthread_shim.c

示例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,代码来源:gcenv.unix.cpp

示例6: pthread_getaffinity_np

cpus_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,代码来源:_linux_affinity.c

示例7: 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

示例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,代码来源:CPUAffinity_exec.cpp

示例9: test_cpu_clr_case_1

static 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,代码来源:init.c

示例10: getcpu_fromset

int 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,代码来源:force-remote.c

示例11: _cpu_count

int
_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,代码来源:sys.c

示例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,代码来源:entity.c

示例13: ufo_cpu_node_equal_real

static gboolean
ufo_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,代码来源:ufo-cpu-node.c

示例14: CPU_COUNT

static int
CPU_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,代码来源:nodeinfo.c

示例15: pmc_cpu_is_active

int
pmc_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,代码来源:kern_pmc.c


注:本文中的CPU_ISSET函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。