From: Liang Zhen Date: Thu, 12 Mar 2015 04:16:10 +0000 (+0800) Subject: LU-6325 libcfs: shortcut to create CPT from NUMA topology X-Git-Tag: 2.7.52~33 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=dd9533737c28bd47a4b10d15ed6a4f0b3353765a LU-6325 libcfs: shortcut to create CPT from NUMA topology If user wants to create CPT table that can match numa topology, she has to query cpu & numa topology, then provide a pattern string to describe the topology, this is inconvenient. To improve it, this patch can support shortcut expression "N" or "n" to create CPT table from NUMA & CPU topology Signed-off-by: Liang Zhen Change-Id: I608f47ad6856ded5bf2f5f223b77b02906ebc8cc Reviewed-on: http://review.whamcloud.com/14049 Tested-by: Jenkins Reviewed-by: Olaf Weber Tested-by: Maloo Reviewed-by: Bobi Jam Reviewed-by: Oleg Drokin --- diff --git a/libcfs/libcfs/linux/linux-cpu.c b/libcfs/libcfs/linux/linux-cpu.c index ea0b087..e55678e 100644 --- a/libcfs/libcfs/linux/linux-cpu.c +++ b/libcfs/libcfs/linux/linux-cpu.c @@ -59,6 +59,8 @@ CFS_MODULE_PARM(cpu_npartitions, "i", int, 0444, "# of CPU partitions"); * 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. * + * 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 = ""; @@ -873,23 +875,33 @@ static struct cfs_cpt_table * cfs_cpt_table_create_pattern(char *pattern) { struct cfs_cpt_table *cptab; - char *str = pattern; + char *str; int node = 0; + int ncpt = 0; int high; - int ncpt; + int cpt; + int rc; int c; - - for (ncpt = 0;; ncpt++) { /* quick scan bracket */ - str = strchr(str, '['); - if (str == NULL) - break; - str++; - } + int i; str = cfs_trimwhite(pattern); if (*str == 'n' || *str == 'N') { pattern = str + 1; - node = 1; + if (*pattern != '\0') { + node = 1; /* numa pattern */ + + } else { /* shortcut to create CPT from NUMA & CPU topology */ + node = -1; + ncpt = num_online_nodes(); + } + } + + if (ncpt == 0) { /* scanning bracket which is mark of partition */ + for (str = pattern;; str++, ncpt++) { + str = strchr(str, '['); + if (str == NULL) + break; + } } if (ncpt == 0 || @@ -900,21 +912,34 @@ cfs_cpt_table_create_pattern(char *pattern) return NULL; } - high = node ? MAX_NUMNODES - 1 : NR_CPUS - 1; - cptab = cfs_cpt_table_alloc(ncpt); if (cptab == NULL) { CERROR("Failed to allocate cpu partition table\n"); return NULL; } + if (node < 0) { /* shortcut to create CPT from NUMA & CPU topology */ + cpt = 0; + for_each_online_node(i) { + if (cpt >= ncpt) { + CERROR("CPU changed while setting CPU " + "partition table, %d/%d\n", cpt, ncpt); + goto failed; + } + + rc = cfs_cpt_set_node(cptab, cpt++, i); + if (!rc) + goto failed; + } + return cptab; + } + + high = node ? MAX_NUMNODES - 1 : nr_cpu_ids - 1; + for (str = cfs_trimwhite(pattern), c = 0;; c++) { struct cfs_range_expr *range; struct cfs_expr_list *el; char *bracket = strchr(str, '['); - int cpt; - int rc; - int i; int n; if (bracket == NULL) {