Hardware Locality (hwloc) 1.4

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List

glibc-sched.h

    00001 /*
    00002  * Copyright © 2009 CNRS
    00003  * Copyright © 2009-2010 inria.  All rights reserved.
    00004  * Copyright © 2009-2011 Université Bordeaux 1
    00005  * Copyright © 2011 Cisco Systems, Inc.  All rights reserved.
    00006  * See COPYING in top-level directory.
    00007  */
    00008
    00017 #ifndef HWLOC_GLIBC_SCHED_H
    00018 #define HWLOC_GLIBC_SCHED_H
    00019
    00020 #include <hwloc.h>
    00021 #include <hwloc/helper.h>
    00022 #include <assert.h>
    00023
    00024 #if !defined _GNU_SOURCE || !defined _SCHED_H || (!defined CPU_SETSIZE && !defined sched_priority)
    00025 #error Please make sure to include sched.h before including glibc-sched.h, and define _GNU_SOURCE before any inclusion of sched.h
    00026 #endif
    00027
    00028
    00029 #ifdef __cplusplus
    00030 extern "C" {
    00031 #endif
    00032
    00033
    00034 #ifdef HWLOC_HAVE_CPU_SET
    00035
    00036
    00049 static inline int
    00050 hwloc_cpuset_to_glibc_sched_affinity(hwloc_topology_t topology , hwloc_const_cpuset_t hwlocset,
    00051                                     cpu_set_t *schedset, size_t schedsetsize)
    00052 {
    00053 #ifdef CPU_ZERO_S
    00054   unsigned cpu;
    00055   CPU_ZERO_S(schedsetsize, schedset);
    00056   hwloc_bitmap_foreach_begin(cpu, hwlocset)
    00057     CPU_SET_S(cpu, schedsetsize, schedset);
    00058   hwloc_bitmap_foreach_end();
    00059 #else /* !CPU_ZERO_S */
    00060   unsigned cpu;
    00061   CPU_ZERO(schedset);
    00062   assert(schedsetsize == sizeof(cpu_set_t));
    00063   hwloc_bitmap_foreach_begin(cpu, hwlocset)
    00064     CPU_SET(cpu, schedset);
    00065   hwloc_bitmap_foreach_end();
    00066 #endif /* !CPU_ZERO_S */
    00067   return 0;
    00068 }
    00069
    00077 static inline int
    00078 hwloc_cpuset_from_glibc_sched_affinity(hwloc_topology_t topology , hwloc_cpuset_t hwlocset,
    00079                                        const cpu_set_t *schedset, size_t schedsetsize)
    00080 {
    00081   int cpu;
    00082 #ifdef CPU_ZERO_S
    00083   int count;
    00084 #endif
    00085   hwloc_bitmap_zero(hwlocset);
    00086 #ifdef CPU_ZERO_S
    00087   count = CPU_COUNT_S(schedsetsize, schedset);
    00088   cpu = 0;
    00089   while (count) {
    00090     if (CPU_ISSET_S(cpu, schedsetsize, schedset)) {
    00091       hwloc_bitmap_set(hwlocset, cpu);
    00092       count--;
    00093     }
    00094     cpu++;
    00095   }
    00096 #else /* !CPU_ZERO_S */
    00097   /* sched.h does not support dynamic cpu_set_t (introduced in glibc 2.7),
    00098    * assume we have a very old interface without CPU_COUNT (added in 2.6)
    00099    */
    00100   assert(schedsetsize == sizeof(cpu_set_t));
    00101   for(cpu=0; cpu<CPU_SETSIZE; cpu++)
    00102     if (CPU_ISSET(cpu, schedset))
    00103       hwloc_bitmap_set(hwlocset, cpu);
    00104 #endif /* !CPU_ZERO_S */
    00105   return 0;
    00106 }
    00107
    00111 #endif /* CPU_SET */
    00112
    00113
    00114 #ifdef __cplusplus
    00115 } /* extern "C" */
    00116 #endif
    00117
    00118
    00119 #endif /* HWLOC_GLIBC_SCHED_H */