split out ARDOUR::how_many_dsp_threads() ; fix test for whether to use use route_grap...
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 9 Feb 2011 02:41:01 +0000 (02:41 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 9 Feb 2011 02:41:01 +0000 (02:41 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@8793 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/graph.h
libs/ardour/ardour/utils.h
libs/ardour/graph.cc
libs/ardour/session_process.cc
libs/ardour/utils.cc

index 798483943140c4eb090e99c8a5eca3b9d152b1b7..a3f1523b1511e287663312daab926ed82608754e 100644 (file)
@@ -58,6 +58,8 @@ class Graph : public SessionHandleRef
     public:
        Graph (Session & session);
 
+        uint32_t threads_in_use () const { return _thread_list.size(); }
+
        void prep();
        void trigger (GraphNode * n);
        void rechain (boost::shared_ptr<RouteList> r);
index 0b3fbc7b6c12b30077c8d7caaaca9c5698022cb8..dac4086cba46b9d61c95a51ba8aedc9f13f4f3b4 100644 (file)
@@ -107,6 +107,8 @@ float meter_falloff_to_db_per_sec (float);
 const char* native_header_format_extension (ARDOUR::HeaderFormat, const ARDOUR::DataType& type);
 bool matching_unsuffixed_filename_exists_in (const std::string& dir, const std::string& name);
 
+uint32_t how_many_dsp_threads ();
+
 #if __APPLE__
 std::string CFStringRefToStdString(CFStringRef stringRef);
 #endif // __APPLE__
index 6fb9305d20f0e78b2db96694d15bc04894d6cc04..2ac465f1e97ffaeab447427807bd607419019271 100644 (file)
@@ -21,7 +21,6 @@
 #include <cmath>
 
 #include "pbd/compose.h"
-#include "pbd/cpus.h"
 #include "pbd/debug_rt_alloc.h"
 
 #include "ardour/debug.h"
@@ -96,40 +95,29 @@ Graph::parameter_changed (std::string param)
 void
 Graph::reset_thread_list ()
 {
-        int num_cpu = hardware_concurrency();
-        int pu = Config->get_processor_usage ();
-       pthread_t a_thread;
-        uint32_t num_threads = max (num_cpu - 1, 2); // default to number of cpus minus one, or 2, whichever is larger
-
-        if (pu < 0) {
-                /* pu is negative: use "pu" less cores for DSP than appear to be available
-                 */
-
-                if (-pu < num_cpu) {
-                        num_threads = num_cpu + pu;
-                }
-
-        } else if (pu == 0) {
+        uint32_t num_threads = how_many_dsp_threads ();
 
-                num_threads = num_cpu;
-
-        } else {
-                /* use "pu" cores, if available
-                 */
-                
-                num_threads = min (num_cpu, pu);
-        }
+        /* don't bother doing anything here if we already have the right
+           number of threads.
+        */
 
         if (_thread_list.size() == num_threads) {
                 return;
         }
 
         Glib::Mutex::Lock lm (_session.engine().process_lock());
+       pthread_t a_thread;
 
         if (!_thread_list.empty()) {
                 drop_threads ();
         }
 
+        if (num_threads <= 1) {
+                /* no point creating 1 thread - the AudioEngine already gives us one
+                 */
+                return;
+        }
+
        if (AudioEngine::instance()->create_process_thread (boost::bind (&Graph::main_thread, this), &a_thread, 100000) == 0) {
                _thread_list.push_back (a_thread);
        }
@@ -139,9 +127,6 @@ Graph::reset_thread_list ()
                        _thread_list.push_back (a_thread);
                }
         }
-
-        info << string_compose (_("Using %1 threads for DSP on %2 CPUs"), _thread_list.size(), num_cpu) << endmsg;
-        cerr << string_compose (_("Using %1 threads for DSP on %2 CPUs"), _thread_list.size(), num_cpu) << endl;
 }
 
 void
index 61c35da4808ef4a656f9b08c77baefd212906251..2c41594d219d514e474b8335e3b82a5f4120c103 100644 (file)
@@ -106,7 +106,7 @@ Session::no_roll (pframes_t nframes)
                _click_io->silence (nframes);
        }
 
-        if (Config->get_processor_usage() != 1) {
+        if (route_graph->threads_in_use() > 1) {
                 DEBUG_TRACE(DEBUG::Graph,"calling graph/no-roll\n");
                 route_graph->routes_no_roll( nframes, _transport_frame, end_frame, non_realtime_work_pending(), actively_recording(), declick);
         } else {
@@ -148,10 +148,9 @@ Session::process_routes (pframes_t nframes, bool& need_butler)
         const framepos_t start_frame = _transport_frame;
         const framepos_t end_frame = _transport_frame + floor (nframes * _transport_speed);
         
-        if (Config->get_processor_usage() != 1) {
+        if (route_graph->threads_in_use() > 1) {
                 DEBUG_TRACE(DEBUG::Graph,"calling graph/process-routes\n");
                 route_graph->process_routes( nframes, start_frame, end_frame, declick, record_active, rec_monitors, need_butler);
-
         } else {
 
                 for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
@@ -190,8 +189,7 @@ Session::silent_process_routes (pframes_t nframes, bool& need_butler)
        const framepos_t start_frame = _transport_frame;
        const framepos_t end_frame = _transport_frame + lrintf(nframes * _transport_speed);
 
-        if (Config->get_processor_usage() != 1) {
-                cerr << "GRAPH PROCESS\n";
+        if (route_graph->threads_in_use() > 1) {
                 route_graph->silent_process_routes( nframes, start_frame, end_frame, record_active, rec_monitors, need_butler);
         } else {
                 for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
index f9d16a47b49050ff9c661838d0896ae8e88a7cc3..b19aad4fa92785fea0739571bb21996109e48e97 100644 (file)
 #include <wordexp.h>
 #endif
 
+#include "pbd/cpus.h"
 #include "pbd/error.h"
 #include "pbd/stacktrace.h"
 #include "pbd/xml++.h"
 #include "pbd/basename.h"
 #include "pbd/strsplit.h"
+
 #include "ardour/utils.h"
+#include "ardour/rc_configuration.h"
 
 #include "i18n.h"
 
@@ -651,6 +654,38 @@ matching_unsuffixed_filename_exists_in (const string& dir, const string& path)
         return ret;
 }
 
+uint32_t
+how_many_dsp_threads ()
+{
+        int num_cpu = hardware_concurrency();
+        int pu = Config->get_processor_usage ();
+        uint32_t num_threads = max (num_cpu - 1, 2); // default to number of cpus minus one, or 2, whichever is larger
+
+        if (pu < 0) {
+                /* pu is negative: use "pu" less cores for DSP than appear to be available
+                 */
+
+                if (-pu < num_cpu) {
+                        num_threads = num_cpu + pu;
+                }
+
+        } else if (pu == 0) {
+
+                /* use all available CPUs 
+                 */
+                
+                num_threads = num_cpu;
+
+        } else {
+                /* use "pu" cores, if available
+                 */
+                
+                num_threads = min (num_cpu, pu);
+        }
+
+        return num_threads;
+}
+
 extern "C" {
        void c_stacktrace() { stacktrace (cerr); }
 }