rc80211_minstrel_debugfs.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License version 2 as
00006  * published by the Free Software Foundation.
00007  *
00008  * Based on minstrel.c:
00009  *   Copyright (C) 2005-2007 Derek Smithies <derek@indranet.co.nz>
00010  *   Sponsored by Indranet Technologies Ltd
00011  *
00012  * Based on sample.c:
00013  *   Copyright (c) 2005 John Bicket
00014  *   All rights reserved.
00015  *
00016  *   Redistribution and use in source and binary forms, with or without
00017  *   modification, are permitted provided that the following conditions
00018  *   are met:
00019  *   1. Redistributions of source code must retain the above copyright
00020  *      notice, this list of conditions and the following disclaimer,
00021  *      without modification.
00022  *   2. Redistributions in binary form must reproduce at minimum a disclaimer
00023  *      similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
00024  *      redistribution must be conditioned upon including a substantially
00025  *      similar Disclaimer requirement for further binary redistribution.
00026  *   3. Neither the names of the above-listed copyright holders nor the names
00027  *      of any contributors may be used to endorse or promote products derived
00028  *      from this software without specific prior written permission.
00029  *
00030  *   Alternatively, this software may be distributed under the terms of the
00031  *   GNU General Public License ("GPL") version 2 as published by the Free
00032  *   Software Foundation.
00033  *
00034  *   NO WARRANTY
00035  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00036  *   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00037  *   LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
00038  *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
00039  *   THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
00040  *   OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00041  *   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00042  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
00043  *   IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00044  *   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00045  *   THE POSSIBILITY OF SUCH DAMAGES.
00046  */
00047 #include <linux/netdevice.h>
00048 #include <linux/types.h>
00049 #include <linux/skbuff.h>
00050 #include <linux/debugfs.h>
00051 #include <linux/ieee80211.h>
00052 #include <linux/slab.h>
00053 #include <linux/export.h>
00054 #include <net/mac80211.h>
00055 #include "rc80211_minstrel.h"
00056 
00057 int
00058 minstrel_stats_open(struct inode *inode, struct file *file)
00059 {
00060         struct minstrel_sta_info *mi = inode->i_private;
00061         struct minstrel_debugfs_info *ms;
00062         unsigned int i, tp, prob, eprob;
00063         char *p;
00064 
00065         ms = kmalloc(sizeof(*ms) + 4096, GFP_KERNEL);
00066         if (!ms)
00067                 return -ENOMEM;
00068 
00069         file->private_data = ms;
00070         p = ms->buf;
00071         p += sprintf(p, "rate     throughput  ewma prob   this prob  "
00072                         "this succ/attempt   success    attempts\n");
00073         for (i = 0; i < mi->n_rates; i++) {
00074                 struct minstrel_rate *mr = &mi->r[i];
00075 
00076                 *(p++) = (i == mi->max_tp_rate) ? 'T' : ' ';
00077                 *(p++) = (i == mi->max_tp_rate2) ? 't' : ' ';
00078                 *(p++) = (i == mi->max_prob_rate) ? 'P' : ' ';
00079                 p += sprintf(p, "%3u%s", mr->bitrate / 2,
00080                                 (mr->bitrate & 1 ? ".5" : "  "));
00081 
00082                 tp = mr->cur_tp / ((18000 << 10) / 96);
00083                 prob = mr->cur_prob / 18;
00084                 eprob = mr->probability / 18;
00085 
00086                 p += sprintf(p, "  %6u.%1u   %6u.%1u   %6u.%1u        "
00087                                 "%3u(%3u)   %8llu    %8llu\n",
00088                                 tp / 10, tp % 10,
00089                                 eprob / 10, eprob % 10,
00090                                 prob / 10, prob % 10,
00091                                 mr->last_success,
00092                                 mr->last_attempts,
00093                                 (unsigned long long)mr->succ_hist,
00094                                 (unsigned long long)mr->att_hist);
00095         }
00096         p += sprintf(p, "\nTotal packet count::    ideal %d      "
00097                         "lookaround %d\n\n",
00098                         mi->packet_count - mi->sample_count,
00099                         mi->sample_count);
00100         ms->len = p - ms->buf;
00101 
00102         return 0;
00103 }
00104 
00105 ssize_t
00106 minstrel_stats_read(struct file *file, char __user *buf, size_t len, loff_t *ppos)
00107 {
00108         struct minstrel_debugfs_info *ms;
00109 
00110         ms = file->private_data;
00111         return simple_read_from_buffer(buf, len, ppos, ms->buf, ms->len);
00112 }
00113 
00114 int
00115 minstrel_stats_release(struct inode *inode, struct file *file)
00116 {
00117         kfree(file->private_data);
00118         return 0;
00119 }
00120 
00121 static const struct file_operations minstrel_stat_fops = {
00122         .owner = THIS_MODULE,
00123         .open = minstrel_stats_open,
00124         .read = minstrel_stats_read,
00125         .release = minstrel_stats_release,
00126         .llseek = default_llseek,
00127 };
00128 
00129 void
00130 minstrel_add_sta_debugfs(void *priv, void *priv_sta, struct dentry *dir)
00131 {
00132         struct minstrel_sta_info *mi = priv_sta;
00133 
00134         mi->dbg_stats = debugfs_create_file("rc_stats", S_IRUGO, dir, mi,
00135                         &minstrel_stat_fops);
00136 }
00137 
00138 void
00139 minstrel_remove_sta_debugfs(void *priv, void *priv_sta)
00140 {
00141         struct minstrel_sta_info *mi = priv_sta;
00142 
00143         debugfs_remove(mi->dbg_stats);
00144 }


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Mon Oct 6 2014 08:27:10