process.cc (10913:38dbdeea7f1f) | process.cc (10929:b2bbfec74eca) |
---|---|
1/* 2 * Copyright (c) 2014 Advanced Micro Devices, Inc. 3 * Copyright (c) 2012 ARM Limited 4 * All rights reserved 5 * 6 * The license below extends only to copyright in the software and shall 7 * not be construed as granting a license to any other intellectual 8 * property including but not limited to intellectual property relating --- 101 unchanged lines hidden (view full) --- 110 next_thread_stack_base(0), 111 M5_pid(system->allocatePID()), 112 useArchPT(params->useArchPT), 113 kvmInSE(params->kvmInSE), 114 pTable(useArchPT ? 115 static_cast<PageTableBase *>(new ArchPageTable(name(), M5_pid, system)) : 116 static_cast<PageTableBase *>(new FuncPageTable(name(), M5_pid)) ), 117 initVirtMem(system->getSystemPort(), this, | 1/* 2 * Copyright (c) 2014 Advanced Micro Devices, Inc. 3 * Copyright (c) 2012 ARM Limited 4 * All rights reserved 5 * 6 * The license below extends only to copyright in the software and shall 7 * not be construed as granting a license to any other intellectual 8 * property including but not limited to intellectual property relating --- 101 unchanged lines hidden (view full) --- 110 next_thread_stack_base(0), 111 M5_pid(system->allocatePID()), 112 useArchPT(params->useArchPT), 113 kvmInSE(params->kvmInSE), 114 pTable(useArchPT ? 115 static_cast<PageTableBase *>(new ArchPageTable(name(), M5_pid, system)) : 116 static_cast<PageTableBase *>(new FuncPageTable(name(), M5_pid)) ), 117 initVirtMem(system->getSystemPort(), this, |
118 SETranslatingPortProxy::Always) | 118 SETranslatingPortProxy::Always), 119 fd_map(new FdMap[NUM_FDS]) |
119{ 120 string in = params->input; 121 string out = params->output; 122 string err = params->errout; 123 124 // initialize file descriptors to default: same as simulator 125 int stdin_fd, stdout_fd, stderr_fd; 126 --- 43 unchanged lines hidden (view full) --- 170 fdo->fd = stderr_fd; 171 fdo->filename = err; 172 fdo->flags = O_WRONLY; 173 fdo->mode = -1; 174 fdo->fileOffset = 0; 175 176 177 // mark remaining fds as free | 120{ 121 string in = params->input; 122 string out = params->output; 123 string err = params->errout; 124 125 // initialize file descriptors to default: same as simulator 126 int stdin_fd, stdout_fd, stderr_fd; 127 --- 43 unchanged lines hidden (view full) --- 171 fdo->fd = stderr_fd; 172 fdo->filename = err; 173 fdo->flags = O_WRONLY; 174 fdo->mode = -1; 175 fdo->fileOffset = 0; 176 177 178 // mark remaining fds as free |
178 for (int i = 3; i <= MAX_FD; ++i) { | 179 for (int i = 3; i < NUM_FDS; ++i) { |
179 fdo = &fd_map[i]; 180 fdo->fd = -1; 181 } 182 183 mmap_start = mmap_end = 0; 184 nxm_start = nxm_end = 0; 185 // other parameters will be initialized when the program is loaded 186} --- 8 unchanged lines hidden (view full) --- 195 .name(name() + ".num_syscalls") 196 .desc("Number of system calls") 197 ; 198} 199 200// 201// static helper functions 202// | 180 fdo = &fd_map[i]; 181 fdo->fd = -1; 182 } 183 184 mmap_start = mmap_end = 0; 185 nxm_start = nxm_end = 0; 186 // other parameters will be initialized when the program is loaded 187} --- 8 unchanged lines hidden (view full) --- 196 .name(name() + ".num_syscalls") 197 .desc("Number of system calls") 198 ; 199} 200 201// 202// static helper functions 203// |
204 |
|
203int 204Process::openInputFile(const string &filename) 205{ 206 int fd = open(filename.c_str(), O_RDONLY); 207 208 if (fd == -1) { 209 perror(NULL); 210 cerr << "unable to open \"" << filename << "\" for reading\n"; --- 16 unchanged lines hidden (view full) --- 227 } 228 229 return fd; 230} 231 232ThreadContext * 233Process::findFreeContext() 234{ | 205int 206Process::openInputFile(const string &filename) 207{ 208 int fd = open(filename.c_str(), O_RDONLY); 209 210 if (fd == -1) { 211 perror(NULL); 212 cerr << "unable to open \"" << filename << "\" for reading\n"; --- 16 unchanged lines hidden (view full) --- 229 } 230 231 return fd; 232} 233 234ThreadContext * 235Process::findFreeContext() 236{ |
235 int size = contextIds.size(); 236 ThreadContext *tc; 237 for (int i = 0; i < size; ++i) { 238 tc = system->getThreadContext(contextIds[i]); 239 if (tc->status() == ThreadContext::Halted) { 240 // inactive context, free to use | 237 for (int id : contextIds) { 238 ThreadContext *tc = system->getThreadContext(id); 239 if (tc->status() == ThreadContext::Halted) |
241 return tc; | 240 return tc; |
242 } | |
243 } 244 return NULL; 245} 246 247void 248Process::initState() 249{ 250 if (contextIds.empty()) --- 10 unchanged lines hidden (view full) --- 261 262DrainState 263Process::drain() 264{ 265 find_file_offsets(); 266 return DrainState::Drained; 267} 268 | 241 } 242 return NULL; 243} 244 245void 246Process::initState() 247{ 248 if (contextIds.empty()) --- 10 unchanged lines hidden (view full) --- 259 260DrainState 261Process::drain() 262{ 263 find_file_offsets(); 264 return DrainState::Drained; 265} 266 |
269// map simulator fd sim_fd to target fd tgt_fd 270void 271Process::dup_fd(int sim_fd, int tgt_fd) 272{ 273 if (tgt_fd < 0 || tgt_fd > MAX_FD) 274 panic("Process::dup_fd tried to dup past MAX_FD (%d)", tgt_fd); 275 276 Process::FdMap *fdo = &fd_map[tgt_fd]; 277 fdo->fd = sim_fd; 278} 279 280 281// generate new target fd for sim_fd | |
282int 283Process::alloc_fd(int sim_fd, const string& filename, int flags, int mode, 284 bool pipe) 285{ 286 // in case open() returns an error, don't allocate a new fd 287 if (sim_fd == -1) 288 return -1; 289 290 // find first free target fd | 267int 268Process::alloc_fd(int sim_fd, const string& filename, int flags, int mode, 269 bool pipe) 270{ 271 // in case open() returns an error, don't allocate a new fd 272 if (sim_fd == -1) 273 return -1; 274 275 // find first free target fd |
291 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) { | 276 for (int free_fd = 0; free_fd < NUM_FDS; ++free_fd) { |
292 Process::FdMap *fdo = &fd_map[free_fd]; 293 if (fdo->fd == -1 && fdo->driver == NULL) { 294 fdo->fd = sim_fd; 295 fdo->filename = filename; 296 fdo->mode = mode; 297 fdo->fileOffset = 0; 298 fdo->flags = flags; 299 fdo->isPipe = pipe; 300 fdo->readPipeSource = 0; 301 return free_fd; 302 } 303 } 304 305 panic("Process::alloc_fd: out of file descriptors!"); 306} 307 | 277 Process::FdMap *fdo = &fd_map[free_fd]; 278 if (fdo->fd == -1 && fdo->driver == NULL) { 279 fdo->fd = sim_fd; 280 fdo->filename = filename; 281 fdo->mode = mode; 282 fdo->fileOffset = 0; 283 fdo->flags = flags; 284 fdo->isPipe = pipe; 285 fdo->readPipeSource = 0; 286 return free_fd; 287 } 288 } 289 290 panic("Process::alloc_fd: out of file descriptors!"); 291} 292 |
308 309// free target fd (e.g., after close) | |
310void | 293void |
311Process::free_fd(int tgt_fd) | 294Process::free_fdmap_entry(int tgt_fd) |
312{ 313 Process::FdMap *fdo = &fd_map[tgt_fd]; | 295{ 296 Process::FdMap *fdo = &fd_map[tgt_fd]; |
314 if (fdo->fd == -1) 315 warn("Process::free_fd: request to free unused fd %d", tgt_fd); | 297 assert(fd_map[tgt_fd].fd > -1); |
316 317 fdo->fd = -1; 318 fdo->filename = "NULL"; 319 fdo->mode = 0; 320 fdo->fileOffset = 0; 321 fdo->flags = 0; 322 fdo->isPipe = false; 323 fdo->readPipeSource = 0; 324 fdo->driver = NULL; 325} 326 | 298 299 fdo->fd = -1; 300 fdo->filename = "NULL"; 301 fdo->mode = 0; 302 fdo->fileOffset = 0; 303 fdo->flags = 0; 304 fdo->isPipe = false; 305 fdo->readPipeSource = 0; 306 fdo->driver = NULL; 307} 308 |
327 328// look up simulator fd for given target fd | |
329int 330Process::sim_fd(int tgt_fd) 331{ | 309int 310Process::sim_fd(int tgt_fd) 311{ |
332 if (tgt_fd < 0 || tgt_fd > MAX_FD) 333 return -1; 334 335 return fd_map[tgt_fd].fd; | 312 FdMap *obj = sim_fd_obj(tgt_fd); 313 return obj ? obj->fd : -1; |
336} 337 338Process::FdMap * 339Process::sim_fd_obj(int tgt_fd) 340{ | 314} 315 316Process::FdMap * 317Process::sim_fd_obj(int tgt_fd) 318{ |
341 if (tgt_fd < 0 || tgt_fd > MAX_FD) | 319 if (tgt_fd < 0 || tgt_fd >= NUM_FDS) |
342 return NULL; | 320 return NULL; |
343 | |
344 return &fd_map[tgt_fd]; 345} 346 | 321 return &fd_map[tgt_fd]; 322} 323 |
324int 325Process::tgt_fd(int sim_fd) 326{ 327 for (int index = 0; index < NUM_FDS; ++index) 328 if (fd_map[index].fd == sim_fd) 329 return index; 330 return -1; 331} 332 |
|
347void 348Process::allocateMem(Addr vaddr, int64_t size, bool clobber) 349{ 350 int npages = divCeil(size, (int64_t)PageBytes); 351 Addr paddr = system->allocPhysPages(npages); 352 pTable->map(vaddr, paddr, size, clobber ? PageTableBase::Clobber : 0); 353} 354 --- 73 unchanged lines hidden (view full) --- 428 panic("Unable to seek to correct location in file: %s", err); 429 } 430 431 fdo_stdin->fd = stdin_fd; 432 fdo_stdout->fd = stdout_fd; 433 fdo_stderr->fd = stderr_fd; 434 435 | 333void 334Process::allocateMem(Addr vaddr, int64_t size, bool clobber) 335{ 336 int npages = divCeil(size, (int64_t)PageBytes); 337 Addr paddr = system->allocPhysPages(npages); 338 pTable->map(vaddr, paddr, size, clobber ? PageTableBase::Clobber : 0); 339} 340 --- 73 unchanged lines hidden (view full) --- 414 panic("Unable to seek to correct location in file: %s", err); 415 } 416 417 fdo_stdin->fd = stdin_fd; 418 fdo_stdout->fd = stdout_fd; 419 fdo_stderr->fd = stderr_fd; 420 421 |
436 for (int free_fd = 3; free_fd <= MAX_FD; ++free_fd) { | 422 for (int free_fd = 3; free_fd < NUM_FDS; ++free_fd) { |
437 Process::FdMap *fdo = &fd_map[free_fd]; 438 if (fdo->fd != -1) { 439 if (fdo->isPipe){ 440 if (fdo->filename == "PIPE-WRITE") 441 continue; 442 else { 443 assert (fdo->filename == "PIPE-READ"); 444 //create a new pipe --- 26 unchanged lines hidden (view full) --- 471 } 472 } 473 } 474} 475 476void 477Process::find_file_offsets() 478{ | 423 Process::FdMap *fdo = &fd_map[free_fd]; 424 if (fdo->fd != -1) { 425 if (fdo->isPipe){ 426 if (fdo->filename == "PIPE-WRITE") 427 continue; 428 else { 429 assert (fdo->filename == "PIPE-READ"); 430 //create a new pipe --- 26 unchanged lines hidden (view full) --- 457 } 458 } 459 } 460} 461 462void 463Process::find_file_offsets() 464{ |
479 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) { | 465 for (int free_fd = 0; free_fd < NUM_FDS; ++free_fd) { |
480 Process::FdMap *fdo = &fd_map[free_fd]; 481 if (fdo->fd != -1) { 482 fdo->fileOffset = lseek(fdo->fd, 0, SEEK_CUR); 483 } else { 484 fdo->filename = "NULL"; 485 fdo->fileOffset = 0; 486 } 487 } --- 36 unchanged lines hidden (view full) --- 524 SERIALIZE_SCALAR(stack_size); 525 SERIALIZE_SCALAR(stack_min); 526 SERIALIZE_SCALAR(next_thread_stack_base); 527 SERIALIZE_SCALAR(mmap_start); 528 SERIALIZE_SCALAR(mmap_end); 529 SERIALIZE_SCALAR(nxm_start); 530 SERIALIZE_SCALAR(nxm_end); 531 pTable->serialize(cp); | 466 Process::FdMap *fdo = &fd_map[free_fd]; 467 if (fdo->fd != -1) { 468 fdo->fileOffset = lseek(fdo->fd, 0, SEEK_CUR); 469 } else { 470 fdo->filename = "NULL"; 471 fdo->fileOffset = 0; 472 } 473 } --- 36 unchanged lines hidden (view full) --- 510 SERIALIZE_SCALAR(stack_size); 511 SERIALIZE_SCALAR(stack_min); 512 SERIALIZE_SCALAR(next_thread_stack_base); 513 SERIALIZE_SCALAR(mmap_start); 514 SERIALIZE_SCALAR(mmap_end); 515 SERIALIZE_SCALAR(nxm_start); 516 SERIALIZE_SCALAR(nxm_end); 517 pTable->serialize(cp); |
532 for (int x = 0; x <= MAX_FD; x++) { | 518 for (int x = 0; x < NUM_FDS; x++) { |
533 fd_map[x].serializeSection(cp, csprintf("FdMap%d", x)); 534 } 535 SERIALIZE_SCALAR(M5_pid); 536 537} 538 539void 540Process::unserialize(CheckpointIn &cp) 541{ 542 UNSERIALIZE_SCALAR(brk_point); 543 UNSERIALIZE_SCALAR(stack_base); 544 UNSERIALIZE_SCALAR(stack_size); 545 UNSERIALIZE_SCALAR(stack_min); 546 UNSERIALIZE_SCALAR(next_thread_stack_base); 547 UNSERIALIZE_SCALAR(mmap_start); 548 UNSERIALIZE_SCALAR(mmap_end); 549 UNSERIALIZE_SCALAR(nxm_start); 550 UNSERIALIZE_SCALAR(nxm_end); 551 pTable->unserialize(cp); | 519 fd_map[x].serializeSection(cp, csprintf("FdMap%d", x)); 520 } 521 SERIALIZE_SCALAR(M5_pid); 522 523} 524 525void 526Process::unserialize(CheckpointIn &cp) 527{ 528 UNSERIALIZE_SCALAR(brk_point); 529 UNSERIALIZE_SCALAR(stack_base); 530 UNSERIALIZE_SCALAR(stack_size); 531 UNSERIALIZE_SCALAR(stack_min); 532 UNSERIALIZE_SCALAR(next_thread_stack_base); 533 UNSERIALIZE_SCALAR(mmap_start); 534 UNSERIALIZE_SCALAR(mmap_end); 535 UNSERIALIZE_SCALAR(nxm_start); 536 UNSERIALIZE_SCALAR(nxm_end); 537 pTable->unserialize(cp); |
552 for (int x = 0; x <= MAX_FD; x++) { | 538 for (int x = 0; x < NUM_FDS; x++) { |
553 fd_map[x].unserializeSection(cp, csprintf("FdMap%d", x)); 554 } 555 fix_file_offsets(); 556 UNSERIALIZE_OPT_SCALAR(M5_pid); 557 // The above returns a bool so that you could do something if you don't 558 // find the param in the checkpoint if you wanted to, like set a default 559 // but in this case we'll just stick with the instantianted value if not | 539 fd_map[x].unserializeSection(cp, csprintf("FdMap%d", x)); 540 } 541 fix_file_offsets(); 542 UNSERIALIZE_OPT_SCALAR(M5_pid); 543 // The above returns a bool so that you could do something if you don't 544 // find the param in the checkpoint if you wanted to, like set a default 545 // but in this case we'll just stick with the instantianted value if not |
560 // found. | 546 // found. |
561} 562 563 564bool 565Process::map(Addr vaddr, Addr paddr, int size, bool cacheable) 566{ 567 pTable->map(vaddr, paddr, size, 568 cacheable ? 0 : PageTableBase::Uncacheable); --- 219 unchanged lines hidden --- | 547} 548 549 550bool 551Process::map(Addr vaddr, Addr paddr, int size, bool cacheable) 552{ 553 pTable->map(vaddr, paddr, size, 554 cacheable ? 0 : PageTableBase::Uncacheable); --- 219 unchanged lines hidden --- |