Skip to content

Commit a026bb1

Browse files
sudeep-hollawildea01
authored andcommitted
drivers/perf: arm-pmu: convert arm_pmu_mutex to spinlock
arm_pmu_mutex is never held long and we don't want to sleep while the lock is being held as it's executed in the context of hotplug notifiers. So it can be converted to a simple spinlock instead. Without this patch we get the following warning: BUG: sleeping function called from invalid context at kernel/locking/mutex.c:620 in_atomic(): 1, irqs_disabled(): 128, pid: 0, name: swapper/2 no locks held by swapper/2/0. irq event stamp: 381314 hardirqs last enabled at (381313): _raw_spin_unlock_irqrestore+0x7c/0x88 hardirqs last disabled at (381314): cpu_die+0x28/0x48 softirqs last enabled at (381294): _local_bh_enable+0x28/0x50 softirqs last disabled at (381293): irq_enter+0x58/0x78 CPU: 2 PID: 0 Comm: swapper/2 Not tainted 4.7.0 torvalds#12 Call trace: dump_backtrace+0x0/0x220 show_stack+0x24/0x30 dump_stack+0xb4/0xf0 ___might_sleep+0x1d8/0x1f0 __might_sleep+0x5c/0x98 mutex_lock_nested+0x54/0x400 arm_perf_starting_cpu+0x34/0xb0 cpuhp_invoke_callback+0x88/0x3d8 notify_cpu_starting+0x78/0x98 secondary_start_kernel+0x108/0x1a8 This patch converts the mutex to spinlock to eliminate the above warnings. This constraints pmu->reset to be non-blocking call which is the case with all the ARM PMU backends. Cc: Stephen Boyd <sboyd@codeaurora.org> Fixes: 37b502f ("arm/perf: Fix hotplug state machine conversion") Acked-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 50ee91b commit a026bb1

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

drivers/perf/arm_pmu.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler)
688688
return 0;
689689
}
690690

691-
static DEFINE_MUTEX(arm_pmu_mutex);
691+
static DEFINE_SPINLOCK(arm_pmu_lock);
692692
static LIST_HEAD(arm_pmu_list);
693693

694694
/*
@@ -701,15 +701,15 @@ static int arm_perf_starting_cpu(unsigned int cpu)
701701
{
702702
struct arm_pmu *pmu;
703703

704-
mutex_lock(&arm_pmu_mutex);
704+
spin_lock(&arm_pmu_lock);
705705
list_for_each_entry(pmu, &arm_pmu_list, entry) {
706706

707707
if (!cpumask_test_cpu(cpu, &pmu->supported_cpus))
708708
continue;
709709
if (pmu->reset)
710710
pmu->reset(pmu);
711711
}
712-
mutex_unlock(&arm_pmu_mutex);
712+
spin_unlock(&arm_pmu_lock);
713713
return 0;
714714
}
715715

@@ -821,9 +821,9 @@ static int cpu_pmu_init(struct arm_pmu *cpu_pmu)
821821
if (!cpu_hw_events)
822822
return -ENOMEM;
823823

824-
mutex_lock(&arm_pmu_mutex);
824+
spin_lock(&arm_pmu_lock);
825825
list_add_tail(&cpu_pmu->entry, &arm_pmu_list);
826-
mutex_unlock(&arm_pmu_mutex);
826+
spin_unlock(&arm_pmu_lock);
827827

828828
err = cpu_pm_pmu_register(cpu_pmu);
829829
if (err)
@@ -859,19 +859,19 @@ static int cpu_pmu_init(struct arm_pmu *cpu_pmu)
859859
return 0;
860860

861861
out_unregister:
862-
mutex_lock(&arm_pmu_mutex);
862+
spin_lock(&arm_pmu_lock);
863863
list_del(&cpu_pmu->entry);
864-
mutex_unlock(&arm_pmu_mutex);
864+
spin_unlock(&arm_pmu_lock);
865865
free_percpu(cpu_hw_events);
866866
return err;
867867
}
868868

869869
static void cpu_pmu_destroy(struct arm_pmu *cpu_pmu)
870870
{
871871
cpu_pm_pmu_unregister(cpu_pmu);
872-
mutex_lock(&arm_pmu_mutex);
872+
spin_lock(&arm_pmu_lock);
873873
list_del(&cpu_pmu->entry);
874-
mutex_unlock(&arm_pmu_mutex);
874+
spin_unlock(&arm_pmu_lock);
875875
free_percpu(cpu_pmu->hw_events);
876876
}
877877

0 commit comments

Comments
 (0)