Skip to content

CP-52911: Negative scheduler for xapi threads. #6416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@
astring
base-threads
base64
bechamel
(bos :with-test)
cdrom
(clock (= :version))
Expand Down
1 change: 1 addition & 0 deletions ocaml/libs/http-lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
tracing_propagator
uri
xapi-backtrace
xapi-consts
xapi-log
xapi-stdext-pervasives
xapi-stdext-threads
Expand Down
8 changes: 0 additions & 8 deletions ocaml/libs/http-lib/http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,6 @@ module Request = struct
let headers, body = to_headers_and_body x in
let frame_header = if x.frame then make_frame_header headers else "" in
frame_header ^ headers ^ body

let with_originator_of req f =
Option.iter
(fun req ->
let originator = List.assoc_opt Hdr.originator req.additional_headers in
f originator
)
req
end

module Response = struct
Expand Down
4 changes: 2 additions & 2 deletions ocaml/libs/http-lib/http.mli
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ module Request : sig

val to_wire_string : t -> string
(** [to_wire_string t] returns a string which could be sent to a server *)

val with_originator_of : t option -> (string option -> unit) -> unit
end

(** Parsed form of the HTTP response *)
Expand Down Expand Up @@ -229,6 +227,8 @@ module Hdr : sig

val hsts : string
(** Header used for HTTP Strict Transport Security *)

val originator : string
end

val output_http : Unix.file_descr -> string list -> unit
Expand Down
25 changes: 22 additions & 3 deletions ocaml/libs/http-lib/http_svr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,31 @@ let handle_connection ~header_read_timeout ~header_total_timeout
~max_length:max_header_length ss
in

Http.Request.with_originator_of req Tgroup.of_req_originator ;

(* 2. now we attempt to process the request *)
let finished =
Option.fold ~none:true
~some:(handle_one x ss x.Server.default_context)
~some:(fun req ->
if !Constants.tgroups_enabled then (
let open Xapi_stdext_threads.Threadext in
let originator =
List.assoc_opt Http.Hdr.originator
req.Http.Request.additional_headers
in
originator
|> Tgroup.of_req_originator
|> Option.iter (fun tgroup ->
ThreadRuntimeContext.get ()
|> ThreadRuntimeContext.update (fun thread_ctx ->
{thread_ctx with tgroup}
)
) ;

let thread_ctx = ThreadRuntimeContext.get () in
Tgroup.with_one_thread_of_group thread_ctx.tgroup @@ fun () ->
handle_one x ss x.Server.default_context req
) else
handle_one x ss x.Server.default_context req
)
req
in
(* 3. do it again if the connection is kept open, but without timeouts *)
Expand Down
7 changes: 6 additions & 1 deletion ocaml/libs/tgroup/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
(name tgroup)
(modules tgroup)
(public_name tgroup)
(libraries xapi-log xapi-stdext-unix xapi-stdext-std))
(libraries
xapi-log
xapi-stdext-pervasives
xapi-stdext-unix
xapi-stdext-std)
)

(test
(name test_tgroup)
Expand Down
16 changes: 9 additions & 7 deletions ocaml/libs/tgroup/test_tgroup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let test_identity () =

let test_make ((user_agent, subject_sid), expected_identity) =
let actual_identity =
Tgroup.Group.Identity.(make ?user_agent subject_sid |> to_string)
Tgroup.Description.Identity.(make ?user_agent subject_sid |> to_string)
in
Alcotest.(check string)
"Check expected identity" expected_identity actual_identity
Expand All @@ -29,28 +29,28 @@ let test_identity () =

let test_of_creator () =
let dummy_identity =
Tgroup.Group.Identity.make ~user_agent:"XenCenter2024" "root"
Tgroup.Description.Identity.make ~user_agent:"XenCenter2024" "root"
in
let specs =
[
((None, None, None, None), "external/unauthenticated")
; ((Some true, None, None, None), "external/intrapool")
; ( ( Some true
, Some Tgroup.Group.Endpoint.External
, Some Tgroup.Description.Endpoint.External
, Some dummy_identity
, Some "sm"
)
, "external/intrapool"
)
; ( ( Some true
, Some Tgroup.Group.Endpoint.Internal
, Some Tgroup.Description.Endpoint.Internal
, Some dummy_identity
, Some "sm"
)
, "external/intrapool"
)
; ( ( None
, Some Tgroup.Group.Endpoint.Internal
, Some Tgroup.Description.Endpoint.Internal
, Some dummy_identity
, Some "cli"
)
Expand All @@ -62,9 +62,11 @@ let test_of_creator () =
]
in
let test_make ((intrapool, endpoint, identity, originator), expected_group) =
let originator = Option.map Tgroup.Group.Originator.of_string originator in
let originator =
Option.map Tgroup.Description.Originator.of_string originator
in
let actual_group =
Tgroup.Group.(
Tgroup.Description.(
Creator.make ?intrapool ?endpoint ?identity ?originator ()
|> of_creator
|> to_string
Expand Down
Loading
Loading