LCOV - code coverage report
Current view: top level - shared - cpu-set-util.h (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 15 17 88.2 %
Date: 2019-08-22 15:41:25 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : #pragma once
       3             : 
       4             : #include <sched.h>
       5             : 
       6             : #include "macro.h"
       7             : #include "missing_syscall.h"
       8             : 
       9             : /* This wraps the libc interface with a variable to keep the allocated size. */
      10             : typedef struct CPUSet {
      11             :         cpu_set_t *set;
      12             :         size_t allocated; /* in bytes */
      13             : } CPUSet;
      14             : 
      15        1721 : static inline void cpu_set_reset(CPUSet *a) {
      16        1721 :         assert((a->allocated > 0) == !!a->set);
      17        1721 :         if (a->set)
      18          19 :                 CPU_FREE(a->set);
      19        1721 :         *a = (CPUSet) {};
      20        1721 : }
      21             : 
      22             : int cpu_set_add_all(CPUSet *a, const CPUSet *b);
      23             : 
      24             : char* cpu_set_to_string(const CPUSet *a);
      25             : char *cpu_set_to_range_string(const CPUSet *a);
      26             : int cpu_set_realloc(CPUSet *cpu_set, unsigned ncpus);
      27             : 
      28             : int parse_cpu_set_full(
      29             :                 const char *rvalue,
      30             :                 CPUSet *cpu_set,
      31             :                 bool warn,
      32             :                 const char *unit,
      33             :                 const char *filename, unsigned line,
      34             :                 const char *lvalue);
      35             : int parse_cpu_set_extend(
      36             :                 const char *rvalue,
      37             :                 CPUSet *old,
      38             :                 bool warn,
      39             :                 const char *unit,
      40             :                 const char *filename,
      41             :                 unsigned line,
      42             :                 const char *lvalue);
      43             : 
      44           0 : static inline int parse_cpu_set(const char *rvalue, CPUSet *cpu_set){
      45           0 :         return parse_cpu_set_full(rvalue, cpu_set, false, NULL, NULL, 0, NULL);
      46             : }
      47             : 
      48             : int cpu_set_to_dbus(const CPUSet *set, uint8_t **ret, size_t *allocated);
      49             : int cpu_set_from_dbus(const uint8_t *bits, size_t size, CPUSet *set);
      50             : 
      51             : int cpus_in_affinity_mask(void);
      52             : 
      53         171 : static inline bool mpol_is_valid(int t) {
      54         171 :         return t >= MPOL_DEFAULT && t <= MPOL_LOCAL;
      55             : }
      56             : 
      57             : typedef struct NUMAPolicy {
      58             :         /* Always use numa_policy_get_type() to read the value */
      59             :         int type;
      60             :         CPUSet nodes;
      61             : } NUMAPolicy;
      62             : 
      63             : bool numa_policy_is_valid(const NUMAPolicy *p);
      64             : 
      65         172 : static inline int numa_policy_get_type(const NUMAPolicy *p) {
      66         172 :         return p->type < 0 ? (p->nodes.set ? MPOL_PREFERRED : -1) : p->type;
      67             : }
      68             : 
      69        1118 : static inline void numa_policy_reset(NUMAPolicy *p) {
      70        1118 :         assert(p);
      71        1118 :         cpu_set_reset(&p->nodes);
      72        1118 :         p->type = -1;
      73        1118 : }
      74             : 
      75             : int apply_numa_policy(const NUMAPolicy *policy);
      76             : 
      77             : const char* mpol_to_string(int i) _const_;
      78             : int mpol_from_string(const char *s) _pure_;

Generated by: LCOV version 1.14