Whamcloud - gitweb
LU-1346 libcfs: cleanup macros in kp30.h
[fs/lustre-release.git] / lnet / klnds / socklnd / socklnd.h
index ae6045f..3fd04ac 100644 (file)
@@ -1,8 +1,8 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  *
+ * Copyright (c) 2011, 2013, Intel Corporation.
+ *
  *   Author: Zach Brown <zab@zabbo.net>
  *   Author: Peter J. Braam <braam@clusterfs.com>
  *   Author: Phil Schwan <phil@clusterfs.com>
  */
 
 #define DEBUG_PORTAL_ALLOC
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
-
 #define DEBUG_SUBSYSTEM S_LND
 
 #if defined(__linux__)
 # define SOCKNAL_RISK_KMAP_DEADLOCK  1
 #endif
 
+struct ksock_sched_info;
+
 typedef struct                                  /* per scheduler state */
 {
-        cfs_spinlock_t    kss_lock;             /* serialise */
-        cfs_list_t        kss_rx_conns;         /* conn waiting to be read */
-        cfs_list_t        kss_tx_conns;         /* conn waiting to be written */
-        cfs_list_t        kss_zombie_noop_txs;  /* zombie noop tx list */
-        cfs_waitq_t       kss_waitq;            /* where scheduler sleeps */
-        int               kss_nconns;           /* # connections assigned to this scheduler */
+       spinlock_t              kss_lock;       /* serialise */
+       cfs_list_t              kss_rx_conns;   /* conn waiting to be read */
+       /* conn waiting to be written */
+       cfs_list_t              kss_tx_conns;
+       /* zombie noop tx list */
+       cfs_list_t              kss_zombie_noop_txs;
+       cfs_waitq_t             kss_waitq;      /* where scheduler sleeps */
+       /* # connections assigned to this scheduler */
+       int                     kss_nconns;
+       struct ksock_sched_info *kss_info;      /* owner of it */
 #if !SOCKNAL_SINGLE_FRAG_RX
-        struct page      *kss_rx_scratch_pgs[LNET_MAX_IOV];
+       struct page             *kss_rx_scratch_pgs[LNET_MAX_IOV];
 #endif
 #if !SOCKNAL_SINGLE_FRAG_TX || !SOCKNAL_SINGLE_FRAG_RX
-        struct iovec      kss_scratch_iov[LNET_MAX_IOV];
+       struct iovec            kss_scratch_iov[LNET_MAX_IOV];
 #endif
 } ksock_sched_t;
 
-typedef struct
-{
-        unsigned int      ksni_valid:1;         /* been set yet? */
-        unsigned int      ksni_bound:1;         /* bound to a cpu yet? */
-        unsigned int      ksni_sched:6;         /* which scheduler (assumes < 64) */
-} ksock_irqinfo_t;
+struct ksock_sched_info {
+       int                     ksi_nthreads_max; /* max allowed threads */
+       int                     ksi_nthreads;   /* number of threads */
+       int                     ksi_cpt;        /* CPT id */
+       ksock_sched_t           *ksi_scheds;    /* array of schedulers */
+};
+
+#define KSOCK_CPT_SHIFT                        16
+#define KSOCK_THREAD_ID(cpt, sid)      (((cpt) << KSOCK_CPT_SHIFT) | (sid))
+#define KSOCK_THREAD_CPT(id)           ((id) >> KSOCK_CPT_SHIFT)
+#define KSOCK_THREAD_SID(id)           ((id) & ((1UL << KSOCK_CPT_SHIFT) - 1))
 
 typedef struct                                  /* in-use interface */
 {
-        __u32             ksni_ipaddr;          /* interface's IP address */
-        __u32             ksni_netmask;         /* interface's network mask */
-        int               ksni_nroutes;         /* # routes using (active) */
-        int               ksni_npeers;          /* # peers using (passive) */
-        char              ksni_name[16];        /* interface name */
+       __u32           ksni_ipaddr;            /* interface's IP address */
+       __u32           ksni_netmask;           /* interface's network mask */
+       int             ksni_nroutes;           /* # routes using (active) */
+       int             ksni_npeers;            /* # peers using (passive) */
+       char            ksni_name[IFNAMSIZ];    /* interface name */
 } ksock_interface_t;
 
 typedef struct
 {
-        int              *ksnd_timeout;         /* "stuck" socket timeout (seconds) */
+       /* "stuck" socket timeout (seconds) */
+       int              *ksnd_timeout;
+       /* # scheduler threads in each pool while starting */
+       int              *ksnd_nscheds;
         int              *ksnd_nconnds;         /* # connection daemons */
+        int              *ksnd_nconnds_max;     /* max # connection daemons */
         int              *ksnd_min_reconnectms; /* first connection retry after (ms)... */
         int              *ksnd_max_reconnectms; /* ...exponentially increasing to this */
         int              *ksnd_eager_ack;       /* make TCP ack eagerly? */
@@ -142,27 +153,35 @@ typedef struct
 
 typedef struct
 {
-        __u64             ksnn_incarnation;     /* my epoch */
-        cfs_spinlock_t    ksnn_lock;            /* serialise */
-        int               ksnn_npeers;          /* # peers */
-        int               ksnn_shutdown;        /* shutting down? */
-        int               ksnn_ninterfaces;     /* IP interfaces */
-        ksock_interface_t ksnn_interfaces[LNET_MAX_INTERFACES];
+       __u64             ksnn_incarnation;     /* my epoch */
+       spinlock_t        ksnn_lock;            /* serialise */
+       cfs_list_t        ksnn_list;            /* chain on global list */
+       int               ksnn_npeers;          /* # peers */
+       int               ksnn_shutdown;        /* shutting down? */
+       int               ksnn_ninterfaces;     /* IP interfaces */
+       ksock_interface_t ksnn_interfaces[LNET_MAX_INTERFACES];
 } ksock_net_t;
 
+/** connd timeout */
+#define SOCKNAL_CONND_TIMEOUT  120
+/** reserved thread for accepting & creating new connd */
+#define SOCKNAL_CONND_RESV     1
+
 typedef struct
 {
-        int               ksnd_init;           /* initialisation state */
-        int               ksnd_nnets;          /* # networks set up */
-
-        cfs_rwlock_t      ksnd_global_lock;    /* stabilize peer/conn ops */
-        cfs_list_t       *ksnd_peers;          /* hash table of all my known peers */
-        int               ksnd_peer_hash_size; /* size of ksnd_peers */
-
-        int               ksnd_nthreads;       /* # live threads */
-        int               ksnd_shuttingdown;   /* tell threads to exit */
-        int               ksnd_nschedulers;    /* # schedulers */
-        ksock_sched_t    *ksnd_schedulers;     /* their state */
+       int                     ksnd_init;      /* initialisation state */
+       int                     ksnd_nnets;     /* # networks set up */
+       cfs_list_t              ksnd_nets;      /* list of nets */
+       /* stabilize peer/conn ops */
+       rwlock_t                ksnd_global_lock;
+       /* hash table of all my known peers */
+       cfs_list_t              *ksnd_peers;
+       int                     ksnd_peer_hash_size; /* size of ksnd_peers */
+
+       int                     ksnd_nthreads;  /* # live threads */
+       int                     ksnd_shuttingdown; /* tell threads to exit */
+       /* schedulers information */
+       struct ksock_sched_info **ksnd_sched_info;
 
         cfs_atomic_t      ksnd_nactive_txs;    /* #active txs */
 
@@ -171,7 +190,7 @@ typedef struct
         cfs_list_t        ksnd_enomem_conns;   /* conns to retry: reaper_lock*/
         cfs_waitq_t       ksnd_reaper_waitq;   /* reaper sleeps here */
         cfs_time_t        ksnd_reaper_waketime;/* when reaper will wake */
-        cfs_spinlock_t    ksnd_reaper_lock;    /* serialise */
+       spinlock_t        ksnd_reaper_lock;     /* serialise */
 
         int               ksnd_enomem_tx;      /* test ENOMEM sender */
         int               ksnd_stall_tx;       /* test sluggish sender */
@@ -181,12 +200,18 @@ typedef struct
         cfs_list_t        ksnd_connd_routes;   /* routes waiting to be connected */
         cfs_waitq_t       ksnd_connd_waitq;    /* connds sleep here */
         int               ksnd_connd_connecting;/* # connds connecting */
-        cfs_spinlock_t    ksnd_connd_lock;     /* serialise */
-
-        cfs_list_t        ksnd_idle_noop_txs;  /* list head for freed noop tx */
-        cfs_spinlock_t    ksnd_tx_lock;        /* serialise, NOT safe in g_lock */
-
-        ksock_irqinfo_t   ksnd_irqinfo[CFS_NR_IRQS];/* irq->scheduler lookup */
+        /** time stamp of the last failed connecting attempt */
+        long              ksnd_connd_failed_stamp;
+        /** # starting connd */
+        unsigned          ksnd_connd_starting;
+        /** time stamp of the last starting connd */
+        long              ksnd_connd_starting_stamp;
+        /** # running connd */
+        unsigned          ksnd_connd_running;
+       spinlock_t        ksnd_connd_lock;      /* serialise */
+
+       cfs_list_t        ksnd_idle_noop_txs;   /* list head for freed noop tx */
+       spinlock_t        ksnd_tx_lock;         /* serialise, g_lock unsafe */
 
 } ksock_nal_data_t;
 
@@ -218,9 +243,10 @@ typedef struct                                  /* transmit packet */
         int            tx_niov;        /* # packet iovec frags */
         struct iovec  *tx_iov;         /* packet iovec frags */
         int            tx_nkiov;       /* # packet page frags */
-        unsigned int   tx_zc_capable:1; /* payload is large enough for ZC */
-        unsigned int   tx_zc_checked:1; /* Have I checked if I should ZC? */
-        unsigned int   tx_nonblk:1;    /* it's a non-blocking ACK */
+        unsigned short tx_zc_aborted;  /* aborted ZC request */
+        unsigned short tx_zc_capable:1; /* payload is large enough for ZC */
+        unsigned short tx_zc_checked:1; /* Have I checked if I should ZC? */
+        unsigned short tx_nonblk:1;    /* it's a non-blocking ACK */
         lnet_kiov_t   *tx_kiov;        /* packet page frags */
         struct ksock_conn  *tx_conn;        /* owning conn */
         lnet_msg_t    *tx_lnetmsg;     /* lnet message for lnet_finalize() */
@@ -270,10 +296,11 @@ typedef struct ksock_conn
         __u32               ksnc_myipaddr;   /* my IP */
         __u32               ksnc_ipaddr;     /* peer's IP */
         int                 ksnc_port;       /* peer's port */
-        int                 ksnc_type:3;     /* type of connection, should be signed value */
-        int                 ksnc_closing:1;  /* being shut down */
-        int                 ksnc_flip:1;     /* flip or not, only for V2.x */
-        int                 ksnc_zc_capable:1; /* enable to ZC */
+       signed int          ksnc_type:3;     /* type of connection,
+                                             * should be signed value */
+       unsigned int        ksnc_closing:1;  /* being shut down */
+       unsigned int        ksnc_flip:1;     /* flip or not, only for V2.x */
+       unsigned int        ksnc_zc_capable:1; /* enable to ZC */
         struct ksock_proto *ksnc_proto;      /* protocol for the connection */
 
         /* reader */
@@ -348,7 +375,7 @@ typedef struct ksock_peer
         cfs_list_t            ksnp_conns;    /* all active connections */
         cfs_list_t            ksnp_routes;   /* routes */
         cfs_list_t            ksnp_tx_queue; /* waiting packets */
-        cfs_spinlock_t        ksnp_lock;     /* serialize, NOT safe in g_lock */
+       spinlock_t            ksnp_lock;        /* serialize, g_lock unsafe */
         cfs_list_t            ksnp_zc_req_list;   /* zero copy requests wait for ACK  */
         cfs_time_t            ksnp_send_keepalive; /* time to send keepalive */
         lnet_ni_t            *ksnp_ni;       /* which network */
@@ -442,13 +469,13 @@ ksocknal_connsock_addref (ksock_conn_t *conn)
 {
         int   rc = -ESHUTDOWN;
 
-        cfs_read_lock (&ksocknal_data.ksnd_global_lock);
-        if (!conn->ksnc_closing) {
-                LASSERT (cfs_atomic_read(&conn->ksnc_sock_refcount) > 0);
-                cfs_atomic_inc(&conn->ksnc_sock_refcount);
-                rc = 0;
-        }
-        cfs_read_unlock (&ksocknal_data.ksnd_global_lock);
+       read_lock(&ksocknal_data.ksnd_global_lock);
+       if (!conn->ksnc_closing) {
+               LASSERT(cfs_atomic_read(&conn->ksnc_sock_refcount) > 0);
+               cfs_atomic_inc(&conn->ksnc_sock_refcount);
+               rc = 0;
+       }
+       read_unlock(&ksocknal_data.ksnd_global_lock);
 
         return (rc);
 }
@@ -554,7 +581,7 @@ extern void ksocknal_txlist_done (lnet_ni_t *ni, cfs_list_t *txlist,
                                   int error);
 extern void ksocknal_notify (lnet_ni_t *ni, lnet_nid_t gw_nid, int alive);
 extern void ksocknal_query (struct lnet_ni *ni, lnet_nid_t nid, cfs_time_t *when);
-extern int ksocknal_thread_start (int (*fn)(void *arg), void *arg);
+extern int ksocknal_thread_start(int (*fn)(void *arg), void *arg, char *name);
 extern void ksocknal_thread_fini (void);
 extern void ksocknal_launch_all_connections_locked (ksock_peer_t *peer);
 extern ksock_route_t *ksocknal_find_connectable_route_locked (ksock_peer_t *peer);
@@ -576,9 +603,7 @@ extern void ksocknal_lib_save_callback(cfs_socket_t *sock, ksock_conn_t *conn);
 extern void ksocknal_lib_set_callback(cfs_socket_t *sock,  ksock_conn_t *conn);
 extern void ksocknal_lib_reset_callback(cfs_socket_t *sock, ksock_conn_t *conn);
 extern void ksocknal_lib_push_conn (ksock_conn_t *conn);
-extern void ksocknal_lib_bind_irq (unsigned int irq);
 extern int ksocknal_lib_get_conn_addrs (ksock_conn_t *conn);
-extern unsigned int ksocknal_lib_sock_irq (cfs_socket_t *sock);
 extern int ksocknal_lib_setup_sock (cfs_socket_t *so);
 extern int ksocknal_lib_send_iov (ksock_conn_t *conn, ksock_tx_t *tx);
 extern int ksocknal_lib_send_kiov (ksock_conn_t *conn, ksock_tx_t *tx);