Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp631812rdb; Sun, 18 Feb 2024 05:00:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVwOcX2gzhIeHXhRxmWQ2s5hh+BVrofjo0hJsioML72jbRh6qXbFhKgNmcd4pyQMreQvMM+yHDLvUo7j2TWACHO5LugGeXYTkwaxra13Q== X-Google-Smtp-Source: AGHT+IGAHDMwIZlqFMi3/2tDdRDd0vKkCg5bmRfhYAAulqM2GizhjqIA3Fbcd5HOfYhUbYSlkbGV X-Received: by 2002:aa7:c551:0:b0:564:3190:9a4b with SMTP id s17-20020aa7c551000000b0056431909a4bmr1974077edr.22.1708261240339; Sun, 18 Feb 2024 05:00:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708261240; cv=pass; d=google.com; s=arc-20160816; b=ApCDE0GG5zVyoS6UFx2U9HqfEhy2WYQr882R27WJ6pky2JguwXHVujPUI3DXhXPIhD 8gENo3JABwRzG2Y47R0/oJaG5iI4ZnM8eDE9WJNgkQ6zP5ZDN8rdr9aUgFfylcmpEj8E beeQyyHCya1l9RsWEwdfuVg01M5iRy500LounnzQcOS6uNvfznoxpFaMIf1G+lczqHwL 8GIPlckajbOe0OWdM8lKRNcR2qDHZxodNFVARHRfZfGLumGjryiDpPkUjp/C59WGrgXL lpjgFYIxKps1ldL7Z9+8BFshH2XxNKJJtrDudrc0E/JLC/jlUTJTTki+4Rkue0Ga8hAT Vnvw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=5DawyGrCFv8MWM89ldx7BIpHWYPaoK4RaQ5rwdaLsT0=; fh=u11G0BUtBya+x9yN78OlVDtuHvnHf7k57Fa21JmGH7U=; b=Dz5uri0nlrQ2//HJedxtnLhJUwEfylmz+fsaKj8aqTy7Xo+UIRTyK9svris0x2Z/1E n7cEshn85NvfD5zEKtfRFIunBXT6DzDzxzLLjy9Pc6OVAZUOyPh+3RDEJRJc98A5tTF4 em35mtRB26ZbJanlmqHXuJuk0mepKJkXpcnyCABHjjkp/vu55xsM7MYtOHMTUDFptQM1 OSVdrFo+B4mPf56T9hb/+Wi/vhrw/o7J0cPcz3iPpGiLTqrXyy40fkHnFYJDpS8IoD7s ZCgRQObo6hi3Jziq24CIVZWIwUtV4QjCDqh5IXbdxTZoqrVdmltrYvFe2wNg0NNjZeLt PzOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=wsUtZUUM; arc=pass (i=1 spf=pass spfdomain=kernel.dk dkim=pass dkdomain=kernel-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-70392-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70392-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z12-20020aa7cf8c000000b0056022a0d6e5si1589714edx.466.2024.02.18.05.00.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 05:00:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70392-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=wsUtZUUM; arc=pass (i=1 spf=pass spfdomain=kernel.dk dkim=pass dkdomain=kernel-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-70392-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70392-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D6A851F2192D for ; Sun, 18 Feb 2024 13:00:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B3026BB51; Sun, 18 Feb 2024 13:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="wsUtZUUM" Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 E2AD36D1A7 for ; Sun, 18 Feb 2024 13:00:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708261234; cv=none; b=rbNRjNRw/s/QqXUHJPg9wNrXx0pCEiHcxR0DOGSZ6/Akm6vqxnZn9ZRFDxSLCqtdrUKNYg53Up9wNxga2ImCS2sKBV7R0SPfEPOgR0zHSmo6iFOsGbyZvd6OJ9TdMgLJL37+Bffcs4H0h8tGH55fFiXjcbzW3LGc3fAtRBtcSB8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708261234; c=relaxed/simple; bh=hRiD6dLKoUyrGjRFujHiRdx70/odMTcB4P8yipX7AkE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=hYNZL5uyXfRofKe6rV1kLqh4FOrgGWZVYqShX813c/GzrO1mQEaLkmfviMLTF2gKUCikDW912LOirsefuqUsCchaBo8cn6UtzKWXs3uo9P1UVJ/ahe1OkLfOvd9/tAaZlqmFGFal9XniyzR83JHOfJoyyxjWmFWw9M+RAFGDsb4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=wsUtZUUM; arc=none smtp.client-ip=209.85.216.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2866b15b013so993517a91.0 for ; Sun, 18 Feb 2024 05:00:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1708261211; x=1708866011; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=5DawyGrCFv8MWM89ldx7BIpHWYPaoK4RaQ5rwdaLsT0=; b=wsUtZUUMjTpUb8qpLctVUTL45iv/OHM0cIZj/jyBrT8Wb5vf9n/hpBBeBhfS9/fspA uGfZElHERt7d55UyCgGTcSka0bpl2VMyGxoFyH74CBDik8wFTKsnWeUu8ORqM6gRyG1U lE2fq5lpWh4WPRPQ1oaf8CgpEvRkJptQo5nmmbTdkazHiVXYwJbHm5m7yQgFBVWXcLF0 zj/jPF0aZlHka87tRVLWy0ND20no1o6OLS4OT45ehidUdJQXg/1ZEov84kdIf4IlZN1T dRZ44EY4c7GLnUEyRK8HwI+4ijI9An4UgjrKkRr8WKgz3k5XNNDeS1kEtCD+9+8giYP8 qhVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708261211; x=1708866011; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5DawyGrCFv8MWM89ldx7BIpHWYPaoK4RaQ5rwdaLsT0=; b=orjcOL4pGO//8lrZ9r1/qDHmetK+aZzHgl/U3ssWduK5J85HOiGqU/SXXOU0Ck4ZwB HROktX7whAJp78ym3h7sDgrikZ3fRfk35wTs+yYWvgT7IPzn4OtSkVJCAqeWlvhno63t xw7CgYxCv4AOD/83y32rl0l+k+EwcCt55JdX7SAaH4EVKwcxBdsSsnQL35NDDhwNPdw3 LzslFBdq72O0Mx/alXVP2cnXxAlox/FwziXj8nVlDRimFazMLDIfHrfan3NFc9XFm3U+ w85jsvrY+FEfmmaOlagp6wSi7GBflOUIUxTKmJqoHk0b9elDQZ8Zhq0uJerMwn0DxnJ9 ePaQ== X-Gm-Message-State: AOJu0YwN/U1JvXtrKJ20n+xcx9RMv7l15j/4ZcWqcXWOvLBQ1Rz7/Jvh vv+qH5FtesSpW3m2k5S1E4kfo/Js3najaqHbTF/abg82RIBxi1qYNMtINnLVoiI= X-Received: by 2002:a05:6a21:1a4:b0:1a0:810e:5f40 with SMTP id le36-20020a056a2101a400b001a0810e5f40mr10357528pzb.4.1708261211014; Sun, 18 Feb 2024 05:00:11 -0800 (PST) Received: from [192.168.1.150] ([198.8.77.194]) by smtp.gmail.com with ESMTPSA id 18-20020a631052000000b005d553239b16sm2906268pgq.20.2024.02.18.05.00.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 18 Feb 2024 05:00:10 -0800 (PST) Message-ID: <522c03d9-a8ba-459d-9f7c-dfbf461dcf6b@kernel.dk> Date: Sun, 18 Feb 2024 06:00:08 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v8] io_uring: Statistics of the true utilization of sq threads. Content-Language: en-US To: Xiaobing Li , asml.silence@gmail.com Cc: linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, kun.dou@samsung.com, peiwei.li@samsung.com, joshi.k@samsung.com, kundan.kumar@samsung.com, wenwen.chen@samsung.com, ruyi.zhang@samsung.com, cliang01.li@samsung.com, xue01.he@samsung.com References: <20240206023910.11307-1-xiaobing.li@samsung.com> From: Jens Axboe In-Reply-To: <20240206023910.11307-1-xiaobing.li@samsung.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2/5/24 7:39 PM, Xiaobing Li wrote: > Count the running time and actual IO processing time of the sqpoll > thread, and output the statistical data to fdinfo. > > Variable description: > "work_time" in the code represents the sum of the jiffies of the sq > thread actually processing IO, that is, how many milliseconds it > actually takes to process IO. "total_time" represents the total time > that the sq thread has elapsed from the beginning of the loop to the > current time point, that is, how many milliseconds it has spent in > total. > > The test tool is fio, and its parameters are as follows: > [global] > ioengine=io_uring > direct=1 > group_reporting > bs=128k > norandommap=1 > randrepeat=0 > refill_buffers > ramp_time=30s > time_based > runtime=1m > clocksource=clock_gettime > overwrite=1 > log_avg_msec=1000 > numjobs=1 > > [disk0] > filename=/dev/nvme0n1 > rw=read > iodepth=16 > hipri > sqthread_poll=1 > > --- If you put --- in here, then the rest of the commit message disappears. The way you format commit messages it to put things you don't want in the git log below it... This one should not be here. > > --- > The test results corresponding to different iodepths are as follows: Same with this one... > |-----------|-------|-------|-------|------|-------| > | iodepth | 1 | 4 | 8 | 16 | 64 | > |-----------|-------|-------|-------|------|-------| > |utilization| 2.9% | 8.8% | 10.9% | 92.9%| 84.4% | > |-----------|-------|-------|-------|------|-------| > | idle | 97.1% | 91.2% | 89.1% | 7.1% | 15.6% | > |-----------|-------|-------|-------|------|-------| > > changes? > v8: Here you need it, the changelog should be below the one and only --- you put in the commit message. > - Get the work time of the sqpoll thread through getrusage > > v7: > - Get the total time of the sqpoll thread through getrusage > - The working time of the sqpoll thread is obtained through ktime_get() > > v6: > - Replace the percentages in the fdinfo output with the actual running > time and the time actually processing IO > > v5? > - list the changes in each iteration. > > v4? > - Resubmit the patch based on removing sq->lock > > v3? > - output actual working time as a percentage of total time > - detailed description of the meaning of each variable > - added test results > > v2? > - output the total statistical time and work time to fdinfo > > v1? > - initial version > - Statistics of total time and work time > > Signed-off-by: Xiaobing Li And since your Signed-off-by is here, it also does not go into the commit message, which it must. > index 976e9500f651..18c6f4aa4a48 100644 > --- a/io_uring/fdinfo.c > +++ b/io_uring/fdinfo.c > @@ -64,6 +64,7 @@ __cold void io_uring_show_fdinfo(struct seq_file *m, struct file *f) > unsigned int sq_shift = 0; > unsigned int sq_entries, cq_entries; > int sq_pid = -1, sq_cpu = -1; > + u64 sq_total_time = 0, sq_work_time = 0; > bool has_lock; > unsigned int i; > > @@ -147,10 +148,17 @@ __cold void io_uring_show_fdinfo(struct seq_file *m, struct file *f) > > sq_pid = sq->task_pid; > sq_cpu = sq->sq_cpu; > + struct rusage r; Here, and in one other spot, you're mixing variable declarations and code. Don't do that, they need to be top of that scope and before any code. > diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c > index 65b5dbe3c850..9155fc0b5eee 100644 > --- a/io_uring/sqpoll.c > +++ b/io_uring/sqpoll.c > @@ -251,6 +251,9 @@ static int io_sq_thread(void *data) > } > > cap_entries = !list_is_singular(&sqd->ctx_list); > + struct rusage start, end; > + > + getrusage(current, RUSAGE_SELF, &start); Ditto, move the variables to the top of the scope. > list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) { > int ret = __io_sq_thread(ctx, cap_entries); > > @@ -260,6 +263,11 @@ static int io_sq_thread(void *data) > if (io_run_task_work()) > sqt_spin = true; > > + getrusage(current, RUSAGE_SELF, &end); > + if (sqt_spin == true) > + sqd->work_time += (end.ru_stime.tv_sec - start.ru_stime.tv_sec) * > + 1000000 + (end.ru_stime.tv_usec - start.ru_stime.tv_usec); > + and this should go in a helper instead. It's trivial code, but the way too long lines makes it hard to read. Compare the above to eg: static void io_sq_update_worktime(struct io_sq_data *sqd, struct rusage *start) { struct rusage end; getrusage(current, RUSAGE_SELF, &end); end.ru_stime.tv_sec -= start->ru_stime.tv_sec; end_ru_stime.tv_usec -= start->ru_stime.tv_usec; sqd->work_time += end.ru_stime.tv_usec + end.ru_stime.tv_sec * 1000000; } which is so much nicer to look at. We're already doing an sqt_spin == true check right below, here: > if (sqt_spin || !time_after(jiffies, timeout)) { > if (sqt_spin) > timeout = jiffies + sqd->sq_thread_idle; why not just put io_sq_update_worktime(sqd, &start); inside this check? > diff --git a/io_uring/sqpoll.h b/io_uring/sqpoll.h > index 8df37e8c9149..e99f5423a3c3 100644 > --- a/io_uring/sqpoll.h > +++ b/io_uring/sqpoll.h > @@ -16,6 +16,7 @@ struct io_sq_data { > pid_t task_pid; > pid_t task_tgid; > > + u64 work_time; > unsigned long state; > struct completion exited; > }; Not sure why this addition is indented differently than everything else in there? -- Jens Axboe