/* RealTimeInterrupt.c This program is a work-arround of the "time slice problem" for Linux system, which may improve performance of an MPI application using several processes on a single CPU system. This program requires that Real Time Clock be enabled in the Linux kernel (see linux/Documentation/rtc.txt). Usage: Compile this program and start it in background (at a higher priority) before running MPI applications. */ #include #include #include #include #include #include #include #include #include /* The frequency must be within the range 2-8192 in increments of power of 2. Only root can use frequencies >= 128 */ #define frequency 64L static void sig_term(int signum); static int fd=-1; void main(void) { int retval; unsigned long data; #ifdef DEBUG fprintf(stderr,"Real Time Clock frequency is set to %ld Hz\n", frequency); #endif fd = open ("/dev/rtc", O_RDONLY); if (fd == -1) { perror("/dev/rtc"); exit(errno); } signal(SIGHUP, SIG_IGN); signal(SIGTERM, sig_term); signal(SIGABRT, sig_term); signal(SIGINT, sig_term); retval = ioctl(fd, RTC_IRQP_SET, frequency); if (retval == -1) { perror("ioctl"); exit(errno); } /* Enable periodic interrupts */ retval = ioctl(fd, RTC_PIE_ON, 0); if (retval == -1) { perror("ioctl"); exit(errno); } while ( 1 ) { /* This blocks */ retval = read(fd, &data, sizeof(unsigned long)); if (retval == -1) { perror("read"); exit(errno); } #ifdef DEBUG fprintf(stderr, "+"); fflush(stderr); #endif } /* Disable periodic interrupts */ retval = ioctl(fd, RTC_PIE_OFF, 0); if (retval == -1) { perror("ioctl"); exit(errno); } close(fd); } /* end main */ static void sig_term(int signum) { if ( fd != -1 ) { ioctl(fd, RTC_PIE_OFF, 0); close(fd); } #ifdef DEBUG fprintf(stderr, "Signal %d received, exit!\n", signum); #endif exit(0); }