Received: by 10.223.164.202 with SMTP id h10csp1075604wrb; Thu, 9 Nov 2017 20:57:06 -0800 (PST) X-Google-Smtp-Source: ABhQp+T9pjrq9G/U/PAVJ5eyiElDApPlM5wKRaHLFQy+6lsi44UirpjcQvDG5Atd0i8grz+CjLid X-Received: by 10.101.82.193 with SMTP id z1mr2848723pgp.312.1510289826613; Thu, 09 Nov 2017 20:57:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510289826; cv=none; d=google.com; s=arc-20160816; b=ifB4nYyV3K2CHMd+HZ72wekYEjpGv2ehchSHgWPeX5Mv/gEatKZ3uwiFknLD6k+q3T 3qO8w3cO1vCjzZjZn1g+1IsuRDMGhZpdwmDlk8WU23Su97ssUoHaStzlI6BQLLd6DjRw no2yhDUEV/BJCmaG30rW08Cc7IstvtikAv3Nf6JelmquoN+SPPzl623AEWXYM29FKEy3 rJC9JuYdZljGISIVzJCs47S8+/AbYC1qUS+BikxnjB4UYNtBJhe+erG5Y2Q1Vj/OBC44 FCdbSUvfn+Ybd91FeSbGx8+VMp1In6y1qG6D2E1FNSnJgN0HKLOkmiTZbOzF3oA+Z0bM q19A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=7QPIsxyP1HaY4xWkV4koG476fc9DNOSGwyr5fWWyNTs=; b=m/8eqP01AldqFZAZll5wYmDKKdXiJ18p0v59JvNqNp/hG+jrxmf5sWzY5u3280U1IH zPk3c71XxbvjEyCBigsqZbeFhC1Vx2WdG0Oid90YuM0b+P0du8z1uOoNZvLpXPkgg0pR DY5x/1dHuE1GUaw+wcxTNfCJali8bBw+12nMbfvWjj+WDdNMlHHvLwb3XxlQOmIVqYJF UScTzczlXJjyvuDZP+KP8wRaOCU+vLCnpXFThw5wzxqapqvHKfICdZVN6Ljz+/6tWA6k BL3h+ZUVcY4pNoqRHjc8xzJ/vEjehWKk34xjfHRdlihR30r1fghX/HLS/HxKoJ1cQ5zN Fy8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Z+JOGyiN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 199si4344142pge.119.2017.11.09.20.56.54; Thu, 09 Nov 2017 20:57:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Z+JOGyiN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756022AbdKJE4K (ORCPT + 83 others); Thu, 9 Nov 2017 23:56:10 -0500 Received: from mail-it0-f65.google.com ([209.85.214.65]:33887 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755888AbdKJE4I (ORCPT ); Thu, 9 Nov 2017 23:56:08 -0500 Received: by mail-it0-f65.google.com with SMTP id m191so380277itg.1; Thu, 09 Nov 2017 20:56:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=7QPIsxyP1HaY4xWkV4koG476fc9DNOSGwyr5fWWyNTs=; b=Z+JOGyiNAEnf6FrHirEYsgaWUVYquZfC5s66vdzXYDUK6hRsGzB5ibq95otwzlBTCl BzrmaQh8USQ2qlvteQl8OhbV8WFwBQGoWTcMkDcDTdPjaWzcVNQqfdD/iuwAR/nBuaxb XU2h8lLZrBHhwqbGcZGzIgF2XpbOXvv6nVPjBuQa4N+STdLQXvTeLlU3G51Q7bpjYvhT fTpql55VYe8sohXgx8bSwmtjqbS3ybI45S2G98hQ8Qx5NeSQ6oAdoF03A2Wm+KfCfEeU e3x92wdz9ZtxPEC3aoS0qJypLlP0f50MJdZhSYxrV6jK1hvEGNGl/Xm7+UR5CwefsQHD zsTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=7QPIsxyP1HaY4xWkV4koG476fc9DNOSGwyr5fWWyNTs=; b=rIDna4pe1d5K/tuzxfb0AikL3VSVzHaQDDvEBVSXBAzf0cDfbn03LScdWZTykFsZjw 1iQ+A6KRNijDGSzHHLeWAouOpaQBFOfJ3rYtOmWLuID/dJe5r3q6Mmjwav6il1jdYg8j c7k/1kwbve6IL0bnHKlgwubM8M9Zxdqd7ORDcwP6JNqTLwlfaZEytyMMeM+NCc+11kBu IWhrpYaKadt2yWlWNKdfxZfB3+eEwacOJuW0SZUxq8lmVKAs9gE9y44pcKC/zPYkyAJ+ U1znU/ihkV+r3h3r/PutEuMZsjJHeq0guYh1Zjrcy/clTV3AEhIr/CoZCoOgxmJo/nt1 kxAw== X-Gm-Message-State: AJaThX4p9LoCyU5uHdATqOeIAfgZDWRHyxJQatZbM+mjHBRFjszX8bPI JOZn6PYEukeAp7KF02FlHZusZqJo50EB5gTgHyw= X-Received: by 10.36.69.234 with SMTP id c103mr164984itd.150.1510289767251; Thu, 09 Nov 2017 20:56:07 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.160.73 with HTTP; Thu, 9 Nov 2017 20:56:06 -0800 (PST) In-Reply-To: <20171109195712.47fe23b6@gandalf.local.home> References: <1510207298-14828-1-git-send-email-laoar.shao@gmail.com> <20171109064326.skfvvohg7qhgl3lp@ast-mbp> <20171109131808.373c296f@gandalf.local.home> <30A95900-7378-439F-954E-BD5487012435@fb.com> <20171109195712.47fe23b6@gandalf.local.home> From: Yafang Shao Date: Fri, 10 Nov 2017 12:56:06 +0800 Message-ID: Subject: Re: [PATCH] tcp: Export to userspace the TCP state names for the trace events To: Steven Rostedt Cc: David Miller , Song Liu , Alexei Starovoitov , "mingo@redhat.com" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-11-10 8:57 GMT+08:00 Steven Rostedt : > > From: "Steven Rostedt (VMware)" > > The TCP trace events (specifically tcp_set_state), maps emums to symbol > names via __print_symbolic(). But this only works for reading trace event= s > from the tracefs trace files. If perf or trace-cmd were to record these > events, the event format file does not convert the enum names into number= s, > and you get something like: > > __print_symbolic(REC->oldstate, > { TCP_ESTABLISHED, "TCP_ESTABLISHED" }, > { TCP_SYN_SENT, "TCP_SYN_SENT" }, > { TCP_SYN_RECV, "TCP_SYN_RECV" }, > { TCP_FIN_WAIT1, "TCP_FIN_WAIT1" }, > { TCP_FIN_WAIT2, "TCP_FIN_WAIT2" }, > { TCP_TIME_WAIT, "TCP_TIME_WAIT" }, > { TCP_CLOSE, "TCP_CLOSE" }, > { TCP_CLOSE_WAIT, "TCP_CLOSE_WAIT" }, > { TCP_LAST_ACK, "TCP_LAST_ACK" }, > { TCP_LISTEN, "TCP_LISTEN" }, > { TCP_CLOSING, "TCP_CLOSING" }, > { TCP_NEW_SYN_RECV, "TCP_NEW_SYN_RECV" }) > > Where trace-cmd and perf do not know the values of those enums. > > Use the TRACE_DEFINE_ENUM() macros that will have the trace events conver= t > the enum strings into their values at system boot. This will allow perf a= nd > trace-cmd to see actual numbers and not enums: > > __print_symbolic(REC->oldstate, > { 1, "TCP_ESTABLISHED" }, > { 2, "TCP_SYN_SENT" }, > { 3, "TCP_SYN_RECV" }, > { 4, "TCP_FIN_WAIT1" }, > { 5, "TCP_FIN_WAIT2" }, > { 6, "TCP_TIME_WAIT" }, > { 7, "TCP_CLOSE" }, > { 8, "TCP_CLOSE_WAIT" }, > { 9, "TCP_LAST_ACK" }, > { 10, "TCP_LISTEN" }, > { 11, "TCP_CLOSING" }, > { 12, "TCP_NEW_SYN_RECV" }) > > Signed-off-by: Steven Rostedt (VMware) > --- > include/trace/events/tcp.h | 41 ++++++++++++++++++++++++++++------------= - > 1 file changed, 28 insertions(+), 13 deletions(-) > > diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h > index 07cccca6cbf1..62e5bad7901f 100644 > --- a/include/trace/events/tcp.h > +++ b/include/trace/events/tcp.h > @@ -9,21 +9,36 @@ > #include > #include > > +#define tcp_state_names \ > + EM(TCP_ESTABLISHED) \ > + EM(TCP_SYN_SENT) \ > + EM(TCP_SYN_RECV) \ > + EM(TCP_FIN_WAIT1) \ > + EM(TCP_FIN_WAIT2) \ > + EM(TCP_TIME_WAIT) \ > + EM(TCP_CLOSE) \ > + EM(TCP_CLOSE_WAIT) \ > + EM(TCP_LAST_ACK) \ > + EM(TCP_LISTEN) \ > + EM(TCP_CLOSING) \ > + EMe(TCP_NEW_SYN_RECV) > + > +/* enums need to be exported to user space */ > +#undef EM > +#undef EMe > +#define EM(a) TRACE_DEFINE_ENUM(a); > +#define EMe(a) TRACE_DEFINE_ENUM(a); > + > +tcp_state_names > + > +#undef EM > +#undef EMe > +#define EM(a) tcp_state_name(a), > +#define EMe(a) tcp_state_name(a) > + > #define tcp_state_name(state) { state, #state } > #define show_tcp_state_name(val) \ > - __print_symbolic(val, \ > - tcp_state_name(TCP_ESTABLISHED), \ > - tcp_state_name(TCP_SYN_SENT), \ > - tcp_state_name(TCP_SYN_RECV), \ > - tcp_state_name(TCP_FIN_WAIT1), \ > - tcp_state_name(TCP_FIN_WAIT2), \ > - tcp_state_name(TCP_TIME_WAIT), \ > - tcp_state_name(TCP_CLOSE), \ > - tcp_state_name(TCP_CLOSE_WAIT), \ > - tcp_state_name(TCP_LAST_ACK), \ > - tcp_state_name(TCP_LISTEN), \ > - tcp_state_name(TCP_CLOSING), \ > - tcp_state_name(TCP_NEW_SYN_RECV)) > + __print_symbolic(val, tcp_state_names) > > /* > * tcp event with arguments sk and skb > -- > 2.13.6 > Could the macro tcp_state_name() be renamed =EF=BC=9F If is included in include/net/tcp.h, it will cause compile error, because there's another function tcp_state_name() defined in net/netfilter/ipvs/ip_vs_proto_tcp.c. static const char * tcp_state_name(int state) { if (state >=3D IP_VS_TCP_S_LAST) return "ERR!"; return tcp_state_name_table[state] ? tcp_state_name_table[state] : = "?"; } Thanks Yafang From 1583641564424819272@xxx Fri Nov 10 01:44:46 +0000 2017 X-GM-THRID: 1583638629223849157 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread