From 0aeab4deb5c6deb93eb38af281e1bb696fcd239b Mon Sep 17 00:00:00 2001 From: James Simmons Date: Tue, 2 Jun 2020 12:48:28 -0400 Subject: [PATCH] LU-9859 libcfs: Fix using smp_processor_id() in preemptible context This warning show up with kernels that enable preemptible BUG: using smp_processor_id() in preemptible [00000000] code: ... Change it to disable preemption around smp_processor_id(). Change is apart of: Linux-commit: 67bc8c33ec14f8290c6883a7d6237e213709561a Change-Id: I41f7a1d3aa22240d3669f94ae92a192d219cca52 Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/38810 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Shaun Tancheff Reviewed-by: Yang Sheng Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- libcfs/libcfs/libcfs_cpu.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libcfs/libcfs/libcfs_cpu.c b/libcfs/libcfs/libcfs_cpu.c index f7d1bde..aa2c6b4 100644 --- a/libcfs/libcfs/libcfs_cpu.c +++ b/libcfs/libcfs/libcfs_cpu.c @@ -844,13 +844,17 @@ out: return rc; } -#define CPT_WEIGHT_MIN 4 +#define CPT_WEIGHT_MIN 4u -static int cfs_cpt_num_estimate(void) +static unsigned int cfs_cpt_num_estimate(void) { - int nthr = cpumask_weight(topology_sibling_cpumask(smp_processor_id())); - int ncpu = num_online_cpus(); - int ncpt = 1; + unsigned int nthr; + unsigned int ncpu = num_online_cpus(); + unsigned int ncpt = 1; + + preempt_disable(); + nthr = cpumask_weight(topology_sibling_cpumask(smp_processor_id())); + preempt_enable(); if (ncpu > CPT_WEIGHT_MIN) for (ncpt = 2; ncpu > 2 * nthr * ncpt; ncpt++) @@ -860,7 +864,7 @@ static int cfs_cpt_num_estimate(void) /* config many CPU partitions on 32-bit system could consume * too much memory */ - ncpt = min(2, ncpt); + ncpt = min(2U, ncpt); #endif while (ncpu % ncpt) ncpt--; /* worst case is 1 */ -- 1.8.3.1