xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Zheng Li <dev@zheng.li>
To: xen-devel@lists.xenproject.org
Cc: Dave Scott <Dave.Scott@citrix.com>, Joe Jin <joe.jin@oracle.com>,
	"Luis R. Rodriguez" <mcgrof@suse.com>,
	Luonengjun <luonengjun@huawei.com>, Zheng Li <dev@zheng.li>,
	Fanhenglong <fanhenglong@huawei.com>,
	Ian Jackson <Ian.Jackson@citrix.com>,
	"Liuqiming (John)" <john.liuqiming@huawei.com>
Subject: [PATCH v3 3/9] oxenstored: add a --use-select command line flag
Date: Thu, 25 Sep 2014 18:34:56 +0100	[thread overview]
Message-ID: <1411666502-23709-4-git-send-email-dev@zheng.li> (raw)
In-Reply-To: <1411666502-23709-1-git-send-email-dev@zheng.li>

This allows to fall back to the original Unix.select if preferred. It could be
useful for debugging purposes too.

Signed-off-by: Zheng Li <dev@zheng.li>
---
 tools/ocaml/xenstored/parse_arg.ml |  8 ++++++--
 tools/ocaml/xenstored/select.ml    | 15 ++++++++++++++-
 tools/ocaml/xenstored/select.mli   |  9 ++++++++-
 tools/ocaml/xenstored/xenstored.ml |  2 ++
 4 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/tools/ocaml/xenstored/parse_arg.ml b/tools/ocaml/xenstored/parse_arg.ml
index 5d21601..6e22c16 100644
--- a/tools/ocaml/xenstored/parse_arg.ml
+++ b/tools/ocaml/xenstored/parse_arg.ml
@@ -25,6 +25,7 @@ type config =
 	tracefile: string option; (* old xenstored compatibility *)
 	restart: bool;
 	disable_socket: bool;
+	use_select: bool;
 }
 
 let do_argv =
@@ -35,7 +36,8 @@ let do_argv =
 	and reraise_top_level = ref false
 	and config_file = ref ""
 	and restart = ref false
-	and disable_socket = ref false in
+	and disable_socket = ref false
+	and use_select = ref false in
 
 	let speclist =
 		[ ("--no-domain-init", Arg.Unit (fun () -> domain_init := false),
@@ -52,8 +54,9 @@ let do_argv =
 		  ("-T", Arg.Set_string tracefile, ""); (* for compatibility *)
 		  ("--restart", Arg.Set restart, "Read database on starting");
 		  ("--disable-socket", Arg.Unit (fun () -> disable_socket := true), "Disable socket");
+		  ("--use-select", Arg.Unit (fun () -> use_select := true), "Use select instead of poll"); (* for backward compatibility and testing *)
 		] in
-	let usage_msg = "usage : xenstored [--config-file <filename>] [--no-domain-init] [--help] [--no-fork] [--reraise-top-level] [--restart] [--disable-socket]" in
+	let usage_msg = "usage : xenstored [--config-file <filename>] [--no-domain-init] [--help] [--no-fork] [--reraise-top-level] [--restart] [--disable-socket] [--use-select]" in
 	Arg.parse speclist (fun s -> ()) usage_msg;
 	{
 		domain_init = !domain_init;
@@ -65,4 +68,5 @@ let do_argv =
 		tracefile = if !tracefile <> "" then Some !tracefile else None;
 		restart = !restart;
 		disable_socket = !disable_socket;
+		use_select = !use_select;
 	}
diff --git a/tools/ocaml/xenstored/select.ml b/tools/ocaml/xenstored/select.ml
index ab8c847..0455e16 100644
--- a/tools/ocaml/xenstored/select.ml
+++ b/tools/ocaml/xenstored/select.ml
@@ -36,7 +36,7 @@ let get_sys_fs_nr_open () =
 
 let init_event () = {read = false; write = false; except = false}
 
-let select in_fds out_fds exc_fds timeout =
+let poll_select in_fds out_fds exc_fds timeout =
 	let h = Hashtbl.create 57 in
 	let add_event event_set fd =
 		let e =
@@ -62,3 +62,16 @@ let select in_fds out_fds exc_fds timeout =
 			 (if event.write then fd :: w else w),
 			 (if event.except then fd :: x else x))
 			a r
+
+(* If the use_poll function is not called at all, we default to the original Unix.select behavior *)
+let select_fun = ref Unix.select
+
+let use_poll yes =
+	let sel_fun, max_fd =
+		if yes then poll_select, get_sys_fs_nr_open ()
+		else Unix.select, 1024 in
+	select_fun := sel_fun;
+	set_fd_limit max_fd
+
+let select in_fds out_fds exc_fds timeout =
+	(!select_fun) in_fds out_fds exc_fds timeout
diff --git a/tools/ocaml/xenstored/select.mli b/tools/ocaml/xenstored/select.mli
index 1253d4e..3912779 100644
--- a/tools/ocaml/xenstored/select.mli
+++ b/tools/ocaml/xenstored/select.mli
@@ -14,7 +14,14 @@
 
 
 (** Same interface and semantics as [Unix.select] but with an extra alternative
-    implementation based on poll. *)
+    implementation based on poll. Switching implementations is done by calling
+     the [use_poll] function. *)
 val select:
 	Unix.file_descr list -> Unix.file_descr list -> Unix.file_descr list -> float
 	-> Unix.file_descr list * Unix.file_descr list * Unix.file_descr list
+
+(** [use_poll true] will use poll based select with max fds number limitation
+   eliminated; [use_poll false] will use standard [Unix.select] with max fd
+   number set to 1024; not calling this function at all equals to use the
+   standard [Unix.select] with max fd number setting untouched. *)
+val use_poll: bool -> unit
diff --git a/tools/ocaml/xenstored/xenstored.ml b/tools/ocaml/xenstored/xenstored.ml
index bfa488f..dacea21 100644
--- a/tools/ocaml/xenstored/xenstored.ml
+++ b/tools/ocaml/xenstored/xenstored.ml
@@ -274,6 +274,8 @@ let _ =
 		);
 	);
 
+	Select.use_poll (not cf.use_select);
+
 	Sys.set_signal Sys.sighup (Sys.Signal_handle sighup_handler);
 	Sys.set_signal Sys.sigterm (Sys.Signal_handle (fun i -> quit := true));
 	Sys.set_signal Sys.sigusr1 (Sys.Signal_handle (fun i -> sigusr1_handler store));
-- 
2.1.1

  parent reply	other threads:[~2014-09-25 17:35 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-25 17:34 Some oxenstored improvements (v3) Zheng Li
2014-09-25 17:34 ` [PATCH v3 1/9] oxenstored: add a poll-based select mechanism Zheng Li
2014-09-25 17:34 ` [PATCH v3 2/9] oxenstored: add facilities to raise the max open fds uplimit Zheng Li
2014-09-25 17:34 ` Zheng Li [this message]
2014-09-25 17:34 ` [PATCH v3 4/9] oxenstored: catch the error when a connection is already deleted Zheng Li
2014-09-25 17:34 ` [PATCH v3 5/9] oxenstored: use hash table to store socket connections Zheng Li
2014-09-25 17:34 ` [PATCH v3 6/9] oxenstored: enable domain connection indexing based on eventchn port Zheng Li
2014-09-25 17:35 ` [PATCH v3 7/9] oxenstored: only process domain connections that notify us by events Zheng Li
2014-09-25 17:35 ` [PATCH v3 8/9] oxenstored: add a safe net mechanism for existing ill-behaved clients Zheng Li
2014-09-25 17:35 ` [PATCH v3 9/9] oxenstored: reduce syslog call overhead Zheng Li
2014-09-25 21:00   ` [PATCH v3 9/9] oxenstored: reduce syslog call overhead (fix typo) Zheng Li
2014-09-26 15:16     ` Ian Jackson
2014-09-26 15:33       ` Zheng Li
2014-09-26 15:57         ` Ian Jackson
2014-09-26 16:29           ` Zheng Li
2014-09-26 16:37             ` Ian Jackson
2014-09-26 16:38             ` Zheng Li
2014-09-29 14:37 ` Some oxenstored improvements (v3) Konrad Rzeszutek Wilk
2014-09-29 20:55   ` Dave Scott
2014-09-30 10:21     ` Zheng Li
2014-10-07 13:24     ` Konrad Rzeszutek Wilk
2014-10-08 12:59       ` Dave Scott
2014-10-08 13:01         ` Konrad Rzeszutek Wilk
2014-10-08 13:42           ` Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1411666502-23709-4-git-send-email-dev@zheng.li \
    --to=dev@zheng.li \
    --cc=Dave.Scott@citrix.com \
    --cc=Ian.Jackson@citrix.com \
    --cc=fanhenglong@huawei.com \
    --cc=joe.jin@oracle.com \
    --cc=john.liuqiming@huawei.com \
    --cc=luonengjun@huawei.com \
    --cc=mcgrof@suse.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).