Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3571509pxp; Tue, 8 Mar 2022 17:45:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzqSwxnVzxB18WUfSQUbufIwvwXfSyEm/yfIlH8WDWD76e297pF+5LMeVKiqcwBN71VeY6w X-Received: by 2002:a17:90a:a594:b0:1bc:5def:a652 with SMTP id b20-20020a17090aa59400b001bc5defa652mr7866277pjq.167.1646790356911; Tue, 08 Mar 2022 17:45:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646790356; cv=none; d=google.com; s=arc-20160816; b=HGMAjhkNmJtpMyDwHF+Y5wZO+QAlf5mGSc82zUOJJlGiz8T32MuqARoJUZHGR2Er7E jREwya19EhBxC+ZPyRzvoeSHBqN0aFv8jWbxHEsw3ofVcFmHrv3z7OzYnEQkZ6GNdpSN HP1sp2zlwdk+LE9ju7J5qNMk5t1u3lQgrTTGbrXiB+0iFmc9AK6RLxZUIhPzEcFobtD7 BxcxuchEA7XjvqKJ4mcPS3gJbRD0jEqmM9XXz2vAAkEzNG3Oi5uS7Na0yCgzGpk0WQ80 NEjoXOeS2nEqcOyISUQ2TPkvZUedCFvve1MPLG+wP3YsxvoIGLr/QOzrDjQPaWqpNmmm t93g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=b7kO3iWm15EvapePA/ECt2i9qYdGIfAsX2tQXFI7Sds=; b=t4yujwMOtow3sod6wfUkt2bucVKFqBTPTdJX/P7FHACGU6dPDkIfwby07GBq2ihpey S8jukTe+Ty+B/DRYu0vWVV3m7hyRhka/ukV5ZMo+tmyERbJwJzNX+iePBXjh1xF609Kt gOFXBxM1+z9yDTyOHX+4XdqrvI2Xct3hoXKayyBWXtgXsKriVnZm/ZzdUz4mc7fPCD6e sPhS8xB5DVaGw+oGJbqOleXpAuOGJQVErF2Oy229yxgt6A5i6A7QqtEjVThSk9LYeDFX +Se4OVIKyZINPjSz9zJb4gW531NUBxE3wiZGU7vEzCZ6FuHOlwq28VDQ1Vgz82RiJRBw qDRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=GkmOoIJE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id bb7-20020a170902bc8700b0014f1dc20455si565202plb.456.2022.03.08.17.45.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 17:45:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=GkmOoIJE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C09FD1CBA92; Tue, 8 Mar 2022 16:23:59 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245091AbiCGTaa (ORCPT + 99 others); Mon, 7 Mar 2022 14:30:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbiCGTa2 (ORCPT ); Mon, 7 Mar 2022 14:30:28 -0500 Received: from alexa-out.qualcomm.com (alexa-out.qualcomm.com [129.46.98.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB6917DE22; Mon, 7 Mar 2022 11:29:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1646681374; x=1678217374; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=b7kO3iWm15EvapePA/ECt2i9qYdGIfAsX2tQXFI7Sds=; b=GkmOoIJExJ5lbkB2TkhF32YtEZ5MCevCO/IXEG+Cwza2OF8Qq26h7KPF JOSxvIlS/N3OdiwSyxjVIIpD7gIKk8pEWEfte/qm3wpdrcFRvd30uTR0O j+55xSQ1gyW1gdtEixITrdPKAOVa272buQHtg7lqOf0EbwRH6xlXxRKhR U=; Received: from ironmsg07-lv.qualcomm.com ([10.47.202.151]) by alexa-out.qualcomm.com with ESMTP; 07 Mar 2022 11:29:33 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg07-lv.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2022 11:29:33 -0800 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.15; Mon, 7 Mar 2022 11:29:32 -0800 Received: from [10.110.30.142] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.15; Mon, 7 Mar 2022 11:29:31 -0800 Message-ID: Date: Mon, 7 Mar 2022 11:29:30 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: [PATCH] i2c: add tracepoints for I2C slave events Content-Language: en-US To: Steven Rostedt CC: Wolfram Sang , Ingo Molnar , Jamie Iles , Graeme Gregory , , References: <20220307182049.3790905-1-quic_jaehyoo@quicinc.com> <20220307141305.18f0c20b@gandalf.local.home> From: Jae Hyun Yoo In-Reply-To: <20220307141305.18f0c20b@gandalf.local.home> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Steven, On 3/7/2022 11:13 AM, Steven Rostedt wrote: > On Mon, 7 Mar 2022 10:20:49 -0800 > Jae Hyun Yoo wrote: > >> I2C slave events tracepoints can be enabled by: >> >> echo 1 > /sys/kernel/tracing/events/i2c_slave/enable >> >> and logs in /sys/kernel/tracing/trace will look like: >> >> ... i2c_slave: i2c-0 a=010 WR_REQ [] >> ... i2c_slave: i2c-0 a=010 WR_RCV [02] >> ... i2c_slave: i2c-0 a=010 WR_RCV [0c] >> ... i2c_slave: i2c-0 a=010 STOP [] >> ... i2c_slave: i2c-0 a=010 RD_REQ [04] >> ... i2c_slave: i2c-0 a=010 RD_PRO [b4] >> ... i2c_slave: i2c-0 a=010 STOP [] >> >> formatted as: >> >> i2c- >> a= >> >> [] >> >> trace printings can be selected by adding a filter like: >> >> echo adapter_nr==1 >/sys/kernel/tracing/events/i2c_slave/filter >> >> Signed-off-by: Jae Hyun Yoo >> --- >> drivers/i2c/i2c-core-slave.c | 15 +++++++++ >> include/linux/i2c.h | 8 ++--- >> include/trace/events/i2c_slave.h | 57 ++++++++++++++++++++++++++++++++ >> 3 files changed, 74 insertions(+), 6 deletions(-) >> create mode 100644 include/trace/events/i2c_slave.h >> >> diff --git a/drivers/i2c/i2c-core-slave.c b/drivers/i2c/i2c-core-slave.c >> index 1589179d5eb9..4968a17328b3 100644 >> --- a/drivers/i2c/i2c-core-slave.c >> +++ b/drivers/i2c/i2c-core-slave.c >> @@ -14,6 +14,9 @@ >> >> #include "i2c-core.h" >> >> +#define CREATE_TRACE_POINTS >> +#include >> + >> int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb) >> { >> int ret; >> @@ -79,6 +82,18 @@ int i2c_slave_unregister(struct i2c_client *client) >> } >> EXPORT_SYMBOL_GPL(i2c_slave_unregister); >> >> +int i2c_slave_event(struct i2c_client *client, >> + enum i2c_slave_event event, u8 *val) >> +{ >> + int ret = client->slave_cb(client, event, val); >> + >> + if (!ret) > > You can make the above into: > > if (trace_i2c_slave_enabled() && !ret) > > to make this conditional compare only happen if the tracepoint is enabled. > As the trace_i2c_slave_enabled() is a static branch (non-conditional jump). Right, that's better. I'll fix it in the next spin. >> + trace_i2c_slave(client, event, val); >> + >> + return ret; >> +} >> +EXPORT_SYMBOL_GPL(i2c_slave_event); >> + >> /** >> * i2c_detect_slave_mode - detect operation mode >> * @dev: The device owning the bus >> diff --git a/include/linux/i2c.h b/include/linux/i2c.h >> index 7d4f52ceb7b5..fbda5ada2afc 100644 >> --- a/include/linux/i2c.h >> +++ b/include/linux/i2c.h >> @@ -392,12 +392,8 @@ enum i2c_slave_event { >> int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb); >> int i2c_slave_unregister(struct i2c_client *client); >> bool i2c_detect_slave_mode(struct device *dev); >> - >> -static inline int i2c_slave_event(struct i2c_client *client, >> - enum i2c_slave_event event, u8 *val) >> -{ >> - return client->slave_cb(client, event, val); >> -} >> +int i2c_slave_event(struct i2c_client *client, >> + enum i2c_slave_event event, u8 *val); >> #else >> static inline bool i2c_detect_slave_mode(struct device *dev) { return false; } >> #endif >> diff --git a/include/trace/events/i2c_slave.h b/include/trace/events/i2c_slave.h >> new file mode 100644 >> index 000000000000..1f0c1cfbf2ef >> --- /dev/null >> +++ b/include/trace/events/i2c_slave.h >> @@ -0,0 +1,57 @@ >> +/* SPDX-License-Identifier: GPL-2.0-or-later */ >> +/* >> + * I2C slave tracepoints >> + * >> + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. >> + */ >> +#undef TRACE_SYSTEM >> +#define TRACE_SYSTEM i2c_slave >> + >> +#if !defined(_TRACE_I2C_SLAVE_H) || defined(TRACE_HEADER_MULTI_READ) >> +#define _TRACE_I2C_SLAVE_H >> + >> +#include >> +#include >> + >> +TRACE_EVENT(i2c_slave, >> + TP_PROTO(const struct i2c_client *client, enum i2c_slave_event event, >> + __u8 *val), >> + TP_ARGS(client, event, val), >> + TP_STRUCT__entry( >> + __field(int, adapter_nr ) >> + __field(__u16, addr ) >> + __field(enum i2c_slave_event, event ) >> + __field(__u16, len ) > > I would keep the u16 together: > > __field(int, adapter_nr ) > __field(__u16, addr ) > __field(__u16, len ) > __field(enum i2c_slave_event, event ) > > Otherwise you will likely have a hole in the event, which wastes space on > the ring buffer. Thanks for your pointing it out. I'll fix it too in v2. >> + __dynamic_array(__u8, buf, 1) ), >> + >> + TP_fast_assign( >> + __entry->adapter_nr = client->adapter->nr; >> + __entry->addr = client->addr; >> + __entry->event = event; >> + switch (event) { >> + case I2C_SLAVE_READ_REQUESTED: >> + case I2C_SLAVE_READ_PROCESSED: >> + case I2C_SLAVE_WRITE_RECEIVED: >> + __entry->len = 1; >> + memcpy(__get_dynamic_array(buf), val, __entry->len); > > Why the dynamic event, if it is always the size of 1? Why not make it an > array. It will save space, as the dynamic meta data has to live on the > event which is 4 bytes big. Just make it: > > __array(__u8, buf, 1); > > It's faster and saves space. Yes, the data length is always 1. I'll fix it too. Thanks a lot for your review and suggestions! I'll address all your comments in the next spin. -Jae > -- Steve > >> + break; >> + default: >> + __entry->len = 0; >> + break; >> + } >> + ), >> + TP_printk("i2c-%d a=%03x %s [%*phD]", >> + __entry->adapter_nr, __entry->addr, >> + __print_symbolic(__entry->event, >> + { I2C_SLAVE_READ_REQUESTED, "RD_REQ" }, >> + { I2C_SLAVE_WRITE_REQUESTED, "WR_REQ" }, >> + { I2C_SLAVE_READ_PROCESSED, "RD_PRO" }, >> + { I2C_SLAVE_WRITE_RECEIVED, "WR_RCV" }, >> + { I2C_SLAVE_STOP, " STOP" }), >> + __entry->len, __get_dynamic_array(buf) >> + )); >> + >> +#endif /* _TRACE_I2C_SLAVE_H */ >> + >> +/* This part must be outside protection */ >> +#include >