Skip to content
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

[WIP] Experiments with worker threads #550

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
13 changes: 11 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ darling = "0.20"
dyn-clone = "1.0"
heapless = "0.8"
ipnetwork = { version = "0.20", default-features = false }
itertools = { version = "0.12", default-features = false }
itertools = { version = "0.13", default-features = false }
libc = "0.2"
libnet = { git = "https://github.com/oxidecomputer/netadm-sys" }
nix = { version = "0.29", features = ["signal", "user"] }
Expand Down
5 changes: 3 additions & 2 deletions bench/src/kbench/measurement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ pub fn build_flamegraph(
}

let terms = [
("xde_rx", rx_name.unwrap_or("rx")),
("xde_mc_tx", tx_name.unwrap_or("tx")),
("xde_rx", rx_name.unwrap_or("in_place")),
("xde_mc_tx", tx_name.unwrap_or("out_place")),
("xde_worker", "process"),
];

for (tracked_fn, out_name) in terms {
Expand Down
61 changes: 60 additions & 1 deletion crates/illumos-sys-hdrs/src/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

// Copyright 2022 Oxide Computer Company
// Copyright 2024 Oxide Computer Company

#![allow(clippy::missing_safety_doc)]

Expand Down Expand Up @@ -80,6 +80,31 @@ impl krw_t {
pub const RW_READER_STARVEWRITER: Self = Self(2);
}

#[repr(C)]
pub struct kcondvar_t {
pub _opaque: c_ushort,
}

#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct kcv_type_t(pub c_int);
impl kcv_type_t {
pub const CV_DEFAULT: Self = Self(0);
pub const CV_DRIVER: Self = Self(1);
}

#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct time_res_t(pub c_int);
impl time_res_t {
pub const TR_NANOSEC: Self = Self(0);
pub const TR_MICROSEC: Self = Self(1);
pub const TR_MILLISEC: Self = Self(2);
pub const TR_SEC: Self = Self(3);
pub const TR_CLOCK_TICK: Self = Self(4);
pub const TR_COUNT: Self = Self(5);
}

extern "C" {
type module_info;
type module_stat;
Expand Down Expand Up @@ -586,6 +611,40 @@ extern "C" {
pub fn rw_tryupgrade(rwlp: *mut krwlock_t);
pub fn rw_read_locked(rwlp: *mut krwlock_t);

pub fn cv_init(
cvp: *mut kcondvar_t,
name: *const c_char,
cv_type: kcv_type_t,
arg: *mut c_void,
);
pub fn cv_destroy(cvp: *mut kcondvar_t);
pub fn cv_wait(cvp: *mut kcondvar_t, mp: *mut kmutex_t);
pub fn cv_signal(cvp: *mut kcondvar_t);
pub fn cv_broadcast(cvp: *mut kcondvar_t);
pub fn cv_wait_sig(cvp: *mut kcondvar_t, mp: *mut kmutex_t) -> c_int;
pub fn cv_timedwait(
cvp: *mut kcondvar_t,
mp: *mut kmutex_t,
timeout: clock_t,
) -> clock_t;
pub fn cv_timedwait_sig(
cvp: *mut kcondvar_t,
mp: *mut kmutex_t,
timeout: clock_t,
) -> clock_t;
pub fn cv_reltimedwait(
cvp: *mut kcondvar_t,
mp: *mut kmutex_t,
delta: clock_t,
res: time_res_t,
) -> clock_t;
pub fn cv_reltimedwait_sig(
cvp: *mut kcondvar_t,
mp: *mut kmutex_t,
delta: clock_t,
res: time_res_t,
) -> clock_t;

pub fn nochpoll() -> c_int;
pub fn nodev() -> c_int;
pub fn nulldev() -> c_int;
Expand Down
3 changes: 2 additions & 1 deletion crates/illumos-sys-hdrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

// Copyright 2022 Oxide Computer Company
// Copyright 2024 Oxide Computer Company
#![cfg_attr(feature = "kernel", feature(extern_types))]
#![allow(non_camel_case_types)]
#![no_std]
Expand Down Expand Up @@ -307,6 +307,7 @@ pub type hrtime_t = c_longlong;
// ======================================================================
// uts/common/sys/types.h
// ======================================================================
pub type clock_t = c_long;
pub type datalink_id_t = uint32_t;
pub type dev_t = c_ulong;
pub type id_t = c_int;
Expand Down
16 changes: 16 additions & 0 deletions dtrace/flow.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
mac_client_set_flow_cb:entry {
printf("entry: mip %p mrh %p mp %p",
arg0, arg1, arg2);
}

mac_client_set_flow_cb:return {
printf("donezo off %p val %p", arg0, arg1);
}

flow_transport_lport_match:entry {
printf("entry: mip %p mrh %p mp %p", arg0, arg1, arg2);
}

flow_transport_lport_match:return {
printf("donezo off %p val %p", arg0, arg1);
}
1 change: 1 addition & 0 deletions dtrace/opte-count-cycles-oneliner.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
worker-pkt-start { self->ts = vtimestamp; self->dir = arg0; } worker-pkt-end /self->dir == 1 && self->ts/ { @time["rx"] = lquantize((vtimestamp - self->ts), 256, 32768, 256); self->ts = 0;} worker-pkt-end /self->dir == 2 && self->ts/ {@time["tx"] = lquantize((vtimestamp - self->ts), 256, 32768, 256); self->ts = 0;} END {}
1 change: 1 addition & 0 deletions dtrace/opte-count-cycles-os.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xde_rx:entry { self->ts = vtimestamp; self->dir = 1; } xde_mc_tx:entry { self->ts = vtimestamp; self->dir = 2; } xde_rx:return /self->ts/ { @time["rx"] = lquantize((vtimestamp - self->ts), 256, 32768, 256); self->ts = 0;} xde_mc_tx:return /self->ts/ {@time["tx"] = lquantize((vtimestamp - self->ts), 256, 32768, 256); self->ts = 0;} END {}
56 changes: 46 additions & 10 deletions dtrace/opte-count-cycles.d
Original file line number Diff line number Diff line change
@@ -1,21 +1,57 @@
xde_mc_tx:entry {
self->tx_ts = vtimestamp;
worker-pkt-start {
self->ts = vtimestamp;
self->dir = arg0;
}

worker-pkt-end /self->dir == 1 && self->ts/ {
@time["rx"] = lquantize((vtimestamp - self->ts), 256, 32768, 256);
}

worker-pkt-end /self->dir == 2 && self->ts/ {
@time["tx"] = lquantize((vtimestamp - self->ts), 256, 32768, 256);
}

worker-pkt-end {
self->ts = 0;
self->dir = 0;
}

xde_rx:entry {
self->rx_ts = vtimestamp;
self->drop_time = vtimestamp;
}

xde_mc_tx:return /self->tx_ts/ {
@time["tx"] = lquantize((vtimestamp - self->tx_ts), 256, 32768, 256);
self->tx_ts = 0;
xde_mc_tx:entry {
self->drop_time = vtimestamp;
}

xde_rx:return /self->rx_ts/ {
@time["rx"] = lquantize((vtimestamp - self->rx_ts), 256, 32768, 256);
self->rx_ts = 0;
xde_rx:return /self->dir/ {
@time["place_in_inner"] = lquantize((vtimestamp - self->ts), 256, 32768, 256);
self->drop_time = 0;
}

END {
xde_mc_tx:return /self->dir/ {
@time["place_out_inner"] = lquantize((vtimestamp - self->ts), 256, 32768, 256);
self->drop_time = 0;
}

xde_rx:return /!self->dir/ {
@time["place_in"] = lquantize((vtimestamp - self->ts), 256, 32768, 256);
self->drop_time = 0;
}

xde_mc_tx:return /!self->dir/ {
@time["place_out"] = lquantize((vtimestamp - self->ts), 256, 32768, 256);
self->drop_time = 0;
}

xde_rx:return {
self->drop_time = 0;
}

xde_mc_tx:return {
self->drop_time = 0;
}

END {

}
31 changes: 31 additions & 0 deletions dtrace/opte-tcp-flowdrop.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Track bad packets as they happen.
*
* dtrace -L ./lib -I . -Cqs ./opte-bad-packet.d
*/
#include "common.h"

#define HDR_FMT "%-12s %-3s %-18s %s\n"
#define LINE_FMT "%-12s %-3s 0x%-16p %s\n"

BEGIN {
printf(HDR_FMT, "PORT", "DIR", "MBLK", "MSG");
num = 0;
}

tcp-err {
this->dir = DIR_STR(arg0);
this->port = stringof(arg1);
this->flow_id = stringof(arg2);
this->mblk = arg3;
this->msg = stringof(arg4);

if (num >= 10) {
printf(HDR_FMT, "PORT", "DIR", "MBLK", "MSG");
num = 0;
}

printf(LINE_FMT, this->port, this->dir, this->mblk, this->msg);
stack();
num++;
}
Loading