mce_amd.c 15.3 KB
Newer Older
1
/*
2
 *  (c) 2005, 2006 Advanced Micro Devices, Inc.
3 4 5 6 7 8 9 10
 *  Your use of this code is subject to the terms and conditions of the
 *  GNU general public license version 2. See "COPYING" or
 *  http://www.gnu.org/licenses/gpl.html
 *
 *  Written by Jacob Shin - AMD, Inc.
 *
 *  Support : jacob.shin@amd.com
 *
11 12
 *  April 2006
 *     - added support for AMD Family 0x10 processors
13
 *
14
 *  All MC4_MISCi registers are shared between multi-cores
15 16 17
 */
#include <linux/interrupt.h>
#include <linux/notifier.h>
I
Ingo Molnar 已提交
18
#include <linux/kobject.h>
19
#include <linux/percpu.h>
20
#include <linux/sysdev.h>
I
Ingo Molnar 已提交
21 22
#include <linux/errno.h>
#include <linux/sched.h>
23
#include <linux/sysfs.h>
I
Ingo Molnar 已提交
24 25 26 27
#include <linux/init.h>
#include <linux/cpu.h>
#include <linux/smp.h>

28
#include <asm/apic.h>
I
Ingo Molnar 已提交
29
#include <asm/idle.h>
30 31 32
#include <asm/mce.h>
#include <asm/msr.h>

J
Jacob Shin 已提交
33 34 35 36 37 38 39
#define PFX               "mce_threshold: "
#define VERSION           "version 1.1.1"
#define NR_BANKS          6
#define NR_BLOCKS         9
#define THRESHOLD_MAX     0xFFF
#define INT_TYPE_APIC     0x00020000
#define MASK_VALID_HI     0x80000000
40 41
#define MASK_CNTP_HI      0x40000000
#define MASK_LOCKED_HI    0x20000000
J
Jacob Shin 已提交
42 43 44 45
#define MASK_LVTOFF_HI    0x00F00000
#define MASK_COUNT_EN_HI  0x00080000
#define MASK_INT_TYPE_HI  0x00060000
#define MASK_OVERFLOW_HI  0x00010000
46
#define MASK_ERR_COUNT_HI 0x00000FFF
47 48
#define MASK_BLKPTR_LO    0xFF000000
#define MCG_XBLK_ADDR     0xC0000400
49

50
struct threshold_block {
I
Ingo Molnar 已提交
51 52 53 54 55 56 57 58
	unsigned int		block;
	unsigned int		bank;
	unsigned int		cpu;
	u32			address;
	u16			interrupt_enable;
	u16			threshold_limit;
	struct kobject		kobj;
	struct list_head	miscj;
59 60
};

61 62
/* defaults used early on boot */
static struct threshold_block threshold_defaults = {
I
Ingo Molnar 已提交
63 64
	.interrupt_enable	= 0,
	.threshold_limit	= THRESHOLD_MAX,
65 66
};

67
struct threshold_bank {
I
Ingo Molnar 已提交
68 69 70
	struct kobject		*kobj;
	struct threshold_block	*blocks;
	cpumask_var_t		cpus;
71
};
72
static DEFINE_PER_CPU(struct threshold_bank * [NR_BANKS], threshold_banks);
73

74 75 76 77 78 79 80 81
#ifdef CONFIG_SMP
static unsigned char shared_bank[NR_BANKS] = {
	0, 0, 0, 0, 1
};
#endif

static DEFINE_PER_CPU(unsigned char, bank_map);	/* see which banks are on */

82 83
static void amd_threshold_interrupt(void);

84 85 86 87
/*
 * CPU Initialization
 */

88
struct thresh_restart {
I
Ingo Molnar 已提交
89 90 91
	struct threshold_block	*b;
	int			reset;
	u16			old_limit;
92 93
};

94
/* must be called with correct cpu affinity */
95 96
/* Called via smp_call_function_single() */
static void threshold_restart_bank(void *_tr)
97
{
98
	struct thresh_restart *tr = _tr;
99 100
	u32 mci_misc_hi, mci_misc_lo;

101
	rdmsr(tr->b->address, mci_misc_lo, mci_misc_hi);
102

103 104
	if (tr->b->threshold_limit < (mci_misc_hi & THRESHOLD_MAX))
		tr->reset = 1;	/* limit cannot be lower than err count */
105

106
	if (tr->reset) {		/* reset err count and overflow bit */
107 108
		mci_misc_hi =
		    (mci_misc_hi & ~(MASK_ERR_COUNT_HI | MASK_OVERFLOW_HI)) |
109 110
		    (THRESHOLD_MAX - tr->b->threshold_limit);
	} else if (tr->old_limit) {	/* change limit w/o reset */
111
		int new_count = (mci_misc_hi & THRESHOLD_MAX) +
112
		    (tr->old_limit - tr->b->threshold_limit);
I
Ingo Molnar 已提交
113

114 115 116 117
		mci_misc_hi = (mci_misc_hi & ~MASK_ERR_COUNT_HI) |
		    (new_count & THRESHOLD_MAX);
	}

118
	tr->b->interrupt_enable ?
119 120 121 122
	    (mci_misc_hi = (mci_misc_hi & ~MASK_INT_TYPE_HI) | INT_TYPE_APIC) :
	    (mci_misc_hi &= ~MASK_INT_TYPE_HI);

	mci_misc_hi |= MASK_COUNT_EN_HI;
123
	wrmsr(tr->b->address, mci_misc_lo, mci_misc_hi);
124 125
}

126
/* cpu init entry point, called from mce.c with preempt off */
127
void mce_amd_feature_init(struct cpuinfo_x86 *c)
128 129
{
	unsigned int cpu = smp_processor_id();
130
	u32 low = 0, high = 0, address = 0;
I
Ingo Molnar 已提交
131
	unsigned int bank, block;
132
	struct thresh_restart tr;
I
Ingo Molnar 已提交
133
	u8 lvt_off;
134 135

	for (bank = 0; bank < NR_BANKS; ++bank) {
136 137 138
		for (block = 0; block < NR_BLOCKS; ++block) {
			if (block == 0)
				address = MSR_IA32_MC0_MISC + bank * 4;
139 140 141 142 143
			else if (block == 1) {
				address = (low & MASK_BLKPTR_LO) >> 21;
				if (!address)
					break;
				address += MCG_XBLK_ADDR;
I
Ingo Molnar 已提交
144
			} else
145 146 147
				++address;

			if (rdmsr_safe(address, &low, &high))
148
				break;
149 150 151 152 153 154 155 156

			if (!(high & MASK_VALID_HI)) {
				if (block)
					continue;
				else
					break;
			}

157 158
			if (!(high & MASK_CNTP_HI)  ||
			     (high & MASK_LOCKED_HI))
159 160 161 162
				continue;

			if (!block)
				per_cpu(bank_map, cpu) |= (1 << bank);
163
#ifdef CONFIG_SMP
164 165
			if (shared_bank[bank] && c->cpu_core_id)
				break;
166
#endif
167 168 169
			lvt_off = setup_APIC_eilvt_mce(THRESHOLD_APIC_VECTOR,
						       APIC_EILVT_MSG_FIX, 0);

170
			high &= ~MASK_LVTOFF_HI;
171
			high |= lvt_off << 20;
172 173 174
			wrmsr(address, low, high);

			threshold_defaults.address = address;
175 176 177 178
			tr.b = &threshold_defaults;
			tr.reset = 0;
			tr.old_limit = 0;
			threshold_restart_bank(&tr);
179 180

			mce_threshold_vector = amd_threshold_interrupt;
181
		}
182 183 184 185 186 187 188 189 190 191 192 193
	}
}

/*
 * APIC Interrupt Handler
 */

/*
 * threshold interrupt handler will service THRESHOLD_APIC_VECTOR.
 * the interrupt goes off when error_count reaches threshold_limit.
 * the handler will simply log mcelog w/ software defined bank number.
 */
194
static void amd_threshold_interrupt(void)
195
{
I
Ingo Molnar 已提交
196
	u32 low = 0, high = 0, address = 0;
197
	unsigned int bank, block;
198 199
	struct mce m;

200
	mce_setup(&m);
201 202 203

	/* assume first bank caused it */
	for (bank = 0; bank < NR_BANKS; ++bank) {
204 205
		if (!(per_cpu(bank_map, m.cpu) & (1 << bank)))
			continue;
206
		for (block = 0; block < NR_BLOCKS; ++block) {
I
Ingo Molnar 已提交
207
			if (block == 0) {
208
				address = MSR_IA32_MC0_MISC + bank * 4;
I
Ingo Molnar 已提交
209
			} else if (block == 1) {
210 211 212 213
				address = (low & MASK_BLKPTR_LO) >> 21;
				if (!address)
					break;
				address += MCG_XBLK_ADDR;
I
Ingo Molnar 已提交
214
			} else {
215
				++address;
I
Ingo Molnar 已提交
216
			}
217 218

			if (rdmsr_safe(address, &low, &high))
219
				break;
220 221 222 223 224 225 226 227

			if (!(high & MASK_VALID_HI)) {
				if (block)
					continue;
				else
					break;
			}

228 229
			if (!(high & MASK_CNTP_HI)  ||
			     (high & MASK_LOCKED_HI))
230 231
				continue;

I
Ingo Molnar 已提交
232 233 234 235
			/*
			 * Log the machine check that caused the threshold
			 * event.
			 */
236 237
			machine_check_poll(MCP_TIMESTAMP,
					&__get_cpu_var(mce_poll_banks));
238

239 240 241 242 243 244 245 246
			if (high & MASK_OVERFLOW_HI) {
				rdmsrl(address, m.misc);
				rdmsrl(MSR_IA32_MC0_STATUS + bank * 4,
				       m.status);
				m.bank = K8_MCE_THRESHOLD_BASE
				       + bank * NR_BLOCKS
				       + block;
				mce_log(&m);
247
				return;
248
			}
249 250 251 252 253 254 255 256 257
		}
	}
}

/*
 * Sysfs Interface
 */

struct threshold_attr {
J
Jacob Shin 已提交
258
	struct attribute attr;
I
Ingo Molnar 已提交
259 260
	ssize_t (*show) (struct threshold_block *, char *);
	ssize_t (*store) (struct threshold_block *, const char *, size_t count);
261 262
};

I
Ingo Molnar 已提交
263 264 265 266
#define SHOW_FIELDS(name)						\
static ssize_t show_ ## name(struct threshold_block *b, char *buf)	\
{									\
	return sprintf(buf, "%lx\n", (unsigned long) b->name);		\
J
Jacob Shin 已提交
267
}
268 269 270
SHOW_FIELDS(interrupt_enable)
SHOW_FIELDS(threshold_limit)

I
Ingo Molnar 已提交
271
static ssize_t
H
Hidetoshi Seto 已提交
272
store_interrupt_enable(struct threshold_block *b, const char *buf, size_t size)
273
{
274
	struct thresh_restart tr;
I
Ingo Molnar 已提交
275 276
	unsigned long new;

H
Hidetoshi Seto 已提交
277
	if (strict_strtoul(buf, 0, &new) < 0)
278
		return -EINVAL;
I
Ingo Molnar 已提交
279

280 281
	b->interrupt_enable = !!new;

I
Ingo Molnar 已提交
282 283 284 285
	tr.b		= b;
	tr.reset	= 0;
	tr.old_limit	= 0;

286
	smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1);
287

H
Hidetoshi Seto 已提交
288
	return size;
289 290
}

I
Ingo Molnar 已提交
291
static ssize_t
H
Hidetoshi Seto 已提交
292
store_threshold_limit(struct threshold_block *b, const char *buf, size_t size)
293
{
294
	struct thresh_restart tr;
I
Ingo Molnar 已提交
295 296
	unsigned long new;

H
Hidetoshi Seto 已提交
297
	if (strict_strtoul(buf, 0, &new) < 0)
298
		return -EINVAL;
I
Ingo Molnar 已提交
299

300 301 302 303
	if (new > THRESHOLD_MAX)
		new = THRESHOLD_MAX;
	if (new < 1)
		new = 1;
I
Ingo Molnar 已提交
304

305
	tr.old_limit = b->threshold_limit;
306
	b->threshold_limit = new;
307 308
	tr.b = b;
	tr.reset = 0;
309

310
	smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1);
311

H
Hidetoshi Seto 已提交
312
	return size;
313 314
}

315
struct threshold_block_cross_cpu {
I
Ingo Molnar 已提交
316 317
	struct threshold_block	*tb;
	long			retval;
318 319 320
};

static void local_error_count_handler(void *_tbcc)
321
{
322 323
	struct threshold_block_cross_cpu *tbcc = _tbcc;
	struct threshold_block *b = tbcc->tb;
324 325
	u32 low, high;

326
	rdmsr(b->address, low, high);
327
	tbcc->retval = (high & 0xFFF) - (THRESHOLD_MAX - b->threshold_limit);
328 329 330 331
}

static ssize_t show_error_count(struct threshold_block *b, char *buf)
{
332 333 334 335
	struct threshold_block_cross_cpu tbcc = { .tb = b, };

	smp_call_function_single(b->cpu, local_error_count_handler, &tbcc, 1);
	return sprintf(buf, "%lx\n", tbcc.retval);
336 337
}

338
static ssize_t store_error_count(struct threshold_block *b,
339 340
				 const char *buf, size_t count)
{
341 342
	struct thresh_restart tr = { .b = b, .reset = 1, .old_limit = 0 };

343
	smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1);
344 345 346
	return 1;
}

347 348 349 350 351
#define RW_ATTR(val)							\
static struct threshold_attr val = {					\
	.attr	= {.name = __stringify(val), .mode = 0644 },		\
	.show	= show_## val,						\
	.store	= store_## val,						\
352 353
};

J
Jacob Shin 已提交
354 355 356
RW_ATTR(interrupt_enable);
RW_ATTR(threshold_limit);
RW_ATTR(error_count);
357 358 359 360 361 362 363 364

static struct attribute *default_attrs[] = {
	&interrupt_enable.attr,
	&threshold_limit.attr,
	&error_count.attr,
	NULL
};

I
Ingo Molnar 已提交
365 366
#define to_block(k)	container_of(k, struct threshold_block, kobj)
#define to_attr(a)	container_of(a, struct threshold_attr, attr)
367 368 369

static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
{
370
	struct threshold_block *b = to_block(kobj);
371 372
	struct threshold_attr *a = to_attr(attr);
	ssize_t ret;
I
Ingo Molnar 已提交
373

374
	ret = a->show ? a->show(b, buf) : -EIO;
I
Ingo Molnar 已提交
375

376 377 378 379 380 381
	return ret;
}

static ssize_t store(struct kobject *kobj, struct attribute *attr,
		     const char *buf, size_t count)
{
382
	struct threshold_block *b = to_block(kobj);
383 384
	struct threshold_attr *a = to_attr(attr);
	ssize_t ret;
I
Ingo Molnar 已提交
385

386
	ret = a->store ? a->store(b, buf, count) : -EIO;
I
Ingo Molnar 已提交
387

388 389 390
	return ret;
}

391
static const struct sysfs_ops threshold_ops = {
I
Ingo Molnar 已提交
392 393
	.show			= show,
	.store			= store,
394 395 396
};

static struct kobj_type threshold_ktype = {
I
Ingo Molnar 已提交
397 398
	.sysfs_ops		= &threshold_ops,
	.default_attrs		= default_attrs,
399 400
};

401 402 403 404 405 406
static __cpuinit int allocate_threshold_blocks(unsigned int cpu,
					       unsigned int bank,
					       unsigned int block,
					       u32 address)
{
	struct threshold_block *b = NULL;
I
Ingo Molnar 已提交
407 408
	u32 low, high;
	int err;
409 410 411 412

	if ((bank >= NR_BANKS) || (block >= NR_BLOCKS))
		return 0;

413
	if (rdmsr_safe_on_cpu(cpu, address, &low, &high))
414
		return 0;
415 416 417 418 419 420 421 422

	if (!(high & MASK_VALID_HI)) {
		if (block)
			goto recurse;
		else
			return 0;
	}

423 424
	if (!(high & MASK_CNTP_HI)  ||
	     (high & MASK_LOCKED_HI))
425 426 427 428 429 430
		goto recurse;

	b = kzalloc(sizeof(struct threshold_block), GFP_KERNEL);
	if (!b)
		return -ENOMEM;

I
Ingo Molnar 已提交
431 432 433 434 435 436
	b->block		= block;
	b->bank			= bank;
	b->cpu			= cpu;
	b->address		= address;
	b->interrupt_enable	= 0;
	b->threshold_limit	= THRESHOLD_MAX;
437 438 439

	INIT_LIST_HEAD(&b->miscj);

I
Ingo Molnar 已提交
440
	if (per_cpu(threshold_banks, cpu)[bank]->blocks) {
441 442
		list_add(&b->miscj,
			 &per_cpu(threshold_banks, cpu)[bank]->blocks->miscj);
I
Ingo Molnar 已提交
443
	} else {
444
		per_cpu(threshold_banks, cpu)[bank]->blocks = b;
I
Ingo Molnar 已提交
445
	}
446

447 448 449
	err = kobject_init_and_add(&b->kobj, &threshold_ktype,
				   per_cpu(threshold_banks, cpu)[bank]->kobj,
				   "misc%i", block);
450 451 452 453 454 455 456 457
	if (err)
		goto out_free;
recurse:
	if (!block) {
		address = (low & MASK_BLKPTR_LO) >> 21;
		if (!address)
			return 0;
		address += MCG_XBLK_ADDR;
I
Ingo Molnar 已提交
458
	} else {
459
		++address;
I
Ingo Molnar 已提交
460
	}
461 462 463 464 465

	err = allocate_threshold_blocks(cpu, bank, ++block, address);
	if (err)
		goto out_free;

466 467
	if (b)
		kobject_uevent(&b->kobj, KOBJ_ADD);
468

469 470 471 472
	return err;

out_free:
	if (b) {
473
		kobject_put(&b->kobj);
474 475 476 477 478
		kfree(b);
	}
	return err;
}

479 480
static __cpuinit long
local_allocate_threshold_blocks(int cpu, unsigned int bank)
481
{
482 483
	return allocate_threshold_blocks(cpu, bank, 0,
					 MSR_IA32_MC0_MISC + bank * 4);
484 485
}

486
/* symlinks sibling shared banks to first core.  first core owns dir/files. */
487
static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)
488
{
489
	int i, err = 0;
490
	struct threshold_bank *b = NULL;
491
	char name[32];
492
#ifdef CONFIG_SMP
493
	struct cpuinfo_x86 *c = &cpu_data(cpu);
494
#endif
495 496

	sprintf(name, "threshold_bank%i", bank);
497 498

#ifdef CONFIG_SMP
499
	if (cpu_data(cpu).cpu_core_id && shared_bank[bank]) {	/* symlink */
500
		i = cpumask_first(c->llc_shared_map);
501 502

		/* first core not up yet */
503
		if (cpu_data(i).cpu_core_id)
504 505 506 507 508 509 510
			goto out;

		/* already linked */
		if (per_cpu(threshold_banks, cpu)[bank])
			goto out;

		b = per_cpu(threshold_banks, i)[bank];
511 512 513

		if (!b)
			goto out;
514

I
Ingo Molnar 已提交
515
		err = sysfs_create_link(&per_cpu(mce_dev, cpu).kobj,
516
					b->kobj, name);
517 518
		if (err)
			goto out;
519

520
		cpumask_copy(b->cpus, c->llc_shared_map);
521
		per_cpu(threshold_banks, cpu)[bank] = b;
I
Ingo Molnar 已提交
522

523 524 525 526
		goto out;
	}
#endif

527
	b = kzalloc(sizeof(struct threshold_bank), GFP_KERNEL);
528 529 530 531
	if (!b) {
		err = -ENOMEM;
		goto out;
	}
532 533 534 535 536
	if (!alloc_cpumask_var(&b->cpus, GFP_KERNEL)) {
		kfree(b);
		err = -ENOMEM;
		goto out;
	}
537

I
Ingo Molnar 已提交
538
	b->kobj = kobject_create_and_add(name, &per_cpu(mce_dev, cpu).kobj);
539 540 541
	if (!b->kobj)
		goto out_free;

542
#ifndef CONFIG_SMP
543
	cpumask_setall(b->cpus);
544
#else
545
	cpumask_copy(b->cpus, c->llc_shared_map);
546 547
#endif

548
	per_cpu(threshold_banks, cpu)[bank] = b;
549

550
	err = local_allocate_threshold_blocks(cpu, bank);
551 552 553
	if (err)
		goto out_free;

554
	for_each_cpu(i, b->cpus) {
555 556 557
		if (i == cpu)
			continue;

I
Ingo Molnar 已提交
558
		err = sysfs_create_link(&per_cpu(mce_dev, i).kobj,
559
					b->kobj, name);
560 561 562 563 564 565 566 567 568 569
		if (err)
			goto out;

		per_cpu(threshold_banks, i)[bank] = b;
	}

	goto out;

out_free:
	per_cpu(threshold_banks, cpu)[bank] = NULL;
570
	free_cpumask_var(b->cpus);
571
	kfree(b);
J
Jacob Shin 已提交
572
out:
573 574 575 576 577 578
	return err;
}

/* create dir/files for all valid threshold banks */
static __cpuinit int threshold_create_device(unsigned int cpu)
{
J
Jacob Shin 已提交
579
	unsigned int bank;
580 581 582
	int err = 0;

	for (bank = 0; bank < NR_BANKS; ++bank) {
583
		if (!(per_cpu(bank_map, cpu) & (1 << bank)))
584 585 586 587 588
			continue;
		err = threshold_create_bank(cpu, bank);
		if (err)
			goto out;
	}
J
Jacob Shin 已提交
589
out:
590 591 592 593 594 595 596 597 598
	return err;
}

/*
 * let's be hotplug friendly.
 * in case of multiple core processors, the first core always takes ownership
 *   of shared sysfs dir/files, and rest of the cores will be symlinked to it.
 */

599
static void deallocate_threshold_block(unsigned int cpu,
600 601 602 603 604 605 606 607 608 609
						 unsigned int bank)
{
	struct threshold_block *pos = NULL;
	struct threshold_block *tmp = NULL;
	struct threshold_bank *head = per_cpu(threshold_banks, cpu)[bank];

	if (!head)
		return;

	list_for_each_entry_safe(pos, tmp, &head->blocks->miscj, miscj) {
610
		kobject_put(&pos->kobj);
611 612 613 614 615 616 617 618
		list_del(&pos->miscj);
		kfree(pos);
	}

	kfree(per_cpu(threshold_banks, cpu)[bank]->blocks);
	per_cpu(threshold_banks, cpu)[bank]->blocks = NULL;
}

619
static void threshold_remove_bank(unsigned int cpu, int bank)
620 621
{
	struct threshold_bank *b;
622
	char name[32];
I
Ingo Molnar 已提交
623
	int i = 0;
624 625 626 627

	b = per_cpu(threshold_banks, cpu)[bank];
	if (!b)
		return;
628 629 630 631 632
	if (!b->blocks)
		goto free_out;

	sprintf(name, "threshold_bank%i", bank);

633
#ifdef CONFIG_SMP
634 635
	/* sibling symlink */
	if (shared_bank[bank] && b->blocks->cpu != cpu) {
I
Ingo Molnar 已提交
636
		sysfs_remove_link(&per_cpu(mce_dev, cpu).kobj, name);
637
		per_cpu(threshold_banks, cpu)[bank] = NULL;
I
Ingo Molnar 已提交
638

639
		return;
640
	}
641
#endif
642 643

	/* remove all sibling symlinks before unregistering */
644
	for_each_cpu(i, b->cpus) {
645 646 647
		if (i == cpu)
			continue;

I
Ingo Molnar 已提交
648
		sysfs_remove_link(&per_cpu(mce_dev, i).kobj, name);
649 650 651 652 653 654
		per_cpu(threshold_banks, i)[bank] = NULL;
	}

	deallocate_threshold_block(cpu, bank);

free_out:
655
	kobject_del(b->kobj);
656
	kobject_put(b->kobj);
657
	free_cpumask_var(b->cpus);
658 659
	kfree(b);
	per_cpu(threshold_banks, cpu)[bank] = NULL;
660 661
}

662
static void threshold_remove_device(unsigned int cpu)
663
{
J
Jacob Shin 已提交
664
	unsigned int bank;
665 666

	for (bank = 0; bank < NR_BANKS; ++bank) {
667
		if (!(per_cpu(bank_map, cpu) & (1 << bank)))
668 669 670 671 672 673
			continue;
		threshold_remove_bank(cpu, bank);
	}
}

/* get notified when a cpu comes on/off */
I
Ingo Molnar 已提交
674 675
static void __cpuinit
amd_64_threshold_cpu_callback(unsigned long action, unsigned int cpu)
676 677 678
{
	switch (action) {
	case CPU_ONLINE:
679
	case CPU_ONLINE_FROZEN:
680 681 682
		threshold_create_device(cpu);
		break;
	case CPU_DEAD:
683
	case CPU_DEAD_FROZEN:
684 685 686 687 688 689 690 691 692
		threshold_remove_device(cpu);
		break;
	default:
		break;
	}
}

static __init int threshold_init_device(void)
{
J
Jacob Shin 已提交
693
	unsigned lcpu = 0;
694 695 696

	/* to hit CPUs online before the notifier is up */
	for_each_online_cpu(lcpu) {
697
		int err = threshold_create_device(lcpu);
I
Ingo Molnar 已提交
698

699
		if (err)
700
			return err;
701
	}
702
	threshold_cpu_callback = amd_64_threshold_cpu_callback;
I
Ingo Molnar 已提交
703

704
	return 0;
705 706
}
device_initcall(threshold_init_device);