Changes in libcfa/src/device/cpu.cfa [33608cb:ab4a595]
- File:
-
- 1 edited
-
libcfa/src/device/cpu.cfa (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/device/cpu.cfa
r33608cb rab4a595 30 30 #include <fcntl.h> 31 31 } 32 33 #include "algorithms/range_iterator.hfa"34 32 35 33 // search a string for character 'character' but looking atmost at len … … 137 135 count++; 138 136 } 139 int ret = iterate_dir(path, lambda); 140 if(ret == ENOTDIR) return 0; 137 iterate_dir(path, lambda); 141 138 142 139 /* paranoid */ verifyf(count == max + 1, "Inconsistent %s count, counted %d, but max %s was %d", prefix, count, prefix, (int)max); … … 146 143 147 144 // Count number of cpus in the system 148 static [int, const char *]count_cpus(void) {145 static int count_cpus(void) { 149 146 const char * fpath = "/sys/devices/system/cpu/online"; 150 147 int fd = open(fpath, 0, O_RDONLY); … … 162 159 163 160 const char * _; 164 return [read_width(buff, r - 1, &_), strndup(buff, r - 1)]; 161 int cnt = read_width(buff, r - 1, &_); 162 /* paranoid */ verify(cnt == count_prefix_dirs("/sys/devices/system/cpu", "cpu")); 163 return cnt; 165 164 } 166 165 … … 227 226 228 227 struct raw_cache_instance { 229 idx_range_t range; // A text description of the cpus covered230 unsigned width; // The number of cpus covered231 unsigned char level; // the cache level228 idx_range_t range; 229 unsigned width; 230 unsigned char level; 232 231 // FIXME add at least size and type 233 232 }; … … 236 235 static void ^?{}(raw_cache_instance & this) { free(this.range);} 237 236 238 // Returns a 2D array of instances of size [cpu count][cache levels] 239 // where cache level doesn't include instruction caches 240 raw_cache_instance ** build_raw_cache_table(unsigned cpus_c, idx_range_t cpus, unsigned idxs, unsigned cache_levels) 237 raw_cache_instance ** build_raw_cache_table(unsigned cpus, unsigned idxs, unsigned cache_levels) 241 238 { 242 raw_cache_instance ** raw = alloc(cpus_c, '\0'`fill); 243 244 RangeIter rc = { cpus }; 245 while(moveNext(rc)) { 246 unsigned i = rc.com; 239 raw_cache_instance ** raw = alloc(cpus); 240 for(i; cpus) { 247 241 raw[i] = alloc(cache_levels); 248 242 void addcache(unsigned fidx, unsigned char level, idx_range_t range, size_t len) { … … 269 263 270 264 // returns an allocate list of all the different distinct last level caches 271 static [*llc_map_t, size_t cnt] distinct_llcs( idx_range_tcpus, unsigned llc_idx, raw_cache_instance ** raw) {265 static [*llc_map_t, size_t cnt] distinct_llcs(unsigned cpus, unsigned llc_idx, raw_cache_instance ** raw) { 272 266 // Allocate at least one element 273 267 llc_map_t* ranges = alloc(); 274 268 size_t range_cnt = 1; 275 269 276 RangeIter rc = { cpus };277 __attribute__((unused)) bool ret =278 moveNext(rc);279 /* paranoid */ verify( ret );280 /* paranoid */ verify( rc.com >= 0 );281 282 270 // Initialize with element 0 283 ranges->raw = &raw[ rc.com][llc_idx];271 ranges->raw = &raw[0][llc_idx]; 284 272 ranges->count = 0; 285 273 ranges->start = -1u; 286 274 287 275 // Go over all other cpus 288 CPU_LOOP: while(moveNext(rc)) { 289 unsigned i = rc.com; 276 CPU_LOOP: for(i; 1~cpus) { 290 277 // Check if the range is already there 291 278 raw_cache_instance * candidate = &raw[i][llc_idx]; … … 317 304 } 318 305 319 static [[]cpu_pairing_t] get_cpu_pairings(unsigned cpus_c, idx_range_t cpus, raw_cache_instance ** raw, llc_map_t * maps, size_t map_cnt) { 320 cpu_pairing_t * pairings = alloc(cpus_c); 321 322 RangeIter rc = { cpus }; 323 CPU_LOOP: while(moveNext(rc)) { 324 unsigned i = rc.com; 306 static [[]cpu_pairing_t] get_cpu_pairings(unsigned cpus, raw_cache_instance ** raw, llc_map_t * maps, size_t map_cnt) { 307 cpu_pairing_t * pairings = alloc(cpus); 308 309 CPU_LOOP: for(i; cpus) { 325 310 pairings[i].cpu = i; 326 311 idx_range_t want = raw[i][0].range; … … 342 327 extern "C" { 343 328 void __cfaabi_device_startup( void ) { 344 int cpus_c; 345 const char * cpus; 346 [cpus_c, cpus] = count_cpus(); 347 #if defined(__CFA_WITH_VERIFY__) 348 // Verify that the mapping is self consistant. 349 { 350 RangeIter rc = { cpus }; 351 while(moveNext(rc)) { 352 unsigned i = rc.com; 353 verify(cpus_c > i); 354 } 355 } 356 #endif 357 329 int cpus = count_cpus(); 358 330 int idxs = count_cache_indexes(); 359 331 … … 361 333 unsigned cache_levels = 0; 362 334 unsigned llc = 0; 363 if (idxs != 0){335 { 364 336 unsigned char prev = -1u; 365 337 void first(unsigned idx, unsigned char level, const char * map, size_t len) { … … 373 345 374 346 // Read in raw data 375 raw_cache_instance ** raw = build_raw_cache_table(cpus _c, cpus, idxs, cache_levels);347 raw_cache_instance ** raw = build_raw_cache_table(cpus, idxs, cache_levels); 376 348 377 349 // Find number of distinct cache instances … … 390 362 width2 += maps[i].raw->width; 391 363 } 392 verify(width1 == cpus _c);393 verify(width2 == cpus _c);364 verify(width1 == cpus); 365 verify(width2 == cpus); 394 366 } 395 367 #endif 396 368 397 369 // Get mappings from cpu to cache instance 398 cpu_pairing_t * pairings = get_cpu_pairings(cpus _c, cpus, raw, maps, map_cnt);370 cpu_pairing_t * pairings = get_cpu_pairings(cpus, raw, maps, map_cnt); 399 371 400 372 // Sort by cache instance 401 qsort(pairings, cpus _c);373 qsort(pairings, cpus); 402 374 403 375 { 404 376 unsigned it = 0; 405 RangeIter rc = { cpus }; 406 while(moveNext(rc)) { 407 unsigned i = rc.com; 377 for(i; cpus) { 408 378 unsigned llc_id = pairings[i].id; 409 379 if(maps[llc_id].start == -1u) { … … 414 384 } 415 385 } 416 /* paranoid */ verify(it == cpus _c);386 /* paranoid */ verify(it == cpus); 417 387 } 418 388 419 389 // From the mappings build the actual cpu map we want 420 struct cpu_map_entry_t * entries = alloc(cpus_c); 421 for(i; cpus_c) { entries[i].count = 0; } 422 423 RangeIter rc = { cpus }; 424 while(moveNext(rc)) { 425 unsigned i = rc.com; 390 struct cpu_map_entry_t * entries = alloc(cpus); 391 for(i; cpus) { entries[i].count = 0; } 392 for(i; cpus) { 426 393 /* paranoid */ verify(pairings[i].id < map_cnt); 427 394 unsigned c = pairings[i].cpu; … … 439 406 free(pairings); 440 407 441 for(i; cpus _c) {442 if( raw[i] )for(j; cache_levels) {408 for(i; cpus) { 409 for(j; cache_levels) { 443 410 ^(raw[i][j]){}; 444 411 } … … 448 415 449 416 cpu_info.llc_map = entries; 450 cpu_info.hthrd_count = cpus_c; 451 cpu_info.llc_count = map_cnt; 417 cpu_info.hthrd_count = cpus; 452 418 } 453 419
Note:
See TracChangeset
for help on using the changeset viewer.