📄 ptllnd.c
字号:
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * * Copyright (C) 2005 Cluster File Systems, Inc. All rights reserved. * Author: Eric Barton <eeb@bartonsoftware.com> * * This file is part of the Lustre file system, http://www.lustre.org * Lustre is a trademark of Cluster File Systems, Inc. * * This file is confidential source code owned by Cluster File Systems. * No viewing, modification, compilation, redistribution, or any other * form of use is permitted except through a signed license agreement. * * If you have not signed such an agreement, then you have no rights to * this file. Please destroy it immediately and contact CFS. * */#include "ptllnd.h"lnd_t the_ptllnd = { .lnd_type = PTLLND, .lnd_startup = ptllnd_startup, .lnd_shutdown = ptllnd_shutdown, .lnd_ctl = ptllnd_ctl, .lnd_send = ptllnd_send, .lnd_recv = ptllnd_recv, .lnd_eager_recv = ptllnd_eager_recv, .lnd_notify = ptllnd_notify, .lnd_wait = ptllnd_wait, .lnd_setasync = ptllnd_setasync,};static int ptllnd_ni_count = 0;static struct list_head ptllnd_idle_history;static struct list_head ptllnd_history_list;voidptllnd_history_fini(void){ ptllnd_he_t *he; while (!list_empty(&ptllnd_idle_history)) { he = list_entry(ptllnd_idle_history.next, ptllnd_he_t, he_list); list_del(&he->he_list); LIBCFS_FREE(he, sizeof(*he)); } while (!list_empty(&ptllnd_history_list)) { he = list_entry(ptllnd_history_list.next, ptllnd_he_t, he_list); list_del(&he->he_list); LIBCFS_FREE(he, sizeof(*he)); }}intptllnd_history_init(void){ int i; ptllnd_he_t *he; int n; int rc; CFS_INIT_LIST_HEAD(&ptllnd_idle_history); CFS_INIT_LIST_HEAD(&ptllnd_history_list); rc = ptllnd_parse_int_tunable(&n, "PTLLND_HISTORY", 0); if (rc != 0) return rc; for (i = 0; i < n; i++) { LIBCFS_ALLOC(he, sizeof(*he)); if (he == NULL) { ptllnd_history_fini(); return -ENOMEM; } list_add(&he->he_list, &ptllnd_idle_history); } PTLLND_HISTORY("Init"); return 0;}voidptllnd_history(const char *fn, const char *file, const int line, const char *fmt, ...){ static int seq; va_list ap; ptllnd_he_t *he; if (!list_empty(&ptllnd_idle_history)) { he = list_entry(ptllnd_idle_history.next, ptllnd_he_t, he_list); } else if (!list_empty(&ptllnd_history_list)) { he = list_entry(ptllnd_history_list.next, ptllnd_he_t, he_list); } else { return; } list_del(&he->he_list); list_add_tail(&he->he_list, &ptllnd_history_list); he->he_seq = seq++; he->he_fn = fn; he->he_file = file; he->he_line = line; gettimeofday(&he->he_time, NULL); va_start(ap, fmt); vsnprintf(he->he_msg, sizeof(he->he_msg), fmt, ap); va_end(ap);}voidptllnd_dump_history(void){ ptllnd_he_t *he; PTLLND_HISTORY("dumping..."); while (!list_empty(&ptllnd_history_list)) { he = list_entry(ptllnd_history_list.next, ptllnd_he_t, he_list); list_del(&he->he_list); CDEBUG(D_WARNING, "%d %d.%06d (%s:%d:%s()) %s\n", he->he_seq, (int)he->he_time.tv_sec, (int)he->he_time.tv_usec, he->he_file, he->he_line, he->he_fn, he->he_msg); list_add_tail(&he->he_list, &ptllnd_idle_history); } PTLLND_HISTORY("complete");}void ptllnd_assert_wire_constants (void){ /* Wire protocol assertions generated by 'wirecheck' * running on Linux fedora 2.6.11-co-0.6.4 #1 Mon Jun 19 05:36:13 UTC 2006 i686 i686 i386 GNU * with gcc version 4.1.1 20060525 (Red Hat 4.1.1-1) */ /* Constants... */ CLASSERT (PTL_RESERVED_MATCHBITS == 0x100); CLASSERT (LNET_MSG_MATCHBITS == 0); CLASSERT (PTLLND_MSG_MAGIC == 0x50746C4E); CLASSERT (PTLLND_MSG_VERSION == 0x04); CLASSERT (PTLLND_RDMA_OK == 0x00); CLASSERT (PTLLND_RDMA_FAIL == 0x01); CLASSERT (PTLLND_MSG_TYPE_INVALID == 0x00); CLASSERT (PTLLND_MSG_TYPE_PUT == 0x01); CLASSERT (PTLLND_MSG_TYPE_GET == 0x02); CLASSERT (PTLLND_MSG_TYPE_IMMEDIATE == 0x03); CLASSERT (PTLLND_MSG_TYPE_NOOP == 0x04); CLASSERT (PTLLND_MSG_TYPE_HELLO == 0x05); CLASSERT (PTLLND_MSG_TYPE_NAK == 0x06); /* Checks for struct kptl_msg_t */ CLASSERT ((int)sizeof(kptl_msg_t) == 136); CLASSERT ((int)offsetof(kptl_msg_t, ptlm_magic) == 0); CLASSERT ((int)sizeof(((kptl_msg_t *)0)->ptlm_magic) == 4); CLASSERT ((int)offsetof(kptl_msg_t, ptlm_version) == 4); CLASSERT ((int)sizeof(((kptl_msg_t *)0)->ptlm_version) == 2); CLASSERT ((int)offsetof(kptl_msg_t, ptlm_type) == 6); CLASSERT ((int)sizeof(((kptl_msg_t *)0)->ptlm_type) == 1); CLASSERT ((int)offsetof(kptl_msg_t, ptlm_credits) == 7); CLASSERT ((int)sizeof(((kptl_msg_t *)0)->ptlm_credits) == 1); CLASSERT ((int)offsetof(kptl_msg_t, ptlm_nob) == 8); CLASSERT ((int)sizeof(((kptl_msg_t *)0)->ptlm_nob) == 4); CLASSERT ((int)offsetof(kptl_msg_t, ptlm_cksum) == 12); CLASSERT ((int)sizeof(((kptl_msg_t *)0)->ptlm_cksum) == 4); CLASSERT ((int)offsetof(kptl_msg_t, ptlm_srcnid) == 16); CLASSERT ((int)sizeof(((kptl_msg_t *)0)->ptlm_srcnid) == 8); CLASSERT ((int)offsetof(kptl_msg_t, ptlm_srcstamp) == 24); CLASSERT ((int)sizeof(((kptl_msg_t *)0)->ptlm_srcstamp) == 8); CLASSERT ((int)offsetof(kptl_msg_t, ptlm_dstnid) == 32); CLASSERT ((int)sizeof(((kptl_msg_t *)0)->ptlm_dstnid) == 8); CLASSERT ((int)offsetof(kptl_msg_t, ptlm_dststamp) == 40); CLASSERT ((int)sizeof(((kptl_msg_t *)0)->ptlm_dststamp) == 8); CLASSERT ((int)offsetof(kptl_msg_t, ptlm_srcpid) == 48); CLASSERT ((int)sizeof(((kptl_msg_t *)0)->ptlm_srcpid) == 4); CLASSERT ((int)offsetof(kptl_msg_t, ptlm_dstpid) == 52); CLASSERT ((int)sizeof(((kptl_msg_t *)0)->ptlm_dstpid) == 4); CLASSERT ((int)offsetof(kptl_msg_t, ptlm_u.immediate) == 56); CLASSERT ((int)sizeof(((kptl_msg_t *)0)->ptlm_u.immediate) == 72); CLASSERT ((int)offsetof(kptl_msg_t, ptlm_u.rdma) == 56); CLASSERT ((int)sizeof(((kptl_msg_t *)0)->ptlm_u.rdma) == 80); CLASSERT ((int)offsetof(kptl_msg_t, ptlm_u.hello) == 56); CLASSERT ((int)sizeof(((kptl_msg_t *)0)->ptlm_u.hello) == 12); /* Checks for struct kptl_immediate_msg_t */ CLASSERT ((int)sizeof(kptl_immediate_msg_t) == 72); CLASSERT ((int)offsetof(kptl_immediate_msg_t, kptlim_hdr) == 0); CLASSERT ((int)sizeof(((kptl_immediate_msg_t *)0)->kptlim_hdr) == 72); CLASSERT ((int)offsetof(kptl_immediate_msg_t, kptlim_payload[13]) == 85); CLASSERT ((int)sizeof(((kptl_immediate_msg_t *)0)->kptlim_payload[13]) == 1); /* Checks for struct kptl_rdma_msg_t */ CLASSERT ((int)sizeof(kptl_rdma_msg_t) == 80); CLASSERT ((int)offsetof(kptl_rdma_msg_t, kptlrm_hdr) == 0); CLASSERT ((int)sizeof(((kptl_rdma_msg_t *)0)->kptlrm_hdr) == 72); CLASSERT ((int)offsetof(kptl_rdma_msg_t, kptlrm_matchbits) == 72); CLASSERT ((int)sizeof(((kptl_rdma_msg_t *)0)->kptlrm_matchbits) == 8); /* Checks for struct kptl_hello_msg_t */ CLASSERT ((int)sizeof(kptl_hello_msg_t) == 12); CLASSERT ((int)offsetof(kptl_hello_msg_t, kptlhm_matchbits) == 0); CLASSERT ((int)sizeof(((kptl_hello_msg_t *)0)->kptlhm_matchbits) == 8); CLASSERT ((int)offsetof(kptl_hello_msg_t, kptlhm_max_msg_size) == 8); CLASSERT ((int)sizeof(((kptl_hello_msg_t *)0)->kptlhm_max_msg_size) == 4);}intptllnd_parse_int_tunable(int *value, char *name, int dflt){ char *env = getenv(name); char *end; if (env == NULL) { *value = dflt; return 0; } *value = strtoull(env, &end, 0); if (*end == 0) return 0; CERROR("Can't parse tunable %s=%s\n", name, env); return -EINVAL;}intptllnd_get_tunables(lnet_ni_t *ni){ ptllnd_ni_t *plni = ni->ni_data; int max_msg_size; int msgs_per_buffer; int rc; int temp; /* Other tunable defaults depend on this */ rc = ptllnd_parse_int_tunable(&plni->plni_debug, "PTLLND_DEBUG", 0); if (rc != 0) return rc; rc = ptllnd_parse_int_tunable(&plni->plni_portal, "PTLLND_PORTAL", PTLLND_PORTAL); if (rc != 0) return rc; rc = ptllnd_parse_int_tunable(&temp, "PTLLND_PID", PTLLND_PID); if (rc != 0) return rc; plni->plni_ptllnd_pid = (ptl_pid_t)temp; rc = ptllnd_parse_int_tunable(&plni->plni_peer_credits, "PTLLND_PEERCREDITS", PTLLND_PEERCREDITS); if (rc != 0) return rc; rc = ptllnd_parse_int_tunable(&max_msg_size, "PTLLND_MAX_MSG_SIZE", PTLLND_MAX_ULND_MSG_SIZE); if (rc != 0) return rc; rc = ptllnd_parse_int_tunable(&msgs_per_buffer, "PTLLND_MSGS_PER_BUFFER", 64); if (rc != 0) return rc; rc = ptllnd_parse_int_tunable(&plni->plni_msgs_spare, "PTLLND_MSGS_SPARE", 256); if (rc != 0) return rc; rc = ptllnd_parse_int_tunable(&plni->plni_peer_hash_size, "PTLLND_PEER_HASH_SIZE", 101); if (rc != 0) return rc; rc = ptllnd_parse_int_tunable(&plni->plni_eq_size, "PTLLND_EQ_SIZE", 1024); if (rc != 0) return rc; rc = ptllnd_parse_int_tunable(&plni->plni_checksum, "PTLLND_CHECKSUM", 0); if (rc != 0) return rc; rc = ptllnd_parse_int_tunable(&plni->plni_max_tx_history, "PTLLND_TX_HISTORY", plni->plni_debug ? 1024 : 0); if (rc != 0) return rc; rc = ptllnd_parse_int_tunable(&plni->plni_abort_on_protocol_mismatch, "PTLLND_ABORT_ON_PROTOCOL_MISMATCH", 1); if (rc != 0) return rc; rc = ptllnd_parse_int_tunable(&plni->plni_abort_on_nak, "PTLLND_ABORT_ON_NAK", 0); if (rc != 0) return rc; rc = ptllnd_parse_int_tunable(&plni->plni_dump_on_nak, "PTLLND_DUMP_ON_NAK", plni->plni_debug); if (rc != 0) return rc; rc = ptllnd_parse_int_tunable(&plni->plni_watchdog_interval, "PTLLND_WATCHDOG_INTERVAL", 1); if (rc != 0) return rc; if (plni->plni_watchdog_interval <= 0) plni->plni_watchdog_interval = 1; rc = ptllnd_parse_int_tunable(&plni->plni_timeout, "PTLLND_TIMEOUT", 50); if (rc != 0) return rc; rc = ptllnd_parse_int_tunable(&plni->plni_long_wait, "PTLLND_LONG_WAIT", plni->plni_debug ? 5 : plni->plni_timeout); if (rc != 0) return rc; plni->plni_long_wait *= 1000; /* convert to mS */ plni->plni_max_msg_size = max_msg_size & ~7; if (plni->plni_max_msg_size < PTLLND_MIN_BUFFER_SIZE) plni->plni_max_msg_size = PTLLND_MIN_BUFFER_SIZE; CLASSERT ((PTLLND_MIN_BUFFER_SIZE & 7) == 0); CLASSERT (sizeof(kptl_msg_t) <= PTLLND_MIN_BUFFER_SIZE); plni->plni_buffer_size = plni->plni_max_msg_size * msgs_per_buffer; CDEBUG(D_NET, "portal = %d\n",plni->plni_portal); CDEBUG(D_NET, "ptllnd_pid = %d\n",plni->plni_ptllnd_pid); CDEBUG(D_NET, "max_msg_size = %d\n",max_msg_size); CDEBUG(D_NET, "msgs_per_buffer = %d\n",msgs_per_buffer); CDEBUG(D_NET, "msgs_spare = %d\n",plni->plni_msgs_spare); CDEBUG(D_NET, "peer_hash_size = %d\n",plni->plni_peer_hash_size); CDEBUG(D_NET, "eq_size = %d\n",plni->plni_eq_size); CDEBUG(D_NET, "max_msg_size = %d\n",plni->plni_max_msg_size); CDEBUG(D_NET, "buffer_size = %d\n",plni->plni_buffer_size); return 0;}ptllnd_buffer_t *ptllnd_create_buffer (lnet_ni_t *ni){ ptllnd_ni_t *plni = ni->ni_data; ptllnd_buffer_t *buf; LIBCFS_ALLOC(buf, sizeof(*buf)); if (buf == NULL) { CERROR("Can't allocate buffer descriptor\n"); return NULL; } buf->plb_ni = ni; buf->plb_posted = 0; CFS_INIT_LIST_HEAD(&buf->plb_list); LIBCFS_ALLOC(buf->plb_buffer, plni->plni_buffer_size); if (buf->plb_buffer == NULL) { CERROR("Can't allocate buffer size %d\n", plni->plni_buffer_size); LIBCFS_FREE(buf, sizeof(*buf)); return NULL; } list_add(&buf->plb_list, &plni->plni_buffers); plni->plni_nbuffers++; return buf;}voidptllnd_destroy_buffer (ptllnd_buffer_t *buf){ ptllnd_ni_t *plni = buf->plb_ni->ni_data; LASSERT (!buf->plb_posted); plni->plni_nbuffers--; list_del(&buf->plb_list); LIBCFS_FREE(buf->plb_buffer, plni->plni_buffer_size); LIBCFS_FREE(buf, sizeof(*buf));}intptllnd_size_buffers (lnet_ni_t *ni, int delta){ ptllnd_ni_t *plni = ni->ni_data; ptllnd_buffer_t *buf; int nmsgs; int nbufs; int rc;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -