Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1076196rdb; Mon, 19 Feb 2024 03:39:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW5xBytjylsTmMhFT5to/dB2fyOrhUWBDjjdAsYZF8l4XkCpE9/1Tn5CiCPEvFy6N+cJWYjYPekmX8Ijh9vP/sO4pBCpYcqem5lknNrsA== X-Google-Smtp-Source: AGHT+IErzpgaxbeWujlK2jwqA3BLmA6oALBJvTdvscdni5Vm8dabwbsjAEoBdyRfdIHTPPW5hSCn X-Received: by 2002:ac2:593b:0:b0:512:b366:6c42 with SMTP id v27-20020ac2593b000000b00512b3666c42mr1603261lfi.32.1708342753112; Mon, 19 Feb 2024 03:39:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708342753; cv=pass; d=google.com; s=arc-20160816; b=oI0YavX2VhK1EHbzxr2zJknVM4nfvCkobt6kWiPyL3HitN/WQIvJVi772uxjMGfYJJ cUVJY4v7iOkf+0t+MTWRRmwNTgORSthfeGVrY8NAPsS9gmcg3YcU1KH6bpxibtoJfyf/ DoYsLuIuwYYZ600R3GALxTpXJFG01mVnrTAPH+Z9vh8cCjRbtkgjb52VqpWwmrmKW5uK MQzjbLAC1oD4ffDWZVbrL7nAKZdxUQTbRYs/oQYloo2om6Z/Zoeh6ewXb7AUlJmJ73z3 PAi3G6dX2JGrq0NoiLus74oZEOX5AplnCUUcpGQ7L3B4rXNnJFHsVQMUdwZLJOGyn9/1 xJIA== 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=RgCc9xkjAlHBUoV30Un9Gq7IYtTdQzKUjRHl/TDRQVI=; fh=WJOVIats7bV4zPIhU2JdeHCO1u/8rnv1bp9HN81/COQ=; b=rhgb9l0ciqfGWQXKvpp/DuE3wlFKl2F+WPcFo1v1yPQ995/KgAfxJgrYwc5jnM5klH YkmbXHmDexmfVkmIoNngNKvOHNrOhracWAJbZdXlouE5//Wgin03lL+1l1luVfa3X6ci a/J5MSuAfK6cRHhPCASSRv2hgotIjulPS4+6k35cN8SfgsjjZRD0LgZxx2b0pfpbeXtf ozM/iYt9D0rAHVpPcqS1Yuj3iBDcRDuxHo0iOppTilvkRi30TMXUO3Gb+aZ++OP26vO/ L9J7E+R8ovpQB6QL4VgWGkDin/BETAhBdsEPDhX2eGtEHT3drJcs2BotJZEZnmVrs2bs qaSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="dUCI/3Yo"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-71221-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71221-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id q27-20020a50cc9b000000b00564348e3ef0si1677884edi.146.2024.02.19.03.39.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 03:39:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71221-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="dUCI/3Yo"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-71221-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71221-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 AD55E1F21ED4 for ; Mon, 19 Feb 2024 11:39:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E28002C694; Mon, 19 Feb 2024 11:38:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="dUCI/3Yo" Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 F39C02C861 for ; Mon, 19 Feb 2024 11:38:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708342733; cv=none; b=JNiQbqfmTsTUEm6aqvz5Db6zKUNraK82RvKr+pXkgtzZEsISg7GXsbR/FcQrfdyo1riPwVOV8HK/2buGNrORk9wZqX/KOA8+yh63HgaKZerxzfX+EhHbxL1hmC9jaLcy4BgwKNYK9adU00Lz+0TSXT6kFx1IcwqzFbaLOS7Bx0s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708342733; c=relaxed/simple; bh=jr44VXtqh1WfN5s8vQyEdoQue8G83eRGigWTX8V3R/U=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=iVkwMZFObv5O7Y/U4gys+ybVUfwDgAOPKQ+b8zX/+0dlXMqiFDBSq6zyN3+zVhAWJbkelSYJ/pui3vQ30vP0AWxTA31VgkwRUF2StdiICKs2RO0yUFjfnm6W5Z4/v8ACsaX/SpTAC3usObghpidf1GtuaJRpWLvblasqqfA3pBc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=dUCI/3Yo; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-33d153254b7so1871622f8f.0 for ; Mon, 19 Feb 2024 03:38:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708342730; x=1708947530; 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=RgCc9xkjAlHBUoV30Un9Gq7IYtTdQzKUjRHl/TDRQVI=; b=dUCI/3YoLDn74dH7MKxWqlh6o+/F141AOh/fE41nsuSgNjweRLMuvwCNxUjW8ujySG ujtf+dgRgSoYWsvebx8Mxy2MOG4OTs4qg6Kk5Yjvqrt/0xQUsU+SwC5WCHccwCJLmnW7 D3IWDBT8sE+k9iX6YG60OUJNZN1P1H0zwRQ6ohUwXdF9ft29zjWRIYUcSXl2BlNrJ9U+ KT2I+nffPIB3fcknUe/T1X5BdL51/aJ6cZJAOAInKPi7U3pyNyDeMk3ODDpE9NrqxuIU KMPIDpT1hDo+sL0aSbZQAWv2ustU4kuW2Y2rdd6F0clmXIwdWgMSK2dxr7JQRweIkyEy lcLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708342730; x=1708947530; 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=RgCc9xkjAlHBUoV30Un9Gq7IYtTdQzKUjRHl/TDRQVI=; b=cRrnEZP7aeCxUtrhHPj1aksnX+Ym4IazsIsc44mU+VREDlXt/O3ZDbLgc8Gt8mkINt geIiAMSFBS5F/svgcOz7YUTLV2uGiVXc1+qYSY8WL1lZSFVFzvdMJ9CsmUoQkoH1Mkz/ gbnA4pBTHIRJMi0t6ssdFte6rtAfZwPDEB+fQFdbcKmtGRs6+XoExsb92xqycBHpsSUM oe8EoY29C8FqYO48ntI1ww6TIgFlif/cmacEGFv7TH/2ltrf5nZETd+dR5nawAEutQEk TtO2TghUO40Aa+zLTnjXBWbtEeJFcMgZPtlBzyfP6X3hHThcKrHxeecBg0I2PfkV7r2Y HgCQ== X-Forwarded-Encrypted: i=1; AJvYcCU/St0Gba3bX+v9r7d0jXlsEjUASg8GpO7OpLApoqQrsRkXx18GsAXRjQ1ESPIAbGqoytnVwDoSOxUR9BihxuMjsUnIFm/mAEeNdxok X-Gm-Message-State: AOJu0Yz5c/fWPgEdL4I8O87JOlQ65FizZVY+sBNVu+oeZD3rRKcf1ebC pDZlhGAeJjYNIlKxnKvYq53mHgCwOlPUfvZseITrHOg5+XBs688cyxhkNKLkxxU= X-Received: by 2002:a5d:4e52:0:b0:33d:3909:ff6 with SMTP id r18-20020a5d4e52000000b0033d39090ff6mr3046644wrt.29.1708342730078; Mon, 19 Feb 2024 03:38:50 -0800 (PST) Received: from [192.168.2.107] ([79.115.63.202]) by smtp.gmail.com with ESMTPSA id e14-20020a5d4e8e000000b0033cdf1f15e8sm10152630wru.16.2024.02.19.03.38.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Feb 2024 03:38:49 -0800 (PST) Message-ID: <058be836-bcd4-403e-bbc3-bb75f3f3d896@linaro.org> Date: Mon, 19 Feb 2024 11:38:48 +0000 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 v2] spi: spi-mem: add statistics support to ->exec_op() calls Content-Language: en-US To: =?UTF-8?Q?Th=C3=A9o_Lebrun?= , Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Dhruva Gole , Gregory CLEMENT , Vladimir Kondratiev , Thomas Petazzoni , Tawfik Bayouk References: <20240216-spi-mem-stats-v2-1-9256dfe4887d@bootlin.com> From: Tudor Ambarus In-Reply-To: <20240216-spi-mem-stats-v2-1-9256dfe4887d@bootlin.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 2/16/24 16:42, Théo Lebrun wrote: > Current behavior is that spi-mem operations do not increment statistics, > neither per-controller nor per-device, if ->exec_op() is used. For > operations that do NOT use ->exec_op(), stats are increased as the > usual spi_sync() is called. > > The newly implemented spi_mem_add_op_stats() function is strongly > inspired by spi_statistics_add_transfer_stats(); locking logic and > l2len computation comes from there. > > Statistics that are being filled: bytes{,_rx,_tx}, messages, transfers, > errors, timedout, transfer_bytes_histo_*. > > Note about messages & transfers counters: in the fallback to spi_sync() > case, there are from 1 to 4 transfers per message. We only register one > big transfer in the ->exec_op() case as that is closer to reality. > > This patch is NOT touching: > - spi_async, spi_sync, spi_sync_immediate: those counters describe > precise function calls, incrementing them would be lying. I believe > comparing the messages counter to spi_async+spi_sync is a good way > to detect ->exec_op() calls, but I might be missing edge cases > knowledge. > - transfers_split_maxsize: splitting cannot happen if ->exec_op() is > provided. > > Reviewed-by: Dhruva Gole > Signed-off-by: Théo Lebrun --- > Changes in v2: > - Turn len and l2len into u64. Remove casts on all 4 nbytes fields. > Remove clamp of l2len to be positive. > - Replace "xferred" in comment by "transferred". > - Remove sysfs demo from commit message. Moved to below the tear line. > - Take Reviewed-by Dhruva Gole. > - Link to v1: https://lore.kernel.org/r/20240209-spi-mem-stats-v1-1-dd1a422fc015@bootlin.com Reviewed-by: Tudor Ambarus > --- > > Testing this patch: > > $ cd /sys/devices/platform/soc > $ find . -type d -path "*spi*" -name statistics > ./2100000.spi/spi_master/spi0/statistics > ./2100000.spi/spi_master/spi0/spi0.0/statistics > $ cd ./2100000.spi/spi_master/spi0/statistics > > $ for f in *; do printf "%s\t" $f; cat $f; done | \ > grep -v transfer_bytes_histo | column -t > bytes 240745444 > bytes_rx 240170907 > bytes_tx 126320 > errors 0 > messages 97354 > spi_async 0 > spi_sync 0 > spi_sync_immediate 0 > timedout 0 > transfers 97354 > transfers_split_maxsize 0 > --- > drivers/spi/spi-mem.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 48 insertions(+), 1 deletion(-) > > diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c > index 2dc8ceb85374..c9d6d42a88f5 100644 > --- a/drivers/spi/spi-mem.c > +++ b/drivers/spi/spi-mem.c > @@ -297,6 +297,49 @@ static void spi_mem_access_end(struct spi_mem *mem) > pm_runtime_put(ctlr->dev.parent); > } > > +static void spi_mem_add_op_stats(struct spi_statistics __percpu *pcpu_stats, > + const struct spi_mem_op *op, int exec_op_ret) > +{ > + struct spi_statistics *stats; > + u64 len, l2len; > + > + get_cpu(); > + stats = this_cpu_ptr(pcpu_stats); > + u64_stats_update_begin(&stats->syncp); > + > + /* > + * We do not have the concept of messages or transfers. Let's consider > + * that one operation is equivalent to one message and one transfer. > + */ > + u64_stats_inc(&stats->messages); > + u64_stats_inc(&stats->transfers); > + > + /* Use the sum of all lengths as bytes count and histogram value. */ > + len = op->cmd.nbytes + op->addr.nbytes; > + len += op->dummy.nbytes + op->data.nbytes; > + u64_stats_add(&stats->bytes, len); > + l2len = min(fls(len), SPI_STATISTICS_HISTO_SIZE) - 1; > + u64_stats_inc(&stats->transfer_bytes_histo[l2len]); > + > + /* Only account for data bytes as transferred bytes. */ > + if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_OUT) > + u64_stats_add(&stats->bytes_tx, op->data.nbytes); > + if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_IN) > + u64_stats_add(&stats->bytes_rx, op->data.nbytes); > + > + /* > + * A timeout is not an error, following the same behavior as > + * spi_transfer_one_message(). > + */ > + if (exec_op_ret == -ETIMEDOUT) > + u64_stats_inc(&stats->timedout); > + else if (exec_op_ret) > + u64_stats_inc(&stats->errors); > + > + u64_stats_update_end(&stats->syncp); > + put_cpu(); > +} > + > /** > * spi_mem_exec_op() - Execute a memory operation > * @mem: the SPI memory > @@ -339,8 +382,12 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) > * read path) and expect the core to use the regular SPI > * interface in other cases. > */ > - if (!ret || ret != -ENOTSUPP || ret != -EOPNOTSUPP) > + if (!ret || ret != -ENOTSUPP || ret != -EOPNOTSUPP) { > + spi_mem_add_op_stats(ctlr->pcpu_statistics, op, ret); > + spi_mem_add_op_stats(mem->spi->pcpu_statistics, op, ret); > + > return ret; > + } > } > > tmpbufsize = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes; > > --- > base-commit: 19b50f80b3a4865bd477aa5c026dd234d39a50d2 > change-id: 20240209-spi-mem-stats-ff9bf91c0f7e > > Best regards,