Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 22cc4ccf authored by Yan, Zheng's avatar Yan, Zheng Committed by Ingo Molnar
Browse files

perf/x86: Avoid kfree() in CPU_{STARTING,DYING}



On -rt kfree() can schedule, but CPU_{STARTING,DYING} should be
atomic. So use a list to defer kfree until CPU_{ONLINE,DEAD}.

Signed-off-by: default avatarYan, Zheng <zheng.z.yan@intel.com>
Acked-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Cc: peterz@infradead.org
Cc: eranian@google.com
Cc: ak@linux.intel.com
Link: http://lkml.kernel.org/r/1366113067-3262-2-git-send-email-zheng.z.yan@intel.com


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 73e21ce2
Loading
Loading
Loading
Loading
+25 −3
Original line number Original line Diff line number Diff line
@@ -2622,6 +2622,21 @@ static void __init uncore_pci_exit(void)
	}
	}
}
}


/* CPU hot plug/unplug are serialized by cpu_add_remove_lock mutex */
static LIST_HEAD(boxes_to_free);

static void __cpuinit uncore_kfree_boxes(void)
{
	struct intel_uncore_box *box;

	while (!list_empty(&boxes_to_free)) {
		box = list_entry(boxes_to_free.next,
				 struct intel_uncore_box, list);
		list_del(&box->list);
		kfree(box);
	}
}

static void __cpuinit uncore_cpu_dying(int cpu)
static void __cpuinit uncore_cpu_dying(int cpu)
{
{
	struct intel_uncore_type *type;
	struct intel_uncore_type *type;
@@ -2636,7 +2651,7 @@ static void __cpuinit uncore_cpu_dying(int cpu)
			box = *per_cpu_ptr(pmu->box, cpu);
			box = *per_cpu_ptr(pmu->box, cpu);
			*per_cpu_ptr(pmu->box, cpu) = NULL;
			*per_cpu_ptr(pmu->box, cpu) = NULL;
			if (box && atomic_dec_and_test(&box->refcnt))
			if (box && atomic_dec_and_test(&box->refcnt))
				kfree(box);
				list_add(&box->list, &boxes_to_free);
		}
		}
	}
	}
}
}
@@ -2666,8 +2681,11 @@ static int __cpuinit uncore_cpu_starting(int cpu)
				if (exist && exist->phys_id == phys_id) {
				if (exist && exist->phys_id == phys_id) {
					atomic_inc(&exist->refcnt);
					atomic_inc(&exist->refcnt);
					*per_cpu_ptr(pmu->box, cpu) = exist;
					*per_cpu_ptr(pmu->box, cpu) = exist;
					kfree(box);
					if (box) {
						list_add(&box->list,
							 &boxes_to_free);
						box = NULL;
						box = NULL;
					}
					break;
					break;
				}
				}
			}
			}
@@ -2806,6 +2824,10 @@ static int
	case CPU_DYING:
	case CPU_DYING:
		uncore_cpu_dying(cpu);
		uncore_cpu_dying(cpu);
		break;
		break;
	case CPU_ONLINE:
	case CPU_DEAD:
		uncore_kfree_boxes();
		break;
	default:
	default:
		break;
		break;
	}
	}