示例#1
0
int main(){
	int policy, result;
	int result_code = PTS_PASS;
	struct sched_param param;

	if(sched_getparam(0, &param) == -1) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}	

	/* test when sched_ss_max_repl < 1 */
	param.sched_ss_max_repl = 0;	
	result = sched_setparam(0,&param);
	
	if(result != -1) {
		printf("The returned code is not -1 when sched_ss_max_repl < 1.\n");
		result_code = PTS_FAIL;
	} else if(errno == EPERM) {
		printf("This process does not have the permission to set its own scheduling parameter.\nTry to launch this test as root\n");
		result_code = PTS_UNRESOLVED;
	} else if(errno != EINVAL) {
		perror("Unknow error");
		result_code = PTS_FAIL;
	}

	/* test when sched_ss_max_repl > SS_REPL_MAX */
	param.sched_ss_max_repl = SS_REPL_MAX+1;
	result = sched_setparam(0,&param);

	if(result == -1 && errno == EINVAL) {
		if(result_code == PTS_PASS){
			printf("Test PASSED\n");
		}
		return result_code;
	} else if(result != -1) {
		printf("The returned code is not -1 when sched_ss_max_repl > SS_REPL_MAX.\n");
		return PTS_FAIL;
	} else if(errno == EPERM) {
		if(result_code == PTS_FAIL){
			printf("This process does not have the permission to set its own scheduling parameter.\nTry to launch this test as root\n");
			return PTS_FAIL;
		}
		return PTS_UNRESOLVED;
	} else {
	        perror("Unknow error");
		return PTS_FAIL;
	}
	

}
示例#2
0
main()
{	struct sched_param p;
	int p1,p2,p3;
			
	p1=fork();	
	
	if (p1==0)
	{	
	p.sched_priority= 70;	sched_setparam(getpid(),&p);
	
	//settinf RT FIFO scheduler with priority 90    
	sched_setscheduler(getpid(),SCHED_FIFO,&p);
	//printf("Master\n");
	execl("p1","/usr/bin/gnome-terminal","-1",NULL);	}

	else if (p1 >0)
	{	printf("P1: Writer\n");	}
	else {	printf("fork P1 fail\n");	}

	p2=fork();
	if (p2==0)
	{	p.sched_priority= 70;	
		sched_setparam(getpid(),&p);
	
		//settinf RT FIFO scheduler with priority 90    
		sched_setscheduler(getpid(),SCHED_FIFO,&p);

		execl("p2","/usr/bin/gnome-terminal","-1",NULL);	}

	else if (p2>0)
	{	printf("P2: Reader\n");	}
	else {	printf("fork P2 fail\n");	}
	//---------------------------------------------------------------
	p3=fork();	
	
	if (p3==0)
	{	
	p.sched_priority= 70;	sched_setparam(getpid(),&p);
	
	//settinf RT FIFO scheduler with priority 90    
	sched_setscheduler(getpid(),SCHED_FIFO,&p);
	//printf("Master\n");
	execl("p3","/usr/bin/gnome-terminal","-1",NULL);	}

	else if (p3 >0)
	{	printf("P3: Reader\n");	}
	else {	printf("fork P3 fail\n");	}
	//---------------------------------------------------------------
}
示例#3
0
文件: 23-3.c 项目: Nan619/ltp-ddt
int main()
{
	int old_priority;
	struct sched_param param;

	if (sched_getparam(0, &param) == -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, &param);

	if (sched_getparam(0, &param) != 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;
	}
}
示例#4
0
int test( void )
{
  pid_t  pid;
  struct sched_param param;
  int    result;

  pid = 0;

  /*
   *  really should use sched_get_priority_min() and sched_get_priority_max()
   */

  param.sched_priority = 0;
#ifdef _POSIX_SPORADIC_SERVER
  param.sched_ss_low_priority = 0;
  param.sched_ss_repl_period.tv_sec = 0;
  param.sched_ss_repl_period.tv_nsec = 0;
  param.sched_ss_init_budget.tv_sec = 0;
  param.sched_ss_init_budget.tv_nsec = 0;
#endif

  result = sched_setparam( pid, &param );

  return result;
}
示例#5
0
int main(int argc, char *argv[]) {
	int i = 0;
	struct sched_param par;
    //int str;

	int arg = atoi(argv[1]);
	int newPriority = atoi(argv[2]);
	printf("jestem w zadaniu 5a wywolanym przez funkcje execl, arg: %d \n", arg);

	int status = getpid();

	sched_getparam(0,&par);
    par.sched_priority = newPriority;
    sched_setparam(0,&par);
	//sched_setscheduler(0,SCHED_FIFO,&par);

	for ( i = 0; i < arg ; i++ ){
	          printf ( "Proces potomny(priorytet %d) o pid %d krok %d\n",par.sched_priority, getpid(), i + 1 );

	          sleep(1);
	   }
   exit(status);//chyba nie potrzebne
	//exit();

}
示例#6
0
int port_thread_set_priority(osthread_t os_thread, int priority)
{
/*  Dhruwat - haiku porting - start */
/*#if defined(FREEBSD)*/
#if defined(FREEBSD) || defined(HAIKU)
/*  Dhruwat - haiku porting - start */
/*TODO - check if it ok for Haiku */
    /* Not sure why we don't just use this on linux? - MRH */
    struct sched_param param;
    int policy;
    int r = pthread_getschedparam(os_thread, &policy, &param);
    if (r == 0) {
        param.sched_priority = priority;
        r = pthread_setschedparam(os_thread, policy, &param);
    }
    return r;
#else
    // setting thread priority on linux is only supported for current thread
    if (os_thread == pthread_self()) {
        int r;
        struct sched_param param;
        pid_t self = gettid();
        param.sched_priority = priority;
        r = sched_setparam(self, &param);
        return r ? errno : 0;
    } else {
        // setting other thread priority not supported on linux
        return 0;
    }
#endif
}
示例#7
0
文件: 25-3.c 项目: Mellanox/arc_ltp
int main() {
	int policy, result;
	struct sched_param param;

	if (sched_getparam(0, &param) != 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;

	result = sched_setparam(0,&param);

	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 parameter.\nTry to launch this test as root\n");
		return PTS_UNRESOLVED;
	} else {
	        perror("Unknown error");
       	        return PTS_FAIL;
	}
}
示例#8
0
文件: 26-1.c 项目: ystk/debian-ltp
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, &param) == -1) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}

	result = sched_setparam(1, &param);

	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;
	}
}
示例#9
0
int main(int ac, char **av)
{

	int lc;
	char *msg;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		/*
		 * Call sched_setparam(2) with pid=0 sothat it will
		 * set the scheduling parameters for the calling process
		 */
		TEST(sched_setparam(0, &param));

		if (TEST_RETURN == 0) {
			tst_resm(TPASS, "sched_setparam() returned %ld",
				 TEST_RETURN);
		} else {
			tst_resm(TFAIL|TTERRNO, "Test Failed, sched_setparam()"
				 "returned %ld", TEST_RETURN);
		}
	}

	cleanup();
	tst_exit();
}
static PyObject *
rtaudio_set_priority(PyObject *obj, PyObject *args)
{
  int priority;
  if(!PyArg_ParseTuple(args, "i", &priority))
    return NULL;

#if defined(__LINUX_ALSA__) || defined(__LINUX_OSS__) || defined(__LINUX_JACK__)
  struct sched_param schp = { 0 };
  int ret;
  schp.sched_priority = priority;

  ret = sched_setparam(0, &schp);
  if(ret == -1)
    {
      PyErr_Format(RtAudioError, strerror(errno));
      return NULL;
    }

#elif defined(__MACOSX_CORE__)

  struct sched_param sp;
 
  memset(&sp, 0, sizeof(struct sched_param));
  sp.sched_priority=priority;
  if (pthread_setschedparam(pthread_self(), SCHED_RR, &sp)  == -1) 
    {
      PyErr_SetString(RtAudioError, strerror(errno));
      return NULL;
    }

#endif
  Py_RETURN_NONE;
}
示例#11
0
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);
}
示例#12
0
/**
 * Restores scheduling attributes.
 * Most of this won't work right, but anyway...
 */
static void rtSchedNativeRestore(PSAVEDPRIORITY pSave)
{
    setpriority(PRIO_PROCESS, 0, pSave->iPriority);
    sched_setscheduler(0, pSave->iPolicy, &pSave->SchedParam);
    sched_setparam(0, &pSave->SchedParam);
    pthread_setschedparam(pthread_self(), pSave->iPthreadPolicy, &pSave->PthreadSchedParam);
}
示例#13
0
文件: 23-4.c 项目: shubmit/shub-ltp
int main() {
	int old_priority;
	struct sched_param param;

	if (sched_getparam(0, &param) == -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,&param);

	if (sched_getparam(0, &param) != 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;
	}

}
示例#14
0
int set_sched_status(int policy, int priority)
{
    int ret, min_prio, max_prio;
    struct sched_param sp;
    max_prio = sched_get_priority_max(policy);
    min_prio = sched_get_priority_min(policy);
    if (max_prio == -1 || min_prio == -1)
        whine("Cannot determine scheduler prio limits!\n");
    else if (priority < min_prio)
        priority = min_prio;
    else if (priority > max_prio)
        priority = max_prio;
    memset(&sp, 0, sizeof(sp));
    sp.sched_priority = priority;
    ret = sched_setscheduler(getpid(), policy, &sp);
    if (ret) {
        whine("Cannot set scheduler policy!\n");
        return -EINVAL;
    }
    ret = sched_setparam(getpid(), &sp);
    if (ret) {
        whine("Cannot set scheduler prio!\n");
        return -EINVAL;
    }
    return 0;
}
示例#15
0
文件: pi.c 项目: columbia/cr-tests
int set_my_static_priority(int prio)
{
	struct sched_param param;

	param.sched_priority = prio;
	return sched_setparam(gettid(), &param);
}
int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr)
{
  struct sched_param param;

  DEBUGASSERT(attr);

  /* Now set the attributes.  Note that we ignore all of the return values
   * here because we have already successfully started the task.  If we
   * return an error value, then we would also have to stop the task.
   */

  /* If we are only setting the priority, then call sched_setparm()
   * to set the priority of the of the new task.
   */

  if ((attr->flags & POSIX_SPAWN_SETSCHEDPARAM) != 0)
    {
      /* Get the priority from the attrributes */

      param.sched_priority = attr->priority;

      /* If we are setting *both* the priority and the scheduler,
       * then we will call sched_setscheduler() below.
       */

      if ((attr->flags & POSIX_SPAWN_SETSCHEDULER) == 0)
        {
          svdbg("Setting priority=%d for pid=%d\n",
                param.sched_priority, pid);

          (void)sched_setparam(pid, &param);
        }
    }

  /* If we are only changing the scheduling policy, then reset
   * the priority to the default value (the same as this thread) in
   * preparation for the sched_setscheduler() call below.
   */

  else if ((attr->flags & POSIX_SPAWN_SETSCHEDULER) != 0)
    {
      (void)sched_getparam(0, &param);
    }

  /* Are we setting the scheduling policy?  If so, use the priority
   * setting determined above.
   */

  if ((attr->flags & POSIX_SPAWN_SETSCHEDULER) != 0)
    {
      svdbg("Setting policy=%d priority=%d for pid=%d\n",
            attr->policy, param.sched_priority, pid);

      (void)sched_setscheduler(pid, attr->policy, &param);
    }

  return OK;
}
示例#17
0
void testValues() {
    f = 2;
    
    struct sched_param p;
    sched_setparam(anyint(), &p);

    //@ assert f == 2;
    //@ assert vacuous: \false;
}
示例#18
0
int main(int ac, char **av)
{

	int lc, i;		/* loop counter */
	char *msg;		/* message returned from parse_opts */

	/* parse standard options */
	if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL))
	    != (char *)NULL) {
		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
	}

	/* perform global setup for test */
	setup();

	/* check looping state if -i option given */
	for (lc = 0; TEST_LOOPING(lc); lc++) {

		/* reset Tst_count in case we are looping. */
		Tst_count = 0;

		for (i = 0; i < TST_TOTAL; ++i) {

			if (i == 2) {
				param1.sched_priority = 0;
			} else {
				param1.sched_priority = 1;
			}
			if ((sched_setscheduler(0, testcases[i].policy,
						&param1)) == -1) {
				tst_brkm(TBROK, cleanup, "sched_setscheduler()"
					 "  failed");
			}
			param.sched_priority = testcases[i].priority;
			/*
			 * Call sched_setparam(2) with pid=0 sothat it will
			 * set the scheduling parameters for the calling process
			 */
			TEST(sched_setparam(0, &param));

			if ((TEST_RETURN == 0) && (verify_priority(i))) {
				tst_resm(TPASS, "%s Passed", testcases[i].desc);
			} else {
				tst_resm(TFAIL|TTERRNO, "%s Failed. sched_setparam()"
					 " returned %ld",
					 testcases[i].desc, TEST_RETURN);
			}
		}
	}			/* End for TEST_LOOPING */

	/* cleanup and exit */
	cleanup();

	 /*NOTREACHED*/ return 0;

}				/* End main */
示例#19
0
文件: 21-2.c 项目: CSU-GH/okl4_3.0
int main() {
	int new_priority, max_priority, policy, result;
	struct sched_param param;
	pthread_t tid;
	pthread_attr_t attr;

	if(sched_getparam(getpid(), &param) != 0){
		perror("An error occurs when calling sched_getparam()");
		pthread_exit((void*)-1);
	}
	/* Make sure new_priority != old_priority */
	policy = sched_getscheduler(getpid());
	max_priority = sched_get_priority_max(policy);
	new_priority = (param.sched_priority == max_priority) ? 
		sched_get_priority_min(policy) :
		max_priority;
	param.sched_priority = new_priority;
	if(sched_setparam(getpid(), &param) != 0){
		perror("An error occurs when calling sched_setparam()");
		return PTS_UNRESOLVED;
	}


	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;
	}


	if(pthread_getschedparam(tid , &policy, &param) != 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("The threads does not inherit the right param.\n");
	return PTS_FAIL;
}
示例#20
0
文件: 2-2.c 项目: jiezh/h5vcc
void child_process(int id){
	int i;
	struct sched_param param;

	if(id == nb_child-1){
		param.sched_priority = sched_get_priority_min(SCHED_RR);
		sched_setparam(getpid(), &param);
	}

	for(i=0; i<NB_LOOP_CHILD; i++) {
		count ++;
	}
}
示例#21
0
int main(int ac, char **av)
{

	int lc, i;
	char *msg;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		for (i = 0; i < TST_TOTAL; ++i) {

			if (i == 2) {
				param1.sched_priority = 0;
			} else {
				param1.sched_priority = 1;
			}
			if ((sched_setscheduler(0, testcases[i].policy,
						&param1)) == -1) {
				tst_brkm(TBROK, cleanup, "sched_setscheduler()"
					 "  failed");
			}
			param.sched_priority = testcases[i].priority;
			/*
			 * Call sched_setparam(2) with pid=0 sothat it will
			 * set the scheduling parameters for the calling process
			 */
			TEST(sched_setparam(0, &param));

			if ((TEST_RETURN == 0) && (verify_priority(i))) {
				tst_resm(TPASS, "%s Passed", testcases[i].desc);
			} else {
				tst_resm(TFAIL | TTERRNO,
					 "%s Failed. sched_setparam()"
					 " returned %ld", testcases[i].desc,
					 TEST_RETURN);
			}
		}
	}

	/* cleanup and exit */
	cleanup();

	tst_exit();

}
示例#22
0
static void child_process(void)
{
	struct sched_param param;

	param.sched_priority = sched_get_priority_max(SCHED_FIFO);
	if (sched_setparam(getpid(), &param) != 0) {
		perror("An error occurs when calling sched_setparam()");
		return;
	}

	/* to avoid blocking */
	alarm(2);
	while (1);
}
示例#23
0
文件: 25-2.c 项目: 1587/ltp
int main(void)
{
	int policy, invalid_priority, result;
	struct sched_param param;

	policy = sched_getscheduler(0);
	if (policy == -1) {
		perror("An error occurs when calling sched_getscheduler()");
		return PTS_UNRESOLVED;
	} else if (policy != SCHED_SPORADIC) {

		if (sched_getparam(0, &param) != 0) {
			perror("An error occurs when calling sched_getparam()");
			return PTS_UNRESOLVED;
		}

		if (sched_setscheduler(0, SCHED_SPORADIC, &param) != 0) {
			perror("An error occurs when calling sched_getparam()");
			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;

	result = sched_setparam(0, &param);

	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 parameter.\nTry to launch this test as root\n");
		return PTS_UNRESOLVED;
	} else {
		perror("Unknow error");
		return PTS_FAIL;
	}
}
示例#24
0
文件: 23-2.c 项目: kraj/ltp
int main(void)
{
	int policy, invalid_priority, old_priority;
	struct sched_param param;

	if (sched_getparam(0, &param) != 0) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}
	old_priority = param.sched_priority;

	policy = sched_getscheduler(0);
	if (policy == -1) {
		perror("An error occurs when calling sched_getscheduler()");
		return PTS_UNRESOLVED;
	} else if (policy != SCHED_SPORADIC) {
		if (sched_setscheduler(0, SCHED_SPORADIC, &param) == -1) {
			perror("An error occurs when calling sched_getparam()");
			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;
	param.sched_priority++;
	sched_setparam(0, &param);

	if (sched_getparam(0, &param) != 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;
	}
}
示例#25
0
int setpriority(int which, id_t who, int prio)
{
	struct sched_param param;
	if (which != PRIO_PROCESS) {
		errno = ENOSYS;
		return -1;
	}

	param.sched_priority = prio;
	int ret = sched_setparam(who, &param);
	if (ret < 0) {
		errno = -ret;
		return -1;
	}

	return ret;
}
示例#26
0
文件: 23-6.c 项目: kraj/ltp
int main(void)
{
	int old_priority;
	struct sched_param param;
	int rc;

	/* 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 */

	param.sched_priority = sched_get_priority_min(SCHED_FIFO);
	/* Cannot test SCHED_OTHER, on 0 valid as its priority */
	sched_setscheduler(0, SCHED_FIFO, &param);
	if (getuid() == 0) {
		if (set_nonroot() != 0) {
			printf("Cannot run this test as non-root user\n");
			return PTS_UNTESTED;
		}
	}

	if (sched_getparam(0, &param) == -1) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}
	old_priority = param.sched_priority;

	param.sched_priority++;
	rc = sched_setparam(0, &param);
	if (rc != -1 || (rc == -1 && errno != EPERM)) {
		perror("sched_setparam() does not return EPERM\n");
		return PTS_UNRESOLVED;
	}

	if (sched_getparam(0, &param) != 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;
	}
}
示例#27
0
文件: 5-1.c 项目: Nan619/ltp-ddt
int main()
{
	int result, new_priority, old_priority, max_prio, policy;
	struct sched_param param;

	if (sched_getparam(getpid(), &param) != 0) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}

	policy = sched_getscheduler(getpid());
	if (policy == -1) {
		perror("An error occurs when calling sched_getscheduler()");
		return PTS_UNRESOLVED;
	}

	/* Make sure new_priority != old_priority */
	max_prio = sched_get_priority_max(policy);
	old_priority = param.sched_priority;
	new_priority = (old_priority == max_prio) ?
	    sched_get_priority_min(policy) : max_prio;
	param.sched_priority = new_priority;

	result = sched_setparam(0, &param);

	if (sched_getparam(getpid(), &param) != 0) {
		perror("An error occurs when calling sched_getparam()");
		return PTS_UNRESOLVED;
	}

	if (result == 0 && param.sched_priority == new_priority) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else if (result == 0 && param.sched_priority == old_priority) {
		printf("The param does not change\n");
		return PTS_FAIL;
	} else if (result == -1 && errno == EPERM) {
		printf
		    ("The process have not permission to change its own param.\n");
		return PTS_UNRESOLVED;
	}

	perror("Unknow error");
	return PTS_FAIL;
}
示例#28
0
/*
스케줄러와 우선순위 변경.
root 권한(CAP_SYS_NICE)으로 실행되어야 한다.
*/
void sched_control()
{
	int policy;
/*
	현재 프로세스에 적용중인 스케줄러 정책 얻기
	#define SCHED_OTHER		0
	#define SCHED_FIFO		1
	#define SCHED_RR		2
	#define SCHED_BATCH		3
	#define SCHED_IDLE		5
*/
	policy = sched_getscheduler(0);
	printf("old scheduler = %d\n", policy);

	struct sched_param sp;
	sp.sched_priority = 1; // 우선순위 지정

	// 스케줄러 정책(라운드 로빈 스케줄링)과 우선순위 변경
	if(sched_setscheduler(0, SCHED_RR, &sp) == -1)
		errexit("sched_setscheduler");

	policy = sched_getscheduler(0);
	printf("new scheduler = %d\n", policy);

	// 우선순위 값 얻기
	if(sched_getparam(0, &sp) == -1)
		errexit("sched_getparam");
	printf("current priority = %d\n", sp.sched_priority);

	// 우선순위 값만 변경
	sp.sched_priority = 2;
	if(sched_setparam(0, &sp) == -1)
		errexit("sched_getparam");
	printf("new priority = %d\n", sp.sched_priority);


	// 현재 스케줄링 정책의 유효한 우선순위 값 확인
	int min, max;
	if((min = sched_get_priority_min(policy)) == -1) // 1
		errexit("sched_get_priority_min");
	if((max = sched_get_priority_max(policy)) == 01) // 99
		errexit("sched_get_priority_max");
	printf("SCHED_RR priority range is %d - %d\n", min, max);

}
示例#29
0
int set_priority(pid_t pid, int policy, int priority)
{
	int ret;
	if (policy != SCHED_OTHER){
		struct sched_param sched_p;
		sched_p.__sched_priority = priority;
		ret = sched_setparam(pid, &sched_p);
		if (ret)
			fprintf(stderr, "sched_setparam returned %d errno=%d (%s).\n", ret, errno, strerror(errno));
	}else{
		/* for SCHED_OTHER we just change the "nice" value: */
		ret = setpriority(PRIO_PROCESS, pid, priority);
		if (ret)
			fprintf(stderr, "setpriority returned %d errno=%d (%s).\n", ret, errno, strerror(errno));

	}
	return -1;
}
示例#30
0
int main(int ac, char **av)
{
	int lc, ind;		/* loop counter */
	char *msg;		/* message returned from parse_opts */

	/* parse standard options */
	if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL))
	    != (char *)NULL) {
		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
	}

	setup();		/* global setup */

	/* The following loop checks looping state if -i option given */
	for (lc = 0; TEST_LOOPING(lc); lc++) {
		/* reset Tst_count in case we are looping */
		Tst_count = 0;

		for (ind = 0; ind < TST_TOTAL; ind++) {
			/*
			 * call the system call with the TEST() macro
			 */
			TEST(sched_setparam(test_cases[ind].pid,
					    test_cases[ind].p));

			if ((TEST_RETURN == -1) &&
			    (TEST_ERRNO == test_cases[ind].exp_errno)) {
				tst_resm(TPASS, "expected failure; Got %s",
					 test_cases[ind].err_desc);
			} else {
				tst_resm(TFAIL, "Call failed to produce "
					 "expected error;  Expected errno: %d "
					 "Got : %d, %s",
					 test_cases[ind].exp_errno,
					 TEST_ERRNO, strerror(TEST_ERRNO));
			}
			TEST_ERROR_LOG(TEST_ERRNO);
		}
	}

	cleanup();

	 /*NOTREACHED*/ return 0;
}