mce_amd.c 15.2 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>
24
#include <linux/slab.h>
I
Ingo Molnar 已提交
25 26 27 28
#include <linux/init.h>
#include <linux/cpu.h>
#include <linux/smp.h>

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

J
Jacob Shin 已提交
34 35 36 37 38 39 40
#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
41 42
#define MASK_CNTP_HI      0x40000000
#define MASK_LOCKED_HI    0x20000000
J
Jacob Shin 已提交
43 44 45 46
#define MASK_LVTOFF_HI    0x00F00000
#define MASK_COUNT_EN_HI  0x00080000
#define MASK_INT_TYPE_HI  0x00060000
#define MASK_OVERFLOW_HI  0x00010000
47
#define MASK_ERR_COUNT_HI 0x00000FFF
48 49
#define MASK_BLKPTR_LO    0xFF000000
#define MCG_XBLK_ADDR     0xC0000400
50

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

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

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

75 76 77 78 79 80 81 82
#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 */

83 84
static void amd_threshold_interrupt(void);

85 86 87 88
/*
 * CPU Initialization
 */

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

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

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

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

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

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

119
	tr->b->interrupt_enable ?
120 121 122 123
	    (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;
124
	wrmsr(tr->b->address, mci_misc_lo, mci_misc_hi);
125 126
}

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

	for (bank = 0; bank < NR_BANKS; ++bank) {
137 138 139
		for (block = 0; block < NR_BLOCKS; ++block) {
			if (block == 0)
				address = MSR_IA32_MC0_MISC + bank * 4;
140 141 142 143
			else if (block == 1) {
				address = (low & MASK_BLKPTR_LO) >> 21;
				if (!address)
					break;
144

145
				address += MCG_XBLK_ADDR;
I
Ingo Molnar 已提交
146
			} else
147 148 149
				++address;

			if (rdmsr_safe(address, &low, &high))
150
				break;
151

152 153
			if (!(high & MASK_VALID_HI))
				continue;
154

155 156
			if (!(high & MASK_CNTP_HI)  ||
			     (high & MASK_LOCKED_HI))
157 158 159 160
				continue;

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

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

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

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

/*
 * 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.
 */
192
static void amd_threshold_interrupt(void)
193
{
I
Ingo Molnar 已提交
194
	u32 low = 0, high = 0, address = 0;
195
	unsigned int bank, block;
196 197
	struct mce m;

198
	mce_setup(&m);
199 200 201

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

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

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

226 227
			if (!(high & MASK_CNTP_HI)  ||
			     (high & MASK_LOCKED_HI))
228 229
				continue;

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

237 238 239 240 241 242 243 244
			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);
245
				return;
246
			}
247 248 249 250 251 252 253 254 255
		}
	}
}

/*
 * Sysfs Interface
 */

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

I
Ingo Molnar 已提交
261 262 263 264
#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 已提交
265
}
266 267 268
SHOW_FIELDS(interrupt_enable)
SHOW_FIELDS(threshold_limit)

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

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

278 279
	b->interrupt_enable = !!new;

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

284
	smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1);
285

H
Hidetoshi Seto 已提交
286
	return size;
287 288
}

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

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

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

303
	tr.old_limit = b->threshold_limit;
304
	b->threshold_limit = new;
305 306
	tr.b = b;
	tr.reset = 0;
307

308
	smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1);
309

H
Hidetoshi Seto 已提交
310
	return size;
311 312
}

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

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

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

static ssize_t show_error_count(struct threshold_block *b, char *buf)
{
330 331 332 333
	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);
334 335
}

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

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

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

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

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

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

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

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

374 375 376 377 378 379
	return ret;
}

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

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

386 387 388
	return ret;
}

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

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

399 400 401 402 403 404
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 已提交
405 406
	u32 low, high;
	int err;
407 408 409 410

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

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

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

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

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

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

	INIT_LIST_HEAD(&b->miscj);

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

445 446 447
	err = kobject_init_and_add(&b->kobj, &threshold_ktype,
				   per_cpu(threshold_banks, cpu)[bank]->kobj,
				   "misc%i", block);
448 449 450 451 452 453 454 455
	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 已提交
456
	} else {
457
		++address;
I
Ingo Molnar 已提交
458
	}
459 460 461 462 463

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

464 465
	if (b)
		kobject_uevent(&b->kobj, KOBJ_ADD);
466

467 468 469 470
	return err;

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

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

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

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

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

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

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

		b = per_cpu(threshold_banks, i)[bank];
509 510 511

		if (!b)
			goto out;
512

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

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

521 522 523 524
		goto out;
	}
#endif

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

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

540
#ifndef CONFIG_SMP
541
	cpumask_setall(b->cpus);
542
#else
543
	cpumask_set_cpu(cpu, b->cpus);
544 545
#endif

546
	per_cpu(threshold_banks, cpu)[bank] = b;
547

548
	err = local_allocate_threshold_blocks(cpu, bank);
549 550 551
	if (err)
		goto out_free;

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

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

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

	goto out;

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

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

	for (bank = 0; bank < NR_BANKS; ++bank) {
581
		if (!(per_cpu(bank_map, cpu) & (1 << bank)))
582 583 584 585 586
			continue;
		err = threshold_create_bank(cpu, bank);
		if (err)
			goto out;
	}
J
Jacob Shin 已提交
587
out:
588 589 590 591 592 593 594 595 596
	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.
 */

597
static void deallocate_threshold_block(unsigned int cpu,
598 599 600 601 602 603 604 605 606 607
						 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) {
608
		kobject_put(&pos->kobj);
609 610 611 612 613 614 615 616
		list_del(&pos->miscj);
		kfree(pos);
	}

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

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

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

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

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

637
		return;
638
	}
639
#endif
640 641

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

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

	deallocate_threshold_block(cpu, bank);

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

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

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

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

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

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

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

702
	return 0;
703 704
}
device_initcall(threshold_init_device);