Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 158233
b: refs/heads/master
c: 6ab82f9
h: refs/heads/master
i:
  158231: 4a74463
v: v3
  • Loading branch information
Robert Richter committed Jul 20, 2009
1 parent 5ba9f7e commit 86ea220
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7e7478c6bc0e011d2854b21f190cc3a1dba89905
refs/heads/master: 6ab82f958a5dca591a6ea17a3ca6f2aca06f4f2f
76 changes: 40 additions & 36 deletions trunk/arch/x86/oprofile/nmi_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,35 @@ inline int op_x86_phys_to_virt(int phys)
return __get_cpu_var(switch_index) + phys;
}

static void nmi_shutdown_mux(void)
{
int i;
for_each_possible_cpu(i) {
kfree(per_cpu(cpu_msrs, i).multiplex);
per_cpu(cpu_msrs, i).multiplex = NULL;
per_cpu(switch_index, i) = 0;
}
}

static int nmi_setup_mux(void)
{
size_t multiplex_size =
sizeof(struct op_msr) * model->num_virt_counters;
int i;
for_each_possible_cpu(i) {
per_cpu(cpu_msrs, i).multiplex =
kmalloc(multiplex_size, GFP_KERNEL);
if (!per_cpu(cpu_msrs, i).multiplex)
return 0;
}
return 1;
}

#else

inline int op_x86_phys_to_virt(int phys) { return phys; }
static inline void nmi_shutdown_mux(void) { }
static inline int nmi_setup_mux(void) { return 1; }

#endif

Expand All @@ -120,51 +146,27 @@ static void free_msrs(void)
per_cpu(cpu_msrs, i).counters = NULL;
kfree(per_cpu(cpu_msrs, i).controls);
per_cpu(cpu_msrs, i).controls = NULL;

#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
kfree(per_cpu(cpu_msrs, i).multiplex);
per_cpu(cpu_msrs, i).multiplex = NULL;
#endif
}
}

static int allocate_msrs(void)
{
int success = 1;
size_t controls_size = sizeof(struct op_msr) * model->num_controls;
size_t counters_size = sizeof(struct op_msr) * model->num_counters;
#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
size_t multiplex_size = sizeof(struct op_msr) * model->num_virt_counters;
#endif

int i;
for_each_possible_cpu(i) {
per_cpu(cpu_msrs, i).counters = kmalloc(counters_size,
GFP_KERNEL);
if (!per_cpu(cpu_msrs, i).counters) {
success = 0;
break;
}
GFP_KERNEL);
if (!per_cpu(cpu_msrs, i).counters)
return 0;
per_cpu(cpu_msrs, i).controls = kmalloc(controls_size,
GFP_KERNEL);
if (!per_cpu(cpu_msrs, i).controls) {
success = 0;
break;
}
#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
per_cpu(cpu_msrs, i).multiplex =
kmalloc(multiplex_size, GFP_KERNEL);
if (!per_cpu(cpu_msrs, i).multiplex) {
success = 0;
break;
}
#endif
GFP_KERNEL);
if (!per_cpu(cpu_msrs, i).controls)
return 0;
}

if (!success)
free_msrs();

return success;
return 1;
}

#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
Expand Down Expand Up @@ -218,11 +220,15 @@ static int nmi_setup(void)
int cpu;

if (!allocate_msrs())
return -ENOMEM;
err = -ENOMEM;
else if (!nmi_setup_mux())
err = -ENOMEM;
else
err = register_die_notifier(&profile_exceptions_nb);

err = register_die_notifier(&profile_exceptions_nb);
if (err) {
free_msrs();
nmi_shutdown_mux();
return err;
}

Expand Down Expand Up @@ -314,9 +320,6 @@ static void nmi_cpu_shutdown(void *dummy)
apic_write(APIC_LVTPC, per_cpu(saved_lvtpc, cpu));
apic_write(APIC_LVTERR, v);
nmi_cpu_restore_registers(msrs);
#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
per_cpu(switch_index, cpu) = 0;
#endif
}

static void nmi_shutdown(void)
Expand All @@ -326,6 +329,7 @@ static void nmi_shutdown(void)
nmi_enabled = 0;
on_each_cpu(nmi_cpu_shutdown, NULL, 1);
unregister_die_notifier(&profile_exceptions_nb);
nmi_shutdown_mux();
msrs = &get_cpu_var(cpu_msrs);
model->shutdown(msrs);
free_msrs();
Expand Down

0 comments on commit 86ea220

Please sign in to comment.