From patchwork Wed Mar 24 18:14:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Greear X-Patchwork-Id: 409285 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DCBAC433E3 for ; Wed, 24 Mar 2021 18:15:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2CFD761A25 for ; Wed, 24 Mar 2021 18:15:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237474AbhCXSPH (ORCPT ); Wed, 24 Mar 2021 14:15:07 -0400 Received: from mail2.candelatech.com ([208.74.158.173]:41036 "EHLO mail3.candelatech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237457AbhCXSOr (ORCPT ); Wed, 24 Mar 2021 14:14:47 -0400 Received: from ben-dt4.candelatech.com (50-251-239-81-static.hfc.comcastbusiness.net [50.251.239.81]) by mail3.candelatech.com (Postfix) with ESMTP id 40F3B13C2B4; Wed, 24 Mar 2021 11:14:47 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 mail3.candelatech.com 40F3B13C2B4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=candelatech.com; s=default; t=1616609687; bh=H9/92mFXqYzGrgud6h8bpb3j19l3NYziPihWMRS93C0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F+KE2NVVGNTuMlP8zbOUAsaI+vBqa8i9pmPtpxzy1VVO9QTVpoqPonKjHMM6pJSEx hstO0OnUGBOSWQau4+uRvWzwq3CTg3IlBPQCsg5cOZT0uhxD/02676ITvhjS8uYsmH vj9L1ybnuBVmXkAYhB3CXRGlkzbCZXt0lI9nxOoU= From: greearb@candelatech.com To: linux-wireless@vger.kernel.org Cc: Ben Greear Subject: [PATCH-v2 2/6] mac80211: Provide per-station stats in debugfs Date: Wed, 24 Mar 2021 11:14:37 -0700 Message-Id: <20210324181441.13755-2-greearb@candelatech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210324181441.13755-1-greearb@candelatech.com> References: <20210324181441.13755-1-greearb@candelatech.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Ben Greear Including per tid and per acs stats. Nice for those who like to peer deep into the guts of a system. Signed-off-by: Ben Greear --- net/mac80211/debugfs_sta.c | 88 ++++++++++++++++++++++++++++++++++++++ net/mac80211/sta_info.c | 33 ++++++++++++++ net/mac80211/sta_info.h | 4 ++ 3 files changed, 125 insertions(+) diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c index 1deacce85177..374db61527a9 100644 --- a/net/mac80211/debugfs_sta.c +++ b/net/mac80211/debugfs_sta.c @@ -102,6 +102,93 @@ static ssize_t sta_flags_read(struct file *file, char __user *userbuf, } STA_OPS(flags); +static ssize_t sta_stats_read(struct file *file, char __user *userbuf, + size_t count, loff_t *ppos) +{ + struct sta_info *sta = file->private_data; + unsigned int len = 0; + const int buf_len = 8000; + char *buf = kzalloc(buf_len, GFP_KERNEL); + unsigned long sum; + char tmp[60]; + int i; + struct ieee80211_sta_rx_stats rx_stats = {0}; + + if (!buf) + return -ENOMEM; + + sta_accum_rx_stats(sta, &rx_stats); + +#define PRINT_MY_STATS(a, b) do { \ + len += scnprintf(buf + len, buf_len - len, "%30s %18lu\n", a, (unsigned long)(b)); \ + if (len >= buf_len) { \ + goto done; \ + } \ + } while (0) + +#define PRINT_MY_STATS_S(a, b) do { \ + len += scnprintf(buf + len, buf_len - len, "%30s %18ld\n", a, (long)(b)); \ + if (len >= buf_len) { \ + goto done; \ + } \ + } while (0) + + PRINT_MY_STATS("rx-packets", rx_stats.packets); + PRINT_MY_STATS("rx-bytes", rx_stats.bytes); + PRINT_MY_STATS("rx-dup", rx_stats.num_duplicates); + PRINT_MY_STATS("rx-fragments", rx_stats.fragments); + PRINT_MY_STATS("rx-dropped", rx_stats.dropped); + PRINT_MY_STATS_S("rx-last-signal", rx_stats.last_signal); + + for (i = 0; itx_stats.packets[0] + sta->tx_stats.packets[1] + + sta->tx_stats.packets[2] + sta->tx_stats.packets[3]; + PRINT_MY_STATS("tx-packets", sum); + + sum = sta->tx_stats.bytes[0] + sta->tx_stats.bytes[1] + + sta->tx_stats.bytes[2] + sta->tx_stats.bytes[3]; + PRINT_MY_STATS("tx-bytes", sum); + + /* per txq stats */ + PRINT_MY_STATS("tx-packets-acs[VO]", sta->tx_stats.packets[IEEE80211_AC_VO]); + PRINT_MY_STATS("tx-packets-acs[VI]", sta->tx_stats.packets[IEEE80211_AC_VI]); + PRINT_MY_STATS("tx-packets-acs[BE]", sta->tx_stats.packets[IEEE80211_AC_BE]); + PRINT_MY_STATS("tx-packets-acs[BK]", sta->tx_stats.packets[IEEE80211_AC_BK]); + + PRINT_MY_STATS("tx-bytes-acs[VO]", sta->tx_stats.bytes[IEEE80211_AC_VO]); + PRINT_MY_STATS("tx-bytes-acs[VI]", sta->tx_stats.bytes[IEEE80211_AC_VI]); + PRINT_MY_STATS("tx-bytes-acs[BE]", sta->tx_stats.bytes[IEEE80211_AC_BE]); + PRINT_MY_STATS("tx-bytes-acs[BK]", sta->tx_stats.bytes[IEEE80211_AC_BK]); + + len += scnprintf(buf + len, buf_len - len, "\n"); + for (i = 0; i<=IEEE80211_NUM_TIDS; i++) { + sprintf(tmp, "tx-msdu-tid[%2i]", i); + PRINT_MY_STATS(tmp, sta->tx_stats.msdu[i]); + } + + len += scnprintf(buf + len, buf_len - len, "\n"); + for (i = 0; i<=IEEE80211_NUM_TIDS; i++) { + sprintf(tmp, "rx-msdu-tid[%2i]", i); + PRINT_MY_STATS(tmp, rx_stats.msdu[i]); + } + +#undef PRINT_MY_STATS +done: + i = simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf)); + kfree(buf); + return i; +} +STA_OPS(stats); + static ssize_t sta_num_ps_buf_frames_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) @@ -1073,6 +1160,7 @@ void ieee80211_sta_debugfs_add(struct sta_info *sta) sta->debugfs_dir = debugfs_create_dir(mac, stations_dir); DEBUGFS_ADD(flags); + DEBUGFS_ADD(stats); DEBUGFS_ADD(aid); DEBUGFS_ADD(num_ps_buf_frames); DEBUGFS_ADD(last_seq_ctrl); diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c index b096370b45b1..aa95db547465 100644 --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c @@ -2650,6 +2650,39 @@ static void sta_update_codel_params(struct sta_info *sta, u32 thr) } } +void sta_accum_rx_stats(struct sta_info *sta, + struct ieee80211_sta_rx_stats *rx_stats) +{ + int cpu; + int i; + + memcpy(rx_stats, &sta->rx_stats, sizeof(*rx_stats)); + + if (!sta->pcpu_rx_stats) + return; + + for_each_possible_cpu(cpu) { + struct ieee80211_sta_rx_stats *cpurxs; + + cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu); + rx_stats->packets += cpurxs->packets; + if (time_after(cpurxs->last_rx, rx_stats->last_rx)) { + rx_stats->last_rx = cpurxs->last_rx; + rx_stats->last_signal = cpurxs->last_signal; + for (i = 0; ichain_signal_last[i] = cpurxs->chain_signal_last[i]; + rx_stats->last_rate = cpurxs->last_rate; + } + rx_stats->num_duplicates += cpurxs->num_duplicates; + rx_stats->fragments += cpurxs->fragments; + rx_stats->dropped += cpurxs->dropped; + rx_stats->bytes += sta_get_stats_bytes(cpurxs); + for (i = 0; i<=IEEE80211_NUM_TIDS; i++) { + rx_stats->msdu[i] += sta_get_tidstats_msdu(cpurxs, i); + } + } +} + void ieee80211_sta_set_expected_throughput(struct ieee80211_sta *pubsta, u32 thr) { diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h index 897b4d12103e..a6b13d749ffa 100644 --- a/net/mac80211/sta_info.h +++ b/net/mac80211/sta_info.h @@ -422,6 +422,7 @@ struct mesh_sta { DECLARE_EWMA(signal, 10, 8) +/* Update sta_accum_rx_stats if you change this structure. */ struct ieee80211_sta_rx_stats { unsigned long packets; unsigned long last_rx; @@ -907,4 +908,7 @@ static inline u32 sta_stats_encode_rate(struct ieee80211_rx_status *s) return r; } +void sta_accum_rx_stats(struct sta_info *sta, + struct ieee80211_sta_rx_stats *rx_stats); + #endif /* STA_INFO_H */