Lines Matching refs:tp_vars

135  * @tp_vars: the private data of the current TP meter session
143 static void batadv_tp_update_cwnd(struct batadv_tp_vars *tp_vars, u32 mss)
145 spin_lock_bh(&tp_vars->cwnd_lock);
148 if (tp_vars->cwnd <= tp_vars->ss_threshold) {
149 tp_vars->dec_cwnd = 0;
150 tp_vars->cwnd = batadv_tp_cwnd(tp_vars->cwnd, mss, mss);
151 spin_unlock_bh(&tp_vars->cwnd_lock);
156 tp_vars->dec_cwnd += max_t(u32, 1U << 3,
157 ((mss * mss) << 6) / (tp_vars->cwnd << 3));
158 if (tp_vars->dec_cwnd < (mss << 3)) {
159 spin_unlock_bh(&tp_vars->cwnd_lock);
163 tp_vars->cwnd = batadv_tp_cwnd(tp_vars->cwnd, mss, mss);
164 tp_vars->dec_cwnd = 0;
166 spin_unlock_bh(&tp_vars->cwnd_lock);
171 * @tp_vars: the private data of the current TP meter session
174 static void batadv_tp_update_rto(struct batadv_tp_vars *tp_vars,
185 if (tp_vars->srtt != 0) {
186 m -= (tp_vars->srtt >> 3); /* m is now error in rtt est */
187 tp_vars->srtt += m; /* rtt = 7/8 srtt + 1/8 new */
191 m -= (tp_vars->rttvar >> 2);
192 tp_vars->rttvar += m; /* mdev ~= 3/4 rttvar + 1/4 new */
195 tp_vars->srtt = m << 3; /* take the measured time to be srtt */
196 tp_vars->rttvar = m << 1; /* new_rtt / 2 */
202 tp_vars->rto = (tp_vars->srtt >> 3) + tp_vars->rttvar;
253 * batadv_tp_list_find() - find a tp_vars object in the global list
257 * Look for a tp_vars object matching dst as end_point and return it after
260 * Return: matching tp_vars or NULL when no tp_vars with @dst was found
265 struct batadv_tp_vars *pos, *tp_vars = NULL;
279 tp_vars = pos;
284 return tp_vars;
288 * batadv_tp_list_find_session() - find tp_vars session object in the global
294 * Look for a tp_vars object matching dst as end_point, session as tp meter
298 * Return: matching tp_vars or NULL when no tp_vars was found
304 struct batadv_tp_vars *pos, *tp_vars = NULL;
321 tp_vars = pos;
326 return tp_vars;
336 struct batadv_tp_vars *tp_vars;
339 tp_vars = container_of(ref, struct batadv_tp_vars, refcount);
344 spin_lock_bh(&tp_vars->unacked_lock);
345 list_for_each_entry_safe(un, safe, &tp_vars->unacked_list, list) {
349 spin_unlock_bh(&tp_vars->unacked_lock);
351 kfree_rcu(tp_vars, rcu);
357 * @tp_vars: the private data of the current TP meter session to be free'd
359 static void batadv_tp_vars_put(struct batadv_tp_vars *tp_vars)
361 if (!tp_vars)
364 kref_put(&tp_vars->refcount, batadv_tp_vars_release);
370 * @tp_vars: the private data of the current TP meter session to cleanup
373 struct batadv_tp_vars *tp_vars)
375 cancel_delayed_work(&tp_vars->finish_work);
377 spin_lock_bh(&tp_vars->bat_priv->tp_list_lock);
378 hlist_del_rcu(&tp_vars->list);
379 spin_unlock_bh(&tp_vars->bat_priv->tp_list_lock);
382 batadv_tp_vars_put(tp_vars);
384 atomic_dec(&tp_vars->bat_priv->tp_num);
387 del_timer_sync(&tp_vars->timer);
393 del_timer(&tp_vars->timer);
394 batadv_tp_vars_put(tp_vars);
400 * @tp_vars: the private data of the current TP meter session
403 struct batadv_tp_vars *tp_vars)
409 tp_vars->other_end, tp_vars->reason);
413 tp_vars->srtt >> 3, tp_vars->rttvar >> 2, tp_vars->rto);
417 tp_vars->cwnd, tp_vars->ss_threshold);
419 session_cookie = batadv_tp_session_cookie(tp_vars->session,
420 tp_vars->icmp_uid);
422 batadv_tp_batctl_notify(tp_vars->reason,
423 tp_vars->other_end,
425 tp_vars->start_time,
426 atomic64_read(&tp_vars->tot_sent),
432 * @tp_vars: the private data of the current TP meter session
435 static void batadv_tp_sender_shutdown(struct batadv_tp_vars *tp_vars,
438 if (!atomic_dec_and_test(&tp_vars->sending))
441 tp_vars->reason = reason;
446 * @work: delayed work reference of the related tp_vars
451 struct batadv_tp_vars *tp_vars;
454 tp_vars = container_of(delayed_work, struct batadv_tp_vars,
457 batadv_tp_sender_shutdown(tp_vars, BATADV_TP_REASON_COMPLETE);
462 * @tp_vars: the private TP meter data for this session
464 * Reschedule the timer using tp_vars->rto as delay
466 static void batadv_tp_reset_sender_timer(struct batadv_tp_vars *tp_vars)
471 if (unlikely(atomic_read(&tp_vars->sending) == 0))
475 mod_timer(&tp_vars->timer, jiffies + msecs_to_jiffies(tp_vars->rto));
480 * @t: address to timer_list inside tp_vars
488 struct batadv_tp_vars *tp_vars = from_timer(tp_vars, t, timer);
489 struct batadv_priv *bat_priv = tp_vars->bat_priv;
491 if (atomic_read(&tp_vars->sending) == 0)
495 if (unlikely(tp_vars->rto >= BATADV_TP_MAX_RTO)) {
496 batadv_tp_sender_shutdown(tp_vars,
504 tp_vars->rto <<= 1;
506 spin_lock_bh(&tp_vars->cwnd_lock);
508 tp_vars->ss_threshold = tp_vars->cwnd >> 1;
509 if (tp_vars->ss_threshold < BATADV_TP_PLEN * 2)
510 tp_vars->ss_threshold = BATADV_TP_PLEN * 2;
514 tp_vars->other_end, tp_vars->cwnd, tp_vars->ss_threshold,
515 atomic_read(&tp_vars->last_acked));
517 tp_vars->cwnd = BATADV_TP_PLEN * 3;
519 spin_unlock_bh(&tp_vars->cwnd_lock);
522 tp_vars->last_sent = atomic_read(&tp_vars->last_acked);
523 wake_up(&tp_vars->more_bytes);
525 batadv_tp_reset_sender_timer(tp_vars);
530 * @tp_vars: the private TP meter data for this session
534 static void batadv_tp_fill_prerandom(struct batadv_tp_vars *tp_vars,
542 spin_lock_bh(&tp_vars->prerandom_lock);
543 local_offset = tp_vars->prerandom_offset;
544 tp_vars->prerandom_offset += nbytes;
545 tp_vars->prerandom_offset %= sizeof(batadv_tp_prerandom);
546 spin_unlock_bh(&tp_vars->prerandom_lock);
562 * @tp_vars: the private TP meter data for this session
577 static int batadv_tp_send_msg(struct batadv_tp_vars *tp_vars, const u8 *src,
611 batadv_tp_fill_prerandom(tp_vars, data, data_len);
633 struct batadv_tp_vars *tp_vars;
644 /* find the tp_vars */
645 tp_vars = batadv_tp_list_find_session(bat_priv, icmp->orig,
647 if (unlikely(!tp_vars))
650 if (unlikely(atomic_read(&tp_vars->sending) == 0))
655 (u32)atomic_read(&tp_vars->last_acked)))
669 batadv_tp_update_rto(tp_vars, rtt);
672 batadv_tp_reset_sender_timer(tp_vars);
677 if (atomic_read(&tp_vars->last_acked) == recv_ack) {
678 atomic_inc(&tp_vars->dup_acks);
679 if (atomic_read(&tp_vars->dup_acks) != 3)
682 if (recv_ack >= tp_vars->recover)
686 batadv_tp_send_msg(tp_vars, primary_if->net_dev->dev_addr,
691 spin_lock_bh(&tp_vars->cwnd_lock);
694 tp_vars->fast_recovery = true;
698 tp_vars->recover = tp_vars->last_sent;
699 tp_vars->ss_threshold = tp_vars->cwnd >> 1;
702 tp_vars->cwnd, tp_vars->ss_threshold,
703 tp_vars->last_sent, recv_ack);
704 tp_vars->cwnd = batadv_tp_cwnd(tp_vars->ss_threshold, 3 * mss,
706 tp_vars->dec_cwnd = 0;
707 tp_vars->last_sent = recv_ack;
709 spin_unlock_bh(&tp_vars->cwnd_lock);
712 atomic64_add(recv_ack - atomic_read(&tp_vars->last_acked),
713 &tp_vars->tot_sent);
715 atomic_set(&tp_vars->dup_acks, 0);
717 if (tp_vars->fast_recovery) {
719 if (batadv_seq_before(recv_ack, tp_vars->recover)) {
725 batadv_tp_send_msg(tp_vars, dev_addr,
730 tp_vars->cwnd = batadv_tp_cwnd(tp_vars->cwnd,
733 tp_vars->fast_recovery = false;
738 cwnd = batadv_tp_cwnd(tp_vars->ss_threshold, 0,
740 tp_vars->cwnd = cwnd;
745 if (recv_ack - atomic_read(&tp_vars->last_acked) >= mss)
746 batadv_tp_update_cwnd(tp_vars, mss);
749 atomic_set(&tp_vars->last_acked, recv_ack);
752 wake_up(&tp_vars->more_bytes);
756 batadv_tp_vars_put(tp_vars);
761 * @tp_vars: the private data of the current TP meter session
766 static bool batadv_tp_avail(struct batadv_tp_vars *tp_vars,
771 win_limit = atomic_read(&tp_vars->last_acked) + tp_vars->cwnd;
772 win_left = win_limit - tp_vars->last_sent;
780 * @tp_vars: the private data of the current TP meter session
788 static int batadv_tp_wait_available(struct batadv_tp_vars *tp_vars, size_t plen)
792 ret = wait_event_interruptible_timeout(tp_vars->more_bytes,
793 batadv_tp_avail(tp_vars, plen),
801 * @arg: address of the related tp_vars
807 struct batadv_tp_vars *tp_vars = arg;
808 struct batadv_priv *bat_priv = tp_vars->bat_priv;
814 if (unlikely(tp_vars->role != BATADV_TP_SENDER)) {
816 tp_vars->reason = err;
820 orig_node = batadv_orig_hash_find(bat_priv, tp_vars->other_end);
823 tp_vars->reason = err;
830 tp_vars->reason = err;
843 batadv_tp_reset_sender_timer(tp_vars);
846 queue_delayed_work(batadv_event_workqueue, &tp_vars->finish_work,
847 msecs_to_jiffies(tp_vars->test_length));
849 while (atomic_read(&tp_vars->sending) != 0) {
850 if (unlikely(!batadv_tp_avail(tp_vars, payload_len))) {
851 batadv_tp_wait_available(tp_vars, payload_len);
860 err = batadv_tp_send_msg(tp_vars, primary_if->net_dev->dev_addr,
861 orig_node, tp_vars->last_sent,
863 tp_vars->session, tp_vars->icmp_uid,
872 if (atomic_dec_and_test(&tp_vars->sending))
873 tp_vars->reason = err;
879 tp_vars->last_sent += payload_len;
888 batadv_tp_sender_end(bat_priv, tp_vars);
889 batadv_tp_sender_cleanup(bat_priv, tp_vars);
891 batadv_tp_vars_put(tp_vars);
899 * @tp_vars: the private data of the current TP meter session
901 static void batadv_tp_start_kthread(struct batadv_tp_vars *tp_vars)
904 struct batadv_priv *bat_priv = tp_vars->bat_priv;
907 kref_get(&tp_vars->refcount);
908 kthread = kthread_create(batadv_tp_send, tp_vars, "kbatadv_tp_meter");
910 session_cookie = batadv_tp_session_cookie(tp_vars->session,
911 tp_vars->icmp_uid);
914 tp_vars->other_end,
918 batadv_tp_vars_put(tp_vars);
921 batadv_tp_sender_cleanup(bat_priv, tp_vars);
938 struct batadv_tp_vars *tp_vars;
950 tp_vars = batadv_tp_list_find(bat_priv, dst);
951 if (tp_vars) {
953 batadv_tp_vars_put(tp_vars);
970 tp_vars = kmalloc(sizeof(*tp_vars), GFP_ATOMIC);
971 if (!tp_vars) {
981 /* initialize tp_vars */
982 ether_addr_copy(tp_vars->other_end, dst);
983 kref_init(&tp_vars->refcount);
984 tp_vars->role = BATADV_TP_SENDER;
985 atomic_set(&tp_vars->sending, 1);
986 memcpy(tp_vars->session, session_id, sizeof(session_id));
987 tp_vars->icmp_uid = icmp_uid;
989 tp_vars->last_sent = BATADV_TP_FIRST_SEQ;
990 atomic_set(&tp_vars->last_acked, BATADV_TP_FIRST_SEQ);
991 tp_vars->fast_recovery = false;
992 tp_vars->recover = BATADV_TP_FIRST_SEQ;
998 tp_vars->cwnd = BATADV_TP_PLEN * 3;
1002 tp_vars->ss_threshold = BATADV_TP_AWND;
1007 tp_vars->rto = 1000;
1008 tp_vars->srtt = 0;
1009 tp_vars->rttvar = 0;
1011 atomic64_set(&tp_vars->tot_sent, 0);
1013 kref_get(&tp_vars->refcount);
1014 timer_setup(&tp_vars->timer, batadv_tp_sender_timeout, 0);
1016 tp_vars->bat_priv = bat_priv;
1017 tp_vars->start_time = jiffies;
1019 init_waitqueue_head(&tp_vars->more_bytes);
1021 spin_lock_init(&tp_vars->unacked_lock);
1022 INIT_LIST_HEAD(&tp_vars->unacked_list);
1024 spin_lock_init(&tp_vars->cwnd_lock);
1026 tp_vars->prerandom_offset = 0;
1027 spin_lock_init(&tp_vars->prerandom_lock);
1029 kref_get(&tp_vars->refcount);
1030 hlist_add_head_rcu(&tp_vars->list, &bat_priv->tp_list);
1033 tp_vars->test_length = test_length;
1034 if (!tp_vars->test_length)
1035 tp_vars->test_length = BATADV_TP_DEF_TEST_LENGTH;
1042 INIT_DELAYED_WORK(&tp_vars->finish_work, batadv_tp_sender_finish);
1047 batadv_tp_start_kthread(tp_vars);
1049 /* don't return reference to new tp_vars */
1050 batadv_tp_vars_put(tp_vars);
1063 struct batadv_tp_vars *tp_vars;
1072 tp_vars = batadv_tp_list_find(bat_priv, orig_node->orig);
1073 if (!tp_vars) {
1079 batadv_tp_sender_shutdown(tp_vars, return_value);
1080 batadv_tp_vars_put(tp_vars);
1087 * @tp_vars: the private data of the current TP meter session
1091 static void batadv_tp_reset_receiver_timer(struct batadv_tp_vars *tp_vars)
1093 mod_timer(&tp_vars->timer,
1100 * @t: address to timer_list inside tp_vars
1104 struct batadv_tp_vars *tp_vars = from_timer(tp_vars, t, timer);
1108 bat_priv = tp_vars->bat_priv;
1111 if (!batadv_has_timed_out(tp_vars->last_recv_time,
1114 batadv_tp_reset_receiver_timer(tp_vars);
1120 BATADV_TP_RECV_TIMEOUT, tp_vars->other_end);
1122 spin_lock_bh(&tp_vars->bat_priv->tp_list_lock);
1123 hlist_del_rcu(&tp_vars->list);
1124 spin_unlock_bh(&tp_vars->bat_priv->tp_list_lock);
1127 batadv_tp_vars_put(tp_vars);
1131 spin_lock_bh(&tp_vars->unacked_lock);
1132 list_for_each_entry_safe(un, safe, &tp_vars->unacked_list, list) {
1136 spin_unlock_bh(&tp_vars->unacked_lock);
1139 batadv_tp_vars_put(tp_vars);
1214 * @tp_vars: the private data of the current TP meter session
1223 static bool batadv_tp_handle_out_of_order(struct batadv_tp_vars *tp_vars,
1241 spin_lock_bh(&tp_vars->unacked_lock);
1243 if (list_empty(&tp_vars->unacked_list)) {
1244 list_add(&new->list, &tp_vars->unacked_list);
1255 list_for_each_entry_reverse(un, &tp_vars->unacked_list, list) {
1280 list_add(&new->list, &tp_vars->unacked_list);
1283 spin_unlock_bh(&tp_vars->unacked_lock);
1291 * @tp_vars: the private data of the current TP meter session
1293 static void batadv_tp_ack_unordered(struct batadv_tp_vars *tp_vars)
1301 spin_lock_bh(&tp_vars->unacked_lock);
1302 list_for_each_entry_safe(un, safe, &tp_vars->unacked_list, list) {
1307 if (batadv_seq_before(tp_vars->last_recv, un->seqno))
1310 to_ack = un->seqno + un->len - tp_vars->last_recv;
1312 if (batadv_seq_before(tp_vars->last_recv, un->seqno + un->len))
1313 tp_vars->last_recv += to_ack;
1318 spin_unlock_bh(&tp_vars->unacked_lock);
1322 * batadv_tp_init_recv() - return matching or create new receiver tp_vars
1326 * Return: corresponding tp_vars or NULL on errors
1332 struct batadv_tp_vars *tp_vars;
1335 tp_vars = batadv_tp_list_find_session(bat_priv, icmp->orig,
1337 if (tp_vars)
1346 tp_vars = kmalloc(sizeof(*tp_vars), GFP_ATOMIC);
1347 if (!tp_vars)
1350 ether_addr_copy(tp_vars->other_end, icmp->orig);
1351 tp_vars->role = BATADV_TP_RECEIVER;
1352 memcpy(tp_vars->session, icmp->session, sizeof(tp_vars->session));
1353 tp_vars->last_recv = BATADV_TP_FIRST_SEQ;
1354 tp_vars->bat_priv = bat_priv;
1355 kref_init(&tp_vars->refcount);
1357 spin_lock_init(&tp_vars->unacked_lock);
1358 INIT_LIST_HEAD(&tp_vars->unacked_list);
1360 kref_get(&tp_vars->refcount);
1361 hlist_add_head_rcu(&tp_vars->list, &bat_priv->tp_list);
1363 kref_get(&tp_vars->refcount);
1364 timer_setup(&tp_vars->timer, batadv_tp_receiver_shutdown, 0);
1366 batadv_tp_reset_receiver_timer(tp_vars);
1371 return tp_vars;
1385 struct batadv_tp_vars *tp_vars;
1396 tp_vars = batadv_tp_init_recv(bat_priv, icmp);
1397 if (!tp_vars) {
1403 tp_vars = batadv_tp_list_find_session(bat_priv, icmp->orig,
1405 if (!tp_vars) {
1413 if (unlikely(tp_vars->role != BATADV_TP_RECEIVER)) {
1416 tp_vars->role);
1420 tp_vars->last_recv_time = jiffies;
1425 if (batadv_seq_before(seqno, tp_vars->last_recv))
1429 if (ntohl(icmp->seqno) != tp_vars->last_recv) {
1433 if (!batadv_tp_handle_out_of_order(tp_vars, skb))
1442 tp_vars->last_recv += packet_size;
1445 batadv_tp_ack_unordered(tp_vars);
1452 batadv_tp_send_ack(bat_priv, icmp->orig, tp_vars->last_recv,
1455 batadv_tp_vars_put(tp_vars);