cpufreq:powernv: Fix init_chip_info initialization in numa=off
Subsystems (3)
PATCH 1/1 cpufreq:powernv: Fix init_chip_info initialization in numa=off
In the numa=off kernel command-line configuration init_chip_info() loops around the number of chips and attempts to copy the cpumask of that node which is NULL for all iterations after the first chip.
Hence, store the cpu mask for each chip instead of derving cpumask from node while populating the "chips" struct array and copy that to the chips[i].mask
--- drivers/cpufreq/powernv-cpufreq.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/cpufreq/powernv-cpufreq.c +13 -2
@@ -1046,12 +1046,20 @@ static int init_chip_info(void)unsigned int *chip;unsigned int cpu, i;unsigned int prev_chip_id =UINT_MAX ; +cpumask_t *chip_cpu_mask;int ret =0 ; chip =kcalloc (num_possible_cpus (),sizeof (*chip),GFP_KERNEL );if (!chip)return -ENOMEM ; +/* Allocate a chip cpu mask large enough to fit mask for all chips */ + chip_cpu_mask =kcalloc (32 ,sizeof (cpumask_t),GFP_KERNEL ); +if (!chip_cpu_mask) { + ret = -ENOMEM ; + goto free_and_return; + } +for_each_possible_cpu (cpu) {unsigned int id =cpu_to_chip_id (cpu);
@@ -1059,22 +1067,25 @@ static int init_chip_info(void) prev_chip_id = id; chip[nr_chips++] = id; } +cpumask_set_cpu (cpu, &chip_cpu_mask[nr_chips-1 ]); } chips =kcalloc (nr_chips,sizeof (struct chip ),GFP_KERNEL );if (!chips) { ret = -ENOMEM ; - goto free_and_return; + goto out_chip_cpu_mask; }for (i =0 ; i < nr_chips; i++) { chips[i].id = chip[i]; -cpumask_copy (&chips[i].mask,cpumask_of_node (chip[i])); +cpumask_copy (&chips[i].mask, &chip_cpu_mask[i]);INIT_WORK (&chips[i].throttle, powernv_cpufreq_work_fn);for_each_cpu (cpu, &chips[i].mask)per_cpu (chip_info, cpu) = &chips[i]; } +out_chip_cpu_mask: +kfree (chip_cpu_mask); free_and_return:kfree (chip);return ret;
Signature · 1 line
2.31.1
Quoted 23 lines · Pratik R. Sampat
In the numa=off kernel command-line configuration
init_chip_info()loops around the number of chips and attempts to copy the cpumask of that node which is NULL for all iterations after the first chip.Hence, store the cpu mask for each chip instead of derving cpumask from node while populating the "chips" struct array and copy that to the chips[i].mask
Fixes 053819e0bf84 ("cpufreq: powernv: Handle throttling due to Pmax capping at chip level")Signed-off-by Pratik R. Sampat <[email protected]>Reported-by Shirisha Ganta <[email protected]>--- drivers/cpufreq/powernv-cpufreq.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/cpufreq/powernv-cpufreq.c +0
-0@@ -1046,12 +1046,20 @@ static int init_chip_info(void)unsigned int *chip;unsigned int cpu, i;
drivers/cpufreq/powernv-cpufreq.c static int init_chip_info(void) · line 1057
Quoted 10 lines
drivers/cpufreq/powernv-cpufreq.c +3
-0unsigned int prev_chip_id =UINT_MAX ; +cpumask_t *chip_cpu_mask;int ret =0 ; chip =kcalloc (num_possible_cpus (),sizeof (*chip),GFP_KERNEL );if (!chip)return -ENOMEM ; +/* Allocate a chip cpu mask large enough to fit mask for all chips */ + chip_cpu_mask =kcalloc (32 ,sizeof (cpumask_t),GFP_KERNEL );
I suppose by 32 you mean the maximum number of chips possible. You could use a #define for that.
Otherwise, the patch looks good to me.
Quoted 39 lines
drivers/cpufreq/powernv-cpufreq.c +10
-2+if (!chip_cpu_mask) { + ret = -ENOMEM ; + goto free_and_return; + } +for_each_possible_cpu (cpu) {unsigned int id =cpu_to_chip_id (cpu);@@ -1059,22 +1067,25 @@ static int init_chip_info(void) prev_chip_id = id; chip[nr_chips++] = id; } +cpumask_set_cpu (cpu, &chip_cpu_mask[nr_chips-1 ]); } chips =kcalloc (nr_chips,sizeof (struct chip ),GFP_KERNEL );if (!chips) { ret = -ENOMEM ; - goto free_and_return; + goto out_chip_cpu_mask; }for (i =0 ; i < nr_chips; i++) { chips[i].id = chip[i]; -cpumask_copy (&chips[i].mask,cpumask_of_node (chip[i])); +cpumask_copy (&chips[i].mask, &chip_cpu_mask[i]);INIT_WORK (&chips[i].throttle, powernv_cpufreq_work_fn);for_each_cpu (cpu, &chips[i].mask)per_cpu (chip_info, cpu) = &chips[i]; } +out_chip_cpu_mask: +kfree (chip_cpu_mask); free_and_return:kfree (chip);return ret;Signature · 1 line
2.31.1
Quoted 28 lines · Gautham R Shenoy
Quoted 27 lines · Pratik R. Sampat
In the numa=off kernel command-line configuration
init_chip_info()loops around the number of chips and attempts to copy the cpumask of that node which is NULL for all iterations after the first chip.Hence, store the cpu mask for each chip instead of derving cpumask from node while populating the "chips" struct array and copy that to the chips[i].mask
Fixes 053819e0bf84 ("cpufreq: powernv: Handle throttling due to Pmax capping at chip level")Signed-off-by Pratik R. Sampat <[email protected]>Reported-by Shirisha Ganta <[email protected]>--- drivers/cpufreq/powernv-cpufreq.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)drivers/cpufreq/powernv-cpufreq.c +1
-0@@ -1046,12 +1046,20 @@ static int init_chip_info(void)unsigned int *chip;unsigned int cpu, i;unsigned int prev_chip_id =UINT_MAX ; +cpumask_t *chip_cpu_mask;int ret =0 ;
Quoted 8 lines
drivers/cpufreq/powernv-cpufreq.c static int init_chip_info(void) · line 1057
Quoted 6 lines
drivers/cpufreq/powernv-cpufreq.c +2
-0chip =kcalloc (num_possible_cpus (),sizeof (*chip),GFP_KERNEL );if (!chip)return -ENOMEM ; +/* Allocate a chip cpu mask large enough to fit mask for all chips */ + chip_cpu_mask =kcalloc (32 ,sizeof (cpumask_t),GFP_KERNEL );I suppose by 32 you mean the maximum number of chips possible. You could use a #define for that.
ack, I could #define the constant.
Quoted 4 lines
Otherwise, the patch looks good to me.
Reviewed-by Gautham R. Shenoy <[email protected]>
Thanks
Pratik
Quoted 40 lines
Quoted 40 lines
drivers/cpufreq/powernv-cpufreq.c +10
-2+if (!chip_cpu_mask) { + ret = -ENOMEM ; + goto free_and_return; + } +for_each_possible_cpu (cpu) {unsigned int id =cpu_to_chip_id (cpu);@@ -1059,22 +1067,25 @@ static int init_chip_info(void) prev_chip_id = id; chip[nr_chips++] = id; } +cpumask_set_cpu (cpu, &chip_cpu_mask[nr_chips-1 ]); } chips =kcalloc (nr_chips,sizeof (struct chip ),GFP_KERNEL );if (!chips) { ret = -ENOMEM ; - goto free_and_return; + goto out_chip_cpu_mask; }for (i =0 ; i < nr_chips; i++) { chips[i].id = chip[i]; -cpumask_copy (&chips[i].mask,cpumask_of_node (chip[i])); +cpumask_copy (&chips[i].mask, &chip_cpu_mask[i]);INIT_WORK (&chips[i].throttle, powernv_cpufreq_work_fn);for_each_cpu (cpu, &chips[i].mask)per_cpu (chip_info, cpu) = &chips[i]; } +out_chip_cpu_mask: +kfree (chip_cpu_mask); free_and_return:kfree (chip);return ret;Signature · 1 line
2.31.1