#include #include #include #include #include #include #include #include #define BOOST_FILESYSTEM_VERSION 3 #define BOOST_ASIO_DISABLE_EPOLL//linux sucks with poll not implemented on filesystems #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "apps/common.h" #include "common/log.h" #include "common/sched.h" #include "vision/types.h" namespace bfs = boost::filesystem; namespace asio = boost::asio; namespace bpt = boost::posix_time; namespace bch = boost::chrono; namespace po = boost::program_options; int sigpipes[2]; void sighandler(int signum, siginfo_t *info, void *p){ printf("signal: %s\n", strsignal(signum)); write(sigpipes[1], &signum, sizeof(signum)); } enum cmd_t{ REQ_EXIT }; const mode_t filemode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; int open(const char* path, int flags, mode_t mode, boost::system::error_code& ec) { errno = 0; int result = boost::asio::detail::descriptor_ops::error_wrapper(::open(path, flags, mode), ec); if (result >= 0) ec = boost::system::error_code(); return result; } struct frame_header_t{ uint32_t width; uint32_t height; uint32_t framenumber; uint8_t channels; uint8_t bpp; uint32_t bytes; } __attribute__((packed)); int main(int argc, char *argv[]){ int verbosity; bool async_logging; std::string fname; int method; po::options_description clspec("Options"); clspec.add_options() ("help,h", "see available options") ("file", po::value(&fname), "destination file") ("verbosity,v", po::value(&verbosity)->default_value((int)logging::info), boost::str(boost::format("log level: %d - %d (everything)")%(int)logging::emergency%(int)logging::debug).c_str()) ("async-logging", po::value(&async_logging)->default_value(true)->implicit_value(true), "asynchronous logging") ("method,m", po::value(&method)->default_value(0), "method, 0 for split, 1 for vectorized") ; po::variables_map vmap; po::store(po::parse_command_line(argc, argv, clspec), vmap); if(vmap.count("help")){ std::cout< > streams; dioattr dioinfo; for(int i = 0; i < nstreams; ++i){ std::string fname_l = boost::str(boost::format("%s_%d")%fname%i); boost::shared_ptr f = boost::make_shared(ioservice, open(fname_l.c_str(), O_CREAT|O_TRUNC|O_WRONLY, filemode, ec)); //d_mem, d_miniosz, d_maxiosz if(xfsctl(fname_l.c_str(), f->native_handle(), XFS_IOC_DIOINFO, &dioinfo) < 0){ lerror()<<"error getting DIOINFO: "<native_handle(), XFS_IOC_FSGETXATTR, &fattr) < 0){ lerror()<<"error getting file attrs: "<native_handle(), XFS_IOC_FSSETXATTR, &fattr) < 0){ lerror()<<"error setting file attrs: "< dioinfo.d_maxiosz){ lerror()<<"larger than d_maxiosz"; } uint8_t *frame_data_mem = aligned_malloc(total_bytes, alignment); linfo()<<"aligned malloc frame ptr: "< frame(frame_data_mem + sizeof(frame_header_t), height, width); for(int r = 0; r < frame.height; ++r){ for(int c = 0; c < frame.width; ++c){ frame(r,c) = r + c; } } linfo()<<"Beginning benchmark"; int timer_fd = timerfd_create(CLOCK_MONOTONIC, 0); { const timespec timeout = { 0, 1 }; const timespec period = {0 , long(50L * 1e6)};//50ms period itimerspec tspec = {period, timeout}; timerfd_settime(timer_fd, 0, &tspec, NULL); } bch::steady_clock::time_point bstart = bch::steady_clock::now(); std::vector dts; int breaks = 0; int missed_deadlines_total = 0; bool doexit = false; for(unsigned i = 0; ;++i){ for(;;) { pollfd poll_fd[2] = {}; poll_fd[0].fd = sigpipes[0]; poll_fd[0].events = POLLIN; poll_fd[1].fd = timer_fd; poll_fd[1].events = POLLIN; sigset_t signal_set; sigemptyset(&signal_set); //sigaddset(&signal_set, SIGINT); //sigaddset(&signal_set, SIGQUIT); int status = ppoll(&poll_fd[0], 2, NULL, &signal_set); if(status > 0){ if(poll_fd[0].revents & POLLIN){ int sig; int ret = read(sigpipes[0], &sig, sizeof(sig)); //linfo()<<"signal sigpipe path"; if(ret == sizeof(sig)){ if(sig == SIGINT || sig == SIGQUIT || sig == SIGTERM){ doexit = true; break; } }else{ linfo()<<"sigpipe received signal ("< 0){ if(expirations > 1){ lwarning()<native_handle(), 0, lseek(f->native_handle(), 0, SEEK_CUR), POSIX_FADV_DONTNEED); if(ec){ ldebug()<close(ec); if(ec){ lerror()<(end - start).count(); dts.push_back(dt); } bch::steady_clock::time_point bend = bch::steady_clock::now(); int64_t min = std::numeric_limits::max(); int64_t max = std::numeric_limits::min(); double avg = 0, var = 0; for(auto it = dts.begin(); it != dts.end(); ++it){ min = std::min(min, *it); max = std::max(max, *it); avg += *it; } avg /= dts.size(); for(auto it = dts.begin(); it != dts.end(); ++it){ var += (*it - avg) * (*it - avg); } var /= dts.size(); int64_t tt = bch::duration_cast(bend - bstart).count(); linfo()<