From 3faf95913da623c030ceac66f74f1e1664666e01 Mon Sep 17 00:00:00 2001 From: Sebastian Wilhelmi Date: Tue, 6 Aug 2002 13:31:26 +0000 Subject: [PATCH] Set the normal PID surrogate priority according to getpid() to avoid 2002-08-06 Sebastian Wilhelmi * glib/gthread.c: Set the normal PID surrogate priority according to getpid() to avoid errors for niced processes. (#86116) * gthread/gthread-impl.c, gthread/gthread-posix.c, gthread/gthread-solaris.c: Do the same for the posix/dce implementation. Solaris still needs to set priority of the main thread, because all unbound threads will schedule according to that value and it defaults to 0 (the minimal value). --- ChangeLog | 11 +++++++++++ ChangeLog.pre-2-10 | 11 +++++++++++ ChangeLog.pre-2-12 | 11 +++++++++++ ChangeLog.pre-2-2 | 11 +++++++++++ ChangeLog.pre-2-4 | 11 +++++++++++ ChangeLog.pre-2-6 | 11 +++++++++++ ChangeLog.pre-2-8 | 11 +++++++++++ glib/gthread.c | 13 ++++++++++++- gthread/gthread-impl.c | 11 ++++------- gthread/gthread-posix.c | 27 +++++++++++++++++++++++---- gthread/gthread-solaris.c | 3 +++ 11 files changed, 119 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 90b6293..ecf5b10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2002-08-06 Sebastian Wilhelmi + + * glib/gthread.c: Set the normal PID surrogate priority according + to getpid() to avoid errors for niced processes. (#86116) + + * gthread/gthread-impl.c, gthread/gthread-posix.c, + gthread/gthread-solaris.c: Do the same for the posix/dce + implementation. Solaris still needs to set priority of the main + thread, because all unbound threads will schedule according to + that value and it defaults to 0 (the minimal value). + Thu Jul 25 14:23:15 2002 Owen Taylor * glib/gfileutils.c: Clarify the behavior of g_build_path() diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 90b6293..ecf5b10 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,14 @@ +2002-08-06 Sebastian Wilhelmi + + * glib/gthread.c: Set the normal PID surrogate priority according + to getpid() to avoid errors for niced processes. (#86116) + + * gthread/gthread-impl.c, gthread/gthread-posix.c, + gthread/gthread-solaris.c: Do the same for the posix/dce + implementation. Solaris still needs to set priority of the main + thread, because all unbound threads will schedule according to + that value and it defaults to 0 (the minimal value). + Thu Jul 25 14:23:15 2002 Owen Taylor * glib/gfileutils.c: Clarify the behavior of g_build_path() diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 90b6293..ecf5b10 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,14 @@ +2002-08-06 Sebastian Wilhelmi + + * glib/gthread.c: Set the normal PID surrogate priority according + to getpid() to avoid errors for niced processes. (#86116) + + * gthread/gthread-impl.c, gthread/gthread-posix.c, + gthread/gthread-solaris.c: Do the same for the posix/dce + implementation. Solaris still needs to set priority of the main + thread, because all unbound threads will schedule according to + that value and it defaults to 0 (the minimal value). + Thu Jul 25 14:23:15 2002 Owen Taylor * glib/gfileutils.c: Clarify the behavior of g_build_path() diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 90b6293..ecf5b10 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,14 @@ +2002-08-06 Sebastian Wilhelmi + + * glib/gthread.c: Set the normal PID surrogate priority according + to getpid() to avoid errors for niced processes. (#86116) + + * gthread/gthread-impl.c, gthread/gthread-posix.c, + gthread/gthread-solaris.c: Do the same for the posix/dce + implementation. Solaris still needs to set priority of the main + thread, because all unbound threads will schedule according to + that value and it defaults to 0 (the minimal value). + Thu Jul 25 14:23:15 2002 Owen Taylor * glib/gfileutils.c: Clarify the behavior of g_build_path() diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 90b6293..ecf5b10 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,14 @@ +2002-08-06 Sebastian Wilhelmi + + * glib/gthread.c: Set the normal PID surrogate priority according + to getpid() to avoid errors for niced processes. (#86116) + + * gthread/gthread-impl.c, gthread/gthread-posix.c, + gthread/gthread-solaris.c: Do the same for the posix/dce + implementation. Solaris still needs to set priority of the main + thread, because all unbound threads will schedule according to + that value and it defaults to 0 (the minimal value). + Thu Jul 25 14:23:15 2002 Owen Taylor * glib/gfileutils.c: Clarify the behavior of g_build_path() diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 90b6293..ecf5b10 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,14 @@ +2002-08-06 Sebastian Wilhelmi + + * glib/gthread.c: Set the normal PID surrogate priority according + to getpid() to avoid errors for niced processes. (#86116) + + * gthread/gthread-impl.c, gthread/gthread-posix.c, + gthread/gthread-solaris.c: Do the same for the posix/dce + implementation. Solaris still needs to set priority of the main + thread, because all unbound threads will schedule according to + that value and it defaults to 0 (the minimal value). + Thu Jul 25 14:23:15 2002 Owen Taylor * glib/gfileutils.c: Clarify the behavior of g_build_path() diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 90b6293..ecf5b10 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,14 @@ +2002-08-06 Sebastian Wilhelmi + + * glib/gthread.c: Set the normal PID surrogate priority according + to getpid() to avoid errors for niced processes. (#86116) + + * gthread/gthread-impl.c, gthread/gthread-posix.c, + gthread/gthread-solaris.c: Do the same for the posix/dce + implementation. Solaris still needs to set priority of the main + thread, because all unbound threads will schedule according to + that value and it defaults to 0 (the minimal value). + Thu Jul 25 14:23:15 2002 Owen Taylor * glib/gfileutils.c: Clarify the behavior of g_build_path() diff --git a/glib/gthread.c b/glib/gthread.c index 15cb97b..e06fc28 100644 --- a/glib/gthread.c +++ b/glib/gthread.c @@ -88,7 +88,7 @@ struct _GRealThread }; #ifdef G_THREAD_USE_PID_SURROGATE -static gint priority_map[] = { 15, 0, -15, -20 }; +static gint priority_map[4]; static gboolean prio_warned = FALSE; # define SET_PRIO(pid, prio) G_STMT_START{ \ gint error = setpriority (PRIO_PROCESS, (pid), priority_map[prio]); \ @@ -171,6 +171,17 @@ g_mutex_init (void) G_THREAD_UF (thread_self, (&main_thread->system_thread)); g_mutex_protect_static_mutex_allocation = g_mutex_new (); + +#ifdef G_THREAD_USE_PID_SURROGATE + priority_map[G_THREAD_PRIORITY_NORMAL] = + getpriority (PRIO_PROCESS, (getpid ())); + priority_map[G_THREAD_PRIORITY_LOW] = + MIN (20, priority_map[G_THREAD_PRIORITY_NORMAL] + 10); + priority_map[G_THREAD_PRIORITY_HIGH] = + MAX (-20, priority_map[G_THREAD_PRIORITY_NORMAL] - 10); + priority_map[G_THREAD_PRIORITY_URGENT] = + MAX (-20, priority_map[G_THREAD_PRIORITY_NORMAL] - 15); +#endif /* G_THREAD_USE_PID_SURROGATE */ } void diff --git a/gthread/gthread-impl.c b/gthread/gthread-impl.c index 24105a3..1ea464d 100644 --- a/gthread/gthread-impl.c +++ b/gthread/gthread-impl.c @@ -53,13 +53,13 @@ static gint g_thread_priority_map [G_THREAD_PRIORITY_URGENT + 1]; #endif #ifndef PRIORITY_NORMAL_VALUE -# define PRIORITY_NORMAL_VALUE \ - (PRIORITY_LOW_VALUE + (PRIORITY_URGENT_VALUE - PRIORITY_LOW_VALUE) * 4 / 10) +# define PRIORITY_NORMAL_VALUE \ + ((PRIORITY_LOW_VALUE * 6 + PRIORITY_URGENT_VALUE * 4) / 10) #endif /* PRIORITY_NORMAL_VALUE */ #ifndef PRIORITY_HIGH_VALUE -# define PRIORITY_HIGH_VALUE \ - (PRIORITY_LOW_VALUE + (PRIORITY_URGENT_VALUE - PRIORITY_LOW_VALUE) * 8 / 10) +# define PRIORITY_HIGH_VALUE \ + ((PRIORITY_NORMAL_VALUE + PRIORITY_URGENT_VALUE * 2) / 3) #endif /* PRIORITY_HIGH_VALUE */ void g_mutex_init (void); @@ -386,9 +386,6 @@ g_thread_init (GThreadFunctions* init) * all the thread functions */ g_threads_got_initialized = TRUE; - - /* we want the main thread to run with normal priority */ - g_thread_set_priority (g_thread_self(), G_THREAD_PRIORITY_NORMAL); } #else /* !G_THREADS_ENABLED */ diff --git a/gthread/gthread-posix.c b/gthread/gthread-posix.c index 4df20b5..f680cc1 100644 --- a/gthread/gthread-posix.c +++ b/gthread/gthread-posix.c @@ -97,6 +97,7 @@ static gboolean posix_check_cmd_prio_warned = FALSE; #if defined (POSIX_MIN_PRIORITY) && defined (POSIX_MAX_PRIORITY) # define HAVE_PRIORITIES 1 +static gint priority_normal_value; # ifdef __FreeBSD__ /* FreeBSD threads use different priority values from the POSIX_ * defines so we just set them here. The corresponding macros @@ -106,23 +107,41 @@ static gboolean posix_check_cmd_prio_warned = FALSE; # define PRIORITY_LOW_VALUE 0 # define PRIORITY_URGENT_VALUE 31 # else /* !__FreeBSD__ */ -# define PRIORITY_LOW_VALUE POSIX_MIN_PRIORITY -# define PRIORITY_URGENT_VALUE POSIX_MAX_PRIORITY +# define PRIORITY_LOW_VALUE POSIX_MIN_PRIORITY +# define PRIORITY_URGENT_VALUE POSIX_MAX_PRIORITY # endif /* !__FreeBSD__ */ +# define PRIORITY_NORMAL_VALUE priority_normal_value #endif /* POSIX_MIN_PRIORITY && POSIX_MAX_PRIORITY */ static gulong g_thread_min_stack_size = 0; #define G_MUTEX_SIZE (sizeof (pthread_mutex_t)) -#ifdef _SC_THREAD_STACK_MIN +#if defined(_SC_THREAD_STACK_MIN) || defined (HAVE_PRIORITIES) #define HAVE_G_THREAD_IMPL_INIT static void g_thread_impl_init() { +#ifdef _SC_THREAD_STACK_MIN g_thread_min_stack_size = MAX (sysconf (_SC_THREAD_STACK_MIN), 0); -} #endif /* _SC_THREAD_STACK_MIN */ +#ifdef HAVE_PRIORITIES +# ifdef G_THREADS_IMPL_POSIX + { + struct sched_param sched; + int policy; + posix_check_cmd (pthread_getschedparam (pthread_self(), &policy, &sched)); + priority_normal_value = sched.sched_priority; + } +# else /* G_THREADS_IMPL_DCE */ + posix_check_cmd (priority_normal_value = + pthread_getprio (*(pthread_t*)thread, + g_thread_priority_map [priority])); +# endif +#endif /* HAVE_PRIORITIES */ + +} +#endif /* _SC_THREAD_STACK_MIN || HAVE_PRIORITIES */ static GMutex * g_mutex_new_posix_impl (void) diff --git a/gthread/gthread-solaris.c b/gthread/gthread-solaris.c index c86c5bd..b9b7ab1 100644 --- a/gthread/gthread-solaris.c +++ b/gthread/gthread-solaris.c @@ -54,6 +54,7 @@ static gulong g_thread_min_stack_size = 0; #define G_MUTEX_SIZE (sizeof (mutex_t)) #define PRIORITY_LOW_VALUE 0 +#define PRIORITY_NORMAL_VALUE 50 #define PRIORITY_URGENT_VALUE 127 #define HAVE_G_THREAD_IMPL_INIT @@ -61,6 +62,8 @@ static void g_thread_impl_init() { g_thread_min_stack_size = thr_min_stack(); + /* The default priority on Solaris is 0. Set it to something sane */ + solaris_check_for_error (thr_setprio (thr_self (), PRIORITY_NORMAL_VALUE)); } static GMutex * -- 2.7.4