Merge tag 'perf-urgent-2020-04-12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull perf fixes from Thomas Gleixner:
"Three fixes/updates for perf:

- Fix the perf event cgroup tracking which tries to track the cgroup
even for disabled events.

- Add Ice Lake server support for uncore events

- Disable pagefaults when retrieving the physical address in the
sampling code"

* tag 'perf-urgent-2020-04-12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
perf/core: Disable page faults when getting phys address
perf/x86/intel/uncore: Add Ice Lake server uncore support
perf/cgroup: Correct indirection in perf_less_group_idx()
perf/core: Fix event cgroup tracking

Changed files
+574 -32
arch
x86
kernel
events
+8
arch/x86/events/intel/uncore.c
··· 1476 1476 .mmio_init = tgl_l_uncore_mmio_init, 1477 1477 }; 1478 1478 1479 + static const struct intel_uncore_init_fun icx_uncore_init __initconst = { 1480 + .cpu_init = icx_uncore_cpu_init, 1481 + .pci_init = icx_uncore_pci_init, 1482 + .mmio_init = icx_uncore_mmio_init, 1483 + }; 1484 + 1479 1485 static const struct intel_uncore_init_fun snr_uncore_init __initconst = { 1480 1486 .cpu_init = snr_uncore_cpu_init, 1481 1487 .pci_init = snr_uncore_pci_init, ··· 1517 1511 X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_L, &icl_uncore_init), 1518 1512 X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_NNPI, &icl_uncore_init), 1519 1513 X86_MATCH_INTEL_FAM6_MODEL(ICELAKE, &icl_uncore_init), 1514 + X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D, &icx_uncore_init), 1515 + X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, &icx_uncore_init), 1520 1516 X86_MATCH_INTEL_FAM6_MODEL(TIGERLAKE_L, &tgl_l_uncore_init), 1521 1517 X86_MATCH_INTEL_FAM6_MODEL(TIGERLAKE, &tgl_uncore_init), 1522 1518 X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT_D, &snr_uncore_init),
+3
arch/x86/events/intel/uncore.h
··· 550 550 int snr_uncore_pci_init(void); 551 551 void snr_uncore_cpu_init(void); 552 552 void snr_uncore_mmio_init(void); 553 + int icx_uncore_pci_init(void); 554 + void icx_uncore_cpu_init(void); 555 + void icx_uncore_mmio_init(void); 553 556 554 557 /* uncore_nhmex.c */ 555 558 void nhmex_uncore_cpu_init(void);
+511
arch/x86/events/intel/uncore_snbep.c
··· 382 382 #define SNR_IMC_MMIO_MEM0_OFFSET 0xd8 383 383 #define SNR_IMC_MMIO_MEM0_MASK 0x7FF 384 384 385 + /* ICX CHA */ 386 + #define ICX_C34_MSR_PMON_CTR0 0xb68 387 + #define ICX_C34_MSR_PMON_CTL0 0xb61 388 + #define ICX_C34_MSR_PMON_BOX_CTL 0xb60 389 + #define ICX_C34_MSR_PMON_BOX_FILTER0 0xb65 390 + 391 + /* ICX IIO */ 392 + #define ICX_IIO_MSR_PMON_CTL0 0xa58 393 + #define ICX_IIO_MSR_PMON_CTR0 0xa51 394 + #define ICX_IIO_MSR_PMON_BOX_CTL 0xa50 395 + 396 + /* ICX IRP */ 397 + #define ICX_IRP0_MSR_PMON_CTL0 0xa4d 398 + #define ICX_IRP0_MSR_PMON_CTR0 0xa4b 399 + #define ICX_IRP0_MSR_PMON_BOX_CTL 0xa4a 400 + 401 + /* ICX M2PCIE */ 402 + #define ICX_M2PCIE_MSR_PMON_CTL0 0xa46 403 + #define ICX_M2PCIE_MSR_PMON_CTR0 0xa41 404 + #define ICX_M2PCIE_MSR_PMON_BOX_CTL 0xa40 405 + 406 + /* ICX UPI */ 407 + #define ICX_UPI_PCI_PMON_CTL0 0x350 408 + #define ICX_UPI_PCI_PMON_CTR0 0x320 409 + #define ICX_UPI_PCI_PMON_BOX_CTL 0x318 410 + #define ICX_UPI_CTL_UMASK_EXT 0xffffff 411 + 412 + /* ICX M3UPI*/ 413 + #define ICX_M3UPI_PCI_PMON_CTL0 0xd8 414 + #define ICX_M3UPI_PCI_PMON_CTR0 0xa8 415 + #define ICX_M3UPI_PCI_PMON_BOX_CTL 0xa0 416 + 417 + /* ICX IMC */ 418 + #define ICX_NUMBER_IMC_CHN 2 419 + #define ICX_IMC_MEM_STRIDE 0x4 420 + 385 421 DEFINE_UNCORE_FORMAT_ATTR(event, event, "config:0-7"); 386 422 DEFINE_UNCORE_FORMAT_ATTR(event2, event, "config:0-6"); 387 423 DEFINE_UNCORE_FORMAT_ATTR(event_ext, event, "config:0-7,21"); ··· 426 390 DEFINE_UNCORE_FORMAT_ATTR(umask_ext, umask, "config:8-15,32-43,45-55"); 427 391 DEFINE_UNCORE_FORMAT_ATTR(umask_ext2, umask, "config:8-15,32-57"); 428 392 DEFINE_UNCORE_FORMAT_ATTR(umask_ext3, umask, "config:8-15,32-39"); 393 + DEFINE_UNCORE_FORMAT_ATTR(umask_ext4, umask, "config:8-15,32-55"); 429 394 DEFINE_UNCORE_FORMAT_ATTR(qor, qor, "config:16"); 430 395 DEFINE_UNCORE_FORMAT_ATTR(edge, edge, "config:18"); 431 396 DEFINE_UNCORE_FORMAT_ATTR(tid_en, tid_en, "config:19"); ··· 4588 4551 } 4589 4552 4590 4553 /* end of SNR uncore support */ 4554 + 4555 + /* ICX uncore support */ 4556 + 4557 + static unsigned icx_cha_msr_offsets[] = { 4558 + 0x2a0, 0x2ae, 0x2bc, 0x2ca, 0x2d8, 0x2e6, 0x2f4, 0x302, 0x310, 4559 + 0x31e, 0x32c, 0x33a, 0x348, 0x356, 0x364, 0x372, 0x380, 0x38e, 4560 + 0x3aa, 0x3b8, 0x3c6, 0x3d4, 0x3e2, 0x3f0, 0x3fe, 0x40c, 0x41a, 4561 + 0x428, 0x436, 0x444, 0x452, 0x460, 0x46e, 0x47c, 0x0, 0xe, 4562 + 0x1c, 0x2a, 0x38, 0x46, 4563 + }; 4564 + 4565 + static int icx_cha_hw_config(struct intel_uncore_box *box, struct perf_event *event) 4566 + { 4567 + struct hw_perf_event_extra *reg1 = &event->hw.extra_reg; 4568 + bool tie_en = !!(event->hw.config & SNBEP_CBO_PMON_CTL_TID_EN); 4569 + 4570 + if (tie_en) { 4571 + reg1->reg = ICX_C34_MSR_PMON_BOX_FILTER0 + 4572 + icx_cha_msr_offsets[box->pmu->pmu_idx]; 4573 + reg1->config = event->attr.config1 & SKX_CHA_MSR_PMON_BOX_FILTER_TID; 4574 + reg1->idx = 0; 4575 + } 4576 + 4577 + return 0; 4578 + } 4579 + 4580 + static struct intel_uncore_ops icx_uncore_chabox_ops = { 4581 + .init_box = ivbep_uncore_msr_init_box, 4582 + .disable_box = snbep_uncore_msr_disable_box, 4583 + .enable_box = snbep_uncore_msr_enable_box, 4584 + .disable_event = snbep_uncore_msr_disable_event, 4585 + .enable_event = snr_cha_enable_event, 4586 + .read_counter = uncore_msr_read_counter, 4587 + .hw_config = icx_cha_hw_config, 4588 + }; 4589 + 4590 + static struct intel_uncore_type icx_uncore_chabox = { 4591 + .name = "cha", 4592 + .num_counters = 4, 4593 + .perf_ctr_bits = 48, 4594 + .event_ctl = ICX_C34_MSR_PMON_CTL0, 4595 + .perf_ctr = ICX_C34_MSR_PMON_CTR0, 4596 + .box_ctl = ICX_C34_MSR_PMON_BOX_CTL, 4597 + .msr_offsets = icx_cha_msr_offsets, 4598 + .event_mask = HSWEP_S_MSR_PMON_RAW_EVENT_MASK, 4599 + .event_mask_ext = SNR_CHA_RAW_EVENT_MASK_EXT, 4600 + .constraints = skx_uncore_chabox_constraints, 4601 + .ops = &icx_uncore_chabox_ops, 4602 + .format_group = &snr_uncore_chabox_format_group, 4603 + }; 4604 + 4605 + static unsigned icx_msr_offsets[] = { 4606 + 0x0, 0x20, 0x40, 0x90, 0xb0, 0xd0, 4607 + }; 4608 + 4609 + static struct event_constraint icx_uncore_iio_constraints[] = { 4610 + UNCORE_EVENT_CONSTRAINT(0x02, 0x3), 4611 + UNCORE_EVENT_CONSTRAINT(0x03, 0x3), 4612 + UNCORE_EVENT_CONSTRAINT(0x83, 0x3), 4613 + UNCORE_EVENT_CONSTRAINT(0xc0, 0xc), 4614 + UNCORE_EVENT_CONSTRAINT(0xc5, 0xc), 4615 + EVENT_CONSTRAINT_END 4616 + }; 4617 + 4618 + static struct intel_uncore_type icx_uncore_iio = { 4619 + .name = "iio", 4620 + .num_counters = 4, 4621 + .num_boxes = 6, 4622 + .perf_ctr_bits = 48, 4623 + .event_ctl = ICX_IIO_MSR_PMON_CTL0, 4624 + .perf_ctr = ICX_IIO_MSR_PMON_CTR0, 4625 + .event_mask = SNBEP_PMON_RAW_EVENT_MASK, 4626 + .event_mask_ext = SNR_IIO_PMON_RAW_EVENT_MASK_EXT, 4627 + .box_ctl = ICX_IIO_MSR_PMON_BOX_CTL, 4628 + .msr_offsets = icx_msr_offsets, 4629 + .constraints = icx_uncore_iio_constraints, 4630 + .ops = &skx_uncore_iio_ops, 4631 + .format_group = &snr_uncore_iio_format_group, 4632 + }; 4633 + 4634 + static struct intel_uncore_type icx_uncore_irp = { 4635 + .name = "irp", 4636 + .num_counters = 2, 4637 + .num_boxes = 6, 4638 + .perf_ctr_bits = 48, 4639 + .event_ctl = ICX_IRP0_MSR_PMON_CTL0, 4640 + .perf_ctr = ICX_IRP0_MSR_PMON_CTR0, 4641 + .event_mask = SNBEP_PMON_RAW_EVENT_MASK, 4642 + .box_ctl = ICX_IRP0_MSR_PMON_BOX_CTL, 4643 + .msr_offsets = icx_msr_offsets, 4644 + .ops = &ivbep_uncore_msr_ops, 4645 + .format_group = &ivbep_uncore_format_group, 4646 + }; 4647 + 4648 + static struct event_constraint icx_uncore_m2pcie_constraints[] = { 4649 + UNCORE_EVENT_CONSTRAINT(0x14, 0x3), 4650 + UNCORE_EVENT_CONSTRAINT(0x23, 0x3), 4651 + UNCORE_EVENT_CONSTRAINT(0x2d, 0x3), 4652 + EVENT_CONSTRAINT_END 4653 + }; 4654 + 4655 + static struct intel_uncore_type icx_uncore_m2pcie = { 4656 + .name = "m2pcie", 4657 + .num_counters = 4, 4658 + .num_boxes = 6, 4659 + .perf_ctr_bits = 48, 4660 + .event_ctl = ICX_M2PCIE_MSR_PMON_CTL0, 4661 + .perf_ctr = ICX_M2PCIE_MSR_PMON_CTR0, 4662 + .box_ctl = ICX_M2PCIE_MSR_PMON_BOX_CTL, 4663 + .msr_offsets = icx_msr_offsets, 4664 + .constraints = icx_uncore_m2pcie_constraints, 4665 + .event_mask = SNBEP_PMON_RAW_EVENT_MASK, 4666 + .ops = &ivbep_uncore_msr_ops, 4667 + .format_group = &ivbep_uncore_format_group, 4668 + }; 4669 + 4670 + enum perf_uncore_icx_iio_freerunning_type_id { 4671 + ICX_IIO_MSR_IOCLK, 4672 + ICX_IIO_MSR_BW_IN, 4673 + 4674 + ICX_IIO_FREERUNNING_TYPE_MAX, 4675 + }; 4676 + 4677 + static unsigned icx_iio_clk_freerunning_box_offsets[] = { 4678 + 0x0, 0x20, 0x40, 0x90, 0xb0, 0xd0, 4679 + }; 4680 + 4681 + static unsigned icx_iio_bw_freerunning_box_offsets[] = { 4682 + 0x0, 0x10, 0x20, 0x90, 0xa0, 0xb0, 4683 + }; 4684 + 4685 + static struct freerunning_counters icx_iio_freerunning[] = { 4686 + [ICX_IIO_MSR_IOCLK] = { 0xa55, 0x1, 0x20, 1, 48, icx_iio_clk_freerunning_box_offsets }, 4687 + [ICX_IIO_MSR_BW_IN] = { 0xaa0, 0x1, 0x10, 8, 48, icx_iio_bw_freerunning_box_offsets }, 4688 + }; 4689 + 4690 + static struct uncore_event_desc icx_uncore_iio_freerunning_events[] = { 4691 + /* Free-Running IIO CLOCKS Counter */ 4692 + INTEL_UNCORE_EVENT_DESC(ioclk, "event=0xff,umask=0x10"), 4693 + /* Free-Running IIO BANDWIDTH IN Counters */ 4694 + INTEL_UNCORE_EVENT_DESC(bw_in_port0, "event=0xff,umask=0x20"), 4695 + INTEL_UNCORE_EVENT_DESC(bw_in_port0.scale, "3.814697266e-6"), 4696 + INTEL_UNCORE_EVENT_DESC(bw_in_port0.unit, "MiB"), 4697 + INTEL_UNCORE_EVENT_DESC(bw_in_port1, "event=0xff,umask=0x21"), 4698 + INTEL_UNCORE_EVENT_DESC(bw_in_port1.scale, "3.814697266e-6"), 4699 + INTEL_UNCORE_EVENT_DESC(bw_in_port1.unit, "MiB"), 4700 + INTEL_UNCORE_EVENT_DESC(bw_in_port2, "event=0xff,umask=0x22"), 4701 + INTEL_UNCORE_EVENT_DESC(bw_in_port2.scale, "3.814697266e-6"), 4702 + INTEL_UNCORE_EVENT_DESC(bw_in_port2.unit, "MiB"), 4703 + INTEL_UNCORE_EVENT_DESC(bw_in_port3, "event=0xff,umask=0x23"), 4704 + INTEL_UNCORE_EVENT_DESC(bw_in_port3.scale, "3.814697266e-6"), 4705 + INTEL_UNCORE_EVENT_DESC(bw_in_port3.unit, "MiB"), 4706 + INTEL_UNCORE_EVENT_DESC(bw_in_port4, "event=0xff,umask=0x24"), 4707 + INTEL_UNCORE_EVENT_DESC(bw_in_port4.scale, "3.814697266e-6"), 4708 + INTEL_UNCORE_EVENT_DESC(bw_in_port4.unit, "MiB"), 4709 + INTEL_UNCORE_EVENT_DESC(bw_in_port5, "event=0xff,umask=0x25"), 4710 + INTEL_UNCORE_EVENT_DESC(bw_in_port5.scale, "3.814697266e-6"), 4711 + INTEL_UNCORE_EVENT_DESC(bw_in_port5.unit, "MiB"), 4712 + INTEL_UNCORE_EVENT_DESC(bw_in_port6, "event=0xff,umask=0x26"), 4713 + INTEL_UNCORE_EVENT_DESC(bw_in_port6.scale, "3.814697266e-6"), 4714 + INTEL_UNCORE_EVENT_DESC(bw_in_port6.unit, "MiB"), 4715 + INTEL_UNCORE_EVENT_DESC(bw_in_port7, "event=0xff,umask=0x27"), 4716 + INTEL_UNCORE_EVENT_DESC(bw_in_port7.scale, "3.814697266e-6"), 4717 + INTEL_UNCORE_EVENT_DESC(bw_in_port7.unit, "MiB"), 4718 + { /* end: all zeroes */ }, 4719 + }; 4720 + 4721 + static struct intel_uncore_type icx_uncore_iio_free_running = { 4722 + .name = "iio_free_running", 4723 + .num_counters = 9, 4724 + .num_boxes = 6, 4725 + .num_freerunning_types = ICX_IIO_FREERUNNING_TYPE_MAX, 4726 + .freerunning = icx_iio_freerunning, 4727 + .ops = &skx_uncore_iio_freerunning_ops, 4728 + .event_descs = icx_uncore_iio_freerunning_events, 4729 + .format_group = &skx_uncore_iio_freerunning_format_group, 4730 + }; 4731 + 4732 + static struct intel_uncore_type *icx_msr_uncores[] = { 4733 + &skx_uncore_ubox, 4734 + &icx_uncore_chabox, 4735 + &icx_uncore_iio, 4736 + &icx_uncore_irp, 4737 + &icx_uncore_m2pcie, 4738 + &skx_uncore_pcu, 4739 + &icx_uncore_iio_free_running, 4740 + NULL, 4741 + }; 4742 + 4743 + /* 4744 + * To determine the number of CHAs, it should read CAPID6(Low) and CAPID7 (High) 4745 + * registers which located at Device 30, Function 3 4746 + */ 4747 + #define ICX_CAPID6 0x9c 4748 + #define ICX_CAPID7 0xa0 4749 + 4750 + static u64 icx_count_chabox(void) 4751 + { 4752 + struct pci_dev *dev = NULL; 4753 + u64 caps = 0; 4754 + 4755 + dev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x345b, dev); 4756 + if (!dev) 4757 + goto out; 4758 + 4759 + pci_read_config_dword(dev, ICX_CAPID6, (u32 *)&caps); 4760 + pci_read_config_dword(dev, ICX_CAPID7, (u32 *)&caps + 1); 4761 + out: 4762 + pci_dev_put(dev); 4763 + return hweight64(caps); 4764 + } 4765 + 4766 + void icx_uncore_cpu_init(void) 4767 + { 4768 + u64 num_boxes = icx_count_chabox(); 4769 + 4770 + if (WARN_ON(num_boxes > ARRAY_SIZE(icx_cha_msr_offsets))) 4771 + return; 4772 + icx_uncore_chabox.num_boxes = num_boxes; 4773 + uncore_msr_uncores = icx_msr_uncores; 4774 + } 4775 + 4776 + static struct intel_uncore_type icx_uncore_m2m = { 4777 + .name = "m2m", 4778 + .num_counters = 4, 4779 + .num_boxes = 4, 4780 + .perf_ctr_bits = 48, 4781 + .perf_ctr = SNR_M2M_PCI_PMON_CTR0, 4782 + .event_ctl = SNR_M2M_PCI_PMON_CTL0, 4783 + .event_mask = SNBEP_PMON_RAW_EVENT_MASK, 4784 + .box_ctl = SNR_M2M_PCI_PMON_BOX_CTL, 4785 + .ops = &snr_m2m_uncore_pci_ops, 4786 + .format_group = &skx_uncore_format_group, 4787 + }; 4788 + 4789 + static struct attribute *icx_upi_uncore_formats_attr[] = { 4790 + &format_attr_event.attr, 4791 + &format_attr_umask_ext4.attr, 4792 + &format_attr_edge.attr, 4793 + &format_attr_inv.attr, 4794 + &format_attr_thresh8.attr, 4795 + NULL, 4796 + }; 4797 + 4798 + static const struct attribute_group icx_upi_uncore_format_group = { 4799 + .name = "format", 4800 + .attrs = icx_upi_uncore_formats_attr, 4801 + }; 4802 + 4803 + static struct intel_uncore_type icx_uncore_upi = { 4804 + .name = "upi", 4805 + .num_counters = 4, 4806 + .num_boxes = 3, 4807 + .perf_ctr_bits = 48, 4808 + .perf_ctr = ICX_UPI_PCI_PMON_CTR0, 4809 + .event_ctl = ICX_UPI_PCI_PMON_CTL0, 4810 + .event_mask = SNBEP_PMON_RAW_EVENT_MASK, 4811 + .event_mask_ext = ICX_UPI_CTL_UMASK_EXT, 4812 + .box_ctl = ICX_UPI_PCI_PMON_BOX_CTL, 4813 + .ops = &skx_upi_uncore_pci_ops, 4814 + .format_group = &icx_upi_uncore_format_group, 4815 + }; 4816 + 4817 + static struct event_constraint icx_uncore_m3upi_constraints[] = { 4818 + UNCORE_EVENT_CONSTRAINT(0x1c, 0x1), 4819 + UNCORE_EVENT_CONSTRAINT(0x1d, 0x1), 4820 + UNCORE_EVENT_CONSTRAINT(0x1e, 0x1), 4821 + UNCORE_EVENT_CONSTRAINT(0x1f, 0x1), 4822 + UNCORE_EVENT_CONSTRAINT(0x40, 0x7), 4823 + UNCORE_EVENT_CONSTRAINT(0x4e, 0x7), 4824 + UNCORE_EVENT_CONSTRAINT(0x4f, 0x7), 4825 + UNCORE_EVENT_CONSTRAINT(0x50, 0x7), 4826 + EVENT_CONSTRAINT_END 4827 + }; 4828 + 4829 + static struct intel_uncore_type icx_uncore_m3upi = { 4830 + .name = "m3upi", 4831 + .num_counters = 4, 4832 + .num_boxes = 3, 4833 + .perf_ctr_bits = 48, 4834 + .perf_ctr = ICX_M3UPI_PCI_PMON_CTR0, 4835 + .event_ctl = ICX_M3UPI_PCI_PMON_CTL0, 4836 + .event_mask = SNBEP_PMON_RAW_EVENT_MASK, 4837 + .box_ctl = ICX_M3UPI_PCI_PMON_BOX_CTL, 4838 + .constraints = icx_uncore_m3upi_constraints, 4839 + .ops = &ivbep_uncore_pci_ops, 4840 + .format_group = &skx_uncore_format_group, 4841 + }; 4842 + 4843 + enum { 4844 + ICX_PCI_UNCORE_M2M, 4845 + ICX_PCI_UNCORE_UPI, 4846 + ICX_PCI_UNCORE_M3UPI, 4847 + }; 4848 + 4849 + static struct intel_uncore_type *icx_pci_uncores[] = { 4850 + [ICX_PCI_UNCORE_M2M] = &icx_uncore_m2m, 4851 + [ICX_PCI_UNCORE_UPI] = &icx_uncore_upi, 4852 + [ICX_PCI_UNCORE_M3UPI] = &icx_uncore_m3upi, 4853 + NULL, 4854 + }; 4855 + 4856 + static const struct pci_device_id icx_uncore_pci_ids[] = { 4857 + { /* M2M 0 */ 4858 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x344a), 4859 + .driver_data = UNCORE_PCI_DEV_FULL_DATA(12, 0, ICX_PCI_UNCORE_M2M, 0), 4860 + }, 4861 + { /* M2M 1 */ 4862 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x344a), 4863 + .driver_data = UNCORE_PCI_DEV_FULL_DATA(13, 0, ICX_PCI_UNCORE_M2M, 1), 4864 + }, 4865 + { /* M2M 2 */ 4866 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x344a), 4867 + .driver_data = UNCORE_PCI_DEV_FULL_DATA(14, 0, ICX_PCI_UNCORE_M2M, 2), 4868 + }, 4869 + { /* M2M 3 */ 4870 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x344a), 4871 + .driver_data = UNCORE_PCI_DEV_FULL_DATA(15, 0, ICX_PCI_UNCORE_M2M, 3), 4872 + }, 4873 + { /* UPI Link 0 */ 4874 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x3441), 4875 + .driver_data = UNCORE_PCI_DEV_FULL_DATA(2, 1, ICX_PCI_UNCORE_UPI, 0), 4876 + }, 4877 + { /* UPI Link 1 */ 4878 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x3441), 4879 + .driver_data = UNCORE_PCI_DEV_FULL_DATA(3, 1, ICX_PCI_UNCORE_UPI, 1), 4880 + }, 4881 + { /* UPI Link 2 */ 4882 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x3441), 4883 + .driver_data = UNCORE_PCI_DEV_FULL_DATA(4, 1, ICX_PCI_UNCORE_UPI, 2), 4884 + }, 4885 + { /* M3UPI Link 0 */ 4886 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x3446), 4887 + .driver_data = UNCORE_PCI_DEV_FULL_DATA(5, 1, ICX_PCI_UNCORE_M3UPI, 0), 4888 + }, 4889 + { /* M3UPI Link 1 */ 4890 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x3446), 4891 + .driver_data = UNCORE_PCI_DEV_FULL_DATA(6, 1, ICX_PCI_UNCORE_M3UPI, 1), 4892 + }, 4893 + { /* M3UPI Link 2 */ 4894 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x3446), 4895 + .driver_data = UNCORE_PCI_DEV_FULL_DATA(7, 1, ICX_PCI_UNCORE_M3UPI, 2), 4896 + }, 4897 + { /* end: all zeroes */ } 4898 + }; 4899 + 4900 + static struct pci_driver icx_uncore_pci_driver = { 4901 + .name = "icx_uncore", 4902 + .id_table = icx_uncore_pci_ids, 4903 + }; 4904 + 4905 + int icx_uncore_pci_init(void) 4906 + { 4907 + /* ICX UBOX DID */ 4908 + int ret = snbep_pci2phy_map_init(0x3450, SKX_CPUNODEID, 4909 + SKX_GIDNIDMAP, true); 4910 + 4911 + if (ret) 4912 + return ret; 4913 + 4914 + uncore_pci_uncores = icx_pci_uncores; 4915 + uncore_pci_driver = &icx_uncore_pci_driver; 4916 + return 0; 4917 + } 4918 + 4919 + static void icx_uncore_imc_init_box(struct intel_uncore_box *box) 4920 + { 4921 + unsigned int box_ctl = box->pmu->type->box_ctl + 4922 + box->pmu->type->mmio_offset * (box->pmu->pmu_idx % ICX_NUMBER_IMC_CHN); 4923 + int mem_offset = (box->pmu->pmu_idx / ICX_NUMBER_IMC_CHN) * ICX_IMC_MEM_STRIDE + 4924 + SNR_IMC_MMIO_MEM0_OFFSET; 4925 + 4926 + __snr_uncore_mmio_init_box(box, box_ctl, mem_offset); 4927 + } 4928 + 4929 + static struct intel_uncore_ops icx_uncore_mmio_ops = { 4930 + .init_box = icx_uncore_imc_init_box, 4931 + .exit_box = uncore_mmio_exit_box, 4932 + .disable_box = snr_uncore_mmio_disable_box, 4933 + .enable_box = snr_uncore_mmio_enable_box, 4934 + .disable_event = snr_uncore_mmio_disable_event, 4935 + .enable_event = snr_uncore_mmio_enable_event, 4936 + .read_counter = uncore_mmio_read_counter, 4937 + }; 4938 + 4939 + static struct intel_uncore_type icx_uncore_imc = { 4940 + .name = "imc", 4941 + .num_counters = 4, 4942 + .num_boxes = 8, 4943 + .perf_ctr_bits = 48, 4944 + .fixed_ctr_bits = 48, 4945 + .fixed_ctr = SNR_IMC_MMIO_PMON_FIXED_CTR, 4946 + .fixed_ctl = SNR_IMC_MMIO_PMON_FIXED_CTL, 4947 + .event_descs = hswep_uncore_imc_events, 4948 + .perf_ctr = SNR_IMC_MMIO_PMON_CTR0, 4949 + .event_ctl = SNR_IMC_MMIO_PMON_CTL0, 4950 + .event_mask = SNBEP_PMON_RAW_EVENT_MASK, 4951 + .box_ctl = SNR_IMC_MMIO_PMON_BOX_CTL, 4952 + .mmio_offset = SNR_IMC_MMIO_OFFSET, 4953 + .ops = &icx_uncore_mmio_ops, 4954 + .format_group = &skx_uncore_format_group, 4955 + }; 4956 + 4957 + enum perf_uncore_icx_imc_freerunning_type_id { 4958 + ICX_IMC_DCLK, 4959 + ICX_IMC_DDR, 4960 + ICX_IMC_DDRT, 4961 + 4962 + ICX_IMC_FREERUNNING_TYPE_MAX, 4963 + }; 4964 + 4965 + static struct freerunning_counters icx_imc_freerunning[] = { 4966 + [ICX_IMC_DCLK] = { 0x22b0, 0x0, 0, 1, 48 }, 4967 + [ICX_IMC_DDR] = { 0x2290, 0x8, 0, 2, 48 }, 4968 + [ICX_IMC_DDRT] = { 0x22a0, 0x8, 0, 2, 48 }, 4969 + }; 4970 + 4971 + static struct uncore_event_desc icx_uncore_imc_freerunning_events[] = { 4972 + INTEL_UNCORE_EVENT_DESC(dclk, "event=0xff,umask=0x10"), 4973 + 4974 + INTEL_UNCORE_EVENT_DESC(read, "event=0xff,umask=0x20"), 4975 + INTEL_UNCORE_EVENT_DESC(read.scale, "3.814697266e-6"), 4976 + INTEL_UNCORE_EVENT_DESC(read.unit, "MiB"), 4977 + INTEL_UNCORE_EVENT_DESC(write, "event=0xff,umask=0x21"), 4978 + INTEL_UNCORE_EVENT_DESC(write.scale, "3.814697266e-6"), 4979 + INTEL_UNCORE_EVENT_DESC(write.unit, "MiB"), 4980 + 4981 + INTEL_UNCORE_EVENT_DESC(ddrt_read, "event=0xff,umask=0x30"), 4982 + INTEL_UNCORE_EVENT_DESC(ddrt_read.scale, "3.814697266e-6"), 4983 + INTEL_UNCORE_EVENT_DESC(ddrt_read.unit, "MiB"), 4984 + INTEL_UNCORE_EVENT_DESC(ddrt_write, "event=0xff,umask=0x31"), 4985 + INTEL_UNCORE_EVENT_DESC(ddrt_write.scale, "3.814697266e-6"), 4986 + INTEL_UNCORE_EVENT_DESC(ddrt_write.unit, "MiB"), 4987 + { /* end: all zeroes */ }, 4988 + }; 4989 + 4990 + static void icx_uncore_imc_freerunning_init_box(struct intel_uncore_box *box) 4991 + { 4992 + int mem_offset = box->pmu->pmu_idx * ICX_IMC_MEM_STRIDE + 4993 + SNR_IMC_MMIO_MEM0_OFFSET; 4994 + 4995 + __snr_uncore_mmio_init_box(box, uncore_mmio_box_ctl(box), mem_offset); 4996 + } 4997 + 4998 + static struct intel_uncore_ops icx_uncore_imc_freerunning_ops = { 4999 + .init_box = icx_uncore_imc_freerunning_init_box, 5000 + .exit_box = uncore_mmio_exit_box, 5001 + .read_counter = uncore_mmio_read_counter, 5002 + .hw_config = uncore_freerunning_hw_config, 5003 + }; 5004 + 5005 + static struct intel_uncore_type icx_uncore_imc_free_running = { 5006 + .name = "imc_free_running", 5007 + .num_counters = 5, 5008 + .num_boxes = 4, 5009 + .num_freerunning_types = ICX_IMC_FREERUNNING_TYPE_MAX, 5010 + .freerunning = icx_imc_freerunning, 5011 + .ops = &icx_uncore_imc_freerunning_ops, 5012 + .event_descs = icx_uncore_imc_freerunning_events, 5013 + .format_group = &skx_uncore_iio_freerunning_format_group, 5014 + }; 5015 + 5016 + static struct intel_uncore_type *icx_mmio_uncores[] = { 5017 + &icx_uncore_imc, 5018 + &icx_uncore_imc_free_running, 5019 + NULL, 5020 + }; 5021 + 5022 + void icx_uncore_mmio_init(void) 5023 + { 5024 + uncore_mmio_uncores = icx_mmio_uncores; 5025 + } 5026 + 5027 + /* end of ICX uncore support */
+52 -32
kernel/events/core.c
··· 983 983 event->shadow_ctx_time = now - t->timestamp; 984 984 } 985 985 986 - /* 987 - * Update cpuctx->cgrp so that it is set when first cgroup event is added and 988 - * cleared when last cgroup event is removed. 989 - */ 990 986 static inline void 991 - list_update_cgroup_event(struct perf_event *event, 992 - struct perf_event_context *ctx, bool add) 987 + perf_cgroup_event_enable(struct perf_event *event, struct perf_event_context *ctx) 993 988 { 994 989 struct perf_cpu_context *cpuctx; 995 - struct list_head *cpuctx_entry; 996 990 997 991 if (!is_cgroup_event(event)) 998 992 return; ··· 1003 1009 * because if the first would mismatch, the second would not try again 1004 1010 * and we would leave cpuctx->cgrp unset. 1005 1011 */ 1006 - if (add && !cpuctx->cgrp) { 1012 + if (ctx->is_active && !cpuctx->cgrp) { 1007 1013 struct perf_cgroup *cgrp = perf_cgroup_from_task(current, ctx); 1008 1014 1009 1015 if (cgroup_is_descendant(cgrp->css.cgroup, event->cgrp->css.cgroup)) 1010 1016 cpuctx->cgrp = cgrp; 1011 1017 } 1012 1018 1013 - if (add && ctx->nr_cgroups++) 1014 - return; 1015 - else if (!add && --ctx->nr_cgroups) 1019 + if (ctx->nr_cgroups++) 1016 1020 return; 1017 1021 1018 - /* no cgroup running */ 1019 - if (!add) 1022 + list_add(&cpuctx->cgrp_cpuctx_entry, 1023 + per_cpu_ptr(&cgrp_cpuctx_list, event->cpu)); 1024 + } 1025 + 1026 + static inline void 1027 + perf_cgroup_event_disable(struct perf_event *event, struct perf_event_context *ctx) 1028 + { 1029 + struct perf_cpu_context *cpuctx; 1030 + 1031 + if (!is_cgroup_event(event)) 1032 + return; 1033 + 1034 + /* 1035 + * Because cgroup events are always per-cpu events, 1036 + * @ctx == &cpuctx->ctx. 1037 + */ 1038 + cpuctx = container_of(ctx, struct perf_cpu_context, ctx); 1039 + 1040 + if (--ctx->nr_cgroups) 1041 + return; 1042 + 1043 + if (ctx->is_active && cpuctx->cgrp) 1020 1044 cpuctx->cgrp = NULL; 1021 1045 1022 - cpuctx_entry = &cpuctx->cgrp_cpuctx_entry; 1023 - if (add) 1024 - list_add(cpuctx_entry, 1025 - per_cpu_ptr(&cgrp_cpuctx_list, event->cpu)); 1026 - else 1027 - list_del(cpuctx_entry); 1046 + list_del(&cpuctx->cgrp_cpuctx_entry); 1028 1047 } 1029 1048 1030 1049 #else /* !CONFIG_CGROUP_PERF */ ··· 1103 1096 } 1104 1097 1105 1098 static inline void 1106 - list_update_cgroup_event(struct perf_event *event, 1107 - struct perf_event_context *ctx, bool add) 1099 + perf_cgroup_event_enable(struct perf_event *event, struct perf_event_context *ctx) 1108 1100 { 1109 1101 } 1110 1102 1103 + static inline void 1104 + perf_cgroup_event_disable(struct perf_event *event, struct perf_event_context *ctx) 1105 + { 1106 + } 1111 1107 #endif 1112 1108 1113 1109 /* ··· 1801 1791 add_event_to_groups(event, ctx); 1802 1792 } 1803 1793 1804 - list_update_cgroup_event(event, ctx, true); 1805 - 1806 1794 list_add_rcu(&event->event_entry, &ctx->event_list); 1807 1795 ctx->nr_events++; 1808 1796 if (event->attr.inherit_stat) 1809 1797 ctx->nr_stat++; 1798 + 1799 + if (event->state > PERF_EVENT_STATE_OFF) 1800 + perf_cgroup_event_enable(event, ctx); 1810 1801 1811 1802 ctx->generation++; 1812 1803 } ··· 1987 1976 1988 1977 event->attach_state &= ~PERF_ATTACH_CONTEXT; 1989 1978 1990 - list_update_cgroup_event(event, ctx, false); 1991 - 1992 1979 ctx->nr_events--; 1993 1980 if (event->attr.inherit_stat) 1994 1981 ctx->nr_stat--; ··· 2003 1994 * of error state is by explicit re-enabling 2004 1995 * of the event 2005 1996 */ 2006 - if (event->state > PERF_EVENT_STATE_OFF) 1997 + if (event->state > PERF_EVENT_STATE_OFF) { 1998 + perf_cgroup_event_disable(event, ctx); 2007 1999 perf_event_set_state(event, PERF_EVENT_STATE_OFF); 2000 + } 2008 2001 2009 2002 ctx->generation++; 2010 2003 } ··· 2237 2226 2238 2227 if (READ_ONCE(event->pending_disable) >= 0) { 2239 2228 WRITE_ONCE(event->pending_disable, -1); 2229 + perf_cgroup_event_disable(event, ctx); 2240 2230 state = PERF_EVENT_STATE_OFF; 2241 2231 } 2242 2232 perf_event_set_state(event, state); ··· 2375 2363 event_sched_out(event, cpuctx, ctx); 2376 2364 2377 2365 perf_event_set_state(event, PERF_EVENT_STATE_OFF); 2366 + perf_cgroup_event_disable(event, ctx); 2378 2367 } 2379 2368 2380 2369 /* ··· 2759 2746 } 2760 2747 2761 2748 #ifdef CONFIG_CGROUP_PERF 2762 - if (is_cgroup_event(event)) { 2749 + if (event->state > PERF_EVENT_STATE_OFF && is_cgroup_event(event)) { 2763 2750 /* 2764 2751 * If the current cgroup doesn't match the event's 2765 2752 * cgroup, we should not try to schedule it. ··· 2919 2906 ctx_sched_out(ctx, cpuctx, EVENT_TIME); 2920 2907 2921 2908 perf_event_set_state(event, PERF_EVENT_STATE_INACTIVE); 2909 + perf_cgroup_event_enable(event, ctx); 2922 2910 2923 2911 if (!ctx->is_active) 2924 2912 return; ··· 3522 3508 3523 3509 static bool perf_less_group_idx(const void *l, const void *r) 3524 3510 { 3525 - const struct perf_event *le = l, *re = r; 3511 + const struct perf_event *le = *(const struct perf_event **)l; 3512 + const struct perf_event *re = *(const struct perf_event **)r; 3526 3513 3527 3514 return le->group_index < re->group_index; 3528 3515 } ··· 3631 3616 } 3632 3617 3633 3618 if (event->state == PERF_EVENT_STATE_INACTIVE) { 3634 - if (event->attr.pinned) 3619 + if (event->attr.pinned) { 3620 + perf_cgroup_event_disable(event, ctx); 3635 3621 perf_event_set_state(event, PERF_EVENT_STATE_ERROR); 3622 + } 3636 3623 3637 3624 *can_add_hw = 0; 3638 3625 ctx->rotate_necessary = 1; ··· 6934 6917 * Try IRQ-safe __get_user_pages_fast first. 6935 6918 * If failed, leave phys_addr as 0. 6936 6919 */ 6937 - if ((current->mm != NULL) && 6938 - (__get_user_pages_fast(virt, 1, 0, &p) == 1)) 6939 - phys_addr = page_to_phys(p) + virt % PAGE_SIZE; 6920 + if (current->mm != NULL) { 6921 + pagefault_disable(); 6922 + if (__get_user_pages_fast(virt, 1, 0, &p) == 1) 6923 + phys_addr = page_to_phys(p) + virt % PAGE_SIZE; 6924 + pagefault_enable(); 6925 + } 6940 6926 6941 6927 if (p) 6942 6928 put_page(p);