1/** 2 * \file 3 * \brief Bitmap manipulation 4 * 5 */ 6 7/* 8 * Copyright (c) 2014, ETH Zurich. 9 * All rights reserved. 10 * 11 * This file is distributed under the terms in the attached LICENSE file. 12 * If you do not find this file, copies can be found by writing to: 13 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group. 14 */ 15 16#include <stdio.h> 17#include <string.h> 18 19#include <barrelfish/barrelfish.h> 20 21#include <numa.h> 22#include <numa_internal.h> 23#include <bitmap.h> 24 25 26/** 27 * \brief parses a character string list of nodes into a bit mask. 28 * 29 * \param string character string to parse 30 * 31 * \returns NUMA bitmask on SUCCESS 32 * NULL if the string is invalid 33 * 34 * The string is a comma-separated list of node numbers or node ranges 35 * Examples: 1-5,7,10 !4-5 +0-3 36 * 37 * If the string length is zero, then the numa_no_nodes_ptr is returned 38 */ 39struct bitmap *numa_parse_nodestring(char *string) 40{ 41 assert(!"NYI"); 42 return NULL; 43} 44 45/** 46 * \brief parses a character string list of cpus into a bit mask. 47 * 48 * \param string character string to parse 49 * 50 * \returns NUMA bitmask on SUCCESS 51 * NULL if the string is invalid 52 * 53 * The string is a comma-separated list of cpu numbers or cpu ranges 54 * Examples: 1-5,7,10 !4-5 +0-3 55 */ 56struct bitmap *numa_parse_cpustring(char *string) 57{ 58 assert(!"NYI"); 59 return NULL; 60} 61 62/** 63 * \brief allocating a bitmap to hold all the configured CPUs 64 * @return 65 */ 66struct bitmap *numa_allocate_cpumask(void) 67{ 68 return bitmap_alloc(numa_topology.num_cores); 69} 70 71/** 72 * \brief frees a previously allocated CPU bitmask 73 * 74 * \param cpumask pointer to a previously allocated CPU bitmask 75 */ 76void numa_free_cpumask(struct bitmap *cpumask) 77{ 78 bitmap_free(cpumask); 79} 80 81/** 82 * \brief allocates a bit mask to represent the nodes in the system 83 * 84 * \returns pointer to a new bitmask 85 * NULL on failure 86 */ 87struct bitmap *numa_allocate_nodemask(void) 88{ 89 return bitmap_alloc(NUMA_MAX_NUMNODES); 90} 91 92/** 93 * \brief frees a previously allocated node bitmask 94 * 95 * \param nodemask pointer to a previously allocated node bitmask 96 */ 97void numa_free_nodemask(struct bitmap *nodemask) 98{ 99 bitmap_free(nodemask); 100} 101 102/** 103 * \brief allocates a bitmask structure and its associated bit mask 104 * 105 * \param n the number of bits 106 * 107 * \returns pointer to the bitmask 108 * NULL on error 109 */ 110struct bitmap *numa_bitmask_alloc(unsigned int n) 111{ 112 return bitmap_alloc(n); 113} 114 115/** 116 * \brief sets all bits in the bit mask to 0. 117 * 118 * \param bmp pointer to the bitmap 119 * 120 * \returns pointer to the cleared bit map 121 */ 122struct bitmap *numa_bitmask_clearall(struct bitmap *bmp) 123{ 124 bitmap_clear_all(bmp); 125 return bmp; 126} 127 128/** 129 * \brief clears the n-th bit of a bitmask 130 * 131 * \param bmp the bitmask 132 * \param n the bit to clear 133 * 134 * \returns pointer to the bitmask 135 */ 136struct bitmap *numa_bitmask_clearbit(struct bitmap *bmp, unsigned int n) 137{ 138 bitmap_clear_bit(bmp, n); 139 return bmp; 140} 141 142/** 143 * \brief checks if two bitmasks are equal 144 * 145 * \param bmp1 bitmask 1 146 * \param bmp2 bitmask 2 147 * 148 * \return TRUE if the bitmasks are equal 149 * FALSE if the are distinct 150 */ 151bool numa_bitmask_equal(const struct bitmap *bmp1, const struct bitmap *bmp2) 152{ 153 return bitmap_equal(bmp1, bmp2); 154} 155 156/** 157 * \brief frees the memory of a bitmask 158 * 159 * \param bmp the bitmask to be freed 160 */ 161void numa_bitmask_free(struct bitmap *bmp) 162{ 163 bitmap_free(bmp); 164} 165 166/** 167 * \brief checks if the n-th bit is set in the bitmask 168 * 169 * \param bmp the bitmap 170 * \param n which bit to check 171 * 172 * \returns TRUE if the n-th bit is set 173 * FALSE otherwise 174 */ 175bool numa_bitmask_isbitset(const struct bitmap *bmp, unsigned int n) 176{ 177 return bitmap_is_bit_set(bmp, n); 178} 179 180/** 181 * \brief returns the size (in bytes) of the bit mask 182 * 183 * \param bmp the bitmask 184 * 185 * \returns the size of the memory in bytes rounded up to a multiple of wordsize 186 */ 187size_t numa_bitmask_nbytes(struct bitmap *bmp) 188{ 189 return bitmap_get_nbytes(bmp); 190} 191 192/** 193 * \brief sets all bits of a bitmask to 1 194 * 195 * \param bmp the bitmask 196 * 197 * \returns the bitmask 198 */ 199struct bitmap *numa_bitmask_setall(struct bitmap *bmp) 200{ 201 bitmap_set_all(bmp); 202 return bmp; 203} 204 205/** 206 * \brief sets the n-th bit of a bitmask to 1 207 * 208 * \param bmp the bitmask 209 * \param n which bit to activate 210 * 211 * \returns the bitmask 212 */ 213struct bitmap *numa_bitmask_setbit(struct bitmap *bmp, unsigned int n) 214{ 215 bitmap_set_bit(bmp, n); 216 return bmp; 217} 218 219/** 220 * \brief copies the bitmask to a nodemask 221 * 222 * \param bmp the bitmask to copy 223 * \param nodemask the destination nodemask 224 * 225 * If the two areas differ in size, the copy is truncated to the size of the 226 * receiving field or zero-filled. 227 */ 228void copy_bitmask_to_nodemask(struct bitmap *bmp, nodemask_t *nodemask) 229{ 230 assert(!"NYI*"); 231} 232 233/** 234 * \brief copies the contents of a nodemask into the bitmask 235 * 236 * \param nodemask node mask to copy from 237 * \param bmp bitmap to copy into 238 * 239 * If the two areas differ in size, the copy is truncated to the size of the 240 * receiving field or zero-filled. 241 */ 242void copy_nodemask_to_bitmask(nodemask_t *nodemask, struct bitmap *bmp) 243{ 244 assert(!"NYI*"); 245} 246 247 248/** 249 * \brief copies one bitmask into another 250 * 251 * \param bmpfrom the source bitmask 252 * \param bmpto the destination bitmask 253 * 254 * If the two areas differ in size, the copy is truncated to the size of the 255 * receiving field or zero-filled. 256 */ 257void copy_bitmask_to_bitmask(struct bitmap *bmpfrom, struct bitmap *bmpto) 258{ 259 bitmap_copy(bmpto, bmpfrom); 260} 261 262/** 263 * \brief returns a count of the bits that are set in the body of the bitmask 264 * 265 * \param bmp the bitmask to count the set bits 266 * 267 * \return number of set bits in this bitmask 268 */ 269uint32_t numa_bitmask_weight(const struct bitmap *bmp) 270{ 271 return bitmap_get_weight(bmp); 272} 273 274