int main(int argc, char **argv) { int result0 = -1; int result1 = -1; result0 = sched_getscheduler(0); result1 = sched_getscheduler(getpid()); if (result0 == result1 && errno == 0) { printf("Test PASSED\n"); return PTS_PASS; } else if (result0 != result1) { printf("Different results between pid == 0 " "and pid == getpid().\n"); return PTS_FAIL; } else { perror("Unexpected error"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; }
void testBadParams() { int id = fork(); int status; if (id>0) { struct sched_param param; int expected_requested_time = 7; int expected_level = 51; param.lshort_params.requested_time = expected_requested_time; param.lshort_params.level = expected_level; assert(sched_setscheduler(id, SCHED_LSHORT, ¶m) == -1); assert(errno = 22); assert(sched_getscheduler(id) == 0); expected_requested_time = 310000; expected_level = 7; param.lshort_params.requested_time = expected_requested_time; param.lshort_params.level = expected_level; assert(sched_setscheduler(id, SCHED_LSHORT, ¶m) == -1); assert(errno = 22); assert(sched_getscheduler(id) == 0); wait(&status); printf("OK\n"); } else if (id == 0) { doShortTask(); _exit(0); } }
int main(){ int old_priority, old_policy, new_policy; struct sched_param param; int invalid_policy; invalid_policy = 0; /* Linux does not treat minus value as invalid for policy */ while(invalid_policy == SCHED_OTHER || invalid_policy == SCHED_FIFO || invalid_policy == SCHED_RR || invalid_policy == SCHED_BATCH) invalid_policy++; if(sched_getparam(getpid(), ¶m) == -1) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } old_priority = param.sched_priority; old_policy = sched_getscheduler(getpid()); if(old_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } sched_setscheduler(0, invalid_policy, ¶m); if(errno == 0) { printf("No error occurs, could %i be a valid value for the scheduling policy ???\n", invalid_policy); return PTS_UNRESOLVED; } if(sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } new_policy = sched_getscheduler(getpid()); if(new_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } if(old_policy == new_policy && old_priority == param.sched_priority) { printf("Test PASSED\n"); return PTS_PASS; } if(param.sched_priority != old_priority) { printf("The param has changed\n"); } if(new_policy != old_policy) { printf("The policy has changed\n"); } return PTS_FAIL; }
int main(void) { int old_priority, old_policy, new_policy; struct sched_param param; int invalid_policy; char *label; pid_t pid = getpid(); int rc; invalid_policy = INT_MAX; label = "sched_getparam()"; rc = sched_getparam(pid, ¶m); if (rc) goto unresolved; old_priority = param.sched_priority; label = "sched_getscheduler()"; rc = sched_getscheduler(pid); if (rc < 0) goto unresolved; old_policy = rc; label = "sched_setscheduler() - invalid policy succeeded?"; rc = sched_setscheduler(0, invalid_policy, ¶m); if (!rc) goto unresolved; label = "sched_getparam()"; rc = sched_getparam(pid, ¶m); if (rc) goto unresolved; label = "sched_getscheduler()"; rc = sched_getscheduler(pid); if (rc < 0) goto unresolved; new_policy = rc; if (old_policy != new_policy) { printf("Failed: invalid policy change, old: %u, new %u\n", old_policy, new_policy); exit(PTS_FAIL); } if (old_priority != param.sched_priority) { printf("Failed: invalid priority change, old: %u, new %u\n", old_priority, param.sched_priority); exit(PTS_FAIL); } printf("Test PASSED\n"); return PTS_PASS; unresolved: ERR_MSG(label, rc); return PTS_UNRESOLVED; }
int main(){ int policy, result; int old_priority, old_policy, new_policy; struct sched_param param; if(sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } old_priority = param.sched_priority; old_policy = sched_getscheduler(getpid()); if(old_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } /* set a sched_ss_repl_period lower than the sched_ss_init_budget */ param.sched_ss_repl_period.tv_sec = 1; param.sched_ss_repl_period.tv_nsec = 0; param.sched_ss_init_budget.tv_sec = 2; param.sched_ss_init_budget.tv_nsec = 0; param.sched_priority = sched_get_priority_max(SCHED_SPORADIC); result = sched_setscheduler(0, SCHED_SPORADIC, ¶m); if(sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } new_policy = sched_getscheduler(getpid()); if(new_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } if(old_policy == new_policy && old_priority == param.sched_priority) { printf("Test PASSED\n"); return PTS_PASS; } if(param.sched_priority != old_priority) { printf("The param has changed\n"); } if(new_policy != old_policy) { printf("The policy has changed\n"); } return PTS_FAIL; }
int main(void) { int invalid_priority; int old_priority, old_policy, new_policy; struct sched_param param; if (sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } old_priority = param.sched_priority; old_policy = sched_getscheduler(getpid()); if (old_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } invalid_priority = sched_get_priority_max(SCHED_SPORADIC); if (invalid_priority == -1) { perror("An error occurs when calling sched_get_priority_max()"); return PTS_UNRESOLVED; } /* set an invalid priority */ invalid_priority++; param.sched_ss_low_priority = invalid_priority; sched_setscheduler(0, SCHED_SPORADIC, ¶m); if (sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } new_policy = sched_getscheduler(getpid()); if (new_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } if (old_policy == new_policy && old_priority == param.sched_priority) { printf("Test PASSED\n"); return PTS_PASS; } if (param.sched_priority != old_priority) { printf("The param has changed\n"); } if (new_policy != old_policy) { printf("The policy has changed\n"); } return PTS_FAIL; }
int main() { int max_priority, old_priority, old_policy, new_policy; struct sched_param param; if (sched_getparam(getpid(), ¶m) == -1) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } old_priority = param.sched_priority; old_policy = sched_getscheduler(getpid()); if (old_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } /* Make sure that param.sched_priority != old_priority */ max_priority = sched_get_priority_max(SCHED_SPORADIC); param.sched_priority = (old_priority == max_priority) ? sched_get_priority_min(SCHED_SPORADIC) : max_priority; param.sched_ss_max_repl = 0; sched_setscheduler(0, SCHED_SPORADIC, ¶m); if (sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } new_policy = sched_getscheduler(getpid()); if (new_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } if (old_policy == new_policy && old_priority == param.sched_priority) { printf("Test PASSED\n"); return PTS_PASS; } if (param.sched_priority != old_priority) { printf("The param has changed\n"); return PTS_FAIL; } if (new_policy != old_policy) { printf("The policy has changed\n"); return PTS_FAIL; } }
int main() { sched_getscheduler(0); //staptest// sched_getscheduler (0) = 0 sched_getscheduler((pid_t)-1); //staptest// sched_getscheduler (-1) = -NNNN (EINVAL) sched_getscheduler(999999); //staptest// sched_getscheduler (999999) = -NNNN (ESRCH) return 0; }
int main() { int rc; rc = sched_getscheduler(0); printf("Init sched: %d\n", rc); rc = sched_setscheduler(0, SCHED_POLICY_MYCFS, &MYPARAM); printf("Rc from set: %d\n", rc); if(rc == -1) printf("Errno %d: %s\n", errno, strerror(errno)); fib(20); rc = sched_getscheduler(0); printf("Now sched: %d\n", rc); return 0; }
int posix_spawnattr_init(posix_spawnattr_t *attr) { struct sched_param param; int ret; DEBUGASSERT(attr); /* Flags: None */ attr->flags = 0; /* Set the default priority to the same priority as this task */ ret = sched_getparam(0, ¶m); if (ret < 0) { return errno; } attr->priority = param.sched_priority; /* Set the default scheduler policy to the policy of this task */ attr->policy = sched_getscheduler(0); /* Empty signal masek */ attr->sigmask = 0; /* Default stack size */ attr->stacksize = TASK_SPAWN_DEFAULT_STACKSIZE; return OK; }
int get_sched_policy(int tid, SchedPolicy *policy) { if (tid == 0) { tid = gettid(); } pthread_once(&the_once, __initialize); if (__sys_supports_schedgroups) { char grpBuf[32]; if (getSchedulerGroup(tid, grpBuf, sizeof(grpBuf)) < 0) return -1; if (grpBuf[0] == '\0') { *policy = SP_FOREGROUND; } else if (!strcmp(grpBuf, "bg_non_interactive")) { *policy = SP_BACKGROUND; } else { errno = ERANGE; return -1; } } else { int rc = sched_getscheduler(tid); if (rc < 0) return -1; else if (rc == SCHED_NORMAL) *policy = SP_FOREGROUND; else if (rc == SCHED_BATCH) *policy = SP_BACKGROUND; else { errno = ERANGE; return -1; } } return 0; }
// ------------------------------------------------------------------------------------------------- static void* ThreadMainFunction ( void* expectedPolicy ///< The expected Linux scheduling policy (SCHED_IDLE or SCHED_OTHER). ) // ------------------------------------------------------------------------------------------------- { LE_INFO("Checking scheduling policy..."); int schedPolicy = sched_getscheduler(0); if (schedPolicy == -1) { LE_FATAL("Failed to fetch scheduling policy (error %d).", errno); } if (expectedPolicy != (void*)(size_t)schedPolicy) { LE_FATAL("Expected policy %p. Got %p.", expectedPolicy, (void*)(size_t)schedPolicy); } else { LE_INFO("Policy correct."); } return NULL; }
void adjust_priority() { int sched = sched_getscheduler(0); if(sched == SCHED_FIFO || sched == SCHED_RR) { printf(">> since the scheduling policy is not standard, I assume\n"); printf(" it has been adjusted to fit the needs of realtime audio\n"); } else { struct sched_param sp; long priority = (sched_get_priority_max(SCHED_FIFO) + sched_get_priority_min(SCHED_FIFO))/2; sp.sched_priority = priority; if(sched_setscheduler(0, SCHED_FIFO, &sp) != -1) { printf(">> running as realtime process now (priority %ld)\n", priority); putenv("STARTED_THROUGH_ARTSWRAPPER=1"); } else { /* can't set realtime priority */ putenv("STARTED_THROUGH_ARTSWRAPPER=2"); } } }
void other(){ original_calloc = (calloc_type)dlsym(RTLD_NEXT, "calloc"); if(!original_calloc){ fprintf(stderr, "original calloc can not be resolved\n"); exit(-1); } original_malloc = (malloc_type)dlsym(RTLD_NEXT, "malloc"); if(!original_malloc){ fprintf(stderr, "original malloc can not be resolved\n"); exit(-1); } original_free = (free_type)dlsym(RTLD_NEXT, "free"); if(!original_free){ fprintf(stderr, "original free can not be resolved\n"); exit(-1); } original_realloc = (realloc_type)dlsym(RTLD_NEXT, "realloc"); if(!original_realloc){ fprintf(stderr, "original realloc can not be resolved\n"); exit(-1); } fprintf(stderr, "other %p, malloc %p, calloc %p, realloc %p, free %p\n", other, malloc, calloc, realloc, free); fprintf(stderr, "other %p, Retrieved malloc %p, calloc %p, realloc %p, \ free %p\n", other, original_malloc, original_calloc, original_realloc, original_free); fprintf(stderr, "SCHED_OTHER: %d\n", sched_getscheduler(getpid()) == SCHED_OTHER? 1 : 0); fprintf(stderr, "Min %d, Max %d\n", sched_get_priority_min(SCHED_OTHER), sched_get_priority_max(SCHED_OTHER)); }
int lx_sched_getparam(uintptr_t pid, uintptr_t param) { int policy, ret; pid_t s_pid; lwpid_t s_tid; struct sched_param sp; if (((pid_t)pid < 0) || (param == NULL)) return (-EINVAL); if (lx_lpid_to_spair((pid_t)pid, &s_pid, &s_tid) < 0) return (-ESRCH); /* * If we're attempting to get information on our own process, we can * get data on a per-thread basis; if not, punt and use the specified * pid. */ if (s_pid == getpid()) { if ((ret = pthread_getschedparam(s_tid, &policy, &sp)) != 0) return (-ret); } else { if (sched_getparam(s_pid, &sp) == -1) return (-errno); if ((policy = sched_getscheduler(s_pid)) < 0) return (-errno); } return (stol_sparam(policy, &sp, (struct lx_sched_param *)param)); }
int main (void) { struct sched_param shdprm; printf ("SCHED_FIFO : from %d to %d\n", sched_get_priority_min (SCHED_FIFO), sched_get_priority_max (SCHED_FIFO)); printf ("SCHED_RR : from %d to %d\n", sched_get_priority_min (SCHED_RR), sched_get_priority_max (SCHED_RR)); printf ("SCHED_OTHER: from %d to %d\n", sched_get_priority_min (SCHED_OTHER), sched_get_priority_max (SCHED_OTHER)); printf ("Current policy for this proccess: "); switch (sched_getscheduler (0)) { case SCHED_FIFO: printf ("SCHED__FIFO\n"); break; case SCHED_RR: printf ("SCHED_RR\n"); break; case SCHED_OTHER: printf ("SCHED_OTHER\n"); break; case -1: perror ("SCHED_GETSCHEDULER"); break; default: printf ("Unknown policy\n"); } if (sched_getparam (0, &shdprm) == 0) { printf ("Current priority for this proccess: %d\n", shdprm.sched_priority); } else { perror ("SCHED_GETPARAM"); } return 0; }
int main(int argc, char *argv[]) { int j, pol; struct sched_param sp; for (j = 1; j < argc; j++) { pol = sched_getscheduler(getLong(argv[j], 0, "pid")); if (pol == -1) errExit("sched_getscheduler"); if (sched_getparam(getLong(argv[j], 0, "pid"), &sp) == -1) errExit("sched_getparam"); printf("%s: %-5s ", argv[j], (pol == SCHED_OTHER) ? "OTHER" : (pol == SCHED_RR) ? "RR" : (pol == SCHED_FIFO) ? "FIFO" : #ifdef SCHED_BATCH /* Linux-specific */ (pol == SCHED_BATCH) ? "BATCH" : #endif #ifdef SCHED_IDLE /* Linux-specific */ (pol == SCHED_IDLE) ? "IDLE" : #endif "???"); printf("%2d\n", sp.sched_priority); } exit(EXIT_SUCCESS); }
void print_prio(pid_t pid) { int sched; struct sched_param sp; printf("pid %d's priority: %d\n", pid, getpriority(PRIO_PROCESS, pid)); printf("scheduling class: "); sched = sched_getscheduler(pid); switch (sched) { case SCHED_FIFO: printf("FIFO\n"); break; case SCHED_RR: printf("RR\n"); break; case SCHED_OTHER: printf("Normal\n"); break; case -1: perror("sched_getscheduler"); break; default: printf("Unknown\n"); } sched_getparam(pid, &sp); printf("RT prio: %d (of %d to %d)\n", sp.sched_priority, sched_get_priority_min(sched), sched_get_priority_max(sched)); }
int main (void) { if (sched_getscheduler (getpid ()) != SCHED_OTHER) abort (); printf ("pass\n"); exit (0); }
int getschedpolicy(int pid){ int ret =0; if((ret= sched_getscheduler(pid)) < 0){ printf("Error when getting sched policy. Err: %d:%s\n",errno,strerror(errno)); return -1; } switch(ret){ case 0: printf("Sched Type:Normal. Not running on any Priority \n"); break; case 1: printf("Sched Type:FIFO\n"); break; case 2: printf("Sched Type:Round Robin Tim sharing Policy\n"); break; case 3: printf("Sched Type:Batch. Not running on any Priority. \n"); break; default: //Not supposed to come printf("Sched Type:Unknown\n"); break; } return ret; }
int main(){ int result, old_policy, new_policy; struct sched_param param; old_policy = sched_getscheduler(getpid()); if(old_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } /* Make sure new_policy != old_policy */ new_policy = (old_policy == SCHED_FIFO) ? SCHED_RR : SCHED_FIFO; param.sched_priority = sched_get_priority_max(new_policy); result = sched_setscheduler(0, new_policy, ¶m); if(result == old_policy){ printf("Test PASSED\n"); return PTS_PASS; } else if(result == -1 && errno == EPERM) { printf("The process have not permission to change its own policy.\nTry to launch this test as root.\n"); return geteuid() != 0 ? PTS_PASS : PTS_UNRESOLVED; } printf("Returned code == %i.\n", result); perror("Unknow error"); return PTS_FAIL; }
long lx_sched_setparam(uintptr_t pid, uintptr_t param) { int err, policy; pid_t s_pid; lwpid_t s_tid; struct lx_sched_param lp; struct sched_param sp; if (((pid_t)pid < 0) || (param == NULL)) return (-EINVAL); if (lx_lpid_to_spair((pid_t)pid, &s_pid, &s_tid) < 0) return (-ESRCH); if (s_pid == getpid()) { struct sched_param dummy; if ((err = pthread_getschedparam(s_tid, &policy, &dummy)) != 0) return (-err); } else if ((policy = sched_getscheduler(s_pid)) < 0) return (-errno); lx_debug("sched_setparam(): current policy %d", policy); if (uucopy((void *)param, &lp, sizeof (lp)) != 0) return (-errno); /* * In Linux, the only valid SCHED_OTHER scheduler priority is 0 */ if ((policy == SCHED_OTHER) && (lp.lx_sched_prio != 0)) return (-EINVAL); if ((err = ltos_sparam(policy, (struct lx_sched_param *)&lp, &sp)) != 0) return (err); /* * Check if we're allowed to change the scheduler for the process. * * If we're operating on a thread, we can't just call * pthread_setschedparam() because as all threads reside within a * single Solaris process, Solaris will allow the modification * * If we're operating on a process, we can't just call sched_setparam() * because Solaris will allow the call to succeed if the scheduler * parameters do not differ from those being installed, but Linux wants * the call to fail. */ if ((err = check_schedperms(s_pid)) != 0) return (err); if (s_pid == getpid()) return (((err = pthread_setschedparam(s_tid, policy, &sp)) != 0) ? -err : 0); return ((sched_setparam(s_pid, &sp) == -1) ? -errno : 0); }
void run_iter(int param) { int policy, rv, max_prio; struct sched_param s_param; (void) param; policy = sched_getscheduler(0); if (policy != EXPECT_POLICY) { fprintf(stderr, "Incorrect scheduler in use.\n"); exit(EXIT_FAILURE); } max_prio = sched_get_priority_max(EXPECT_POLICY); rv = sched_getparam(0, &s_param); if (rv != 0) { perror("sched_getparam"); exit(EXIT_FAILURE); } if (s_param.sched_priority != max_prio) { fprintf(stderr, "Wrong scheduler priority: expect %d, got %d.\n", max_prio, s_param.sched_priority); exit(EXIT_FAILURE); } }
/** \brief Get the process effective scheduling class * * Possible Results: * - process scheduling class is OS_SCHED_REALTIME * - process scheduling class is OS_SCHED_TIMESHARE * - process scheduling class is OS_SCHED_DEFAULT if * the class effective could not be determined */ os_schedClass os_procAttrGetClass(void) { os_schedClass class; int policy; policy = sched_getscheduler(getpid()); switch (policy) { case SCHED_FIFO: case SCHED_RR: class = OS_SCHED_REALTIME; break; case SCHED_OTHER: class = OS_SCHED_TIMESHARE; break; case -1: OS_REPORT_1(OS_WARNING, "os_procAttrGetClass", 1, "sched_getscheduler failed with error %d", errno); class = OS_SCHED_DEFAULT; break; default: OS_REPORT_1(OS_WARNING, "os_procAttrGetClass", 1, "sched_getscheduler unexpected return value %d", policy); class = OS_SCHED_DEFAULT; break; } return class; }
int pthread_getschedparam(pthread_t thread, FAR int *policy, FAR struct sched_param *param) { int ret; sdbg("Thread ID=%d policy=0x%p param=0x%p\n", thread, policy, param); if (!policy || !param) { ret = EINVAL; } else { /* Get the schedparams of the thread. */ ret = sched_getparam((pid_t)thread, param); if (ret != OK) { ret = EINVAL; } /* Return the policy. */ *policy = sched_getscheduler((pid_t)thread); if (*policy == ERROR) { ret = get_errno(); } } sdbg("Returning %d\n", ret); return ret; }
int UC_posix_class::uc_sched_setparam(pid_t pid, const struct uc_sched_param *param) { UC_process_class *process; UC_task_class *task; int policy; if (param == NULL) { return EINVAL; } if (pid == 0) { process = qt_parent_process; } else { process = qt_parent_rtos->get_process(pid); } if (process == NULL) { errno = ESRCH; return -1; } policy = sched_getscheduler(pid); if (param->sched_priority > sched_get_priority_max(policy) || param->sched_priority < sched_get_priority_min(policy)) { errno = EINVAL; return -1; } task = process->m_task_list[0]; if(task == NULL){ errno= EPERM; return -1; } task->m_schedparam = *param; return 0; }
static void gki_set_timer_scheduling( void ) { pid_t main_pid = getpid(); struct sched_param param; int policy; policy = sched_getscheduler(main_pid); if ( policy != -1 ) { GKI_TRACE("gki_set_timer_scheduling(()::scheduler current policy: %d", policy); /* ensure highest priority in the system + 2 to allow space for read threads */ param.sched_priority = GKI_LINUX_TIMER_TICK_PRIORITY; if ( 0!=sched_setscheduler(main_pid, GKI_LINUX_TIMER_POLICY, ¶m ) ) { GKI_TRACE("sched_setscheduler() failed with error: %d", errno); } } else { GKI_TRACE( "getscheduler failed: %d", errno); } }
void testBecomingOverdue() { int id = fork(); int status; if (id > 0) { struct sched_param param; int expected_requested_time = 2; int expected_level = 8; param.lshort_params.requested_time = expected_requested_time; param.lshort_params.level = expected_level; sched_setscheduler(id, SCHED_LSHORT, ¶m); assert(sched_getscheduler(id) == SCHED_LSHORT); assert(sched_getparam(id, ¶m) == 0); //assert(param.lshort_params.requested_time == expected_requested_time); assert(param.lshort_params.level == expected_level); wait(&status); printf("OK\n"); } else if (id == 0) { int myId = getpid(); int i = lshort_query_overdue_time(myId); for (i; i < 2; ) { i = lshort_query_overdue_time(myId); doShortTask(); } _exit(0); } }
int main(void) { int result = -1; /* We assume process Number 1 is created by root */ /* and can only be accessed by root */ /* This test should be run under standard user permissions */ if (getuid() == 0) { if (set_nonroot() != 0) { printf("Cannot run this test as non-root user\n"); return PTS_UNTESTED; } } result = sched_getscheduler(1); if (result == -1 && errno == EPERM) { printf("Test PASSED\n"); return PTS_PASS; } if (result == 0) { printf("The function sched_getscheduler has successed.\n"); return PTS_UNTESTED; } if (errno != EPERM) { perror("errno is not EPERM"); return PTS_FAIL; } else { perror("Unresolved test error"); return PTS_UNRESOLVED; } }
void notify_function(union sigval sv) { int ok; struct timespec ts; //write(1, ".", 1); if (count == 0) { printf("notify_function: getpid()=%d, gettid()=%d\n", getpid(), gettid()); ok = sched_getscheduler(gettid()); printf("scheduler = %d\n", ok); } if (count < MAX_COUNT) { ok = clock_gettime(CLOCK_MONOTONIC, &ts); if (0 == ok) { unsigned delta_sec = ts.tv_sec - previous.tv_sec; int delta_ns = ts.tv_nsec - previous.tv_nsec; if (delta_ns < 0) { delta_ns += 1000000000; --delta_sec; } struct timespec delta_x; delta_x.tv_sec = delta_sec; delta_x.tv_nsec = delta_ns; delta_ts[count++] = delta_x; previous = ts; ATRACE_INT("cycle_us", delta_ns / 1000); } } }