胡斌

add root directive cpu_affinity, to set the cpu affinity of srs

... ... @@ -65,6 +65,9 @@ asprocess off;
# whether using build-in speex to aac transcoding
# default: off
speex2aac off;
# set cpu affinity,the index of the cpu core,0,1,2,...
# default -1,don't set affinity
cpu_affinity -1;
#############################################################################################
# heartbeat/stats sections
... ...
... ... @@ -47,6 +47,10 @@ using namespace std;
#include <srs_app_utility.hpp>
#include <srs_core_performance.hpp>
#include "../../objs/version.h"
#ifndef __USE_GNU
#define __USE_GNU
#endif
#include<sched.h>
using namespace _srs_internal;
... ... @@ -1007,8 +1011,6 @@ int SrsConfig::reload_conf(SrsConfig* conf)
return ret;
}
set_config_static();
return ret;
}
... ... @@ -1584,6 +1586,7 @@ int SrsConfig::check_config()
&& n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms"
&& n != "http_stream" && n != "http_server" && n != "stream_caster"
&& n != "utc_time" && n != "work_dir" && n != "asprocess" && n != "speex2aac"
&& n != "cpu_affinity"
) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported directive %s, ret=%d", n.c_str(), ret);
... ... @@ -2102,7 +2105,23 @@ void SrsConfig::set_config_static()
}
else
_speex2aac = false;
conf = root->get("cpu_affinity");
int cpu_index = -1;
if(conf){
cpu_index = atoi(conf->arg0().c_str());
}
if(cpu_index >= 0){
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(cpu_index, &mask);
if (sched_setaffinity(0, sizeof(mask), &mask) == -1){
srs_error("error when set cpu affinity to CPU:%d",cpu_index);
}
else{
srs_trace("success in set cpu affinity to CPU:%d",cpu_index);
}
}
}
int SrsConfig::parse_buffer(SrsConfigBuffer* buffer)
... ...