From patchwork Sat Feb 24 05:07:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13570241 Received: from mail-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6285B12B66 for ; Sat, 24 Feb 2024 05:07:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708751269; cv=none; b=hV1jOS0Tdv6DUy/tATltpgrVqXdcLoWooYVYIpwCgq2uOTKugL5vasSXkxPvSZcz5maO+ogvE/9ASvCc/ejuTt9Vv7iKsZ8yHY30Bvv9gnI27x/9ybsVI7P+NyFQIt6SeuSTcmWPUe5b+au2pdYOF+J4eb/+IUzaK+M/jJ8trsU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708751269; c=relaxed/simple; bh=F91BiQ6O1mlQE+A4+9Lsnj2wEnbcDpwImoZ96TkvNac=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=MMBhj8wzMHu7d2mhVoTzaBNsZaozAG2b890nlEqfVTxNf+rUoE1pKsWudKqmNpB52gUWHt9v1iEpR+rxmWn34OwqHfcUxEwgcL4xzuJdU3cMIWwLpAIRQAF0SlnaXTilWXLJHrrDRCEG590lF2yWtNuljpPe9n8OuyYKBjh7csI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=j/Mlo/jW; arc=none smtp.client-ip=209.85.166.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="j/Mlo/jW" Received: by mail-il1-f169.google.com with SMTP id e9e14a558f8ab-36523b9fa11so5337695ab.3 for ; Fri, 23 Feb 2024 21:07:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1708751266; x=1709356066; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+wPGmxuJ4SPc/NqTmX1iLEmNyhHARVyyFYwhGzxPm8Q=; b=j/Mlo/jWhOD9B/aa6NV/Me4aFwbQ5qjc/CuHEKX2Ytn3uYOgxKbx/lU0ymnHP+j4Ca p/BmUxJhoLknB45f2/1ozAikrwa6E5Qxasmly7Mr5nuIWis17Q6ljbZrIYGh4D9xHY86 wzc2C1DNgAcvapnuqrE6TcCdoVPwKZ71y06t10zHnSgFumhX55yJt+vhzmeSpq4lqx0W V6uqMD1c4Ejm4qrpgqQC5TJPMTxII37WO4tVYvzgs/wZSyu+4WyAcMKE3jEKcT2wJETc YRm55EnRfD4/Onst913BYpwAEuKs9U//UcJZQSlNq8kI1tLdhKHt84QIeMe7IFUfnoGj 2hjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708751266; x=1709356066; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+wPGmxuJ4SPc/NqTmX1iLEmNyhHARVyyFYwhGzxPm8Q=; b=jBgp6cCcCKbBGrU5jnmkLjLEIDNtzD1p7TBZnSLRgOFbXM3QlLtHDz5d6147WxYNPC LytS8loI/iGNvISiUmw15dMrM0KMgJthntFBeuXugF/4CfNC/b1pcr/rrazIHpEIFASl fs4qd5hd5X3XWnNx/afcu6ILt9iWCcf/FgSoxJyhU6Q/nxqhxlkW+kF6/hFDlHPe9dun hECy2a+IqMWRNIyJXBN/lre3NxmjJ4rQ3Z3ALfJJGIBk40gkgGOuMTcXpRF8Gs584YZT guaAlAfBUCeEu5peebexeCkqXNX9DfspSIz32uaezJleEpiadfeHwbIGd7ety4j0jstA hP8A== X-Gm-Message-State: AOJu0YyCJfmIfADzNjn6VqP4Xa9jGRAdq4Mpa3EV53SEqwh+qka/t0Co Rm7vGTbSAM6ZUo5SgNlWVz2Kl717pqJEDGOiRxTk7ui3oJQoudTuefS6jBk45+G1n2ARfgX2ZSw b X-Google-Smtp-Source: AGHT+IERtmZZ01Y3GzhsN8YgL9ej2ni+/o635QQTjhnWvO8KJ0XfS13yH1Ta+CzraD+xvyg6XmB5qQ== X-Received: by 2002:a92:4a03:0:b0:363:b95a:b55a with SMTP id m3-20020a924a03000000b00363b95ab55amr2031354ilf.16.1708751266168; Fri, 23 Feb 2024 21:07:46 -0800 (PST) Received: from localhost (fwdproxy-prn-020.fbsv.net. [2a03:2880:ff:14::face:b00c]) by smtp.gmail.com with ESMTPSA id w191-20020a6382c8000000b005c6617b52e6sm344538pgd.5.2024.02.23.21.07.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 21:07:45 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov Subject: [PATCH v1 1/4] io_uring: only account cqring wait time as iowait if enabled for a ring Date: Fri, 23 Feb 2024 21:07:32 -0800 Message-ID: <20240224050735.1759733-1-dw@davidwei.uk> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently we unconditionally account time spent waiting for events in CQ ring as iowait time. Some userspace tools consider iowait time to be CPU util/load which can be misleading as the process is sleeping. High iowait time might be indicative of issues for storage IO, but for network IO e.g. socket recv() we do not control when the completions happen so its value misleads userspace tooling. This patch gates the previously unconditional iowait accounting behind a new IORING_REGISTER opcode. By default time is not accounted as iowait, unless this is explicitly enabled for a ring. Thus userspace can decide, depending on the type of work it expects to do, whether it wants to consider cqring wait time as iowait or not. Signed-off-by: David Wei --- include/linux/io_uring_types.h | 1 + include/uapi/linux/io_uring.h | 3 +++ io_uring/io_uring.c | 9 +++++---- io_uring/register.c | 17 +++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index bd7071aeec5d..c568e6b8c9f9 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -242,6 +242,7 @@ struct io_ring_ctx { unsigned int drain_disabled: 1; unsigned int compat: 1; unsigned int iowq_limits_set : 1; + unsigned int iowait_enabled: 1; struct task_struct *submitter_task; struct io_rings *rings; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 7bd10201a02b..b068898c2283 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -575,6 +575,9 @@ enum { IORING_REGISTER_NAPI = 27, IORING_UNREGISTER_NAPI = 28, + /* account time spent in cqring wait as iowait */ + IORING_REGISTER_IOWAIT = 29, + /* this goes last */ IORING_REGISTER_LAST, diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index cf2f514b7cc0..7f8d2a03cce6 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -2533,12 +2533,13 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx, return 0; /* - * Mark us as being in io_wait if we have pending requests, so cpufreq - * can take into account that the task is waiting for IO - turns out - * to be important for low QD IO. + * Mark us as being in io_wait if we have pending requests if enabled + * via IORING_REGISTER_IOWAIT, so cpufreq can take into account that + * the task is waiting for IO - turns out to be important for low QD + * IO. */ io_wait = current->in_iowait; - if (current_pending_io()) + if (ctx->iowait_enabled && current_pending_io()) current->in_iowait = 1; ret = 0; if (iowq->timeout == KTIME_MAX) diff --git a/io_uring/register.c b/io_uring/register.c index 99c37775f974..fbdf3d3461d8 100644 --- a/io_uring/register.c +++ b/io_uring/register.c @@ -387,6 +387,17 @@ static __cold int io_register_iowq_max_workers(struct io_ring_ctx *ctx, return ret; } +static int io_register_iowait(struct io_ring_ctx *ctx, int val) +{ + int was_enabled = ctx->iowait_enabled; + + if (val) + ctx->iowait_enabled = 1; + else + ctx->iowait_enabled = 0; + return was_enabled; +} + static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode, void __user *arg, unsigned nr_args) __releases(ctx->uring_lock) @@ -563,6 +574,12 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode, break; ret = io_unregister_napi(ctx, arg); break; + case IORING_REGISTER_IOWAIT: + ret = -EINVAL; + if (arg) + break; + ret = io_register_iowait(ctx, nr_args); + break; default: ret = -EINVAL; break; From patchwork Sat Feb 24 05:07:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13570242 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F29C12E51 for ; Sat, 24 Feb 2024 05:07:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708751269; cv=none; b=pZM/goMOiCG2kbP8CzQ9qnaK7tSjCAtcPIg+wtAP0hv2/Qyr93M5H5rKU0DKQEaEIxYnEdfKQAsWfFaIH+TBiotmeeR7PQ0Gr7o+TFNTYBwsxjAzflWbbG3ukTDbZp/Ga74yre1Qt5ueOC+eTDlG3onREIECx4pmYE+mJVrDR4Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708751269; c=relaxed/simple; bh=HTtofWdLtXwoxkpmkidgtk48vDW4ybgbqrBGySc2op8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O/pY0aIymxYjeuMBZfZhXLOKAgi8N9bg5PeujsqVF7voxFVVIakHwOmEctONxZ+0pqFFeuBr5vN2ERjbSSzYyuHCh0NoH6GjiPr6saFIJ+GrKl7Gff8LLWvheCNqxSfbsBzs9pmVHSeqEJ0ghPmGbJzTN3JBOtVJOl7BHEk1nfI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=E3tF6ecH; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="E3tF6ecH" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-5d3912c9a83so1130871a12.3 for ; Fri, 23 Feb 2024 21:07:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1708751267; x=1709356067; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Pu+yQ8ayliskgpsY+U87x70jpuMRyp1SCw69OCNtbRo=; b=E3tF6ecHd0/wgQVshDwR57s8BruJMhWWAhJjmI4zwQkvJJmwPXknDTjj4IDLMsneag kjbcfyAYZPV5F7WRcm6pkB9HlpwHkbegCn9+HXDGJBXV2mdfWpkuSIlLE1a6h+AAZyq0 RRstJLUPZuZbjFeldKqBta0QxkoeLgPW1QOqHKi8gJ9FmItXPQcsDk6wqAnXOyRECv77 H3EEpcPI2QDRxbFxN6HE1t1Zvw8eoGYLf0d0DetTuTy6i5DH1Xe1X6pSeFdnJIjINNKO q5IRnO6DdJaWryAm1AGB2r+A+fXo5DbkYFvdASZpLls1OD8VBfSqOt+9n3U3Aaqe8Nm/ jROA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708751267; x=1709356067; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pu+yQ8ayliskgpsY+U87x70jpuMRyp1SCw69OCNtbRo=; b=MDS1m0inFPRXo+O3GlVOGfjiCnlgPp5jQNiCT3LxCjmJJfXne+nkrL3FgOrMJoOPNn jsLmYbT52xafQHA0yJ5vontx5tUcCRycY/T581coJzZDjP1g2vq8W9337KkglZ82+T71 +65+xVBz1LgvETNvHDE8TKJg6597/TWUX900BTbHqeCYVwgxgJNnd5gjNX2nrZADurkP 8/HnyAmA1VFcAzqdzjP0w5re3vKW/El+sMtADPZOX6DYvCS09yypqCw+qbZPizykoZIJ y+8uGNSa9Slxyq1HqJdRVXZbXrGkTCuKNzSEp3liHAdeFhbDICW5ixZT+2x7QnCs7qk9 rcIg== X-Gm-Message-State: AOJu0YyQTP3SNCbUsxYnyTEnjoYe9jNI84seKdA+B6njoMAmUVkfXBT3 sStaDCT/Ratxvc+lblA9iH7BL6wT577CL1rldBOs/Kzt1jkU3Utm3XhOYHn8NyTwuQeA43k+due H X-Google-Smtp-Source: AGHT+IGItOlvDj83o2wA2R0Pi+tKpcvSo53OvRY7H+uoJFw8IQ6W55Ar/0E30AazRbxQemOUZGXf4A== X-Received: by 2002:a05:6a20:d046:b0:19f:ce3:5aee with SMTP id hv6-20020a056a20d04600b0019f0ce35aeemr1604447pzb.8.1708751266991; Fri, 23 Feb 2024 21:07:46 -0800 (PST) Received: from localhost (fwdproxy-prn-006.fbsv.net. [2a03:2880:ff:6::face:b00c]) by smtp.gmail.com with ESMTPSA id y6-20020a62ce06000000b006e39d08cb3asm340896pfg.167.2024.02.23.21.07.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 21:07:46 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov Subject: [PATCH v1 2/4] liburing: add examples/proxy to .gitignore Date: Fri, 23 Feb 2024 21:07:33 -0800 Message-ID: <20240224050735.1759733-2-dw@davidwei.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240224050735.1759733-1-dw@davidwei.uk> References: <20240224050735.1759733-1-dw@davidwei.uk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: David Wei Also re-ordered to be alphabetical. Signed-off-by: David Wei --- .gitignore | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d355c59..f08cbe9 100644 --- a/.gitignore +++ b/.gitignore @@ -21,10 +21,11 @@ /examples/link-cp /examples/napi-busy-poll-client /examples/napi-busy-poll-server -/examples/ucontext-cp /examples/poll-bench -/examples/send-zerocopy +/examples/proxy /examples/rsrc-update-bench +/examples/send-zerocopy +/examples/ucontext-cp /test/*.t /test/*.dmesg From patchwork Sat Feb 24 05:07:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13570243 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D096E13FE5 for ; Sat, 24 Feb 2024 05:07:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708751270; cv=none; b=AMuHLOsG03m+usCnS1VGO/ZCTUMQELh3Mf7XfAEUxR0csFNjN4xvXF5IEhp6UprXG8YAdDVjwJx8Os+z3n3hXL3rZF9mxv1HeqXRUsymXYPbao5x37eQxE2/bRG9da80a+FDlAnHW5SZFJD1NarHoypu2mYtdM+AwSUXzH26P/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708751270; c=relaxed/simple; bh=MUCelfbEnJxFc4UHpHb7G3ylE0wMOiFfSiBd7d0DJ2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bdqyU9wkRM20820yPmJzJ9WI5yIm4OJwx9WvDD/JE/1J8aEWO/5rVIAl6JIZu9q6cFW3pzyNHTp0rNXHZnGKLeeUBk8GU1g2nc2/hUz0vm2/r3RNfnZKd4XAwbuwZ+5VfShBYaHEW9AupMNUS6H1eOjAwRXDhFzNtHaUFII+TGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=t/+drhIz; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="t/+drhIz" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1dbf1fe91fcso13463525ad.3 for ; Fri, 23 Feb 2024 21:07:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1708751268; x=1709356068; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7/8si6PIugm/jB7oq1cCOR5SjQTiCtweC1NZaO9RyUw=; b=t/+drhIzf7O8IuRssSrGg/xX/azyByl9zJhPXcPbkSeO5YGPnv2XrFpzZQlxbPiWCo PyHZcJhyEKaWXThmgJqBeQtONqi00qSZCZ97MpPjyVrjaqT8c9XdogaMTT6oPQ1GH6Lq /AU8lDVVViQBHBwmAdMGp444nmwvPYN5d7wXgv+s8VbKLPVOkjTUVzNsaa3+ArMDwf/G +jDu48XfLnSXszQxVhk/RXAFQRTekVWhPV+kfxeWr6e4VZzVl1FIbXwZoX/dGUzceoFT jgxj2mHfwFhtoqBh3xl4V5Zx16t+iIIwJvetR0H0xAKfX4DKmLW27eVg7pifnWuWNPsd 6w4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708751268; x=1709356068; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7/8si6PIugm/jB7oq1cCOR5SjQTiCtweC1NZaO9RyUw=; b=lbxI3OhPey6rVKoxv3a9rQg2RvHCun3R0I+DRrL4M/vWzIlC3eOCs5P8GcV9ip9qYl kAvhjT2BA9fTG52SBsIujiX172q9QClImH3ui3qlAffBT3Hy3cMz4cXW74qsokPJsNef /uNkOUFKWtbyOrBuTT4yPEZgp9ElfWManvXH2ZVt8tlMNWHag2MsjovH9JjrG+uqMNdO xADbDSoN2S/Oxlbb1CvzoJAC+2DhVk1yUHpWJkkzvQZPj8vV6gnd0vlHNO14YxKjOhtI DO8q5Sst8PDkktSc90//OcVgoFOdhVIhxyLAGlq0q/Gg7hDOpGZlprczAFi0DMNa6HdI 5X7A== X-Gm-Message-State: AOJu0YzSVjh2UA6pUOfwKDStiIRpeDhXx4xzJZynZJ8Qa09rC+peCFcm pqzhbjmunOHE5v/E+JEzAnQQhWSZ9KkDbKod5T1OhA+UH60Inenkdc9OUOV7BYSMKdw4FMvARwi k X-Google-Smtp-Source: AGHT+IEeQEvl+Mp9NheHJPx3zrz3pgzqlutQxuiT0sREP9a7FR2DnCRfK4y/ewMMw+/SuLva6AGkkQ== X-Received: by 2002:a17:902:eb8c:b0:1d8:ee44:629d with SMTP id q12-20020a170902eb8c00b001d8ee44629dmr2367222plg.30.1708751267886; Fri, 23 Feb 2024 21:07:47 -0800 (PST) Received: from localhost (fwdproxy-prn-000.fbsv.net. [2a03:2880:ff::face:b00c]) by smtp.gmail.com with ESMTPSA id z5-20020a170902ee0500b001d9620dd3fdsm259882plb.206.2024.02.23.21.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 21:07:47 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov Subject: [PATCH v1 3/4] liburing: add helper for IORING_REGISTER_IOWAIT Date: Fri, 23 Feb 2024 21:07:34 -0800 Message-ID: <20240224050735.1759733-3-dw@davidwei.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240224050735.1759733-1-dw@davidwei.uk> References: <20240224050735.1759733-1-dw@davidwei.uk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: David Wei Sync include/liburing/io_uring.h and add io_uring_register_iowait() helper function. Currently we unconditionally account time spent waiting for events in CQ ring as iowait time. Some userspace tools consider iowait time to be CPU util/load which can be misleading as the process is sleeping. High iowait time might be indicative of issues for storage IO, but for network IO e.g. socket recv() we do not control when the completions happen so its value misleads userspace tooling. Add io_uring_register_iowait() which gates the previously unconditional iowait accounting. By default time is not accounted as iowait, unless this is explicitly enabled for a ring. Thus userspace can decide, depending on the type of work it expects to do, whether it wants to consider cqring wait time as iowait or not. Signed-off-by: David Wei --- src/include/liburing.h | 2 ++ src/include/liburing/io_uring.h | 3 +++ src/register.c | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/src/include/liburing.h b/src/include/liburing.h index 6850fa7..5e39cc6 100644 --- a/src/include/liburing.h +++ b/src/include/liburing.h @@ -241,6 +241,8 @@ int io_uring_register_file_alloc_range(struct io_uring *ring, int io_uring_register_napi(struct io_uring *ring, struct io_uring_napi *napi); int io_uring_unregister_napi(struct io_uring *ring, struct io_uring_napi *napi); +int io_uring_register_iowait(struct io_uring *ring, int enabled); + int io_uring_get_events(struct io_uring *ring); int io_uring_submit_and_get_events(struct io_uring *ring); diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h index bde1199..ba94955 100644 --- a/src/include/liburing/io_uring.h +++ b/src/include/liburing/io_uring.h @@ -570,6 +570,9 @@ enum { IORING_REGISTER_NAPI = 27, IORING_UNREGISTER_NAPI = 28, + /* account time spent in cqring wait as iowait */ + IORING_REGISTER_IOWAIT = 29, + /* this goes last */ IORING_REGISTER_LAST, diff --git a/src/register.c b/src/register.c index f9bc52b..7f2890e 100644 --- a/src/register.c +++ b/src/register.c @@ -368,3 +368,9 @@ int io_uring_unregister_napi(struct io_uring *ring, struct io_uring_napi *napi) return __sys_io_uring_register(ring->ring_fd, IORING_UNREGISTER_NAPI, napi, 1); } + +int io_uring_register_iowait(struct io_uring *ring, int enabled) +{ + return __sys_io_uring_register(ring->ring_fd, + IORING_REGISTER_IOWAIT, NULL, enabled); +} From patchwork Sat Feb 24 05:07:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13570244 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E439B12E51 for ; Sat, 24 Feb 2024 05:07:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708751271; cv=none; b=TCMXndaMbvzt7vjqZdRRlqs3Qtz2MYTh0KTwPGcBT6b5UXmrfSY+9K8sD29OpGsQ96ERaFWa2f3FUtmPzx2TovbfHxypd7YpYw4uJroSiZ9qo6WjcgcKkA5J97nipfVi49/G2fbOQpgikOMFMInyB1mNGP+bwczmbEBGftAGmBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708751271; c=relaxed/simple; bh=2o8hV7HXk8RnWZU0l/awuXlvNoVcC6EOX0n+qzkiK5k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kVfdb2M/I6Fkc9uEKhLPzGNm1P3OX3hgZq/nCzn1uj9gK0hT+mz3HcavEeaTkGW6uV3Folj/LLbwUr4O8NYK30uxTD7H+9zIoVzAjzcXc4DIA57DWcEpjLyHjwtrrotQKB518duRnCVlzmBd5BhSKsf95W4AfeJIuuP1sSJgqfU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=mrhtn8CD; arc=none smtp.client-ip=209.85.215.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="mrhtn8CD" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-5dbcfa0eb5dso1344309a12.3 for ; Fri, 23 Feb 2024 21:07:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1708751269; x=1709356069; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wjBQFgNMe4f+4ZKhFs7JtH4JtEkCLrwOLfbsses+mMA=; b=mrhtn8CDLF4zY1WTIEtKc0GJE1to8tdhzLN92bLz0DqPYiXdoW47uH27xOyFf3MMc+ Qwz4YXg7qG2EhTPsQSZ8MDahJNhe0U5XEz7Q4xobXvfSOdqzEI/B/R+RPOdKQmWF3W98 sWUe/DU+wv2L34Lxdwi0t+t+2r+uIBDOQ93ZCbL0sDBavAcKqMy/DZpKUuDcuMrqPB8p yXT3vtuKrMzs4zlEDbrlXQoqxVCvrNjQcqj8MM2I9GUUTpT2xWwDiJeLNf3MF9rTwoGk qC8lUMhyEwY9PBjhw2so6i9ywlLNmB4E4uo3lsbGa2N4qU3ytzOfDg69xVqQimIJIy5h mZ/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708751269; x=1709356069; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wjBQFgNMe4f+4ZKhFs7JtH4JtEkCLrwOLfbsses+mMA=; b=hGTLzBEeP+uoRv49K5JrN21+KRnYehGs4aCigqMJzmxu3vkB2WDMqVD0fts6lVjPYM Dc8Oj1cr0UXK+mLRsOzLtHH19lU+vrSLaj2xpvXS3qpneR2YHwCj2skU/aQcKFo5jFJe TmuWGvRHb8SqPBeAxHw3DZRaeUCZFGIuZ5tSvFm2+V2Y1GEITymopNl1oVwFJJnlgXpj Vv9RkZVKuLbCenhLFvuJtZtLd0M5PmV0B/mwmopM6y92CYxSUiCyXkjWwgzT4ziAf0f9 47Gogdwp7w3Ohzowv5ESFoOHMCb7yhc3n7vSltfQOqUu7jMlhhTC2+aFcJ59XFouXGBn zDiQ== X-Gm-Message-State: AOJu0Yw538CfcDpL2VRHvTvCVzsLOOWrBMWvHZ+Tdxo9HvkslkNgP/IK 6fxTQN+b+vej594YK+8RnBxsHsoLuc9bmK3Y40lSZltQiHviTZnJukY5M3gsY1pnSN+wsVtSSE0 / X-Google-Smtp-Source: AGHT+IFs3rw5IZzr0fNOKsez6d/HhQbKqAItyxSEAA2qhxhLqiBqI6Sq3e6RzRFVifRwUcIwH6rs7w== X-Received: by 2002:a05:6a00:26ed:b0:6e3:759b:cdde with SMTP id p45-20020a056a0026ed00b006e3759bcddemr1670871pfw.33.1708751268976; Fri, 23 Feb 2024 21:07:48 -0800 (PST) Received: from localhost (fwdproxy-prn-118.fbsv.net. [2a03:2880:ff:76::face:b00c]) by smtp.gmail.com with ESMTPSA id s15-20020a62e70f000000b006e4701c0aedsm322267pfh.213.2024.02.23.21.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 21:07:48 -0800 (PST) From: David Wei To: io-uring@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov Subject: [PATCH v1 4/4] liburing: add unit test for io_uring_register_iowait() Date: Fri, 23 Feb 2024 21:07:35 -0800 Message-ID: <20240224050735.1759733-4-dw@davidwei.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240224050735.1759733-1-dw@davidwei.uk> References: <20240224050735.1759733-1-dw@davidwei.uk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: David Wei Add a unit test for io_uring_register_iowait() by creating a thread that writes into a pipe after a delay, checking iowait before and after. Signed-off-by: David Wei --- test/Makefile | 1 + test/iowait.c | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 test/iowait.c diff --git a/test/Makefile b/test/Makefile index b09228f..779a7db 100644 --- a/test/Makefile +++ b/test/Makefile @@ -107,6 +107,7 @@ test_srcs := \ io_uring_passthrough.c \ io_uring_register.c \ io_uring_setup.c \ + iowait.c \ lfs-openat.c \ lfs-openat-write.c \ link.c \ diff --git a/test/iowait.c b/test/iowait.c new file mode 100644 index 0000000..fcd4004 --- /dev/null +++ b/test/iowait.c @@ -0,0 +1,157 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Description: Test that waiting for CQ is accounted as iowait if enabled via + * io_uring_register_iowait(), and vice versa. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "liburing.h" +#include "helpers.h" + +struct data { + pthread_barrier_t startup; + int out_fd; +}; + +static unsigned long long get_iowait() +{ + FILE *fp; + char buf[256]; + unsigned long long user, nice, system, idle, iowait; + + fp = fopen("/proc/stat", "r"); + if (!fp) { + perror("fopen"); + exit(T_EXIT_FAIL); + } + + if (fgets(buf, sizeof(buf), fp) == NULL) { + perror("fgets"); + fclose(fp); + exit(T_EXIT_FAIL); + } + fclose(fp); + + sscanf(buf, "cpu %llu %llu %llu %llu %llu", &user, &nice, &system, + &idle, &iowait); + + return iowait; +} + +static void *pipe_write(void *data) +{ + struct data *d = data; + char buf[32]; + int ret; + + memset(buf, 0x55, sizeof(buf)); + pthread_barrier_wait(&d->startup); + usleep(100000); + + ret = write(d->out_fd, buf, sizeof(buf)); + if (ret < 0) { + perror("write"); + return NULL; + } + + return NULL; +} + +static int test_iowait(struct io_uring *ring, bool enabled) +{ + unsigned long long iowait_pre, iowait_post, iowait; + double iowait_ms_max_diff; + struct io_uring_cqe *cqe; + struct io_uring_sqe *sqe; + pthread_t thread; + double iowait_ms; + int ret, fds[2]; + struct data d; + char buf[32]; + void *tret; + + if (pipe(fds) < 0) { + perror("pipe"); + return T_EXIT_FAIL; + } + d.out_fd = fds[1]; + + pthread_barrier_init(&d.startup, NULL, 2); + pthread_create(&thread, NULL, pipe_write, &d); + pthread_barrier_wait(&d.startup); + + io_uring_register_iowait(ring, enabled); + + sqe = io_uring_get_sqe(ring); + io_uring_prep_read(sqe, fds[0], buf, sizeof(buf), 0); + + io_uring_submit(ring); + + iowait_pre = get_iowait(); + ret = io_uring_wait_cqe(ring, &cqe); + if (ret) { + fprintf(stderr, "wait_cqe: %d\n", ret); + return T_EXIT_FAIL; + } + io_uring_cq_advance(ring, 1); + + iowait_post = get_iowait(); + + /* + * writer sleeps for 100 ms, so max diff is 100 plus a tolerance of + * 10 ms + */ + iowait_ms_max_diff = (enabled ? 100.0 : 0.0) + 10.0; + + if (iowait_post > iowait_pre) + iowait = iowait_post - iowait_pre; + else + iowait = iowait_pre - iowait_post; + iowait_ms = ((double)iowait / sysconf(_SC_CLK_TCK)) * 1000; + + if (iowait_ms > iowait_ms_max_diff) + ret = T_EXIT_FAIL; + else + ret = T_EXIT_PASS; + + pthread_join(thread, &tret); + close(fds[0]); + close(fds[1]); + return ret; +} + +int main(int argc, char *argv[]) +{ + struct io_uring ring; + struct io_uring_params p = { }; + int ret; + + if (argc > 1) + return 0; + + ret = t_create_ring_params(8, &ring, &p); + if (ret == T_SETUP_SKIP) + return T_EXIT_SKIP; + else if (ret != T_SETUP_OK) + return ret; + + ret = test_iowait(&ring, false); + if (ret == T_EXIT_FAIL || ret == T_EXIT_SKIP) + return ret; + + ret = test_iowait(&ring, true); + if (ret == T_EXIT_FAIL || ret == T_EXIT_SKIP) + return ret; + + io_uring_queue_exit(&ring); + return T_EXIT_PASS; +}