- while (1) {
- usleep(1000);
- gettimeofday(&cur_tv, NULL);
-
- n = 0;
- while (timercmp(&prev_tv, &cur_tv, <)) {
- if (n > 5) {
- /* give some time between subsequent
- * signals */
- usleep(100);
- n = 0;
- }
- pthread_mutex_lock(&mut);
- g_msg.type = SCHED;
- pthread_kill(thread, SIGUSR1);
-
- /* signal was acked */
- tv_millisec.tv_sec = 0;
- tv_millisec.tv_usec = 1000;
- timeradd(&prev_tv, &tv_millisec, &prev_tv);
- n ++;
- }
+/* enable loaded ittimers */
+int hostsim_ittimer_enable(unsigned timer_resolution_us)
+{
+ struct sigaction sigact;
+ struct itimerval t;
+
+ /* register a signal handler, which is interruptible */
+ memset(&sigact, 0, sizeof(sigact));
+ sigemptyset(&sigact.sa_mask);
+ sigact.sa_flags |= SA_NODEFER;
+ sigact.sa_sigaction = sigtimer;
+ sigaction(SIGALRM, &sigact, NULL);
+
+ /* do not interrupt syscalls */
+ if (siginterrupt (SIGALRM, 0) != 0)
+ return -1;
+
+ memset(&t, 0, sizeof(t));
+ t.it_value.tv_usec = timer_resolution_us;
+ t.it_value.tv_sec = 0;
+ t.it_interval.tv_usec = timer_resolution_us;
+ t.it_interval.tv_sec = 0;
+
+ if (setitimer(ITIMER_REAL, &t, NULL) < 0) {
+ printf("setitimer failed\n");
+ return -1;