Exemple #1
0
/*
 * Get the highest priority value available on this system.
 */
PJ_DEF(int) pj_thread_get_prio_max(pj_thread_t *thread)
{
    struct sched_param param;
    int policy;
    int rc;

    rc = pthread_getschedparam(thread->thread, &policy, &param);
    if (rc != 0)
	return -1;

#if defined(_POSIX_PRIORITY_SCHEDULING)
    return sched_get_priority_max(policy);
#elif defined __OpenBSD__
    /* Thread prio min/max are declared in OpenBSD private hdr */
    return 31;
#else
    pj_assert("pj_thread_get_prio_max() not supported!");
    return 0;
#endif
}
static PyObject *
rtaudio_boost_priority(PyObject *obj, PyObject *args)
{
#if defined(__LINUX_ALSA__) || defined(__LINUX_OSS__) || defined(__LINUX_JACK__)
  struct sched_param schp = { 0 };
  int priority = (sched_get_priority_max(SCHEDULER_POLICY) -
                  sched_get_priority_min(SCHEDULER_POLICY)) / 2;
  schp.sched_priority = priority;
  
  if (sched_setscheduler(0, SCHEDULER_POLICY, &schp) != 0)
    {
      PyErr_Format(RtAudioError, "insufficient priveledges");
      return NULL;
    }

  /* We are running at high priority so we should have a watchdog in
     case audio goes wild. */
#endif

#if defined(__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;
    }

  sp.sched_priority += 40;
  if (pthread_setschedparam(pthread_self(), SCHED_RR, &sp)  == -1) 
    {
      PyErr_SetString(RtAudioError, strerror(errno));
      return NULL;
    }

#endif
  Py_RETURN_NONE;
}
Exemple #3
0
bool gcore::Thread::priority(gcore::Thread::Priority prio) {
  if (mRunning) {
    sched_param sched; // = {0, 0};
    int plcy = 0;
    if (pthread_getschedparam((pthread_t)mSelf, &plcy, &sched) == 0) {
#if defined(_POSIX_PRIORITY_SCHEDULING)
      int priomax = sched_get_priority_max(plcy);
      int priomin = sched_get_priority_min(plcy);
#elif defined(PTHREAD_MINPRIORITY) && defined(PTHREAD_MAX_PRIORITY)
      int priomin = PTHREAD_MIN_PRIORITY;
      int priomax = PTHREAD_MAX_PRIORITY;
#else
      int priomin = 0;
      int priomax = 32;
#endif
      int priomed = (priomax + priomin) / 2;
      switch (prio) {
      case PRI_VERY_LOW:
        sched.sched_priority = priomin;
        break;
      case PRI_LOW:
        sched.sched_priority = (priomin + priomed) / 2;
        break;
      case PRI_NORMAL:
        sched.sched_priority = priomed;
        break;
      case PRI_HIGH:
        sched.sched_priority = (priomax + priomed) / 2;
        break;
      case PRI_VERY_HIGH:
        sched.sched_priority = priomax;
        break;
      default:
        sched.sched_priority = priomed;
        break;
      }
      return (pthread_setschedparam((pthread_t)mSelf, plcy, &sched) == 0);
    }
  }
  return false;
}
Exemple #4
0
/* Make the current thread a realtime thread, and acquire the highest
 * rtprio we can get that is less or equal the specified parameter. If
 * the thread is already realtime, don't do anything. */
int pa_make_realtime(int rtprio) {

#ifdef _POSIX_PRIORITY_SCHEDULING
    struct sched_param sp;
    int r, policy;

    memset(&sp, 0, sizeof(sp));
    policy = 0;

    if ((r = pthread_getschedparam(pthread_self(), &policy, &sp)) != 0) {
        pa_log("pthread_getschedgetparam(): %s", pa_cstrerror(r));
        return -1;
    }

    if (policy == SCHED_FIFO && sp.sched_priority >= rtprio) {
        pa_log_info("Thread already being scheduled with SCHED_FIFO with priority %i.", sp.sched_priority);
        return 0;
    }

    sp.sched_priority = rtprio;
    if ((r = pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp)) != 0) {

        while (sp.sched_priority > 1) {
            sp.sched_priority --;

            if ((r = pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp)) == 0) {
                pa_log_info("Successfully enabled SCHED_FIFO scheduling for thread, with priority %i, which is lower than the requested %i.", sp.sched_priority, rtprio);
                return 0;
            }
        }

        pa_log_warn("pthread_setschedparam(): %s", pa_cstrerror(r));
        return -1;
    }

    pa_log_info("Successfully enabled SCHED_FIFO scheduling for thread, with priority %i.", sp.sched_priority);
    return 0;
#else
    return -1;
#endif
}
Exemple #5
0
void benchmark_pthread_setschedparam(void)
{
  int status;
  int policy;
  struct sched_param param;
  pthread_t thread_ID;

  status = pthread_create(&thread_ID, NULL, test_thread, NULL);
  rtems_test_assert( status == 0 );

  /* make test_thread equal to POSIX_Init() */
  pthread_getschedparam(pthread_self(), &policy, &param);
  pthread_setschedparam(thread_ID, policy, &param);
  /* At this point, we've switched to test_thread */

  /* Back from test_thread, switch to test_thread again */
  param.sched_priority = sched_get_priority_max(policy) - 1;

  benchmark_timer_initialize();
  pthread_setschedparam(thread_ID, policy, &param);
}
Exemple #6
0
gcore::Thread::Scheduling gcore::Thread::scheduling() const {
  Scheduling result = SCH_UNKNOWN;
  if (mRunning) {
    sched_param sched; // = {0, 0};
    int plcy = 0;
    if (pthread_getschedparam((pthread_t)mSelf, &plcy, &sched) == 0) {
      switch (plcy) {
      case SCHED_FIFO:
        result = SCH_FIFO;
        break;
      case SCHED_RR:
        result = SCH_RR;
        break;
      default:
        result = SCH_DEFAULT;
        break;
      }
    }
  }
  return result;
}
Exemple #7
0
void set_real_time_priority(pthread_t thread)
{
	int policy;
	struct sched_param param;

	pthread_getschedparam (thread, &policy, &param);
#ifdef __linux__
	policy = SCHED_FIFO;
	const char* env = getenv("SC_SCHED_PRIO");
	// jack uses a priority of 10 in realtime mode, so this is a good default
	const int defprio = 5;
	const int minprio = sched_get_priority_min(policy);
	const int maxprio = sched_get_priority_max(policy);
	const int prio = env ? atoi(env) : defprio;
	param.sched_priority = sc_clip(prio, minprio, maxprio);
#else
	policy = SCHED_RR;         // round-robin, AKA real-time scheduling
	param.sched_priority = 63; // you'll have to play with this to see what it does
#endif
	pthread_setschedparam (thread, policy, &param);
}
Exemple #8
0
void coremu_init_sched_core()
{
    int policy;
    CMCore *self;
    struct sched_param param;
    assert(!pthread_getschedparam(pthread_self(), &policy, &param));
    assert(policy == CM_SCHED_POLICY);

    coremu_thread_setpriority(PRIO_PROCESS, 0, avg_prio);
    self = coremu_get_core_self();
    self->tid = coremu_gettid();

    /* display the scheduling info */
    display_thread_sched_attr("CORE thread scheduler settings:");

#ifdef CM_ENABLE_BIND_CORE
    /* bind thread to a specific core */
    //topology_bind_core();
#endif

}
int osd_thread_adjust_priority(osd_thread *thread, int adjust)
{
#ifdef WIN32
   if (adjust)
      SetThreadPriority(thread->handle, THREAD_PRIORITY_ABOVE_NORMAL);
   else
      SetThreadPriority(thread->handle, GetThreadPriority(GetCurrentThread()));
   return TRUE;
#else
	struct sched_param  sched;
	int                 policy;

	if ( pthread_getschedparam( thread->thread, &policy, &sched ) == 0 )
	{
		sched.sched_priority += adjust;
		if ( pthread_setschedparam(thread->thread, policy, &sched ) == 0)
			return TRUE;
	}
   return FALSE;
#endif
}
Exemple #10
0
void benchmark_pthread_getschedparam(void)
{
  uint32_t            end_time;
  int                 status;
  int                 policy;
  struct sched_param  param;

  benchmark_timer_initialize();
  status = pthread_getschedparam( pthread_self(), &policy, &param );
  end_time = benchmark_timer_read();
  rtems_test_assert( status == 0 );

  put_time(
    "pthread_getschedparam: only case",
    end_time,
    1,        /* Only executed once */
    0,
    0
  );

}
Exemple #11
0
void* func_noise(void* arg)
{
	Thread* pthr = (Thread*)arg;
	int rc, i, j, policy, tid = gettid();
	struct sched_param schedp;
	cpu_set_t mask;
	CPU_ZERO(&mask);
	CPU_SET(0, &mask);

	rc = sched_setaffinity(0, sizeof(mask), &mask);
	if (rc < 0) {
		 printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
		 exit(-1);
	}
	rc = sched_getaffinity(0, sizeof(mask), &mask);

	printf("Noise Thread started %d on CPU %ld\n", pthr->priority, (long)mask.__bits[0]);
	pthread_getschedparam(pthr->pthread, &policy, &schedp);

	while (1) {
		sleep(1);
		printf("Noise Thread running %d\n", pthr->priority);

		for (i = 0; i < 10000; i++) {
			if ((i % 100) == 0) {
				sched_getparam(tid, &schedp);
				policy = sched_getscheduler(tid);
				printf("Noise Thread %d(%d) loop %d pthread pol %d pri %d\n", tid, pthr->priority, i, policy, schedp.sched_priority);
				fflush(NULL);
			}
			pthr->id++;
			for (j = 0; j < 5000; j++) {
				pthread_mutex_lock(&(pthr->mutex));
				pthread_mutex_unlock(&(pthr->mutex));
			}
		}
		pthread_yield();
	}
	return NULL;
}
Exemple #12
0
long
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);
	}

	/*
	 * Make sure that any non-SCHED_FIFO non-SCHED_RR scheduler is mapped
	 * onto SCHED_OTHER.
	 */
	if (policy != SCHED_FIFO && policy != SCHED_RR)
		policy = SCHED_OTHER;

	return (stol_sparam(policy, &sp, (struct lx_sched_param *)param));
}
Exemple #13
0
void * hilo(void * arg)
{
    struct sched_param sp;
    int algoritmo;
    
    param * valores = (param * ) arg;
    
    pthread_t tid = pthread_self();
    
    pthread_getschedparam(tid, &algoritmo, &sp);
    printf("Algoritmo = %d, Prioridad = %d \n",
           algoritmo, sp.sched_priority);
    
    algoritmo = SCHED_RR;
    sp.sched_priority = 5;
    
    pthread_setschedparam(tid, algoritmo, &sp);
    printf("Algoritmo = %d, Prioridad = %d \n",
           algoritmo, sp.sched_priority);
    
    
    pthread_setspecific(tsd, (void *) &valores->tid);
    
    int * numero = (int *) pthread_getspecific(tsd);
    
    printf("TSD en %s = %d antes de modificar \n", valores->nombre, *numero);
    
    *numero = rand() % 100;
    
    pthread_setspecific(tsd, (void *) numero);
    
    numero = (int *) pthread_getspecific(tsd);
    
    printf("TSD en %s (%zd) = %d antes de modificar \n",
           valores->nombre,
           tid,
           *numero);
    
    pthread_exit(NULL);
}
Exemple #14
0
  static int server_thread_start () {
    pthread_attr_t thread_attr;
    struct sched_param param;
    int policy, result;

    logd ("server_thread_start thread_state: %d", thread_state);

    if (thread_state == 1) {
      logd ("server_thread_start & thread_state = running");
      return (BT_HC_STATUS_SUCCESS);
    }

    if (thread_state == 2) {
      logd ("server_thread_start & thread_state = not needed and running");
      return (BT_HC_STATUS_SUCCESS);
    }

    thread_state = 1;                                                   // Thread started
    pthread_mutex_init (& server_thread.mutex, NULL);
    pthread_cond_init  (& server_thread.cond, NULL);
    pthread_attr_init  (& thread_attr);

    if (pthread_create (& server_thread.server_thread, & thread_attr, bt_server_thread, NULL) != 0) {
      loge ("server_thread_start pthread_create failed");
      thread_state = 0;
      return (BT_HC_STATUS_FAIL);
    }

    if (pthread_getschedparam (server_thread.server_thread, & policy, & param) == 0) {
      policy = SCHED_NORMAL;
      //param.sched_priority = BTHC_MAIN_THREAD_PRIORITY;
      errno = 0;
      result = pthread_setschedparam (server_thread.server_thread, policy, & param);
      if (result != 0) {
        loge ("server_thread_start pthread_setschedparam failed errno: %d (%s) (%s)", errno, strerror (errno), strerror (result));  // ????
      }
    }
    logd ("server_thread_start done");
    return (BT_HC_STATUS_SUCCESS);
  }
Exemple #15
0
int dim_get_priority(int threadId, int *prio)
{
#ifdef __linux__
	pthread_t id=MAIN_thread;
	int ret;
	int pclass;
	struct sched_param param;

	if(threadId == 1)
		id = MAIN_thread;
	else if(threadId == 2)
		id = IO_thread;
	else if(threadId == 3)
		id = ALRM_thread;

	ret = pthread_getschedparam(id, &pclass, &param);   
	*prio = param.sched_priority;
	if(!ret)
	  return 1;
#endif
	return 0;
}
void il_tool_cb_empty_buffer_done(
                            il_comp_t           component_handle,
                            OMX_BUFFERHEADERTYPE*    buffer_done_p)
{
#if 0
    {
        struct sched_param sched_param;
        int    sched_policy;
        int    nice_prio;

        pthread_getschedparam(pthread_self(), &sched_policy, &sched_param);
        ALOG_STATUS("SCHED_OTHER=%d, SCHED_FIFO=%d, SCHED_RR=%d\n", SCHED_OTHER, SCHED_FIFO, SCHED_RR);
        ALOG_STATUS("IL ETB callback thread info: getpriority=%d pthread.policy=%d pthread.sched_priority=%d\n",
                    getpriority(PRIO_PROCESS, gettid()), sched_policy, sched_param.sched_priority);
    }
#endif

    ADM_ASSERT(component_handle != NULL);
    ADM_ASSERT(buffer_done_p != NULL);

    srv_send_il_buffer_msg(component_handle, buffer_done_p, CB_TYPE_BUFFER_EMPTIED);
}
Exemple #17
0
void GroupManager::StartThread() {
	if (! isRunning()) {
		debug("Starting Userlist Handling thread");
		bRunning = true;

		pfds[0].fd = ccn_get_connection_fd(ccn);
		pfds[0].events = POLLIN;
		start(QThread::HighestPriority);
#ifdef Q_OS_LINUX
		// QThread::HighestPriority == Same as everything else...
		int policy;
		sched_param param;
		if (pthread_getschedparam(pthread_self(), &policy, &param) == 0) {
			if (policy == SCHED_OTHER) {
				policy = SCHED_FIFO;
				param.sched_priority = 1;
				pthread_setschedparam(pthread_self(), policy, &param);
			}
		}
#endif
	}
}
Exemple #18
0
    bool set_priority(int priority) {
      int _policy;
      struct sched_param params;

      assert(pthread_getschedparam(native_, &_policy, &params) == 0);
      int max = sched_get_priority_max(_policy);
      int min = sched_get_priority_min(_policy);

      if(min > priority) {
        priority = min;
      }
      else if(max < priority) {
        priority = max;
      }

      params.sched_priority = priority;

      int err = pthread_setschedparam(native_, _policy, &params);
      if(err == ENOTSUP) return false;

      return true;
    }
Exemple #19
0
bool CThread::SetPrioritySched_RR(int iPriority)
{
  // Changing to SCHED_RR is safe under OSX, you don't need elevated privileges and the
  // OSX scheduler will monitor SCHED_RR threads and drop to SCHED_OTHER if it detects
  // the thread running away. OSX automatically does this with the CoreAudio audio
  // device handler thread.
  int32_t result;
  thread_extended_policy_data_t theFixedPolicy;

  // make thread fixed, set to 'true' for a non-fixed thread
  theFixedPolicy.timeshare = false;
  result = thread_policy_set(pthread_mach_thread_np(ThreadId()), THREAD_EXTENDED_POLICY,
    (thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT);

  int policy;
  struct sched_param param;
  result = pthread_getschedparam(ThreadId(), &policy, &param );
  // change from default SCHED_OTHER to SCHED_RR
  policy = SCHED_RR;
  result = pthread_setschedparam(ThreadId(), policy, &param );
  return result == 0;
}
Exemple #20
0
long
lx_sched_getscheduler(uintptr_t pid)
{
	int	policy, rv;
	pid_t	s_pid;
	lwpid_t	s_tid;

	if ((pid_t)pid < 0)
		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 ((rv = pthread_getschedparam(s_tid, &policy, &dummy)) != 0)
			return (-rv);
	} else
		if ((policy = sched_getscheduler(s_pid)) < 0)
			return (-errno);

	/*
	 * Linux only supports certain policies; avoid confusing apps with
	 * alien policies.
	 */
	switch (policy) {
	case SCHED_FIFO:
		return (LX_SCHED_FIFO);
	case SCHED_OTHER:
		return (LX_SCHED_OTHER);
	case SCHED_RR:
		return (LX_SCHED_RR);
	default:
		break;
	}

	return (LX_SCHED_OTHER);
}
Exemple #21
0
static void *thread_func(void *data)
{
	struct sched_param sp;
	int policy;
	int rc;

	rc = pthread_getschedparam(pthread_self(), &policy, &sp);
	if (rc)
		FAIL_AND_EXIT("pthread_getschedparam()", rc);

	rc = pthread_mutex_lock(&c_mutex);
	if (rc)
		FAIL_AND_EXIT("pthread_mutex_lock()", rc);
	thread_started = 1;
	rc = pthread_cond_signal(&cond);
	if (rc)
		FAIL_AND_EXIT("pthread_cond_signal()", rc);
	rc = pthread_mutex_unlock(&c_mutex);
	if (rc)
		FAIL_AND_EXIT("pthread_mutex_unlock()", rc);

	rc = pthread_mutex_lock(&mutex);
	if (rc)
		FAIL_AND_EXIT("pthread_mutex_lock()", rc);

	/* Stuff the priority in execution order */
	if (!priorities[0])
		priorities[0] = sp.sched_priority;
	else if (!priorities[1])
		priorities[1] = sp.sched_priority;
	else
		priorities[2] = sp.sched_priority;

	rc = pthread_mutex_unlock(&mutex);
	if (rc)
		FAIL_AND_EXIT("pthread_mutex_unlock()", rc);

	return (void *)(long)rc;
}
/******************************************************************************
 * Create a thread with default priority, without inheriting from the thread 
 * calling this function.
 *
 * Returns 0 on success; otherwise the failure codes are those returned by 
 * either pthread_attr_...() or pthread_create() calls. These are extremely 
 * unlikely, and in most cases signifiy something bad.
 ******************************************************************************/
int32_t vqec_pthread_create (pthread_t *tid, 
                             void *(*start_routine)(void *), void *arg)
{
    pthread_attr_t attr;
    struct sched_param sp;
    int32_t ret = 0, policy;
    size_t vqec_stack_size;

#ifdef USE_SMALL_VQEC_STACK
    vqec_stack_size = VQEC_SMALL_STACK;
#else
    vqec_stack_size = VQEC_NORMAL_STACK;
#endif

    memset(&sp, 0, sizeof(sp));
    if ((ret = pthread_attr_init(&attr)) ||
        (ret = pthread_attr_setschedpolicy(&attr, SCHED_OTHER)) ||
        (ret = pthread_attr_setschedparam(&attr, &sp)) ||
        (ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) ||
        (ret = pthread_attr_setstacksize(&attr, vqec_stack_size))) {        

        printf("=== Unable to set attributes for pthread (%s) ===\n",
               strerror(ret));
    } else if ((ret = pthread_create(tid, &attr, 
                                     start_routine, arg))) {
        
            printf("=== Unable to create pthread (%s) ===\n",
                   strerror(ret));
    } else {
        if (!pthread_getschedparam(*tid, &policy, &sp)) {
        	printf("=== pthread (%u) policy (%s), prio (%d) ===\n",
                       (uint32_t)*tid, 
                       (policy == SCHED_OTHER) ? "low" : "realtime", 
                       sp.sched_priority);	
        }
    }

    return (ret);
}
Exemple #23
0
bool gcore::Thread::scheduling(gcore::Thread::Scheduling sced) {
  if (mRunning) {
    sched_param sched; // = {0, 0};
    int oldplcy = 0;
    int newplcy = 0;
    if (pthread_getschedparam((pthread_t)mSelf, &oldplcy, &sched) == 0) {
      switch (sced) {
      case SCH_FIFO:
        newplcy = SCHED_FIFO;
        break;
      case SCH_RR:
        newplcy = SCHED_RR;
        break;
      default:
        newplcy = SCHED_OTHER;
        break;
      }
      return (pthread_setschedparam((pthread_t)mSelf, newplcy, &sched) == 0);
    }
  }
  return false;
}
//-----------------------------------------------------------------------------
// name: set_priority()
// desc: ...
//-----------------------------------------------------------------------------
static t_CKBOOL set_priority( CHUCK_THREAD tid, t_CKINT priority )
{
    struct sched_param param;
    int policy;

    // log
    EM_log( CK_LOG_FINE, "setting thread priority to: %ld...", priority );

    // get for thread
    if( pthread_getschedparam( tid, &policy, &param) ) 
        return FALSE;

    // priority
    param.sched_priority = priority;
    // policy
    policy = SCHED_RR;
    // set for thread
    if( pthread_setschedparam( tid, policy, &param ) )
        return FALSE;

    return TRUE;
}
Exemple #25
0
bool Thread::setPriority(int prio)
{
#if defined(_WIN32)

	return SetThreadPriority(m_thread_handle, prio);

#else

	struct sched_param sparam;
	int policy;

	if (pthread_getschedparam(m_thread_handle, &policy, &sparam) != 0)
		return false;

	int min = sched_get_priority_min(policy);
	int max = sched_get_priority_max(policy);

	sparam.sched_priority = min + prio * (max - min) / THREAD_PRIORITY_HIGHEST;
	return pthread_setschedparam(m_thread_handle, policy, &sparam) == 0;

#endif
}
Exemple #26
0
bool
BoostThreadPriority(SDL_Thread* inThread) {
#if defined(_POSIX_PRIORITY_SCHEDULING)
  pthread_t theTargetThread = (pthread_t) SDL_GetThreadID(inThread);
  int theSchedulingPolicy;
  struct sched_param theSchedulingParameters;

  if(pthread_getschedparam(theTargetThread, &theSchedulingPolicy,
                           &theSchedulingParameters) != 0) {
    return false;
  }

  theSchedulingParameters.sched_priority =
    sched_get_priority_max(theSchedulingPolicy);

  if(pthread_setschedparam(theTargetThread, theSchedulingPolicy,
                           &theSchedulingParameters) != 0) {
    return false;
  }
#endif
  return true;
}
Exemple #27
0
int main(int argc, const char **argv)
{
    int i;
    poller = new PortalPoller();
    IpcTestIndication ipcTestIndication(IfcNames_IpcTestIndicationH2S, poller);
    ipcTestRequestProxy = new IpcTestRequestProxy(IfcNames_IpcTestRequestS2H);
    pthread_mutex_lock(&mutex_heard);
    sem_init(&sem_heard, 0, 0);

    poller->start();

    run_test();
    printf("turn off printf in responder\n");
    silent = 1;
    for (i = 0; i < LOOP_COUNT; i++)
        run_test();
    printf("now try as mutex\n");
    use_mutex = 1;
    for (i = 0; i < LOOP_COUNT; i++)
        run_test();
    use_mutex = 0;

    struct sched_param sched_param;
    int sched_policy;
    pthread_getschedparam(pthread_self(), &sched_policy, &sched_param);
    sched_param.sched_priority = sched_get_priority_max(SCHED_RR);
    pthread_setschedparam(pthread_self(), SCHED_RR, &sched_param);
    printf("[%s:%d] scheduling policy changed to SCHED_RR\n", __FUNCTION__, __LINE__);
    for (i = 0; i < LOOP_COUNT; i++)
        run_test();
    printf("disable interrupts for ipcTestIndication\n");
    poller->stop();
    printf("now try inline\n");
    use_inline = 1;
    for (i = 0; i < LOOP_COUNT; i++)
        run_test();
printf("[%s:%d] end\n", __FUNCTION__, __LINE__);
    return 0;
}
Exemple #28
0
void *thread_func(void *arg)
{
	int rc;
	int new_policy;
	pthread_t self = pthread_self();

	struct sched_param param;
	memset(&param, 0, sizeof(param));

	rc = pthread_getschedparam(self, &new_policy, &param);
	if (rc != 0) {
		perror(ERROR_PREFIX "pthread_getschedparam");
		exit(PTS_UNRESOLVED);
	}
	if (new_policy == old_policy) {
		fprintf(stderr, ERROR_PREFIX "The scheduling attribute should "
			"not be inherited from creating thread \n");
		exit(PTS_FAIL);
	}
	pthread_exit(0);
	return NULL;
}
Exemple #29
0
static void showThreadInfo(epicsThreadOSD *pthreadInfo,unsigned int level)
{
    if(!pthreadInfo) {
        fprintf(epicsGetStdout(),"            NAME     EPICS ID   "
            "PTHREAD ID   OSIPRI  OSSPRI  STATE\n");
    } else {
        struct sched_param param;
        int policy;
        int priority = 0;

        if(pthreadInfo->tid) {
            int status;
            status = pthread_getschedparam(pthreadInfo->tid,&policy,&param);
            if(!status) priority = param.sched_priority;
        }
        fprintf(epicsGetStdout(),"%16.16s %12p %12lu    %3d%8d %8.8s\n",
             pthreadInfo->name,(void *)
             pthreadInfo,(unsigned long)pthreadInfo->tid,
             pthreadInfo->osiPriority,priority,
             pthreadInfo->isSuspended?"SUSPEND":"OK");
    }
}
bool GetThisThreadsPriority(int & Priority, int & MaxAllowed)
{
#ifdef WIN32
	Priority;
	MaxAllowed;
	std::cerr<<"MOOS::GetThisThreadsPriority is not supported in WIN32 (yet)\n";
	return false;
#else
	int policy;
	struct sched_param param;
	int max_priority;

	try
	{
		if(pthread_getschedparam(pthread_self(), &policy, &param)!=0)
		{
			throw std::runtime_error("MOOS::BoostThisThread() failed to get this thread's scheduling details");
		}

		if((max_priority = sched_get_priority_max(policy))==-1)
		{
			throw std::runtime_error("MOOS::BoostThisThread() failed to get this thread's max priority");
		}

	}
	catch(const std::runtime_error & e)
	{
		std::cerr<<e.what()<<" "<<strerror(errno)<<"\n";
		return false;
	}

	Priority = param.sched_priority;
	MaxAllowed = max_priority ;

	return true;
#endif

}