diff --git a/ChangeLog b/ChangeLog index a56cdeb..e62f1e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 0.5.5 ===== + 4-Apr-2004: - Realtime Scheduling for RTP proxy 3-Apr-2004: - fix: SDP 'c=' items in media part 2-Apr-2004: - PID file 31-Mar-2004: - accessctl.c: text correction in ERROR output diff --git a/config.h.in b/config.h.in index 923b548..062f8e5 100644 --- a/config.h.in +++ b/config.h.in @@ -84,12 +84,21 @@ /* Define if you have POSIX threads libraries and header files. */ #undef HAVE_PTHREAD +/* Define to 1 if you have the `pthread_setschedparam' function. */ +#undef HAVE_PTHREAD_SETSCHEDPARAM + /* Define to 1 if you have the header file. */ #undef HAVE_PWD_H /* Define to 1 if you have the `read' function. */ #undef HAVE_READ +/* Define to 1 if you have the `sched_get_priority_max' function. */ +#undef HAVE_SCHED_GET_PRIORITY_MAX + +/* Define to 1 if you have the `sched_get_priority_min' function. */ +#undef HAVE_SCHED_GET_PRIORITY_MIN + /* Define to 1 if you have the `select' function. */ #undef HAVE_SELECT diff --git a/configure.in b/configure.in index 5c9a925..da25ec6 100644 --- a/configure.in +++ b/configure.in @@ -335,6 +335,9 @@ AC_CHECK_FUNCS(hstrerror,,AC_CHECK_LIB(resolv,hstrerror,[ AC_DEFINE_UNQUOTED(HAVE_HSTRERROR) LIBS="$LIBS -lresolv"])) AC_CHECK_FUNCS(inet_pton inet_ntop inet_aton inet_ntoa) +AC_CHECK_FUNCS(pthread_setschedparam sched_get_priority_min) +AC_CHECK_FUNCS(sched_get_priority_max) + dnl diff --git a/src/rtpproxy_relay.c b/src/rtpproxy_relay.c index dbc22a9..9d6362e 100644 --- a/src/rtpproxy_relay.c +++ b/src/rtpproxy_relay.c @@ -9,7 +9,7 @@ (at your option) any later version. Siproxd is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of + but WITHOUT ANY WARRANTY; without even the implied warrantry of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -32,6 +32,10 @@ #include #include +#ifdef HAVE_PTHREAD_SETSCHEDPARAM + #include +#endif + #include #include "siproxd.h" @@ -103,6 +107,35 @@ int rtp_relay_init( void ) { sts=pthread_create(&rtpproxy_tid, NULL, rtpproxy_main, (void *)&arg); DEBUGC(DBCLASS_RTP,"created, sts=%i", sts); + /* set realtime scheduling - if started by root */ +#ifdef HAVE_PTHREAD_SETSCHEDPARAM + { + int uid,euid; + struct sched_param schedparam; + + uid=getuid(); + euid=geteuid(); + if (uid != euid) seteuid(0); + + if (geteuid()==0) { + int pmin, pmax; + /* place ourself at 1/3 of the available priority space */ + pmin=sched_get_priority_min(SCHED_RR); + pmax=sched_get_priority_max(SCHED_RR); + schedparam.sched_priority=pmin+(pmax-pmin)/3; + DEBUGC(DBCLASS_RTP,"pmin=%i, pmax=%i, using p=%i", pmin, pmax, + schedparam.sched_priority); + sts=pthread_setschedparam(rtpproxy_tid, SCHED_RR, &schedparam); + if (sts != 0) { + ERROR("pthread_setschedparam failed: %s", strerror(errno)); + } + } else { + WARN("Cannot set realtime scheduling for RTP (start siproxd as root)"); + } + if (uid != euid) seteuid(euid); + } +#endif + return STS_SUCCESS; }