int main() { int old_priority; struct sched_param param; if (sched_getparam(0, ¶m) == -1) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } old_priority = param.sched_priority; param.sched_ss_max_repl = 0; param.sched_priority++; sched_setparam(0,¶m); if (sched_getparam(0, ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } if (param.sched_priority == old_priority) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("The priority have changed.\n"); return PTS_FAIL; } }
int main() { int old_priority; struct sched_param param; if (sched_getparam(0, ¶m) == -1) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } old_priority = param.sched_priority; /* 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_setparam(0, ¶m); if (sched_getparam(0, ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } if (param.sched_priority == old_priority) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("The priority have 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 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(){ 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; } }
/*------------------------------------------------------------------------------ * Set POSIX real-time scheduling *----------------------------------------------------------------------------*/ void DarkIce :: setRealTimeScheduling ( void ) throw ( Exception ) { // Only if the OS has the POSIX real-time scheduling functions implemented. #if defined( HAVE_SCHED_GETSCHEDULER ) && defined( HAVE_SCHED_GETPARAM ) int high_priority; struct sched_param param; /* store the old scheduling parameters */ if ( (origSchedPolicy = sched_getscheduler(0)) == -1 ) { throw Exception( __FILE__, __LINE__, "sched_getscheduler", errno); } if ( sched_getparam( 0, ¶m) == -1 ) { throw Exception( __FILE__, __LINE__, "sched_getparam", errno); } origSchedPriority = param.sched_priority; /* set SCHED_FIFO with max - 1 priority or user configured value */ if ( (high_priority = sched_get_priority_max(SCHED_FIFO)) == -1 ) { throw Exception(__FILE__,__LINE__,"sched_get_priority_max",errno); } reportEvent( 8, "scheduler high priority", high_priority); if (realTimeSchedPriority > high_priority) { param.sched_priority = high_priority - 1; } else { param.sched_priority = realTimeSchedPriority; } if ( sched_setscheduler( 0, SCHED_FIFO, ¶m) == -1 ) { reportEvent( 1, "Could not set POSIX real-time scheduling, " "this may cause recording skips.\n" "Try to run darkice as the super-user."); } else { /* ask the new priortiy and report it */ if ( sched_getparam( 0, ¶m) == -1 ) { throw Exception( __FILE__, __LINE__, "sched_getparam", errno); } reportEvent( 1, "Using POSIX real-time scheduling, priority", param.sched_priority ); } #else reportEvent( 1, "POSIX scheduling not supported on this system, " "this may cause recording skips"); #endif // HAVE_SCHED_GETSCHEDULER && HAVE_SCHED_GETPARAM }
/*------------------------------------------------------------------------------ * Set POSIX real-time scheduling, if super-user *----------------------------------------------------------------------------*/ void DarkIce :: setRealTimeScheduling ( void ) throw ( Exception ) { uid_t euid; euid = geteuid(); if ( euid == 0 ) { int high_priority; struct sched_param param; /* store the old scheduling parameters */ if ( (origSchedPolicy = sched_getscheduler(0)) == -1 ) { throw Exception( __FILE__, __LINE__, "sched_getscheduler", errno); } if ( sched_getparam( 0, ¶m) == -1 ) { throw Exception( __FILE__, __LINE__, "sched_getparam", errno); } origSchedPriority = param.sched_priority; /* set SCHED_FIFO with max - 1 priority */ if ( (high_priority = sched_get_priority_max(SCHED_FIFO)) == -1 ) { throw Exception(__FILE__,__LINE__,"sched_get_priority_max",errno); } reportEvent( 8, "scheduler high priority", high_priority); param.sched_priority = high_priority - 1; if ( sched_setscheduler( 0, SCHED_FIFO, ¶m) == -1 ) { throw Exception( __FILE__, __LINE__, "sched_setscheduler", errno); } /* ask the new priortiy and report it */ if ( sched_getparam( 0, ¶m) == -1 ) { throw Exception( __FILE__, __LINE__, "sched_getparam", errno); } reportEvent( 1, "Using POSIX real-time scheduling, priority", param.sched_priority ); } else { reportEvent( 1, "Not running as super-user, unable to use POSIX real-time scheduling" ); reportEvent( 1, "It is recommended that you run this program as super-user"); } }
int main(int argc, char **argv) { struct sched_param param; int result = -1; param.sched_priority = -1; result = sched_getparam(0, ¶m); if (result == 0 && param.sched_priority != -1 && errno == 0) { printf("Test PASSED\n"); return PTS_PASS; } if (errno != 0) { perror("Unexpected error"); return PTS_FAIL; } if (result != 0) { printf("returned code is not zero.\n"); return PTS_FAIL; } else { perror("Unresolved test error"); return PTS_UNRESOLVED; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; }
int go_realtime(void) { int max_pri; struct sched_param sp; if (sched_getparam(0, &sp)) { perror("sched_getparam"); return -1; } max_pri = sched_get_priority_max(SCHED_FIFO); sp.sched_priority = REALTIME_PRIORITY; if (sp.sched_priority > max_pri) { fprintf(stderr, "Invalid priority (maximum %d)\n", max_pri); return -1; } if (sched_setscheduler(0, SCHED_FIFO, &sp)) { perror("sched_setscheduler"); return -1; } 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); }
int main(){ int result; struct sched_param param; /* 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; } } if(sched_getparam(0, ¶m) == -1) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } result = sched_setparam(1, ¶m); if(result == -1 && errno == EPERM) { printf("Test PASSED\n"); return PTS_PASS; } else if(errno != EPERM) { perror("errno is not EPERM"); return PTS_FAIL; } else { printf("The returned code is not -1.\n"); return PTS_FAIL; } }
int main() { int policy, result; struct sched_param param; if (sched_getparam(0, ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); 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 (result == -1 && errno == EINVAL) { printf("Test PASSED\n"); return PTS_PASS; } else if (result != -1) { printf("The returned code is not -1.\n"); return PTS_FAIL; } else if (errno == EPERM) { printf ("This process does not have the permission to set its own scheduling policy.\nTry to launch this test as root.\n"); return PTS_UNRESOLVED; } perror("Unknow error"); return PTS_FAIL; }
static int raise_priority() { int max_pri; struct sched_param sp; fprintf(stderr, "Setting scheduler priority...\n"); if (sched_getparam(0, &sp)) { perror("sched_getparam"); return -1; } max_pri = sched_get_priority_max(SCHED_FIFO); sp.sched_priority = REALTIME_PRIORITY; if (sp.sched_priority > max_pri) { fprintf(stderr, "Invalid scheduling priority (maximum %d).\n", max_pri); return -1; } if (sched_setscheduler(0, SCHED_FIFO, &sp)) { perror("sched_setscheduler"); fprintf(stderr, "Failed to set scheduler. Run as root otherwise you " "may get wow and skips!\n"); } return 0; }
int main(int argc, char **argv) { struct sched_param param; 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 (geteuid() == 0) { if (set_nonroot() != 0) { printf("Cannot run this test as non-root user\n"); return PTS_UNTESTED; } } result = sched_getparam(1, ¶m); if (result == -1 && errno == EPERM) { printf("Test PASSED\n"); return PTS_PASS; } if (result == 0) { printf("The function sched_getparam has successed.\n"); return PTS_FAIL; } if (errno != EPERM) { perror("errno is not EPERM: The system allows a non-root" "user to use sched_getparam()"); return PTS_UNRESOLVED; } else { perror("Unresolved test error"); return PTS_UNRESOLVED; } }
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; }
/****************************************************************************** * Initialize Portable layer Thread functions * * Parameter: * NONE * Return value: * 0 successful *****************************************************************************/ OSA_RESULT osa_t_init(void) { struct sched_param sparam; pid_t mypid; d3(printf("osa_t_init:\n")); /* setup thread handle list */ g_ThreadList = (ThreadHandle_t*) malloc( sizeof(ThreadHandle_t) ); memset(g_ThreadList, 0, sizeof(ThreadHandle_t)); INIT_LIST_HEAD( &(g_ThreadList->list) ); g_ThreadList->id = 0; g_ThreadList->magic = OSA_T_MAGIC; /* create, set tid tsd */ if( _osa_tid_key == -1 ) _osa_tsd_create(&_osa_tid_key); _osa_tsd_set( &_osa_tid_key, (size_t) g_ThreadList); /* set my schedule policy ?*/ #if 1 mypid = getpid(); sched_getparam(mypid,&sparam); sparam.sched_priority = (OSA_T_LNX_PRIORITY_MAX - OSA_T_LNX_PRIORITY_MIN + 1)/2; sched_setscheduler(mypid, SCHED_RR, &sparam); //sched_setscheduler(mypid,SCHED_OTHER,&sparam); #endif // setup thread signal actions _osa_t_setup_signal(); d3(printf("osa_t_init: end\n")); return 0; }
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 spi_dev_channel_init( comm_channel_t *channel, char *interface, int baudrate ) { spi_connection_t *sc = spi_get_connection( channel ); if (!sc) { return( -1 ); } sc->fd = open(interface, O_RDWR); if (sc->fd == -1) { perror("open robostix dev"); return -1; } struct sched_param param; pthread_attr_t attr; pthread_attr_init(&attr); sched_getparam(0, ¶m); if (param.sched_priority > 0) { /* javiator connection got a higher priority than the controller */ param.sched_priority++; pthread_attr_setschedparam(&attr, ¶m); pthread_attr_setschedpolicy(&attr, SCHED_FIFO); pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); } pthread_create(&sc->thread, &attr, spi_thread, sc); return( 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); } }
int main() { int new_priority, max_priority, policy, result; struct sched_param param; pthread_t tid; pthread_attr_t attr; if(sched_getparam(getpid(), ¶m) != 0){ perror("An error occurs when calling sched_getparam()"); pthread_exit((void*)-1); } /* Make sure new_priority != old priority */ max_priority = sched_get_priority_max(SCHED_FIFO); new_priority = (param.sched_priority == max_priority) ? sched_get_priority_min(SCHED_FIFO) : max_priority; if(pthread_attr_init(&attr) != 0) { printf("An error occurs when calling pthread_attr_init()"); return PTS_UNRESOLVED; } result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS); if(result == ENOTSUP) { printf("Process contention scope threads are not supported. Use System contention schope instead.\n"); result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); // return PTS_UNSUPPORTED; } else if(result != 0) { printf("An error occurs when calling pthread_attr_setscope()"); return PTS_UNRESOLVED; } if(pthread_create(&tid, &attr, runner, NULL) != 0) { printf("An error occurs when calling pthread_create()"); return PTS_UNRESOLVED; } param.sched_priority = new_priority; if(sched_setscheduler(getpid(), SCHED_FIFO, ¶m) != 0){ if(errno == EPERM) { printf("This process does not have the permission to set its own scheduling policy.\nTry to launch this test as root.\n"); return PTS_UNRESOLVED; } perror("An error occurs when calling sched_setscheduler()"); return PTS_UNRESOLVED; } if(pthread_getschedparam(tid , &policy, ¶m) != 0) { printf("An error occurs when calling pthread_getschedparam()"); return PTS_UNRESOLVED; } pthread_cancel(tid); if(param.sched_priority == new_priority){ printf("Test PASSED\n"); return PTS_PASS; } printf("sched_setscheduler() does not set the right param.\n"); return PTS_FAIL; }
int main(int argc, char **argv) { struct sched_param param; int result = -1; param.sched_priority = -1; result = sched_getparam(getpid(), ¶m); if (result == 0 && param.sched_priority != -1 && errno == 0) { printf("Test PASSED\n"); return PTS_PASS; } else if (result != 0) { printf("Return code is not zero.\n"); return PTS_FAIL; } else if (errno != 0) { perror("Unexpected error"); return PTS_FAIL; } else if (param.sched_priority == -1) { printf("The 'sched_priority' member does not change.\n"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; }
static PyObject * rtaudio_get_priority(PyObject *obj, PyObject *args) { #if defined(__LINUX_ALSA__) || defined(__LINUX_OSS__) || defined(__LINUX_JACK__) struct sched_param schp = { 0 }; int ret; ret = sched_getparam(0, &schp); if(ret == -1) { PyErr_Format(RtAudioError, strerror(errno)); return NULL; } return Py_BuildValue("i", schp.sched_priority); #endif #ifdef __MACOSX_CORE__ struct sched_param sp; memset(&sp, 0, sizeof(struct sched_param)); int policy; if (pthread_getschedparam(pthread_self(), &policy, &sp) == -1) { PyErr_SetString(RtAudioError, strerror(errno)); return NULL; } return Py_BuildValue("i", sp.sched_priority); #endif Py_RETURN_NONE; }
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; }
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) { 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 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)); }
/*------------------------------------------------------------------------------ * Set the original scheduling of the process, the one prior to the * setRealTimeScheduling call. * WARNING: make sure you don't call this before setRealTimeScheduling!! *----------------------------------------------------------------------------*/ void DarkIce :: setOriginalScheduling ( void ) throw ( Exception ) { // Only if the OS has the POSIX real-time scheduling functions implemented. #if defined( HAVE_SCHED_GETSCHEDULER ) && defined( HAVE_SCHED_GETPARAM ) uid_t euid; euid = geteuid(); if ( euid == 0 ) { struct sched_param param; if ( sched_getparam( 0, ¶m) == -1 ) { throw Exception( __FILE__, __LINE__, "sched_getparam", errno); } param.sched_priority = origSchedPriority; if ( sched_setscheduler( 0, origSchedPolicy, ¶m) == -1 ) { throw Exception( __FILE__, __LINE__, "sched_setscheduler", errno); } reportEvent( 5, "reverted to original scheduling"); } #endif // HAVE_SCHED_GETSCHEDULER && HAVE_SCHED_GETPARAM }
/*! * \brief Sets the scheduling policy of the current process. * * \internal * * \return * \li \c 0 on success. * \li \c result of GetLastError() on failure. * */ static int SetPolicyType( /*! . */ PolicyType in) { int retVal = 0; #ifdef __CYGWIN__ /* TODO not currently working... */ retVal = 0; #elif defined(__OSX__) || defined(__APPLE__) || defined(__NetBSD__) setpriority(PRIO_PROCESS, 0, 0); retVal = 0; #elif defined(_WIN32) retVal = sched_setscheduler(0, in); #elif defined(_POSIX_PRIORITY_SCHEDULING) && _POSIX_PRIORITY_SCHEDULING > 0 struct sched_param current; int sched_result; memset(¤t, 0, sizeof(current)); sched_getparam(0, ¤t); current.sched_priority = sched_get_priority_min(DEFAULT_POLICY); sched_result = sched_setscheduler(0, in, ¤t); retVal = (sched_result != -1 || errno == EPERM) ? 0 : errno; #else retVal = 0; #endif return retVal; }