From b48de00cfefac61414b0ea568e5014f2794e50cd Mon Sep 17 00:00:00 2001 From: jcorgan Date: Fri, 20 Jun 2008 18:14:47 +0000 Subject: [PATCH] Merged -r8639:8641 from jcorgan/gruel into trunk. Adds libgruel, the GNU Radio Utility Etcetera Library. See README for description. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8642 221aa14e-8319-0410-a670-987f0aec2ac5 --- Makefile.common | 4 + config/Makefile.am | 1 + config/grc_gruel.m4 | 44 +++++++++++ configure.ac | 1 + gruel/AUTHORS | 1 + gruel/ChangeLog | 20 +++++ gruel/Makefile.am | 30 ++++++++ gruel/README | 30 ++++++++ gruel/gruel.pc.in | 11 +++ gruel/src/Makefile.am | 22 ++++++ gruel/src/include/Makefile.am | 22 ++++++ gruel/src/include/gruel/Makefile.am | 27 +++++++ gruel/src/include/gruel/realtime.h | 44 +++++++++++ gruel/src/lib/Makefile.am | 39 ++++++++++ gruel/src/lib/realtime.cc | 112 ++++++++++++++++++++++++++++ 15 files changed, 408 insertions(+) create mode 100644 config/grc_gruel.m4 create mode 100644 gruel/AUTHORS create mode 100644 gruel/ChangeLog create mode 100644 gruel/Makefile.am create mode 100644 gruel/README create mode 100644 gruel/gruel.pc.in create mode 100644 gruel/src/Makefile.am create mode 100644 gruel/src/include/Makefile.am create mode 100644 gruel/src/include/gruel/Makefile.am create mode 100644 gruel/src/include/gruel/realtime.h create mode 100644 gruel/src/lib/Makefile.am create mode 100644 gruel/src/lib/realtime.cc diff --git a/Makefile.common b/Makefile.common index 0ee6f2bf..a4a3139c 100644 --- a/Makefile.common +++ b/Makefile.common @@ -72,6 +72,10 @@ GNURADIO_CORE_LA = @gnuradio_core_LA@ # This is a dependency for many swig operations GNURADIO_I = @gnuradio_core_I@ +# How to link in the USRP library from inside the tree +GRUEL_INCLUDES = @gruel_INCLUDES@ +GRUEL_LA = @gruel_LA@ + # How to link in the USRP library from inside the tree USRP_INCLUDES = @usrp_INCLUDES@ USRP_LA = @usrp_LA@ diff --git a/config/Makefile.am b/config/Makefile.am index 4e87bc45..310568bf 100644 --- a/config/Makefile.am +++ b/config/Makefile.am @@ -53,6 +53,7 @@ m4macros = \ grc_gr_video_sdl.m4 \ grc_gr_wxgui.m4 \ grc_mblock.m4 \ + grc_gruel.m4 \ gr_check_createfilemapping.m4 \ gr_check_mc4020.m4 \ gr_check_shm_open.m4 \ diff --git a/config/grc_gruel.m4 b/config/grc_gruel.m4 new file mode 100644 index 00000000..81f53ce1 --- /dev/null +++ b/config/grc_gruel.m4 @@ -0,0 +1,44 @@ +dnl Copyright 2001,2002,2003,2004,2005,2006,2008 Free Software Foundation, Inc. +dnl +dnl This file is part of GNU Radio +dnl +dnl GNU Radio is free software; you can redistribute it and/or modify +dnl it under the terms of the GNU General Public License as published by +dnl the Free Software Foundation; either version 3, or (at your option) +dnl any later version. +dnl +dnl GNU Radio is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +dnl GNU General Public License for more details. +dnl +dnl You should have received a copy of the GNU General Public License +dnl along with GNU Radio; see the file COPYING. If not, write to +dnl the Free Software Foundation, Inc., 51 Franklin Street, +dnl Boston, MA 02110-1301, USA. + +AC_DEFUN([GRC_GRUEL],[ + GRC_ENABLE(gruel) + GRC_WITH(gruel) + + dnl If execution gets to here, $passed will be: + dnl with : if the --with code didn't error out + dnl yes : if the --enable code passed muster and all dependencies are met + dnl no : otherwise + if test $passed != with; then + dnl how and where to find INCLUDES and LA + gruel_INCLUDES="-I\${abs_top_srcdir}/gruel/src/include" + gruel_LA="\${abs_top_builddir}/gruel/src/lib/libgruel.la" + fi + + AC_CONFIG_FILES([\ + gruel/Makefile \ + gruel/gruel.pc \ + gruel/src/Makefile \ + gruel/src/include/Makefile \ + gruel/src/include/gruel/Makefile \ + gruel/src/lib/Makefile \ + ]) + + GRC_BUILD_CONDITIONAL(gruel,[]) +]) diff --git a/configure.ac b/configure.ac index 9160b4ca..f20ca9e4 100644 --- a/configure.ac +++ b/configure.ac @@ -239,6 +239,7 @@ AC_ARG_ENABLE( ) build_dirs="config" +GRC_GRUEL dnl must come first GRC_OMNITHREAD dnl must come before gnuradio-core and mblock GRC_GCELL GRC_GNURADIO_CORE diff --git a/gruel/AUTHORS b/gruel/AUTHORS new file mode 100644 index 00000000..18e03c4a --- /dev/null +++ b/gruel/AUTHORS @@ -0,0 +1 @@ +Johnathan Corgan diff --git a/gruel/ChangeLog b/gruel/ChangeLog new file mode 100644 index 00000000..b185665e --- /dev/null +++ b/gruel/ChangeLog @@ -0,0 +1,20 @@ +# +# Copyright 2008 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# diff --git a/gruel/Makefile.am b/gruel/Makefile.am new file mode 100644 index 00000000..93f56a7d --- /dev/null +++ b/gruel/Makefile.am @@ -0,0 +1,30 @@ +# +# Copyright 2008 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +include $(top_srcdir)/Makefile.common + +EXTRA_DIST = \ + gruel.pc.in + +SUBDIRS = src + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = gruel.pc diff --git a/gruel/README b/gruel/README new file mode 100644 index 00000000..585cf026 --- /dev/null +++ b/gruel/README @@ -0,0 +1,30 @@ +# +# Copyright 2008 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +The GNU Radio Utility Etcetera Library, a collection of low-level routines +to avoid dependencies on the full GNU Radio core or other libraries. + +Over time, some code from libgnuradio-core, libpmt, libmblock, libusrp, +and libusrp2 will migrate here, to avoid duplication of code and simplify +dependencies. + +By design, this library will not have dependencies on any other part +of GNU Radio, but may have external dependencies such as Boost. diff --git a/gruel/gruel.pc.in b/gruel/gruel.pc.in new file mode 100644 index 00000000..6377f5bb --- /dev/null +++ b/gruel/gruel.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: gruel +Description: The GNU Radio Utility Etcetera Library +Requires: +Version: @VERSION@ +Libs: -L${libdir} -lgruel +Cflags: -I${includedir} diff --git a/gruel/src/Makefile.am b/gruel/src/Makefile.am new file mode 100644 index 00000000..90c0f88b --- /dev/null +++ b/gruel/src/Makefile.am @@ -0,0 +1,22 @@ +# +# Copyright 2008 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +SUBDIRS = include lib diff --git a/gruel/src/include/Makefile.am b/gruel/src/include/Makefile.am new file mode 100644 index 00000000..7a178810 --- /dev/null +++ b/gruel/src/include/Makefile.am @@ -0,0 +1,22 @@ +# +# Copyright 2008 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +SUBDIRS = gruel diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am new file mode 100644 index 00000000..8ea484ce --- /dev/null +++ b/gruel/src/include/gruel/Makefile.am @@ -0,0 +1,27 @@ +# +# Copyright 2008 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +include $(top_srcdir)/Makefile.common + +gruelincludedir = $(prefix)/include/gruel + +gruelinclude_HEADERS = \ + realtime.h diff --git a/gruel/src/include/gruel/realtime.h b/gruel/src/include/gruel/realtime.h new file mode 100644 index 00000000..ded70ed0 --- /dev/null +++ b/gruel/src/include/gruel/realtime.h @@ -0,0 +1,44 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_REALTIME_H +#define INCLUDED_REALTIME_H + +namespace gruel { + + typedef enum { + RT_OK = 0, + RT_NOT_IMPLEMENTED, + RT_NO_PRIVS, + RT_OTHER_ERROR + } rt_status_t; + + /*! + * \brief If possible, enable high-priority "real time" scheduling. + * \ingroup misc + */ + rt_status_t + enable_realtime_scheduling(); + +} // namespace gruel + +#endif /* INCLUDED_GR_REALTIME_H */ diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am new file mode 100644 index 00000000..972ff4ca --- /dev/null +++ b/gruel/src/lib/Makefile.am @@ -0,0 +1,39 @@ +# +# Copyright 2008 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +include $(top_srcdir)/Makefile.common + +AM_CPPFLAGS = $(DEFINES) $(BOOST_CFLAGS) $(GRUEL_INCLUDES) $(WITH_INCLUDES) + +lib_LTLIBRARIES = libgruel.la + +# These are the source files that go into the gruel shared library +libgruel_la_SOURCES = \ + realtime.cc + +# magic flags +libgruel_la_LDFLAGS = $(NO_UNDEFINED) + +# link the library against the c++ standard library +libgruel_la_LIBADD = \ + -lstdc++ + +noinst_HEADERS = diff --git a/gruel/src/lib/realtime.cc b/gruel/src/lib/realtime.cc new file mode 100644 index 00000000..bdcb31ab --- /dev/null +++ b/gruel/src/lib/realtime.cc @@ -0,0 +1,112 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2007 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#ifdef HAVE_SCHED_H +#include +#endif + +#include +#include +#include + +#if defined(HAVE_SCHED_SETSCHEDULER) + +namespace gruel { + + rt_status_t + enable_realtime_scheduling() + { + int policy = SCHED_FIFO; + int pri = (sched_get_priority_max (policy) + sched_get_priority_min (policy)) / 2; + int pid = 0; // this process + + struct sched_param param; + memset(¶m, 0, sizeof(param)); + param.sched_priority = pri; + int result = sched_setscheduler(pid, policy, ¶m); + if (result != 0){ + if (errno == EPERM) + return RT_NO_PRIVS; + else { + perror ("sched_setscheduler: failed to set real time priority"); + return RT_OTHER_ERROR; + } + } + + //printf("SCHED_FIFO enabled with priority = %d\n", pri); + return RT_OK; + } + +} // namespace gruel + +#elif defined(HAVE_PTHREAD_SETSCHEDPARAM) + +#include +#include + +namespace gruel { + + rt_status_t + enable_realtime_scheduling() + { + int policy = SCHED_FIFO; + int pri = (sched_get_priority_max (policy) + + sched_get_priority_min (policy)) / 2; + pthread_t this_thread = pthread_self (); // this process + struct sched_param param; + memset (¶m, 0, sizeof (param)); + param.sched_priority = pri; + int result = pthread_setschedparam (this_thread, policy, ¶m); + if (result != 0) { + if (errno == EPERM) + return RT_NO_PRIVS; + else { + perror ("pthread_setschedparam: failed to set real time priority"); + return RT_OTHER_ERROR; + } + } + + //printf("SCHED_FIFO enabled with priority = %d\n", pri); + return RT_OK; + } +} // namespace gruel + +// #elif // could try negative niceness + +#else + +namespace gruel { + + rt_status_t + enable_realtime_scheduling() + { + return RT_NOT_IMPLEMENTED; + } +} // namespace gruel + +#endif -- 2.30.2