Add a command line option (-n) to use native threading, for testing.

I added this to test the impact of green threading.
This commit is contained in:
Brian Anderson 2014-06-05 10:42:52 -07:00
parent b6c9b65355
commit e783666a19
3 changed files with 45 additions and 27 deletions

View file

@ -59,6 +59,7 @@ pub extern "C" fn cef_run_message_loop() {
headless: false, headless: false,
hard_fail: false, hard_fail: false,
bubble_widths_separately: false, bubble_widths_separately: false,
native_threading: false
}; };
native::start(0, 0 as **u8, proc() { native::start(0, 0 as **u8, proc() {
servo::run(opts); servo::run(opts);

View file

@ -51,23 +51,15 @@ extern crate core_graphics;
#[cfg(target_os="macos")] #[cfg(target_os="macos")]
extern crate core_text; extern crate core_text;
#[cfg(not(test))]
use compositing::{CompositorChan, CompositorTask}; use compositing::{CompositorChan, CompositorTask};
#[cfg(not(test))]
use constellation::Constellation; use constellation::Constellation;
#[cfg(not(test))]
use servo_msg::constellation_msg::{ConstellationChan, InitLoadUrlMsg}; use servo_msg::constellation_msg::{ConstellationChan, InitLoadUrlMsg};
#[cfg(not(test))]
use servo_net::image_cache_task::{ImageCacheTask, SyncImageCacheTask}; use servo_net::image_cache_task::{ImageCacheTask, SyncImageCacheTask};
#[cfg(not(test))]
use servo_net::resource_task::ResourceTask; use servo_net::resource_task::ResourceTask;
#[cfg(not(test))]
use servo_util::time::Profiler; use servo_util::time::Profiler;
#[cfg(not(test))]
use servo_util::opts; use servo_util::opts;
#[cfg(not(test))]
use servo_util::url::parse_url; use servo_util::url::parse_url;
@ -75,9 +67,7 @@ use servo_util::url::parse_url;
use std::os; use std::os;
#[cfg(not(test), target_os="android")] #[cfg(not(test), target_os="android")]
use std::str; use std::str;
#[cfg(not(test))]
use std::task::TaskOpts; use std::task::TaskOpts;
#[cfg(not(test))]
use url::Url; use url::Url;
@ -161,12 +151,42 @@ pub extern "C" fn android_start(argc: int, argv: **u8) -> int {
}) })
} }
#[cfg(not(test))] fn spawn_main(opts: opts::Opts,
pub fn run(opts: opts::Opts) { compositor_port: Receiver<compositing::Msg>,
profiler_chan: servo_util::time::ProfilerChan,
result_port: Receiver<ConstellationChan>,
p: proc(): Send) {
if !opts.native_threading {
let mut pool_config = green::PoolConfig::new(); let mut pool_config = green::PoolConfig::new();
pool_config.event_loop_factory = rustuv::event_loop; pool_config.event_loop_factory = rustuv::event_loop;
let mut pool = green::SchedPool::new(pool_config); let mut pool = green::SchedPool::new(pool_config);
pool.spawn(TaskOpts::new(), p);
let constellation_chan = result_port.recv();
debug!("preparing to enter main loop");
CompositorTask::create(opts,
compositor_port,
constellation_chan,
profiler_chan);
pool.shutdown();
} else {
native::task::spawn(p);
let constellation_chan = result_port.recv();
debug!("preparing to enter main loop");
CompositorTask::create(opts,
compositor_port,
constellation_chan,
profiler_chan);
}
}
pub fn run(opts: opts::Opts) {
let (compositor_port, compositor_chan) = CompositorChan::new(); let (compositor_port, compositor_chan) = CompositorChan::new();
let profiler_chan = Profiler::create(opts.profiler_period); let profiler_chan = Profiler::create(opts.profiler_period);
@ -174,7 +194,7 @@ pub fn run(opts: opts::Opts) {
let profiler_chan_clone = profiler_chan.clone(); let profiler_chan_clone = profiler_chan.clone();
let (result_chan, result_port) = channel(); let (result_chan, result_port) = channel();
pool.spawn(TaskOpts::new(), proc() { spawn_main(opts.clone(), compositor_port, profiler_chan, result_port, proc() {
let opts = &opts_clone; let opts = &opts_clone;
// Create a Servo instance. // Create a Servo instance.
let resource_task = ResourceTask(); let resource_task = ResourceTask();
@ -210,15 +230,5 @@ pub fn run(opts: opts::Opts) {
// Send the constallation Chan as the result // Send the constallation Chan as the result
result_chan.send(constellation_chan); result_chan.send(constellation_chan);
}); });
let constellation_chan = result_port.recv();
debug!("preparing to enter main loop");
CompositorTask::create(opts,
compositor_port,
constellation_chan,
profiler_chan);
pool.shutdown();
} }

View file

@ -61,6 +61,9 @@ pub struct Opts {
/// may wish to turn this flag on in order to benchmark style recalculation against other /// may wish to turn this flag on in order to benchmark style recalculation against other
/// browser engines. /// browser engines.
pub bubble_widths_separately: bool, pub bubble_widths_separately: bool,
/// Use native threads instead of green threads
pub native_threading: bool
} }
fn print_usage(app: &str, opts: &[getopts::OptGroup]) { fn print_usage(app: &str, opts: &[getopts::OptGroup]) {
@ -77,7 +80,7 @@ pub fn from_cmdline_args(args: &[String]) -> Option<Opts> {
let app_name = args[0].to_str(); let app_name = args[0].to_str();
let args = args.tail(); let args = args.tail();
let opts = vec!( let opts = vec![
getopts::optflag("c", "cpu", "CPU rendering"), getopts::optflag("c", "cpu", "CPU rendering"),
getopts::optopt("o", "output", "Output file", "output.png"), getopts::optopt("o", "output", "Output file", "output.png"),
getopts::optopt("r", "rendering", "Rendering backend", "direct2d|core-graphics|core-graphics-accelerated|cairo|skia."), getopts::optopt("r", "rendering", "Rendering backend", "direct2d|core-graphics|core-graphics-accelerated|cairo|skia."),
@ -90,8 +93,9 @@ pub fn from_cmdline_args(args: &[String]) -> Option<Opts> {
getopts::optflag("z", "headless", "Headless mode"), getopts::optflag("z", "headless", "Headless mode"),
getopts::optflag("f", "hard-fail", "Exit on task failure instead of displaying about:failure"), getopts::optflag("f", "hard-fail", "Exit on task failure instead of displaying about:failure"),
getopts::optflag("b", "bubble-widths", "Bubble intrinsic widths separately like other engines"), getopts::optflag("b", "bubble-widths", "Bubble intrinsic widths separately like other engines"),
getopts::optflag("n", "native-threading", "Use native threading instead of green threading"),
getopts::optflag("h", "help", "Print this message") getopts::optflag("h", "help", "Print this message")
); ];
let opt_match = match getopts::getopts(args, opts.as_slice()) { let opt_match = match getopts::getopts(args, opts.as_slice()) {
Ok(m) => m, Ok(m) => m,
@ -169,6 +173,8 @@ pub fn from_cmdline_args(args: &[String]) -> Option<Opts> {
None => cmp::max(rt::default_sched_threads() * 3 / 4, 1), None => cmp::max(rt::default_sched_threads() * 3 / 4, 1),
}; };
let native_threading = opt_match.opt_present("h") || opt_match.opt_present("help");
Some(Opts { Some(Opts {
urls: urls, urls: urls,
render_backend: render_backend, render_backend: render_backend,
@ -183,5 +189,6 @@ pub fn from_cmdline_args(args: &[String]) -> Option<Opts> {
headless: opt_match.opt_present("z"), headless: opt_match.opt_present("z"),
hard_fail: opt_match.opt_present("f"), hard_fail: opt_match.opt_present("f"),
bubble_widths_separately: opt_match.opt_present("b"), bubble_widths_separately: opt_match.opt_present("b"),
native_threading: native_threading
}) })
} }