} else if (res==0) {
return -1;
} else if (errno != EINTR) {
+ perror("pread_whole");
return -1;
}
}
close(fd);
}
+static
+int open_process_file(pid_t pid, const char* file, int flags)
+{
+ char buff[50];
+ snprintf(buff, sizeof(buff), "/proc/%li/%s", (long) pid, file);
+ return open(buff, flags);
+}
+
}
namespace simgrid {
process->heap = NULL;
process->heap_info = NULL;
process->init_memory_map_info();
+ process->clear_refs_fd_ = -1;
+ process->pagemap_fd_ = -1;
// Open the memory file
if (process->is_self())
free(process->heap_info);
process->heap_info = NULL;
+
+ if (process->clear_refs_fd_ >= 0)
+ close(process->clear_refs_fd_);
+ if (process->pagemap_fd_ >= 0)
+ close(process->pagemap_fd_);
}
/** Refresh the information about the process
ignored_regions_.begin() + position, region);
}
+void Process::reset_soft_dirty()
+{
+ if (this->clear_refs_fd_ < 0) {
+ this->clear_refs_fd_ = open_process_file(pid_, "clear_refs", O_WRONLY|O_CLOEXEC);
+ if (this->clear_refs_fd_ < 0)
+ xbt_die("Could not open clear_refs file for soft-dirty tracking. Run as root?");
+ }
+ if(::write(this->clear_refs_fd_, "4\n", 2) != 2)
+ xbt_die("Could not reset softdirty bits");
+}
+
+void Process::read_pagemap(uint64_t* pagemap, size_t page_start, size_t page_count)
+{
+ if (pagemap_fd_ < 0) {
+ pagemap_fd_ = open_process_file(pid_, "pagemap", O_RDONLY|O_CLOEXEC);
+ if (pagemap_fd_ < 0)
+ xbt_die("Could not open pagemap file for soft-dirty tracking. Run as root?");
+ }
+ ssize_t bytesize = sizeof(uint64_t) * page_count;
+ off_t offset = sizeof(uint64_t) * page_start;
+ if (pread_whole(pagemap_fd_, pagemap, bytesize, offset) != bytesize)
+ xbt_die("Could not read pagemap");
+}
+
}
}