From 7f8cde3b77ada95e8b96dee1996f8d40bd17a538 Mon Sep 17 00:00:00 2001 From: James Simmons Date: Wed, 28 Feb 2024 21:34:17 -0500 Subject: [PATCH] LU-9859 lnet: move CPT handling to LNet The CPT work is used for LNet and ptlrpc which is the Lustre LNet interface. Move this work there and merge the lib-mem.c code as well since they both work closely together. Move cpt debugfs handling from libcfs to lnet. Now all remaining debugfs in libcfs is for debugging. Test-Parameters: trivial Change-Id: I016a90520bd7c6428b45bafff8618bc864e9112b Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/52923 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Timothy Day Reviewed-by: Oleg Drokin --- libcfs/include/libcfs/Makefile.am | 1 - libcfs/include/libcfs/libcfs.h | 1 - libcfs/libcfs/Makefile.in | 4 +- libcfs/libcfs/autoMakefile.am | 2 +- libcfs/libcfs/module.c | 114 ++------------------- lnet/include/lnet/Makefile.am | 1 + .../libcfs_cpu.h => lnet/include/lnet/lib-cpt.h | 19 ++-- lnet/include/lnet/lib-lnet.h | 1 + lnet/lnet/Makefile.in | 6 +- lnet/lnet/autoMakefile.am | 2 +- libcfs/libcfs/libcfs_cpu.c => lnet/lnet/lib-cpt.c | 106 ++++++++++++++++--- lnet/lnet/lib-mem.c | 114 --------------------- lnet/lnet/{router_proc.c => lnet_debugfs.c} | 103 +++++++++++++++++-- lnet/lnet/module.c | 9 ++ lustre/include/obd_support.h | 1 + 15 files changed, 226 insertions(+), 258 deletions(-) rename libcfs/include/libcfs/libcfs_cpu.h => lnet/include/lnet/lib-cpt.h (97%) rename libcfs/libcfs/libcfs_cpu.c => lnet/lnet/lib-cpt.c (92%) delete mode 100644 lnet/lnet/lib-mem.c rename lnet/lnet/{router_proc.c => lnet_debugfs.c} (92%) diff --git a/libcfs/include/libcfs/Makefile.am b/libcfs/include/libcfs/Makefile.am index 0d33759..308de9e 100644 --- a/libcfs/include/libcfs/Makefile.am +++ b/libcfs/include/libcfs/Makefile.am @@ -7,7 +7,6 @@ libcfsdir = $(includedir)/libcfs EXTRA_DIST = \ libcfs.h \ - libcfs_cpu.h \ libcfs_crypto.h \ libcfs_debug.h \ libcfs_fail.h \ diff --git a/libcfs/include/libcfs/libcfs.h b/libcfs/include/libcfs/libcfs.h index 0c646f9..84138760 100644 --- a/libcfs/include/libcfs/libcfs.h +++ b/libcfs/include/libcfs/libcfs.h @@ -49,7 +49,6 @@ #include #include #include -#include #include #include #include diff --git a/libcfs/libcfs/Makefile.in b/libcfs/libcfs/Makefile.in index 3dd6942..7808af2 100644 --- a/libcfs/libcfs/Makefile.in +++ b/libcfs/libcfs/Makefile.in @@ -15,11 +15,9 @@ default: all libcfs-linux-objs := $(addprefix linux/,$(libcfs-linux-objs)) libcfs-crypto-objs := $(addprefix crypto/,$(libcfs-crypto-objs)) -libcfs-objs-$(CONFIG_SMP) = libcfs_cpu.o libcfs-all-objs := debug.o fail.o module.o tracefile.o \ libcfs_string.o hash.o \ - linux-crypto.o linux-crypto-adler.o \ - $(libcfs-objs-y) + linux-crypto.o linux-crypto-adler.o libcfs-objs := $(libcfs-linux-objs) $(libcfs-all-objs) @LLCRYPT_TRUE@libcfs-objs += $(libcfs-crypto-objs) diff --git a/libcfs/libcfs/autoMakefile.am b/libcfs/libcfs/autoMakefile.am index 8c312a0..633b359 100644 --- a/libcfs/libcfs/autoMakefile.am +++ b/libcfs/libcfs/autoMakefile.am @@ -58,4 +58,4 @@ endif # MODULES MOSTLYCLEANFILES := @MOSTLYCLEANFILES@ linux/*.o libcfs crypto/*.o EXTRA_DIST := $(libcfs-all-objs:%.o=%.c) tracefile.h \ - fail.c libcfs_cpu.c linux-crypto.h + fail.c linux-crypto.h diff --git a/libcfs/libcfs/module.c b/libcfs/libcfs/module.c index d21cbb2..293f786 100644 --- a/libcfs/libcfs/module.c +++ b/libcfs/libcfs/module.c @@ -55,6 +55,16 @@ #include #include "tracefile.h" +int cpu_npartitions; +EXPORT_SYMBOL(cpu_npartitions); +module_param(cpu_npartitions, int, 0444); +MODULE_PARM_DESC(cpu_npartitions, "# of CPU partitions"); + +char *cpu_pattern = "N"; +EXPORT_SYMBOL(cpu_pattern); +module_param(cpu_pattern, charp, 0444); +MODULE_PARM_DESC(cpu_pattern, "CPU partitions pattern"); + struct lnet_debugfs_symlink_def { const char *name; const char *target; @@ -317,88 +327,6 @@ static int debugfs_dostring(struct ctl_table *table, int write, return len; } -static int proc_cpt_table(struct ctl_table *table, int write, - void __user *buffer, size_t *lenp, loff_t *ppos) -{ - size_t nob = *lenp; - loff_t pos = *ppos; - char *buf = NULL; - int len = 4096; - int rc = 0; - - if (write) - return -EPERM; - - while (1) { - LIBCFS_ALLOC(buf, len); - if (buf == NULL) - return -ENOMEM; - - rc = cfs_cpt_table_print(cfs_cpt_tab, buf, len); - if (rc >= 0) - break; - - if (rc == -EFBIG) { - LIBCFS_FREE(buf, len); - len <<= 1; - continue; - } - goto out; - } - - if (pos >= rc) { - rc = 0; - goto out; - } - - rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL); -out: - if (buf != NULL) - LIBCFS_FREE(buf, len); - return rc; -} - -static int proc_cpt_distance(struct ctl_table *table, int write, - void __user *buffer, size_t *lenp, loff_t *ppos) -{ - size_t nob = *lenp; - loff_t pos = *ppos; - char *buf = NULL; - int len = 4096; - int rc = 0; - - if (write) - return -EPERM; - - while (1) { - LIBCFS_ALLOC(buf, len); - if (buf == NULL) - return -ENOMEM; - - rc = cfs_cpt_distance_print(cfs_cpt_tab, buf, len); - if (rc >= 0) - break; - - if (rc == -EFBIG) { - LIBCFS_FREE(buf, len); - len <<= 1; - continue; - } - goto out; - } - - if (pos >= rc) { - rc = 0; - goto out; - } - - rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL); - out: - if (buf != NULL) - LIBCFS_FREE(buf, len); - return rc; -} - static struct ctl_table lnet_table[] = { { .procname = "debug", @@ -422,18 +350,6 @@ static struct ctl_table lnet_table[] = { .proc_handler = &proc_dobitmasks, }, { - .procname = "cpu_partition_table", - .maxlen = 128, - .mode = 0444, - .proc_handler = &proc_cpt_table, - }, - { - .procname = "cpu_partition_distance", - .maxlen = 128, - .mode = 0444, - .proc_handler = &proc_cpt_distance, - }, - { .procname = "debug_log_upcall", .data = lnet_debug_log_upcall, .maxlen = sizeof(lnet_debug_log_upcall), @@ -679,16 +595,12 @@ int libcfs_setup(void) goto cleanup_lock; } - rc = cfs_cpu_init(); - if (rc != 0) - goto cleanup_debug; - cfs_rehash_wq = alloc_workqueue("cfs_rh", WQ_SYSFS, 4); if (!cfs_rehash_wq) { rc = -ENOMEM; CERROR("libcfs: failed to start rehash workqueue: rc = %d\n", rc); - goto cleanup_cpu; + goto cleanup_debug; } rc = cfs_crypto_register(); @@ -706,8 +618,6 @@ out: cleanup_wq: destroy_workqueue(cfs_rehash_wq); cfs_rehash_wq = NULL; -cleanup_cpu: - cfs_cpu_fini(); cleanup_debug: libcfs_debug_cleanup(); cleanup_lock: @@ -760,8 +670,6 @@ static void __exit libcfs_exit(void) cfs_crypto_unregister(); - cfs_cpu_fini(); - /* the below message is checked in test-framework.sh check_mem_leak() */ if (libcfs_kmem_read() != 0) CERROR("Portals memory leaked: %lld bytes\n", diff --git a/lnet/include/lnet/Makefile.am b/lnet/include/lnet/Makefile.am index 88a4e4c..609dd3e 100644 --- a/lnet/include/lnet/Makefile.am +++ b/lnet/include/lnet/Makefile.am @@ -1,5 +1,6 @@ EXTRA_DIST = \ api.h \ + lib-cpt.h \ lib-lnet.h \ lib-types.h \ udsp.h \ diff --git a/libcfs/include/libcfs/libcfs_cpu.h b/lnet/include/lnet/lib-cpt.h similarity index 97% rename from libcfs/include/libcfs/libcfs_cpu.h rename to lnet/include/lnet/lib-cpt.h index 1009318..55ef966 100644 --- a/libcfs/include/libcfs/libcfs_cpu.h +++ b/lnet/include/lnet/lib-cpt.h @@ -15,15 +15,11 @@ * * GPL HEADER END */ -/* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * * Copyright (c) 2012, 2017, Intel Corporation. */ -/* - * This file is part of Lustre, http://www.lustre.org/ - * - * libcfs/include/libcfs/libcfs_cpu.h +/* This file is part of Lustre, http://www.lustre.org/ * * CPU partition * . CPU partition is virtual processing unit @@ -296,6 +292,10 @@ static inline void cfs_cpu_fini(void) #endif /* CONFIG_SMP */ +/* Module parameters */ +extern int cpu_npartitions; +extern char *cpu_pattern; + static inline struct workqueue_struct *cfs_cpt_bind_workqueue(const char *wq_name, struct cfs_cpt_table *tbl, @@ -320,16 +320,13 @@ struct workqueue_struct *cfs_cpt_bind_workqueue(const char *wq_name, return wq; } -/* - * allocate per-cpu-partition data, returned value is an array of pointers, +/* allocate per-cpu-partition data, returned value is an array of pointers, * variable can be indexed by CPU ID. * cptab != NULL: size of array is number of CPU partitions * cptab == NULL: size of array is number of HW cores */ void *cfs_percpt_alloc(struct cfs_cpt_table *cptab, unsigned int size); -/* - * destroy per-cpu-partition variable - */ +/* destroy per-cpu-partition variable */ void cfs_percpt_free(void *vars); int cfs_percpt_number(void *vars); diff --git a/lnet/include/lnet/lib-lnet.h b/lnet/include/lnet/lib-lnet.h index 68a48ae..ad33e40 100644 --- a/lnet/include/lnet/lib-lnet.h +++ b/lnet/include/lnet/lib-lnet.h @@ -44,6 +44,7 @@ #include #include +#include #include #include #include diff --git a/lnet/lnet/Makefile.in b/lnet/lnet/Makefile.in index 21ba3c0..ec64cac 100644 --- a/lnet/lnet/Makefile.in +++ b/lnet/lnet/Makefile.in @@ -1,9 +1,11 @@ MODULES := lnet +lnet-objs-$(CONFIG_SMP) = lib-cpt.o lnet-objs := api-ni.o config.o nidstrings.o lnet_rdma.o lock.o -lnet-objs += lib-me.o lib-msg.o lib-md.o lib-ptl.o lib-mem.o +lnet-objs += lib-me.o lib-msg.o lib-md.o lib-ptl.o lnet-objs += lib-socket.o lib-move.o module.o lo.o -lnet-objs += router.o router_proc.o acceptor.o peer.o net_fault.o udsp.o +lnet-objs += router.o lnet_debugfs.o acceptor.o peer.o net_fault.o udsp.o +lnet-objs += $(lnet-objs-y) CFLAGS_lnet_rdma.o += -I @GDS_PATH@ -I@CUDA_PATH@ diff --git a/lnet/lnet/autoMakefile.am b/lnet/lnet/autoMakefile.am index eccb202..02831ac 100644 --- a/lnet/lnet/autoMakefile.am +++ b/lnet/lnet/autoMakefile.am @@ -6,6 +6,6 @@ endif # LINUX endif # MODULES -EXTRA_DIST := $(lnet-objs:%.o=%.c) +EXTRA_DIST := $(lnet-objs:%.o=%.c) lib-cpt.c MOSTLYCLEANFILES = @MOSTLYCLEANFILES@ lnet diff --git a/libcfs/libcfs/libcfs_cpu.c b/lnet/lnet/lib-cpt.c similarity index 92% rename from libcfs/libcfs/libcfs_cpu.c rename to lnet/lnet/lib-cpt.c index 763a033..a8ae50e 100644 --- a/libcfs/libcfs/libcfs_cpu.c +++ b/lnet/lnet/lib-cpt.c @@ -15,14 +15,12 @@ * * GPL HEADER END */ -/* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2017, Intel Corporation. */ -/* - * This file is part of Lustre, http://www.lustre.org/ +/* This file is part of Lustre, http://www.lustre.org/ * - * Please see comments in libcfs/include/libcfs/libcfs_cpu.h for introduction + * Please see comments in include/lnet/lib-cpt.h for introduction * * Author: liang@whamcloud.com */ @@ -31,8 +29,12 @@ #include #include +#include +#include + +#include #include -#include +#include /** virtual processing unit */ struct cfs_cpu_partition { @@ -79,7 +81,6 @@ EXPORT_SYMBOL(cfs_cpt_tab); * 1 : disable multiple partitions * >1 : specify number of partitions */ -static int cpu_npartitions; module_param(cpu_npartitions, int, 0444); MODULE_PARM_DESC(cpu_npartitions, "# of CPU partitions"); @@ -87,16 +88,15 @@ MODULE_PARM_DESC(cpu_npartitions, "# of CPU partitions"); * modparam for setting CPU partitions patterns: * * i.e: "0[0,1,2,3] 1[4,5,6,7]", number before bracket is CPU partition ID, - * number in bracket is processor ID (core or HT) + * number in bracket is processor ID (core or HT) * * i.e: "N 0[0,1] 1[2,3]" the first character 'N' means numbers in bracket - * are NUMA node ID, number before bracket is CPU partition ID. + * are NUMA node ID, number before bracket is CPU partition ID. * * i.e: "N", shortcut expression to create CPT from NUMA & CPU topology * * NB: If user specified cpu_pattern, cpu_npartitions will be ignored */ -static char *cpu_pattern = "N"; module_param(cpu_pattern, charp, 0444); MODULE_PARM_DESC(cpu_pattern, "CPU partitions pattern"); @@ -366,8 +366,7 @@ unsigned int cfs_cpt_distance(struct cfs_cpt_table *cptab, int cpt1, int cpt2) } EXPORT_SYMBOL(cfs_cpt_distance); -/* - * Calculate the maximum NUMA distance between all nodes in the +/* Calculate the maximum NUMA distance between all nodes in the * from_mask and all nodes in the to_mask. */ static unsigned int cfs_cpt_distance_calculate(nodemask_t *from_mask, @@ -795,8 +794,7 @@ static int cfs_cpt_choose_ncpus(struct cfs_cpt_table *cptab, int cpt, return 0; } - /* - * Allocate scratch buffers + /* Allocate scratch buffers * As we cannot initialize a cpumask_var_t, we need * to alloc both before we can risk trying to free either */ @@ -1126,6 +1124,86 @@ err_free_str: return ERR_PTR(rc); } +struct cfs_var_array { + unsigned int va_count; /* # of buffers */ + unsigned int va_size; /* size of each var */ + struct cfs_cpt_table *va_cptab; /* cpu partition table */ + void *va_ptrs[0]; /* buffer addresses */ +}; + +/* free per-cpu data, see more detail in cfs_percpt_free */ +void +cfs_percpt_free(void *vars) +{ + struct cfs_var_array *arr; + int i; + + arr = container_of(vars, struct cfs_var_array, va_ptrs[0]); + + for (i = 0; i < arr->va_count; i++) { + if (arr->va_ptrs[i]) + LIBCFS_FREE(arr->va_ptrs[i], arr->va_size); + } + + LIBCFS_FREE(arr, offsetof(struct cfs_var_array, + va_ptrs[arr->va_count])); +} +EXPORT_SYMBOL(cfs_percpt_free); + +/* allocate per cpu-partition variables, returned value is an array of pointers, + * variable can be indexed by CPU partition ID, i.e: + * + * arr = cfs_percpt_alloc(cfs_cpu_pt, size); + * then caller can access memory block for CPU 0 by arr[0], + * memory block for CPU 1 by arr[1]... + * memory block for CPU N by arr[N]... + * + * cacheline aligned. + */ +void * +cfs_percpt_alloc(struct cfs_cpt_table *cptab, unsigned int size) +{ + struct cfs_var_array *arr; + int count; + int i; + + count = cfs_cpt_number(cptab); + + LIBCFS_ALLOC(arr, offsetof(struct cfs_var_array, va_ptrs[count])); + if (!arr) + return NULL; + + size = L1_CACHE_ALIGN(size); + arr->va_size = size; + arr->va_count = count; + arr->va_cptab = cptab; + + for (i = 0; i < count; i++) { + LIBCFS_CPT_ALLOC(arr->va_ptrs[i], cptab, i, size); + if (!arr->va_ptrs[i]) { + cfs_percpt_free((void *)&arr->va_ptrs[0]); + return NULL; + } + } + + return (void *)&arr->va_ptrs[0]; +} +EXPORT_SYMBOL(cfs_percpt_alloc); + +/* return number of CPUs (or number of elements in per-cpu data) + * according to cptab of @vars + */ +int +cfs_percpt_number(void *vars) +{ + struct cfs_var_array *arr; + + arr = container_of(vars, struct cfs_var_array, va_ptrs[0]); + + return arr->va_count; +} +EXPORT_SYMBOL(cfs_percpt_number); + #ifdef CONFIG_HOTPLUG_CPU #ifdef HAVE_HOTPLUG_STATE_MACHINE static enum cpuhp_state lustre_cpu_online; diff --git a/lnet/lnet/lib-mem.c b/lnet/lnet/lib-mem.c deleted file mode 100644 index 2e3d5f2..0000000 --- a/lnet/lnet/lib-mem.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * GPL HEADER START - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License version 2 for more details (a copy is included - * in the LICENSE file that accompanied this code). - * - * GPL HEADER END - */ -/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012, Intel Corporation. - */ -/* This file is part of Lustre, http://www.lustre.org/ - * - * Author: liang@whamcloud.com - */ - -#define DEBUG_SUBSYSTEM S_LNET - -#include -#include -#include -#include -#include -#include - -struct cfs_var_array { - unsigned int va_count; /* # of buffers */ - unsigned int va_size; /* size of each var */ - struct cfs_cpt_table *va_cptab; /* cpu partition table */ - void *va_ptrs[0]; /* buffer addresses */ -}; - -/* free per-cpu data, see more detail in cfs_percpt_free - */ -void -cfs_percpt_free(void *vars) -{ - struct cfs_var_array *arr; - int i; - - arr = container_of(vars, struct cfs_var_array, va_ptrs[0]); - - for (i = 0; i < arr->va_count; i++) { - if (arr->va_ptrs[i] != NULL) - LIBCFS_FREE(arr->va_ptrs[i], arr->va_size); - } - - LIBCFS_FREE(arr, offsetof(struct cfs_var_array, - va_ptrs[arr->va_count])); -} -EXPORT_SYMBOL(cfs_percpt_free); - -/* allocate per cpu-partition variables, returned value is an array of pointers, - * variable can be indexed by CPU partition ID, i.e: - * - * arr = cfs_percpt_alloc(cfs_cpu_pt, size); - * then caller can access memory block for CPU 0 by arr[0], - * memory block for CPU 1 by arr[1]... - * memory block for CPU N by arr[N]... - * - * cacheline aligned. - */ -void * -cfs_percpt_alloc(struct cfs_cpt_table *cptab, unsigned int size) -{ - struct cfs_var_array *arr; - int count; - int i; - - count = cfs_cpt_number(cptab); - - LIBCFS_ALLOC(arr, offsetof(struct cfs_var_array, va_ptrs[count])); - if (!arr) - return NULL; - - size = L1_CACHE_ALIGN(size); - arr->va_size = size; - arr->va_count = count; - arr->va_cptab = cptab; - - for (i = 0; i < count; i++) { - LIBCFS_CPT_ALLOC(arr->va_ptrs[i], cptab, i, size); - if (!arr->va_ptrs[i]) { - cfs_percpt_free((void *)&arr->va_ptrs[0]); - return NULL; - } - } - - return (void *)&arr->va_ptrs[0]; -} -EXPORT_SYMBOL(cfs_percpt_alloc); - -/* return number of CPUs (or number of elements in per-cpu data) - * according to cptab of @vars - */ -int -cfs_percpt_number(void *vars) -{ - struct cfs_var_array *arr; - - arr = container_of(vars, struct cfs_var_array, va_ptrs[0]); - - return arr->va_count; -} -EXPORT_SYMBOL(cfs_percpt_number); diff --git a/lnet/lnet/router_proc.c b/lnet/lnet/lnet_debugfs.c similarity index 92% rename from lnet/lnet/router_proc.c rename to lnet/lnet/lnet_debugfs.c index af40833..0373b07 100644 --- a/lnet/lnet/router_proc.c +++ b/lnet/lnet/lnet_debugfs.c @@ -27,12 +27,8 @@ #include #include -/* This is really lnet_proc.c. You might need to update sanity test 215 - * if any file format is changed. */ - #define LNET_LOFFT_BITS (sizeof(loff_t) * 8) -/* - * NB: max allowed LNET_CPT_BITS is 8 on 64-bit system and 2 on 32-bit system +/* NB: max allowed LNET_CPT_BITS is 8 on 64-bit system and 2 on 32-bit system */ #define LNET_PROC_CPT_BITS (LNET_CPT_BITS + 1) /* change version, 16 bits or 8 bits */ @@ -40,8 +36,7 @@ clamp_t(int, LNET_LOFFT_BITS / 4, 8, 16) #define LNET_PROC_HASH_BITS LNET_PEER_HASH_BITS -/* - * bits for peer hash offset +/* bits for peer hash offset * NB: we don't use the highest bit of *ppos because it's signed */ #define LNET_PROC_HOFF_BITS (LNET_LOFFT_BITS - \ @@ -78,6 +73,88 @@ #define LNET_PROC_VERSION(v) ((unsigned int)((v) & LNET_PROC_VER_MASK)) +static int proc_cpt_table(struct ctl_table *table, int write, + void __user *buffer, size_t *lenp, loff_t *ppos) +{ + size_t nob = *lenp; + loff_t pos = *ppos; + char *buf = NULL; + int len = 4096; + int rc = 0; + + if (write) + return -EPERM; + + while (1) { + LIBCFS_ALLOC(buf, len); + if (!buf) + return -ENOMEM; + + rc = cfs_cpt_table_print(cfs_cpt_tab, buf, len); + if (rc >= 0) + break; + + if (rc == -EFBIG) { + LIBCFS_FREE(buf, len); + len <<= 1; + continue; + } + goto out; + } + + if (pos >= rc) { + rc = 0; + goto out; + } + + rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL); +out: + if (buf) + LIBCFS_FREE(buf, len); + return rc; +} + +static int proc_cpt_distance(struct ctl_table *table, int write, + void __user *buffer, size_t *lenp, loff_t *ppos) +{ + size_t nob = *lenp; + loff_t pos = *ppos; + char *buf = NULL; + int len = 4096; + int rc = 0; + + if (write) + return -EPERM; + + while (1) { + LIBCFS_ALLOC(buf, len); + if (!buf) + return -ENOMEM; + + rc = cfs_cpt_distance_print(cfs_cpt_tab, buf, len); + if (rc >= 0) + break; + + if (rc == -EFBIG) { + LIBCFS_FREE(buf, len); + len <<= 1; + continue; + } + goto out; + } + + if (pos >= rc) { + rc = 0; + goto out; + } + + rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL); +out: + if (buf) + LIBCFS_FREE(buf, len); + return rc; +} + static int proc_lnet_stats(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { @@ -847,6 +924,18 @@ static struct ctl_table lnet_table[] = { * to go via /proc for portability. */ { + .procname = "cpu_partition_table", + .maxlen = 128, + .mode = 0444, + .proc_handler = &proc_cpt_table, + }, + { + .procname = "cpu_partition_distance", + .maxlen = 128, + .mode = 0444, + .proc_handler = &proc_cpt_distance, + }, + { .procname = "stats", .mode = 0644, .proc_handler = &proc_lnet_stats, diff --git a/lnet/lnet/module.c b/lnet/lnet/module.c index b0fe719..ad63090 100644 --- a/lnet/lnet/module.c +++ b/lnet/lnet/module.c @@ -435,15 +435,23 @@ static int __init lnet_init(void) if (rc) return rc; + rc = cfs_cpu_init(); + if (rc < 0) { + CERROR("cfs_cpu_init: rc = %d\n", rc); + RETURN(rc); + } + rc = lnet_lib_init(); if (rc != 0) { CERROR("lnet_lib_init: rc = %d\n", rc); + cfs_cpu_fini(); RETURN(rc); } rc = misc_register(&lnet_dev); if (rc) { CERROR("misc_register: rc = %d\n", rc); + cfs_cpu_fini(); RETURN(rc); } @@ -466,6 +474,7 @@ static void __exit lnet_exit(void) lnet_router_exit(); lnet_lib_exit(); + cfs_cpu_fini(); } MODULE_AUTHOR("OpenSFS, Inc. "); diff --git a/lustre/include/obd_support.h b/lustre/include/obd_support.h index f770359..e21e547 100644 --- a/lustre/include/obd_support.h +++ b/lustre/include/obd_support.h @@ -39,6 +39,7 @@ #include #include +#include #include #include -- 1.8.3.1