[<prev] [next>] [day] [month] [year] [list]
Message-ID: <CABzZ0PHPshVp6+8skcawTaW64=kwxwFiWpaDCWpKhnYvm2ugKg@mail.gmail.com>
Date: Wed, 29 Feb 2012 18:41:26 +0100
From: Riccardo Trebbi <riccardo.trebbi89@...il.com>
To: netdev@...r.kernel.org
Subject: Function to get bytes/s received on a socket
Hi all,
I am working on a project for the university and I needed a function
that could calculate the throughput of a socket in terms of bytes/s
received.
I followed the line of tcp_rcv_space_adjust() in net/ipv4/tcp_input.c
and I did something like this.
First I modified the struct tcp_sock to add this:
+++++++++++++++++++++++++++++++++++++++++++++++++
/* Throughput estimation of the receiver */
struct {
u32 time; // time we got the seq
u32 seq; // seq number we expected at time
u32 thrpt; // last value of throughput
} thrpt_est;
+++++++++++++++++++++++++++++++++++++++++++++++++
Then I implemented this function in net/ipv4/tcp_input.c:
+++++++++++++++++++++++++++++++++++++++++++++++++
/* This function is used to calculate the throughput of a
* tcp_sock that is receiveing data */
void my_function(struct sock *sk)
{
struct tcp_sock *tp = tcp_sk(sk);
u32 time;
u32 rcvd_bytes;
if (tp->thrpt_est.time == 0 || tp->thrpt_est.seq == 0)
goto new_measure;
time = tcp_time_stamp - tp->thrpt_est.time;
if(time < 100)
return;
if(tp->rcv_nxt < tp->thrpt_est.seq)
printk("tp->rcv_nxt < tp->thrpt_est.seq\n");
rcvd_bytes = tp->rcv_nxt - tp->thrpt_est.seq;
if(time == 0)
goto new_measure;
tp->thrpt_est.thrpt = rcvd_bytes / time;
new_measure:
tp->thrpt_est.seq = tp->rcv_nxt;
tp->thrpt_est.time = tcp_time_stamp;
}
+++++++++++++++++++++++++++++++++++++++++++++++++
The my_function() is called when tcp_rcv_space_adjust() is called.
The value in tp->thrpt_est.thrpt is bytes/ms but I can get the bytes/s
with a simple conversion.
I am a total newbie in kernel hacking and there's so many things I don't know,
but I thought that this was quite simple and should have worked.
The problem is the value in tp->thrpt_est.thrpt is way higher than the
real throughput.
I get values 4-5 times higher than the reality.
Would you please help me understand?
Thanks,
Riccardo
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists