/* RxRPC individual remote procedure call handling * * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include #include #include #include #include #include #include #include "ar-internal.h" /* * Maximum lifetime of a call (in jiffies). */ unsigned rxrpc_max_call_lifetime = 60 * HZ; /* * Time till dead call expires after last use (in jiffies). */ unsigned rxrpc_dead_call_expiry = 2 * HZ; const char *const rxrpc_call_states[] = { [RXRPC_CALL_CLIENT_SEND_REQUEST] = "ClSndReq", [RXRPC_CALL_CLIENT_AWAIT_REPLY] = "ClAwtRpl", [RXRPC_CALL_CLIENT_RECV_REPLY] = "ClRcvRpl", [RXRPC_CALL_CLIENT_FINAL_ACK] = "ClFnlACK", [RXRPC_CALL_SERVER_SECURING] = "SvSecure", [RXRPC_CALL_SERVER_ACCEPTING] = "SvAccept", [RXRPC_CALL_SERVER_RECV_REQUEST] = "SvRcvReq", [RXRPC_CALL_SERVER_ACK_REQUEST] = "SvAckReq", [RXRPC_CALL_SERVER_SEND_REPLY] = "SvSndRpl", [RXRPC_CALL_SERVER_AWAIT_ACK] = "SvAwtACK", [RXRPC_CALL_COMPLETE] = "Complete", [RXRPC_CALL_SERVER_BUSY] = "SvBusy ", [RXRPC_CALL_REMOTELY_ABORTED] = "RmtAbort", [RXRPC_CALL_LOCALLY_ABORTED] = "LocAbort", [RXRPC_CALL_NETWORK_ERROR] = "NetError", [RXRPC_CALL_DEAD] = "Dead ", }; struct kmem_cache *rxrpc_call_jar; LIST_HEAD(rxrpc_calls); DEFINE_RWLOCK(rxrpc_call_lock); static void rxrpc_destroy_call(struct work_struct *work); static void rxrpc_call_life_expired(unsigned long _call); static void rxrpc_dead_call_expired(unsigned long _call); static void rxrpc_ack_time_expired(unsigned long _call); static void rxrpc_resend_time_expired(unsigned long _call); static DEFINE_SPINLOCK(rxrpc_call_hash_lock); static DEFINE_HASHTABLE(rxrpc_call_hash, 10); /* * Hash function for rxrpc_call_hash */ static unsigned long rxrpc_call_hashfunc( u8 clientflag, __be32 cid, __be32 call_id, __be32 epoch, __be16 service_id, sa_family_t proto, void *localptr, unsigned int addr_size, const u8 *peer_addr) { const u16 *p; unsigned int i; unsigned long key; u32 hcid = ntohl(cid); _enter(""); key = (unsigned long)localptr; /* We just want to add up the __be32 values, so forcing the * cast should be okay. */ key += (__force u32)epoch; key += (__force u16)service_id; key += (__force u32)call_id; key += (hcid & RXRPC_CIDMASK) >> RXRPC_CIDSHIFT; key += hcid & RXRPC_CHANNELMASK; key += clientflag; key += proto; /* Step through the peer address in 16-bit portions for speed */ for (i = 0, p = (const u16 *)peer_addr; i < addr_size >> 1; i++, p++) key += *p; _leave(" key = 0x%lx", key); return key; } /* * Add a call to the hashtable */ static void rxrpc_call_hash_add(struct rxrpc_call *call) { unsigned long key; unsigned int addr_size = 0; _enter(""); switch (call->proto) { case AF_INET: addr_size = sizeof(call->peer_ip.ipv4_addr); break; case AF_INET6: addr_size = sizeof(call->peer_ip.ipv6_addr); break; default: break; } key = rxrpc_call_hashfunc(call->in_clientflag, call->cid, call->call_id, call->epoch, call->service_id, call->proto, call->conn->trans->local, addr_size, call->peer_ip.ipv6_addr); /* Store the full key in the call */ call->hash_key = key; spin_lock(&rxrpc_call_hash_lock); hash_add_rcu(rxrpc_call_hash, &call->hash_node, key); spin_unlock(&rxrpc_call_hash_lock); _leave(""); } /* * Remove a call from the hashtable */ static void rxrpc_call_hash_del(struct rxrpc_call *call) { _enter(""); spin_lock(&rxrpc_call_hash_lock); hash_del_rcu(&call->hash_node); spin_unlock(&rxrpc_call_hash_lock); _leave(""); } /* * Find a call in the hashtable and return it, or NULL if it * isn't there. */ struct rxrpc_call *rxrpc_find_call_hash( u8 clientflag, __be32 cid, __be32 call_id, __be32 epoch, __be16 service_id, void *localptr, sa_family_t proto, const u8 *peer_addr) { unsigned long key; unsigned int addr_size = 0; struct rxrpc_call *call = NULL; struct rxrpc_call *ret = NULL; _enter(""); switch (proto) { case AF_INET: addr_size = sizeof(call->peer_ip.ipv4_addr); break; case AF_INET6: addr_size = sizeof(call->peer_ip.ipv6_addr); break; default: break; } key = rxrpc_call_hashfunc(clientflag, cid, call_id, epoch, service_id, proto, localptr, addr_size, peer_addr); hash_for_each_possible_rcu(rxrpc_call_hash, call, hash_node, key) { if (call->hash_key == key && call->call_id == call_id && call->cid == cid && call->in_clientflag == clientflag && call->service_id == service_id && call->proto == proto && call->local == localptr && memcmp(call->peer_ip.ipv6_addr, peer_addr, addr_size) == 0 && call->epoch == epoch) { ret = call; break; } } _leave(" = %p", ret); return ret; } /* * allocate a new call */ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp) { struct rxrpc_call *call; call = kmem_cache_zalloc(rxrpc_call_jar, gfp); if (!call) return NULL; call->acks_winsz = 16; call->acks_window = kmalloc(call->acks_winsz * sizeof(unsigned long), gfp); if (!call->acks_window) { kmem_cache_free(rxrpc_call_jar, call); return NULL; } setup_timer(&call->lifetimer, &rxrpc_call_life_expired, (unsigned long) call); setup_timer(&call->deadspan, &rxrpc_dead_call_expired, (unsigned long) call); setup_timer(&call->ack_timer, &rxrpc_ack_time_expired, (unsigned long)
##############################################################################
# Copyright (c) 2017 Ericsson AB and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
---
# Sample benchmark task config file to measure network latency using ping
# Client/server parts are located in different contexts(stacks)
# => longer communication path and higher latency

schema: "yardstick:task:0.1"

scenarios:
-
  type: Ping
  options:
    packetsize: 100
  host: athena.demo1
  target: hades.demo2
  runner:
    type: Duration
    duration: 60
    interval: 1
  sla:
    max_rtt: 15
    action: monitor

contexts:
-
  name: demo1
  image: cirros-0.3.5
  flavor: yardstick-flavor
  user: cirros
  placement_groups:
    pgrp1:
      policy: "availability"
  servers:
    athena:
      floating_ip: true
      placement: "pgrp1"
  networks:
    test:
      cidr: '10.0.1.0/24'
-
  name: demo2
  image: cirros-0.3.5
  flavor: yardstick-flavor
  user: cirros
  placement_groups:
    pgrp1:
      policy: "availability"
  servers:
    hades:
      floating_ip: true
      placement: "pgrp1"
  networks:
    test:
      cidr: '10.0.1.0/24'
no longer wanting incoming packets */ for (p = rb_first(&rx->calls); p; p = rb_next(p)) { call = rb_entry(p, struct rxrpc_call, sock_node); rxrpc_mark_call_released(call); } /* kill the not-yet-accepted incoming calls */ list_for_each_entry(call, &rx->secureq, accept_link) { rxrpc_mark_call_released(call); } list_for_each_entry(call, &rx->acceptq, accept_link) { rxrpc_mark_call_released(call); } read_unlock_bh(&rx->call_lock); _leave(""); } /* * release a call */ void __rxrpc_put_call(struct rxrpc_call *call) { ASSERT(call != NULL); _enter("%p{u=%d}", call, atomic_read(&call->usage)); ASSERTCMP(atomic_read(&call->usage), >, 0); if (atomic_dec_and_test(&call->usage)) { _debug("call %d dead", call->debug_id); ASSERTCMP(call->state, ==, RXRPC_CALL_DEAD); rxrpc_queue_work(&call->destroyer); } _leave(""); } /* * clean up a call */ static void rxrpc_cleanup_call(struct rxrpc_call *call) { _net("DESTROY CALL %d", call->debug_id); ASSERT(call->socket); memset(&call->sock_node, 0xcd, sizeof(call->sock_node)); del_timer_sync(&call->lifetimer); del_timer_sync(&call->deadspan); del_timer_sync(&call->ack_timer); del_timer_sync(&call->resend_timer); ASSERT(test_bit(RXRPC_CALL_RELEASED, &call->flags)); ASSERTCMP(call->events, ==, 0); if (work_pending(&call->processor)) { _debug("defer destroy"); rxrpc_queue_work(&call->destroyer); return; } if (call->conn) { spin_lock(&call->conn->trans->peer->lock); list_del(&call->error_link); spin_unlock(&call->conn->trans->peer->lock); write_lock_bh(&call->conn->lock); rb_erase(&call->conn_node, &call->conn->calls); write_unlock_bh(&call->conn->lock); rxrpc_put_connection(call->conn); } /* Remove the call from the hash */ rxrpc_call_hash_del(call); if (call->acks_window) { _debug("kill Tx window %d", CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz)); smp_mb(); while (CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz) > 0) { struct rxrpc_skb_priv *sp; unsigned long _skb; _skb = call->acks_window[call->acks_tail] & ~1; sp = rxrpc_skb((struct sk_buff *) _skb); _debug("+++ clear Tx %u", ntohl(sp->hdr.seq)); rxrpc_free_skb((struct sk_buff *) _skb); call->acks_tail = (call->acks_tail + 1) & (call->acks_winsz - 1); } kfree(call->acks_window); } rxrpc_free_skb(call->tx_pending); rxrpc_purge_queue(&call->rx_queue); ASSERT(skb_queue_empty(&call->rx_oos_queue)); sock_put(&call->socket->sk); kmem_cache_free(rxrpc_call_jar, call); } /* * destroy a call */ static void rxrpc_destroy_call(struct work_struct *work) { struct rxrpc_call *call = container_of(work, struct rxrpc_call, destroyer); _enter("%p{%d,%d,%p}", call, atomic_read(&call->usage), call->channel, call->conn); ASSERTCMP(call->state, ==, RXRPC_CALL_DEAD); write_lock_bh(&rxrpc_call_lock); list_del_init(&call->link); write_unlock_bh(&rxrpc_call_lock); rxrpc_cleanup_call(call); _leave(""); } /* * preemptively destroy all the call records from a transport endpoint rather * than waiting for them to time out */ void __exit rxrpc_destroy_all_calls(void) { struct rxrpc_call *call; _enter(""); write_lock_bh(&rxrpc_call_lock); while (!list_empty(&rxrpc_calls)) { call = list_entry(rxrpc_calls.next, struct rxrpc_call, link); _debug("Zapping call %p", call); list_del_init(&call->link); switch (atomic_read(&call->usage)) { case 0: ASSERTCMP(call->state, ==, RXRPC_CALL_DEAD); break; case 1: if (del_timer_sync(&call->deadspan) != 0 && call->state != RXRPC_CALL_DEAD) rxrpc_dead_call_expired((unsigned long) call); if (call->state != RXRPC_CALL_DEAD) break; default: printk(KERN_ERR "RXRPC:" " Call %p still in use (%d,%d,%s,%lx,%lx)!\n", call, atomic_read(&call->usage), atomic_read(&call->ackr_not_idle), rxrpc_call_states[call->state], call->flags, call->events); if (!skb_queue_empty(&call->rx_queue)) printk(KERN_ERR"RXRPC: Rx queue occupied\n"); if (!skb_queue_empty(&call->rx_oos_queue)) printk(KERN_ERR"RXRPC: OOS queue occupied\n"); break; } write_unlock_bh(&rxrpc_call_lock); cond_resched(); write_lock_bh(&rxrpc_call_lock); } write_unlock_bh(&rxrpc_call_lock); _leave(""); } /* * handle call lifetime being exceeded */ static void rxrpc_call_life_expired(unsigned long _call) { struct rxrpc_call *call = (struct rxrpc_call *) _call; if (call->state >= RXRPC_CALL_COMPLETE) return; _enter("{%d}", call->debug_id); read_lock_bh(&call->state_lock); if (call->state < RXRPC_CALL_COMPLETE) { set_bit(RXRPC_CALL_LIFE_TIMER, &call->events); rxrpc_queue_call(call); } read_unlock_bh(&call->state_lock); } /* * handle resend timer expiry * - may not take call->state_lock as this can deadlock against del_timer_sync() */ static void rxrpc_resend_time_expired(unsigned long _call) { struct rxrpc_call *call = (struct rxrpc_call *) _call; _enter("{%d}", call->debug_id); if (call->state >= RXRPC_CALL_COMPLETE) return; clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags); if (!test_and_set_bit(RXRPC_CALL_RESEND_TIMER, &call->events)) rxrpc_queue_call(call); } /* * handle ACK timer expiry */ static void rxrpc_ack_time_expired(unsigned long _call) { struct rxrpc_call *call = (struct rxrpc_call *) _call; _enter("{%d}", call->debug_id); if (call->state >= RXRPC_CALL_COMPLETE) return; read_lock_bh(&call->state_lock); if (call->state < RXRPC_CALL_COMPLETE && !test_and_set_bit(RXRPC_CALL_ACK, &call->events)) rxrpc_queue_call(call); read_unlock_bh(&call->state_lock); }